Search in sources :

Example 11 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project fuse-karaf by jboss-fuse.

the class GitPatchManagementServiceIT method installPPatchWithFeatures.

@Test
public void installPPatchWithFeatures() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    try (FileOutputStream fos = new FileOutputStream(new File(karafHome, "etc/org.apache.karaf.features.xml"))) {
        FileUtils.copyFile(new File("src/test/resources/baselines/baseline6/etc/org.apache.karaf.features.xml"), fos);
    }
    preparePatchZip("src/test/resources/baselines/baseline6", "target/karaf/system/org/jboss/fuse/fuse-karaf/7.0.0/fuse-karaf-7.0.0-baseline.zip", true);
    validateInitialGitRepository();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch10", "target/karaf/patches/source/patch-10.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData10 = service.fetchPatches(new File("target/karaf/patches/source/patch-10.zip").toURI().toURL()).get(0);
    Patch patch10 = service.trackPatch(patchData10);
    // before patching:
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<FeatureReplacements.OverrideFeature> features = fp.getFeatureReplacements().getReplacements();
    assertThat(features.size(), equalTo(2));
    assertThat(features.get(0).getFeature().getBundles().size(), equalTo(1));
    assertThat(features.get(0).getFeature().getBundles().get(0).getLocation(), equalTo("mvn:org.jboss.fuse/fuse-utils/0.9"));
    assertThat(features.get(1).getFeature().getBundles().size(), equalTo(1));
    assertThat(features.get(1).getFeature().getBundles().get(0).getLocation(), equalTo("mvn:org.jboss.fuse/fuse-utils/0.9"));
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch10, null);
    service.commitInstallation(tx);
    // override from P-Patch should go to etc/org.apache.karaf.features.xml - both bundle and feature overrides
    fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    features = fp.getFeatureReplacements().getReplacements();
    // unchanged
    assertThat(bundles.size(), equalTo(2));
    assertThat(features.size(), equalTo(2));
    assertThat(features.get(0).getFeature().getBundles().size(), equalTo(2));
    assertThat(features.get(0).getFeature().getBundles().get(0).getLocation(), equalTo("mvn:org.jboss.fuse/fuse-utils/1.0"));
    assertThat(features.get(0).getFeature().getBundles().get(1).getLocation(), equalTo("mvn:org.jboss.fuse/fuse-utils-extra/1.1"));
    assertThat(features.get(1).getFeature().getBundles().size(), equalTo(1));
    assertThat(features.get(1).getFeature().getBundles().get(0).getLocation(), equalTo("mvn:org.jboss.fuse/fuse-utils/0.9"));
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 12 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project karaf by apache.

the class FeaturesProcessingSerializer method read.

/**
 * Reads {@link FeaturesProcessing features processing model} from input stream
 * @param stream
 * @param versions additional properties to resolve placeholders in features processing XML
 * @return
 */
public FeaturesProcessing read(InputStream stream, Properties versions) throws Exception {
    Unmarshaller unmarshaller = FEATURES_PROCESSING_CONTEXT.createUnmarshaller();
    UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
    // BundleContextPropertyResolver gives access to e.g., ${karaf.base}
    final PropertyResolver resolver = bundleContext == null ? new DictionaryPropertyResolver(versions) : new DictionaryPropertyResolver(versions, new BundleContextPropertyResolver(bundleContext));
    // indirect unmarshaling with property resolution inside XML attribute values and CDATA
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    xmlReader.setContentHandler(new ResolvingContentHandler(new Properties() {

        @Override
        public String getProperty(String key) {
            return resolver.get(key);
        }

        @Override
        public String getProperty(String key, String defaultValue) {
            String value = resolver.get(key);
            return value == null ? defaultValue : value;
        }
    }, handler));
    xmlReader.parse(new InputSource(stream));
    return (FeaturesProcessing) handler.getResult();
}
Also used : BundleContextPropertyResolver(org.ops4j.pax.swissbox.property.BundleContextPropertyResolver) InputSource(org.xml.sax.InputSource) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) Unmarshaller(javax.xml.bind.Unmarshaller) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) PropertyResolver(org.ops4j.util.property.PropertyResolver) BundleContextPropertyResolver(org.ops4j.pax.swissbox.property.BundleContextPropertyResolver) Properties(java.util.Properties) XMLReader(org.xml.sax.XMLReader) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 13 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project karaf by apache.

the class FeaturesProcessorTest method serializeWithComments.

@Test
public void serializeWithComments() {
    FeaturesProcessingSerializer serializer = new FeaturesProcessingSerializer();
    FeaturesProcessing featuresProcessing = new FeaturesProcessing();
    featuresProcessing.getBlacklistedRepositories().add("repository 1");
    OverrideBundleDependency.OverrideDependency d1 = new OverrideBundleDependency.OverrideDependency();
    d1.setDependency(true);
    d1.setUri("uri 1");
    featuresProcessing.getOverrideBundleDependency().getRepositories().add(d1);
    OverrideBundleDependency.OverrideFeatureDependency d2 = new OverrideBundleDependency.OverrideFeatureDependency();
    d2.setDependency(false);
    d2.setName("n");
    d2.setVersion("1.2.3");
    featuresProcessing.getOverrideBundleDependency().getFeatures().add(d2);
    BundleReplacements.OverrideBundle override = new BundleReplacements.OverrideBundle();
    override.setOriginalUri("original");
    override.setReplacement("replacement");
    override.setMode(BundleReplacements.BundleOverrideMode.OSGI);
    featuresProcessing.getBundleReplacements().getOverrideBundles().add(override);
    FeatureReplacements.OverrideFeature of = new FeatureReplacements.OverrideFeature();
    of.setMode(FeatureReplacements.FeatureOverrideMode.REPLACE);
    org.apache.karaf.features.internal.model.Feature f = new org.apache.karaf.features.internal.model.Feature();
    f.setName("f1");
    Bundle b = new Bundle();
    b.setLocation("location");
    f.getBundle().add(b);
    of.setFeature(f);
    featuresProcessing.getFeatureReplacements().getReplacements().add(of);
    serializer.write(featuresProcessing, System.out);
}
Also used : Bundle(org.apache.karaf.features.internal.model.Bundle) BundleReplacements(org.apache.karaf.features.internal.model.processing.BundleReplacements) FeatureReplacements(org.apache.karaf.features.internal.model.processing.FeatureReplacements) Feature(org.apache.karaf.features.Feature) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) OverrideBundleDependency(org.apache.karaf.features.internal.model.processing.OverrideBundleDependency) Test(org.junit.Test)

Example 14 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project karaf by apache.

the class FeaturesProcessorTest method jaxbModelForProcessor.

@Test
public void jaxbModelForProcessor() throws Exception {
    JAXBContext jaxb = JAXBContext.newInstance(ObjectFactory.class);
    FeaturesProcessing fp = (FeaturesProcessing) jaxb.createUnmarshaller().unmarshal(getClass().getResourceAsStream("/org/apache/karaf/features/internal/service/org.apache.karaf.features.xml"));
    assertThat(fp.getFeatureReplacements().getReplacements().get(0).getFeature().getName(), equalTo("pax-jsf-resources-support"));
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(fp, System.out);
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Aggregations

FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)14 Test (org.junit.Test)11 File (java.io.File)9 BundleReplacements (org.apache.karaf.features.internal.model.processing.BundleReplacements)5 LinkedList (java.util.LinkedList)4 FeatureReplacements (org.apache.karaf.features.internal.model.processing.FeatureReplacements)4 Git (org.eclipse.jgit.api.Git)4 GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)4 GitPatchRepository (org.jboss.fuse.patch.management.impl.GitPatchRepository)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 Properties (java.util.Properties)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 FileReader (java.io.FileReader)2 Arrays (java.util.Arrays)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)2 FileUtils (org.apache.commons.io.FileUtils)2