-
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.
#4: Refactoring around credential support & downloading
- Loading branch information
Showing
22 changed files
with
581 additions
and
152 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
63 changes: 0 additions & 63 deletions
63
src/main/java/io/redskap/swagger/brake/maven/Maven2LatestArtifactDownloader.java
This file was deleted.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
src/main/java/io/redskap/swagger/brake/maven/http/HttpClientErrorHandler.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,19 @@ | ||
package io.redskap.swagger.brake.maven.http; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.HttpException; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.HttpResponseInterceptor; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
public class HttpClientErrorHandler implements HttpResponseInterceptor { | ||
@Override | ||
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { | ||
int statusCode = response.getStatusLine().getStatusCode(); | ||
if (HttpStatus.SC_UNAUTHORIZED == statusCode) { | ||
throw new UnauthorizedException("Request unauthorized"); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...aven/exception/UnauthorizedException.java → ...ake/maven/http/UnauthorizedException.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
21 changes: 21 additions & 0 deletions
21
src/main/java/io/redskap/swagger/brake/maven/maven2/LatestArtifactVersionResolver.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,21 @@ | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import io.redskap.swagger.brake.maven.model.MavenMetadata; | ||
import io.redskap.swagger.brake.maven.url.UrlFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
class LatestArtifactVersionResolver { | ||
private final UrlFactory urlFactory; | ||
private final MavenMetadataDownloader metadataDownloader; | ||
private final RepositoryRequestFactory requestFactory; | ||
|
||
String resolve(DownloadOptions options) { | ||
String metadataUrl = urlFactory.createLatestArtifactVersionMetadataUrl(options); | ||
MavenMetadata mavenMetadata = metadataDownloader.download(requestFactory.create(metadataUrl, options)); | ||
return mavenMetadata.getVersioning().getLatest(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/redskap/swagger/brake/maven/maven2/LatestJarArtifactDownloader.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,23 @@ | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
import java.io.File; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import io.redskap.swagger.brake.maven.url.UrlFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
class LatestJarArtifactDownloader { | ||
private final UrlFactory urlFactory; | ||
private final TemporaryJarFileDownloader temporaryJarFileDownloader; | ||
private final RepositoryRequestFactory requestFactory; | ||
|
||
File download(DownloadOptions options, String latestSnapshotName, String latestVersion) { | ||
String url = urlFactory.createLatestArtifactUrl(options, latestVersion, latestSnapshotName); | ||
HttpUriRequest httpRequest = requestFactory.create(url, options); | ||
return temporaryJarFileDownloader.download(httpRequest); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/redskap/swagger/brake/maven/maven2/LatestSnapshotNameResolver.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.maven.maven2; | ||
|
||
import static java.lang.String.format; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import io.redskap.swagger.brake.maven.model.MavenMetadata; | ||
import io.redskap.swagger.brake.maven.model.MavenSnapshot; | ||
import io.redskap.swagger.brake.maven.url.UrlFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
class LatestSnapshotNameResolver { | ||
private final UrlFactory urlFactory; | ||
private final MavenMetadataDownloader metadataDownloader; | ||
private final RepositoryRequestFactory requestFactory; | ||
|
||
String resolve(DownloadOptions options, String latestVersion) { | ||
String metadataUrl = urlFactory.createLatestArtifactSnapshotMetadataUrl(options, latestVersion); | ||
MavenMetadata snapshotMetadata = metadataDownloader.download(requestFactory.create(metadataUrl, options)); | ||
MavenSnapshot snapshot = snapshotMetadata.getVersioning().getSnapshot(); | ||
String snapshotVersion = latestVersion.replaceAll("SNAPSHOT", snapshot.getTimestamp()); | ||
return format("%s-%s-%s", snapshotMetadata.getArtifactId(), snapshotVersion, snapshot.getBuildNumber()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/redskap/swagger/brake/maven/maven2/Maven2LatestArtifactDownloader.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,23 @@ | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
import java.io.File; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import io.redskap.swagger.brake.maven.LatestArtifactDownloader; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component("maven2LatestArtifactDownloader") | ||
@RequiredArgsConstructor | ||
class Maven2LatestArtifactDownloader implements LatestArtifactDownloader { | ||
private final LatestArtifactVersionResolver latestArtifactVersionResolver; | ||
private final LatestSnapshotNameResolver latestSnapshotNameResolver; | ||
private final LatestJarArtifactDownloader latestJarArtifactDownloader; | ||
|
||
@Override | ||
public File download(DownloadOptions options) { | ||
String latestVersion = latestArtifactVersionResolver.resolve(options); | ||
String latestSnapshotName = latestSnapshotNameResolver.resolve(options, latestVersion); | ||
return latestJarArtifactDownloader.download(options, latestSnapshotName, latestVersion); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/io/redskap/swagger/brake/maven/maven2/RepositoryRequestFactory.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,25 @@ | ||
package io.redskap.swagger.brake.maven.maven2; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import io.redskap.swagger.brake.maven.http.HttpRequestFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RepositoryRequestFactory { | ||
private final HttpRequestFactory requestFactory; | ||
|
||
public HttpUriRequest create(String url, DownloadOptions options) { | ||
try { | ||
if (options.isAuthenticationNeeded()) { | ||
return requestFactory.authenticatedGet(url, options.getUsername(), options.getPassword()); | ||
} else { | ||
return requestFactory.get(url); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Error while creating the http request", e); | ||
} | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...ake/maven/TemporaryJarFileDownloader.java → ...en/maven2/TemporaryJarFileDownloader.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
29 changes: 29 additions & 0 deletions
29
src/main/java/io/redskap/swagger/brake/maven/url/UrlFactory.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,29 @@ | ||
package io.redskap.swagger.brake.maven.url; | ||
|
||
import static java.lang.String.format; | ||
|
||
import io.redskap.swagger.brake.maven.DownloadOptions; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class UrlFactory { | ||
public String createLatestArtifactSnapshotMetadataUrl(DownloadOptions options, String latestVersion) { | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options); | ||
return format("%s/%s/maven-metadata.xml", artifactBasePathUrl, latestVersion); | ||
} | ||
|
||
public String createLatestArtifactVersionMetadataUrl(DownloadOptions options) { | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options); | ||
return format("%s/maven-metadata.xml", artifactBasePathUrl); | ||
} | ||
|
||
public String createLatestArtifactUrl(DownloadOptions options, String latestVersion, String latestSnapshotName) { | ||
String artifactBasePathUrl = createLatestArtifactBasePathUrl(options); | ||
return format("%s/%s/%s.jar", artifactBasePathUrl, latestVersion, latestSnapshotName); | ||
} | ||
|
||
private String createLatestArtifactBasePathUrl(DownloadOptions options) { | ||
String groupPath = options.getGroupId().replaceAll("\\.", "/"); | ||
return format("%s/%s/%s", options.getRepoUrl(), groupPath, options.getArtifactId()); | ||
} | ||
} |
Oops, something went wrong.