/**
     * Explodes the plugin into a directory, if necessary.
     */
    private static void explode(File archive, File destDir) throws IOException {
        if(!destDir.exists())
            destDir.mkdirs();

        // timestamp check
        File explodeTime = new File(destDir,".timestamp");
        if(explodeTime.exists() && explodeTime.lastModified()==archive.lastModified())
            return; // no need to expand

        // delete the contents so that old files won't interfere with new files
        Util.deleteRecursive(destDir);

        try {
            Expand e = new Expand();
            e.setProject(new Project());
            e.setTaskType("unzip");
            e.setSrc(archive);
            e.setDest(destDir);
            e.execute();
        } catch (BuildException x) {
            throw new IOException2("Failed to expand " + archive,x);
        }

        try {
            new FilePath(explodeTime).touch(archive.lastModified());
        } catch (InterruptedException e) {
            throw new AssertionError(e); // impossible
        }
    }
Ejemplo n.º 2
0
  /** Performs tagging. */
  public void perform(String tagName, TaskListener listener) {
    File destdir = null;
    try {
      destdir = Util.createTempDir();

      // unzip the archive
      listener
          .getLogger()
          .println(hudson.scm.cvs.Messages.CVSSCM_ExpandingWorkspaceArchive(destdir));
      Expand e = new Expand();
      e.setProject(new org.apache.tools.ant.Project());
      e.setDest(destdir);
      e.setSrc(CVSSCM.getArchiveFile(build));
      e.setTaskType("unzip");
      e.execute();

      // run cvs tag command
      listener.getLogger().println(hudson.scm.cvs.Messages.CVSSCM_TaggingWorkspace());
      for (ModuleLocation moduleLocation : scmInstance.getModuleLocations()) {
        @SuppressWarnings("unchecked")
        ModuleLocation parametrizedLocation =
            new ParametrizedModuleLocationImpl(moduleLocation, build.getBuildVariables());
        for (String module : parametrizedLocation.getNormalizedModules()) {
          if (!createTag(
              tagName,
              listener,
              destdir,
              parametrizedLocation.getLocalDir(),
              module,
              scmInstance.isFlatten())) {
            return;
          }
        }
      }

      // completed successfully
      onTagCompleted(tagName);
      build.save();
    } catch (Throwable e) {
      e.printStackTrace(listener.fatalError(e.getMessage()));
    } finally {
      try {
        if (destdir != null) {
          listener.getLogger().println("cleaning up " + destdir);
          Util.deleteRecursive(destdir);
        }
      } catch (IOException e) {
        e.printStackTrace(listener.fatalError(e.getMessage()));
      }
    }
  }