当前位置: 首页>>代码示例>>Java>>正文


Java GroovyClassLoader类代码示例

本文整理汇总了Java中groovy.lang.GroovyClassLoader的典型用法代码示例。如果您正苦于以下问题:Java GroovyClassLoader类的具体用法?Java GroovyClassLoader怎么用?Java GroovyClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GroovyClassLoader类属于groovy.lang包,在下文中一共展示了GroovyClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newCredentialSelectionPredicate

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
/**
 * Gets credential selection predicate.
 *
 * @param selectionCriteria the selection criteria
 * @return the credential selection predicate
 */
public static Predicate<org.apereo.cas.authentication.Credential> newCredentialSelectionPredicate(final String selectionCriteria) {
    try {
        if (StringUtils.isBlank(selectionCriteria)) {
            return credential -> true;
        }

        if (selectionCriteria.endsWith(".groovy")) {
            final ResourceLoader loader = new DefaultResourceLoader();
            final Resource resource = loader.getResource(selectionCriteria);
            if (resource != null) {
                final String script = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
                final GroovyClassLoader classLoader = new GroovyClassLoader(Beans.class.getClassLoader(),
                        new CompilerConfiguration(), true);
                final Class<Predicate> clz = classLoader.parseClass(script);
                return clz.newInstance();
            }
        }

        final Class predicateClazz = ClassUtils.getClass(selectionCriteria);
        return (Predicate<org.apereo.cas.authentication.Credential>) predicateClazz.newInstance();
    } catch (final Exception e) {
        final Predicate<String> predicate = Pattern.compile(selectionCriteria).asPredicate();
        return credential -> predicate.test(credential.getId());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:Beans.java

示例2: executeCommand

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
/**
 * 执行几串简单的命令
 * 
 * @param importList
 * @param commandLines
 * @return
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws IOException
 * @throws ScriptException
 * @throws IllegalArgumentException
 * @throws InvocationTargetException
 */
public AbstractScriptLoader<KEY> executeCommand(List<String> importList, String commandLines)
		throws InstantiationException, IllegalAccessException, IOException, ScriptException,
		IllegalArgumentException, InvocationTargetException {
	StringBuilder importBuffer = new StringBuilder();
	if (importList != null) {
		for (String temp : importList) {
			importBuffer.append("import " + temp + ";");
		}
	}
	String result = importBuffer.toString()
			+ "import com.limitart.script.IDynamicCode; public class DynamicCodeProxy"
			+ dynamicCodeCount.getAndIncrement() + " extends IDynamicCode {" + " public void execute() {"
			+ commandLines + "}" + "}";
	try (GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader())) {
		@SuppressWarnings("rawtypes")
		Class parseClass = loader.parseClass(result);
		IDynamicCode newInstance = (IDynamicCode) parseClass.newInstance();
		log.info("compile code success,start executing...");
		newInstance.execute();
		log.info("done!");
	}
	return this;
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:37,代码来源:AbstractScriptLoader.java

示例3: reloadScript

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
/**
 * 重载脚本
 * 
 * @param scriptId
 * @throws IOException
 * @throws CompilationFailedException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ScriptException
 */
public AbstractScriptLoader<KEY> reloadScript(KEY scriptId) throws CompilationFailedException, IOException,
		InstantiationException, IllegalAccessException, ScriptException {
	File file = scriptPath.get(scriptId);
	Objects.requireNonNull(file, "script id:" + scriptId + " does not exist!");
	try (GroovyClassLoader loader = new GroovyClassLoader(ClassLoader.getSystemClassLoader())) {
		Class<?> parseClass = loader.parseClass(file);
		Object newInstance = parseClass.newInstance();
		if (!(newInstance instanceof IScript)) {
			throw new ScriptException("script file must implement IScript:" + file.getName());
		}
		@SuppressWarnings("unchecked")
		IScript<KEY> newScript = (IScript<KEY>) newInstance;
		scriptMap.put(scriptId, newScript);
		log.info("reload script success:" + file.getName());
	}
	return this;
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:28,代码来源:FileScriptLoader.java

示例4: loadGroovy

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
public static void loadGroovy(String name, String content) throws Exception {
	logger.info("begin load groovy name=" + name);
	logger.debug("groovy content=" + content);
	if(name.toLowerCase().contains("abstract")){
		logger.info("skip load groovy name=" + name);
		return;
	}
	ClassLoader parent = GroovyLoadUtil.class.getClassLoader();
	GroovyClassLoader loader = new GroovyClassLoader(parent);
	Class<?> groovyClass = loader.parseClass(content,name+".groovy");
	GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
	
	GroovyObject proxyObject=groovyObject;		
	if(pluginList!=null){
		
		int size=pluginList.size();
		for(int i=0;i<size;i++){
			IGroovyLoadPlugin plugin=(IGroovyLoadPlugin) pluginList.get(i);
			proxyObject=plugin.execPlugIn(name, groovyObject, proxyObject);
		}
	}		
	GroovyExecUtil.getGroovyMap().put(name, proxyObject);		
	//GroovyExecUtil.getGroovyMap().put(name, groovyObject);
	logger.info("finish load groovy name=" + name);
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:26,代码来源:GroovyLoadUtil.java

示例5: initGroovyTransformer

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
private void initGroovyTransformer(String code, List<String> extraPackage) {
    GroovyClassLoader loader = new GroovyClassLoader(GroovyTransformer.class.getClassLoader());
    String groovyRule = getGroovyRule(code, extraPackage);

    Class groovyClass;
    try {
        groovyClass = loader.parseClass(groovyRule);
    } catch (CompilationFailedException cfe) {
        throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_GROOVY_INIT_EXCEPTION, cfe);
    }

    try {
        Object t = groovyClass.newInstance();
        if (!(t instanceof Transformer)) {
            throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_GROOVY_INIT_EXCEPTION, "datax bug! contact askdatax");
        }
        this.groovyTransformer = (Transformer) t;
    } catch (Throwable ex) {
        throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_GROOVY_INIT_EXCEPTION, ex);
    }
}
 
开发者ID:yaogdu,项目名称:datax,代码行数:22,代码来源:GroovyTransformer.java

示例6: classLoading

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
@Test
@SuppressWarnings("resource")
public void classLoading() throws Exception {
	StaticApplicationContext context = new StaticApplicationContext();

	GroovyClassLoader gcl = new GroovyClassLoader();
	Class<?> class1 = gcl.parseClass("class TestBean { def myMethod() { \"foo\" } }");
	Class<?> class2 = gcl.parseClass("class TestBean { def myMethod() { \"bar\" } }");

	context.registerBeanDefinition("testBean", new RootBeanDefinition(class1));
	Object testBean1 = context.getBean("testBean");
	Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
	Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
	assertEquals("foo", result1);

	context.removeBeanDefinition("testBean");
	context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
	Object testBean2 = context.getBean("testBean");
	Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
	Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
	assertEquals("bar", result2);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:GroovyClassLoadingTests.java

示例7: registerVersion

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
public void registerVersion(String name, String xdatClass) {
    RadioMenuItem menuItem = new RadioMenuItem(name);
    menuItem.setMnemonicParsing(false);
    menuItem.selectedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            editor.execute(() -> {
                Class<? extends IOEntity> clazz = Class.forName(xdatClass, true, new GroovyClassLoader(getClass().getClassLoader())).asSubclass(IOEntity.class);
                Platform.runLater(() -> editor.setXdatClass(clazz));
                return null;
            }, e -> {
                String msg = String.format("%s: XDAT class load error", name);
                log.log(Level.WARNING, msg, e);
                Platform.runLater(() -> {
                    version.getToggles().remove(menuItem);
                    versionMenu.getItems().remove(menuItem);

                    Dialogs.showException(Alert.AlertType.ERROR, msg, e.getMessage(), e);
                });
            });
        }
    });
    version.getToggles().add(menuItem);
    versionMenu.getItems().add(menuItem);
}
 
开发者ID:acmi,项目名称:xdat_editor,代码行数:25,代码来源:Controller.java

示例8: create

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
public static AetherGrapeEngine create(GroovyClassLoader classLoader,
		List<RepositoryConfiguration> repositoryConfigurations,
		DependencyResolutionContext dependencyResolutionContext) {

	RepositorySystem repositorySystem = createServiceLocator()
			.getService(RepositorySystem.class);

	DefaultRepositorySystemSession repositorySystemSession = MavenRepositorySystemUtils
			.newSession();

	ServiceLoader<RepositorySystemSessionAutoConfiguration> autoConfigurations = ServiceLoader
			.load(RepositorySystemSessionAutoConfiguration.class);

	for (RepositorySystemSessionAutoConfiguration autoConfiguration : autoConfigurations) {
		autoConfiguration.apply(repositorySystemSession, repositorySystem);
	}

	new DefaultRepositorySystemSessionAutoConfiguration()
			.apply(repositorySystemSession, repositorySystem);

	return new AetherGrapeEngine(classLoader, repositorySystem,
			repositorySystemSession, createRepositories(repositoryConfigurations),
			dependencyResolutionContext);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:AetherGrapeEngineFactory.java

示例9: AetherGrapeEngine

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
public AetherGrapeEngine(GroovyClassLoader classLoader,
		RepositorySystem repositorySystem,
		DefaultRepositorySystemSession repositorySystemSession,
		List<RemoteRepository> remoteRepositories,
		DependencyResolutionContext resolutionContext) {
	this.classLoader = classLoader;
	this.repositorySystem = repositorySystem;
	this.session = repositorySystemSession;
	this.resolutionContext = resolutionContext;
	this.repositories = new ArrayList<RemoteRepository>();
	List<RemoteRepository> remotes = new ArrayList<RemoteRepository>(
			remoteRepositories);
	Collections.reverse(remotes); // priority is reversed in addRepository
	for (RemoteRepository repository : remotes) {
		addRepository(repository);
	}
	this.progressReporter = getProgressReporter(this.session);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:AetherGrapeEngine.java

示例10: setUp

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	given(this.resolver.getGroupId("spring-boot-starter-logging"))
			.willReturn("org.springframework.boot");
	given(this.resolver.getArtifactId("spring-boot-starter-logging"))
			.willReturn("spring-boot-starter-logging");
	this.moduleNode.addClass(this.classNode);
	this.dependencyCustomizer = new DependencyCustomizer(
			new GroovyClassLoader(getClass().getClassLoader()), this.moduleNode,
			new DependencyResolutionContext() {

				@Override
				public ArtifactCoordinatesResolver getArtifactCoordinatesResolver() {
					return DependencyCustomizerTests.this.resolver;
				}

			});
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:DependencyCustomizerTests.java

示例11: getGroovyObject

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
@SuppressWarnings("resource")
private static final GroovyObject getGroovyObject(String rule)
		throws IllegalAccessException, InstantiationException {
	if (!RULE_CLASS_CACHE.containsKey(rule)) {
		synchronized (GroovyRuleEngine.class) {
			if (!RULE_CLASS_CACHE.containsKey(rule)) {
				Matcher matcher = DimensionRule.RULE_COLUMN_PATTERN.matcher(rule);
				StringBuilder engineClazzImpl = new StringBuilder(200)
						.append("class RuleEngineBaseImpl extends " + RuleEngineBase.class.getName() + "{")
						.append("Object execute(Map context) {").append(matcher.replaceAll("context.get(\"$1\")"))
						.append("}").append("}");
				GroovyClassLoader loader = new GroovyClassLoader(AbstractDimensionRule.class.getClassLoader());
				Class<?> engineClazz = loader.parseClass(engineClazzImpl.toString());
				RULE_CLASS_CACHE.put(rule, engineClazz);
			}
		}
	}
	return (GroovyObject) RULE_CLASS_CACHE.get(rule).newInstance();
}
 
开发者ID:dianping,项目名称:zebra,代码行数:20,代码来源:GroovyRuleEngine.java

示例12: parseClass

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
/**
 * 将groovy源码解析为Class
 */
public static Class parseClass(String groovySource) throws GroovyException {

    GroovyClassLoader loader = new GroovyClassLoader();

    ClassLoader contextClassLoader = null;

    try {
        contextClassLoader = Thread.currentThread().getContextClassLoader();
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(null);
        }
        return loader.parseClass(groovySource);
    } catch (Throwable t) {
        throw new GroovyException("parseClass error:", t);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
 
开发者ID:WenZuHuai,项目名称:light-task-scheduler,代码行数:24,代码来源:GroovyEngine.java

示例13: generateDefaultVariableValues

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
protected HashMap<String, Object> generateDefaultVariableValues() {
    HashMap<String, Object> result = new HashMap<>();
    try {
        Map<String, Variable> variableInstances = HybridbpmUI.getBpmAPI().createFirstVariables(processModel);
        for (String name : variableInstances.keySet()) {
            Variable vi = variableInstances.get(name);
            if (FieldModelUtil.isSimple(vi.getClassName())) {

            } else {
                GroovyClassLoader groovyClassLoader = HybridbpmUI.getDevelopmentAPI().getGroovyClassLoader();
                Class clazz = groovyClassLoader.loadClass(vi.getClassName());
                Object object = clazz.newInstance();
                System.out.println("object = " + object);
                result.put(name, object);
            }
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return result;
}
 
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:22,代码来源:TaskForm.java

示例14: main

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "resource" })
public static void main(String[] args) throws InstantiationException, IllegalAccessException {
	
	String classCode = ""+
			"import java.util.Map; "+
			"class GroovyServiceImpl2 implements IGroovyService{"+
			"	@Override"+
			"	public Object execute(Map<String, Object> param) {"+
			"		return 1656565;"+
			"	}"+
			"}"+
			";";
	
	GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
	Class<IGroovyService> clazz = groovyClassLoader.parseClass(classCode);
	IGroovyService service = clazz.newInstance();
	System.out.println(service.execute(null));
	
}
 
开发者ID:xuxueli,项目名称:xxl-glue,代码行数:20,代码来源:TestGroovy.java

示例15: makeCompileUnit

import groovy.lang.GroovyClassLoader; //导入依赖的package包/类
protected CompilationUnit makeCompileUnit(GroovyClassLoader loader) {
    Map<String, Object> options = configuration.getJointCompilationOptions();
    if (options != null) {
        if (keepStubs) {
            options.put("keepStubs", Boolean.TRUE);
        }
        if (stubDir != null) {
            options.put("stubDir", stubDir);
        } else {
            try {
                File tempStubDir = DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
                temporaryFiles.add(tempStubDir);
                options.put("stubDir", tempStubDir);
            } catch (IOException ioe) {
                throw new BuildException(ioe);
            }
        }
        return new JavaAwareCompilationUnit(configuration, loader);
    } else {
        return new CompilationUnit(configuration, null, loader);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:Groovyc.java


注:本文中的groovy.lang.GroovyClassLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。