Skip to content

Commit

Permalink
Merge pull request #253 from spyrkob/MODULES-395
Browse files Browse the repository at this point in the history
[MODULES-395] Fix MavenResourceTest using https and add code to follo…
  • Loading branch information
dmlloyd committed Feb 3, 2020
2 parents 9d5fb98 + 28b4fe0 commit 81308ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/main/java/org/jboss/modules/maven/MavenArtifactUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -157,10 +157,21 @@ static void downloadFile(String artifact, String src, File dest) throws IOExcept
if (dest.exists()){
return;
}
final URL url = new URL(src);
final URLConnection connection = MavenSettings.getSettings().openConnection(url);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection)MavenSettings.getSettings().openConnection(url);
boolean message = Boolean.getBoolean("maven.download.message");

int statusCode = connection.getResponseCode();
if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
return;
}
if (statusCode == HttpURLConnection.HTTP_MOVED_TEMP
|| statusCode == HttpURLConnection.HTTP_MOVED_PERM) {
src = connection.getHeaderField("Location");
url = new URL(src);
connection = (HttpURLConnection) url.openConnection();
}

try (InputStream bis = connection.getInputStream()){
dest.getParentFile().mkdirs();
if (message) { System.out.println("Downloading " + artifact); }
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jboss/modules/MavenResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void setupRepo() throws Exception {
@Test
public void testWithPassedRepository() throws Exception {
System.setProperty("maven.repo.local", tmpdir.newFolder("repository").getAbsolutePath());
System.setProperty("remote.maven.repo", "http://repository.jboss.org/nexus/content/groups/public/,https://maven-central.storage.googleapis.com/");
System.setProperty("remote.maven.repo", "https://repository.jboss.org/nexus/content/groups/public/,https://maven-central.storage.googleapis.com/");
try {
Module module = moduleLoader.loadModule(MODULE_ID);
URL url = module.getResource("org/jboss/resteasy/plugins/providers/jackson/ResteasyJacksonProvider.class");
Expand Down

0 comments on commit 81308ea

Please sign in to comment.