Exemplo n.º 1
0
  public static void delete(Long id) throws IOException {
    models.Upload upload = getUpload(id);
    File uploadsDir = Util.getUploadDir(id);

    upload.delete();
    FileUtils.deleteDirectory(uploadsDir);

    MyCache.evictUploadsForOwner(upload.owner);

    flash("message", "Upload repository deleted");
    index();
  }
Exemplo n.º 2
0
  public static void newUpload() throws IOException {
    models.Upload upload = new models.Upload();
    upload.owner = getUser();
    upload.created = Util.currentTimeInUTC();
    upload.create();
    File uploadDir = Util.getUploadDir(upload.id);
    if (!uploadDir.mkdirs())
      throw new RuntimeException("Failed to create upload dir " + uploadDir.getAbsolutePath());

    MyCache.evictUploadsForOwner(upload.owner);

    view(upload.id);
  }
Exemplo n.º 3
0
  public static void publish(Long id) throws IOException {
    models.Upload upload = getUpload(id);
    File uploadsDir = Util.getUploadDir(id);
    User user = getUser();
    UploadInfo uploadInfo = getUploadInfo(upload, uploadsDir, user);

    if (!uploadInfo.isPublishable()) {
      Validation.addError(null, "Upload is not valid, cannot publish. Fix errors first.");
      prepareForErrorRedirect();
      view(id);
    }

    List<models.ModuleVersion> versions = new LinkedList<models.ModuleVersion>();
    for (Module module : uploadInfo.modules) {
      models.Module mod = models.Module.find("name = ?", module.name).first();
      if (mod == null) {
        mod = new models.Module();
        mod.name = module.name;
        mod.owner = user;
        mod.create();
      }

      models.ModuleVersion modVersion = new models.ModuleVersion();
      modVersion.module = mod;
      modVersion.version = module.version;
      modVersion.isCarPresent = module.car.exists;
      modVersion.isJarPresent = module.jar.exists;
      modVersion.isJsPresent = module.js.exists;
      modVersion.isSourcePresent = module.source.exists;
      modVersion.isScriptsPresent = module.scripts.exists;
      modVersion.isAPIPresent = module.docs.hasUnzipped;
      modVersion.isDocPresent = module.docs.exists;
      modVersion.isResourcesPresent = module.docs.exists;
      modVersion.isRunnable = module.isRunnable;
      modVersion.jvmBinMajor = module.jvmBinMajor;
      modVersion.jvmBinMinor = module.jvmBinMinor;
      modVersion.jsBinMajor = module.jsBinMajor;
      modVersion.jsBinMinor = module.jsBinMinor;
      modVersion.isNativeJvm = module.isNativeJvm();
      modVersion.isNativeJs = module.isNativeJs();
      modVersion.published = Util.currentTimeInUTC();
      modVersion.doc = module.doc;
      modVersion.license = module.license;
      if (module.authors != null) {
        for (String author : module.authors) {
          modVersion.authors.add(Author.findOrCreate(author));
        }
      }
      modVersion.create();

      for (Import imp : module.getAllDependencies())
        modVersion.addDependency(
            imp.name,
            imp.version,
            imp.optional,
            imp.export,
            imp.mavenDependency != null,
            imp.herdDependency != null,
            imp.isNativeJvm(),
            imp.isNativeJs());

      for (ModuleChecker.Member member : module.members)
        modVersion.addMember(member.packageName, member.name, member.type, member.shared);

      for (ModuleChecker.Script script : module.scriptDescriptions)
        modVersion.addScript(
            script.name, script.description, script.unix, script.plugin, script.module);

      versions.add(modVersion);
    }

    FileUtils.copyDirectory(uploadsDir, Util.getRepoDir(), NonEmptyDirectoryFilter);
    FileUtils.deleteDirectory(uploadsDir);
    upload.delete();

    MyCache.evictUploadsForOwner(user);
    MyCache.evictModulesForOwner(user);

    if (versions.size() == 1) {
      flash("message", "Your module has been published");
      models.ModuleVersion moduleVersion = versions.get(0);
      Repo.view(moduleVersion.module.name, moduleVersion.version);
    } else {
      flash("message", "Your modules have been published");
      render(versions);
    }
  }