/** * Creates a new Spoon Java compiler in order to process and compile Java * source code. * * @param factory * the factory this compiler works on */ public SpoonModelBuilder createCompiler(Factory factory) { SpoonModelBuilder comp = new JDTBasedSpoonCompiler(factory); Environment env = getEnvironment(); // building comp.setBinaryOutputDirectory(jsapActualArgs.getFile("destination")); // backward compatibility // we don't have to set the source classpath if (jsapActualArgs.contains("source-classpath")) { comp.setSourceClasspath(jsapActualArgs.getString("source-classpath").split(System.getProperty("path.separator"))); } env.debugMessage("destination: " + comp.getBinaryOutputDirectory()); env.debugMessage("source classpath: " + Arrays.toString(comp.getSourceClasspath())); env.debugMessage("template classpath: " + Arrays.toString(comp.getTemplateClasspath())); return comp; }
public static TestListener runTest(Configuration configuration, Launcher launcher, String failingTestClass, String failingTestMethod) { final SpoonModelBuilder compiler = launcher.createCompiler(); compiler.setBinaryOutputDirectory(new File(configuration.getBinaryOutputDirectory())); compiler.compile(SpoonModelBuilder.InputType.CTTYPES); try { return EntryPoint.runTests( configuration.getBinaryOutputDirectory() + Util.PATH_SEPARATOR + configuration.getClasspath(), failingTestClass, failingTestMethod ); } catch (TimeoutException e) { throw new RuntimeException(e); } }
addedMethod.add(clone); }); compiler.setBinaryOutputDirectory(new File(configuration.getBinaryOutputDirectory())); compiler.compile(SpoonModelBuilder.InputType.CTTYPES);
public static boolean compile(InputConfiguration configuration, String pathToSources, String dependencies, File binaryOutputDirectory) { Launcher launcher = new Launcher(); if (configuration.isVerbose()) { launcher.getEnvironment().setLevel("INFO"); } launcher.getEnvironment().setNoClasspath(true); launcher.getEnvironment().setCommentEnabled(true); launcher.getEnvironment().setOutputType(OutputType.CLASSES); DSpotUtils.copyPackageFromResources(); String[] sourcesArray = (pathToSources + PATH_SEPARATOR).split(PATH_SEPARATOR); Arrays.stream(sourcesArray).forEach(launcher::addInputResource); String[] dependenciesArray = dependencies.split(PATH_SEPARATOR); launcher.getModelBuilder().setSourceClasspath(dependenciesArray); launcher.buildModel(); SpoonModelBuilder modelBuilder = launcher.getModelBuilder(); modelBuilder.setBinaryOutputDirectory(binaryOutputDirectory); return modelBuilder.compile(SpoonModelBuilder.InputType.CTTYPES); }
compiler.setBinaryOutputDirectory(new File(configuration.getBinaryOutputDirectory())); compiler.compile(SpoonModelBuilder.InputType.CTTYPES);