Exemple #1
0
  private static void deleteFileImpl(String path, File file, File uploadsDir, Upload upload)
      throws IOException {
    checkUploadPath(file, uploadsDir);

    if (!file.exists()) {
      notFound(path);
    }

    Logger.info("delete: %s exists: %s", path, file.exists());

    if (uploadsDir.getCanonicalPath().equals(file.getCanonicalPath())) {
      // clear the entire repo
      for (File f : uploadsDir.listFiles()) {
        if (f.isDirectory()) FileUtils.deleteDirectory(f);
        else f.delete();
      }
      // let's be helpful and remove maven dependencies too
      for (MavenDependency md : upload.mavenDependencies) {
        md.delete();
      }
      flash("message", "Upload cleared");
    } else if (file.isDirectory()) {
      FileUtils.deleteDirectory(file);
      flash("message", "Directory deleted");
    } else {
      file.delete();
      flash("message", "File deleted");
    }
  }
Exemple #2
0
  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);
  }
Exemple #3
0
  public static void removeMavenDependency(Long id, String name, String version)
      throws IOException {
    models.Upload upload = getUpload(id);

    MavenDependency md = getMavenDependency(upload, name, version);
    if (md == null) {
      Validation.addError(null, "Module was not resolved from Maven");
      prepareForErrorRedirect();
      view(id);
    }
    md.delete();
    view(upload.id);
  }
Exemple #4
0
 public static void clearMavenDependencies(Long id) throws IOException {
   models.Upload upload = getUpload(id);
   for (MavenDependency md : upload.mavenDependencies) md.delete();
   flash("message", "Maven dependencies cleared");
   view(id);
 }