public static Launcher getSpoonModelOf(String pathToSources, String pathToDependencies) { Launcher launcher = new Launcher(); launcher.getEnvironment().setNoClasspath(true); launcher.getEnvironment().setCommentEnabled(true); launcher.getEnvironment().setOutputType(OutputType.CLASSES); DSpotUtils.copyPackageFromResources(); String[] sourcesArray = (pathToSources + PATH_SEPARATOR + DSpotUtils.getAbsolutePathToDSpotDependencies()).split(PATH_SEPARATOR); Arrays.stream(sourcesArray).forEach(launcher::addInputResource); if (!pathToDependencies.isEmpty()) { String[] dependenciesArray = pathToDependencies.split(PATH_SEPARATOR); launcher.getModelBuilder().setSourceClasspath(dependenciesArray); } launcher.buildModel(); return launcher; }
spoon.getModelBuilder().setSourceClasspath(classpath(dependencies).split(File.pathSeparatorChar + "")); spoon.buildModel();
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); }
/** * Compile the original code * * @param properties */ protected void compileProject(ProjectConfiguration properties) { final Launcher launcher = new Launcher(); for (String path_src : properties.getOriginalDirSrc()) { log.debug("Add folder to compile: " + path_src); launcher.addInputResource(path_src); } for (String path_test : properties.getTestDirSrc()) { log.debug("Add folder to compile: " + path_test); launcher.addInputResource(path_test); } String binoutput = properties.getWorkingDirForBytecode() + File.separator + (ProgramVariant.DEFAULT_ORIGINAL_VARIANT); launcher.setBinaryOutputDirectory(binoutput); log.info("Compiling original code from " + launcher.getModelBuilder().getInputSources() + "\n bytecode saved in " + launcher.getModelBuilder().getBinaryOutputDirectory()); launcher.getEnvironment() .setPreserveLineNumbers(ConfigurationProperties.getPropertyBool("preservelinenumbers")); launcher.getEnvironment().setComplianceLevel(ConfigurationProperties.getPropertyInt("javacompliancelevel")); launcher.getEnvironment().setShouldCompile(true); launcher.getEnvironment().setSourceClasspath(properties.getDependenciesString().split(File.pathSeparator)); launcher.buildModel(); launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.COMPILATION_UNITS); launcher.getModelBuilder().compile(InputType.FILES); // launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.CLASSES); }