maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r453073 - in /maven/sandbox/maven-artifact-tools: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/artifact/ src/main/java/org/apache/maven/artifact...
Date Thu, 05 Oct 2006 00:47:01 GMT
Author: jdcasey
Date: Wed Oct  4 17:46:58 2006
New Revision: 453073

URL: http://svn.apache.org/viewvc?view=rev&rev=453073
Log:
First attempt at a convenience API for resolving artifacts.

Added:
    maven/sandbox/maven-artifact-tools/
    maven/sandbox/maven-artifact-tools/pom.xml   (with props)
    maven/sandbox/maven-artifact-tools/src/
    maven/sandbox/maven-artifact-tools/src/main/
    maven/sandbox/maven-artifact-tools/src/main/java/
    maven/sandbox/maven-artifact-tools/src/main/java/org/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java
  (with props)
    maven/sandbox/maven-artifact-tools/src/test/
    maven/sandbox/maven-artifact-tools/src/test/java/
    maven/sandbox/maven-artifact-tools/src/test/java/org/
    maven/sandbox/maven-artifact-tools/src/test/java/org/apache/
    maven/sandbox/maven-artifact-tools/src/test/java/org/apache/maven/
    maven/sandbox/maven-artifact-tools/src/test/java/org/apache/maven/artifact/
    maven/sandbox/maven-artifact-tools/src/test/java/org/apache/maven/artifact/tools/

Added: maven/sandbox/maven-artifact-tools/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/pom.xml?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/pom.xml (added)
+++ maven/sandbox/maven-artifact-tools/pom.xml Wed Oct  4 17:46:58 2006
@@ -0,0 +1,90 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven</groupId>
+  <artifactId>maven-artifact-tools</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Maven Artifact-Access Tools</name>
+  <url>http://maven.apache.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact-manager</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>create-component-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <!--  Nothing to merge on this project, yet.
+          <execution>
+            <id>merge</id>
+            <configuration>
+              <output>${project.build.outputDirectory}/META-INF/plexus/components.xml</output>
+              <descriptors>
+                <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
+                <descriptor>src/main/resources/META-INF/plexus/components.xml</descriptor>
+              </descriptors>
+            </configuration>
+            <goals>
+              <goal>merge-descriptors</goal>
+            </goals>
+          </execution>
+           -->
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <descriptorRefs>
+            <descriptorRef>jar-with-dependencies</descriptorRef>
+          </descriptorRefs>
+        </configuration>
+
+        <executions>
+          <execution>
+            <id>make-assembly</id>
+            <phase>package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <pluginRepositories>
+    <pluginRepository>
+      <id>apache.snapshots</id>
+      <url>http://people.apache.org/repo/m2-snapshot-repository</url>
+    </pluginRepository>
+  </pluginRepositories>
+</project>

Propchange: maven/sandbox/maven-artifact-tools/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,19 @@
+package org.apache.maven.artifact.tools;
+
+public class InvalidConfigurationException
+    extends Exception
+{
+
+    private static final long serialVersionUID = 1L;
+
+    public InvalidConfigurationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public InvalidConfigurationException( String message )
+    {
+        super( message );
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/InvalidConfigurationException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,14 @@
+package org.apache.maven.artifact.tools.components;
+
+public class ComponentAccessException
+    extends Exception
+{
+
+    private static final long serialVersionUID = 1L;
+
+    public ComponentAccessException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/ComponentAccessException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,132 @@
+package org.apache.maven.artifact.tools.components;
+
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.tools.InvalidConfigurationException;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.codehaus.plexus.DefaultPlexusContainer;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+
+/**
+ * @plexus.component role="org.apache.maven.artifact.tools.components" role-hint="default"
+ * 
+ * @author jdcasey
+ */
+public class MavenComponentAccess
+    implements Contextualizable
+{
+
+    public static final String ROLE = MavenComponentAccess.class.getName();
+
+    /**
+     * @plexus.requirement
+     */
+    private MavenSettingsBuilder settingsBuilder;
+
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactResolver artifactResolver;
+
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactHandlerManager artifactHandlerManager;
+    
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactRepositoryFactory artifactRepositoryFactory;
+    
+    /**
+     * @plexus.requirement
+     */
+    private MavenProjectBuilder mavenProjectBuilder;
+    
+    private PlexusContainer container;
+
+    private static MavenComponentAccess staticInstance;
+
+    public static MavenComponentAccess create()
+        throws ComponentAccessException
+    {
+        if ( staticInstance == null )
+        {
+            PlexusContainer container = new DefaultPlexusContainer();
+
+            try
+            {
+                container.start();
+            }
+            catch ( PlexusContainerException e )
+            {
+                throw new ComponentAccessException( "Failed to start plexus container for
maven artifact tooling.", e );
+            }
+            
+            try
+            {
+                staticInstance = (MavenComponentAccess) container.lookup( ROLE );
+            }
+            catch ( ComponentLookupException e )
+            {
+                throw new ComponentAccessException( "Failed to lookup components necessary
for maven artifact tooling.", e );
+            }
+        }
+
+        return staticInstance;
+    }
+    
+    public ArtifactRepositoryLayout getArtifactRepositoryLayout( String layoutId )
+        throws InvalidConfigurationException
+    {
+        try
+        {
+            return (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
layoutId );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new InvalidConfigurationException( "Invalid Maven repository layout: \'"
+ layoutId + "\'.", e );
+        }
+    }
+
+    public ArtifactHandlerManager getArtifactHandlerManager()
+    {
+        return artifactHandlerManager;
+    }
+
+    public ArtifactResolver getArtifactResolver()
+    {
+        return artifactResolver;
+    }
+
+    public MavenSettingsBuilder getSettingsBuilder()
+    {
+        return settingsBuilder;
+    }
+
+    public ArtifactRepositoryFactory getArtifactRepositoryFactory()
+    {
+        return artifactRepositoryFactory;
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+
+    public MavenProjectBuilder getMavenProjectBuilder()
+    {
+        return mavenProjectBuilder;
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/components/MavenComponentAccess.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,18 @@
+package org.apache.maven.artifact.tools.repository;
+
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.tools.InvalidConfigurationException;
+
+public interface ArtifactRepositorySource
+{
+
+    ArtifactRepository getLocalRepository()
+        throws InvalidConfigurationException;
+
+    List getArtifactRepositories();
+
+    ArtifactRepository getMirrorRepository( ArtifactRepository baseRepository );
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositorySource.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,33 @@
+package org.apache.maven.artifact.tools.repository;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.tools.InvalidConfigurationException;
+import org.apache.maven.artifact.tools.components.MavenComponentAccess;
+import org.apache.maven.settings.Mirror;
+
+public class ArtifactRepositoryTool
+{
+
+    public ArtifactRepository buildMirrorRepository( ArtifactRepository baseRepository, Mirror
mirror,
+                                                     MavenComponentAccess componentAccess
)
+    {
+        ArtifactRepositoryFactory repoFactory = componentAccess.getArtifactRepositoryFactory();
+
+        ArtifactRepository mirrorRepository = repoFactory.createArtifactRepository( baseRepository.getId(),
mirror
+            .getUrl(), baseRepository.getLayout(), baseRepository.getSnapshots(), baseRepository.getReleases()
);
+
+        return mirrorRepository;
+    }
+
+    public ArtifactRepository buildLocalRepository( String localRepositoryLocation, MavenComponentAccess
componentAccess )
+        throws InvalidConfigurationException
+    {
+        ArtifactRepositoryFactory repoFactory = componentAccess.getArtifactRepositoryFactory();
+        ArtifactRepositoryLayout repoLayout = componentAccess.getArtifactRepositoryLayout(
"default" );
+        
+        return repoFactory.createArtifactRepository( "local", localRepositoryLocation, repoLayout,
null, null );
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/ArtifactRepositoryTool.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,130 @@
+package org.apache.maven.artifact.tools.repository;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.tools.InvalidConfigurationException;
+import org.apache.maven.artifact.tools.components.MavenComponentAccess;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Mirror;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+public class MavenArtifactRepositorySource
+    implements ArtifactRepositorySource
+{
+
+    private final MavenProject project;
+
+    private final Settings settings;
+
+    private final boolean usePluginRepositories;
+
+    private ArtifactRepositoryTool repositoryTool = new ArtifactRepositoryTool();
+
+    // cache.
+    private ArtifactRepository localRepository;
+
+    private final MavenComponentAccess componentAccess;
+
+    public MavenArtifactRepositorySource( MavenProject project, File userSettingsLocation,
+                                          MavenComponentAccess componentAccess, boolean usePluginRepositories
)
+        throws InvalidConfigurationException
+    {
+        this.project = project;
+        this.componentAccess = componentAccess;
+        this.usePluginRepositories = usePluginRepositories;
+
+        try
+        {
+            if ( userSettingsLocation == null )
+            {
+                this.settings = componentAccess.getSettingsBuilder().buildSettings();
+            }
+            else
+            {
+                this.settings = componentAccess.getSettingsBuilder().buildSettings( userSettingsLocation
);
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new InvalidConfigurationException( "Error reading Maven settings.", e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new InvalidConfigurationException( "Error reading Maven settings.", e );
+        }
+    }
+
+    public List getArtifactRepositories()
+    {
+        List repos = new ArrayList();
+        List repoUrls = new ArrayList();
+
+        if ( usePluginRepositories )
+        {
+            List pluginRepos = project.getPluginArtifactRepositories();
+
+            for ( Iterator it = pluginRepos.iterator(); it.hasNext(); )
+            {
+                ArtifactRepository repo = (ArtifactRepository) it.next();
+
+                if ( !repoUrls.contains( repo.getUrl() ) )
+                {
+                    repos.add( repo );
+                }
+
+                repoUrls.add( repo.getUrl() );
+            }
+
+        }
+
+        List normalRepos = project.getRemoteArtifactRepositories();
+
+        for ( Iterator it = normalRepos.iterator(); it.hasNext(); )
+        {
+            ArtifactRepository repo = (ArtifactRepository) it.next();
+
+            if ( !repoUrls.contains( repo.getUrl() ) )
+            {
+                repos.add( repo );
+            }
+
+            repoUrls.add( repo.getUrl() );
+        }
+
+        return repos;
+    }
+
+    public ArtifactRepository getMirrorRepository( ArtifactRepository baseRepository )
+    {
+        Mirror mirror = settings.getMirrorOf( baseRepository.getId() );
+
+        ArtifactRepository mirrored = null;
+
+        if ( mirror != null )
+        {
+            mirrored = repositoryTool.buildMirrorRepository( baseRepository, mirror, componentAccess
);
+        }
+
+        return mirrored;
+    }
+
+    public ArtifactRepository getLocalRepository()
+        throws InvalidConfigurationException
+    {
+        if ( localRepository == null )
+        {
+            String localRepoLocation = settings.getLocalRepository();
+            
+            localRepository = repositoryTool.buildLocalRepository( localRepoLocation, componentAccess
);
+        }
+        
+        return localRepository;
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/repository/MavenArtifactRepositorySource.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,116 @@
+package org.apache.maven.artifact.tools.resolve;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+public class ArtifactQuery
+{
+
+    private final String artifactId;
+
+    private final String groupId;
+
+    private String version;
+
+    private String classifier;
+
+    private String type = "jar";
+
+    private String versionRangeSpec;
+
+    private String scope = Artifact.SCOPE_COMPILE;
+
+    private boolean isOptional = false;
+    
+    public ArtifactQuery( String groupId, String artifactId )
+    {
+        this.groupId = groupId;
+        this.artifactId = artifactId;
+    }
+    
+    public ArtifactQuery copy()
+    {
+        ArtifactQuery query = new ArtifactQuery( groupId, artifactId );
+        
+        query.version = version;
+        query.classifier = classifier;
+        query.type = type;
+        query.versionRangeSpec = versionRangeSpec;
+        query.scope = scope;
+        query.isOptional = isOptional;
+        
+        return query;
+    }
+
+    public ArtifactQuery setVersion( String version )
+    {
+        this.version = version;
+
+        return this;
+    }
+
+    public ArtifactQuery setVersionRangeSpec( String versionRangeSpec )
+    {
+        this.versionRangeSpec = versionRangeSpec;
+        return this;
+    }
+
+    public ArtifactQuery setClassifier( String classifier )
+    {
+        this.classifier = classifier;
+
+        return this;
+    }
+
+    public ArtifactQuery setScope( String scope )
+    {
+        this.scope = scope;
+        return this;
+    }
+
+    public ArtifactQuery setType( String type )
+    {
+        this.type = type;
+
+        return this;
+    }
+
+    public ArtifactQuery setOptional( boolean isOptional )
+    {
+        this.isOptional = isOptional;
+
+        return this;
+    }
+
+    public Artifact createArtifact( ArtifactHandlerManager artifactHandlerManager )
+        throws InvalidVersionSpecificationException
+    {
+        ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( type
);
+
+        VersionRange versionRange;
+
+        if ( versionRangeSpec != null )
+        {
+            versionRange = VersionRange.createFromVersionSpec( versionRangeSpec );
+        }
+        else if ( version != null )
+        {
+            versionRange = VersionRange.createFromVersion( version );
+        }
+        else
+        {
+            throw new IllegalArgumentException(
+                                                "Cannot create Artifact instance from incomplete
ArtifactQuery; please supply version or versionRangeSpec." );
+        }
+
+        Artifact artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope,
type, classifier,
+                                                 artifactHandler, isOptional );
+
+        return artifact;
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactQuery.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,48 @@
+package org.apache.maven.artifact.tools.resolve;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.project.MavenProject;
+
+public class ArtifactResolutionResult
+{
+    
+    private Artifact artifact;
+    
+    private Model model;
+    
+    private MavenProject project;
+    
+    private ArtifactRepository sourceRepository;
+
+    public ArtifactResolutionResult( Artifact artifact, MavenProject project )
+    {
+        this.artifact = artifact;
+        this.project = project;
+        
+        this.model = project.getOriginalModel();
+        this.sourceRepository = artifact.getRepository();
+    }
+
+    public Artifact getArtifact()
+    {
+        return artifact;
+    }
+
+    public Model getModel()
+    {
+        return model;
+    }
+
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
+    public ArtifactRepository getSourceRepository()
+    {
+        return sourceRepository;
+    }
+
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionResult.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java?view=auto&rev=453073
==============================================================================
--- maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java
(added)
+++ maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java
Wed Oct  4 17:46:58 2006
@@ -0,0 +1,93 @@
+package org.apache.maven.artifact.tools.resolve;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.tools.InvalidConfigurationException;
+import org.apache.maven.artifact.tools.components.MavenComponentAccess;
+import org.apache.maven.artifact.tools.repository.ArtifactRepositorySource;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+
+/**
+ * Convenience API for resolving Artifacts and their associated POM metadata.
+ */
+public class ArtifactResolutionTool
+{
+    private final ArtifactResolver artifactResolver;
+
+    private final ArtifactHandlerManager artifactHandlerManager;
+
+    private final MavenProjectBuilder mavenProjectBuilder;
+
+    public ArtifactResolutionTool( MavenComponentAccess componentAccess )
+    {
+        this.artifactResolver = componentAccess.getArtifactResolver();
+        this.artifactHandlerManager = componentAccess.getArtifactHandlerManager();
+        this.mavenProjectBuilder = componentAccess.getMavenProjectBuilder();
+    }
+
+    public ArtifactResolutionResult resolve( ArtifactQuery query, ArtifactRepositorySource
repositorySource )
+        throws InvalidVersionSpecificationException, ArtifactResolutionException, ArtifactNotFoundException,
+        InvalidConfigurationException, ProjectBuildingException
+    {
+        Artifact artifact = query.createArtifact( artifactHandlerManager );
+
+        List repositories = constructMirroredRepositoryList( repositorySource );
+
+        ArtifactRepository localRepository = repositorySource.getLocalRepository();
+
+        artifactResolver.resolve( artifact, repositories, localRepository );
+
+        MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST,
+                                                                        localRepository );
+
+        ArtifactResolutionResult result = new ArtifactResolutionResult( artifact, project
);
+
+        return result;
+    }
+
+    public ArtifactResolutionResult resolveProjectMetadata( ArtifactQuery query, ArtifactRepositorySource
repositorySource )
+        throws InvalidVersionSpecificationException, ArtifactResolutionException, ArtifactNotFoundException,
+        InvalidConfigurationException, ProjectBuildingException
+    {
+        ArtifactQuery pomQuery = query.copy();
+        pomQuery.setType( "pom" );
+        
+        return resolve( pomQuery, repositorySource );
+    }
+
+    private List constructMirroredRepositoryList( ArtifactRepositorySource repositorySource
)
+    {
+        List repositories = repositorySource.getArtifactRepositories();
+        List mirrorEnabled = new ArrayList( repositories.size() );
+
+        for ( Iterator it = repositories.iterator(); it.hasNext(); )
+        {
+            ArtifactRepository repository = (ArtifactRepository) it.next();
+
+            ArtifactRepository mirrorRepo = repositorySource.getMirrorRepository( repository
);
+
+            if ( mirrorRepo == null )
+            {
+                mirrorEnabled.add( repository );
+            }
+            else
+            {
+                mirrorEnabled.add( mirrorRepo );
+            }
+        }
+
+        return mirrorEnabled;
+    }
+}

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-artifact-tools/src/main/java/org/apache/maven/artifact/tools/resolve/ArtifactResolutionTool.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message