// TODO: Make this more decoupled and unit testable public static void resolveHerdDependency(Long id, String name, String version) throws IOException { models.Upload upload = getUpload(id); HerdDependency hd = getHerdDependency(upload, name, version); // check that we didn't already resolve it from Herd if (hd != null) { Validation.addError(null, "Module already resolved from Herd"); prepareForErrorRedirect(); view(id); } String url = "http://modules.ceylon-lang.org/modules/" + name + "/" + version; Logger.info("Looking up module in Herd at: %s", url); HttpResponse response = WS.url(url).head(); if (response.getStatus() == HttpURLConnection.HTTP_OK) { hd = new HerdDependency(name, version, upload); hd.create(); flash("message", "Found in Herd"); } else if (response.getStatus() == HttpURLConnection.HTTP_NOT_FOUND) { flash("message", "Module could not be found in Herd"); } else { flash( "message", "Module could not be found in Herd: " + response.getStatus() + ": " + response.getString()); } view(id); }
public static void resolveMavenDependency(Long id, String name, String version) throws IOException { models.Upload upload = getUpload(id); MavenDependency md = getMavenDependency(upload, name, version); // check that we didn't already resolve it from Maven if (md != null) { Validation.addError(null, "Module already resolved from Maven"); prepareForErrorRedirect(); view(id); } // 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 int idSep = name.lastIndexOf(':'); if (idSep == -1) idSep = name.lastIndexOf('.'); if (idSep == -1) { Validation.addError( null, "Module name does not contain any ':' or '.' (used to separate the artifact group and ID)"); prepareForErrorRedirect(); view(id); } String mavenUrl = Play.configuration.getProperty("maven.url", "http://repo1.maven.org/maven2"); String groupId = name.substring(0, idSep); String groupIdPath = groupId.replace('.', '/'); String artifactId = name.substring(idSep + 1); String url = mavenUrl + "/" + 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); md.create(); flash("message", "Found in Maven central"); } else if (response.getStatus() == HttpURLConnection.HTTP_NOT_FOUND) { flash("message", "Module could not be found in Maven central"); } else { flash( "message", "Module could not be found in Maven central: " + response.getStatus() + ": " + response.getString()); } view(id); }