use of org.kie.util.maven.support.PomModel in project drools by kiegroup.
the class ClasspathKieProject method generatePomPropertiesFromPom.
private static String generatePomPropertiesFromPom(String rootPath) {
// recurse until we reach root or find a pom.xml
File file = null;
for (File folder = new File(rootPath); folder.getParent() != null; folder = new File(folder.getParent())) {
file = new File(folder, "pom.xml");
if (file.exists()) {
break;
}
file = null;
}
if (file != null) {
try (FileInputStream fis = new FileInputStream(file)) {
PomModel pomModel = PomModel.Parser.parse(rootPath + "/pom.xml", fis);
// throws an exception if invalid
KieBuilderImpl.validatePomModel(pomModel);
ReleaseId gav = pomModel.getReleaseId();
String str = KieBuilderImpl.generatePomProperties(gav);
log.info("Recursed up folders, found and used pom.xml " + file);
return str;
} catch (Exception e) {
log.error("As folder project tried to fall back to pom.xml " + file + "\nbut failed with exception:\n" + e.getMessage());
}
} else {
log.warn("As folder project tried to fall back to pom.xml, but could not find one");
}
return null;
}
use of org.kie.util.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");
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