Search in sources :

Example 1 with Dependency

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

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

the class GenerateDescriptorMojo method processFeatureArtifact.

private void processFeatureArtifact(Features features, Feature feature, Map<Dependency, Feature> otherFeatures, Map<Feature, String> featureRepositories, Object artifact, Object parent, boolean add) throws MojoExecutionException, XMLStreamException, JAXBException, IOException {
    if (this.dependencyHelper.isArtifactAFeature(artifact) && FEATURE_CLASSIFIER.equals(this.dependencyHelper.getClassifier(artifact))) {
        File featuresFile = this.dependencyHelper.resolve(artifact, getLog());
        if (featuresFile == null || !featuresFile.exists()) {
            throw new MojoExecutionException("Cannot locate file for feature: " + artifact + " at " + featuresFile);
        }
        Features includedFeatures = readFeaturesFile(featuresFile);
        for (String repository : includedFeatures.getRepository()) {
            processFeatureArtifact(features, feature, otherFeatures, featureRepositories, new DefaultArtifact(MavenUtil.mvnToAether(repository)), parent, false);
        }
        for (Feature includedFeature : includedFeatures.getFeature()) {
            Dependency dependency = new Dependency(includedFeature.getName(), includedFeature.getVersion());
            dependency.setPrerequisite(prerequisiteFeatures.contains(dependency.getName()));
            dependency.setDependency(dependencyFeatures.contains(dependency.getName()));
            // Determine what dependency we're actually going to use
            Dependency matchingDependency = findMatchingDependency(feature.getFeature(), dependency);
            if (matchingDependency != null) {
                // The feature already has a matching dependency, merge
                mergeDependencies(matchingDependency, dependency);
                dependency = matchingDependency;
            }
            // We mustn't de-duplicate here, we may have seen a feature in !add mode
            otherFeatures.put(dependency, includedFeature);
            if (add) {
                if (!feature.getFeature().contains(dependency)) {
                    feature.getFeature().add(dependency);
                }
                if (aggregateFeatures) {
                    features.getFeature().add(includedFeature);
                }
            }
            if (!featureRepositories.containsKey(includedFeature)) {
                featureRepositories.put(includedFeature, this.dependencyHelper.artifactToMvn(artifact, getVersionOrRange(parent, artifact)));
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Features(org.apache.karaf.features.internal.model.Features) Dependency(org.apache.karaf.features.internal.model.Dependency) LocalDependency(org.apache.karaf.tooling.utils.LocalDependency) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) File(java.io.File) Feature(org.apache.karaf.features.internal.model.Feature) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 3 with Dependency

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

the class AbstractFeatureMojo method addFeaturesDependencies.

protected void addFeaturesDependencies(List<Dependency> featureNames, Set<Feature> features, Map<String, Feature> featuresMap, boolean transitive) {
    for (Dependency dependency : featureNames) {
        Feature f = getMatchingFeature(featuresMap, dependency.getName(), dependency.getVersion());
        features.add(f);
        if (transitive) {
            addFeaturesDependencies(f.getFeature(), features, featuresMap, true);
        }
    }
}
Also used : Dependency(org.apache.karaf.features.internal.model.Dependency) Feature(org.apache.karaf.features.internal.model.Feature)

Example 4 with Dependency

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

the class Builder method createDependency.

private Dependency createDependency(String dependency) {
    Dependency dep;
    dep = new Dependency();
    String[] split = dependency.split("/");
    dep.setName(split[0]);
    if (split.length > 1) {
        dep.setVersion(split[1]);
    }
    return dep;
}
Also used : Dependency(org.apache.karaf.features.internal.model.Dependency)

Example 5 with Dependency

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

the class Builder method addFeatures.

private void addFeatures(Set<Feature> allFeatures, String feature, Set<Feature> features, boolean mandatory) {
    String name;
    VersionRange range;
    int idx = feature.indexOf('/');
    if (idx > 0) {
        name = feature.substring(0, idx);
        String version = feature.substring(idx + 1);
        version = version.trim();
        if (version.equals(org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)) {
            range = new VersionRange(Version.emptyVersion);
        } else {
            range = new VersionRange(version, true, true);
        }
    } else {
        name = feature;
        range = new VersionRange(Version.emptyVersion);
    }
    Set<Feature> set = allFeatures.stream().filter(f -> f.getName().equals(name) && range.contains(VersionTable.getVersion(f.getVersion()))).collect(Collectors.toSet());
    if (mandatory && set.isEmpty()) {
        throw new IllegalStateException("Could not find matching feature for " + feature);
    }
    for (Feature f : set) {
        features.add(f);
        for (Dependency dep : f.getFeature()) {
            addFeatures(allFeatures, dep.toString(), features, !dep.isDependency() && !dep.isPrerequisite());
        }
    }
}
Also used : Manifest(java.util.jar.Manifest) Dependency(org.apache.karaf.features.internal.model.Dependency) Profile(org.apache.karaf.profile.Profile) Arrays(java.util.Arrays) Constants(org.osgi.framework.Constants) KarafPropertiesEditor(org.apache.karaf.tools.utils.KarafPropertiesEditor) LoggerFactory(org.slf4j.LoggerFactory) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) FeaturesService(org.apache.karaf.features.FeaturesService) java.nio.file(java.nio.file) DownloadManagerHelper(org.apache.karaf.features.internal.download.impl.DownloadManagerHelper) Clause(org.apache.felix.utils.manifest.Clause) ByteArrayInputStream(java.io.ByteArrayInputStream) JaxbUtil(org.apache.karaf.features.internal.model.JaxbUtil) Map(java.util.Map) URI(java.net.URI) VersionTable(org.apache.felix.utils.version.VersionTable) ZipEntry(java.util.zip.ZipEntry) BundleRevision(org.osgi.framework.wiring.BundleRevision) EnumSet(java.util.EnumSet) MavenResolver(org.ops4j.pax.url.mvn.MavenResolver) Blacklist(org.apache.karaf.features.internal.service.Blacklist) Deployer(org.apache.karaf.features.internal.service.Deployer) MapUtils(org.apache.karaf.features.internal.util.MapUtils) Collection(java.util.Collection) Set(java.util.Set) MANIFEST_NAME(java.util.jar.JarFile.MANIFEST_NAME) UUID(java.util.UUID) Library(org.apache.karaf.features.Library) Version(org.osgi.framework.Version) Attributes(java.util.jar.Attributes) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) VersionRange(org.apache.felix.utils.version.VersionRange) List(java.util.List) PropertiesLoader(org.apache.karaf.util.config.PropertiesLoader) Properties(org.apache.felix.utils.properties.Properties) Pattern(java.util.regex.Pattern) DownloadManager(org.apache.karaf.features.internal.download.DownloadManager) Features(org.apache.karaf.features.internal.model.Features) Dictionary(java.util.Dictionary) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DownloadCallback(org.apache.karaf.features.internal.download.DownloadCallback) HashMap(java.util.HashMap) ResourceBuilder(org.apache.karaf.features.internal.resolver.ResourceBuilder) Kar(org.apache.karaf.kar.internal.Kar) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StreamProvider(org.apache.karaf.features.internal.download.StreamProvider) ProfileBuilder(org.apache.karaf.profile.ProfileBuilder) Parser(org.apache.karaf.util.maven.Parser) BaseRepository(org.apache.karaf.features.internal.repository.BaseRepository) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Bundle(org.apache.karaf.features.internal.model.Bundle) MavenResolvers(org.ops4j.pax.url.mvn.MavenResolvers) VersionUtils(org.apache.karaf.profile.versioning.VersionUtils) Downloader(org.apache.karaf.features.internal.download.Downloader) TYPE_REPOSITORY(org.apache.karaf.features.internal.service.Blacklist.TYPE_REPOSITORY) Content(org.apache.karaf.features.internal.model.Content) Hashtable(java.util.Hashtable) LinkedHashSet(java.util.LinkedHashSet) Logger(org.slf4j.Logger) Profiles(org.apache.karaf.profile.impl.Profiles) MalformedURLException(java.net.MalformedURLException) Conditional(org.apache.karaf.features.internal.model.Conditional) Resource(org.osgi.resource.Resource) IOException(java.io.IOException) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Resolver(org.osgi.service.resolver.Resolver) KarafPropertyEdits(org.apache.karaf.tools.utils.model.KarafPropertyEdits) File(java.io.File) TreeMap(java.util.TreeMap) Feature(org.apache.karaf.features.internal.model.Feature) Config(org.apache.karaf.features.internal.model.Config) Startup(org.apache.karaf.profile.assembly.Builder.Stage.Startup) Collections(java.util.Collections) InputStream(java.io.InputStream) VersionRange(org.apache.felix.utils.version.VersionRange) Dependency(org.apache.karaf.features.internal.model.Dependency) Feature(org.apache.karaf.features.internal.model.Feature)

Aggregations

Dependency (org.apache.karaf.features.internal.model.Dependency)11 Feature (org.apache.karaf.features.internal.model.Feature)10 Features (org.apache.karaf.features.internal.model.Features)7 File (java.io.File)6 ConfigFile (org.apache.karaf.features.internal.model.ConfigFile)6 Bundle (org.apache.karaf.features.internal.model.Bundle)5 LocalDependency (org.apache.karaf.tooling.utils.LocalDependency)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Conditional (org.apache.karaf.features.internal.model.Conditional)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Properties (org.apache.felix.utils.properties.Properties)3 Library (org.apache.karaf.features.Library)3