Package org.apache.archiva.metadata.model

Examples of org.apache.archiva.metadata.model.ArtifactMetadata


        assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );
    }

    private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered )
    {
        ArtifactMetadata artifact = new ArtifactMetadata();
        artifact.setNamespace( "org.apache.archiva" );
        artifact.setId( artifactId + "-" + version + ".jar" );
        artifact.setRepositoryId( TEST_REPO );
        artifact.setWhenGathered( whenGathered );
        artifact.setProject( artifactId );
        artifact.setProjectVersion( version );
        artifact.setVersion( version );
        return artifact;
    }
View Full Code Here


        MockControl control = MockControl.createControl(MetadataRepository.class);
        MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
        when(session.getRepository()).thenReturn(metadataRepository);

        ArtifactMetadata artifact = createArtifact("archiva-configuration", "1.0");
        control.expectAndReturn(metadataRepository.getArtifactsByChecksum(TEST_REPO, TEST_CHECKSUM),
                                Collections.singletonList(artifact));

        userReposControl.expectAndReturn(userRepos.getObservableRepositoryIds(GUEST),
                                         Collections.singletonList(TEST_REPO));
View Full Code Here

        userReposControl.verify();
    }

    private ArtifactMetadata createArtifact(String project, String version)
    {
        ArtifactMetadata metadata = new ArtifactMetadata();
        metadata.setNamespace("org.apache.archiva");
        metadata.setProject(project);
        metadata.setProjectVersion(version);
        metadata.setVersion(version);
        metadata.setRepositoryId(TEST_REPO);
        metadata.setId(project + "-" + version + ".jar");
        return metadata;
    }
View Full Code Here

        return createArtifact( version, null, 0 );
    }

    private static ArtifactMetadata createArtifact( String version, String timestamp, int buildNumber )
    {
        ArtifactMetadata metadata = new ArtifactMetadata();
        metadata.setProject( TEST_ARTIFACT_ID );
        metadata.setId( TEST_ARTIFACT_ID + "-" + version + ".jar" );
        metadata.setNamespace( TEST_GROUP_ID );
        metadata.setRepositoryId( TEST_REPO );
        metadata.setSize( TEST_SIZE );
        metadata.setProjectVersion( VersionUtil.getBaseVersion( version ) );
        metadata.setVersion( version );

        MavenArtifactFacet facet = new MavenArtifactFacet();
        facet.setType( "jar" );
        facet.setTimestamp( timestamp );
        facet.setBuildNumber( buildNumber );
        metadata.addFacet( facet );

        return metadata;
    }
View Full Code Here

    {
        // note that we do minimal processing including checksums and POM information for performance of
        // the initial scan. Any request for this information will be intercepted and populated on-demand
        // or picked up by subsequent scans

        ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath( repoId, path );

        ProjectMetadata project = new ProjectMetadata();
        project.setNamespace( artifact.getNamespace() );
        project.setId( artifact.getProject() );

        String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );

        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            MetadataRepository metadataRepository = repositorySession.getRepository();

            boolean createVersionMetadata = false;

            // FIXME: maybe not too efficient since it may have already been read and stored for this artifact
            ProjectVersionMetadata versionMetadata = null;
            try
            {
                versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId, artifact.getNamespace(),
                                                                                artifact.getProject(), projectVersion );
                createVersionMetadata = true;
            }
            catch ( RepositoryStorageMetadataNotFoundException e )
            {
                log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" );

                versionMetadata = new ProjectVersionMetadata();
                versionMetadata.setId( projectVersion );
                versionMetadata.setIncomplete( true );
                createVersionMetadata = true;
            }
            catch ( RepositoryStorageMetadataInvalidException e )
            {
                log.warn( "Error occurred resolving POM for artifact: " + path + "; message: " + e.getMessage() );
            }

            // read the metadata and update it if it is newer or doesn't exist
            artifact.setWhenGathered( whenGathered );
            metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion,
                                               artifact );
            if ( createVersionMetadata )
            {
                metadataRepository.updateProjectVersion( repoId, project.getNamespace(), project.getId(),
View Full Code Here

            if ( tok.hasMoreTokens() && "artifact".equals( tok.nextToken() ) )
            {
                String field = tok.nextToken();
                String id = tok.nextToken();

                ArtifactMetadata artifact = artifacts.get( id );
                if ( artifact == null )
                {
                    artifact = new ArtifactMetadata();
                    artifact.setRepositoryId( repoId );
                    artifact.setNamespace( namespace );
                    artifact.setProject( projectId );
                    artifact.setProjectVersion( projectVersion );
                    artifact.setVersion( projectVersion );
                    artifact.setId( id );
                    artifacts.put( id, artifact );
                }

                String value = (String) entry.getValue();
                if ( "updated".equals( field ) )
                {
                    artifact.setFileLastModified( Long.parseLong( value ) );
                }
                else if ( "size".equals( field ) )
                {
                    artifact.setSize( Long.valueOf( value ) );
                }
                else if ( "whenGathered".equals( field ) )
                {
                    artifact.setWhenGathered( new Date( Long.parseLong( value ) ) );
                }
                else if ( "version".equals( field ) )
                {
                    artifact.setVersion( value );
                }
                else if ( "md5".equals( field ) )
                {
                    artifact.setMd5( value );
                }
                else if ( "sha1".equals( field ) )
                {
                    artifact.setSha1( value );
                }
                else if ( "facetIds".equals( field ) )
                {
                    if ( value.length() > 0 )
                    {
                        String propertyPrefix = "artifact:facet:" + id + ":";
                        for ( String facetId : value.split( "," ) )
                        {
                            MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
                            if ( factory == null )
                            {
                                log.error( "Attempted to load unknown artifact metadata facet: " + facetId );
                            }
                            else
                            {
                                MetadataFacet facet = factory.createMetadataFacet();
                                String prefix = propertyPrefix + facet.getFacetId();
                                Map<String, String> map = new HashMap<String, String>();
                                for ( Object key : new ArrayList( properties.keySet() ) )
                                {
                                    String property = (String) key;
                                    if ( property.startsWith( prefix ) )
                                    {
                                        map.put( property.substring( prefix.length() + 1 ),
                                                 properties.getProperty( property ) );
                                    }
                                }
                                facet.fromProperties( map );
                                artifact.addFacet( facet );
                            }
                        }
                    }

                    updateArtifactFacets( artifact, properties );
View Full Code Here

    private ArtifactMetadata getArtifactFromNode( String repositoryId, Node artifactNode )
        throws RepositoryException
    {
        String id = artifactNode.getName();

        ArtifactMetadata artifact = new ArtifactMetadata();
        artifact.setId( id );
        artifact.setRepositoryId( repositoryId );

        Node projectVersionNode = artifactNode.getParent();
        Node projectNode = projectVersionNode.getParent();
        Node namespaceNode = projectNode.getParent();

        artifact.setNamespace( namespaceNode.getProperty( "namespace" ).getString() );
        artifact.setProject( projectNode.getName() );
        artifact.setProjectVersion( projectVersionNode.getName() );
        artifact.setVersion( artifactNode.hasProperty( "version" )
                                 ? artifactNode.getProperty( "version" ).getString()
                                 : projectVersionNode.getName() );

        if ( artifactNode.hasProperty( JCR_LAST_MODIFIED ) )
        {
            artifact.setFileLastModified( artifactNode.getProperty( JCR_LAST_MODIFIED ).getDate().getTimeInMillis() );
        }

        if ( artifactNode.hasProperty( "whenGathered" ) )
        {
            artifact.setWhenGathered( artifactNode.getProperty( "whenGathered" ).getDate().getTime() );
        }

        if ( artifactNode.hasProperty( "size" ) )
        {
            artifact.setSize( artifactNode.getProperty( "size" ).getLong() );
        }

        if ( artifactNode.hasProperty( "md5" ) )
        {
            artifact.setMd5( artifactNode.getProperty( "md5" ).getString() );
        }

        if ( artifactNode.hasProperty( "sha1" ) )
        {
            artifact.setSha1( artifactNode.getProperty( "sha1" ).getString() );
        }

        for ( Node n : JcrUtils.getChildNodes( artifactNode ) )
        {
            if ( n.isNodeType( FACET_NODE_TYPE ) )
            {
                String name = n.getName();
                MetadataFacetFactory factory = metadataFacetFactories.get( name );
                if ( factory == null )
                {
                    log.error( "Attempted to load unknown project version metadata facet: " + name );
                }
                else
                {
                    MetadataFacet facet = factory.createMetadataFacet();
                    Map<String, String> map = new HashMap<String, String>();
                    for ( Property p : JcrUtils.getProperties( n ) )
                    {
                        String property = p.getName();
                        if ( !property.startsWith( "jcr:" ) )
                        {
                            map.put( property, p.getString() );
                        }
                    }
                    facet.fromProperties( map );
                    artifact.addFacet( facet );
                }
            }
        }
        return artifact;
    }
View Full Code Here

    }

    private List<ArtifactMetadata> getArtifacts()
    {
        List<ArtifactMetadata> metadata = new ArrayList<ArtifactMetadata>();
        ArtifactMetadata artifact1 = new ArtifactMetadata();
        artifact1.setNamespace( "com.example.test" );
        artifact1.setProject( "test-artifact" );
        artifact1.setVersion( "1.0-SNAPSHOT" );
        artifact1.setProjectVersion( "1.0-SNAPSHOT" );
        artifact1.setId( "test-artifact-1.0-20100308.230825-1.jar" );

        metadata.add( artifact1 );
        return metadata;
    }
View Full Code Here

    public void testMergeWithOutConflictArtifacts()
        throws Exception
    {
        String sourceRepoId = "source-repo";
        ArtifactMetadata artifact1 = new ArtifactMetadata();
        artifact1.setNamespace( "org.testng" );
        artifact1.setProject( "testng" );
        artifact1.setVersion( "5.8" );
        artifact1.setProjectVersion( "5.8" );
        artifact1.setId( "testng-5.8-jdk15.jar" );
        artifact1.setRepositoryId( sourceRepoId );

        List<ArtifactMetadata> sourceRepoArtifactsList = getArtifacts();
        sourceRepoArtifactsList.add( artifact1 );
        List<ArtifactMetadata> targetRepoArtifactsList = getArtifacts();
View Full Code Here

                                                                       org.apache.archiva.admin.model.beans.ManagedRepository.class ) );

        repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );

        List<ArtifactMetadata> artifacts = getArtifacts();
        ArtifactMetadata artifact = artifacts.get( 0 );

        metadataRepositoryControl.expectAndReturn(
            metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
                                             artifact.getVersion() ), artifacts );
        metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
                                           artifact.getVersion(), artifact.getId() );

        listener.deleteArtifact( metadataRepository, repoContent.getId(), artifact.getNamespace(),
                                 artifact.getProject(), artifact.getVersion(), artifact.getId() );
        listenerControl.setVoidCallable( 1 );

        archivaConfigControl.replay();
        configControl.replay();
        repoFactoryControl.replay();
View Full Code Here

TOP

Related Classes of org.apache.archiva.metadata.model.ArtifactMetadata

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.