Package org.apache.maven.artifact.versioning

Examples of org.apache.maven.artifact.versioning.VersionRange


            Dependency dependency = (Dependency)dependencies.next();

            String groupId = dependency.getGroupId();
            String artifactId = dependency.getArtifactId();

            VersionRange versionRange;
            try {
                versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
            } catch (InvalidVersionSpecificationException e) {
                throw new MojoExecutionException("unable to parse version", e);
            }
View Full Code Here


            Dependency dependency = (Dependency)dependencies.next();

            String groupId = dependency.getGroupId();
            String artifactId = dependency.getArtifactId();

            VersionRange versionRange;
            try {
                versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
            } catch (InvalidVersionSpecificationException e) {
                throw new MojoExecutionException("unable to parse version", e);
            }
View Full Code Here

        if (implementationClass == null)
        {
            return false;
        }

        VersionRange range = VersionRange.createFromVersionSpec(versionRange == null ? cdiImplementation
                .getVersionRange() : versionRange);
        String containerVersion = getJarSpecification(implementationClass);
        return containerVersion != null && range.containsVersion(new DefaultArtifactVersion(containerVersion));
    }
View Full Code Here

        {
            if ( version == null )
            {
                version = Artifact.RELEASE_VERSION;
            }
            VersionRange versionSpec = VersionRange.createFromVersionSpec( version );
            artifact =
                factory.createDependencyArtifact( skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar", null,
                                                  null );

            resolver.resolve( artifact, getProject().getRemoteArtifactRepositories(), localRepository );
View Full Code Here

        return Collections.EMPTY_LIST;
    }

    protected File getLocalArtifactPath( String groupId, String artifactId, String version, String type )
    {
        VersionRange versionRange = VersionRange.createFromVersion( version );

        Artifact artifact =
            new DefaultArtifact( groupId, artifactId, versionRange, Artifact.SCOPE_COMPILE, type, null,
                                 new DefaultArtifactHandler( type ) );
View Full Code Here

                ResolutionNode previous = (ResolutionNode) i.next();

                if ( previous.isActive() )
                {
                    // Version mediation
                    VersionRange previousRange = previous.getArtifact().getVersionRange();
                    VersionRange currentRange = node.getArtifact().getVersionRange();

                    if ( previousRange != null && currentRange != null )
                    {
                        // TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
                        // version but the restriction is identical
                        VersionRange newRange = previousRange.restrict( currentRange );
                        // TODO: ick. this forces the OCE that should have come from the previous call. It is still correct
                        if ( newRange.isSelectedVersionKnown( previous.getArtifact() ) )
                        {
                            fireEvent( ResolutionListener.RESTRICT_RANGE, listeners, node, previous.getArtifact(),
                                       newRange );
                        }
                        previous.getArtifact().setVersionRange( newRange );
                        node.getArtifact().setVersionRange( currentRange.restrict( previousRange ) );

                        //Select an appropriate available version from the (now restricted) range
                        //Note this version was selected before to get the appropriate POM
                        //But it was reset by the call to setVersionRange on restricting the version
                        ResolutionNode[] resetNodes = {previous, node};
                        for ( int j = 0; j < 2; j++ )
                        {
                            Artifact resetArtifact = resetNodes[j].getArtifact();

                            //MNG-2123: if the previous node was not a range, then it wouldn't have any available
                            //versions. We just clobbered the selected version above. (why? i have no idea.)
                            //So since we are here and this is ranges we must go figure out the version (for a third time...)
                            if ( resetArtifact.getVersion() == null && resetArtifact.getVersionRange() != null )
                            {

                                // go find the version. This is a total hack. See previous comment.
                                List versions = resetArtifact.getAvailableVersions();
                                if ( versions == null )
                                {
                                    try
                                    {
                                        versions =
                                            source.retrieveAvailableVersions( resetArtifact, localRepository,
                                                                              remoteRepositories );
                                        resetArtifact.setAvailableVersions( versions );
                                    }
                                    catch ( ArtifactMetadataRetrievalException e )
                                    {
                                        resetArtifact.setDependencyTrail( node.getDependencyTrail() );
                                        throw new ArtifactResolutionException(
                                                                               "Unable to get dependency information: " +
                                                                                   e.getMessage(), resetArtifact,
                                                                               remoteRepositories, e );
                                    }
                                }
                                //end hack

                                //MNG-2861: match version can return null
                                ArtifactVersion selectedVersion = resetArtifact.getVersionRange().matchVersion( resetArtifact.getAvailableVersions() );
                                if (selectedVersion != null)
                                {
                                  resetArtifact.selectVersion( selectedVersion.toString() );
                                }
                                else
                                {
                                  throw new OverConstrainedVersionException(" Unable to find a version in "+ resetArtifact.getAvailableVersions()+" to match the range "+ resetArtifact.getVersionRange(), resetArtifact);
                                }

                                fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, resetNodes[j] );
                            }
                        }
                    }

                    // Conflict Resolution
                    // TODO: use as conflict resolver(s), chain

                    // TODO: should this be part of mediation?
                    // previous one is more dominant
                    ResolutionNode nearest;
                    ResolutionNode farthest;
                    if ( previous.getDepth() <= node.getDepth() )
                    {
                        nearest = previous;
                        farthest = node;
                    }
                    else
                    {
                        nearest = node;
                        farthest = previous;
                    }

                    if ( checkScopeUpdate( farthest, nearest, listeners ) )
                    {
                        // if we need to update scope of nearest to use farthest scope, use the nearest version, but farthest scope
                        nearest.disable();
                        farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() );
                        fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, nearest, farthest.getArtifact() );
                    }
                    else
                    {
                        farthest.disable();
                        fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, farthest, nearest.getArtifact() );
                    }
                }
            }
        }
        else
        {
            previousNodes = new ArrayList();
            resolvedArtifacts.put( key, previousNodes );
        }
        previousNodes.add( node );

        if ( node.isActive() )
        {
            fireEvent( ResolutionListener.INCLUDE_ARTIFACT, listeners, node );
        }

        // don't pull in the transitive deps of a system-scoped dependency.
        if ( node.isActive() && !Artifact.SCOPE_SYSTEM.equals( node.getArtifact().getScope() ) )
        {
            fireEvent( ResolutionListener.PROCESS_CHILDREN, listeners, node );

            Artifact parentArtifact = node.getArtifact();
           
            for ( Iterator i = node.getChildrenIterator(); i.hasNext(); )
            {
                ResolutionNode child = (ResolutionNode) i.next();

                // We leave in optional ones, but don't pick up its dependencies
                if ( !child.isResolved() && ( !child.getArtifact().isOptional() || child.isChildOfRootNode() ) )
                {
                    Artifact artifact = child.getArtifact();
                    List childRemoteRepositories = child.getRemoteRepositories();
                    try
                    {
                        Object childKey;
                        do
                        {
                            childKey = child.getKey();

                            if ( managedVersions.containsKey( childKey ) )
                            {
                                // If this child node is a managed dependency, ensure
                                // we are using the dependency management version
                                // of this child if applicable b/c we want to use the
                                // managed version's POM, *not* any other version's POM.
                                // We retrieve the POM below in the retrieval step.
                                manageArtifact( child, managedVersions, listeners );

                                // Also, we need to ensure that any exclusions it presents are
                                // added to the artifact before we retrieve the metadata
                                // for the artifact; otherwise we may end up with unwanted
                                // dependencies.
                                Artifact ma = (Artifact) managedVersions.get( childKey );
                                ArtifactFilter managedExclusionFilter = ma.getDependencyFilter();
                                if ( null != managedExclusionFilter )
                                {
                                    if ( null != artifact.getDependencyFilter() )
                                    {
                                        AndArtifactFilter aaf = new AndArtifactFilter();
                                        aaf.add( artifact.getDependencyFilter() );
                                        aaf.add( managedExclusionFilter );
                                        artifact.setDependencyFilter( aaf );
                                    }
                                    else
                                    {
                                        artifact.setDependencyFilter( managedExclusionFilter );
                                    }
                                }
                            }

                            if ( artifact.getVersion() == null )
                            {
                                // set the recommended version
                                // TODO: maybe its better to just pass the range through to retrieval and use a transformation?
                                ArtifactVersion version;
                                if ( artifact.isSelectedVersionKnown() )
                                {
                                    version = artifact.getSelectedVersion();
                                }
                                else
                                {
                                    //go find the version
                                    List versions = artifact.getAvailableVersions();
                                    if ( versions == null )
                                    {
                                        versions = source.retrieveAvailableVersions( artifact, localRepository,
                                                                                     childRemoteRepositories );
                                        artifact.setAvailableVersions( versions );
                                    }

                                    Collections.sort( versions );

                                    VersionRange versionRange = artifact.getVersionRange();

                                    version = versionRange.matchVersion( versions );

                                    if ( version == null )
                                    {
                                        // Getting the dependency trail so it can be logged in the exception
                                        artifact.setDependencyTrail( node.getDependencyTrail() );
View Full Code Here

            {
                Dependency d = (Dependency) i.next();

                try
                {
                    VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );

                    Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
                                                                                  versionRange, d.getType(),
                                                                                  d.getClassifier(), d.getScope(),
                                                                                  d.isOptional() );
View Full Code Here

                }

                Artifact artifact;
                try
                {
                    VersionRange versionRange = VersionRange.createFromVersionSpec( version );
                    artifact =
                        artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange );
                }
                catch ( InvalidVersionSpecificationException e )
                {
View Full Code Here

        // FIXME: need to find out how a plugin gets marked as 'installed'
        // and no ChildContainer exists. The check for that below fixes
        // the 'Can't find plexus container for plugin: xxx' error.
        try
        {
            VersionRange versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );

            List remoteRepositories = new ArrayList();
            remoteRepositories.addAll( project.getPluginArtifactRepositories() );
            remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
View Full Code Here

        // Maven uses is hidden from downstream use. We will also bump up any
        // anything below 1.1 to 1.1 as this mimics the behaviour in 2.0.5 where
        // plexus-utils 1.1 was being forced into use.
        // ----------------------------------------------------------------------------

        VersionRange vr = null;

        try
        {
            vr = VersionRange.createFromVersionSpec( "[1.1,)" );
        }
        catch ( InvalidVersionSpecificationException e )
        {
            // Won't happen
        }

        boolean plexusUtilsPresent = false;

        for ( Iterator i = dependencyArtifacts.iterator(); i.hasNext(); )
        {
            Artifact a = (Artifact) i.next();

            if ( a.getArtifactId().equals( "plexus-utils" ) &&
                vr.containsVersion( new DefaultArtifactVersion( a.getVersion() ) ) )
            {
                plexusUtilsPresent = true;

                break;
            }
View Full Code Here

TOP

Related Classes of org.apache.maven.artifact.versioning.VersionRange

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.