use of org.kie.workbench.common.services.backend.compiler.AFCompiler in project kie-wb-common by kiegroup.
the class DefaultLocalExecutor method internalBuild.
private CompletableFuture<KieCompilationResponse> internalBuild(Path projectPath, String mavenRepoPath, String settingXML, boolean skipProjectDepCreation, String goal, Map<Path, InputStream> override) {
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(projectPath);
AFCompiler compiler = getCompiler(projectPath);
CompilationRequest req;
if (settingXML != null) {
req = getDefaultRequest(mavenRepoPath, info, skipProjectDepCreation, new String[] { MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingXML, goal });
} else {
req = getDefaultRequest(mavenRepoPath, info, skipProjectDepCreation, new String[] { goal });
}
return CompletableFuture.supplyAsync(() -> ((KieCompilationResponse) compiler.compile(req, override)), executor);
}
use of org.kie.workbench.common.services.backend.compiler.AFCompiler in project kie-wb-common by kiegroup.
the class DefaultRemoteExecutor method internalBuild.
private CompletableFuture<KieCompilationResponse> internalBuild(String projectPath, String mavenRepoPath, boolean skipProjectDepCreation, String[] args) {
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(projectPath));
AFCompiler compiler = getCompiler(projectPath);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, args, skipProjectDepCreation);
return runInItsOwnThread(compiler, req);
}
use of org.kie.workbench.common.services.backend.compiler.AFCompiler in project kie-wb-common by kiegroup.
the class DefaultRemoteExecutor method setupCompileInfo.
private CompilerAggregateEntryCache setupCompileInfo(String workingDir) {
AFCompiler compiler = new KieAfterDecorator(new OutputLogAfterDecorator(new ClasspathDepsAfterDecorator(new BaseMavenCompiler(true, true))));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(workingDir));
return new CompilerAggregateEntryCache(compiler, info);
}
use of org.kie.workbench.common.services.backend.compiler.AFCompiler in project kie-wb-common by kiegroup.
the class CompilerClassloaderUtils method getClassloaderFromAllDependencies.
/**
* It run a maven build-classpath in memory and return a classloader with only this deps
* @param prjPath
* @param localRepo
* @return
*/
public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) {
AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath)));
CompilationRequest req;
if (settingsXmlPath != null) {
req = new DefaultCompilationRequest(localRepo, info, new String[] { MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath }, Boolean.FALSE);
} else {
req = new DefaultCompilationRequest(localRepo, info, new String[] { MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH }, Boolean.FALSE);
}
CompilationResponse res = compiler.compile(req);
if (res.isSuccessful()) {
/**
* Maven dependency plugin is not able to append the modules classpath using an absolute path in -Dmdep.outputFile,
* it override each time and at the end only the last writted is present in the file,
* for this reason we use a relative path and then we read each file present in each module to build a unique classpath file
*/
if (!res.getDependencies().isEmpty()) {
Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies());
if (urlClassLoader.isPresent()) {
return urlClassLoader;
}
}
}
return Optional.empty();
}
use of org.kie.workbench.common.services.backend.compiler.AFCompiler in project kie-wb-common by kiegroup.
the class KieDefaultMavenCompilerTest method buildWithCloneTest.
@Test
public void buildWithCloneTest() throws Exception {
final String repoName = "myrepoxxxx";
final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), new HashMap<String, Object>() {
{
put("init", Boolean.TRUE);
put("internal", Boolean.TRUE);
}
});
ioService.startBatch(fs);
ioService.write(fs.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_multimodule_untouched/pom.xml").toPath())));
ioService.write(fs.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
ioService.write(fs.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
ioService.write(fs.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
ioService.write(fs.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
ioService.endBatch();
Path tmpCloned = Files.createTempDirectory("cloned");
final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");
final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call();
assertThat(cloned).isNotNull();
// Compile the repo
Path prjFolder = Paths.get(gitClonedFolder + "/");
byte[] encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
Path incrementalConfiguration = Paths.get(prjFolder + TestConstants.TARGET_TAKARI_PLUGIN);
assertThat(incrementalConfiguration.toFile()).exists();
encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
TestUtil.rm(tmpCloned.toFile());
}
Aggregations