use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class KieDefaultMavenCompilerTest method buildCompileWithOverrideOnGitVFS.
@Test
public void buildCompileWithOverrideOnGitVFS() throws Exception {
final String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
final URI originRepo = URI.create("git://buildCompileWithOverrideOnGitVFS");
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);
// git://buildCompileWithOverrideOnGitVFS/dummy/pom.xml
ioService.write(// git://buildCompileWithOverrideOnGitVFS/dummy/pom.xml
origin.getPath("master", "/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_override/pom.xml").toPath())));
// git://buildCompileWithOverrideOnGitVFS/dummy/src/main/java/dummy/Dummy.java
ioService.write(// git://buildCompileWithOverrideOnGitVFS/dummy/src/main/java/dummy/Dummy.java
origin.getPath("master", "/src/main/java/dummy/Dummy.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy/src/main/java/dummy/Dummy.java").toPath())));
ioService.endBatch();
byte[] encoded = ioService.readAllBytes(origin.getPath("master", "/src/main/java/dummy/Dummy.java"));
String dummyAsAstring = new String(encoded, StandardCharsets.UTF_8);
assertThat(dummyAsAstring).doesNotContain("public Dummy(Integer age) {\n" + " this.age = age;\n" + " }");
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD, KieDecorator.ENABLE_LOGGING));
// git://buildCompileWithOverrideOnGitVFS/dummy/
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(origin.getPath("master", "/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.TRUE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(res.getWorkingDir().get(), res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
// /file:///User/temp8998876986179/dummy//target/classes/dummy/DummyOverride.class
assertThat(new File(res.getWorkingDir().get() + "/target/classes/dummy/DummyOverride.class")).doesNotExist();
// change some files
Map<org.uberfire.java.nio.file.Path, InputStream> override = new HashMap<>();
org.uberfire.java.nio.file.Path path = origin.getPath("master", "/src/main/java/dummy/DummyOverride.java");
InputStream input = new FileInputStream(new File("target/test-classes/dummy_override/src/main/java/dummy/DummyOverride.java"));
override.put(path, input);
org.uberfire.java.nio.file.Path pathTwo = origin.getPath("master", "/src/main/java/dummy/Dummy.java");
InputStream inputTwo = new FileInputStream(new File("target/test-classes/dummy_override/src/main/java/dummy/Dummy.java"));
override.put(pathTwo, inputTwo);
// recompile
res = compiler.compile(req, override);
assertThat(res.isSuccessful()).isTrue();
assertThat(new File(res.getWorkingDir().get() + "/target/classes/dummy/Dummy.class")).doesNotExist();
assertThat(new File(res.getWorkingDir().get() + "/target/classes/dummy/DummyOverride.class")).exists();
encoded = Files.readAllBytes(Paths.get(res.getWorkingDir().get().toString(), "/src/main/java/dummy/Dummy.java"));
dummyAsAstring = new String(encoded, StandardCharsets.UTF_8);
assertThat(dummyAsAstring).contains("public Dummy(String name) {\n" + " this.name = name;\n" + " }");
compiler.cleanInternalCache();
TestUtil.rm(origin.getGit().getRepository().getDirectory());
}
use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class KieDefaultMavenCompilerTest method buildWithAllDecoratorsTest.
@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void buildWithAllDecoratorsTest() throws Exception {
String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
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();
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD, KieDecorator.ENABLE_LOGGING));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmpCloned + "/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, 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.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class DefaultMavenIncrementalCompilerTest method testCheckIncrementalWithChanges.
@Test
public void testCheckIncrementalWithChanges() throws Exception {
Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_INCREMENTAL_DIR);
// compiler
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
// checks
assertThat(res.isSuccessful()).isTrue();
List<String> fileNames = new ArrayList<>();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
for (Path path : directoryStream) {
fileNames.add(path.toString());
}
}
assertThat(fileNames).hasSize(2);
String dummyJava;
if (fileNames.get(0).endsWith("Dummy.class")) {
dummyJava = fileNames.get(0);
} else {
dummyJava = fileNames.get(1);
}
long dummyJavaSize = Paths.get(dummyJava).toFile().length();
List<String> output = res.getMavenOutput();
assertThat(isTextPresent(output, "Previous incremental build state does not exist, performing full build")).isTrue();
assertThat(isTextPresent(output, "Previous incremental build state does not exist, performing full build")).isTrue();
assertThat(isTextPresent(output, "Compiled 2 out of 2 sources ")).isTrue();
Files.delete(Paths.get(temp + "/src/main/java/dummy/DummyA.java"));
// overwrite the class with a new version with two additional methods and one int variable
Files.write(Paths.get(temp + "/src/main/java/dummy/Dummy.java"), Files.readAllBytes(Paths.get("src/test/projects/Dummy.java")));
// second compilation
res = compiler.compile(req);
// checks
assertThat(res.isSuccessful()).isTrue();
fileNames = new ArrayList<>();
// impl
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
for (Path path : directoryStream) {
fileNames.add(path.toString());
}
}
assertThat(fileNames).hasSize(1);
assertThat(fileNames.get(0)).endsWith("Dummy.class");
long dummyJavaSizeAfterChanges = Paths.get(dummyJava).toFile().length();
assertThat(dummyJavaSize).isLessThan(dummyJavaSizeAfterChanges);
output = res.getMavenOutput();
assertThat(isTextPresent(output, "Performing incremental build")).isTrue();
assertThat(isTextPresent(output, "Compiled 1 out of 1 sources ")).isTrue();
}
use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class DefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabled.
@Test
public void testIncrementalWithPluginEnabled() throws Exception {
Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_DIR);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
Path incrementalConfiguration = Paths.get(temp.toAbsolutePath().toString(), "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
assertThat(incrementalConfiguration.toFile()).exists();
}
use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class DefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabledThreeTime.
@Test
public void testIncrementalWithPluginEnabledThreeTime() throws Exception {
Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_DIR);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
CompilationResponse res = compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
res = compiler.compile(req);
assertThat(res.isSuccessful()).isTrue();
res = compiler.compile(req);
assertThat(res.isSuccessful()).isTrue();
Path incrementalConfiguration = Paths.get(temp.toAbsolutePath().toString(), "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
assertThat(incrementalConfiguration.toFile()).exists();
}
Aggregations