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


Java GroovyCodeSource类代码示例

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


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

示例1: test

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void test() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/actions.groovy"))).load(network);

    assertEquals(2, actionDb.getContingencies().size());
    Contingency contingency = actionDb.getContingency("contingency1");
    ContingencyElement element = contingency.getElements().iterator().next();
    assertEquals("NHV1_NHV2_1", element.getId());

    contingency = actionDb.getContingency("contingency2");
    element = contingency.getElements().iterator().next();
    assertEquals("GEN", element.getId());

    assertEquals(1, actionDb.getRules().size());
    Rule rule = actionDb.getRules().iterator().next();
    assertEquals("rule", rule.getId());
    assertEquals("rule description", rule.getDescription());
    assertTrue(rule.getActions().contains("action"));
    assertEquals(2, rule.getLife());

    Action action = actionDb.getAction("action");
    assertEquals("action", action.getId());
    assertEquals("action description", action.getDescription());
    assertEquals(0, action.getTasks().size());
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:26,代码来源:ActionDslLoaderTest.java

示例2: setUp

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    network = createNetwork();
    ComputationManager computationManager = Mockito.mock(ComputationManager.class);
    LoadFlow loadFlow = Mockito.mock(LoadFlow.class);
    LoadFlowFactory loadFlowFactory = Mockito.mock(LoadFlowFactory.class);
    Mockito.when(loadFlowFactory.create(Mockito.any(Network.class), Mockito.any(ComputationManager.class), Mockito.anyInt()))
            .thenReturn(loadFlow);
    LoadFlowResult loadFlowResult = Mockito.mock(LoadFlowResult.class);
    Mockito.when(loadFlowResult.isOk())
            .thenReturn(true);
    Mockito.when(loadFlow.getName()).thenReturn("load flow mock");
    Mockito.when(loadFlow.run())
            .thenReturn(loadFlowResult);
    LoadFlowActionSimulatorObserver observer = createObserver();
    GroovyCodeSource src = new GroovyCodeSource(new InputStreamReader(getClass().getResourceAsStream(getDslFile())), "test", GroovyShell.DEFAULT_CODE_BASE);
    actionDb = new ActionDslLoader(src).load(network);
    engine = new LoadFlowActionSimulator(network, computationManager, new LoadFlowActionSimulatorConfig(LoadFlowFactory.class, 3, false), observer) {
        @Override
        protected LoadFlowFactory newLoadFlowFactory() {
            return loadFlowFactory;
        }
    };
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:25,代码来源:AbstractLoadFlowRulesEngineTest.java

示例3: run

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
/**
 * Standalone execution for Designer and Gradle.
 */
public void run() {
    startExecution();

    CompilerConfiguration compilerConfig = new CompilerConfiguration(System.getProperties());
    compilerConfig.setScriptBaseClass(TestCaseScript.class.getName());
    Binding binding = new Binding();
    binding.setVariable("testCaseRun", this);

    ClassLoader classLoader = this.getClass().getClassLoader();
    GroovyShell shell = new GroovyShell(classLoader, binding, compilerConfig);
    shell.setProperty("out", getLog());
    setupContextClassLoader(shell);
    try {
        shell.run(new GroovyCodeSource(getTestCase().file()), new String[0]);
        finishExecution(null);
    }
    catch (IOException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:24,代码来源:StandaloneTestCaseRun.java

示例4: prepareGroovyCodeSource

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Override
protected GroovyCodeSource prepareGroovyCodeSource(String dsl) {
    ScriptApproval.get()
            .configuring(
                    dsl,
                    GroovyLanguage.get(),
                    ApprovalContext.create().
                            withCurrentUser()
                            .withItem(source)
            );
    try {
        ScriptApproval.get().using(dsl, GroovyLanguage.get());
    } catch (RejectedAccessException e) {
        throw ScriptApproval.get().accessRejected(e, ApprovalContext.create().withItem(source));
    }
    return super.prepareGroovyCodeSource(dsl);
}
 
开发者ID:jenkinsci,项目名称:ontrack-plugin,代码行数:18,代码来源:ApprovalBasedDSLLauncher.java

示例5: run

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Override
public Object run(String dsl, Binding binding) {
    CompilerConfiguration compilerConfiguration = prepareCompilerConfiguration();
    ClassLoader classLoader = prepareClassLoader(AbstractDSLLauncher.class.getClassLoader());
    GroovyCodeSource groovyCodeSource = prepareGroovyCodeSource(dsl);

    // Groovy shell
    GroovyShell shell = new GroovyShell(
            classLoader,
            new Binding(),
            compilerConfiguration
    );

    // Groovy script
    Script groovyScript = shell.parse(groovyCodeSource);

    // Binding
    groovyScript.setBinding(binding);

    // Runs the script
    return run(groovyScript);
}
 
开发者ID:jenkinsci,项目名称:ontrack-plugin,代码行数:23,代码来源:AbstractDSLLauncher.java

示例6: doParseClass

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
private Class<?> doParseClass(GroovyCodeSource codeSource) {
    // local is kept as hard reference to avoid garbage collection
    ThreadLocal<LocalData> localTh = getLocalData();
    LocalData localData = new LocalData();
    localTh.set(localData);
    StringSetMap cache = localData.dependencyCache;
    Class<?> answer = null;
    try {
        updateLocalDependencyCache(codeSource, localData);
        answer = super.parseClass(codeSource, false);
        updateScriptCache(localData);
    } finally {
        cache.clear();
        localTh.remove();
    }
    return answer;
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:GroovyScriptEngine.java

示例7: updateLocalDependencyCache

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
private void updateLocalDependencyCache(GroovyCodeSource codeSource, LocalData localData) {
    // we put the old dependencies into local cache so createCompilationUnit
    // can pick it up. We put that entry under the name "."
    ScriptCacheEntry origEntry = scriptCache.get(codeSource.getName());
    Set<String> origDep = null;
    if (origEntry != null) origDep = origEntry.dependencies;
    if (origDep != null) {
        Set<String> newDep = new HashSet<String>(origDep.size());
        for (String depName : origDep) {
            ScriptCacheEntry dep = scriptCache.get(depName);
            try {
                if (origEntry == dep || GroovyScriptEngine.this.isSourceNewer(dep)) {
                    newDep.add(depName);
                }
            } catch (ResourceException re) {

            }
        }
        StringSetMap cache = localData.dependencyCache;
        cache.put(".", newDep);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:GroovyScriptEngine.java

示例8: assertExecute

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
protected void assertExecute(final String scriptStr, String codeBase, final Permission missingPermission) {
    if (!isSecurityAvailable()) {
        return;
    }
    final String effectiveCodeBase = (codeBase != null) ? codeBase : "/groovy/security/test";
    // Use our privileged access in order to prevent checks lower in the call stack.  Otherwise we would have
    // to grant access to IDE unit test runners and unit test libs.  We only care about testing the call stack
    // higher upstream from this point of execution.
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
        @Override
        public Void run() {
            parseAndExecute(new GroovyCodeSource(scriptStr, generateClassName(), effectiveCodeBase), missingPermission);
            return null;
        }
    });
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:SecurityTestSupport.java

示例9: parseScript

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
/**
 * Parses a script
 * @param clazzName
    * @param sourceCode
 * @return
 */
public String parseScript(String clazzName, String sourceCode) {
	String compilationError = null;
	int lastIndexOf = clazzName.lastIndexOf(".");
	String codeBase = clazzName;
	if (lastIndexOf!=-1) {
		codeBase = clazzName.substring(0, lastIndexOf);
	}
	GroovyCodeSource groovyCodeSource = new GroovyCodeSource(
			sourceCode, clazzName, codeBase);
	try {
		Class<?> parsedClass = groovyClassLoader.parseClass(groovyCodeSource, false);
		availableClasses.put(clazzName, parsedClass);
	} catch (CompilationFailedException e) {
		compilationError = "Compilation for " + clazzName + " failed with " + e.getMessage();
		LOGGER.warn(compilationError);
	} catch (Exception ex) {
		compilationError = "Parsing class " + clazzName + " failed with " + ex.getMessage();
		LOGGER.warn(compilationError);
	}
	return compilationError;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:28,代码来源:GroovyScriptLoader.java

示例10: compileScript

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Class<Script> compileScript(final String scriptBaseClass, String scriptSource, final String scriptName) {
    final String script = preProcessScript(scriptSource);

    GroovyCodeSource codeSource = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>)
            () -> new GroovyCodeSource(script, scriptName, getScriptCodeBase()));

    String currentScriptBaseClass = compilerConfiguration.getScriptBaseClass();
    try {
        if (scriptBaseClass != null) {
            compilerConfiguration.setScriptBaseClass(scriptBaseClass);
        }
        return groovyClassLoader.parseClass(codeSource, false);
    }
    finally {
        compilerConfiguration.setScriptBaseClass(currentScriptBaseClass);
    }
}
 
开发者ID:apache,项目名称:commons-scxml,代码行数:19,代码来源:GroovyExtendableScriptCache.java

示例11: start

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Override
public void start() {
	try {
		String t_pathname = ContextUtils.getGroovyClasspath().getPath() + "/DailyWeekJob.groovy";
		File file = new File(t_pathname);

		Class groovyClass = ContextUtils.getClassLoader().loadClass("DailyWeekJob", true, false, true);
		if (null == groovyClass) {
			groovyClass = ContextUtils.getGroovyScriptEngine().loadScriptByName("DailyWeekJob.groovy");
		}
		if (null == groovyClass) {

			groovyClass = ContextUtils.getClassLoader().parseClass(new GroovyCodeSource(file));
		}
		//
		GroovyObject object = (GroovyObject) groovyClass.newInstance();

		object.invokeMethod("schedule", "daily.mail");
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	status = ModuleStatus.STARTED;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:24,代码来源:DailyModule.java

示例12: getContingencies

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Override
public List<Contingency> getContingencies(Network network) {
    try (Reader reader = Files.newBufferedReader(dslFile, StandardCharsets.UTF_8)) {
        ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(reader, "script", GroovyShell.DEFAULT_CODE_BASE))
                .load(network);
        return ImmutableList.copyOf(actionDb.getContingencies());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:11,代码来源:GroovyDslContingenciesProvider.java

示例13: testGeneratorScalableStack

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testGeneratorScalableStack() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/scalable.groovy"))).load(network);
    Action action = actionDb.getAction("actionScale"); // scale to 15000
    assertEquals(607.0f, g1.getTargetP(), 0.0f);
    assertEquals(9999.99f, g1.getMaxP(), 0.0f);
    action.run(network, null);
    assertEquals(9999.99f, g1.getTargetP(), 0.0f);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:10,代码来源:ScalableActionTest.java

示例14: testCompatible

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testCompatible() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/scalable.groovy"))).load(network);
    Action action = actionDb.getAction("testCompatible"); // scale to 15000
    assertEquals(607.0f, g1.getTargetP(), 0.0f);
    assertEquals(9999.99f, g1.getMaxP(), 0.0f);
    action.run(network, null);
    assertEquals(9999.99f, g1.getTargetP(), 0.0f);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:10,代码来源:ScalableActionTest.java

示例15: testGeneratorScalableProportional

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testGeneratorScalableProportional() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/scalable.groovy"))).load(network);
    Action action = actionDb.getAction("testProportional"); // scale to 15000
    assertEquals(607.0f, g1.getTargetP(), 0.0f);
    assertEquals(9999.99f, g1.getMaxP(), 0.0f);
    action.run(network, null);
    assertEquals(7500.0f, g1.getTargetP(), 0.0f);
    assertEquals(3000.0f, g2.getTargetP(), 0.0f);
    assertEquals(4500.0f, g3.getTargetP(), 0.0f);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:12,代码来源:ScalableActionTest.java


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