Search in sources :

Example 6 with Feature

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

the class ExportFeatureMetaDataMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Set<Feature> featuresSet = resolveFeatures();
    if (mergedFeature) {
        Feature feature = oneVersion ? mergeFeatureOneVersion(featuresSet) : mergeFeature(featuresSet);
        featuresSet = new HashSet<>();
        featuresSet.add(feature);
    }
    try {
        metaDataFile.getParentFile().mkdirs();
        Features features = new Features();
        features.getFeature().addAll(featuresSet);
        try (OutputStream os = new FileOutputStream(metaDataFile)) {
            JaxbUtil.marshal(features, os);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error writing feature meta data to " + metaDataFile + ": " + e.getMessage(), e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Features(org.apache.karaf.features.internal.model.Features) Feature(org.apache.karaf.features.internal.model.Feature) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 7 with Feature

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

use of org.apache.karaf.features.internal.model.Feature 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);
    }
    Features repo = JaxbUtil.unmarshal(translateFromMaven(uri.replaceAll(" ", "%20")), 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 9 with Feature

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

the class AddToRepositoryMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Set<Feature> featuresSet = resolveFeatures();
    for (Artifact descriptor : descriptorArtifacts) {
        copy(descriptor, repository);
    }
    for (Feature feature : featuresSet) {
        copyBundlesToDestRepository(feature.getBundle());
        for (Conditional conditional : feature.getConditional()) {
            copyBundlesConditionalToDestRepository(conditional.getBundles());
        }
        copyConfigFilesToDestRepository(feature.getConfigfile());
    }
    copyFileBasedDescriptorsToDestRepository();
}
Also used : Conditional(org.apache.karaf.features.Conditional) Feature(org.apache.karaf.features.internal.model.Feature) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with Feature

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

the class BlacklistTest method testBlacklistFeatureWithoutVersion.

@Test
public void testBlacklistFeatureWithoutVersion() {
    URL url = getClass().getResource("f02.xml");
    Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
    List<String> blacklist = new ArrayList<>();
    blacklist.add("spring");
    Blacklist.blacklist(features, blacklist);
    for (Feature feature : features.getFeature()) {
        assertFalse(feature.getId().startsWith("spring/"));
    }
}
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)

Aggregations

Feature (org.apache.karaf.features.internal.model.Feature)25 Features (org.apache.karaf.features.internal.model.Features)16 ArrayList (java.util.ArrayList)10 Bundle (org.apache.karaf.features.internal.model.Bundle)9 ConfigFile (org.apache.karaf.features.internal.model.ConfigFile)8 HashMap (java.util.HashMap)7 Downloader (org.apache.karaf.features.internal.download.Downloader)6 Dependency (org.apache.karaf.features.internal.model.Dependency)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 File (java.io.File)4 URL (java.net.URL)4 LinkedHashSet (java.util.LinkedHashSet)4 Properties (org.apache.felix.utils.properties.Properties)4 Conditional (org.apache.karaf.features.internal.model.Conditional)4 Profile (org.apache.karaf.profile.Profile)4 Test (org.junit.Test)4 Hashtable (java.util.Hashtable)3 LinkedHashMap (java.util.LinkedHashMap)3