Package org.apache.archiva.metadata.model

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


        {
            // 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() );

            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
            {
                ReadMetadataRequest readMetadataRequest =
                    new ReadMetadataRequest().repositoryId( repoId ).namespace( artifact.getNamespace() ).projectId(
                        artifact.getProject() ).projectVersion( projectVersion );
                versionMetadata = repositoryStorage.readProjectVersionMetadata( readMetadataRequest );
                createVersionMetadata = true;
            }
            catch ( RepositoryStorageMetadataNotFoundException e )
            {
                log.warn( "Missing or invalid POM for artifact:{} (repository:{}); creating empty metadata", path,
                          repoId );

                versionMetadata = new ProjectVersionMetadata();
                versionMetadata.setId( projectVersion );
                versionMetadata.setIncomplete( true );
                createVersionMetadata = true;
            }
            catch ( RepositoryStorageMetadataInvalidException e )
            {
                log.warn( "Error occurred resolving POM for artifact:{} (repository:{}); message: {}",
                          new Object[]{ path, repoId, 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


            throw new ConsumerException( e.getMessage(), e );
        }

        if ( CollectionUtils.isNotEmpty( results ) )
        {
            ArtifactMetadata originalArtifact;
            try
            {
                originalArtifact = pathTranslator.getArtifactForPath( repoId, path );
            }
            catch ( Exception e )
            {
                log.warn( "Not reporting problem for invalid artifact in checksum check: {}", e.getMessage() );
                return;
            }

            for ( ArtifactMetadata dupArtifact : results )
            {
                String id = path.substring( path.lastIndexOf( '/' ) + 1 );
                if ( dupArtifact.getId().equals( id ) && dupArtifact.getNamespace().equals(
                    originalArtifact.getNamespace() ) && dupArtifact.getProject().equals(
                    originalArtifact.getProject() ) && dupArtifact.getVersion().equals(
                    originalArtifact.getVersion() ) )
                {
                    // Skip reference to itself.

                    log.debug( "Not counting duplicate for artifact {} for path {}", dupArtifact, path );

                    continue;
                }

                RepositoryProblemFacet problem = new RepositoryProblemFacet();
                problem.setRepositoryId( repoId );
                problem.setNamespace( originalArtifact.getNamespace() );
                problem.setProject( originalArtifact.getProject() );
                problem.setVersion( originalArtifact.getVersion() );
                problem.setId( id );
                // FIXME: need to get the right storage resolver for the repository the dupe artifact is in, it might be
                //       a different type
                // FIXME: we need the project version here, not the artifact version
                problem.setMessage( "Duplicate Artifact Detected: " + path + " <--> " + pathTranslator.toPath(
View Full Code Here

        assertEquals( "duplicate-artifact", problem.getProblem() );
    }

    private static ArtifactMetadata createMetadata( String version )
    {
        ArtifactMetadata artifact = new ArtifactMetadata();
        artifact.setId( TEST_PROJECT + "-" + version + ".jar" );
        artifact.setNamespace( TEST_NAMESPACE );
        artifact.setProject( TEST_PROJECT );
        artifact.setProjectVersion( version );
        artifact.setVersion( version );
        artifact.setRepositoryId( TEST_REPO );
        return artifact;
    }
View Full Code Here

            repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
        assertThat( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull();

        assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isEmpty();

        ArtifactMetadata metadata = createArtifact();

        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        Collection<ArtifactMetadata> artifacts =
            repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
View Full Code Here

        MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
        versionMetadata.addFacet( facet );
        repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );

        ArtifactMetadata artifactMetadata = createArtifact();
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
        repository.save();

        Collection<ArtifactMetadata> artifacts =
            repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
View Full Code Here

    @Test
    public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved()
        throws Exception
    {
        ArtifactMetadata metadata = createArtifact();

        Map<String, String> additionalProps = new HashMap<>();
        additionalProps.put( "deleteKey", "deleteValue" );

        MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
        metadata.addFacet( facet );
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        Collection<ArtifactMetadata> artifacts =
            repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );

        assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
        metadata = artifacts.iterator().next();

        Collection<String> ids = metadata.getFacetIds();
        assertThat( ids ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );

        TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
        Map<String, String> facetProperties = testFacet.toProperties();

        assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );

        facetProperties.remove( "deleteKey" );

        TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
        metadata.addFacet( newTestFacet );

        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );

        assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
        metadata = artifacts.iterator().next();

        ids = metadata.getFacetIds();
        assertThat( ids ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );

        testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );

        Map<String, String> props = testFacet.toProperties();
        assertThat( props ).isNotNull().doesNotContainKey( "deleteKey" );
    }
View Full Code Here

    @Test
    public void testUpdateArtifactMetadataWithExistingFacets()
        throws Exception
    {
        ArtifactMetadata metadata = createArtifact();
        MetadataFacet facet = new TestMetadataFacet( "baz" );
        metadata.addFacet( facet );
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
                                            TEST_PROJECT_VERSION ).iterator().next();
        assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );

        metadata = createArtifact();
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
                                            TEST_PROJECT_VERSION ).iterator().next();
        assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
        TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
        assertEquals( "baz", testFacet.getValue() );
    }
View Full Code Here

    @Test
    public void testUpdateArtifactMetadataWithNoExistingFacets()
        throws Exception
    {
        ArtifactMetadata metadata = createArtifact();
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
                                            TEST_PROJECT_VERSION ).iterator().next();
        assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );

        metadata = createArtifact();
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );

        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
                                            TEST_PROJECT_VERSION ).iterator().next();
        assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
    }
View Full Code Here

    @Test
    public void testGetArtifacts()
        throws Exception
    {
        ArtifactMetadata artifact1 = createArtifact();
        ArtifactMetadata artifact2 = createArtifact( "pom" );
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );

        Collection<ArtifactMetadata> artifacts =
            repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
View Full Code Here

    @Test
    public void testGetArtifactVersions()
        throws Exception
    {
        ArtifactMetadata artifact1 = createArtifact();
        String version1 = "1.0-20091212.012345-1";
        artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" );
        artifact1.setVersion( version1 );
        ArtifactMetadata artifact2 = createArtifact();
        String version2 = "1.0-20091212.123456-2";
        artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" );
        artifact2.setVersion( version2 );
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );

        Collection<String> versions =
            repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
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.