Package org.apache.maven.artifact.resolver

Examples of org.apache.maven.artifact.resolver.ArtifactResolver


   
    ArtifactRepository localRepo = createLocalArtifactRepository();
    log( "Using local repository: " + localRepo.getBasedir(), Project.MSG_VERBOSE );
   
    // Look up required resources from the plexus container
    ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
    ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
    MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
   
    Pom pom = initializePom( localRepo );
    if ( pom != null ){
      dependencies = pom.getDependencies();
    }
    else
      {
        // we have to have some sort of Pom object in order to satisfy the requirements for building the
        // originating Artifact below...
        pom = createDummyPom( localRepo );
      }
   
    if ( dependencies.isEmpty() ){
      log( "There were no dependencies specified", Project.MSG_WARN );
    }
   
    log( "Resolving dependencies...", Project.MSG_VERBOSE );
   
    ArtifactResolutionResult result;
    Set artifacts;
   
    List remoteArtifactRepositories = createRemoteArtifactRepositories( pom.getRepositories() );
   
    try
      {
        artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );
     
        Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(),
                                      pom.getVersion(), pom.getPackaging() );
     
        List listeners = Collections.singletonList( new AntResolutionListener( getProject() ) );
     
        Map managedDependencies = pom.getMavenProject().getManagedVersionMap();
     
        ArtifactFilter filter = null;
        if ( useScope != null )
          {
            filter = new ScopeArtifactFilter( useScope );
          }
        if ( scopes != null )
          {
            filter = new SpecificScopesArtifactFilter( scopes );
          }
        if ( type != null )
          {
            ArtifactFilter typeArtifactFilter = new TypesArtifactFilter( type );
            if ( filter != null )
              {
                AndArtifactFilter andFilter = new AndArtifactFilter();
                andFilter.add( filter );
                andFilter.add( typeArtifactFilter );
                filter = andFilter;
              }
            else
              {
                filter = typeArtifactFilter;
              }
          }
     
        result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
                             remoteArtifactRepositories, metadataSource, filter, listeners );
      }
    catch ( ArtifactResolutionException e )
      {
        throw new BuildException( "Unable to resolve artifact: " + e.getMessage(), e );
View Full Code Here


        Field artifactFactoryField = ShadeMojo.class.getDeclaredField( "artifactFactory" );
        artifactFactoryField.setAccessible( true );
        artifactFactoryField.set( mojo, artifactFactory );

        // configure artifactResolver (mocked) for mojo
        ArtifactResolver mockArtifactResolver = new DefaultArtifactResolver()
        {

            public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepos, ArtifactRepository repo )
                throws ArtifactResolutionException, ArtifactNotFoundException
            {
                // artifact is resolved
                artifact.setResolved( true );

                // set file
                artifact.setFile( new File(
                    artifact.getArtifactId() + "-" + artifact.getVersion() + ( artifact.getClassifier() != null ? "-"
                        + artifact.getClassifier() : "" ) + ".jar" ) );
            }

        };
        Field artifactResolverField = ShadeMojo.class.getDeclaredField( "artifactResolver" );
        artifactResolverField.setAccessible( true );
        artifactResolverField.set( mojo, mockArtifactResolver );

        // create and configure MavenProject
        MavenProject project = new MavenProject();
        ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE );
        Artifact artifact = new DefaultArtifact( "org.apache.myfaces.core", "myfaces-impl",
                                                 VersionRange.createFromVersion( "2.0.1-SNAPSHOT" ), "compile", "jar",
                                                 null, artifactHandler );
        mockArtifactResolver.resolve( artifact, null, null ); // setFile and setResolved
        project.setArtifact( artifact );
        Field projectField = ShadeMojo.class.getDeclaredField( "project" );
        projectField.setAccessible( true );
        projectField.set( mojo, project );
View Full Code Here

            // and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
            // to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
            resolutionFilter = new ProjectArtifactFilter( pomArtifact, filter );
        }

        final ArtifactResolver resolver = config.artifactResolver();
       
        @SuppressWarnings( "rawtypes" )
        Map managed = config.project().getManagedVersionMap();
       
        final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(
                artifactSet, pomArtifact, managed, localRepo, remoteRepos, metadataSource, resolutionFilter );

        final List<String> result = new ArrayList<String>( artifacts.size() );
        for ( final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts() )
        {
View Full Code Here

            MavenSession session = (MavenSession) helper.evaluate( "${session}" );
            String target = (String) helper.evaluate( "${project.build.directory}" );
            String artifactId = (String) helper.evaluate( "${project.artifactId}" );

            // retreive any component out of the session directly
            ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class );
            RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );

            log.info( "Retrieved Target Folder: " + target );
            log.info( "Retrieved ArtifactId: " +artifactId );
            log.info( "Retrieved Project: " + project );
View Full Code Here

    public void doExecute()
        throws BuildException
    {
        MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );

        ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
        ArtifactRepository artifactRepository = createRemoteArtifactRepository( getDefaultRemoteRepository() );
        List remoteRepositories = Collections.singletonList( artifactRepository );

        VersionRange versionRange;
        try
        {
            versionRange = VersionRange.createFromVersionSpec( version );
        }
        catch ( InvalidVersionSpecificationException e )
        {
            throw new BuildException( "Unable to get extension '" +
                ArtifactUtils.versionlessKey( WAGON_GROUP_ID, artifactId ) + "' because version '" + version +
                " is invalid: " + e.getMessage(), e );
        }

        ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
        Artifact providerArtifact = factory.createExtensionArtifact( WAGON_GROUP_ID, artifactId, versionRange );

        ArtifactResolutionResult result;
        try
        {
            result = resolver.resolveTransitively( Collections.singleton( providerArtifact ),
                                                   createArtifact( createDummyPom() ), createLocalArtifactRepository(),
                                                   remoteRepositories, metadataSource, null );
        }
        catch ( ArtifactResolutionException e )
        {
View Full Code Here

    protected void doExecute()
    {
        ArtifactRepository localRepo = createLocalArtifactRepository();

        ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
        MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
        MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );

        List dependencies = this.dependencies;

        Pom pom = buildPom( projectBuilder, localRepo );
        if ( pom != null )
        {
            if ( !dependencies.isEmpty() )
            {
                throw new BuildException( "You cannot specify both dependencies and a pom in the dependencies task" );
            }

            dependencies = pom.getDependencies();

            for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
            {
                Repository pomRepository = (Repository) i.next();

                remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
            }
        }
        else
        {
            // we have to have some sort of Pom object in order to satisfy the requirements for building the
            // originating Artifact below...
            pom = createDummyPom();
        }

        if ( dependencies.isEmpty() )
        {
            log( "There were no dependencies specified", Project.MSG_WARN );
        }

        log( "Resolving dependencies...", Project.MSG_VERBOSE );

        WagonManager wagonManager = (WagonManager) lookup( WagonManager.ROLE );
        wagonManager.setDownloadMonitor( new AntDownloadMonitor() );

        ArtifactResolutionResult result;
        Set artifacts;
        try
        {
            artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );

            Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom
                .getVersion(), pom.getPackaging() );

            List listeners = Collections.EMPTY_LIST;
            if ( verbose )
            {
                listeners = Collections.singletonList( new AntResolutionListener( getProject() ) );
            }

            List remoteRepositories = getRemoteRepositories();

            RemoteRepository remoteRepository = getDefaultRemoteRepository();
            remoteRepositories.add( remoteRepository );

            List remoteArtifactRepositories = createRemoteArtifactRepositories( remoteRepositories );

            // TODO: managed dependencies
            Map managedDependencies = Collections.EMPTY_MAP;

            ArtifactFilter filter = null;
            if ( useScope != null )
            {
                filter = new ScopeArtifactFilter( useScope );
            }
            if ( type != null )
            {
                TypeArtifactFilter typeArtifactFilter = new TypeArtifactFilter( type );
                if ( filter != null )
                {
                    AndArtifactFilter andFilter = new AndArtifactFilter();
                    andFilter.add( filter );
                    andFilter.add( typeArtifactFilter );
                    filter = andFilter;
                }
                else
                {
                    filter = typeArtifactFilter;
                }
            }

            result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
                                                   remoteArtifactRepositories, metadataSource, filter, listeners );
        }
        catch ( ArtifactResolutionException e )
        {
            throw new BuildException( "Unable to resolve artifact: " + e.getMessage(), e );
View Full Code Here

public class ContainerDependentTest extends PlexusTestCase
{
   
    public void testOne() throws Exception
    {
        ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
       
        assertNotNull( resolver );
       
        Thing thing = (Thing) lookup( Thing.ROLE );
       
View Full Code Here

        ArtifactResolutionResult result;
        try
        {
            MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
            ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
            List remoteRepositories = createRemoteArtifactRepositories();

            result = resolver.resolveTransitively( Collections.singleton( providerArtifact ),
                                                   createDummyArtifact(), createLocalArtifactRepository(),
                                                   remoteRepositories, metadataSource, null );
        }
        catch ( ArtifactResolutionException e )
        {
View Full Code Here

       
        ArtifactRepository localRepo = createLocalArtifactRepository();
        log( "Using local repository: " + localRepo.getBasedir(), Project.MSG_VERBOSE );

        // Look up required resources from the plexus container
        ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
        MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );

        Pom pom = initializePom( localRepo );
        if ( pom != null )
        {
            dependencies = pom.getDependencies();
        }
        else
        {
            // we have to have some sort of Pom object in order to satisfy the requirements for building the
            // originating Artifact below...
            pom = createDummyPom( localRepo );
        }

        if ( dependencies.isEmpty() )
        {
            log( "There were no dependencies specified", Project.MSG_WARN );
        }

        log( "Resolving dependencies...", Project.MSG_VERBOSE );

        ArtifactResolutionResult result;
        Set artifacts;

        List remoteArtifactRepositories = createRemoteArtifactRepositories( pom.getRepositories() );

        try
        {
            artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );

            Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(),
                pom.getVersion(), pom.getPackaging() );

            List listeners = Collections.singletonList( new AntResolutionListener( getProject() ) );

            Map managedDependencies = pom.getMavenProject().getManagedVersionMap();

            ArtifactFilter filter = null;
            if ( useScope != null )
            {
                filter = new ScopeArtifactFilter( useScope );
            }
            if ( scopes != null )
            {
                filter = new SpecificScopesArtifactFilter( scopes );
            }
            if ( type != null )
            {
                ArtifactFilter typeArtifactFilter = new TypesArtifactFilter( type );
                if ( filter != null )
                {
                    AndArtifactFilter andFilter = new AndArtifactFilter();
                    andFilter.add( filter );
                    andFilter.add( typeArtifactFilter );
                    filter = andFilter;
                }
                else
                {
                    filter = typeArtifactFilter;
                }
            }

            result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
                                                   remoteArtifactRepositories, metadataSource, filter, listeners );
        }
        catch ( ArtifactResolutionException e )
        {
            throw new BuildException( "Unable to resolve artifact: " + e.getMessage(), e );
View Full Code Here

TOP

Related Classes of org.apache.maven.artifact.resolver.ArtifactResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.