Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Fixed Maven resolving with : in module names #223
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Apr 3, 2015
1 parent c2a3714 commit eb9cb48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 12 additions & 5 deletions app/controllers/Uploads.java
Expand Up @@ -4,7 +4,10 @@
import models.MavenDependency;
import models.Upload;
import models.User;

import org.apache.commons.io.FileUtils;

import play.Logger;
import play.data.validation.Required;
import play.data.validation.Validation;
import play.libs.WS;
Expand Down Expand Up @@ -151,16 +154,20 @@ public static void resolveMavenDependency(Long id, String name, String version)

// check if the module in question is really in maven
// ex: http://repo1.maven.org/maven2/io/vertx/vertx-core/2.0.0-beta5/vertx-core-2.0.0-beta5.jar
String namePath = name.replace('.', '/');
int idSep = name.lastIndexOf('.');
int idSep = name.lastIndexOf(':');
if(idSep == -1)
idSep = name.lastIndexOf('.');
if(idSep == -1){
Validation.addError(null, "Module name does not contain any '.' (used to separate the artifact group and ID)");
Validation.addError(null, "Module name does not contain any ':' or '.' (used to separate the artifact group and ID)");
prepareForErrorRedirect();
view(id);
}
String idPart = name.substring(idSep+1);
String url = "http://repo1.maven.org/maven2/" + namePath + "/" + version + "/" + idPart + "-" + version + ".jar";
String groupId = name.substring(0, idSep);
String groupIdPath = groupId.replace('.', '/');
String artifactId = name.substring(idSep+1);
String url = "http://repo1.maven.org/maven2/" + groupIdPath + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar";

Logger.info("Looking up module in Maven Central at: %s", url);
HttpResponse response = WS.url(url).head();
if(response.getStatus() == HttpURLConnection.HTTP_OK){
md = new MavenDependency(name, version, upload);
Expand Down
10 changes: 6 additions & 4 deletions app/models/Dependency.java
Expand Up @@ -47,10 +47,12 @@ public boolean isOtherVersions(){
@Transient
public String getMavenUrl(){
// http://search.maven.org/#artifactdetails%7Cio.vertx%7Cvertx-core%7C2.0.0-beta5%7Cjar
int lastdoc = name.lastIndexOf('.');
if(lastdoc != -1){
String groupId = name.substring(0, lastdoc);
String artifactId = name.substring(lastdoc+1);
int idSep = name.lastIndexOf(':');
if(idSep == -1)
idSep = name.lastIndexOf('.');
if(idSep != -1){
String groupId = name.substring(0, idSep);
String artifactId = name.substring(idSep+1);
return "http://search.maven.org/#artifactdetails%7C"+groupId+"%7C"+artifactId+"%7C"+version+"%7Cjar";
}
// try to help
Expand Down

0 comments on commit eb9cb48

Please sign in to comment.