use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class OutputLogAfterDecoratorTest method compileWithOverrideTest.
@Test
public void compileWithOverrideTest() throws Exception {
Map<Path, InputStream> override = new HashMap<>();
org.uberfire.java.nio.file.Path path = org.uberfire.java.nio.file.Paths.get(tmpRoot + "/src/main/java/dummy/DummyOverride.java");
InputStream input = new FileInputStream(new File(ResourcesConstants.DUMMY_OVERRIDE + "/src/main/java/dummy/DummyOverride.java"));
override.put(path, input);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
OutputLogAfterDecorator decorator = new OutputLogAfterDecorator(new BaseMavenCompiler(true, true));
CompilationResponse res = decorator.compile(req, override);
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(res.isSuccessful()).isTrue();
softly.assertThat(res.getMavenOutput().size()).isGreaterThan(0);
});
}
use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest in project kie-wb-common by kiegroup.
the class KieClassLoaderProviderTest method compileProjectInRepo.
private CompilationResponse compileProjectInRepo(String... mavenPhases) throws IOException {
tmpRoot = Files.createTempDirectory("repo");
tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_KIE_MULTIMODULE_CLASSLOADER_DIR);
uberfireTmp = Paths.get(tmp.toAbsolutePath().toString());
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(new HashSet<>());
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(uberfireTmp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, mavenPhases, Boolean.FALSE);
return compiler.compile(req);
}
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