コード例 #1
0
  /**
   * Initializes default class loader. It inherits from classloader, which was used to load this
   * task, therefore build-in classes and resources are loaded automatically.
   *
   * <p>Notice: task's classpath has priority over default classpath, therefore we are able to
   * easily override resources (templates)
   */
  protected void initClassloader() {
    // NOTICE: we should use the same classloader, which was used to load this task
    // otherwise we won't be able to cast instances
    // (that were loaded via different class loaders)

    // we are introducting workaround,
    // that tries to add classpath for current task to original class loader
    // and stores original classpath
    // after the task is executed, classpath is restored

    ClassLoader classLoader = getClass().getClassLoader();
    if (classLoader instanceof AntClassLoader) {
      // add defined classpath
      AntClassLoader antClassLoader = (AntClassLoader) classLoader;
      antClassLoader.setParentFirst(false);
      antClassLoader.setProject(getProject());
      savedClasspath = antClassLoader.getClasspath();

      Path cp = getClasspath();
      // add defined classpath to original path
      cp.add(new Path(getProject(), savedClasspath));
      antClassLoader.setClassPath(cp);
    } else {
      // create new class loader
      classLoader =
          new AntClassLoader(getClass().getClassLoader(), getProject(), getClasspath(), false);
    }

    // set this class loader as new class loader for whole thread
    // ContextClassLoader is used in StringTemplate's PathGroupLoader and other classes
    Thread.currentThread().setContextClassLoader(classLoader);
  }
コード例 #2
0
ファイル: IvyCachePath.java プロジェクト: foursquare/ant-ivy
 protected void addToPath(Path path, File f) throws Exception {
   if (!osgi || !f.isDirectory()) {
     path.createPathElement().setLocation(f);
     return;
   }
   File manifest = new File(f, "META-INF/MANIFEST.MF");
   if (!manifest.exists()) {
     path.createPathElement().setLocation(f);
     return;
   }
   BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
   List /* <String> */ cp = bundleInfo.getClasspath();
   if (cp == null) {
     path.createPathElement().setLocation(f);
     return;
   }
   for (int i = 0; i < cp.size(); i++) {
     String p = (String) cp.get(i);
     if (p.equals(".")) {
       path.createPathElement().setLocation(f);
     } else {
       path.createPathElement().setLocation(new File(f, p));
     }
   }
 }
コード例 #3
0
ファイル: Groovydoc.java プロジェクト: codehaus/groovy-git
  public void execute() throws BuildException {
    List<String> packagesToDoc = new ArrayList<String>();
    Path sourceDirs = new Path(getProject());
    Properties properties = new Properties();
    properties.setProperty("windowTitle", windowTitle);
    properties.setProperty("docTitle", docTitle);
    properties.setProperty("footer", footer);
    properties.setProperty("header", header);
    checkScopeProperties(properties);
    properties.setProperty("publicScope", publicScope.toString());
    properties.setProperty("protectedScope", protectedScope.toString());
    properties.setProperty("packageScope", packageScope.toString());
    properties.setProperty("privateScope", privateScope.toString());
    properties.setProperty("author", author.toString());
    properties.setProperty("processScripts", processScripts.toString());
    properties.setProperty("includeMainForScripts", includeMainForScripts.toString());
    properties.setProperty(
        "overviewFile", overviewFile != null ? overviewFile.getAbsolutePath() : "");
    properties.setProperty("charset", charset != null ? charset : "");
    properties.setProperty("fileEncoding", fileEncoding != null ? fileEncoding : "");

    if (sourcePath != null) {
      sourceDirs.addExisting(sourcePath);
    }
    parsePackages(packagesToDoc, sourceDirs);

    GroovyDocTool htmlTool =
        new GroovyDocTool(
            new ClasspathResourceManager(), // we're gonna get the default templates out of the dist
                                            // jar file
            sourcePath.list(),
            getDocTemplates(),
            getPackageTemplates(),
            getClassTemplates(),
            links,
            properties);

    try {
      htmlTool.add(sourceFilesToDoc);
      FileOutputTool output = new FileOutputTool();
      htmlTool.renderToOutput(
          output, destDir.getCanonicalPath()); // TODO push destDir through APIs?
    } catch (Exception e) {
      e.printStackTrace();
    }
    // try to override the default stylesheet with custom specified one if needed
    if (styleSheetFile != null) {
      try {
        String css = ResourceGroovyMethods.getText(styleSheetFile);
        File outfile = new File(destDir, "stylesheet.css");
        ResourceGroovyMethods.setText(outfile, css);
      } catch (IOException e) {
        System.out.println(
            "Warning: Unable to copy specified stylesheet '"
                + styleSheetFile.getAbsolutePath()
                + "'. Using default stylesheet instead. Due to: "
                + e.getMessage());
      }
    }
  }
コード例 #4
0
ファイル: Depend.java プロジェクト: saeg/experiments
  /**
   * Get the classpath for dependency checking.
   *
   * <p>This method removes the dest dirs if it is given from the dependency classpath
   */
  private Path getCheckClassPath() {
    if (dependClasspath == null) {
      return null;
    }

    String[] destPathElements = destPath.list();
    String[] classpathElements = dependClasspath.list();
    String checkPath = "";
    for (int i = 0; i < classpathElements.length; ++i) {
      String element = classpathElements[i];
      boolean inDestPath = false;
      for (int j = 0; j < destPathElements.length && !inDestPath; ++j) {
        inDestPath = destPathElements[j].equals(element);
      }
      if (!inDestPath) {
        if (checkPath.length() == 0) {
          checkPath = element;
        } else {
          checkPath += ":" + element;
        }
      }
    }

    if (checkPath.length() == 0) {
      return null;
    }

    return new Path(getProject(), checkPath);
  }
コード例 #5
0
ファイル: Path.java プロジェクト: nhojpatrick/ant
 /**
  * Adds a nested path
  *
  * @param path a <code>Path</code> to be added to the path
  * @throws BuildException on error
  * @since Ant 1.6
  */
 public void add(Path path) throws BuildException {
   if (path == this) {
     throw circularReference();
   }
   if (path.getProject() == null) {
     path.setProject(getProject());
   }
   add((ResourceCollection) path);
 }
コード例 #6
0
ファイル: Path.java プロジェクト: nhojpatrick/ant
 /**
  * Clone this Path.
  *
  * @return Path with shallowly cloned Resource children.
  */
 public Object clone() {
   try {
     Path result = (Path) super.clone();
     result.union = union == null ? union : (Union) union.clone();
     return result;
   } catch (CloneNotSupportedException e) {
     throw new BuildException(e);
   }
 }
コード例 #7
0
 /** {@inheritDoc} */
 public final Path convertToPath(File[] entries) {
   Assure.notNull("entries", entries);
   Path antPath = new Path(getAntProject());
   for (File entry : entries) {
     // TODO getPath() vs. getAbsolutePath()
     antPath.append(new Path(getAntProject(), entry.getPath()));
   }
   return antPath;
 }
コード例 #8
0
ファイル: Sieve.java プロジェクト: onyxbits/ScenePainter
 /**
  * Test the layout of a directory against the sieve.
  *
  * @param dir the directory to test
  * @return true if the directory structure matches the sieve's configuration.
  */
 public boolean matches(File dir) {
   for (String str : includes) {
     File f = new File(dir, Path.translateFile(str));
     if (!f.exists()) return false;
   }
   for (String str : excludes) {
     File f = new File(dir, Path.translateFile(str));
     if (f.exists()) return false;
   }
   return true;
 }
コード例 #9
0
ファイル: BndTask.java プロジェクト: lostiniceland/bnd
 public void setClasspath(String value) {
   Path p = (Path) getProject().getReference(value);
   if (p == null) addAll(classpath, value, File.pathSeparator + ",");
   else {
     String[] path = p.list();
     for (int i = 0; i < path.length; i++) {
       File f = new File(path[i]);
       if (f.exists()) classpath.add(f);
       else messages.NoSuchFile_(f.getAbsoluteFile());
     }
   }
   classpathDirectlySet = true;
 }
コード例 #10
0
 public void setClassPath(final Path classpath) {
   this.pathComponents.removeAllElements();
   if (classpath != null) {
     final Path actualClasspath = classpath.concatSystemClasspath("ignore");
     final String[] pathElements = actualClasspath.list();
     for (int i = 0; i < pathElements.length; ++i) {
       try {
         this.addPathElement(pathElements[i]);
       } catch (BuildException ex) {
       }
     }
   }
 }
コード例 #11
0
ファイル: PitestTaskTest.java プロジェクト: noroute/pitest
 @Override
 public boolean matches(final Object argument) {
   final Path argPath = (Path) argument;
   final String[] paths = argPath.toString().split(File.pathSeparator);
   final boolean matches = paths.length == this.expectedPaths.length;
   if (matches) {
     for (final String expectedPathElement : this.expectedPaths) {
       if (isNotPresent(paths, expectedPathElement)) {
         return false;
       }
     }
   }
   return matches;
 }
コード例 #12
0
  private void addSourcePath(Resource resource, Javadoc javadoc, Path source) {
    //
    // handle the target resource
    //

    if (null != resource.getBaseDir()) {
      File src = new File(resource.getBaseDir(), "target/build/main");
      if (src.exists()) {
        log("Adding src path: " + src);
        source.createPathElement().setLocation(src);
        final DirSet packages = new DirSet();
        packages.setDir(src);
        packages.setIncludes("**/*");
        String excludes = getPackageExcludes(resource);
        if (null != excludes) {
          packages.setExcludes(excludes);
        }
        javadoc.addPackageset(packages);
      }
    }

    // add providers

    String path = resource.getResourcePath();
    Resource[] providers = resource.getAggregatedProviders(Scope.RUNTIME, true, false);
    for (int i = 0; i < providers.length; i++) {
      Resource provider = providers[i];
      if (provider.getResourcePath().startsWith(path)) {
        String flag = provider.getProperty("project.javadoc.exclude", "false");
        if ("false".equals(flag)) {
          File basedir = provider.getBaseDir();
          if (null != basedir) {
            File src = new File(basedir, "target/build/main");
            if (src.exists()) {
              log("Adding src path: " + src);
              source.createPathElement().setLocation(src);
              final DirSet packages = new DirSet();
              packages.setDir(src);
              packages.setIncludes("**/**");
              String excludes = getPackageExcludes(provider);
              if (null != excludes) {
                packages.setExcludes(excludes);
              }
              javadoc.addPackageset(packages);
            }
          }
        }
      }
    }
  }
コード例 #13
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
  private void doForkCommandLineList(
      List<String> commandLineList, Path classpath, String separator) {
    if (!fork) return;

    if (includeAntRuntime) {
      classpath.addExisting((new Path(getProject())).concatSystemClasspath("last"));
    }
    if (includeJavaRuntime) {
      classpath.addJavaRuntime();
    }

    if (forkedExecutable != null && !forkedExecutable.equals("")) {
      commandLineList.add(forkedExecutable);
    } else {
      String javaHome;
      if (forkJavaHome != null) {
        javaHome = forkJavaHome.getPath();
      } else {
        javaHome = System.getProperty("java.home");
      }
      commandLineList.add(javaHome + separator + "bin" + separator + "java");
    }
    commandLineList.add("-classpath");
    commandLineList.add(classpath.toString());

    final String fileEncodingProp = System.getProperty("file.encoding");
    if ((fileEncodingProp != null) && !fileEncodingProp.equals("")) {
      commandLineList.add("-Dfile.encoding=" + fileEncodingProp);
    }
    if (targetBytecode != null) {
      commandLineList.add("-Dgroovy.target.bytecode=" + targetBytecode);
    }

    if ((memoryInitialSize != null) && !memoryInitialSize.equals("")) {
      commandLineList.add("-Xms" + memoryInitialSize);
    }
    if ((memoryMaximumSize != null) && !memoryMaximumSize.equals("")) {
      commandLineList.add("-Xmx" + memoryMaximumSize);
    }
    if (!"*.groovy".equals(getScriptExtension())) {
      String tmpExtension = getScriptExtension();
      if (tmpExtension.startsWith("*.")) tmpExtension = tmpExtension.substring(1);
      commandLineList.add("-Dgroovy.default.scriptExtension=" + tmpExtension);
    }
    commandLineList.add(FileSystemCompilerFacade.class.getName());
    if (forceLookupUnnamedFiles) {
      commandLineList.add("--forceLookupUnnamedFiles");
    }
  }
コード例 #14
0
  public org.apache.tools.ant.types.Path toAntPath(List artifacts) {
    org.apache.tools.ant.types.Path path = new org.apache.tools.ant.types.Path(antProject);

    for (Iterator i = artifacts.iterator(); i.hasNext(); ) {
      RepoArtifact artifact = (RepoArtifact) i.next();

      if (artifact.getLocalCopy() != null) { // Possible for "paths" type
        path.add(
            new org.apache.tools.ant.types.Path(
                antProject, artifact.getLocalCopy().getAbsolutePath()));
      }
    }

    return path;
  }
コード例 #15
0
  /**
   * Adds a path for decompilation source.
   *
   * @return source path
   */
  public Path createSrc() {
    if (src == null) {
      src = new Path(getProject());
    }

    return src.createPath();
  }
コード例 #16
0
  /** Scans the source directories looking for source files to be decompiled. */
  protected void scanSrc() throws BuildException {
    for (@SuppressWarnings("unchecked") Iterator<Resource> it = src.iterator(); it.hasNext(); ) {
      Resource resource = it.next();
      FileResource fileResource = resource instanceof FileResource ? (FileResource) resource : null;
      if (fileResource != null) {
        File file = fileResource.getFile();
        if (file.isDirectory()) {
          DirectoryScanner ds = getDirectoryScanner(file);
          String[] files = ds.getIncludedFiles();

          scanDir(file, destdir != null ? destdir : file, files);
        } else {
          String[] files = new String[] {fileResource.getName()};

          scanDir(
              fileResource.getBaseDir(),
              destdir != null ? destdir : fileResource.getBaseDir(),
              files);
        }
      }
      //			else
      //			{
      //				//FIXME what to do?
      //			}
    }
  }
コード例 #17
0
 /**
  * Sets the source directories to find the compiled report design files.
  *
  * @param srcdir source path
  */
 public void setSrcdir(Path srcdir) {
   if (src == null) {
     src = srcdir;
   } else {
     src.append(srcdir);
   }
 }
コード例 #18
0
ファイル: Groovydoc.java プロジェクト: TTwxj/groovy
 /**
  * Specify where to find source file
  *
  * @param src a Path instance containing the various source directories.
  */
 public void setSourcepath(Path src) {
   if (sourcePath == null) {
     sourcePath = src;
   } else {
     sourcePath.append(src);
   }
 }
コード例 #19
0
  /**
   * Adds a path to the classpath.
   *
   * @return classpath to use when decompiling the report
   */
  public Path createClasspath() {
    if (classpath == null) {
      classpath = new Path(getProject());
    }

    return classpath.createPath();
  }
  @Override
  public void execute() throws BuildException {
    if (classpath == null) {
      throw new BuildException("The classpath is not defined");
    }
    if (wadlFile == null) {
      throw new BuildException("destfile attribute required", getLocation());
    }

    if (baseUri == null || baseUri.length() == 0) {
      throw new BuildException("baseUri attribute required", getLocation());
    }

    try {
      Application a = createApplication(classpath.list());
      a.getResources().setBase(baseUri);
      JAXBContext c =
          JAXBContext.newInstance("com.sun.research.ws.wadl", this.getClass().getClassLoader());
      Marshaller m = c.createMarshaller();
      OutputStream out = new BufferedOutputStream(new FileOutputStream(wadlFile));
      m.marshal(a, out);
      out.close();
    } catch (Exception e) {
      throw new BuildException(e);
    }
  }
コード例 #21
0
ファイル: Depend.java プロジェクト: saeg/experiments
 /**
  * Set the classpath to be used for this dependency check.
  *
  * @param classpath the classpath to be used when checking for dependencies on elements in the
  *     classpath
  */
 public void setClasspath(Path classpath) {
   if (dependClasspath == null) {
     dependClasspath = classpath;
   } else {
     dependClasspath.append(classpath);
   }
 }
コード例 #22
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
 /**
  * Set the classpath to be used for this compilation.
  *
  * @param classpath an Ant Path object containing the compilation classpath.
  */
 public void setClasspath(Path classpath) {
   if (compileClasspath == null) {
     compileClasspath = classpath;
   } else {
     compileClasspath.append(classpath);
   }
 }
コード例 #23
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
  /**
   * Executes the task.
   *
   * @throws BuildException if an error occurs
   */
  public void execute() throws BuildException {
    checkParameters();
    resetFileLists();
    loadRegisteredScriptExtensions();

    if (javac != null) jointCompilation = true;

    // scan source directories and dest directory to build up
    // compile lists
    String[] list = src.list();
    for (String filename : list) {
      File file = getProject().resolveFile(filename);
      if (!file.exists()) {
        throw new BuildException(
            "srcdir \"" + file.getPath() + "\" does not exist!", getLocation());
      }
      DirectoryScanner ds = this.getDirectoryScanner(file);
      String[] files = ds.getIncludedFiles();
      scanDir(file, destDir != null ? destDir : file, files);
    }

    compile();
    if (updatedProperty != null && taskSuccess && compileList.length != 0) {
      getProject().setNewProperty(updatedProperty, "true");
    }
  }
コード例 #24
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
  private void loadRegisteredScriptExtensions() {
    if (scriptExtensions.isEmpty()) {

      scriptExtensions.add(
          getScriptExtension()
              .substring(2)); // first extension will be the one set explicitly on <groovyc>

      Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
      final String[] pe = classpath.list();
      final GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
      for (String file : pe) {
        loader.addClasspath(file);
      }
      scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
    }
  }
コード例 #25
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
 /**
  * Set the sourcepath to be used for this compilation.
  *
  * @param sourcepath the source path
  */
 public void setSourcepath(Path sourcepath) {
   if (compileSourcepath == null) {
     compileSourcepath = sourcepath;
   } else {
     compileSourcepath.append(sourcepath);
   }
 }
コード例 #26
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
 /**
  * Add "groovyc" parameters to the commandLineList, based on the ant configuration.
  *
  * @param commandLineList
  * @param jointOptions
  * @param classpath
  */
 private void doNormalCommandLineList(
     List<String> commandLineList, List<String> jointOptions, Path classpath) {
   commandLineList.add("--classpath");
   commandLineList.add(classpath.toString());
   if (jointCompilation) {
     commandLineList.add("-j");
     commandLineList.addAll(jointOptions);
   }
   if (destDir != null) {
     commandLineList.add("-d");
     commandLineList.add(destDir.getPath());
   }
   if (encoding != null) {
     commandLineList.add("--encoding");
     commandLineList.add(encoding);
   }
   if (stacktrace) {
     commandLineList.add("-e");
   }
   if (parameters) {
     commandLineList.add("--parameters");
   }
   if (useIndy) {
     commandLineList.add("--indy");
   }
   if (scriptBaseClass != null) {
     commandLineList.add("-b");
     commandLineList.add(scriptBaseClass);
   }
   if (configscript != null) {
     commandLineList.add("--configscript");
     commandLineList.add(configscript);
   }
 }
コード例 #27
0
ファイル: BndTask.java プロジェクト: lostiniceland/bnd
 private void addFilesFrom(Path path, List<File> files) {
   for (String fileName : path.list()) {
     File f = new File(fileName.replace('\\', '/'));
     if (f.exists()) files.add(f);
     else messages.NoSuchFile_(f.getAbsoluteFile());
   }
 }
コード例 #28
0
 /**
  * Support nested <code>classpath</code> elements
  *
  * @return
  */
 public Path createClasspath() {
   // return this.cpDelegate.createClasspath();
   if (classpath == null) {
     classpath = new Path(this.getProject());
   }
   return classpath.createPath();
 }
コード例 #29
0
ファイル: AbstractAnalyzer.java プロジェクト: nhojpatrick/ant
 /**
  * Add a source path to the source path used by this analyzer. The elements in the given path
  * contain the source files for the classes being analyzed. Not all analyzers will use this
  * information.
  *
  * @param sourcePath The Path instance specifying the source path elements.
  */
 public void addSourcePath(Path sourcePath) {
   if (sourcePath == null) {
     return;
   }
   this.sourcePath.append(sourcePath);
   this.sourcePath.setProject(sourcePath.getProject());
 }
コード例 #30
0
ファイル: Path.java プロジェクト: nhojpatrick/ant
  /**
   * Same as addExisting, but support classpath behavior if tryUserDir is true. Classpaths are
   * relative to user dir, not the project base. That used to break jspc test
   *
   * @param source the source path
   * @param tryUserDir if true try the user directory if the file is not present
   */
  public void addExisting(Path source, boolean tryUserDir) {
    String[] list = source.list();
    File userDir = (tryUserDir) ? new File(System.getProperty("user.dir")) : null;

    for (int i = 0; i < list.length; i++) {
      File f = resolveFile(getProject(), list[i]);

      // probably not the best choice, but it solves the problem of
      // relative paths in CLASSPATH
      if (tryUserDir && !f.exists()) {
        f = new File(userDir, list[i]);
      }
      if (f.exists()) {
        setLocation(f);
      } else if (f.getParentFile() != null
          && f.getParentFile().exists()
          && containsWildcards(f.getName())) {
        setLocation(f);
        log(
            "adding "
                + f
                + " which contains wildcards and may not"
                + " do what you intend it to do depending on your OS or"
                + " version of Java",
            Project.MSG_VERBOSE);
      } else {
        log("dropping " + f + " from path as it doesn't exist", Project.MSG_VERBOSE);
      }
    }
  }