use of org.kie.scanner.KieModuleMetaData in project kie-wb-common by kiegroup.
the class ClassLoaderProviderTest method getResourcesFromADroolsPRJ.
@Test
// https://issues.redhat.com/browse/AF-2892
@Ignore
public void getResourcesFromADroolsPRJ() throws Exception {
/**
* If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
*/
String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
Path tmpRoot = Files.createTempDirectory("repo");
Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
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(tmp, 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();
Optional<KieModule> kieModuleOptional = res.getKieModule();
assertThat(kieModuleOptional).isPresent();
KieModule kModule = kieModuleOptional.get();
assertThat(res.getDependenciesAsURI()).hasSize(4);
KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule, res.getDependenciesAsURI());
assertThat(kieModuleMetaData).isNotNull();
List<String> resources = CompilerClassloaderUtils.getStringFromTargets(tmpRoot);
assertThat(resources).hasSize(3);
}
use of org.kie.scanner.KieModuleMetaData 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.scanner.KieModuleMetaData in project kie-wb-common by kiegroup.
the class BuilderTest method testBuilderKModuleHasDependencyMetaData.
@Test
public void testBuilderKModuleHasDependencyMetaData() throws Exception {
URL url = this.getClass().getResource("/GuvnorM2RepoDependencyExample2");
SimpleFileSystemProvider p = new SimpleFileSystemProvider();
org.uberfire.java.nio.file.Path path = p.getPath(url.toURI());
final Module module = moduleService.resolveModule(Paths.convert(path));
final Builder builder = new Builder(module, ioService, moduleService, importsService, new ArrayList<>(), dependenciesClassLoaderCache, pomModelCache, getPackageNameAllowListService(), alwaysTrue);
final BuildResults results = builder.build();
// Debug output
if (!results.getMessages().isEmpty()) {
for (BuildMessage m : results.getMessages()) {
logger.debug(m.getText());
}
}
assertTrue(results.getMessages().isEmpty());
final KieModuleMetaData metaData = KieModuleMetaData.Factory.newKieModuleMetaData(builder.getKieModule());
// Check packages
final Set<String> packageNames = new HashSet<>();
final Iterator<String> packageNameIterator = metaData.getPackages().iterator();
while (packageNameIterator.hasNext()) {
packageNames.add(packageNameIterator.next());
}
assertEquals(2, packageNames.size());
assertTrue(packageNames.contains("defaultpkg"));
assertTrue(packageNames.contains("org.kie.workbench.common.services.builder.tests.test1"));
// Check classes
final String packageName = "org.kie.workbench.common.services.builder.tests.test1";
assertEquals(1, metaData.getClasses(packageName).size());
final String className = metaData.getClasses(packageName).iterator().next();
assertEquals("Bean", className);
// Check metadata
final Class clazz = metaData.getClass(packageName, className);
final TypeMetaInfo typeMetaInfo = metaData.getTypeMetaInfo(clazz);
assertNotNull(typeMetaInfo);
assertFalse(typeMetaInfo.isEvent());
}
use of org.kie.scanner.KieModuleMetaData in project kie-wb-common by kiegroup.
the class ModuleDataModelOracleBuilderProvider method newBuilder.
public InnerBuilder newBuilder(final KieModule project, final BuildInfo buildInfo) {
final KieModuleMetaData kieModuleMetaData = buildInfo.getKieModuleMetaDataIgnoringErrors();
final TypeSourceResolver typeSourceResolver = buildInfo.getTypeSourceResolver(kieModuleMetaData);
return new InnerBuilder(project, kieModuleMetaData, typeSourceResolver);
}
Aggregations