use of org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class DefaultMavenCompilerTest method buildWithJGitDecoratorTest.
@Test
public void buildWithJGitDecoratorTest() throws Exception {
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD));
String MAIN_BRANCH = "master";
// Setup origin in memory
final URI originRepo = URI.create("git://repo");
final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {
{
put("init", Boolean.TRUE);
put("internal", Boolean.TRUE);
put("listMode", "ALL");
}
});
assertThat(origin).isNotNull();
ioService.startBatch(origin);
ioService.write(origin.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
ioService.write(origin.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
ioService.write(origin.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
ioService.write(origin.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
ioService.write(origin.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
ioService.endBatch();
RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
assertThat(lastCommit).isNotNull();
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(origin.getPath("/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(origin.getPath("/"), res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
assertThat(lastCommit).isNotNull();
ioService.write(origin.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/DummyA.java").toPath())));
RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
assertThat(commitBefore).isNotNull();
assertThat(lastCommit.getId().toString()).isNotEqualTo(commitBefore.getId().toString());
// recompile
res = compiler.compile(req);
assertThat(res.isSuccessful()).isTrue();
}
use of org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class DefaultMavenCompilerTest method buildWithAllDecoratorsTest.
@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void buildWithAllDecoratorsTest() throws Exception {
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.UPDATE_JGIT_BEFORE_BUILD));
String MAIN_BRANCH = "master";
// Setup origin in memory
final URI originRepo = URI.create("git://repo");
final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {
{
put("init", Boolean.TRUE);
put("internal", Boolean.TRUE);
put("listMode", "ALL");
}
});
assertThat(origin).isNotNull();
ioService.startBatch(origin);
ioService.write(origin.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/pom.xml").toPath())));
ioService.write(origin.getPath("/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java").toPath())));
ioService.write(origin.getPath("/src/main/resources/AllResourceTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl").toPath())));
ioService.write(origin.getPath("/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml").toPath())));
ioService.endBatch();
RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
assertThat(lastCommit).isNotNull();
// clone into a regularfs
Path tmpRootCloned = Files.createTempDirectory("cloned");
Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone.git"));
final Git cloned = Git.cloneRepository().setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(tmpCloned.toFile()).call();
assertThat(cloned).isNotNull();
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmpCloned + "/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + TestUtilMaven.getSettingsFile() }, Boolean.TRUE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
assertThat(lastCommit).isNotNull();
// change one file and commit on the origin repo
ioService.write(origin.getPath("/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/Person.java").toPath())));
RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
assertThat(commitBefore).isNotNull();
assertThat(lastCommit.getId().toString()).isNotEqualTo(commitBefore.getId().toString());
// recompile
res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
TestUtil.rm(tmpRootCloned.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo 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.impl.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class BuildInMemoryClasspathMojoTest method getClassloaderFromAllDependenciesComplexTest.
@Test
public void getClassloaderFromAllDependenciesComplexTest() {
Path path = Paths.get(".").resolve("target/test-classes/dummy_deps_complex");
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(path);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath, MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH }, Boolean.FALSE);
CompilationResponse res = compiler.compile(req);
assertThat(res.isSuccessful()).isTrue();
assertThat(res.getDependencies()).isNotEmpty();
assertThat(res.getDependencies()).hasSize(7);
}
use of org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class BuildInMemoryClasspathMojoTest method getClassloaderFromAllDependenciesSimpleTest.
@Test
public void getClassloaderFromAllDependenciesSimpleTest() {
Path path = Paths.get(".").resolve("target/test-classes/dummy_deps_simple");
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(path);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath, MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH }, Boolean.FALSE);
CompilationResponse res = compiler.compile(req);
assertThat(res.isSuccessful()).isTrue();
assertThat(res.getDependencies()).isNotEmpty();
assertThat(res.getDependencies()).hasSize(4);
}
Aggregations