コード例 #1
0
  void unpackJars() throws BuildException {
    // unpack in separate dirs, to allow multiple instances of the same
    // resource from different jars.

    int jarId = 0;

    Iterator it = task.getLibs().iterator();
    while (it.hasNext()) {
      FileSet fs = (FileSet) it.next();
      DirectoryScanner scanner = fs.getDirectoryScanner(task.getProject());

      String[] files = scanner.getIncludedFiles();
      Expand unjar = (Expand) task.createSubtask(Expand.class);

      for (int i = 0; i < files.length; i++) {

        File unpackDir = new File(scratchDir, jarId++ + "");
        unpackDir.mkdirs();
        unpackedJarDirs.add(unpackDir);

        unjar.setDest(unpackDir);
        unjar.setSrc(new File(scanner.getBasedir(), files[i]));
        unjar.execute();
      }
    }
  }
コード例 #2
0
    /**
     * 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
        }
    }
コード例 #3
0
ファイル: ExpandTask.java プロジェクト: nykma/ykt4sungard
  public static void expand(File source, File destination) {
    Expand expand = new Expand();

    expand.setProject(AntUtil.getProject());
    expand.setSrc(source);
    expand.setDest(destination);

    expand.execute();
  }
コード例 #4
0
ファイル: URLImportTask.java プロジェクト: cniweb/ant-contrib
  public void execute() throws BuildException {

    IvyAdapter adapter = null;

    try {
      Class.forName("org.apache.ivy.Ivy");
      adapter = new Ivy20Adapter();
    } catch (ClassNotFoundException e) {
      adapter = new Ivy14Adapter();
    }

    String setId = org + "." + module + "." + rev + ".fileset";
    adapter.configure(this);
    adapter.fileset(this, setId);

    FileSet fileset = (FileSet) getProject().getReference(setId);

    DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());

    String files[] = scanner.getIncludedFiles();

    File file = new File(scanner.getBasedir(), files[0]);

    File importFile = null;

    if ("xml".equalsIgnoreCase(type)) {
      importFile = file;
    } else if ("jar".equalsIgnoreCase(type) || "zip".equalsIgnoreCase(type)) {
      File dir = new File(file.getParentFile(), file.getName() + ".extracted");
      if (!dir.exists() || dir.lastModified() < file.lastModified()) {
        dir.mkdir();
        Expand expand = (Expand) getProject().createTask("unjar");
        expand.setSrc(file);
        expand.setDest(dir);
        expand.perform();
      }
      importFile = new File(dir, resource);
      if (!importFile.exists()) {
        throw new BuildException("Cannot find a '" + resource + "' file in " + file.getName());
      }
    } else {
      throw new BuildException("Don't know what to do with type: " + type);
    }

    log("Importing " + importFile.getName(), Project.MSG_INFO);

    super.setFile(importFile.getAbsolutePath());
    super.execute();

    log("Import complete.", Project.MSG_INFO);
  }
コード例 #5
0
ファイル: TagAction.java プロジェクト: hedrickbt/cvs-plugin
  /** 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()));
      }
    }
  }