use of org.appformer.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;
}
use of org.appformer.maven.support.PomModel in project drools by kiegroup.
the class KieBuilderImpl method init.
private PomModel init() {
KieServices ks = KieServices.Factory.get();
results = new ResultsImpl();
// if pomXML is null it will generate a default, using default ReleaseId
// if pomXml is invalid, it assign pomModel to null
PomModel pomModel = getPomModel();
// if kModuleModelXML is null or invalid it will generate a default kModule, with a default kbase name
buildKieModuleModel();
if (pomModel != null) {
// creates ReleaseId from build pom
// If the pom was generated, it will be the same as teh default ReleaseId
releaseId = pomModel.getReleaseId();
// add all the pom dependencies to this builder ... not sure this is a good idea (?)
KieRepositoryImpl repository = (KieRepositoryImpl) ks.getRepository();
for (AFReleaseId dep : pomModel.getDependencies(DependencyFilter.COMPILE_FILTER)) {
KieModule depModule = repository.getKieModule(adapt(dep), pomModel);
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 pomModel;
}
use of org.appformer.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.appformer.maven.support.PomModel in project drools by kiegroup.
the class KieBuilderImpl method buildAll.
public KieBuilder buildAll(BiFunction<InternalKieModule, ClassLoader, KieModuleKieProject> kprojectSupplier, Predicate<String> classFilter) {
PomModel pomModel = init();
// 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(adapt(releaseId), kModuleModel, trgMfs);
if (kieDependencies != null && !kieDependencies.isEmpty()) {
for (KieModule kieModule : kieDependencies) {
memoryKieModule.addKieDependency((InternalKieModule) kieModule);
}
}
if (pomModel != null) {
memoryKieModule.setPomModel(pomModel);
}
KieModuleKieProject kProject = kprojectSupplier.apply(memoryKieModule, classLoader);
for (ReleaseId unresolvedDep : memoryKieModule.getUnresolvedDependencies()) {
results.addMessage(Level.ERROR, "pom.xml", "Unresolved dependency " + unresolvedDep);
}
List<String> pmmlFileNames = getPmmlFileNames(srcMfs);
if (pmmlFileNames != null && !pmmlFileNames.isEmpty()) {
buildPMMLPojos(pmmlFileNames, kProject);
}
compileJavaClasses(kProject.getClassLoader(), classFilter);
buildKieProject(results, kProject, trgMfs);
kModule = kProject.getInternalKieModule();
}
return this;
}
use of org.appformer.maven.support.PomModel in project drools by kiegroup.
the class KieBuilderTest method testSetPomModelReuse.
@Test
public void testSetPomModelReuse() throws IOException {
String namespace = "org.kie.test";
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "pomModelReuse", "1.0-SNAPSHOT");
String pom = KieBuilderImpl.generatePomXml(releaseId);
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
kfs.writePomXML(pom);
// Create a KieBuilder instance
KieBuilder kieBuilder1 = createKieBuilder(kfs);
kieBuilder1.buildAll();
// Get PomModel to re-use in second KieBuilder instance
PomModel pomModel = ((KieBuilderImpl) kieBuilder1).getPomModel();
kfs.writePomXML(pom);
// Create another KieBuilder instance with the same KieFileSystem, setting PomModel
KieBuilder kieBuilder2 = createKieBuilder(kfs);
((KieBuilderImpl) kieBuilder2).setPomModel(pomModel);
kieBuilder2.buildAll();
// Read pom.xml from first KieBuilder's KieModule
InternalKieModule kieModule1 = (InternalKieModule) ((KieBuilderImpl) kieBuilder1).getKieModuleIgnoringErrors();
final Reader reader1 = kieModule1.getResource("META-INF/maven/org.kie.test/pomModelReuse/pom.xml").getReader();
int charCode;
String readPom1 = "";
while ((charCode = reader1.read()) != -1) {
readPom1 = readPom1 + (char) charCode;
}
reader1.close();
assertEquals(pom, readPom1);
// Read pom.xml from second KieBuilder's KieModule
InternalKieModule kieModule2 = (InternalKieModule) ((KieBuilderImpl) kieBuilder2).getKieModuleIgnoringErrors();
final Reader reader2 = kieModule2.getResource("META-INF/maven/org.kie.test/pomModelReuse/pom.xml").getReader();
String readPom2 = "";
while ((charCode = reader2.read()) != -1) {
readPom2 = readPom2 + (char) charCode;
}
reader1.close();
assertEquals(pom, readPom2);
}
Aggregations