public EmbeddedLauncher(final Logger logger, final ScriptFactory factory) throws ScriptException { this.logger = logger; this.factory = factory; if (factory.classRealm != null) { this.classRealm = cloneClassRealm(factory.jrubyJar, factory.classpathElements, factory.classRealm); } else { this.classRealm = null; } }
public void executeScript(final File launchDirectory, final String script, final List<String> args, final File outputFile) throws ScriptException, IOException { final StringBuilder buf = new StringBuilder(); for (final Map.Entry<String, String> entry : this.factory.environment().entrySet()) { if (entry.getValue() != null) { buf.append("ENV['") .append(entry.getKey()) .append("']='") .append(entry.getValue()) .append("';"); } } buf.append(script); args.add(0, "-e"); args.add(1, buf.toString()); args.add(2, "--"); doExecute(launchDirectory, outputFile, args, false); } }
public ScriptFactory(final Logger logger, final ClassRealm classRealm, final File jrubyJar, File stdlibJar, final List<String> classpathElements, final boolean fork) throws ScriptException, IOException { this.logger = logger; this.jrubyStdlibJar = stdlibJar; this.jrubyJar = jrubyJar; if(this.jrubyJar != null){ this.logger.debug("script uses jruby jar:" + this.jrubyJar.getAbsolutePath()); } this.classpathElements = classpathElements == null ? NO_CLASSPATH : Collections.unmodifiableList(classpathElements); this.fork = fork; if (classRealm != null && jrubyJar != null) { this.classRealm = getOrCreateClassRealm(classRealm, jrubyJar); } else { this.classRealm = classRealm; } if (fork) { this.launcher = new AntLauncher(logger, this); } else { this.launcher = new EmbeddedLauncher(logger, this); } }
private void doExecute(final File launchDirectory, final File outputFile, final List<String> args, final boolean warn) throws ScriptException, IOException { final String currentDir; if (launchDirectory != null) { currentDir = System.getProperty("user.dir"); logger.debug("launch directory: " + launchDirectory.getAbsolutePath()); System.setProperty("user.dir", launchDirectory.getAbsolutePath()); } else { currentDir = null; } args.addAll(0, this.factory.switches.list); if (warn) { if (this.factory.jvmArgs.list.size() > 0) { this.logger.warn("have to ignore jvm arguments and properties in the current setup"); } if (this.factory.environment().size() > 0) { this.logger.warn("have to ignore environment settings in the current setup"); } } final PrintStream output = System.out; ClassLoader current = null; try { if (outputFile != null) { final PrintStream writer = new PrintStream(outputFile);