use of org.kie.util.maven.support.PomModel in project drools by kiegroup.
the class DependentScopeNamedBeanTest method testPlexusBeanScanning.
@Test
public void testPlexusBeanScanning() {
// This is the shortest way I can find a root to com.google.inject.internal.Scoping#makeInjectable()
// where the @Dependent scoped bean on the classpath causes guice to fail. The below call goes through
// the following classes:-
//
// - MavenPomModelGenerator#parse()
// - MavenProjectLoader#parseMavenPom()
// - MavenEmbedder#constructor
// - MavenEmbedderUtils#buildPlexusContainer()
//
// This builds a PlexusContainer with classpath scanning enabled (to detect classes needing guice injection)
final InputStream is = getClass().getResourceAsStream("/kjar/pom-kjar.xml");
final PomModelGenerator generator = new MavenPomModelGenerator();
try {
final PomModel pom = generator.parse("pom.xml", is);
} catch (Exception e) {
System.out.println(e.getMessage());
fail("This should not fail");
}
}
use of org.kie.util.maven.support.PomModel in project drools by kiegroup.
the class KieBuilderImpl method init.
private PomModel init(PomModel projectPomModel) {
results = new ResultsImpl();
final PomModel actualPomModel;
if (projectPomModel == null) {
// if pomModel is null it will generate one from pom.xml
// if pomXml is invalid, it assigns pomModel to null
actualPomModel = buildPomModel();
} else {
actualPomModel = projectPomModel;
}
KieServices ks = KieServices.Factory.get();
// if kModuleModelXML is null or invalid it will generate a default kModule, with a default kbase name
buildKieModuleModel();
if (actualPomModel != null) {
// creates ReleaseId from build pom
// If the pom was generated, it will be the same as teh default ReleaseId
releaseId = actualPomModel.getReleaseId();
// add all the pom dependencies to this builder ... not sure this is a good idea (?)
KieRepositoryImpl repository = (KieRepositoryImpl) ks.getRepository();
for (ReleaseId dep : actualPomModel.getDependencies(DependencyFilter.COMPILE_FILTER)) {
KieModule depModule = repository.getKieModule(dep, actualPomModel);
if (depModule != null) {
addKieDependency(depModule);
}
}
} else {
// if the pomModel is null it means that the provided pom.xml is invalid so use the default releaseId
releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId();
}
return actualPomModel;
}
use of org.kie.util.maven.support.PomModel in project drools by kiegroup.
the class KieBuilderImpl method buildAll.
public KieBuilder buildAll(BiFunction<InternalKieModule, ClassLoader, KieModuleKieProject> kprojectSupplier, Predicate<String> classFilter) {
final PomModel currentProjectPomModel = init(pomModel);
// kModuleModel will be null if a provided pom.xml or kmodule.xml is invalid
if (!isBuilt() && kModuleModel != null) {
trgMfs = new MemoryFileSystem();
writePomAndKModule();
addKBasesFilesToTrg();
markSource();
MemoryKieModule memoryKieModule = new MemoryKieModule(releaseId, kModuleModel, trgMfs);
if (kieDependencies != null && !kieDependencies.isEmpty()) {
for (KieModule kieModule : kieDependencies) {
memoryKieModule.addKieDependency((InternalKieModule) kieModule);
}
}
if (currentProjectPomModel != null) {
memoryKieModule.setPomModel(currentProjectPomModel);
}
KieModuleKieProject kProject = kprojectSupplier.apply(memoryKieModule, classLoader);
for (ReleaseId unresolvedDep : memoryKieModule.getUnresolvedDependencies()) {
results.addMessage(Level.ERROR, "pom.xml", "Unresolved dependency " + unresolvedDep);
}
compileJavaClasses(kProject.getClassLoader(), classFilter);
buildKieProject(kProject.createBuildContext(results), kProject, trgMfs);
kModule = kProject.getInternalKieModule();
}
return this;
}
use of org.kie.util.maven.support.PomModel in project drools by kiegroup.
the class KieBuilderImpl method buildPomModel.
private PomModel buildPomModel() {
pomXml = getOrGeneratePomXml(srcMfs);
if (pomXml == null) {
// will be null if the provided pom is invalid
return null;
}
try {
PomModel tempPomModel = PomModel.Parser.parse("pom.xml", new ByteArrayInputStream(pomXml));
// throws an exception if invalid
validatePomModel(tempPomModel);
return tempPomModel;
} catch (Exception e) {
results.addMessage(Level.ERROR, "pom.xml", "maven pom.xml found, but unable to read\n" + e.getMessage());
}
return null;
}
use of org.kie.util.maven.support.PomModel in project drools by kiegroup.
the class AbstractKieModule method getPomModel.
public PomModel getPomModel() {
if (pomModel == null) {
try {
byte[] pomXml = getPomXml();
if (pomXml != null) {
PomModel tempPomModel = PomModel.Parser.parse("pom.xml", new ByteArrayInputStream(pomXml));
// throws an exception if invalid
validatePomModel(tempPomModel);
pomModel = tempPomModel;
}
} catch (Exception e) {
// nothing to do as it was not possible to retrieve pom.xml
}
}
return pomModel;
}
Aggregations