karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Pieber <anpie...@gmail.com>
Subject Re: svn commit: r1098893 - in /karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features: DependencyHelper.java GenerateFeaturesXmlMojo2.java GraphArtifactCollector.java
Date Tue, 03 May 2011 02:50:24 GMT
Hey,

Just because I've seen it on some classes: @version $Rev:$ $Date:$

I mean, I have no problem using it, but we should decide (and
document) if we want to use it so that we can be consistent here...

Kind regards,
Andreas

On Tue, May 3, 2011 at 4:13 AM,  <djencks@apache.org> wrote:
> Author: djencks
> Date: Tue May  3 02:13:48 2011
> New Revision: 1098893
>
> URL: http://svn.apache.org/viewvc?rev=1098893&view=rev
> Log:
> KARAF-424 Remove unused class, separate out transitive dependency computation for reuse
in geronimo
>
> Added:
>    karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
  (with props)
> Removed:
>    karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GraphArtifactCollector.java
> Modified:
>    karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java
>
> Added: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java?rev=1098893&view=auto
> ==============================================================================
> --- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
(added)
> +++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
Tue May  3 02:13:48 2011
> @@ -0,0 +1,239 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *  http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +
> +
> +package org.apache.karaf.tooling.features;
> +
> +import java.util.ArrayList;
> +import java.util.LinkedHashMap;
> +import java.util.LinkedHashSet;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Set;
> +
> +import org.apache.maven.RepositoryUtils;
> +import org.apache.maven.plugin.MojoExecutionException;
> +import org.apache.maven.plugin.logging.Log;
> +import org.apache.maven.plugin.logging.SystemStreamLog;
> +import org.apache.maven.project.MavenProject;
> +import org.sonatype.aether.RepositorySystem;
> +import org.sonatype.aether.RepositorySystemSession;
> +import org.sonatype.aether.artifact.Artifact;
> +import org.sonatype.aether.collection.CollectRequest;
> +import org.sonatype.aether.collection.CollectResult;
> +import org.sonatype.aether.collection.DependencyCollectionException;
> +import org.sonatype.aether.collection.DependencyGraphTransformer;
> +import org.sonatype.aether.graph.Dependency;
> +import org.sonatype.aether.graph.DependencyNode;
> +import org.sonatype.aether.repository.RemoteRepository;
> +import org.sonatype.aether.util.DefaultRepositorySystemSession;
> +import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
> +import org.sonatype.aether.util.graph.transformer.ConflictMarker;
> +import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
> +import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
> +
> +import static org.apache.karaf.deployer.kar.KarArtifactInstaller.FEATURE_CLASSIFIER;
> +
> +/**
> + * @version $Rev:$ $Date:$
> + */
> +public class DependencyHelper {
> +
> +    /**
> +      * The entry point to Aether, i.e. the component doing all the work.
> +      *
> +      * @component
> +      * @required
> +      * @readonly
> +      */
> +     private final RepositorySystem repoSystem;
> +
> +     /**
> +      * The current repository/network configuration of Maven.
> +      *
> +      * @parameter default-value="${repositorySystemSession}"
> +      * @required
> +      * @readonly
> +      */
> +     private final RepositorySystemSession repoSession;
> +
> +     /**
> +      * The project's remote repositories to use for the resolution of project dependencies.
> +      *
> +      * @parameter default-value="${project.remoteProjectRepositories}"
> +      * @readonly
> +      */
> +     private final List<RemoteRepository> projectRepos;
> +
> +     /**
> +      * The project's remote repositories to use for the resolution of plugins and
their dependencies.
> +      *
> +      * @parameter default-value="${project.remotePluginRepositories}"
> +      * @required
> +      * @readonly
> +      */
> +     private final List<RemoteRepository> pluginRepos;
> +
> +    //dependencies we are interested in
> +    protected Map<Artifact, String> localDependencies;
> +    //log of what happened during search
> +    protected String treeListing;
> +
> +
> +
> +    public DependencyHelper(List<RemoteRepository> pluginRepos, List<RemoteRepository>
projectRepos, RepositorySystemSession repoSession, RepositorySystem repoSystem) {
> +        this.pluginRepos = pluginRepos;
> +        this.projectRepos = projectRepos;
> +        this.repoSession = repoSession;
> +        this.repoSystem = repoSystem;
> +    }
> +
> +    public Map<Artifact, String> getLocalDependencies() {
> +        return localDependencies;
> +    }
> +
> +    public String getTreeListing() {
> +        return treeListing;
> +    }
> +
> +    //artifact search code adapted from geronimo car plugin
> +
> +    public void getDependencies(MavenProject project, boolean useTransitiveDependencies)
throws MojoExecutionException {
> +
> +        DependencyNode rootNode = getDependencyTree(RepositoryUtils.toArtifact(project.getArtifact()));
> +
> +        Scanner scanner = new Scanner();
> +        scanner.scan(rootNode, useTransitiveDependencies);
> +        localDependencies = scanner.localDependencies;
> +        treeListing = scanner.getLog();
> +    }
> +
> +    private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException
{
> +        try {
> +            List<org.sonatype.aether.graph.Dependency> managedArtifacts
= new ArrayList<Dependency>();
> +            CollectRequest collectRequest = new CollectRequest(new org.sonatype.aether.graph.Dependency(artifact,
"compile"), null, projectRepos);
> +            DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repoSession);
> +            DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new
ConflictMarker(),
> +                    new JavaEffectiveScopeCalculator(),
> +                    new JavaDependencyContextRefiner());
> +            session.setDependencyGraphTransformer(transformer);
> +            CollectResult result = repoSystem.collectDependencies(session, collectRequest);
> +            return result.getRoot();
> +        } catch (DependencyCollectionException e) {
> +            throw new MojoExecutionException("Cannot build project dependency
tree", e);
> +        }
> +    }
> +
> +
> +    private static class Scanner {
> +
> +        private static enum Accept {
> +            ACCEPT(true, true),
> +            PROVIDED(true, false),
> +            STOP(false, false);
> +
> +            private final boolean more;
> +            private final boolean local;
> +
> +            private Accept(boolean more, boolean local) {
> +                this.more = more;
> +                this.local = local;
> +            }
> +
> +            public boolean isContinue() {
> +                return more;
> +            }
> +
> +            public boolean isLocal() {
> +                return local;
> +            }
> +        }
> +
> +        //all the dependencies needed for this car, with provided dependencies removed.
artifact to scope map
> +        private final Map<Artifact, String> localDependencies = new LinkedHashMap<Artifact,
String>();
> +        //dependencies from ancestor cars, to be removed from localDependencies.
> +        private final Set<Artifact> carDependencies = new LinkedHashSet<Artifact>();
> +
> +        private final StringBuilder log = new StringBuilder();
> +
> +        public void scan(DependencyNode rootNode, boolean useTransitiveDependencies)
throws MojoExecutionException {
> +            for (DependencyNode child : rootNode.getChildren()) {
> +                scan(child, Accept.ACCEPT, useTransitiveDependencies, false,
"");
> +            }
> +            if (useTransitiveDependencies) {
> +                localDependencies.keySet().removeAll(carDependencies);
> +            }
> +        }
> +
> +        private void scan(DependencyNode dependencyNode, Accept parentAccept, boolean
useTransitiveDependencies, boolean isFromFeature, String indent) throws MojoExecutionException
{
> +//            Artifact artifact = getArtifact(rootNode);
> +
> +            Accept accept = accept(dependencyNode, parentAccept);
> +            if (accept.isContinue()) {
> +                List<DependencyNode> children = dependencyNode.getChildren();
> +                if (isFromFeature) {
> +                    if (!isFeature(dependencyNode)) {
> +                        log.append(indent).append("from feature:").append(dependencyNode).append("\n");
> +                        carDependencies.add(dependencyNode.getDependency().getArtifact());
> +                    } else {
> +                        log.append(indent).append("is feature:").append(dependencyNode).append("\n");
> +                    }
> +                } else {
> +                    log.append(indent).append("local:").append(dependencyNode).append("\n");
> +                    if (carDependencies.contains(dependencyNode.getDependency().getArtifact()))
{
> +                        log.append(indent).append("already in feature, returning:").append(dependencyNode).append("\n");
> +                        return;
> +                    }
> +                    //TODO resolve scope conflicts
> +                    localDependencies.put(dependencyNode.getDependency().getArtifact(),
dependencyNode.getDependency().getScope());
> +                    if (isFeature(dependencyNode) || !useTransitiveDependencies)
{
> +                        isFromFeature = true;
> +                    }
> +                }
> +                for (DependencyNode child : children) {
> +                    scan(child, accept, useTransitiveDependencies, isFromFeature,
indent + "  ");
> +                }
> +            }
> +        }
> +
> +
> +        public String getLog() {
> +            return log.toString();
> +        }
> +
> +        private Accept accept(DependencyNode dependency, Accept previous) {
> +            String scope = dependency.getPremanagedScope();
> +            if (scope == null || "runtime".equalsIgnoreCase(scope) || "compile".equalsIgnoreCase(scope))
{
> +                return previous;
> +            }
> +            return Accept.STOP;
> +        }
> +
> +    }
> +
> +    public static boolean isFeature(DependencyNode dependencyNode) {
> +        return isFeature(dependencyNode.getDependency().getArtifact());
> +    }
> +
> +    public static boolean isFeature(Artifact artifact) {
> +        return artifact.getExtension().equals("kar") || FEATURE_CLASSIFIER.equals(artifact.getClassifier());
> +    }
> +
> +
> +}
>
> Propchange: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Revision
>
> Propchange: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java?rev=1098893&r1=1098892&r2=1098893&view=diff
> ==============================================================================
> --- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java
(original)
> +++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java
Tue May  3 02:13:48 2011
> @@ -31,22 +31,18 @@ import java.util.ArrayList;
>  import java.util.Collection;
>  import java.util.Collections;
>  import java.util.Comparator;
> -import java.util.LinkedHashMap;
> -import java.util.LinkedHashSet;
>  import java.util.List;
>  import java.util.Map;
> -import java.util.Set;
>
>  import javax.xml.bind.JAXBException;
>  import javax.xml.parsers.ParserConfigurationException;
>  import javax.xml.stream.XMLStreamException;
> +import org.apache.karaf.features.internal.model.Bundle;
>  import org.apache.karaf.features.internal.model.Dependency;
>  import org.apache.karaf.features.internal.model.Feature;
> -import org.apache.karaf.features.internal.model.Bundle;
>  import org.apache.karaf.features.internal.model.Features;
>  import org.apache.karaf.features.internal.model.JaxbUtil;
>  import org.apache.karaf.features.internal.model.ObjectFactory;
> -import org.apache.maven.RepositoryUtils;
>  import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
>  import org.apache.maven.artifact.resolver.ArtifactResolutionException;
>  import org.apache.maven.execution.MavenSession;
> @@ -66,19 +62,9 @@ import org.codehaus.plexus.util.StringUt
>  import org.sonatype.aether.RepositorySystem;
>  import org.sonatype.aether.RepositorySystemSession;
>  import org.sonatype.aether.artifact.Artifact;
> -import org.sonatype.aether.collection.CollectRequest;
> -import org.sonatype.aether.collection.CollectResult;
> -import org.sonatype.aether.collection.DependencyCollectionException;
> -import org.sonatype.aether.collection.DependencyGraphTransformer;
> -import org.sonatype.aether.graph.DependencyNode;
>  import org.sonatype.aether.repository.RemoteRepository;
>  import org.sonatype.aether.resolution.ArtifactRequest;
>  import org.sonatype.aether.resolution.ArtifactResult;
> -import org.sonatype.aether.util.DefaultRepositorySystemSession;
> -import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
> -import org.sonatype.aether.util.graph.transformer.ConflictMarker;
> -import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
> -import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
>  import org.xml.sax.SAXException;
>
>  import static org.apache.karaf.deployer.kar.KarArtifactInstaller.FEATURE_CLASSIFIER;
> @@ -223,7 +209,10 @@ public class GenerateFeaturesXmlMojo2 ex
>
>     public void execute() throws MojoExecutionException, MojoFailureException {
>         try {
> -            getDependencies(project, true);
> +            DependencyHelper dependencyHelper = new DependencyHelper(pluginRepos,
projectRepos, repoSession, repoSystem);
> +            dependencyHelper.getDependencies(project, true);
> +            this.localDependencies = dependencyHelper.getLocalDependencies();
> +            this.treeListing = dependencyHelper.getTreeListing();
>             File dir = outputFile.getParentFile();
>             if (dir.isDirectory() || dir.mkdirs()) {
>                 PrintStream out = new PrintStream(new FileOutputStream(outputFile));
> @@ -277,7 +266,7 @@ public class GenerateFeaturesXmlMojo2 ex
>         feature.setResolver(resolver);
>         for (Map.Entry<Artifact, String> entry : localDependencies.entrySet())
{
>             Artifact artifact = entry.getKey();
> -            if (isFeature(artifact)) {
> +            if (DependencyHelper.isFeature(artifact)) {
>                 if (aggregateFeatures && FEATURE_CLASSIFIER.equals(artifact.getClassifier()))
{
>                     File featuresFile = resolve(artifact);
>                     if (featuresFile == null || !featuresFile.exists()) {
> @@ -355,35 +344,6 @@ public class GenerateFeaturesXmlMojo2 ex
>         return features;
>     }
>
> -
> -    //artifact search code adapted from geronimo car plugin
> -
> -    protected void getDependencies(MavenProject project, boolean useTransitiveDependencies)
throws MojoExecutionException {
> -
> -        DependencyNode rootNode = getDependencyTree(RepositoryUtils.toArtifact(project.getArtifact()));
> -
> -        Scanner scanner = new Scanner();
> -        scanner.scan(rootNode, useTransitiveDependencies);
> -        localDependencies = scanner.localDependencies;
> -        treeListing = scanner.getLog();
> -    }
> -
> -    private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException
{
> -        try {
> -            List<org.sonatype.aether.graph.Dependency> managedArtifacts
= new ArrayList<org.sonatype.aether.graph.Dependency>();
> -            CollectRequest collectRequest = new CollectRequest(new org.sonatype.aether.graph.Dependency(artifact,
"compile"), null, projectRepos);
> -            DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repoSession);
> -            DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new
ConflictMarker(),
> -                    new JavaEffectiveScopeCalculator(),
> -                    new JavaDependencyContextRefiner());
> -            session.setDependencyGraphTransformer(transformer);
> -            CollectResult result = repoSystem.collectDependencies(session, collectRequest);
> -            return result.getRoot();
> -        } catch (DependencyCollectionException e) {
> -            throw new MojoExecutionException("Cannot build project dependency
tree", e);
> -        }
> -    }
> -
>     public void setLog(Log log) {
>         this.log = log;
>     }
> @@ -396,99 +356,6 @@ public class GenerateFeaturesXmlMojo2 ex
>     }
>
>
> -    private static class Scanner {
> -
> -        private static enum Accept {
> -            ACCEPT(true, true),
> -            PROVIDED(true, false),
> -            STOP(false, false);
> -
> -            private final boolean more;
> -            private final boolean local;
> -
> -            private Accept(boolean more, boolean local) {
> -                this.more = more;
> -                this.local = local;
> -            }
> -
> -            public boolean isContinue() {
> -                return more;
> -            }
> -
> -            public boolean isLocal() {
> -                return local;
> -            }
> -        }
> -
> -        //all the dependencies needed for this car, with provided dependencies removed.
artifact to scope map
> -        private final Map<Artifact, String> localDependencies = new LinkedHashMap<Artifact,
String>();
> -        //dependencies from ancestor cars, to be removed from localDependencies.
> -        private final Set<Artifact> carDependencies = new LinkedHashSet<Artifact>();
> -
> -        private final StringBuilder log = new StringBuilder();
> -
> -        public void scan(DependencyNode rootNode, boolean useTransitiveDependencies)
throws MojoExecutionException {
> -            for (DependencyNode child : rootNode.getChildren()) {
> -                scan(child, Accept.ACCEPT, useTransitiveDependencies, false,
"");
> -            }
> -            if (useTransitiveDependencies) {
> -                localDependencies.keySet().removeAll(carDependencies);
> -            }
> -        }
> -
> -        private void scan(DependencyNode dependencyNode, Accept parentAccept, boolean
useTransitiveDependencies, boolean isFromFeature, String indent) throws MojoExecutionException
{
> -//            Artifact artifact = getArtifact(rootNode);
> -
> -            Accept accept = accept(dependencyNode, parentAccept);
> -            if (accept.isContinue()) {
> -                List<DependencyNode> children = dependencyNode.getChildren();
> -                if (isFromFeature) {
> -                    if (!isFeature(dependencyNode)) {
> -                        log.append(indent).append("from feature:").append(dependencyNode).append("\n");
> -                        carDependencies.add(dependencyNode.getDependency().getArtifact());
> -                    } else {
> -                        log.append(indent).append("is feature:").append(dependencyNode).append("\n");
> -                    }
> -                } else {
> -                    log.append(indent).append("local:").append(dependencyNode).append("\n");
> -                    if (carDependencies.contains(dependencyNode.getDependency().getArtifact()))
{
> -                        log.append(indent).append("already in feature, returning:").append(dependencyNode).append("\n");
> -                        return;
> -                    }
> -                    //TODO resolve scope conflicts
> -                    localDependencies.put(dependencyNode.getDependency().getArtifact(),
dependencyNode.getDependency().getScope());
> -                    if (isFeature(dependencyNode) || !useTransitiveDependencies)
{
> -                        isFromFeature = true;
> -                    }
> -                }
> -                for (DependencyNode child : children) {
> -                    scan(child, accept, useTransitiveDependencies, isFromFeature,
indent + "  ");
> -                }
> -            }
> -        }
> -
> -
> -        public String getLog() {
> -            return log.toString();
> -        }
> -
> -        private Accept accept(DependencyNode dependency, Accept previous) {
> -            String scope = dependency.getPremanagedScope();
> -            if (scope == null || "runtime".equalsIgnoreCase(scope) || "compile".equalsIgnoreCase(scope))
{
> -                return previous;
> -            }
> -            return Accept.STOP;
> -        }
> -
> -    }
> -
> -    private static boolean isFeature(DependencyNode dependencyNode) {
> -        return isFeature(dependencyNode.getDependency().getArtifact());
> -    }
> -
> -    private static boolean isFeature(Artifact artifact) {
> -        return artifact.getExtension().equals("kar") || FEATURE_CLASSIFIER.equals(artifact.getClassifier());
> -    }
>
>     //------------------------------------------------------------------------//
>     // dependency change detection
>
>
>

Mime
View raw message