use of org.kie.workbench.common.services.backend.compiler.CompilationRequest 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.CompilationRequest in project kie-wb-common by kiegroup.
the class JGITCompilerBeforeDecoratorTest method compileTestTwo.
@Test
public void compileTestTwo() throws Exception {
final FileSystem fileSystem = createFileSystem("myrepodecorator");
// Compile the repo
JGITCompilerBeforeDecorator compiler = new JGITCompilerBeforeDecorator(new BaseMavenCompiler(true, false));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(fileSystem.getPath("/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
CompilationResponse res = compiler.compile(req);
final java.nio.file.Path tempPath = ((Git) compiler.getGitMap().get(fileSystem)).getRepository().getDirectory().toPath().getParent();
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tempPath, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
final Path incrementalConfiguration = Paths.get(tempPath.toUri() + TARGET_TAKARI_PLUGIN);
assertThat(incrementalConfiguration.toFile()).exists();
TestUtil.rm(tempPath.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.CompilationRequest in project kie-wb-common by kiegroup.
the class JGITCompilerBeforeDecoratorTest method compileWithOverrideTest.
@Test
public void compileWithOverrideTest() throws Exception {
final FileSystem fileSystem = createFileSystem("myrepo");
// Compile the repo
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(fileSystem.getPath("/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
Map<Path, InputStream> override = new HashMap<>();
org.uberfire.java.nio.file.Path path = fileSystem.getPath("/", "/dummyA/src/main/java/dummy/Person.java");
InputStream input = new FileInputStream(new File("target/test-classes/kjar-2-single-resources_override/src/main/java/dummy/PersonOverride.java"));
override.put(path, input);
JGITCompilerBeforeDecorator compiler = new JGITCompilerBeforeDecorator(new BaseMavenCompiler(true, false));
CompilationResponse res = compiler.compile(req, override);
final java.nio.file.Path tempPath = ((Git) compiler.getGitMap().get(fileSystem)).getRepository().getDirectory().toPath().getParent();
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tempPath, res, this.getClass(), testName);
assertThat(res.isSuccessful()).isTrue();
final Path incrementalConfiguration = Paths.get(tempPath.toUri() + TARGET_TAKARI_PLUGIN);
assertThat(incrementalConfiguration.toFile().exists()).isTrue();
TestUtil.rm(tempPath.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.CompilationRequest in project kie-wb-common by kiegroup.
the class KieMetadataTest method compileAndLoadKieJarMetadataAllResourcesPackagedJar.
@Ignore("https://issues.redhat.com/browse/AF-2741\n" + "https://issues.redhat.com/browse/AF-2892")
// AF-1459 it tooks 30% of the time of the time spent by all module's test (108), alone it took 30 sec
@Test
public void compileAndLoadKieJarMetadataAllResourcesPackagedJar() throws Exception {
/**
* If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
*/
Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_ALL_RESOURCES);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
if (!res.isSuccessful()) {
List<String> msgs = res.getMavenOutput();
for (String msg : msgs) {
logger.info(msg);
}
}
assertThat(res.isSuccessful()).isTrue();
Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
assertThat(metaDataOptional).isPresent();
KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
assertThat(kieModuleMetaInfo).isNotNull();
Map<String, Set<String>> rulesBP = kieModuleMetaInfo.getRulesByPackage();
assertThat(rulesBP).hasSize(6);
Map<String, TypeMetaInfo> typesMI = kieModuleMetaInfo.getTypeMetaInfos();
// This is a "magic number" test and may or may not be valid since changes
// to the mechanism for generating classes, especially in PMML processing,
// may cause this value to change.
assertThat(typesMI).hasSize(22);
Optional<KieModule> kieModuleOptional = res.getKieModule();
assertThat(kieModuleOptional).isPresent();
assertThat(res.getDependenciesAsURI()).hasSize(4);
KieModule kModule = kieModuleOptional.get();
KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule, res.getDependenciesAsURI());
assertThat(kieModuleMetaData).isNotNull();
}
use of org.kie.workbench.common.services.backend.compiler.CompilationRequest 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();
}
Aggregations