Package org.apache.maven.archiva.model

Examples of org.apache.maven.archiva.model.ArtifactReference


        {
            return;
        }

        // Build the artifact POM reference
        ArtifactReference pomReference = new ArtifactReference();
        pomReference.setGroupId( artifact.getGroupId() );
        pomReference.setArtifactId( artifact.getArtifactId() );
        pomReference.setVersion( artifact.getVersion() );
        pomReference.setType( "pom" );

        // Get the artifact POM from proxied repositories if needed
        connectors.fetchFromProxies( managedRepository, pomReference );

        // Open and read the POM from the managed repo
View Full Code Here


     * @param classifier TODO
     */
    private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
        throws LayoutException
    {
        ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );

        // --- Artifact Tests.
        // Artifact to Path
        assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );

        // --- Artifact Reference Tests

        // Path to Artifact Reference.
        ArtifactReference testReference = toArtifactReference( path );
        assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );

        // And back again, using test Reference from previous step.
        assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
    }
View Full Code Here

        assertEquals( expectedId + " - Type", type, actualReference.getType() );
    }

    protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, String type )
    {
        ArtifactReference artifact = new ArtifactReference();
        artifact.setGroupId( groupId );
        artifact.setArtifactId( artifactId );
        artifact.setVersion( version );
        artifact.setClassifier( classifier );
        artifact.setType( type );
        assertNotNull( artifact );
        return artifact;
    }
View Full Code Here

    private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";

    protected static ArtifactReference toArtifactReference( String path )
        throws LayoutException
    {
        ArtifactReference artifact = new ArtifactReference();

        String normalizedPath = StringUtils.replace( path, "\\", "/" );

        String pathParts[] = StringUtils.split( normalizedPath, '/' );

        /* Always 3 parts. (Never more or less)
         *
         *   path = "commons-lang/jars/commons-lang-2.1.jar"
         *   path[0] = "commons-lang";          // The Group ID
         *   path[1] = "jars";                  // The Directory Type
         *   path[2] = "commons-lang-2.1.jar";  // The Filename.
         */

        if ( pathParts.length != 3 )
        {
            // Illegal Path Parts Length.
            throw new LayoutException( INVALID_ARTIFACT_PATH
                + "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found "
                + pathParts.length + " instead." );
        }

        // The Group ID.
        artifact.setGroupId( pathParts[0] );

        // The Expected Type.
        String expectedType = pathParts[1];

        // Sanity Check: expectedType should end in "s".
        if ( !expectedType.endsWith( "s" ) )
        {
            throw new LayoutException( INVALID_ARTIFACT_PATH
                + "legacy paths should have an expected type ending in [s] in the second part of the path." );
        }

        // The Filename.
        String filename = pathParts[2];

        FilenameParser parser = new FilenameParser( filename );

        artifact.setArtifactId( parser.nextNonVersion() );

        // Sanity Check: does it have an artifact id?
        if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
        {
            // Special Case: The filename might start with a version id (like "test-arch-1.0.jar").
            int idx = filename.indexOf( '-' );
            if ( idx > 0 )
            {
                parser.reset();
                // Take the first section regardless of content.
                String artifactId = parser.next();
               
                // Is there anything more that is considered not a version id?
                String moreArtifactId = parser.nextNonVersion();
                if ( StringUtils.isNotBlank( moreArtifactId ) )
                {
                    artifact.setArtifactId( artifactId + "-" + moreArtifactId );
                }
                else
                {
                    artifact.setArtifactId( artifactId );
                }
            }

            // Sanity Check: still no artifact id?
            if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
            {
                throw new LayoutException( INVALID_ARTIFACT_PATH + "no artifact id present." );
            }
        }

        artifact.setVersion( parser.remaining() );

        // Sanity Check: does it have a version?
        if ( StringUtils.isEmpty( artifact.getVersion() ) )
        {
            // Special Case: use last section of artifactId as version.
            String artifactId = artifact.getArtifactId();
            int idx = artifactId.lastIndexOf( '-' );
            if ( idx > 0 )
            {
                artifact.setVersion( artifactId.substring( idx + 1 ) );
                artifact.setArtifactId( artifactId.substring( 0, idx ) );
            }
            else
            {
                throw new LayoutException( INVALID_ARTIFACT_PATH + "no version found." );
            }
        }

        // Set Type
        artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
       
        // Sanity Check: does it have an extension?
        if ( StringUtils.isEmpty( artifact.getType() ) )
        {
            throw new LayoutException( INVALID_ARTIFACT_PATH + "no extension found." );
        }

        // Special Case with Maven Plugins
        if ( StringUtils.equals( "jar", artifact.getType() ) && StringUtils.equals( "plugins", expectedType ) )
        {
            artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN );
        }
        else
        {
            // Sanity Check: does extension match pathType on path?
            String trimPathType = expectedType.substring( 0, expectedType.length() - 1 );
   
            String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType );
            String actualExtension = parser.getExtension();
   
            if ( !expectedExtension.equals( actualExtension ) )
            {
                throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + actualExtension
                    + "] and layout specified type [" + expectedType + "] (which maps to extension: ["
                    + expectedExtension + "]) on path [" + path + "]" );
            }
        }

        String classifier = ArtifactClassifierMapping.getClassifier( artifact.getType() );
        if ( classifier != null )
        {
            String version = artifact.getVersion();
            if ( ! version.endsWith( "-" + classifier ) )
            {
                throw new LayoutException( INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier );
            }
            version = version.substring( 0, version.length() - classifier.length() - 1 );
            artifact.setVersion( version );
            artifact.setClassifier( classifier );
        }

        return artifact;
    }
View Full Code Here

        // Ignore paths like .indexer etc
        if ( !path.startsWith( "." ) )
        {
            try
            {
                ArtifactReference artifact = repository.toArtifactReference( path );
                updateVersionMetadata( artifact, path );
                updateProjectMetadata( artifact, path );
            }
            catch ( LayoutException e )
            {
View Full Code Here

            if ( !artifactFile.exists() )
            {
                return;
            }

            ArtifactReference artifact = repository.toArtifactReference( path );

            Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
            olderThanThisDate.add( Calendar.DATE, -daysOlder );

            // respect retention count
            VersionedReference reference = new VersionedReference();
            reference.setGroupId( artifact.getGroupId() );
            reference.setArtifactId( artifact.getArtifactId() );
            reference.setVersion( artifact.getVersion() );

            List<String> versions = new ArrayList<String>( repository.getVersions( reference ) );

            Collections.sort( versions, VersionComparator.getInstance() );

            if ( retentionCount > versions.size() )
            {
                // Done. nothing to do here. skip it.
                return;
            }

            int countToPurge = versions.size() - retentionCount;

            for ( String version : versions )
            {
                if ( countToPurge-- <= 0 )
                {
                    break;
                }

                ArtifactReference newArtifactReference =
                    repository.toArtifactReference( artifactFile.getAbsolutePath() );
                newArtifactReference.setVersion( version );

                File newArtifactFile = repository.toFile( newArtifactReference );

                // Is this a generic snapshot "1.0-SNAPSHOT" ?
                if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion() ) )
                {
                    if ( newArtifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
                    {
                        doPurgeAllRelated( newArtifactReference );
                    }
                }
                // Is this a timestamp snapshot "1.0-20070822.123456-42" ?
                else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion() ) )
                {
                    Calendar timestampCal = uniqueSnapshotToCalendar( newArtifactReference.getVersion() );

                    if ( timestampCal.getTimeInMillis() < olderThanThisDate.getTimeInMillis() )
                    {
                        doPurgeAllRelated( newArtifactReference );
                    }
View Full Code Here

            {
                // Nothing to do here, file doesn't exist, skip it.
                return;
            }

            ArtifactReference artifactRef = repository.toArtifactReference( path );

            if ( !VersionUtil.isSnapshot( artifactRef.getVersion() ) )
            {
                // Nothing to do here, not a snapshot, skip it.
                return;
            }

            ProjectReference reference = new ProjectReference();
            reference.setGroupId( artifactRef.getGroupId() );
            reference.setArtifactId( artifactRef.getArtifactId() );
           
            // Gather up all of the versions.
            List<String> allVersions = new ArrayList<String>( repository.getVersions( reference ) );

            List<ManagedRepositoryConfiguration> repos = archivaConfig.getConfiguration().getManagedRepositories();
            for( ManagedRepositoryConfiguration repo : repos )
            {  
                if( repo.isReleases() && !repo.getId().equals( repository.getId() ) )
                {  
                    try
                    {  
                        ManagedRepositoryContent repoContent = repoContentFactory.getManagedRepositoryContent( repo.getId() );                       
                        allVersions.addAll( repoContent.getVersions( reference ) );
                    }
                    catch( RepositoryNotFoundException  e )
                    {
                        // swallow
                    }
                    catch( RepositoryException  e )
                    {
                        // swallow
                    }
                }
            }

            // Split the versions into released and snapshots.
            List<String> releasedVersions = new ArrayList<String>();
            List<String> snapshotVersions = new ArrayList<String>();

            for ( String version : allVersions )
            {  
                if ( VersionUtil.isSnapshot( version ) )
                {
                    snapshotVersions.add( version );
                }
                else
                {
                    releasedVersions.add( version );
                }
            }

            Collections.sort( allVersions, VersionComparator.getInstance() );
            Collections.sort( releasedVersions, VersionComparator.getInstance() );
            Collections.sort( snapshotVersions, VersionComparator.getInstance() );
           
            // Now clean out any version that is earlier than the highest released version.
            boolean needsMetadataUpdate = false;

            VersionedReference versionRef = new VersionedReference();
            versionRef.setGroupId( artifactRef.getGroupId() );
            versionRef.setArtifactId( artifactRef.getArtifactId() );
           
            ArchivaArtifact artifact =
                new ArchivaArtifact( artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(),
                                     artifactRef.getClassifier(), artifactRef.getType(), repository.getId() );
           
            for ( String version : snapshotVersions )
            {  
                if( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) )
                {                   
View Full Code Here

            if ( !artifactFile.exists() )
            {
                return;
            }
                                                                    
            ArtifactReference artifact = repository.toArtifactReference( path );

            if ( VersionUtil.isSnapshot( artifact.getVersion() ) )
            {
                VersionedReference reference = new VersionedReference();
                reference.setGroupId( artifact.getGroupId() );
                reference.setArtifactId( artifact.getArtifactId() );
                reference.setVersion( artifact.getVersion() );

                List<String> versions = new ArrayList<String>( repository.getVersions( reference ) );

                Collections.sort( versions, VersionComparator.getInstance() );
View Full Code Here

    }

    private void doPurgeAllRelated( ArtifactReference reference, String version )
        throws LayoutException
    {
        ArtifactReference artifact = new ArtifactReference();
        artifact.setGroupId( reference.getGroupId() );
        artifact.setArtifactId( reference.getArtifactId() );
        artifact.setVersion( version );
        artifact.setClassifier( reference.getClassifier() );
        artifact.setType( reference.getType() );
       
        try
        {
            Set<ArtifactReference> related = repository.getRelatedArtifacts( artifact );
            purge( related );
View Full Code Here

        try
        {
            ManagedRepositoryConfiguration repoConfig =
                configuration.getConfiguration().findManagedRepositoryById( repositoryId );

            ArtifactReference artifactReference = new ArtifactReference();
            artifactReference.setArtifactId( artifactId );
            artifactReference.setGroupId( groupId );
            artifactReference.setVersion( version );
            artifactReference.setClassifier( classifier );
            artifactReference.setType( packaging );

            ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );

            String artifactPath = repository.toPath( artifactReference );
View Full Code Here

TOP

Related Classes of org.apache.maven.archiva.model.ArtifactReference

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.