• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GroovyCodeSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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


示例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


示例16: testDslExtension

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testDslExtension() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/actions2.groovy"))).load(network);
    Action another = actionDb.getAction("anotherAction");
    exception.expect(RuntimeException.class);
    exception.expectMessage("Switch 'switchId' not found");
    another.run(network, null);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:9,代码来源:ActionDslLoaderTest.java


示例17: testFixTapDslExtension

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testFixTapDslExtension() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/actions2.groovy"))).load(network);
    Action fixedTapAction = actionDb.getAction("fixedTap");
    assertNotNull(fixedTapAction);
    addPhaseShifter();
    PhaseTapChanger phaseTapChanger = network.getTwoWindingsTransformer("NGEN_NHV1").getPhaseTapChanger();
    assertEquals(0, phaseTapChanger.getTapPosition());
    assertTrue(phaseTapChanger.isRegulating());
    assertEquals(PhaseTapChanger.RegulationMode.CURRENT_LIMITER, phaseTapChanger.getRegulationMode());
    fixedTapAction.run(network, null);
    assertEquals(1, phaseTapChanger.getTapPosition());
    assertEquals(PhaseTapChanger.RegulationMode.FIXED_TAP, phaseTapChanger.getRegulationMode());
    assertFalse(phaseTapChanger.isRegulating());
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:16,代码来源:ActionDslLoaderTest.java


示例18: testUnvalidate

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testUnvalidate() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/actions2.groovy"))).load(network);
    Action someAction = actionDb.getAction("someAction");
    exception.expect(ActionDslException.class);
    exception.expectMessage("Dsl extension task(closeSwitch) is forbidden in task script");
    someAction.run(network, null);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:9,代码来源:ActionDslLoaderTest.java


示例19: testUnKnownMethodInScript

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Test
public void testUnKnownMethodInScript() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/actions2.groovy"))).load(network);
    Action someAction = actionDb.getAction("missingMethod");
    exception.expect(MissingMethodException.class);
    someAction.run(network, null);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:8,代码来源:ActionDslLoaderTest.java


示例20: validate

import groovy.lang.GroovyCodeSource; //导入依赖的package包/类
@Override
public void validate(IValidatable<String> validatable) {
    String script = validatable.getValue();
    com.angkorteam.mbaas.server.bean.GroovyClassLoader classLoader = Spring.getBean(com.angkorteam.mbaas.server.bean.GroovyClassLoader.class);
    String sourceId = System.currentTimeMillis() + "";
    String className = null;
    if (!Strings.isNullOrEmpty(script)) {
        GroovyCodeSource source = new GroovyCodeSource(script, sourceId, "/groovy/script");
        source.setCachable(false);
        Class<?> groovyClass = null;
        try {
            groovyClass = classLoader.parseClass(source, false);
            className = groovyClass.getName();
        } catch (CompilationFailedException e) {
            validatable.error(new ValidationError(this, "error").setVariable("reason", e.getMessage()));
            return;
        }
        if (!groovyClass.getName().startsWith("com.angkorteam.mbaas.server.groovy.")) {
            validatable.error(new ValidationError(this, "invalid").setVariable("object", groovyClass.getName()));
            return;
        }
        int count = 0;
        DSLContext context = Spring.getBean(DSLContext.class);
        GroovyTable table = Tables.GROOVY.as("table");
        if (Strings.isNullOrEmpty(this.documentId)) {
            count = context.selectCount().from(table).where(table.JAVA_CLASS.eq(groovyClass.getName())).fetchOneInto(int.class);
        } else {
            count = context.selectCount().from(table).where(table.JAVA_CLASS.eq(groovyClass.getName())).and(table.GROOVY_ID.notEqual(this.documentId)).fetchOneInto(int.class);
        }
        if (count > 0) {
            validatable.error(new ValidationError(this, "duplicated").setVariable("object", groovyClass.getName()));
        }
    }
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:35,代码来源:GroovyScriptValidator.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Column类代码示例发布时间:2022-05-21
下一篇:
Java ClassSigType类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap