Java 类org.apache.maven.plugin.version.PluginVersionResult 实例源码

项目:xmvn    文件:XMvnPluginVersionResolver.java   
@Override
public PluginVersionResult resolve( PluginVersionRequest request )
{
    RepositorySystemSession session = request.getRepositorySession();
    WorkspaceReader reader = session.getWorkspaceReader();
    List<String> versions =
        reader.findVersions( new DefaultArtifact( request.getGroupId(), request.getArtifactId(),
                                                  Artifact.DEFAULT_EXTENSION, Artifact.DEFAULT_VERSION ) );
    final String version = versions.isEmpty() ? Artifact.DEFAULT_VERSION : versions.iterator().next();
    final ArtifactRepository repository = reader.getRepository();

    return new PluginVersionResult()
    {
        @Override
        public ArtifactRepository getRepository()
        {
            return repository;
        }

        @Override
        public String getVersion()
        {
            return version;
        }
    };
}
项目:oceano    文件:DefaultPluginVersionResolver.java   
public PluginVersionResult resolve( PluginVersionRequest request )
    throws PluginVersionResolutionException
{
    logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() );

    PluginVersionResult result = resolveFromProject( request );

    if ( result == null )
    {
        result = resolveFromRepository( request );

        if ( logger.isDebugEnabled() )
        {
            logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
                + " to " + result.getVersion() + " from repository " + result.getRepository() );
        }
    }
    else if ( logger.isDebugEnabled() )
    {
        logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
            + " to " + result.getVersion() + " from POM " + request.getPom() );
    }

    return result;
}
项目:oceano    文件:DefaultPluginVersionResolver.java   
private PluginVersionResult resolveFromProject( PluginVersionRequest request )
{
    PluginVersionResult result = null;

    if ( request.getPom() != null && request.getPom().getBuild() != null )
    {
        Build build = request.getPom().getBuild();

        result = resolveFromProject( request, build.getPlugins() );

        if ( result == null && build.getPluginManagement() != null )
        {
            result = resolveFromProject( request, build.getPluginManagement().getPlugins() );
        }
    }

    return result;
}
项目:oceano    文件:DefaultPluginVersionResolver.java   
private PluginVersionResult resolveFromProject( PluginVersionRequest request, List<Plugin> plugins )
{
    for ( Plugin plugin : plugins )
    {
        if ( request.getGroupId().equals( plugin.getGroupId() )
            && request.getArtifactId().equals( plugin.getArtifactId() ) )
        {
            if ( plugin.getVersion() != null )
            {
                return new DefaultPluginVersionResult( plugin.getVersion() );
            }
            else
            {
                return null;
            }
        }
    }
    return null;
}
项目:oceano    文件:PluginVersionResolverStub.java   
public PluginVersionResult resolve( PluginVersionRequest request )
    throws PluginVersionResolutionException
{
    return new PluginVersionResult()
    {
        public String getVersion()
        {
            return "0.42";
        }

        public ArtifactRepository getRepository()
        {
            return null;
        }
    };
}
项目:xmvn    文件:PluginVersionResolverTest.java   
@Test
public void testResolution()
    throws Exception
{
    // test of default version resolution (version list is empty)
    EasyMock.expect( rq.getRepositorySession() ).andReturn( session );
    EasyMock.expect( rq.getGroupId() ).andReturn( "test.example" );
    EasyMock.expect( rq.getArtifactId() ).andReturn( "nonexistent" );

    EasyMock.expect( session.getWorkspaceReader() ).andReturn( reader );

    EasyMock.expect( reader.findVersions( EasyMock.anyObject( DefaultArtifact.class ) ) ).andReturn( Collections.emptyList() );
    EasyMock.expect( reader.getRepository() ).andReturn( repo );

    EasyMock.replay( rq, session, reader );

    PluginVersionResult result;

    result = resolver.resolve( rq );
    Assert.assertTrue( result.getRepository().equals( repo ) );
    Assert.assertTrue( result.getVersion().equals( Artifact.DEFAULT_VERSION ) );

    EasyMock.verify( rq, session, reader );

    // test of arbitrary version resolution (version list contains some version)
    ArrayList<String> list = new ArrayList<>();
    list.add( "1.2.3" );

    EasyMock.reset( rq, session, reader );
    EasyMock.expect( rq.getRepositorySession() ).andReturn( session );
    EasyMock.expect( rq.getGroupId() ).andReturn( "test.example" );
    EasyMock.expect( rq.getArtifactId() ).andReturn( "nonexistent" );

    EasyMock.expect( session.getWorkspaceReader() ).andReturn( reader );

    EasyMock.expect( reader.findVersions( EasyMock.anyObject( DefaultArtifact.class ) ) ).andReturn( list );
    EasyMock.expect( reader.getRepository() ).andReturn( repo );

    EasyMock.replay( rq, session, reader );

    result = resolver.resolve( rq );
    Assert.assertTrue( result.getRepository().equals( repo ) );
    Assert.assertTrue( result.getVersion().equals( "1.2.3" ) );

    EasyMock.verify( rq, session, reader );
}