-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#26 Latest artifact resolution fix for snapshot and release artifacts
- Loading branch information
Showing
24 changed files
with
362 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...main/java/io/redskap/swagger/brake/cli/options/handler/CurrentArtifactVersionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.redskap.swagger.brake.cli.options.handler; | ||
|
||
import io.redskap.swagger.brake.cli.options.CliOptions; | ||
import io.redskap.swagger.brake.runner.Options; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CurrentArtifactVersionHandler implements CliOptionHandler { | ||
@Override | ||
public void handle(String propertyValue, Options options) { | ||
if (StringUtils.isNotBlank(propertyValue)) { | ||
options.setCurrentArtifactVersion(propertyValue); | ||
} | ||
} | ||
|
||
@Override | ||
public String getHandledPropertyName() { | ||
return CliOptions.CURRENT_ARTIFACT_VERSION; | ||
} | ||
|
||
@Override | ||
public String getHelpMessage() { | ||
return "Specifies the current artifact version against the latest artifact resolution. Example: 1.0.0, 1.0.0-SNAPSHOT"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...c/main/java/io/redskap/swagger/brake/cli/options/handler/MavenSnapshotRepoUrlHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.redskap.swagger.brake.cli.options.handler; | ||
|
||
import io.redskap.swagger.brake.cli.options.CliOptions; | ||
import io.redskap.swagger.brake.runner.Options; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MavenSnapshotRepoUrlHandler implements CliOptionHandler { | ||
@Override | ||
public void handle(String propertyValue, Options options) { | ||
if (StringUtils.isNotBlank(propertyValue)) { | ||
options.setMavenSnapshotRepoUrl(propertyValue); | ||
} | ||
} | ||
|
||
@Override | ||
public String getHandledPropertyName() { | ||
return CliOptions.MAVEN_SNAPSHOT_REPO_URL; | ||
} | ||
|
||
@Override | ||
public String getHelpMessage() { | ||
return "Specifies the Maven snapshot repository URL where the latest artifact denoted by the groupId and artifactId will be downloaded"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ger-brake/src/main/java/io/redskap/swagger/brake/maven/maven2/ArtifactVersionDecider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
public abstract class ArtifactVersionDecider { | ||
public static boolean isSnapshot(String version) { | ||
return version.endsWith("-SNAPSHOT"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 17 additions & 7 deletions
24
...p/swagger/brake/maven/url/UrlFactory.java → .../brake/maven/maven2/Maven2UrlFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
package io.redskap.swagger.brake.maven.url; | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
import static java.lang.String.format; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class UrlFactory { | ||
public class Maven2UrlFactory { | ||
public String createLatestArtifactSnapshotMetadataUrl(DownloadOptions options, String latestVersion) { | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options); | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options, options.getSnapshotRepoUrl()); | ||
return format("%s/%s/maven-metadata.xml", artifactBasePathUrl, latestVersion); | ||
} | ||
|
||
public String createLatestArtifactVersionMetadataUrl(DownloadOptions options) { | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options); | ||
String repoUrl = getRepoUrl(options); | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options, repoUrl); | ||
return format("%s/maven-metadata.xml", artifactBasePathUrl); | ||
} | ||
|
||
public String createLatestArtifactUrl(DownloadOptions options, String latestVersion, String latestSnapshotName) { | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options); | ||
String repoUrl = getRepoUrl(options); | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options, repoUrl); | ||
return format("%s/%s/%s.jar", artifactBasePathUrl, latestVersion, latestSnapshotName); | ||
} | ||
|
||
private String createLatestArtifactBasePathUrl(DownloadOptions options) { | ||
private String createLatestArtifactBasePathUrl(DownloadOptions options, String repoUrl) { | ||
String groupPath = options.getGroupId().replaceAll("\\.", "/"); | ||
return format("%s/%s/%s", options.getRepoUrl(), groupPath, options.getArtifactId()); | ||
return format("%s/%s/%s", repoUrl, groupPath, options.getArtifactId()); | ||
} | ||
|
||
private String getRepoUrl(DownloadOptions options) { | ||
String repoUrl = options.getRepoUrl(); | ||
if (ArtifactVersionDecider.isSnapshot(options.getCurrentArtifactVersion())) { | ||
repoUrl = options.getSnapshotRepoUrl(); | ||
} | ||
return repoUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
...-brake/src/main/java/io/redskap/swagger/brake/runner/download/DownloadOptionsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
package io.redskap.swagger.brake.runner.download; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import io.redskap.swagger.brake.runner.Options; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class DownloadOptionsFactory { | ||
public DownloadOptions create(String mavenRepoUrl, String groupId, String artifactId, String mavenRepoUsername, String mavenRepoPassword) { | ||
public DownloadOptions create(Options options) { | ||
DownloadOptions result = new DownloadOptions(); | ||
result.setRepoUrl(mavenRepoUrl); | ||
result.setGroupId(groupId); | ||
result.setArtifactId(artifactId); | ||
result.setUsername(mavenRepoUsername); | ||
result.setPassword(mavenRepoPassword); | ||
result.setRepoUrl(options.getMavenRepoUrl()); | ||
result.setSnapshotRepoUrl(options.getMavenSnapshotRepoUrl()); | ||
result.setGroupId(options.getGroupId()); | ||
result.setArtifactId(options.getArtifactId()); | ||
result.setUsername(options.getMavenRepoUsername()); | ||
result.setPassword(options.getMavenRepoPassword()); | ||
result.setCurrentArtifactVersion(options.getCurrentArtifactVersion()); | ||
return result; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...brake/src/test/java/io/redskap/swagger/brake/maven/maven2/ArtifactVersionDeciderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class ArtifactVersionDeciderTest { | ||
@Test | ||
public void testIsSnapshotReturnsTrueWhenVersionIsEndingWithSnapshot() { | ||
// given | ||
// when | ||
boolean result = ArtifactVersionDecider.isSnapshot("1.0.0-SNAPSHOT"); | ||
// then | ||
assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void testIsSnapshotReturnsFalseWhenVersionIsNotEndingWithSnapshot() { | ||
// given | ||
// when | ||
boolean result = ArtifactVersionDecider.isSnapshot("1.0.0"); | ||
// then | ||
assertFalse(result); | ||
} | ||
|
||
@Test | ||
public void testIsSnapshotReturnsFalseWhenVersionIsCompletelyRandom() { | ||
// given | ||
// when | ||
boolean result = ArtifactVersionDecider.isSnapshot("something-else-that-is-not-a-version"); | ||
// then | ||
assertFalse(result); | ||
} | ||
} |
Oops, something went wrong.