Skip to content

Commit

Permalink
Workaround issues in mojohaus#251
Browse files Browse the repository at this point in the history
  • Loading branch information
blacelle committed May 8, 2019
1 parent e767c37 commit fbbceed
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
@@ -1,5 +1,7 @@
package org.codehaus.mojo.versions;

import javax.xml.stream.XMLStreamException;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -22,6 +24,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -31,8 +34,6 @@
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;

import javax.xml.stream.XMLStreamException;

/**
* Sets the parent version to the latest parent version.
*
Expand Down Expand Up @@ -110,6 +111,12 @@ protected void update( ModifiedPomXMLEventReader pom )
{
throw new MojoExecutionException( e.getMessage(), e );
}

if (getHelper().getVersionComparator(artifact)
.compare(new DefaultArtifactVersion(currentVersion), artifactVersion) > 0) {
getLog().warn( "Not changing versions " + currentVersion + " to seemingly latest " + artifactVersion.toString() );
return;
}

if ( !shouldApplyUpdate( artifact, currentVersion, artifactVersion ) )
{
Expand Down
@@ -1,5 +1,13 @@
package org.codehaus.mojo.versions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.stream.XMLStreamException;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -36,14 +44,6 @@
import org.codehaus.mojo.versions.ordering.MajorMinorIncrementalFilter;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;

import javax.xml.stream.XMLStreamException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Replaces any release versions with the latest release version.
*
Expand Down Expand Up @@ -156,7 +156,14 @@ private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection<Depend

getLog().debug( "Looking for newer versions of " + toString( dep ) );
ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false );
ArtifactVersion[] newer = versions.getNewerVersions( version, segment, false );
ArtifactVersion[] newer;
try {
newer = versions.getNewerVersions( version, segment, false );
} catch (RuntimeException e) {
// Workaround https://github.com/mojohaus/versions-maven-plugin/issues/251
getLog().warn("Issue with artifact: " + artifact);
newer = new ArtifactVersion[0];
}
newer = filterVersionsWithIncludes( newer, artifact );

ArtifactVersion[] filteredVersions = majorMinorIncfilter.filter( selectedVersion, newer );
Expand Down
Expand Up @@ -72,6 +72,7 @@ protected int innerGetSegmentCount( ArtifactVersion v )
{
// the version has parts and was not parsed successfully
// have to have one segment
// This happens on '1.2.3.4' and '[1.2,]'
return version.equals( v.getQualifier() ) ? 1 : 3;
}
if ( StringUtils.isEmpty( version ) )
Expand Down
@@ -1,5 +1,7 @@
package org.codehaus.mojo.versions.ordering;

import static org.junit.Assert.assertEquals;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -20,10 +22,9 @@
*/

import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MavenVersionComparatorTest
{
private MavenVersionComparator instance = new MavenVersionComparator();
Expand Down Expand Up @@ -57,6 +58,18 @@ public void testSegmentIncrementing()
assertIncrement( "1.0-za-SNAPSHOT", "1.0-z-SNAPSHOT", 3 );
assertIncrement( "1.0-z90-SNAPSHOT", "1.0-z9-SNAPSHOT", 3 );
}

@Ignore
@Test
public void testSegmentIncrementing_Failing()
throws Exception
{
// https://github.com/mojohaus/versions-maven-plugin/issues/251
assertIncrement( "17.1", "2.2.38.141", 3 );
assertIncrement( "17.1", "v3-rev126-1.19.1", 3 );
assertIncrement( "17.1", "17.0", 1 );
assertIncrement( "17.1", "[17.0,]", 1 );
}

private void assertIncrement( String expected, String initial, int segment )
{
Expand Down

0 comments on commit fbbceed

Please sign in to comment.