Author: jdcasey Date: Thu Aug 27 16:00:44 2009 New Revision: 808474 URL: http://svn.apache.org/viewvc?rev=808474&view=rev Log: [MRRESOURCES-41][MSHARED-126] Creating an API based on that found in Maven 3.x (trunk) to resolve the dependency transitive closure for a project or collection of projects. Still needs tests (working on these now).
NOTE: The package specifications for the two interfaces is critical, since we're aiming to be able to filter out this library in Maven 3.x and simply allow the user to use the built-in functionality instead. Added: maven/shared/trunk/maven-artifact-resolver/ maven/shared/trunk/maven-artifact-resolver/pom.xml (with props) maven/shared/trunk/maven-artifact-resolver/src/ maven/shared/trunk/maven-artifact-resolver/src/main/ maven/shared/trunk/maven-artifact-resolver/src/main/java/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ProjectDependenciesResolver.java (with props) maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/RepositoryRequest.java (with props) maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/CumulativeScopeArtifactFilter.java (with props) maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultProjectDependenciesResolver.java (with props) maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultRepositoryRequest.java (with props) maven/shared/trunk/maven-artifact-resolver/src/test/ maven/shared/trunk/maven-artifact-resolver/src/test/java/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/CumlativeScopeArtifactFilter.java (with props) Added: maven/shared/trunk/maven-artifact-resolver/pom.xml URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/pom.xml?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/pom.xml (added) +++ maven/shared/trunk/maven-artifact-resolver/pom.xml Thu Aug 27 16:00:44 2009 @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>maven-shared-components</artifactId> + <groupId>org.apache.maven.shared</groupId> + <version>12-SNAPSHOT</version> + </parent> + + <artifactId>maven-artifact-resolver</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Maven Artifact Resolution API</name> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>2.2.1</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact-manager</artifactId> + <version>2.2.1</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.2.1</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.2.1</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <version>1.3.8</version> + <executions> + <execution> + <id>create-component-descriptor</id> + <phase>generate-resources</phase> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/shared/trunk/maven-artifact-resolver/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ProjectDependenciesResolver.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ProjectDependenciesResolver.java?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ProjectDependenciesResolver.java (added) +++ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ProjectDependenciesResolver.java Thu Aug 27 16:00:44 2009 @@ -0,0 +1,77 @@ +package org.apache.maven; + +/* + * 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. + */ + +import java.util.Collection; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.RepositoryRequest; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.model.Dependency; +import org.apache.maven.project.MavenProject; + +/** + * Common interface for plugins and other third-party components running inside a Maven runtime to + * resolve the transitive dependency closure for various {...@link MavenProject} instances. + * + * @author jdcasey + */ +// NOTE: The package specified for this interface is REQUIRED, since it must match Maven 3.x!! +public interface ProjectDependenciesResolver +{ + /** + * Resolve the dependencies for a collection of {...@link MavenProject} instances, using a common + * set of remote repositories and a common set of scopes. + * + * @param projects The projects whose dependencies should be resolved. + * @param scopes The list of scopes to resolve. These scopes may imply other scopes. + * @param repositoryRequest The request containing a {...@link RepositoryCache}, along with + * zero or more {...@link ArtifactRepository} remote repositories, a local {...@link ArtifactRepository}, + * and a flag determining whether to run in offline mode. + * @return The set of resolved artifacts. If the projects contain no dependencies, this will return an empty set. + * @throws ArtifactResolutionException In case {...@link Artifact} instances cannot be created from + * project {...@link Dependency} instances, or artifact resolution fails. + * @throws ArtifactNotFoundException In cases where one or more dependency artifacts cannot be found in the + * various repositories. + */ + public Set<Artifact> resolve( Collection<MavenProject> projects, Collection<String> scopes, RepositoryRequest repositoryRequest ) + throws ArtifactResolutionException, ArtifactNotFoundException; + + /** + * Resolve the dependencies for a single {...@link MavenProject} instance, using the supplied + * set of remote repositories and scopes. + * + * @param project The project whose dependencies should be resolved. + * @param scopes The list of scopes to resolve. These scopes may imply other scopes. + * @param repositoryRequest The request containing a {...@link RepositoryCache}, along with + * zero or more {...@link ArtifactRepository} remote repositories, a local {...@link ArtifactRepository}, + * and a flag determining whether to run in offline mode. + * @return The set of resolved artifacts. If the project contains no dependencies, this will return an empty set. + * @throws ArtifactResolutionException In case {...@link Artifact} instances cannot be created from the + * project {...@link Dependency} instance, or artifact resolution fails. + * @throws ArtifactNotFoundException In cases where one or more dependency artifacts cannot be found in the + * various repositories. + */ + public Set<Artifact> resolve( MavenProject project, Collection<String> scopes, RepositoryRequest repositoryRequest ) + throws ArtifactResolutionException, ArtifactNotFoundException; +} Propchange: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/ProjectDependenciesResolver.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/RepositoryRequest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/RepositoryRequest.java?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/RepositoryRequest.java (added) +++ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/RepositoryRequest.java Thu Aug 27 16:00:44 2009 @@ -0,0 +1,80 @@ +package org.apache.maven.artifact.repository; + +/* + * 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. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; + +import java.util.List; + +/** + * Collects basic settings to access the repository system. + * + * @author Benjamin Bentmann + */ +//NOTE: The package specified for this interface is REQUIRED, since it must match Maven 3.x!! +public interface RepositoryRequest +{ + + /** + * Indicates whether network access to remote repositories has been disabled. + * + * @return {...@code true} if remote access has been disabled, {...@code false} otherwise. + */ + boolean isOffline(); + + /** + * Enables/disables network access to remote repositories. + * + * @param offline {...@code true} to disable remote access, {...@code false} to allow network access. + * @return This request, never {...@code null}. + */ + RepositoryRequest setOffline( boolean offline ); + + /** + * Gets the local repository to use. + * + * @return The local repository to use or {...@code null} if not set. + */ + ArtifactRepository getLocalRepository(); + + /** + * Sets the local repository to use. + * + * @param localRepository The local repository to use. + * @return This request, never {...@code null}. + */ + RepositoryRequest setLocalRepository( ArtifactRepository localRepository ); + + /** + * Gets the remote repositories to use. + * + * @return The remote repositories to use, never {...@code null}. + */ + List<ArtifactRepository> getRemoteRepositories(); + + /** + * Sets the remote repositories to use. + * + * @param remoteRepositories The remote repositories to use. + * @return This request, never {...@code null}. + */ + RepositoryRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories ); + +} Propchange: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/artifact/repository/RepositoryRequest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/CumulativeScopeArtifactFilter.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/CumulativeScopeArtifactFilter.java?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/CumulativeScopeArtifactFilter.java (added) +++ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/CumulativeScopeArtifactFilter.java Thu Aug 27 16:00:44 2009 @@ -0,0 +1,123 @@ +package org.apache.maven.shared.artifact.resolver; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; + +/** + * Filter to only retain objects in the given scope or better. This implementation allows the + * accumulation of multiple scopes and their associated implied scopes, so that the user can filter + * apply a series of implication rules in a single step. This should be a more efficient implementation + * of multiple standard {...@link ScopeArtifactFilter} instances ORed together. + * + * @author <a href="mailto:br...@apache.org">Brett Porter</a> + * @author jdcasey + * @version $Id$ + */ +public class CumulativeScopeArtifactFilter + implements ArtifactFilter +{ + private boolean compileScope; + + private boolean runtimeScope; + + private boolean testScope; + + private boolean providedScope; + + private boolean systemScope; + + /** + * Create a new filter with all scopes disabled. + */ + public CumulativeScopeArtifactFilter() + { + } + + /** + * Create a new filter with the specified scope and its implied scopes enabled. + * @param scope The scope to enable, along with all implied scopes. + */ + public CumulativeScopeArtifactFilter( String scope ) + { + addScope( scope ); + } + + /** + * Enable a new scope, along with its implied scopes, in this filter. + * @param scope The scope to enable, along with all implied scopes. + */ + public void addScope( String scope ) + { + if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) ) + { + systemScope = true; + providedScope = true; + compileScope = true; + } + else if ( DefaultArtifact.SCOPE_RUNTIME.equals( scope ) ) + { + compileScope = true; + runtimeScope = true; + } + else if ( DefaultArtifact.SCOPE_TEST.equals( scope ) ) + { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = true; + testScope = true; + } + } + + /** + * {...@inheritdoc} + */ + public boolean include( Artifact artifact ) + { + if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) ) + { + return compileScope; + } + else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) ) + { + return runtimeScope; + } + else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) ) + { + return testScope; + } + else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) ) + { + return providedScope; + } + else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) + { + return systemScope; + } + else + { + return true; + } + } +} Propchange: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/CumulativeScopeArtifactFilter.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultProjectDependenciesResolver.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultProjectDependenciesResolver.java?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultProjectDependenciesResolver.java (added) +++ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultProjectDependenciesResolver.java Thu Aug 27 16:00:44 2009 @@ -0,0 +1,217 @@ +package org.apache.maven.shared.artifact.resolver; + +/* + * 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. + */ + +import static org.apache.maven.project.MavenProject.getProjectReferenceId; + +import org.apache.maven.ProjectDependenciesResolver; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.RepositoryRequest; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Default implementation of {...@link ProjectDependenciesResolver}. + * + * @author jdcasey + * + * @see ProjectDependenciesResolver + * @plexus.component role="org.apache.maven.shared.artifact.resolver.ProjectDependenciesResolver" role-hint="default" + */ +public class DefaultProjectDependenciesResolver + implements ProjectDependenciesResolver +{ + + /** + * @plexus.requirement + */ + private ArtifactResolver resolver; + + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement role-hint="maven" + */ + private ArtifactMetadataSource metadataSource; + + /** + * @plexus.requirement + */ + private WagonManager wagonManager; + + /** + * {...@inheritdoc} + */ + @SuppressWarnings( "unchecked" ) + public Set<Artifact> resolve( Collection<MavenProject> projects, Collection<String> scopes, RepositoryRequest repositoryRequest ) + throws ArtifactResolutionException, ArtifactNotFoundException + { + if ( projects == null || projects.isEmpty() ) + { + return Collections.emptySet(); + } + + boolean online = wagonManager.isOnline(); + Set<Artifact> resolved = new LinkedHashSet<Artifact>(); + try + { + wagonManager.setOnline( !repositoryRequest.isOffline() ); + + CumulativeScopeArtifactFilter scopeFilter = new CumulativeScopeArtifactFilter(); + if ( scopes == null ) + { + scopeFilter.addScope( Artifact.SCOPE_COMPILE ); + } + else + { + for ( String scope : scopes ) + { + scopeFilter.addScope( scope ); + } + } + + for ( MavenProject project : projects ) + { + Set<Artifact> depArtifacts = (Set<Artifact>) project.getDependencyArtifacts(); + if ( depArtifacts == null ) + { + try + { + depArtifacts = project.createArtifacts( artifactFactory, null, scopeFilter ); + } + catch ( InvalidDependencyVersionException e ) + { + throw new ArtifactResolutionException( "Failed to create Artifact instances for project dependencies: " + + e.getMessage(), null, e ); + } + } + + if ( depArtifacts == null || depArtifacts.isEmpty() ) + { + continue; + } + + for ( Iterator<Artifact> it = depArtifacts.iterator(); it.hasNext(); ) + { + Artifact artifact = it.next(); + if ( resolved.contains( artifact ) ) + { + // already resolved, don't do it again. + it.remove(); + } + } + + Artifact projectArtifact = project.getArtifact(); + if ( projectArtifact == null ) + { + projectArtifact = artifactFactory.createProjectArtifact( project.getGroupId(), project.getArtifactId(), + project.getVersion() ); + } + + try + { + ArtifactResolutionResult result = resolver.resolveTransitively( depArtifacts, projectArtifact, + project.getManagedVersionMap(), + repositoryRequest.getLocalRepository(), + repositoryRequest.getRemoteRepositories(), + metadataSource, scopeFilter ); + + if ( result.getArtifacts() != null && !result.getArtifacts().isEmpty() ) + { + resolved.addAll( result.getArtifacts() ); + } + } + catch ( MultipleArtifactsNotFoundException me ) + { + Set<String> projectIds = getProjectIds( projects ); + Collection<Artifact> missing = new HashSet<Artifact>( me.getMissingArtifacts() ); + for ( Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) + { + Artifact artifact = it.next(); + if ( projectIds.contains( getProjectReferenceId( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion() ) ) ) + { + it.remove(); + } + } + + if ( missing.isEmpty() ) + { + resolved.addAll( me.getResolvedArtifacts() ); + } + else + { + throw me; + } + } + } + } + finally + { + wagonManager.setOnline( online ); + } + + return resolved; + } + + /** + * {...@inheritdoc} + */ + public Set<Artifact> resolve( MavenProject project, Collection<String> scopes, RepositoryRequest repositoryRequest ) + throws ArtifactResolutionException, ArtifactNotFoundException + { + Collection<MavenProject> projects = Collections.singleton( project ); + + return resolve( projects, scopes, repositoryRequest ); + } + + private Set<String> getProjectIds( Collection<MavenProject> projects ) + { + Set<String> ids = new HashSet<String>(); + if ( projects != null && !projects.isEmpty() ) + { + for ( MavenProject project : projects ) + { + ids.add( getProjectReferenceId( project.getGroupId(), project.getArtifactId(), project.getVersion() ) ); + } + } + + return ids; + } + +} Propchange: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultProjectDependenciesResolver.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultRepositoryRequest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultRepositoryRequest.java?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultRepositoryRequest.java (added) +++ maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultRepositoryRequest.java Thu Aug 27 16:00:44 2009 @@ -0,0 +1,169 @@ +package org.apache.maven.shared.artifact.resolver; + +/* + * 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. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.RepositoryRequest; +import org.apache.maven.project.MavenProject; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import edu.emory.mathcs.backport.java.util.Collections; + +/** + * Collects basic settings to access the repository system. + * + * @author Benjamin Bentmann + * @author jdcasey + */ +public class DefaultRepositoryRequest + implements RepositoryRequest +{ + + private boolean offline; + + private ArtifactRepository localRepository; + + private List<ArtifactRepository> remoteRepositories; + + /** + * Creates an empty repository request. + */ + public DefaultRepositoryRequest() + { + // enables no-arg constructor + } + + /** + * Creates a shallow copy of the specified repository request. + * + * @param repositoryRequest The repository request to copy from, must not be {...@code null}. + */ + public DefaultRepositoryRequest( RepositoryRequest repositoryRequest ) + { + setLocalRepository( repositoryRequest.getLocalRepository() ); + setRemoteRepositories( repositoryRequest.getRemoteRepositories() ); + setOffline( repositoryRequest.isOffline() ); + } + + /** + * Create a new request using the remote repositories associated with the project, along with the + * specified local repository. This constructor also initializes an instance of + * {...@link DefaultRepositoryCache} for use during resolution. + * + * @param project The {...@link MavenProject} instance, from which to retrieve the remote repositories + * to be used. + * @param localRepository The local {...@link ArtifactRepository} instance to be used. + */ + @SuppressWarnings( "unchecked" ) + public DefaultRepositoryRequest( MavenProject project, ArtifactRepository localRepository ) + { + this( Collections.singleton( project ), localRepository ); + } + + /** + * Create a new request using the remote repositories associated with the projects, along with the + * specified local repository. This constructor also initializes an instance of + * {...@link DefaultRepositoryCache} for use during resolution. + * + * @param projects The {...@link MavenProject} instances, from which to retrieve the remote repositories + * to be used. + * @param localRepository The local {...@link ArtifactRepository} instance to be used. + */ + @SuppressWarnings( "unchecked" ) + public DefaultRepositoryRequest( Collection<MavenProject> projects, ArtifactRepository localRepository ) + { + Set<ArtifactRepository> remoteRepositories = new LinkedHashSet<ArtifactRepository>(); + if ( projects != null && !projects.isEmpty() ) + { + for ( MavenProject project : projects ) + { + remoteRepositories.addAll( (List<ArtifactRepository>) project.getRemoteArtifactRepositories() ); + } + } + + setRemoteRepositories( new ArrayList<ArtifactRepository>( remoteRepositories ) ); + setLocalRepository( localRepository ); + } + + /** + * {...@inheritdoc} + */ + public boolean isOffline() + { + return offline; + } + + /** + * {...@inheritdoc} + */ + public DefaultRepositoryRequest setOffline( boolean offline ) + { + this.offline = offline; + + return this; + } + + /** + * {...@inheritdoc} + */ + public ArtifactRepository getLocalRepository() + { + return localRepository; + } + + /** + * {...@inheritdoc} + */ + public DefaultRepositoryRequest setLocalRepository( ArtifactRepository localRepository ) + { + this.localRepository = localRepository; + + return this; + } + + /** + * {...@inheritdoc} + */ + public List<ArtifactRepository> getRemoteRepositories() + { + if ( remoteRepositories == null ) + { + remoteRepositories = new ArrayList<ArtifactRepository>(); + } + + return remoteRepositories; + } + + /** + * {...@inheritdoc} + */ + public DefaultRepositoryRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories ) + { + this.remoteRepositories = remoteRepositories; + + return this; + } + +} Propchange: maven/shared/trunk/maven-artifact-resolver/src/main/java/org/apache/maven/shared/artifact/resolver/DefaultRepositoryRequest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/CumlativeScopeArtifactFilter.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/CumlativeScopeArtifactFilter.java?rev=808474&view=auto ============================================================================== --- maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/CumlativeScopeArtifactFilter.java (added) +++ maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/CumlativeScopeArtifactFilter.java Thu Aug 27 16:00:44 2009 @@ -0,0 +1,14 @@ +package org.apache.maven.shared.artifact.resolver; + +import org.junit.Test; + +public class CumlativeScopeArtifactFilter +{ + + @Test + public void testNothingEnabledWhenNoScopesAdded() + { + + } + +} Propchange: maven/shared/trunk/maven-artifact-resolver/src/test/java/org/apache/maven/shared/artifact/resolver/CumlativeScopeArtifactFilter.java ------------------------------------------------------------------------------ svn:eol-style = native