Search in sources :

Example 1 with KarafPropertyEdits

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;
}
Also used : KarafPropertyInstructionsModelStaxReader(org.apache.karaf.tools.utils.model.io.stax.KarafPropertyInstructionsModelStaxReader) KarafPropertyEdits(org.apache.karaf.tools.utils.model.KarafPropertyEdits) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with KarafPropertyEdits

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"));
}
Also used : Path(java.nio.file.Path) KarafPropertyInstructionsModelStaxReader(org.apache.karaf.tools.utils.model.io.stax.KarafPropertyInstructionsModelStaxReader) KarafPropertyEdits(org.apache.karaf.tools.utils.model.KarafPropertyEdits) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 KarafPropertyEdits (org.apache.karaf.tools.utils.model.KarafPropertyEdits)2 KarafPropertyInstructionsModelStaxReader (org.apache.karaf.tools.utils.model.io.stax.KarafPropertyInstructionsModelStaxReader)2 URL (java.net.URL)1 Path (java.nio.file.Path)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 ZipFile (java.util.zip.ZipFile)1 Test (org.junit.Test)1