Package org.apache.maven.artifact.resolver

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


            remoteRepositories.add( factory.createArtifactRepository( "apache.snapshots",
                                                                      "http://people.apache.org/repo/m2-snapshot-repository",
                                                                      layout, null, null ) );
        }

        ArtifactResolver resolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );

        List<String> exclusions = new ArrayList<String>();
        exclusions.add( "org.apache.continuum:data-management-api" );
        exclusions.add( "org.codehaus.plexus:plexus-component-api" );
        exclusions.add( "org.codehaus.plexus:plexus-container-default" );
        exclusions.add( "org.slf4j:slf4j-api" );
        exclusions.add( "log4j:log4j" );

        ArtifactFilter filter = new ExcludesArtifactFilter( exclusions );

        List<? extends ResolutionListener> listeners;
        if ( LOGGER.isDebugEnabled() )
        {
            listeners = Collections.singletonList( new DebugResolutionListener( container.getLogger() ) );
        }
        else
        {
            listeners = Collections.emptyList();
        }

        ArtifactMetadataSource source =
            (ArtifactMetadataSource) container.lookup( ArtifactMetadataSource.ROLE, "maven" );
        ArtifactResolutionResult result =
            resolver.resolveTransitively( Collections.singleton( artifact ), dummyArtifact, Collections.emptyMap(),
                                          localRepository, remoteRepositories, source, filter, listeners );

        return result.getArtifacts();
    }
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();

        final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(
                artifactSet, pomArtifact, 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

            Artifact parentArtifact = factory.createParentArtifact( groupId, artifactId, version );

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

                resolver.resolveTransitively( Collections.singleton( parentArtifact ),
                                              createDummyArtifact(), createLocalArtifactRepository(),
                                              remoteRepositories, metadataSource, null );
            }
            catch ( ArtifactResolutionException e )
            {
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

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

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

        List dependencies = this.dependencies;

        Pom pom = buildPom( 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();
        }
        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(), verbose ) );

            // 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

    // Gets the classloader for this artifact's file.
    private ClassLoader getContextClassloader( Artifact archetypeArtifact, ArtifactRepository localRepository,
                                               List<ArtifactRepository> remoteRepositories )
        throws Exception
    {
        ArtifactResolver artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.class.getName() );
        try
        {
            artifactResolver.resolve( archetypeArtifact, remoteRepositories, localRepository );
        }
        catch ( ArtifactResolutionException e )
        {
            throw new ArchetypeDescriptorException( "Error attempting to download archetype: " + e.getMessage(), e );
        }
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

            remoteRepositories.add( factory.createArtifactRepository( "apache.snapshots",
                                                                      "http://people.apache.org/repo/m2-snapshot-repository",
                                                                      layout, null, null ) );
        }

        ArtifactResolver resolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );

        List<String> exclusions = new ArrayList<String>();
        exclusions.add( "org.apache.continuum:data-management-api" );
        exclusions.add( "org.codehaus.plexus:plexus-component-api" );
        exclusions.add( "org.codehaus.plexus:plexus-container-default" );
        exclusions.add( "stax:stax-api" );
        exclusions.add( "log4j:log4j" );

        ArtifactFilter filter = new ExcludesArtifactFilter( exclusions );

        ArtifactMetadataSource source =
            (ArtifactMetadataSource) container.lookup( ArtifactMetadataSource.ROLE, "maven" );
        ArtifactResolutionResult result = resolver.resolveTransitively( Collections.singleton( artifact ),
                                                                        dummyArtifact, localRepository,
                                                                        remoteRepositories, source, filter );

        return result.getArtifacts();
    }
View Full Code Here

    }
    final DependencyGraphBuilder dependencyGraphBuilder = this.getDependencyGraphBuilder();
    if (dependencyGraphBuilder == null) {
      throw new IllegalStateException("this.getDependencyGraphBuilder()", new NullPointerException("this.getDependencyGraphBuilder()"));
    }
    final ArtifactResolver resolver = this.getArtifactResolver();
    if (resolver == null) {
      throw new IllegalStateException("this.getArtifactResolver()", new NullPointerException("this.getArtifactResolver()"));
    }
    final Collection<? extends Artifact> artifacts = new Artifacts().getArtifactsInTopologicalOrder(project,
                                                                                                    dependencyGraphBuilder,
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 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

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.