use of org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class KieDefaultMavenCompilerTest method buildWithPullRebaseUberfireTest.
@Test
public void buildWithPullRebaseUberfireTest() throws Exception {
// 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");
}
});
ioService.startBatch(origin);
ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
ioService.write(origin.getPath("/dummy/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("/dummy/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("/dummy/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("/dummy/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
ioService.endBatch();
// clone into a regularfs
Path tmpRootCloned = Files.createTempDirectory("cloned");
Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));
final Git cloned = Git.cloneRepository().setURI("git://localhost:9418/repo").setBare(false).setDirectory(tmpCloned.toFile()).call();
assertNotNull(cloned);
PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
PullResult pullRes = pc.call();
// nothing changed yet
assertTrue(pullRes.getRebaseResult().getStatus().equals(RebaseResult.Status.UP_TO_DATE));
RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
RebaseResult rbResult = rb.setPreserveMerges(true).call();
assertTrue(rbResult.getStatus().isSuccessful());
// Compile the repo
AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.LOG_OUTPUT_AFTER);
byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/dummy/pom.xml"));
String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
Assert.assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
Path prjFolder = Paths.get(tmpCloned + "/dummy/");
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.TRUE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerTest.buildWithPullRebaseUberfireTest");
}
assertTrue(res.isSuccessful());
Path incrementalConfiguration = Paths.get(prjFolder + "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
assertTrue(incrementalConfiguration.toFile().exists());
encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
assertTrue(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
TestUtil.rm(tmpRootCloned.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class KieDefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabledThreeTime.
@Test
public void testIncrementalWithPluginEnabledThreeTime() throws Exception {
Path tmpRoot = Files.createTempDirectory("repo");
// NIO creation and copy content
Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
TestUtil.copyTree(Paths.get("src/test/projects/dummy"), temp);
// end NIO
AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.NONE);
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testIncrementalWithPluginEnabledThreeTime");
}
Assert.assertTrue(res.isSuccessful());
res = compiler.compileSync(req);
Assert.assertTrue(res.isSuccessful());
res = compiler.compileSync(req);
Assert.assertTrue(res.isSuccessful());
Path incrementalConfiguration = Paths.get(temp.toAbsolutePath().toString(), "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
Assert.assertTrue(incrementalConfiguration.toFile().exists());
TestUtil.rm(tmpRoot.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class KieDefaultMavenIncrementalCompilerTest method testIsValidMavenHome.
@Test
public void testIsValidMavenHome() throws Exception {
Path tmpRoot = Files.createTempDirectory("repo");
// NIO creation and copy content
Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
TestUtil.copyTree(Paths.get("src/test/projects/dummy"), temp);
// end NIO
AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.NONE);
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.VERSION }, new HashMap<>(), Boolean.FALSE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testIsValidMavenHome");
}
Assert.assertTrue(res.isSuccessful());
TestUtil.rm(tmpRoot.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo in project kie-wb-common by kiegroup.
the class KieDefaultMavenIncrementalCompilerTest method testCheckIncrementalWithChanges.
@Test
public void testCheckIncrementalWithChanges() throws Exception {
String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
Path tmpRoot = Files.createTempDirectory("repo");
// NIO creation and copy content
Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
TestUtil.copyTree(Paths.get("target/test-classes/dummy_kie_incremental"), temp);
// end NIO
// compiler
AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.LOG_OUTPUT_AFTER);
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, new HashMap<>(), Boolean.TRUE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testCheckIncrementalWithChanges");
}
// checks
Assert.assertTrue(res.isSuccessful());
List<String> fileNames = new ArrayList<>();
// nio
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
for (Path path : directoryStream) {
fileNames.add(path.toString());
}
}
Assert.assertTrue(fileNames.size() == 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();
Assert.assertTrue(res.getMavenOutput().isPresent());
List<String> output = res.getMavenOutput().get();
Assert.assertTrue(isPresent(output, "Previous incremental build state does not exist, performing full build"));
Assert.assertTrue(isPresent(output, "Compiled 2 out of 2 sources "));
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.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testCheckIncrementalWithChanges");
}
// checks
Assert.assertTrue(res.isSuccessful());
fileNames = new ArrayList<>();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
for (Path path : directoryStream) {
fileNames.add(path.toString());
}
}
Assert.assertTrue(fileNames.size() == 1);
Assert.assertTrue(fileNames.get(0).endsWith("Dummy.class"));
long dummyJavaSizeAfterChanges = Paths.get(dummyJava).toFile().length();
Assert.assertTrue(dummyJavaSize < dummyJavaSizeAfterChanges);
Assert.assertTrue(res.getMavenOutput().isPresent());
output = res.getMavenOutput().get();
Assert.assertTrue(isPresent(output, "Performing incremental build"));
Assert.assertTrue(isPresent(output, "Compiled 1 out of 1 sources "));
TestUtil.rm(tmpRoot.toFile());
}
Aggregations