當前位置: 首頁>>代碼示例>>Java>>正文


Java CompilerConfiguration.setClasspath方法代碼示例

本文整理匯總了Java中org.codehaus.groovy.control.CompilerConfiguration.setClasspath方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilerConfiguration.setClasspath方法的具體用法?Java CompilerConfiguration.setClasspath怎麽用?Java CompilerConfiguration.setClasspath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.groovy.control.CompilerConfiguration的用法示例。


在下文中一共展示了CompilerConfiguration.setClasspath方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadByPath

import org.codehaus.groovy.control.CompilerConfiguration; //導入方法依賴的package包/類
@Override
public void loadByPath(Path path) throws Throwable {
	String id;
	if (Files.isDirectory(path)) {
		id = path.getFileName().toString();
		path = path.resolve("plugin.groovy");
	} else {
		if(path.getFileName().toString().equals("plugin.groovy"))
			id = path.getParent().getFileName().toString();
		else {
			id = path.getFileName().toString();
			id = id.substring(0, id.length() - 7);
		}
	}
	System.setProperty("groovy.grape.report.downloads", "true");
	CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
	compilerConfiguration.setSourceEncoding("UTF-8");
	compilerConfiguration.setScriptBaseClass("info.deskchan.groovy_support.GroovyPlugin");
	compilerConfiguration.setClasspath(path.getParent().toString());
	GroovyShell groovyShell = new GroovyShell(compilerConfiguration);
	Script script = groovyShell.parse(path.toFile());
	GroovyPlugin plugin = (GroovyPlugin) script;
	plugin.setPluginDirPath(path.getParent());
	PluginConfig config = new PluginConfig("Groovy");
	path = path.getParent().resolve("manifest.json");
	config.appendFromJson(path);
	PluginManager.getInstance().initializePlugin(id, plugin, config);
}
 
開發者ID:DeskChan,項目名稱:DeskChan,代碼行數:29,代碼來源:Main.java

示例2: getGroovyClassLoader

import org.codehaus.groovy.control.CompilerConfiguration; //導入方法依賴的package包/類
protected CubaGroovyClassLoader getGroovyClassLoader() {
    if (gcl == null) {
        synchronized (this) {
            if (gcl == null) {
                CompilerConfiguration cc = new CompilerConfiguration();
                cc.setClasspath(groovyClassPath);
                cc.setRecompileGroovySource(true);
                gcl = new CubaGroovyClassLoader(cc);
            }
        }
    }
    return gcl;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:14,代碼來源:AbstractScripting.java

示例3: newEvaluator

import org.codehaus.groovy.control.CompilerConfiguration; //導入方法依賴的package包/類
protected GroovyClassLoader newEvaluator() throws MalformedURLException {

    try {
      Class.forName("org.codehaus.groovy.control.customizers.ImportCustomizer");
    } catch (ClassNotFoundException e1) {
      String gjp = System.getenv(GROOVY_JAR_PATH);
      String errorMsg = null;
      if (gjp != null && !gjp.isEmpty()) {
        errorMsg = "Groovy libary not found, GROOVY_JAR_PATH = " + gjp;
      } else {
        errorMsg = "Default groovy libary not found. No GROOVY_JAR_PATH variable set.";
      }
      throw new GroovyNotFoundException(errorMsg);
    }

    ImportCustomizer icz = new ImportCustomizer();

    if (!imports.isEmpty()) {
      for (String importLine : imports) {
        if (importLine.startsWith(STATIC_WORD_WITH_SPACE)) {

          String pureImport = importLine
                  .replace(STATIC_WORD_WITH_SPACE, StringUtils.EMPTY)
                  .replace(DOT_STAR_POSTFIX, StringUtils.EMPTY);

          if (importLine.endsWith(DOT_STAR_POSTFIX)) {
            icz.addStaticStars(pureImport);
          } else {
            int index = pureImport.lastIndexOf('.');
            if (index == -1) {
              continue;
            }
            icz.addStaticImport(pureImport.substring(0, index), pureImport.substring(index + 1));
          }

        } else {

          if (importLine.endsWith(DOT_STAR_POSTFIX)) {
            icz.addStarImports(importLine.replace(DOT_STAR_POSTFIX, StringUtils.EMPTY));
          } else {
            icz.addImports(importLine);
          }

        }
      }
    }
    CompilerConfiguration config = new CompilerConfiguration().addCompilationCustomizers(icz);

    String acloader_cp = "";
    for (int i = 0; i < classPath.size(); i++) {
      acloader_cp += classPath.get(i);
      acloader_cp += File.pathSeparatorChar;
    }
    acloader_cp += outDir;

    config.setClasspath(acloader_cp);

    compilerConfiguration = config;

    scriptBinding = new Binding();
    return new GroovyClassLoader(newClassLoader(), compilerConfiguration);
  }
 
開發者ID:twosigma,項目名稱:beaker-notebook-archive,代碼行數:63,代碼來源:GroovyEvaluator.java

示例4: createScenario

import org.codehaus.groovy.control.CompilerConfiguration; //導入方法依賴的package包/類
public static Scenario createScenario(String pathString){
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    compilerConfiguration.setSourceEncoding("UTF-8");
    compilerConfiguration.setScriptBaseClass("info.deskchan.groovy_support.Scenario");
    Path path = Paths.get(pathString);
    compilerConfiguration.setClasspath(path.getParent().toString());
    GroovyShell groovyShell = new GroovyShell(compilerConfiguration);
    List<String> scriptLines = null;
    try {
        scriptLines = Files.readAllLines(path, Charset.forName("UTF-8"));
    } catch (Exception e){
        pluginProxy.log("Invalid path specified for scenario");
        return null;
    }
    StringBuilder scriptText = new StringBuilder();
    String[] buffers = new String[1];
    for(int u=0; u<buffers.length; u++) buffers[u] = null;
    for(int i = 0; i<scriptLines.size(); i++){
        String line = scriptLines.get(i).trim();
        switch (line.charAt(0)){
            case '<':
                scriptLines.set(i, line.substring(1).trim()+" = receive()");
                break;
            case '>':
                scriptLines.set(i, "say('"+line.substring(1).trim()+"')");
                break;
            case '$':{
                List<String> matches = new ArrayList<String>();
                Matcher m = Pattern.compile("([\"'])(?:(?=(\\\\?))\\2.)*?\\1|[^\\s]+").matcher(line.substring(1));
                while (m.find() && matches.size()<4) {
                    matches.add(m.group());
                }
                if(matches.size()==0){
                    scriptLines.remove(i);
                    i--;
                    continue;
                }
                StringBuilder sb = new StringBuilder("sendMessage(");
                for(int u=0; u<matches.size(); u++) {
                    String arg = matches.get(u);
                    if(arg.charAt(0)!='"' && arg.charAt(0)!='\''){
                        if(u>0) sb.append(arg.replace("\"","\\\""));
                        else sb.append('"'+arg.replace("\"","\\\"")+'"');
                    }

                    else sb.append(arg);
                    sb.append(',');
                }
                sb.deleteCharAt(sb.length()-1);
                sb.append(')');
                scriptLines.set(i, sb.toString());
            } break;
        }
        scriptText.append(scriptLines.get(i));
        scriptText.append("\n");
    }
    Script script = groovyShell.parse(scriptText.toString());
    return (Scenario) script;
}
 
開發者ID:DeskChan,項目名稱:DeskChan,代碼行數:60,代碼來源:ScenarioPlugin.java

示例5: generateCompilerConfigurationFromOptions

import org.codehaus.groovy.control.CompilerConfiguration; //導入方法依賴的package包/類
public static CompilerConfiguration generateCompilerConfigurationFromOptions(CommandLine cli) throws IOException {
    // Setup the configuration data
    CompilerConfiguration configuration = new CompilerConfiguration();

    if (cli.hasOption("classpath")) {
        configuration.setClasspath(cli.getOptionValue("classpath"));
    }

    if (cli.hasOption('d')) {
        configuration.setTargetDirectory(cli.getOptionValue('d'));
    }

    configuration.setParameters(cli.hasOption("pa"));

    if (cli.hasOption("encoding")) {
        configuration.setSourceEncoding(cli.getOptionValue("encoding"));
    }

    if (cli.hasOption("basescript")) {
        configuration.setScriptBaseClass(cli.getOptionValue("basescript"));
    }

    // joint compilation parameters
    if (cli.hasOption('j')) {
        Map<String, Object> compilerOptions = new HashMap<String, Object>();

        String[] namedValues = cli.getOptionValues("J");
        compilerOptions.put("namedValues", namedValues);

        String[] flags = cli.getOptionValues("F");
        if (flags != null && cli.hasOption("pa")){
            flags = Arrays.copyOf(flags, flags.length + 1);
            flags[flags.length - 1] = "parameters";
        }
        compilerOptions.put("flags", flags);

        configuration.setJointCompilationOptions(compilerOptions);
    }

    if (cli.hasOption("indy")) {
        configuration.getOptimizationOptions().put("int", false);
        configuration.getOptimizationOptions().put("indy", true);
    }

    String configScripts = System.getProperty("groovy.starter.configscripts", null);
    if (cli.hasOption("configscript") || (configScripts != null && !configScripts.isEmpty())) {
        List<String> scripts = new ArrayList<String>();
        if (cli.hasOption("configscript")) {
            scripts.add(cli.getOptionValue("configscript"));
        }
        if (configScripts != null) {
            scripts.addAll(StringGroovyMethods.tokenize((CharSequence) configScripts, ','));
        }
        processConfigScripts(scripts, configuration);
    }

    return configuration;
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:59,代碼來源:FileSystemCompiler.java


注:本文中的org.codehaus.groovy.control.CompilerConfiguration.setClasspath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。