Search in sources :

Example 16 with Features

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

the class AbstractFeatureMojo method retrieveDescriptorsRecursively.

protected void retrieveDescriptorsRecursively(String uri, Set<String> bundles, Map<String, Feature> featuresMap) {
    // let's ensure a mvn: based url is sitting in the local repo before we try reading it
    Artifact descriptor;
    try {
        descriptor = resourceToArtifact(uri, true);
    } catch (MojoExecutionException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (descriptor != null) {
        resolveArtifact(descriptor, remoteRepos);
        descriptorArtifacts.add(descriptor);
    }
    if (includeMvnBasedDescriptors) {
        bundles.add(uri);
    }
    String uriToUse = descriptor != null ? descriptor.getFile().toURI().toString() : translateFromMaven(uri);
    Features repo = JaxbUtil.unmarshal(uriToUse, true);
    for (Feature f : repo.getFeature()) {
        featuresMap.put(f.getId(), f);
    }
    if (resolveDefinedRepositoriesRecursively) {
        for (String r : repo.getRepository()) {
            retrieveDescriptorsRecursively(r, bundles, featuresMap);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Features(org.apache.karaf.features.internal.model.Features) Feature(org.apache.karaf.features.internal.model.Feature) Artifact(org.apache.maven.artifact.Artifact)

Example 17 with Features

use of org.apache.karaf.features.internal.model.Features 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 18 with Features

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

the class BlacklistTest method testBlacklistFeatureWithRange.

@Test
public void testBlacklistFeatureWithRange() {
    URL url = getClass().getResource("f02.xml");
    Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
    List<String> blacklist = new ArrayList<>();
    blacklist.add("spring;range=\"[2,3)\"");
    Blacklist.blacklist(features, blacklist);
    for (Feature feature : features.getFeature()) {
        assertNotEquals("spring/2.5.6.SEC02", feature.getId());
    }
}
Also used : 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 19 with Features

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

the class FeaturesValidationTest method testNs13Unmarshall.

@Test
public void testNs13Unmarshall() throws Exception {
    URL url = getClass().getResource("f07.xml");
    Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
    assertNotNull(features);
    assertEquals("2.5.6.SEC02", features.getFeature().get(0).getVersion());
    assertTrue(features.getFeature().get(1).isHidden());
    assertNotNull(features.getFeature().get(1).getLibraries());
    assertEquals(1, features.getFeature().get(0).getLibraries().size());
    assertEquals("my-library", features.getFeature().get(0).getLibraries().get(0).getLocation());
    assertEquals(Library.TYPE_ENDORSED, features.getFeature().get(0).getLibraries().get(0).getType());
    assertFalse(features.getFeature().get(0).getLibraries().get(0).isExport());
    assertTrue(features.getFeature().get(0).getLibraries().get(0).isDelegate());
}
Also used : Features(org.apache.karaf.features.internal.model.Features) URL(java.net.URL) Test(org.junit.Test)

Example 20 with Features

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

the class FeaturesValidationTest method testNs10NoNameUnmarshall.

@Test
public void testNs10NoNameUnmarshall() throws Exception {
    URL url = getClass().getResource("f03.xml");
    Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
    assertNotNull(features);
}
Also used : Features(org.apache.karaf.features.internal.model.Features) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Features (org.apache.karaf.features.internal.model.Features)37 Feature (org.apache.karaf.features.internal.model.Feature)21 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 File (java.io.File)12 LinkedHashMap (java.util.LinkedHashMap)12 IOException (java.io.IOException)11 LinkedHashSet (java.util.LinkedHashSet)11 URL (java.net.URL)10 HashSet (java.util.HashSet)10 ConfigFile (org.apache.karaf.features.internal.model.ConfigFile)10 Test (org.junit.Test)10 Map (java.util.Map)9 TreeMap (java.util.TreeMap)9 Downloader (org.apache.karaf.features.internal.download.Downloader)8 InputStream (java.io.InputStream)7 List (java.util.List)7 Bundle (org.apache.karaf.features.internal.model.Bundle)7 Conditional (org.apache.karaf.features.internal.model.Conditional)7 Dependency (org.apache.karaf.features.internal.model.Dependency)7