org.apache.maven.artifact.versioning.DefaultArtifactVersion Java Examples

The following examples show how to use org.apache.maven.artifact.versioning.DefaultArtifactVersion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeployParticipant.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
private void checkSupport() {
  Properties properties = new Properties();

  try (InputStream in = Maven.class.getResourceAsStream("/META-INF/maven/org.apache.maven/maven-core/pom.properties")) {
    if (in != null) {
      properties.load(in);
    }
  } catch (IOException e) {
    log.error("Unable determine maven version, deploy at end might fail", e);
    return;
  }

  String mavenVersion = properties.getProperty("version");
  if (mavenVersion != null) {
    int c = new DefaultArtifactVersion(mavenVersion).compareTo(new DefaultArtifactVersion("3.3.1"));
    if (c < 0) {
      throw new IllegalStateException("Deploy-at-end is not supported on maven versions <3.3.1");
    }
  } else {
    log.error("Unable determine maven version, deploy at end might fail");
  }
}
 
Example #2
Source File: NumericVersionComparatorTest.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testSegmentIncrementing()
    throws Exception
{
    assertEquals( new DefaultArtifactVersion( "6" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0 ).toString() );
    assertEquals( new DefaultArtifactVersion( "6.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.1" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.alpha-1.2" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 2 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), 1 ).toString() );
}
 
Example #3
Source File: MercuryVersionComparatorTest.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testSegmentIncrementing()
    throws Exception
{
    assertEquals( new DefaultArtifactVersion( "6" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0 ).toString() );
    assertEquals( new DefaultArtifactVersion( "6.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.1" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 1 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 2 ).toString() );
    assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(),
                  instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), 1 ).toString() );
}
 
Example #4
Source File: ResolvableDependency.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
List<Dependency> resolveVersions(final MavenProject project, final Log log) throws InvalidVersionSpecificationException, MojoExecutionException {
  if (resolvedVersions != null)
    return resolvedVersions;

  if (isSingleVersion())
    return resolvedVersions = Collections.singletonList(MavenUtil.newDependency(getGroupId(), getArtifactId(), getVersion()));

  final ResolvableDependency versionDependency = isOwnVersion() ? this : ResolvableDependency.parse(getVersion());
  resolvedVersions = new ArrayList<>();

  final SortedSet<DefaultArtifactVersion> versions = resolveVersions(project, log, versionDependency);
  final VersionRange versionRange = VersionRange.createFromVersionSpec(versionDependency.getVersion());
  for (final DefaultArtifactVersion version : versions)
    if (versionRange.containsVersion(version))
      resolvedVersions.add(MavenUtil.newDependency(getGroupId(), getArtifactId(), version.toString()));

  return resolvedVersions;
}
 
Example #5
Source File: ResolvableDependency.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static SortedSet<DefaultArtifactVersion> resolveVersions(final MavenProject project, final Log log, final ResolvableDependency dependency) throws MojoExecutionException {
  final List<Repository> repositories = project.getRepositories();
  final SortedSet<DefaultArtifactVersion> allVersions = new TreeSet<>();
  for (final Repository repository : repositories) {
    final DependencyId dependencyId = new DependencyId(dependency, repository);
    final SortedSet<DefaultArtifactVersion> versions;
    if (dependencyIdToVersions.containsKey(dependencyId))
      versions = dependencyIdToVersions.get(dependencyId);
    else
      dependencyIdToVersions.put(dependencyId, versions = downloadVersions(log, dependencyId));

    if (versions != null)
      allVersions.addAll(versions);
  }

  if (allVersions.size() == 0)
    throw new MojoExecutionException("Artifact " + dependency.getGroupId() + ":" + dependency.getArtifactId() + " was not found in any repositories:\n" + AssembleUtil.toIndentedString(repositories));

  return allVersions;
}
 
Example #6
Source File: RangeResolver.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
private List<ArtifactVersion> getVersions( ProjectRef ga )
{
    MavenMetadataView mavenMetadataView;
    try
    {
        mavenMetadataView = readerWrapper.readMetadataView( ga );
    }
    catch ( GalleyMavenException e )
    {
        throw new ManipulationUncheckedException( new ManipulationException( "Caught Galley exception processing artifact", e ) );
    }
    return mavenMetadataView.resolveXPathToAggregatedStringList( "/metadata/versioning/versions/version", true, -1 )
                            .stream()
                            .distinct()
                            .map( DefaultArtifactVersion::new )
                            .collect( Collectors.toList() );


}
 
Example #7
Source File: IronTestApplication.java    From irontest with Apache License 2.0 6 votes vote down vote up
/**
 * @param systemDBJdbi
 * @return true if version check finds no problem, false otherwise.
 */
private boolean checkVersion(Jdbi systemDBJdbi) {
    DefaultArtifactVersion systemDBVersion = IronTestUtils.getSystemDBVersion(systemDBJdbi);
    DefaultArtifactVersion jarFileVersion = new DefaultArtifactVersion(Version.VERSION);
    int comparison = systemDBVersion.compareTo(jarFileVersion);
    if (comparison == 0) {  //  system database and the jar file are of the same version
        return true;
    } else if (comparison > 0) {    //  system database version is bigger than the jar file version
        System.out.printf(IronTestConstants.PROMPT_TEXT_WHEN_SYSTEM_DB_VERSION_IS_BIGGER_THAN_JAR_VERSION,
                systemDBVersion, jarFileVersion);
        System.out.println();
        return false;
    } else {    //  system database version is smaller than the jar file version
        System.out.printf("System database version %1$s is smaller than jar file version %2$s.%n", systemDBVersion,
                jarFileVersion);
        System.out.println("Please download and build the latest release of Iron Test. Under the dist directory, " +
                "run command 'java -jar <jarFileName> upgrade <IronTest_Home>' to upgrade your existing " +
                "Iron Test instance.");
        System.out.println("Follow the instructions to finish upgrade. In the end, you should see in the " +
                "command line output 'UPGRADE SUCCESS'.");
        return false;
    }
}
 
Example #8
Source File: RequiredMavenVersionFinderTest.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void findReturnsValueWhenSecondEnforcerExecutionIsValidAndFirstEnforcerExecutionHasNoConfigurationTag() {
    String mavenVersionRange = "1.0";
    ArrayList<Plugin> buildPlugins = new ArrayList<>();
    buildPlugins.add(enforcerPlugin);
    when(mavenProject.getBuildPlugins()).thenReturn(buildPlugins);
    ArrayList<PluginExecution> pluginExecutions = new ArrayList<>();
    pluginExecutions.add(otherPluginExecution);
    pluginExecutions.add(pluginExecution);
    ArrayList<String> goals = new ArrayList<>();
    ArrayList<String> otherGoals = new ArrayList<>();
    goals.add("enforce");
    otherGoals.add("enforce");
    when(pluginExecution.getGoals()).thenReturn(goals);
    when(otherPluginExecution.getGoals()).thenReturn(otherGoals);
    when(enforcerPlugin.getExecutions()).thenReturn(pluginExecutions);
    when(pluginExecution.getConfiguration()).thenReturn(configurationTag);
    when(otherPluginExecution.getConfiguration()).thenReturn(null);
    when(configurationTag.getChild("rules")).thenReturn(rulesTag);
    when(rulesTag.getChild("requireMavenVersion")).thenReturn(requireMavenVersionTag);
    when(requireMavenVersionTag.getChild("version")).thenReturn(versionTag);
    when(versionTag.getValue()).thenReturn(mavenVersionRange);
    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(mavenVersionRange);
    assertEquals(artifactVersion, new RequiredMavenVersionFinder(mavenProject).find());
}
 
Example #9
Source File: CdiContainerUnderTest.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * Verify if the runtime is using the following CdiImplementation
 * 
 * @param cdiImplementation
 * @param versionRange
 *            optional - If not defined it will used the range defined on {@link CdiImplementation}
 * @return
 * @throws InvalidVersionSpecificationException
 */
public static boolean isCdiVersion(CdiImplementation cdiImplementation, String versionRange)
    throws InvalidVersionSpecificationException
{

    Class implementationClass = tryToLoadClassForName(cdiImplementation.getImplementationClassName());

    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));
}
 
Example #10
Source File: DataflowDependencyManagerTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLatestVersions() {
  ArtifactVersion latestVersionOne = new DefaultArtifactVersion("1.2.3");
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.ONE.getVersionRange()))
      .thenReturn(latestVersionOne);
  ArtifactVersion latestVersionTwo = new DefaultArtifactVersion("2.0.0");
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.TWO.getVersionRange()))
      .thenReturn(latestVersionTwo);

  Map<ArtifactVersion, MajorVersion> expected = ImmutableMap.of(
      latestVersionOne, MajorVersion.ONE,
      latestVersionTwo, MajorVersion.TWO);
  assertEquals(
      expected,
      manager.getLatestVersions(ImmutableSortedSet.of(MajorVersion.ONE, MajorVersion.TWO)));
}
 
Example #11
Source File: DataflowDependencyManagerTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLatestVersionUnstableWithStableVersionInMap() {
  ArtifactVersion latestQualified = new DefaultArtifactVersion("2.0.0-beta2");
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.QUALIFIED_TWO.getVersionRange()))
      .thenReturn(latestQualified);
  ArtifactVersion latestMajor = new DefaultArtifactVersion("2.0.0");
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.TWO.getVersionRange()))
      .thenReturn(latestMajor);

  assertEquals(
      Collections.singletonMap(latestMajor, MajorVersion.TWO),
      manager.getLatestVersions(
          ImmutableSortedSet.of(MajorVersion.QUALIFIED_TWO, MajorVersion.TWO)));
}
 
Example #12
Source File: DataflowDependencyManagerTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLatestVersionUnstableWithNoStableVersion() {
  ArtifactVersion latestOne = new DefaultArtifactVersion("1.9.0");
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.ONE.getVersionRange()))
      .thenReturn(latestOne);
  ArtifactVersion latestQualifiedTwo = new DefaultArtifactVersion("2.0.0-beta2");
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.QUALIFIED_TWO.getVersionRange()))
      .thenReturn(latestQualifiedTwo);

  Map<ArtifactVersion, MajorVersion> expected = ImmutableMap.of(
      latestOne, MajorVersion.ONE,
      latestQualifiedTwo, MajorVersion.QUALIFIED_TWO);
  assertEquals(
      expected,
      manager.getLatestVersions(
          ImmutableSortedSet.of(MajorVersion.ONE, MajorVersion.QUALIFIED_TWO)));
}
 
Example #13
Source File: UpgradeCommand.java    From irontest with Apache License 2.0 6 votes vote down vote up
@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception {
    String ironTestHome = namespace.getString("IronTestHome");
    IronTestConfiguration configuration = getIronTestConfiguration(ironTestHome);
    DataSourceFactory systemDBConfiguration = configuration.getSystemDatabase();
    String fullyQualifiedSystemDBURL = getFullyQualifiedSystemDBURL(ironTestHome, systemDBConfiguration.getUrl());
    DefaultArtifactVersion systemDBVersion = getSystemDBVersionStr(fullyQualifiedSystemDBURL, systemDBConfiguration.getUser(),
            systemDBConfiguration.getPassword());
    DefaultArtifactVersion jarFileVersion = new DefaultArtifactVersion(Version.VERSION);

    int comparison = systemDBVersion.compareTo(jarFileVersion);
    if ("SNAPSHOT".equals(systemDBVersion.getQualifier())) {
        System.out.println("System database version " + systemDBVersion + " is a SNAPSHOT version. Upgrade is not supported.");
    } else if ("SNAPSHOT".equals(jarFileVersion.getQualifier())) {
        System.out.println("Jar file version " + jarFileVersion + " is a SNAPSHOT version. Upgrade is not supported.");
    } else if (comparison == 0) {
        System.out.println("System database and the jar file are of the same version, so no need to upgrade.");
    } else if (comparison > 0) {    //  system database version is bigger than the jar file version
        System.out.printf(IronTestConstants.PROMPT_TEXT_WHEN_SYSTEM_DB_VERSION_IS_BIGGER_THAN_JAR_VERSION,
                systemDBVersion, jarFileVersion);
    } else {    //  system database version is smaller than the jar file version
        UpgradeActions upgradeActions = new UpgradeActions();
        upgradeActions.upgrade(systemDBVersion, jarFileVersion, ironTestHome, fullyQualifiedSystemDBURL,
                systemDBConfiguration.getUser(), systemDBConfiguration.getPassword());
    }
}
 
Example #14
Source File: RequiredMavenVersionFinder.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion getPrerequisitesMavenVersion() {
    Prerequisites prerequisites = mavenProject.getPrerequisites();
    if (null == prerequisites) {
        return null;
    }

    String prerequisitesMavenValue = prerequisites.getMaven();
    if (null == prerequisitesMavenValue) {
        return null;
    }

    return new DefaultArtifactVersion(prerequisitesMavenValue);
}
 
Example #15
Source File: GMProcessFactoryImplTest.java    From gm4java with Apache License 2.0 5 votes vote down vote up
@Test
public void getVersion_callsGMProcessAndExtractVersion() throws Exception {
    when(process.getReader()).thenReturn(new BufferedReader(new StringReader(fakeGMOutput())));

    DefaultArtifactVersion result = sut.getVersion();
    assertThat(result, notNullValue());
    assertThat(result.toString(), equalTo(version));

    verify(factory).getProcess(gmPath, "version");
}
 
Example #16
Source File: VersionComparators.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: RequiredMavenVersionFinderTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void findReturnsValueWhenSecondEnforcerExecutionIsValidAndFirstEnforcerExecutionHasNoRequireMavenVersionTag() {
    String mavenVersionRange = "1.0";
    ArrayList<Plugin> buildPlugins = new ArrayList<>();
    buildPlugins.add(enforcerPlugin);
    when(mavenProject.getBuildPlugins()).thenReturn(buildPlugins);
    ArrayList<PluginExecution> pluginExecutions = new ArrayList<>();
    pluginExecutions.add(otherPluginExecution);
    pluginExecutions.add(pluginExecution);
    ArrayList<String> goals = new ArrayList<>();
    ArrayList<String> otherGoals = new ArrayList<>();
    goals.add("enforce");
    otherGoals.add("enforce");
    when(pluginExecution.getGoals()).thenReturn(goals);
    when(otherPluginExecution.getGoals()).thenReturn(otherGoals);
    when(enforcerPlugin.getExecutions()).thenReturn(pluginExecutions);
    when(pluginExecution.getConfiguration()).thenReturn(configurationTag);
    when(otherPluginExecution.getConfiguration()).thenReturn(otherConfigurationTag);
    when(configurationTag.getChild("rules")).thenReturn(rulesTag);
    when(otherConfigurationTag.getChild("rules")).thenReturn(otherRulesTag);
    when(rulesTag.getChild("requireMavenVersion")).thenReturn(requireMavenVersionTag);
    when(otherRulesTag.getChild("requireMavenVersion")).thenReturn(null);
    when(requireMavenVersionTag.getChild("version")).thenReturn(versionTag);
    when(versionTag.getValue()).thenReturn(mavenVersionRange);
    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(mavenVersionRange);
    assertEquals(artifactVersion, new RequiredMavenVersionFinder(mavenProject).find());
}
 
Example #18
Source File: NumericVersionComparatorTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSegmentCounting()
    throws Exception
{
    assertEquals( 1, instance.getSegmentCount( new DefaultArtifactVersion( "5" ) ) );
    assertEquals( 2, instance.getSegmentCount( new DefaultArtifactVersion( "5.0" ) ) );
    assertEquals( 1, instance.getSegmentCount( new DefaultArtifactVersion( "5-0" ) ) );
    assertEquals( 3, instance.getSegmentCount( new DefaultArtifactVersion( "5.3.a" ) ) );
    assertEquals( 6, instance.getSegmentCount( new DefaultArtifactVersion( "5.0.a.1.4.5" ) ) );
    assertEquals( 0, instance.getSegmentCount( new DefaultArtifactVersion( "" ) ) );
}
 
Example #19
Source File: MinimumVersionAgentMetadataInspector.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public InspectionReport inspect(@Valid final AgentClientMetadata agentClientMetadata) {

    final String minimumVersionString = this.agentFilterProperties.getMinimumVersion();
    final String agentVersionString = agentClientMetadata.getVersion().orElse(null);

    if (StringUtils.isBlank(minimumVersionString)) {
        return InspectionReport.newAcceptance("Minimum version requirement not set");

    } else if (StringUtils.isBlank(agentVersionString)) {
        return InspectionReport.newRejection("Agent version not set");

    } else {
        final ArtifactVersion minimumVersion = new DefaultArtifactVersion(minimumVersionString);
        final ArtifactVersion agentVersion = new DefaultArtifactVersion(agentVersionString);

        final boolean deprecated = minimumVersion.compareTo(agentVersion) > 0;

        return new InspectionReport(
            deprecated ? InspectionReport.Decision.REJECT : InspectionReport.Decision.ACCEPT,
            String.format(
                "Agent version: %s is %s than minimum: %s",
                agentVersionString,
                deprecated ? "older" : "newer or equal",
                minimumVersionString
            )
        );
    }
}
 
Example #20
Source File: RequiredMavenVersionFinderTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void findReturnsParentVersionWhenChildWithLowerVersionAndParentWithHigherVersion() {
    when(mavenProject.hasParent()).thenReturn(true);
    when(mavenProject.getParent()).thenReturn(parentMavenProject);
    when(mavenProject.getPrerequisites()).thenReturn(prerequisites);
    String childMavenVersion = "1";
    when(prerequisites.getMaven()).thenReturn(childMavenVersion);
    when(parentMavenProject.getPrerequisites()).thenReturn(parentPrerequisites);
    String parentMavenVersion = "2";
    when(parentPrerequisites.getMaven()).thenReturn(parentMavenVersion);
    DefaultArtifactVersion parentArtifactVersion = new DefaultArtifactVersion(parentMavenVersion);
    assertEquals(parentArtifactVersion, new RequiredMavenVersionFinder(mavenProject).find());
}
 
Example #21
Source File: UpgradeActions.java    From irontest with Apache License 2.0 5 votes vote down vote up
/**
 * Result is sorted by fromVersion.
 * @param oldVersion
 * @param newVersion
 * @param subPackage
 * @param prefix
 * @param extension
 * @return
 */
private List<ResourceFile> getApplicableUpgradeResourceFiles(DefaultArtifactVersion oldVersion,
                                                             DefaultArtifactVersion newVersion, String subPackage,
                                                             String prefix, String extension) {
    List<ResourceFile> result = new ArrayList<>();

    Reflections reflections = new Reflections(
            getClass().getPackage().getName() + "." + subPackage, new ResourcesScanner());
    Set<String> upgradeFilePaths =
            reflections.getResources(Pattern.compile(prefix + ".*\\." + extension));
    for (String upgradeFilePath: upgradeFilePaths) {
        String[] upgradeFilePathFragments = upgradeFilePath.split("/");
        String upgradeFileName = upgradeFilePathFragments[upgradeFilePathFragments.length - 1];
        String[] versionsInUpgradeFileName = upgradeFileName.replace(prefix + "_", "").
                replace("." + extension, "").split("_To_");
        DefaultArtifactVersion fromVersionInUpgradeFileName = new DefaultArtifactVersion(
                versionsInUpgradeFileName[0].replace("_", "."));
        DefaultArtifactVersion toVersionInUpgradeFileName = new DefaultArtifactVersion(
                versionsInUpgradeFileName[1].replace("_", "."));
        if (fromVersionInUpgradeFileName.compareTo(oldVersion) >= 0 &&
                toVersionInUpgradeFileName.compareTo(newVersion) <=0) {
            ResourceFile upgradeResourceFile = new ResourceFile();
            upgradeResourceFile.setResourcePath(upgradeFilePath);
            upgradeResourceFile.setFromVersion(fromVersionInUpgradeFileName);
            upgradeResourceFile.setToVersion(toVersionInUpgradeFileName);
            result.add(upgradeResourceFile);
        }
    }

    Collections.sort(result);

    return result;
}
 
Example #22
Source File: DefaultVersionsHelperTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testPerRuleVersionsIgnored() throws Exception
{
    final ArtifactMetadataSource metadataSource = mock( ArtifactMetadataSource.class );
    final Artifact artifact = mock( Artifact.class );
    when( artifact.getGroupId() ).thenReturn( "com.mycompany.maven" );
    when( artifact.getArtifactId() ).thenReturn( "artifact-one" );
    
    final List<ArtifactVersion> artifactVersions = new ArrayList<ArtifactVersion>();
    
    artifactVersions.add( new DefaultArtifactVersion( "one" ) );
    artifactVersions.add( new DefaultArtifactVersion( "two" ) );
    final ArtifactVersion three = new DefaultArtifactVersion( "three" );
    artifactVersions.add( three );
    final ArtifactVersion oneTwoHundred = new DefaultArtifactVersion( "1.200" );
    artifactVersions.add( oneTwoHundred );
    final ArtifactVersion illegal = new DefaultArtifactVersion( "illegalVersion" );
    artifactVersions.add( illegal );

    when( metadataSource.retrieveAvailableVersions( same( artifact ), any( ArtifactRepository.class ), anyList() ) )
        .thenReturn( artifactVersions );
    
    VersionsHelper helper = createHelper( metadataSource );
    
    final ArtifactVersions versions = helper.lookupArtifactVersions( artifact, true );
    
    final List<ArtifactVersion> actual = asList( versions.getVersions( true ) );
    
    assertEquals( 3, actual.size() );
    assertThat( actual, hasItems( three, oneTwoHundred, illegal ) );
}
 
Example #23
Source File: DefaultVersionsHelperTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGlobalRuleVersionsIgnored() throws Exception
{
    final ArtifactMetadataSource metadataSource = mock( ArtifactMetadataSource.class );
    final Artifact artifact = mock( Artifact.class );
    when( artifact.getGroupId() ).thenReturn( "other.company" );
    when( artifact.getArtifactId() ).thenReturn( "artifact-two" );
    
    final List<ArtifactVersion> artifactVersions = new ArrayList<ArtifactVersion>();
    
    final ArtifactVersion one = new DefaultArtifactVersion( "one" );
    final ArtifactVersion two = new DefaultArtifactVersion( "two" );
    final ArtifactVersion three = new DefaultArtifactVersion( "three" );
    artifactVersions.add( one );
    artifactVersions.add( two );
    artifactVersions.add( new DefaultArtifactVersion( "three-alpha" ) );
    artifactVersions.add( new DefaultArtifactVersion( "three-beta" ) );
    artifactVersions.add( three );
    final ArtifactVersion illegal = new DefaultArtifactVersion( "illegalVersion" );
    artifactVersions.add( illegal );

    when(metadataSource.retrieveAvailableVersions( same( artifact ), any( ArtifactRepository.class ), anyList() ) )
        .thenReturn( artifactVersions );
    
    VersionsHelper helper = createHelper( metadataSource );
    
    final ArtifactVersions versions = helper.lookupArtifactVersions( artifact, true );
    
    final List<ArtifactVersion> actual = asList( versions.getVersions( true ) );
    
    assertEquals( 4, actual.size() );
    assertThat( actual, hasItems( one, two, three, illegal ) );
}
 
Example #24
Source File: UpgradeActions.java    From irontest with Apache License 2.0 5 votes vote down vote up
private void copyFilesToBeUpgraded(String ironTestHome, DefaultArtifactVersion oldVersion,
                                   DefaultArtifactVersion newVersion) throws IOException {
    List<CopyFilesForOneVersionUpgrade> applicableCopyFiles =
            new CopyFiles().getApplicableCopyFiles(oldVersion, newVersion);
    for (CopyFilesForOneVersionUpgrade filesForOneVersionUpgrade: applicableCopyFiles) {
        Map<String, String> filePathMap = filesForOneVersionUpgrade.getFilePathMap();
        for (Map.Entry<String, String> mapEntry: filePathMap.entrySet()) {
            Path sourceFilePath = Paths.get(".", mapEntry.getKey()).toAbsolutePath();
            Path targetFilePath = Paths.get(ironTestHome, mapEntry.getValue()).toAbsolutePath();
            Files.copy(sourceFilePath, targetFilePath, StandardCopyOption.REPLACE_EXISTING);
            LOGGER.info("Copied " + sourceFilePath + " to " + targetFilePath + ".");
        }
    }
}
 
Example #25
Source File: UpgradeActions.java    From irontest with Apache License 2.0 5 votes vote down vote up
private void copyNewJarFromDistToIronTestHome(DefaultArtifactVersion newJarFileVersion, String ironTestHome)
        throws IOException {
    String newJarFileName = "irontest-" + newJarFileVersion + ".jar";
    Path soureFilePath = Paths.get(".", newJarFileName).toAbsolutePath();
    Path targetFilePath = Paths.get(ironTestHome, newJarFileName).toAbsolutePath();
    Files.copy(soureFilePath, targetFilePath);
    LOGGER.info("Copied " + soureFilePath + " to " + targetFilePath + ".");
}
 
Example #26
Source File: CopyFiles.java    From irontest with Apache License 2.0 5 votes vote down vote up
public List<CopyFilesForOneVersionUpgrade> getApplicableCopyFiles(DefaultArtifactVersion oldVersion,
                                                                  DefaultArtifactVersion newVersion) {
    List<CopyFilesForOneVersionUpgrade> result = new ArrayList<>();
    for (CopyFilesForOneVersionUpgrade filesForOneVersionUpgrade: allFiles) {
        if (filesForOneVersionUpgrade.getFromVersion().compareTo(oldVersion) >= 0 &&
                filesForOneVersionUpgrade.getToVersion().compareTo(newVersion) <=0) {
            result.add(filesForOneVersionUpgrade);
        }
    }
    return result;
}
 
Example #27
Source File: CopyFiles.java    From irontest with Apache License 2.0 5 votes vote down vote up
public CopyFiles() {
    CopyFilesForOneVersionUpgrade filesForOneVersion = new CopyFilesForOneVersionUpgrade(
            new DefaultArtifactVersion("0.14.0"), new DefaultArtifactVersion("0.15.0"));
    filesForOneVersion.getFilePathMap().put("start.bat", "start.bat");
    filesForOneVersion.getFilePathMap().put("start-team.bat", "start-team.bat");
    allFiles.add(filesForOneVersion);
}
 
Example #28
Source File: LibraryFile.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
  }
}
 
Example #29
Source File: RequiredMavenVersionFinderTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void findReturnsValueWhenVersionTagValueSetsInclusiveMinExclusiveMax() {
    String mavenVersionRange = "[1.0,2.0)";
    String minimumVersion = "1.0";
    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(minimumVersion);
    findReturnsValueWhenVersionTagValueIsSet(mavenVersionRange);
    assertEquals(artifactVersion, new RequiredMavenVersionFinder(mavenProject).find());
}
 
Example #30
Source File: MercuryVersionComparatorTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSegmentCounting()
    throws Exception
{
    assertEquals( 1, instance.getSegmentCount( new DefaultArtifactVersion( "5" ) ) );
    assertEquals( 2, instance.getSegmentCount( new DefaultArtifactVersion( "5.0" ) ) );
    assertEquals( 2, instance.getSegmentCount( new DefaultArtifactVersion( "5-0" ) ) );
    assertEquals( 3, instance.getSegmentCount( new DefaultArtifactVersion( "5.3.a" ) ) );
    assertEquals( 6, instance.getSegmentCount( new DefaultArtifactVersion( "5.0.a.1.4.5" ) ) );
    assertEquals( 0, instance.getSegmentCount( new DefaultArtifactVersion( "" ) ) );
}