当前位置: 首页>>代码示例>>Java>>正文


Java ArtifactVersion.toString方法代码示例

本文整理汇总了Java中org.apache.maven.artifact.versioning.ArtifactVersion.toString方法的典型用法代码示例。如果您正苦于以下问题:Java ArtifactVersion.toString方法的具体用法?Java ArtifactVersion.toString怎么用?Java ArtifactVersion.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.maven.artifact.versioning.ArtifactVersion的用法示例。


在下文中一共展示了ArtifactVersion.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copySnapshot

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
static ArtifactVersion copySnapshot( ArtifactVersion source, ArtifactVersion destination )
{
    if ( isSnapshot( destination ) )
    {
        destination = stripSnapshot( destination );
    }
    Pattern matchSnapshotRegex = SNAPSHOT_PATTERN;
    final Matcher matcher = matchSnapshotRegex.matcher( source.toString() );
    if ( matcher.find() )
    {
        return new DefaultArtifactVersion( destination.toString() + "-" + matcher.group( 0 ) );
    }
    else
    {
        return new DefaultArtifactVersion( destination.toString() + "-SNAPSHOT" );
    }
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:18,代码来源:VersionComparators.java

示例2: getRequiredMavenVersion

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
private String getRequiredMavenVersion( MavenProject mavenProject, String defaultValue )
{
    ArtifactVersion requiredMavenVersion = null;
    while ( mavenProject != null )
    {
        final Prerequisites prerequisites = mavenProject.getPrerequisites();
        final String mavenVersion = prerequisites == null ? null : prerequisites.getMaven();
        if ( mavenVersion != null )
        {
            final ArtifactVersion v = new DefaultArtifactVersion( mavenVersion );
            if ( requiredMavenVersion == null || requiredMavenVersion.compareTo( v ) < 0 )
            {
                requiredMavenVersion = v;
            }
        }
        mavenProject = mavenProject.getParent();
    }
    return requiredMavenVersion == null ? defaultValue : requiredMavenVersion.toString();
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:20,代码来源:DisplayPluginUpdatesMojo.java

示例3: getLatestVersion

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
public static String getLatestVersion(Artifact artifact, IProgressMonitor monitor) throws CoreException {
	monitor.beginTask("Getting latest version for " + artifact.getGroupId() + ":" + artifact.getArtifactId(), 1);
	try {
		final IMaven maven = MavenPlugin.getMaven();
		final ArtifactMetadataSource source = ((MavenImpl) maven).getPlexusContainer().lookup(
				ArtifactMetadataSource.class, "org.apache.maven.artifact.metadata.ArtifactMetadataSource", "maven"); //$NON-NLS-1$ $NON-NLS-2$
		List<ArtifactVersion> versions = source.retrieveAvailableVersions(artifact, maven.getLocalRepository(),
				maven.getArtifactRepositories());

		Collections.reverse(versions);
		for (ArtifactVersion artifactVersion : versions) {
			String version = artifactVersion.toString();
			if (!version.endsWith("-SNAPSHOT")) {
				return version;
			}
		}
	} catch (Exception e) {
		throw new CoreException(
				new Status(Status.ERROR, PolyglotSupportActivator.PLUGIN_ID, "Error resolving version range", e)); //$NON-NLS-1$
	}
	return null;
}
 
开发者ID:jbosstools,项目名称:m2e-polyglot-poc,代码行数:23,代码来源:ArtifactSearcher.java

示例4: getCurrentVersion

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
private static String getCurrentVersion(String group, String artifact, String defaultVersion) {
  ArtifactVersion version = ArtifactRetriever.DEFAULT.getLatestReleaseVersion(group, artifact);
  if (version == null) {
    return defaultVersion;
  }
  return version.toString();
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:8,代码来源:CodeTemplates.java

示例5: updateVersion

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
/**
 * Check Maven Central to find the latest release version of this artifact.
 * This check is made at most once. Subsequent checks are no-ops.
 */
void updateVersion() {
  if (!fixedVersion && !isPinned()) {
    ArtifactVersion remoteVersion = ArtifactRetriever.DEFAULT.getBestVersion(
        mavenCoordinates.getGroupId(), mavenCoordinates.getArtifactId());
    if (remoteVersion != null) {
      DefaultArtifactVersion localVersion = new DefaultArtifactVersion(mavenCoordinates.getVersion());
      if (remoteVersion.compareTo(localVersion) > 0) {
        String updatedVersion = remoteVersion.toString(); 
        mavenCoordinates = mavenCoordinates.toBuilder().setVersion(updatedVersion).build();
      }
    }
    fixedVersion = true;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:19,代码来源:LibraryFile.java

示例6: innerGetSegmentCount

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
protected int innerGetSegmentCount( ArtifactVersion v )
{
    final String version = v.toString();
    StringTokenizer tok = new StringTokenizer( version, "." );
    return tok.countTokens();
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:10,代码来源:NumericVersionComparator.java

示例7: stripSnapshot

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
static ArtifactVersion stripSnapshot( ArtifactVersion v )
{
    final String version = v.toString();
    final Matcher matcher = SNAPSHOT_PATTERN.matcher( version );
    if ( matcher.find() )
    {
        return new DefaultArtifactVersion( version.substring( 0, matcher.start( 1 ) - 1 ) );
    }
    return v;
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:11,代码来源:VersionComparators.java

示例8: getMavenCoordinates

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
private static MavenCoordinates getMavenCoordinates(IConfigurationElement[] children) {
  if (children.length != 1) {
    logger.warning(
        "Single configuration element for MavenCoordinates was expected, found: " //$NON-NLS-1$
        + children.length);
  }
  IConfigurationElement mavenCoordinatesElement = children[0];
  String groupId = mavenCoordinatesElement.getAttribute(ATTRIBUTE_NAME_GROUP_ID);
  String artifactId = mavenCoordinatesElement.getAttribute(ATTRIBUTE_NAME_ARTIFACT_ID);

  MavenCoordinates.Builder builder = new MavenCoordinates.Builder()
      .setGroupId(groupId)
      .setArtifactId(artifactId);

  String repository = mavenCoordinatesElement.getAttribute(ATTRIBUTE_NAME_REPOSITORY_URI);
  if (!Strings.isNullOrEmpty(repository)) {
    builder.setRepository(repository);
  }

  // Only look up latest version if version isn't specified in file.
  String version = mavenCoordinatesElement.getAttribute(ATTRIBUTE_NAME_VERSION);
  if (Strings.isNullOrEmpty(version) || "LATEST".equals(version)) {
    ArtifactVersion artifactVersion =
        ArtifactRetriever.DEFAULT.getBestVersion(groupId, artifactId);
    if (artifactVersion != null) {
      version = artifactVersion.toString();
    }
  }

  if (!Strings.isNullOrEmpty(version)) {
    builder.setVersion(version);
  }
  String type = mavenCoordinatesElement.getAttribute(ATTRIBUTE_NAME_TYPE);
  if (!Strings.isNullOrEmpty(type)) {
    builder.setType(type);
  }
  String classifier = mavenCoordinatesElement.getAttribute(ATTRIBUTE_NAME_CLASSIFIER);
  if (!Strings.isNullOrEmpty(classifier)) {
    builder.setClassifier(classifier);
  }
  return builder.build();
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:43,代码来源:LibraryFactory.java

示例9: updateDependencies

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
/**
 * Adjust the pom to add any required dependencies for the selected libraries and remove any
 * unnecessary dependencies for the removed libraries.
 * 
 * @param selectedLibraries the set of libraries to be included
 * @param removedLibraries these library dependencies are removed providing they are not required
 *        by any of the {@code selectedLibraries}
 */
void updateDependencies(Collection<Library> selectedLibraries,
    Collection<Library> removedLibraries) throws CoreException {
  // see
  // m2e-core/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/AddDependencyAction.java
  // m2e-core/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/AddDependencyOperation.java
  
  NodeList dependenciesList = document.getElementsByTagName("dependencies");
  Element dependencies;
  if (dependenciesList.getLength() > 0) {
    dependencies = (Element) dependenciesList.item(0);
  } else {
    dependencies = document.createElement("dependencies");
  }

  if (removedLibraries != null) {
    removeUnusedDependencies(dependencies, selectedLibraries, removedLibraries);
  }

  for (Library library : selectedLibraries) {
    for (LibraryFile artifact : library.getDirectDependencies()) {
      MavenCoordinates coordinates = artifact.getMavenCoordinates();
      
      String groupId = coordinates.getGroupId();
      String artifactId = coordinates.getArtifactId();
      
      if (!dependencyExists(dependencies, groupId, artifactId)) {
        Element dependency = document.createElement("dependency");
        Element groupIdElement = document.createElement("groupId");
        groupIdElement.setTextContent(groupId);
        dependency.appendChild(groupIdElement);

        Element artifactIdElement = document.createElement("artifactId");
        artifactIdElement.setTextContent(artifactId);
        dependency.appendChild(artifactIdElement);

        String version = coordinates.getVersion();
        ArtifactVersion latestVersion =
            ArtifactRetriever.DEFAULT.getBestVersion(groupId, artifactId);
        if (latestVersion != null) {
          version = latestVersion.toString(); 
        }
        
        // todo latest version may not be needed anymore.
        if (!MavenCoordinates.LATEST_VERSION.equals(version)) {
          Element versionElement = document.createElement("version");
          versionElement.setTextContent(version);
          dependency.appendChild(versionElement);
        }
        
        dependencies.appendChild(dependency);
      }
    }
  }
  
  if (dependencies.getParentNode() == null) {
    document.getDocumentElement().appendChild(dependencies);
  }
  
  try {
    writeDocument();
  } catch (TransformerException ex) {
    throw new CoreException(null);
  }   
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:73,代码来源:Pom.java

示例10: resolveRangesInParent

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
private void resolveRangesInParent( ModifiedPomXMLEventReader pom )
    throws MojoExecutionException, ArtifactMetadataRetrievalException, XMLStreamException
{
    Matcher versionMatcher = matchRangeRegex.matcher( getProject().getModel().getParent().getVersion() );

    if ( versionMatcher.find() )
    {
        Artifact artifact = this.toArtifact( getProject().getModel().getParent() );

        if ( artifact != null && isIncluded( artifact ) )
        {
            getLog().debug( "Resolving version range for parent: " + artifact );

            String artifactVersion = artifact.getVersion();
            if ( artifactVersion == null )
            {
                ArtifactVersion latestVersion =
                    findLatestVersion( artifact, artifact.getVersionRange(), allowSnapshots, false );

                if ( latestVersion != null )
                {
                    artifactVersion = latestVersion.toString();
                }
                else
                {
                    getLog().warn( "Not updating version " + artifact + " : could not resolve any versions" );
                }
            }

            if ( artifactVersion != null )
            {
                if ( PomHelper.setProjectParentVersion( pom, artifactVersion ) )
                {
                    getLog().debug( "Version set to " + artifactVersion + " for parent: " + artifact );
                }
                else
                {
                    getLog().warn( "Could not find the version tag for parent " + artifact + " in project "
                        + getProject().getId() + " so unable to set version to " + artifactVersion );
                }
            }
        }
    }

}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:46,代码来源:ResolveRangesMojo.java

示例11: resolveRanges

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
private void resolveRanges( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies )
    throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException
{

    for ( Dependency dep : dependencies )
    {
        if ( isExcludeReactor() && isProducedByReactor( dep ) )
        {
            continue;
        }

        Matcher versionMatcher = matchRangeRegex.matcher( dep.getVersion() );

        if ( versionMatcher.find() )
        {
            Artifact artifact = this.toArtifact( dep );

            if ( artifact != null && isIncluded( artifact ) )
            {
                getLog().debug( "Resolving version range for dependency: " + artifact );

                String artifactVersion = artifact.getVersion();
                if ( artifactVersion == null )
                {
                    ArtifactVersion latestVersion =
                        findLatestVersion( artifact, artifact.getVersionRange(), allowSnapshots, false );

                    if ( latestVersion != null )
                    {
                        artifactVersion = latestVersion.toString();
                    }
                    else
                    {
                        getLog().warn( "Not updating version " + artifact + " : could not resolve any versions" );
                    }
                }

                if ( artifactVersion != null )
                {
                    if ( PomHelper.setDependencyVersion( pom, artifact.getGroupId(), artifact.getArtifactId(),
                                                         dep.getVersion(), artifactVersion,
                                                         getProject().getModel() ) )
                    {
                        getLog().debug( "Version set to " + artifactVersion + " for dependency: " + artifact );
                    }
                    else
                    {
                        getLog().debug( "Could not find the version tag for dependency " + artifact + " in project "
                            + getProject().getId() + " so unable to set version to " + artifactVersion );
                    }
                }
            }
        }
    }
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:56,代码来源:ResolveRangesMojo.java

示例12: innerGetSegmentCount

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
protected int innerGetSegmentCount( ArtifactVersion v )
{
    final String version = v.toString();
    StringTokenizer tok = new StringTokenizer( version, ".-" );
    return tok.countTokens();
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:7,代码来源:MercuryVersionComparator.java

示例13: innerGetSegmentCount

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
protected int innerGetSegmentCount( ArtifactVersion v )
{
    // if the version does not match the maven rules, then we have only one segment
    // i.e. the qualifier
    if ( v.getBuildNumber() != 0 )
    {
        // the version was successfully parsed, and we have a build number
        // have to have four segments
        return 4;
    }
    if ( ( v.getMajorVersion() != 0 || v.getMinorVersion() != 0 || v.getIncrementalVersion() != 0 )
        && v.getQualifier() != null )
    {
        // the version was successfully parsed, and we have a qualifier
        // have to have four segments
        return 4;
    }
    final String version = v.toString();
    if ( version.indexOf( '-' ) != -1 )
    {
        // the version has parts and was not parsed successfully
        // have to have one segment
        return version.equals( v.getQualifier() ) ? 1 : 4;
    }
    if ( version.indexOf( '.' ) != -1 )
    {
        // the version has parts and was not parsed successfully
        // have to have one segment
        return version.equals( v.getQualifier() ) ? 1 : 3;
    }
    if ( StringUtils.isEmpty( version ) )
    {
        return 3;
    }
    try
    {
        Integer.parseInt( version );
        return 3;
    }
    catch ( NumberFormatException e )
    {
        return 1;
    }
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:48,代码来源:MavenVersionComparator.java

示例14: execute

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
@SuppressWarnings( "unchecked" )
public void execute()
{
    org.apache.maven.artifact.Artifact artifact =
        artifactFactory.createArtifact( getProject().getGroupId(), getProject().getArtifactId(), "", "", "" );
    try
    {
        ArtifactVersion releasedVersion = null;
        List<ArtifactVersion> versions =
            artifactMetadataSource.retrieveAvailableVersions( artifact, localRepository,
                                                              remoteArtifactRepositories );
        for ( ArtifactVersion version : versions )
        {
            if ( !ArtifactUtils.isSnapshot( version.toString() )
                && ( releasedVersion == null || version.compareTo( releasedVersion ) > 0 ) )
            {
                releasedVersion = version;
            }
        }

        if ( releasedVersion != null )
        {
            // Use ArtifactVersion.toString(), the major, minor and incrementalVersion return all an int.
            String releasedVersionValue = releasedVersion.toString();

            // This would not always reflect the expected version.
            int dashIndex = releasedVersionValue.indexOf( '-' );
            if ( dashIndex >= 0 )
            {
                releasedVersionValue = releasedVersionValue.substring( 0, dashIndex );
            }

            defineVersionProperty( "version", releasedVersionValue );
            defineVersionProperty( "majorVersion", releasedVersion.getMajorVersion() );
            defineVersionProperty( "minorVersion", releasedVersion.getMinorVersion() );
            defineVersionProperty( "incrementalVersion", releasedVersion.getIncrementalVersion() );
            defineVersionProperty( "buildNumber", releasedVersion.getBuildNumber() );
            defineVersionProperty( "qualifier", releasedVersion.getQualifier() );
        }

    }
    catch ( ArtifactMetadataRetrievalException e )
    {
        if ( getLog().isWarnEnabled() )
        {
            getLog().warn( "Failed to retrieve artifacts metadata, cannot resolve the released version" );
        }
    }
}
 
开发者ID:mojohaus,项目名称:build-helper-maven-plugin,代码行数:50,代码来源:ReleasedVersionMojo.java

示例15: logUpdates

import org.apache.maven.artifact.versioning.ArtifactVersion; //导入方法依赖的package包/类
private void logUpdates( Map updates, String section )
{
    List withUpdates = new ArrayList();
    List usingCurrent = new ArrayList();
    Iterator i = updates.values().iterator();
    while ( i.hasNext() )
    {
        ArtifactVersions versions = (ArtifactVersions) i.next();
        String left = "  " + ArtifactUtils.versionlessKey( versions.getArtifact() ) + " ";
        final String current;
        ArtifactVersion latest;
        if ( versions.isCurrentVersionDefined() )
        {
            current = versions.getCurrentVersion().toString();
            latest = versions.getNewestUpdate( UpdateScope.ANY, Boolean.TRUE.equals( allowSnapshots ) );
        }
        else
        {
            ArtifactVersion newestVersion = versions.getNewestVersion( versions.getArtifact().getVersionRange(),
                                                                       Boolean.TRUE.equals( allowSnapshots ) );
            current = versions.getArtifact().getVersionRange().toString();
            latest = newestVersion == null
                ? null
                : versions.getNewestUpdate( newestVersion, UpdateScope.ANY, Boolean.TRUE.equals( allowSnapshots ) );
            if ( latest != null && ArtifactVersions.isVersionInRange( latest,
                                                                      versions.getArtifact().getVersionRange() ) )
            {
                latest = null;
            }
        }
        String right = " " + ( latest == null ? current : current + " -> " + latest.toString() );
        List t = latest == null ? usingCurrent : withUpdates;
        if ( right.length() + left.length() + 3 > INFO_PAD_SIZE )
        {
            t.add( left + "..." );
            t.add( StringUtils.leftPad( right, INFO_PAD_SIZE ) );

        }
        else
        {
            t.add( StringUtils.rightPad( left, INFO_PAD_SIZE - right.length(), "." ) + right );
        }
    }
    if ( isVerbose() && usingCurrent.isEmpty() && !withUpdates.isEmpty() )
    {
        getLog().info( "No dependencies in " + section + " are using the newest version." );
        getLog().info( "" );
    }
    else if ( isVerbose() && !usingCurrent.isEmpty() )
    {
        getLog().info( "The following dependencies in " + section + " are using the newest version:" );
        i = usingCurrent.iterator();
        while ( i.hasNext() )
        {
            getLog().info( (String) i.next() );
        }
        getLog().info( "" );
    }
    if ( withUpdates.isEmpty() && !usingCurrent.isEmpty() )
    {
        getLog().info( "No dependencies in " + section + " have newer versions." );
        getLog().info( "" );
    }
    else if ( !withUpdates.isEmpty() )
    {
        getLog().info( "The following dependencies in " + section + " have newer versions:" );
        i = withUpdates.iterator();
        while ( i.hasNext() )
        {
            getLog().info( (String) i.next() );
        }
        getLog().info( "" );
    }
}
 
开发者ID:petr-ujezdsky,项目名称:versions-maven-plugin-svn-clone,代码行数:75,代码来源:DisplayDependencyUpdatesMojo.java


注:本文中的org.apache.maven.artifact.versioning.ArtifactVersion.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。