Examples of ArtifactReference


Examples of org.apache.archiva.model.ArtifactReference

    public void testManagedLegacyNotPresentRemoteLegacyNotPresent()
        throws Exception
    {
        String path = "org.apache.archiva.test/jars/mystery-lib-1.0.jar";
        File expectedFile = new File( managedLegacyDir, path );
        ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );

        assertNotExistsInManagedLegacyRepo( expectedFile );

        // Configure Connector (usually done within archiva.xml configuration)
        saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

    public void testManagedLegacyNotPresentRemoteDefaultNotPresent()
        throws Exception
    {
        String path = "org.apache.archiva.test/jars/mystery-lib-2.1.jar";
        File expectedFile = new File( managedLegacyDir, path );
        ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );

        assertNotExistsInManagedLegacyRepo( expectedFile );

        // Configure Connector (usually done within archiva.xml configuration)
        saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, false );
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

     * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(java.lang.String)
     */
    public ArtifactReference toArtifactReference( String path )
        throws LayoutException
    {
        ArtifactReference artifact = new ArtifactReference();

        // First, look if a custom resolution rule has been set for this artifact
        Collection<LegacyArtifactPath> legacy = configuration.getConfiguration().getLegacyArtifactPaths();
        for ( LegacyArtifactPath legacyPath : legacy )
        {
            if ( legacyPath.match( path ) )
            {
                artifact.setGroupId( legacyPath.getGroupId() );
                artifact.setArtifactId( legacyPath.getArtifactId() );
                artifact.setClassifier( legacyPath.getClassifier() );
                artifact.setVersion( legacyPath.getVersion() );
                artifact.setType( legacyPath.getType() );
                return artifact;
            }
        }

        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." );
            }
        }

        String classifier = ArtifactClassifierMapping.getClassifier( expectedType );
        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 );
        }

        String extension = parser.getExtension();

        // Set Type
        String defaultExtension = expectedType.substring( 0, expectedType.length() - 1 );
        artifact.setType(
            ArtifactExtensionMapping.mapExtensionAndClassifierToType( classifier, extension, defaultExtension ) );

        // 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", extension ) && StringUtils.equals( "plugins", expectedType ) )
        {
            artifact.setType( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN );
        }
        else
        {
            // Sanity Check: does extension match pathType on path?
            String expectedExtension = ArtifactExtensionMapping.getExtension( artifact.getType() );

            if ( !expectedExtension.equals( extension ) )
            {
                throw new LayoutException(
                    INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension + "] and layout specified type ["
                        + artifact.getType() + "] (which maps to extension: [" + expectedExtension + "]) on path ["
                        + path + "]" );
            }
        }

        return artifact;
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

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

            // Gether the released versions
            List<String> releasedVersions = new ArrayList<String>();

            List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
            for ( ManagedRepository repo : repos )
            {
                if ( repo.isReleases() )
                {
                    try
                    {
                        ManagedRepositoryContent repoContent =
                            repoContentFactory.getManagedRepositoryContent( repo.getId() );
                        for ( String version : repoContent.getVersions( reference ) )
                        {
                            if ( !VersionUtil.isSnapshot( version ) )
                            {
                                releasedVersions.add( version );
                            }
                        }
                    }
                    catch ( RepositoryNotFoundException e )
                    {
                        // swallow
                    }
                    catch ( RepositoryException e )
                    {
                        // swallow
                    }
                }
            }

            Collections.sort( releasedVersions, 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() );

            MetadataRepository metadataRepository = repositorySession.getRepository();

            if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion() ) ) )
            {
                versionRef.setVersion( artifactRef.getVersion() );
                repository.deleteVersion( versionRef );

                // FIXME: looks incomplete, might not delete related metadata?
                for ( RepositoryListener listener : listeners )
                {
                    listener.deleteArtifact( metadataRepository, repository.getId(), artifactRef.getGroupId(),
                                             artifactRef.getArtifactId(), artifactRef.getVersion(),
                                             artifactFile.getName() );
                }

                needsMetadataUpdate = true;
            }
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

    {
        String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
        setupTestableManagedRepository( path );

        File expectedFile = new File( managedDefaultDir, path );
        ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

        // Ensure file isn't present first.
        assertNotExistsInManagedDefaultRepo( expectedFile );

        // Configure Connector (usually done within archiva.xml configuration)
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

    {
        String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
        setupTestableManagedRepository( path );

        File expectedFile = new File( managedDefaultDir, path );
        ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

        // Ensure file isn't present first.
        assertNotExistsInManagedDefaultRepo( expectedFile );

        // Configure Connector (usually done within archiva.xml configuration)
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
        setupTestableManagedRepository( path );

        File expectedFile = new File( managedDefaultDir, path );

        ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

        assertTrue( expectedFile.exists() );

        // Configure Connector (usually done within archiva.xml configuration)
        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

       
        // Set the managed File to be newer than local.
        setManagedNewerThanRemote( expectedFile, remoteFile );

        long originalModificationTime = expectedFile.lastModified();
        ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

        assertTrue( expectedFile.exists() );

        // Configure Connector (usually done within archiva.xml configuration)
        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

        File remoteFile = new File( REPOPATH_PROXIED1, path );
       
        // Set the managed file to be newer than remote file.
        setManagedOlderThanRemote( expectedFile, remoteFile );
   
        ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

        assertTrue( expectedFile.exists() );

        // Configure Connector (usually done within archiva.xml configuration)
        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
View Full Code Here

Examples of org.apache.archiva.model.ArtifactReference

    {
        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
        setupTestableManagedRepository( path );

        File expectedFile = new File( managedDefaultDir, path );
        ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

        assertTrue( expectedFile.exists() );
        expectedFile.setLastModified( getPastDate().getTime() );

        // Configure Connector (usually done within archiva.xml configuration)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.