use of org.apache.karaf.tools.utils.model.KarafPropertyEdits in project karaf by apache.
the class AssemblyMojo method configurePropertyEdits.
private KarafPropertyEdits configurePropertyEdits() throws IOException, XMLStreamException {
KarafPropertyEdits edits = null;
if (propertyFileEdits != null) {
File file = new File(propertyFileEdits);
if (file.exists()) {
try (InputStream editsStream = new FileInputStream(propertyFileEdits)) {
KarafPropertyInstructionsModelStaxReader kipmsr = new KarafPropertyInstructionsModelStaxReader();
edits = kipmsr.read(editsStream, true);
}
}
}
return edits;
}
use of org.apache.karaf.tools.utils.model.KarafPropertyEdits in project karaf by apache.
the class KarafPropertiesEditorTest method onceOver.
@Test
public void onceOver() throws Exception {
KarafPropertyInstructionsModelStaxReader kipmsr = new KarafPropertyInstructionsModelStaxReader();
URL editsUrl = Resources.getResource(KarafPropertiesEditorTest.class, "test-edits.xml");
KarafPropertyEdits edits;
try (InputStream editsStream = Resources.asByteSource(editsUrl).openStream()) {
edits = kipmsr.read(editsStream, true);
}
Path path = FileSystems.getDefault().getPath("target");
Path outputEtc = Files.createTempDirectory(path, "test-etc");
outputEtc.toFile().deleteOnExit();
KarafPropertiesEditor editor = new KarafPropertiesEditor();
editor.setInputEtc(new File(ETC_TO_START_WITH)).setOutputEtc(outputEtc.toFile()).setEdits(edits);
editor.run();
File resultConfigProps = new File(outputEtc.toFile(), "config.properties");
Properties properties = new Properties();
try (InputStream resultInputStream = new FileInputStream(resultConfigProps)) {
properties.load(resultInputStream);
}
assertEquals("equinox", properties.getProperty("karaf.framework"));
assertEquals("prepended,root,toor", properties.getProperty("karaf.name"));
resultConfigProps = new File(outputEtc.toFile(), "jre.properties");
try (InputStream resultInputStream = new FileInputStream(resultConfigProps)) {
properties.load(resultInputStream);
}
assertEquals("This is the cereal: shot from guns", properties.getProperty("test-add-one"));
assertEquals("This is the gun that shoots cereal", properties.getProperty("test-add-two"));
}
Aggregations