Package org.apache.maven.artifact.versioning

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


     * @param theVersion the version to be checked.
     * @return true if the version is contained by the range.
     */
    public static boolean containsVersion( VersionRange allowedRange, ArtifactVersion theVersion )
    {
        ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion();
        if ( recommendedVersion == null )
        {
            List<Restriction> restrictions = allowedRange.getRestrictions();
            for ( Restriction restriction : restrictions )
            {
                if ( restriction.containsVersion( theVersion ) )
                {
                    return true;
                }
            }
        }

        // only singular versions ever have a recommendedVersion
        return recommendedVersion.compareTo( theVersion ) <= 0;
    }
View Full Code Here


        if ( testNgVersion != null )
        {
            goals1.add( "-DtestNgVersion=" + testNgVersion );

            ArtifactVersion v = new DefaultArtifactVersion( testNgVersion );
            try
            {
                if ( VersionRange.createFromVersionSpec( "(,5.12.1)" ).containsVersion( v ) )
                {
                    goals1.add( "-DtestNgClassifier=jdk15" );
View Full Code Here

        if ( testNgVersion != null )
        {
            goals.add( "-DtestNgVersion=" + testNgVersion );

            ArtifactVersion v = new DefaultArtifactVersion( testNgVersion );
            try
            {
                if ( VersionRange.createFromVersionSpec( "(,5.12.1)" ).containsVersion( v ) )
                {
                    goals.add( "-DtestNgClassifier=jdk15" );
View Full Code Here

    protected boolean isMavenVersion( String version )
    {
        try
        {
            VersionRange versionRange = VersionRange.createFromVersionSpec( version );
            ArtifactVersion mavenVersion = runtimeInformation.getApplicationVersion();
            return versionRange.containsVersion( mavenVersion );
        }
        catch ( InvalidVersionSpecificationException e )
        {
            throw new IllegalArgumentException( e.getMessage() );
View Full Code Here

        if ( this.testNgVersion != null )
        {
            goals1.add( "-DtestNgVersion=" + testNgVersion );

            ArtifactVersion v = new DefaultArtifactVersion( testNgVersion );
            try
            {
                if ( VersionRange.createFromVersionSpec( "(,5.12.1)" ).containsVersion( v ) )
                {
                    goals1.add( "-DtestNgClassifier=jdk15" );
View Full Code Here

        int depth1 = e1.getDepth();
        int depth2 = e2.getDepth();

        if ( depth1 == depth2 )
        {
            ArtifactVersion v1 = new DefaultArtifactVersion( e1.getVersion() );
            ArtifactVersion v2 = new DefaultArtifactVersion( e2.getVersion() );

            if ( newerFirst )
            {
                return v1.compareTo( v2 ) > 0 ? e1 : e2;
            }
View Full Code Here

            return changeVersion(jarFile, project.getVersion(), newVersion);
        }
       
        // if this is a final release append "final"
        try {
            final ArtifactVersion v = this.project.getArtifact().getSelectedVersion();
            if ( v.getBuildNumber() == 0 && v.getQualifier() == null ) {
                final String newVersion = this.project.getArtifact().getVersion() + ".FINAL";
                return changeVersion(jarFile, project.getVersion(), newVersion);
            }
        } catch (OverConstrainedVersionException ocve) {
            // we ignore this and don't append "final"!
View Full Code Here

    public void execute() throws MojoExecutionException, MojoFailureException {
        getLog().debug("Looking for previous release of " + project.getGroupId() + ":" + project.getArtifactId() + ":"
                + project.getVersion());
        Artifact projectArtifact = artifactFactory
                .createProjectArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion());
        ArtifactVersion projectVersion = new DefaultArtifactVersion(project.getVersion());

        ArtifactVersion latest = null;
        try {
            List<ArtifactVersion> artifactVersions = artifactMetadataSource
                    .retrieveAvailableVersions(projectArtifact, localRepository,
                            project.getRemoteArtifactRepositories());
            for (ArtifactVersion version : artifactVersions) {
                if (SNAPSHOT_PATTERN.matcher(version.toString()).find() || projectVersion.compareTo(version) <= 0) {
                    continue;
                }
                if (latest == null || latest.compareTo(version) < 0) {
                    latest = version;
                }
            }
        } catch (ArtifactMetadataRetrievalException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        getLog().debug("Previous release = " + latest);

        Map<GroupArtifactId, String> addedDeps = new LinkedHashMap<GroupArtifactId, String>();
        Map<GroupArtifactId, String> removedDeps = new LinkedHashMap<GroupArtifactId, String>();
        Map<GroupArtifactId, Map.Entry<String, String>> updatedDeps =
                new LinkedHashMap<GroupArtifactId, Map.Entry<String, String>>();

        for (Dependency dep : project.getDependencies()) {
            addedDeps.put(new GroupArtifactId(dep), dep.getVersion());
        }

        String startTag = null;
        String endTag = null;
        if (latest != null) {
            Artifact latestArtifact = artifactFactory
                    .createProjectArtifact(project.getGroupId(), project.getArtifactId(), latest.toString());
            try {
                artifactResolver.resolve(latestArtifact, project.getRemoteArtifactRepositories(), localRepository);
            } catch (ArtifactResolutionException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            } catch (ArtifactNotFoundException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }

            ProjectBuildingRequest request = new DefaultProjectBuildingRequest();

            request.setProcessPlugins(true);
            request.setProfiles(request.getProfiles());
            request.setActiveProfileIds(session.getRequest().getActiveProfiles());
            request.setInactiveProfileIds(session.getRequest().getInactiveProfiles());
            request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
            request.setSystemProperties(session.getSystemProperties());
            request.setUserProperties(session.getUserProperties());
            request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
            request.setPluginArtifactRepositories(session.getRequest().getPluginArtifactRepositories());
            request.setRepositorySession(session.getRepositorySession());
            request.setLocalRepository(localRepository);
            request.setBuildStartTime(session.getRequest().getStartTime());
            request.setResolveDependencies(true);
            request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
            MavenProject latestProject;
            try {
                latestProject = projectBuilder.build(latestArtifact.getFile(), request).getProject();
            } catch (ProjectBuildingException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            for (Dependency dep : latestProject.getDependencies()) {
                GroupArtifactId key = new GroupArtifactId(dep);
                if (addedDeps.containsKey(key)) {
                    String v = addedDeps.get(key);
                    addedDeps.remove(key);
                    if (!v.equals(dep.getVersion())) {
                        updatedDeps.put(key, new AbstractMap.SimpleImmutableEntry<String, String>(dep.getVersion(), v));
                    }
                } else if (updatedDeps.containsKey(key)) {
                    String v = updatedDeps.get(key).getValue();
                    if (!v.equals(dep.getVersion())) {
                        updatedDeps.remove(key);
                        addedDeps.put(key, v);
                    } else {
                        updatedDeps.put(key, new AbstractMap.SimpleImmutableEntry<String, String>(dep.getVersion(), v));
                    }
                } else {
                    removedDeps.put(key, dep.getVersion());
                }
            }

            String tagNameFormat = getTagNameFormat(latestProject);
            getLog().debug("Start Tag name format = " + tagNameFormat);
            Interpolator interpolator = new StringSearchInterpolator("@{", "}");
            List<String> possiblePrefixes = java.util.Arrays.asList("project", "pom");
            Properties values = new Properties();
            values.setProperty("artifactId", project.getArtifactId());
            values.setProperty("groupId", project.getGroupId());
            values.setProperty("version", latest.toString());
            interpolator.addValueSource(new PrefixedPropertiesValueSource(possiblePrefixes, values, true));
            RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor(possiblePrefixes);
            try {
                startTag = interpolator.interpolate(tagNameFormat, recursionInterceptor);
            } catch (InterpolationException e) {
View Full Code Here

     *         otherwise.
     */
    protected boolean isMavenVersion(String version) {
        try {
            VersionRange versionRange = VersionRange.createFromVersionSpec(version);
            ArtifactVersion mavenVersion = runtimeInformation.getApplicationVersion();
            return versionRange.containsVersion(mavenVersion);
        } catch (InvalidVersionSpecificationException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }
View Full Code Here

     * @param artifacts   Set of artifacts for our project
     * @param len         expected length of the version sub-string
     */
    public static String getArtifactVersion(String[] artifactIds, List dependencies, int len) {
        String version = null;
        ArtifactVersion artifactVersion = getArtifactVersion(artifactIds, dependencies);
        if (artifactVersion != null) {
            StringBuffer versionBuffer = new StringBuffer();
            if (len >= 1) {
                versionBuffer.append(artifactVersion.getMajorVersion());
            }
            if (len >= 2) {
                versionBuffer.append('.');
            }
            if (len >= 3) {
                versionBuffer.append(artifactVersion.getMinorVersion());
            }
            if (len >= 4) {
                versionBuffer.append('.');
            }
            if (len >= 5) {
                versionBuffer.append(artifactVersion.getIncrementalVersion());
            }
            version = versionBuffer.toString();
        }
        return version;
    }
View Full Code Here

TOP

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

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.