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"));
}
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();
}
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);
}
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);
}
Aggregations