Search in sources :

Example 1 with Bundle

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

the class GenerateDescriptorMojo method checkChanges.

private void checkChanges(Features newFeatures, ObjectFactory objectFactory) throws Exception {
    if (checkDependencyChange) {
        //combine all the dependencies to one feature and strip out versions
        Features features = objectFactory.createFeaturesRoot();
        features.setName(newFeatures.getName());
        Feature feature = objectFactory.createFeature();
        features.getFeature().add(feature);
        for (Feature f : newFeatures.getFeature()) {
            for (Bundle b : f.getBundle()) {
                Bundle bundle = objectFactory.createBundle();
                bundle.setLocation(b.getLocation());
                feature.getBundle().add(bundle);
            }
            for (Dependency d : f.getFeature()) {
                Dependency dependency = objectFactory.createDependency();
                dependency.setName(d.getName());
                feature.getFeature().add(dependency);
            }
        }
        feature.getBundle().sort(Comparator.comparing(Bundle::getLocation));
        feature.getFeature().sort(Comparator.comparing(Dependency::getName));
        if (dependencyCache.exists()) {
            //filter dependencies file
            filter(dependencyCache, filteredDependencyCache);
            //read dependency types, convert to dependencies, compare.
            Features oldfeatures = readFeaturesFile(filteredDependencyCache);
            Feature oldFeature = oldfeatures.getFeature().get(0);
            List<Bundle> addedBundles = new ArrayList<>(feature.getBundle());
            List<Bundle> removedBundles = new ArrayList<>();
            for (Bundle test : oldFeature.getBundle()) {
                boolean t1 = addedBundles.contains(test);
                int s1 = addedBundles.size();
                boolean t2 = addedBundles.remove(test);
                int s2 = addedBundles.size();
                if (t1 != t2) {
                    getLog().warn("dependencies.contains: " + t1 + ", dependencies.remove(test): " + t2);
                }
                if (t1 == (s1 == s2)) {
                    getLog().warn("dependencies.contains: " + t1 + ", size before: " + s1 + ", size after: " + s2);
                }
                if (!t2) {
                    removedBundles.add(test);
                }
            }
            List<Dependency> addedDependencys = new ArrayList<>(feature.getFeature());
            List<Dependency> removedDependencys = new ArrayList<>();
            for (Dependency test : oldFeature.getFeature()) {
                boolean t1 = addedDependencys.contains(test);
                int s1 = addedDependencys.size();
                boolean t2 = addedDependencys.remove(test);
                int s2 = addedDependencys.size();
                if (t1 != t2) {
                    getLog().warn("dependencies.contains: " + t1 + ", dependencies.remove(test): " + t2);
                }
                if (t1 == (s1 == s2)) {
                    getLog().warn("dependencies.contains: " + t1 + ", size before: " + s1 + ", size after: " + s2);
                }
                if (!t2) {
                    removedDependencys.add(test);
                }
            }
            if (!addedBundles.isEmpty() || !removedBundles.isEmpty() || !addedDependencys.isEmpty() || !removedDependencys.isEmpty()) {
                saveDependencyChanges(addedBundles, removedBundles, addedDependencys, removedDependencys, objectFactory);
                if (overwriteChangedDependencies) {
                    writeDependencies(features, dependencyCache);
                }
            } else {
                getLog().info(saveTreeListing());
            }
        } else {
            writeDependencies(features, dependencyCache);
        }
    }
}
Also used : Bundle(org.apache.karaf.features.internal.model.Bundle) ArrayList(java.util.ArrayList) Features(org.apache.karaf.features.internal.model.Features) Dependency(org.apache.karaf.features.internal.model.Dependency) LocalDependency(org.apache.karaf.tooling.utils.LocalDependency) Feature(org.apache.karaf.features.internal.model.Feature)

Example 2 with Bundle

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

the class AbstractFeatureMojo method resolveFeatures.

protected Set<Feature> resolveFeatures() throws MojoExecutionException {
    Set<Feature> featuresSet = new HashSet<>();
    try {
        Set<String> artifactsToCopy = new HashSet<>();
        Map<String, Feature> featuresMap = new HashMap<>();
        for (String uri : descriptors) {
            retrieveDescriptorsRecursively(uri, artifactsToCopy, featuresMap);
        }
        // no features specified, handle all of them
        if (features == null) {
            features = new ArrayList<>(featuresMap.keySet());
        }
        addFeatures(features, featuresSet, featuresMap, addTransitiveFeatures);
        getLog().info("Using local repository at: " + localRepo.getUrl());
        for (Feature feature : featuresSet) {
            try {
                for (Bundle bundle : feature.getBundle()) {
                    resolveArtifact(bundle.getLocation());
                }
                for (Conditional conditional : feature.getConditional()) {
                    for (BundleInfo bundle : conditional.getBundles()) {
                        if (ignoreDependencyFlag || (!ignoreDependencyFlag && !bundle.isDependency())) {
                            resolveArtifact(bundle.getLocation());
                        }
                    }
                }
                for (ConfigFile configfile : feature.getConfigfile()) {
                    resolveArtifact(configfile.getLocation());
                }
            } catch (RuntimeException e) {
                throw new RuntimeException("Error resolving feature " + feature.getName() + "/" + feature.getVersion(), e);
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error populating repository", e);
    }
    return featuresSet;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) Bundle(org.apache.karaf.features.internal.model.Bundle) Conditional(org.apache.karaf.features.Conditional) Feature(org.apache.karaf.features.internal.model.Feature) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleInfo(org.apache.karaf.features.BundleInfo) HashSet(java.util.HashSet)

Example 3 with Bundle

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

the class ExportFeatureMetaDataMojo method mergeFeature.

private Feature mergeFeature(Set<Feature> featuresSet) throws MojoExecutionException {
    Feature merged = new Feature("merged");
    Set<String> bundleIds = new HashSet<>();
    for (Feature feature : featuresSet) {
        for (Bundle bundle : feature.getBundle()) {
            String symbolicName = getBundleSymbolicName(bundle);
            if (symbolicName == null) {
                logIgnored(bundle);
                continue;
            }
            String bundleId = symbolicName + ":" + getBundleVersion(bundle);
            if (!bundleIds.contains(bundleId)) {
                bundleIds.add(bundleId);
                merged.getBundle().add(bundle);
            }
        }
    }
    return merged;
}
Also used : Bundle(org.apache.karaf.features.internal.model.Bundle) Feature(org.apache.karaf.features.internal.model.Feature) HashSet(java.util.HashSet)

Example 4 with Bundle

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

the class BlacklistTest method testBlacklistBundle.

@Test
public void testBlacklistBundle() {
    URL url = getClass().getResource("f02.xml");
    Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
    List<String> blacklist = new ArrayList<>();
    blacklist.add("mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/1.7_1");
    Blacklist.blacklist(features, blacklist);
    for (Feature feature : features.getFeature()) {
        for (Bundle bundle : feature.getBundle()) {
            assertNotEquals("mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/1.7_1", bundle.getLocation());
        }
    }
}
Also used : Bundle(org.apache.karaf.features.internal.model.Bundle) ArrayList(java.util.ArrayList) Features(org.apache.karaf.features.internal.model.Features) Feature(org.apache.karaf.features.internal.model.Feature) URL(java.net.URL) Test(org.junit.Test)

Example 5 with Bundle

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

the class AddToRepositoryMojo method copyBundlesToDestRepository.

private void copyBundlesToDestRepository(List<? extends Bundle> artifactRefs) throws MojoExecutionException {
    for (Bundle artifactRef : artifactRefs) {
        Artifact artifact = resourceToArtifact(artifactRef.getLocation(), skipNonMavenProtocols);
        // Avoid getting NPE on artifact.getFile in some cases 
        resolveArtifact(artifact, remoteRepos);
        if (artifact != null) {
            copy(artifact, repository);
        }
    }
}
Also used : Bundle(org.apache.karaf.features.internal.model.Bundle) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Bundle (org.apache.karaf.features.internal.model.Bundle)9 Feature (org.apache.karaf.features.internal.model.Feature)8 Features (org.apache.karaf.features.internal.model.Features)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 ConfigFile (org.apache.karaf.features.internal.model.ConfigFile)4 ArrayList (java.util.ArrayList)3 Dependency (org.apache.karaf.features.internal.model.Dependency)3 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 Downloader (org.apache.karaf.features.internal.download.Downloader)2 Conditional (org.apache.karaf.features.internal.model.Conditional)2 Profile (org.apache.karaf.profile.Profile)2 LocalDependency (org.apache.karaf.tooling.utils.LocalDependency)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 LinkedHashMap (java.util.LinkedHashMap)1