Search in sources :

Example 1 with FeaturesProcessing

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

the class FeaturesProcessorTest method readingLegacyBlacklist.

@Test
public void readingLegacyBlacklist() {
    FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(null, "file:src/test/resources/org/apache/karaf/features/internal/service/blacklisted2.properties", null, null));
    FeaturesProcessing instructions = processor.getInstructions();
    Blacklist blacklist = instructions.getBlacklist();
    Clause[] clauses = blacklist.getClauses();
    assertThat(clauses.length, equalTo(4));
    assertTrue(blacklist.isFeatureBlacklisted("spring", "2.5.6.SEC02"));
    assertFalse(blacklist.isFeatureBlacklisted("spring", "2.5.7.SEC02"));
    assertFalse(blacklist.isFeatureBlacklisted("jclouds", "1"));
    assertTrue(blacklist.isBundleBlacklisted("mvn:org.spring/spring-infinity/42"));
    assertFalse(blacklist.isBundleBlacklisted("mvn:org.spring/spring-infinity/41"));
    assertTrue(blacklist.isBundleBlacklisted("mvn:org.spring/spring-eternity/42"));
    assertTrue(blacklist.isBundleBlacklisted("mvn:jclouds/jclouds/1"));
}
Also used : Clause(org.apache.felix.utils.manifest.Clause) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 2 with FeaturesProcessing

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

the class FeaturesProcessorTest method readingLegacyOverrides.

@Test
public void readingLegacyOverrides() {
    FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig("file:src/test/resources/org/apache/karaf/features/internal/service/overrides2.properties", null, null, null));
    FeaturesProcessing instructions = processor.getInstructions();
    BundleReplacements bundleReplacements = instructions.getBundleReplacements();
    assertThat(bundleReplacements.getOverrideBundles().size(), equalTo(5));
    BundleReplacements.OverrideBundle o1 = bundleReplacements.getOverrideBundles().get(0);
    assertThat(o1.getOriginalUri(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.command/[2.3.0,2.3.0.61033X)"));
    assertThat(o1.getReplacement(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.command/2.3.0.61033X"));
    BundleReplacements.OverrideBundle o2 = bundleReplacements.getOverrideBundles().get(1);
    assertThat(o2.getOriginalUri(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.core/[2.2.0,2.4.0)"));
    assertThat(o2.getReplacement(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.core/2.3.0.61033X"));
    BundleReplacements.OverrideBundle o3 = bundleReplacements.getOverrideBundles().get(2);
    assertThat(o3.getOriginalUri(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.resources/[2.3.0,2.3.14)"));
    assertThat(o3.getReplacement(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.resources/2.3.14"));
    BundleReplacements.OverrideBundle o4 = bundleReplacements.getOverrideBundles().get(3);
    assertThat(o4.getOriginalUri(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.kernel/[2.0.0,2.0.0]"));
    assertThat(o4.getReplacement(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.kernel/2.3.14"));
    BundleReplacements.OverrideBundle o5 = bundleReplacements.getOverrideBundles().get(4);
    assertThat(o5.getOriginalUri(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.infinity/[1.0.0,*)"));
    assertThat(o5.getReplacement(), equalTo("mvn:org.apache.karaf.admin/org.apache.karaf.admin.infinity/2.3.14"));
}
Also used : BundleReplacements(org.apache.karaf.features.internal.model.processing.BundleReplacements) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 3 with FeaturesProcessing

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

the class GitPatchManagementServiceImpl method updateOverrides.

/**
 * <p>Updates existing <code>etc/org.apache.karaf.features.xml</code> after installing single {@link PatchKind#NON_ROLLUP}
 * patch. Both bundle and feature replacements are taken into account.</p>
 * @param workTree
 * @param patches
 */
private void updateOverrides(File workTree, List<PatchData> patches) throws IOException {
    File overrides = new File(workTree, "etc/" + featureProcessing);
    File versions = new File(workTree, "etc/" + featureProcessingVersions);
    // we need two different versions to detect whether the version is externalized in etc/versions.properties
    FeaturesProcessing fp1;
    FeaturesProcessing fp2;
    if (overrides.isFile()) {
        fp1 = InternalUtils.loadFeatureProcessing(overrides, versions);
        fp2 = InternalUtils.loadFeatureProcessing(overrides, null);
    } else {
        fp1 = fp2 = new FeaturesProcessing();
    }
    List<BundleReplacements.OverrideBundle> br1 = fp1.getBundleReplacements().getOverrideBundles();
    List<BundleReplacements.OverrideBundle> br2 = fp2.getBundleReplacements().getOverrideBundles();
    org.apache.felix.utils.properties.Properties props = null;
    boolean propertyChanged = false;
    if (versions.isFile()) {
        props = new org.apache.felix.utils.properties.Properties(versions);
    }
    for (PatchData patchData : patches) {
        for (String bundle : patchData.getBundles()) {
            Artifact artifact = mvnurlToArtifact(bundle, true);
            if (artifact == null) {
                continue;
            }
            // Compute patch bundle version and range
            Version oVer = Utils.getOsgiVersion(artifact.getVersion());
            String vr = patchData.getVersionRange(bundle);
            if (vr != null && !vr.isEmpty()) {
                artifact.setVersion(vr);
            } else {
                Version v1 = new Version(oVer.getMajor(), oVer.getMinor(), 0);
                Version v2 = new Version(oVer.getMajor(), oVer.getMinor() + 1, 0);
                artifact.setVersion(new VersionRange(VersionRange.LEFT_CLOSED, v1, v2, VersionRange.RIGHT_OPEN).toString());
            }
            // features processing file may contain e.g.,:
            // <bundle originalUri="mvn:org.jboss.fuse/fuse-zen/[1,2)/war"
            // replacement="mvn:org.jboss.fuse/fuse-zen/${version.test2}/war" mode="maven" />
            // patch descriptor contains e.g.,:
            // bundle.0 = mvn:org.jboss.fuse/fuse-zen/1.2.0/war
            // bundle.0.range = [1.1,1.2)
            // 
            // we will always match by replacement attribute, ignoring originalUri - the patch descriptor must be
            // prepared correctly
            int idx = 0;
            BundleReplacements.OverrideBundle existing = null;
            // we'll examine model with resolved property placeholders, but modify the other one
            for (BundleReplacements.OverrideBundle override : br1) {
                LocationPattern lp = new LocationPattern(artifact.getCanonicalUri());
                if (lp.matches(override.getReplacement())) {
                    // we've found existing override in current etc/org.apache.karaf.features.xml
                    existing = br2.get(idx);
                    break;
                }
                idx++;
            }
            if (existing == null) {
                existing = new BundleReplacements.OverrideBundle();
                br2.add(existing);
            }
            // either update existing override or configure a new one
            existing.setMode(BundleReplacements.BundleOverrideMode.MAVEN);
            existing.setOriginalUri(artifact.getCanonicalUri());
            String replacement = existing.getReplacement();
            if (replacement != null && replacement.contains("${")) {
                // assume that we have existing replacement="mvn:org.jboss.fuse/fuse-zen/${version.test2}/war"
                // so we can't change the replacement and instead we have to update properties
                String property = null;
                String value = null;
                if (replacement.startsWith("mvn:")) {
                    LocationPattern existingReplacement = new LocationPattern(replacement);
                    property = existingReplacement.getVersionString().substring(existingReplacement.getVersionString().indexOf("${") + 2);
                    if (property.contains("}")) {
                        // it should...
                        property = property.substring(0, property.indexOf("}"));
                    }
                    LocationPattern newReplacement = new LocationPattern(bundle);
                    value = newReplacement.getVersionString();
                } else {
                // non-mvn? then we can't determine the version from non-mvn: URI...
                }
                // we are not changing replacement - we'll have to update properties
                if (props != null && property != null) {
                    props.setProperty(property, value);
                    propertyChanged = true;
                }
            } else {
                existing.setReplacement(bundle);
            }
        }
        // feature overrides
        File featureOverridesLocation = new File(patchData.getPatchDirectory(), "org.apache.karaf.features.xml");
        if (featureOverridesLocation.isFile()) {
            FeaturesProcessing featureOverrides = InternalUtils.loadFeatureProcessing(featureOverridesLocation, null);
            Map<String, FeatureReplacements.OverrideFeature> patchedFeatures = new LinkedHashMap<>();
            List<FeatureReplacements.OverrideFeature> mergedOverrides = new LinkedList<>();
            featureOverrides.getFeatureReplacements().getReplacements().forEach(of -> patchedFeatures.put(of.getFeature().getId(), of));
            fp2.getFeatureReplacements().getReplacements().forEach(of -> {
                FeatureReplacements.OverrideFeature override = patchedFeatures.remove(of.getFeature().getId());
                mergedOverrides.add(override == null ? of : override);
            });
            // add remaining
            mergedOverrides.addAll(patchedFeatures.values());
            fp2.getFeatureReplacements().getReplacements().clear();
            fp2.getFeatureReplacements().getReplacements().addAll(mergedOverrides);
        }
    }
    if (propertyChanged) {
        props.save();
    }
    InternalUtils.saveFeatureProcessing(fp2, overrides, versions);
}
Also used : BundleReplacements(org.apache.karaf.features.internal.model.processing.BundleReplacements) VersionRange(org.osgi.framework.VersionRange) FeatureReplacements(org.apache.karaf.features.internal.model.processing.FeatureReplacements) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) LinkedHashMap(java.util.LinkedHashMap) Version(org.osgi.framework.Version) PatchData(org.jboss.fuse.patch.management.PatchData) Artifact(org.jboss.fuse.patch.management.Artifact) LinkedList(java.util.LinkedList) LocationPattern(org.apache.karaf.features.LocationPattern) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 4 with FeaturesProcessing

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

the class GitPatchManagementServiceImpl method loadPatch.

/**
 * Retrieves patch information from existing file
 * @param patchDescriptor existing file with patch descriptor (<code>*.patch</code> file)
 * @param details whether the returned {@link Patch} should contain {@link ManagedPatch} information
 * @return
 * @throws IOException
 */
private Patch loadPatch(File patchDescriptor, boolean details) throws IOException {
    Patch p = new Patch();
    if (!patchDescriptor.exists() || !patchDescriptor.isFile()) {
        return null;
    }
    PatchData data = PatchData.load(new FileInputStream(patchDescriptor));
    p.setPatchData(data);
    File patchDirectory = new File(patchesDir, FilenameUtils.getBaseName(patchDescriptor.getName()));
    if (patchDirectory.exists() && patchDirectory.isDirectory()) {
        // not every descriptor downloaded may be a ZIP file, not every patch has content
        data.setPatchDirectory(patchDirectory);
        File featureOverridesLocation = new File(patchDirectory, "org.apache.karaf.features.xml");
        if (featureOverridesLocation.isFile()) {
            // them available during all patch operations
            try {
                FeaturesProcessing featureOverrides = InternalUtils.loadFeatureProcessing(featureOverridesLocation, null);
                List<String> overrides = new LinkedList<>();
                if (featureOverrides.getFeatureReplacements().getReplacements() != null) {
                    featureOverrides.getFeatureReplacements().getReplacements().forEach(of -> overrides.add(of.getFeature().getId()));
                }
                data.setFeatureOverrides(overrides);
            } catch (Exception e) {
                Activator.log(LogService.LOG_WARNING, "Problem loading org.apache.karaf.features.xml from patch " + data.getId() + ": " + e.getMessage());
            }
        }
    }
    data.setPatchLocation(patchesDir);
    File resultFile = new File(patchesDir, FilenameUtils.getBaseName(patchDescriptor.getName()) + ".patch.result");
    if (resultFile.exists() && resultFile.isFile()) {
        PatchResult result = PatchResult.load(data, new FileInputStream(resultFile));
        p.setResult(result);
    }
    if (details) {
        ManagedPatch mp = gitPatchRepository.getManagedPatch(data.getId());
        p.setManagedPatch(mp);
    }
    return p;
}
Also used : ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) PatchData(org.jboss.fuse.patch.management.PatchData) PatchResult(org.jboss.fuse.patch.management.PatchResult) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) LinkedList(java.util.LinkedList) PatchException(org.jboss.fuse.patch.management.PatchException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

Example 5 with FeaturesProcessing

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

the class FeatureProcessingTest method writeProcessingInstructions.

@Test
public void writeProcessingInstructions() {
    FeaturesProcessing fp1 = InternalUtils.loadFeatureProcessing(new File("src/test/resources/processing/oakf.1.xml"), null);
    fp1.getBlacklistedBundles().add("mvn:x/y");
    fp1.getBlacklistedFeatures().add(new FeaturesProcessing.BlacklistedFeature("f", "1"));
    FeaturesProcessingSerializer serializer = new FeaturesProcessingSerializer();
    serializer.write(fp1, System.out);
    System.out.flush();
}
Also used : FeaturesProcessingSerializer(org.apache.karaf.features.internal.service.FeaturesProcessingSerializer) File(java.io.File) 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