Search in sources :

Example 21 with Model

use of org.apache.sling.provisioning.model.Model in project sling by apache.

the class IOTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    final Model result = U.readCompleteTestModel();
    U.verifyTestModel(result, false);
    // Write the merged raw model
    StringWriter writer = new StringWriter();
    try {
        ModelWriter.write(writer, result);
    } finally {
        writer.close();
    }
    // read it again
    StringReader reader = new StringReader(writer.toString());
    final Model readModel = ModelReader.read(reader, "memory");
    reader.close();
    final Map<Traceable, String> readErrors = ModelUtility.validate(readModel);
    if (readErrors != null) {
        throw new Exception("Invalid read model : " + readErrors);
    }
    // and verify the result
    U.verifyTestModel(readModel, false);
    // Resolve variables and verify the result
    final Model effective = ModelUtility.getEffectiveModel(readModel);
    U.verifyTestModel(effective, true);
    // write effective model
    writer = new StringWriter();
    ModelWriter.write(writer, effective);
    writer.close();
    reader = new StringReader(writer.toString());
    final Model readModel2 = ModelReader.read(reader, "memory");
    reader.close();
    final Map<Traceable, String> readErrors2 = ModelUtility.validate(readModel2);
    if (readErrors2 != null) {
        throw new Exception("Invalid read model : " + readErrors2);
    }
    // and verify the result
    U.verifyTestModel(readModel2, true);
}
Also used : StringWriter(java.io.StringWriter) Model(org.apache.sling.provisioning.model.Model) StringReader(java.io.StringReader) Traceable(org.apache.sling.provisioning.model.Traceable) Test(org.junit.Test)

Example 22 with Model

use of org.apache.sling.provisioning.model.Model in project sling by apache.

the class IOTest method testAddition.

@Test
public void testAddition() throws Exception {
    final Model model = U.readCompleteTestModel(new String[] { "additional.txt" });
    final Feature f = model.getFeature("main");
    assertNotNull(f);
    assertEquals(1, f.getAdditionalSections().size());
    assertEquals(1, f.getAdditionalSections("additional").size());
}
Also used : Model(org.apache.sling.provisioning.model.Model) Feature(org.apache.sling.provisioning.model.Feature) Test(org.junit.Test)

Example 23 with Model

use of org.apache.sling.provisioning.model.Model in project sling by apache.

the class Launcher method mergeModel.

/** Can be called before launch() to read and merge additional models.
     *  @param r provisioning model to read, closed by this method after reading */
public static void mergeModel(Model mergeInto, Reader r, String sourceInfo) throws IOException {
    log.info("Merging provisioning model {}", sourceInfo);
    try {
        final Model m = ModelReader.read(r, sourceInfo);
        ModelUtility.merge(mergeInto, m);
    } finally {
        r.close();
    }
}
Also used : Model(org.apache.sling.provisioning.model.Model)

Aggregations

Model (org.apache.sling.provisioning.model.Model)23 IOException (java.io.IOException)12 File (java.io.File)11 StringReader (java.io.StringReader)8 Feature (org.apache.sling.provisioning.model.Feature)7 Traceable (org.apache.sling.provisioning.model.Traceable)7 Artifact (org.apache.sling.provisioning.model.Artifact)6 MavenExecutionException (org.apache.maven.MavenExecutionException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 Test (org.junit.Test)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ModelReader (org.apache.sling.provisioning.model.io.ModelReader)4 FileInputStream (java.io.FileInputStream)3 Reader (java.io.Reader)3 StringWriter (java.io.StringWriter)3 Map (java.util.Map)3 Manifest (java.util.jar.Manifest)3 FileOutputStream (java.io.FileOutputStream)2 FileReader (java.io.FileReader)2