Search in sources :

Example 1 with Features

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

the class Builder method startupStage.

private Profile startupStage(Profile startupProfile) throws Exception {
    LOGGER.info("Startup stage");
    //
    // Compute startup
    //
    Profile startupOverlay = Profiles.getOverlay(startupProfile, allProfiles, environment);
    Profile startupEffective = Profiles.getEffective(startupOverlay, false);
    // Load startup repositories
    LOGGER.info("   Loading repositories");
    Map<String, Features> startupRepositories = loadRepositories(manager, startupEffective.getRepositories(), false);
    //
    // Resolve
    //
    LOGGER.info("   Resolving features");
    Map<String, Integer> bundles = resolve(manager, resolver, startupRepositories.values(), startupEffective.getFeatures(), startupEffective.getBundles(), startupEffective.getOverrides(), startupEffective.getOptionals());
    //
    // Generate startup.properties
    //
    Properties startup = new Properties();
    startup.setHeader(Collections.singletonList("# Bundles to be started on startup, with startlevel"));
    Map<Integer, Set<String>> invertedStartupBundles = MapUtils.invert(bundles);
    for (Map.Entry<Integer, Set<String>> entry : new TreeMap<>(invertedStartupBundles).entrySet()) {
        String startLevel = Integer.toString(entry.getKey());
        for (String location : new TreeSet<>(entry.getValue())) {
            if (useReferenceUrls) {
                if (location.startsWith("mvn:")) {
                    location = "file:" + Parser.pathFromMaven(location);
                }
                if (location.startsWith("file:")) {
                    location = "reference:" + location;
                }
            }
            if (location.startsWith("file:") && karafVersion == KarafVersion.v24) {
                location = location.substring("file:".length());
            }
            startup.put(location, startLevel);
        }
    }
    Path startupProperties = etcDirectory.resolve("startup.properties");
    startup.save(startupProperties.toFile());
    return startupEffective;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Properties(org.apache.felix.utils.properties.Properties) Profile(org.apache.karaf.profile.Profile) TreeSet(java.util.TreeSet) Features(org.apache.karaf.features.internal.model.Features) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 2 with Features

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

the class GenerateDescriptorMojoTest method testReadXml1.

@Test
public void testReadXml1() throws Exception {
    URL url = getClass().getClassLoader().getResource("input-features-1.1.0.xml");
    Features featuresRoot = JaxbUtil.unmarshal(url.toExternalForm(), false);
    List<Feature> featuresList = featuresRoot.getFeature();
    assertEquals(featuresList.size(), 1);
    Feature feature = featuresList.get(0);
    assertEquals(feature.getInstall(), "auto");
}
Also used : 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 3 with Features

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

the class GenerateDescriptorMojo method saveDependencyChanges.

protected void saveDependencyChanges(Collection<Bundle> addedBundles, Collection<Bundle> removedBundles, Collection<Dependency> addedDependencys, Collection<Dependency> removedDependencys, ObjectFactory objectFactory) throws Exception {
    File addedFile = new File(filteredDependencyCache.getParentFile(), "dependencies.added.xml");
    Features added = toFeatures(addedBundles, addedDependencys, objectFactory);
    writeDependencies(added, addedFile);
    File removedFile = new File(filteredDependencyCache.getParentFile(), "dependencies.removed.xml");
    Features removed = toFeatures(removedBundles, removedDependencys, objectFactory);
    writeDependencies(removed, removedFile);
    StringWriter out = new StringWriter();
    out.write(saveTreeListing());
    out.write("Dependencies have changed:\n");
    if (!addedBundles.isEmpty() || !addedDependencys.isEmpty()) {
        out.write("\tAdded dependencies are saved here: " + addedFile.getAbsolutePath() + "\n");
        if (logDependencyChanges) {
            JaxbUtil.marshal(added, out);
        }
    }
    if (!removedBundles.isEmpty() || !removedDependencys.isEmpty()) {
        out.write("\tRemoved dependencies are saved here: " + removedFile.getAbsolutePath() + "\n");
        if (logDependencyChanges) {
            JaxbUtil.marshal(removed, out);
        }
    }
    out.write("Delete " + dependencyCache.getAbsolutePath() + " if you are happy with the dependency changes.");
    if (failOnDependencyChange) {
        throw new MojoFailureException(out.toString());
    } else {
        getLog().warn(out.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Features(org.apache.karaf.features.internal.model.Features) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) File(java.io.File)

Example 4 with Features

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

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

the class FeaturesValidationTest method testNs11Unmarshall.

@Test
public void testNs11Unmarshall() throws Exception {
    URL url = getClass().getResource("f04.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