org.apache.tools.ant.types.Path.list()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(70)

本文整理了Java中org.apache.tools.ant.types.Path.list()方法的一些代码示例,展示了Path.list()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.list()方法的具体详情如下:
包路径:org.apache.tools.ant.types.Path
类名称:Path
方法名:list

Path.list介绍

[英]Returns all path elements defined by this and nested path objects.
[中]返回此对象和嵌套路径对象定义的所有路径元素。

代码示例

代码示例来源:origin: org.apache.ant/ant

/**
 * Get the file that contains the class definition
 *
 * @param classname the name of the required class
 * @return the file instance, zip or class, containing the
 *         class or null if the class could not be found.
 * @exception IOException if the files in the classpath cannot be read.
 */
@Override
public File getClassContainer(String classname) throws IOException {
  String classLocation = classname.replace('.', '/') + ".class";
  // we look through the classpath elements. If the element is a dir
  // we look for the file. IF it is a zip, we look for the zip entry
  return getResourceContainer(classLocation, classPath.list());
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Get the file that contains the class source.
 *
 * @param classname the name of the required class
 * @return the file instance, zip or java, containing the
 *         source or null if the source for the class could not be found.
 * @exception IOException if the files in the sourcepath cannot be read.
 */
@Override
public File getSourceContainer(String classname) throws IOException {
  String sourceLocation = classname.replace('.', '/') + ".java";
  // we look through the source path elements. If the element is a dir
  // we look for the file. If it is a zip, we look for the zip entry.
  // This isn't normal for source paths but we get it for free
  return getResourceContainer(sourceLocation, sourcePath.list());
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

/**
 * Build a classloader using the additional elements specified in
 * <code>classpath</code> and <code>classpathRef</code>.
 *
 * @return a new classloader that includes the extra path elements found in
 *         the <code>classpath</code> and <code>classpathRef</code> config
 *         values
 */
private ClassLoader buildExtendedClassloader() {
  final List<URL> classpathUrls = new ArrayList<>();
  for (String pathElement : getClasspath().list()) {
    try {
      classpathUrls.add(new File(pathElement).toURI().toURL());
    } catch (MalformedURLException e) {
      throw new BuildException("Unable to use classpath entry as it could not be understood as a valid URL: " + pathElement, e);
    }
  }
  final ClassLoader parentClassloader = Thread.currentThread().getContextClassLoader();
  return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
    @Override
    public ClassLoader run() {
      return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), parentClassloader);
    }
  });
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Set the classpath to search for classes to load. This should not be
 * changed once the classloader starts to server classes
 *
 * @param classpath the search classpath consisting of directories and
 *        jar/zip files.
 */
public void setClassPath(Path classpath) {
  pathComponents.removeAllElements();
  if (classpath != null) {
    Path actualClasspath = classpath.concatSystemClasspath("ignore");
    String[] pathElements = actualClasspath.list();
    for (int i = 0; i < pathElements.length; ++i) {
      try {
        addPathElement(pathElements[i]);
      } catch (BuildException e) {
        // ignore path elements which are invalid
        // relative to the project
      }
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

/**
 * the auxAnalyzepath to use.
 *
 * @param src
 *            auxAnalyzepath
 */
public void setAuxAnalyzepath(Path src) {
  boolean nonEmpty = false;
  String[] elementList = src.list();
  for (String anElementList : elementList) {
    if (!"".equals(anElementList)) {
      nonEmpty = true;
      break;
    }
  }
  if (nonEmpty) {
    if (auxAnalyzepath == null) {
      auxAnalyzepath = src;
    } else {
      auxAnalyzepath.append(src);
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

/**
 * the auxclasspath to use.
 *
 * @param src
 *            auxclasspath to use
 */
public void setAuxClasspath(Path src) {
  boolean nonEmpty = false;
  String[] elementList = src.list();
  for (String anElementList : elementList) {
    if (!"".equals(anElementList)) {
      nonEmpty = true;
      break;
    }
  }
  if (nonEmpty) {
    if (auxClasspath == null) {
      auxClasspath = src;
    } else {
      auxClasspath.append(src);
    }
  }
}

代码示例来源:origin: apache/groovy

private RootLoader makeRoot() {
  String[] list = taskClasspath.list();
  LoaderConfiguration lc = new LoaderConfiguration();
  for (int i=0; i<list.length; i++) {
    if (list[i].matches(".*ant-[^/]*jar$")) {
      continue;
    }
    if (list[i].matches(".*commons-logging-[^/]*jar$")) {
      continue;
    }
    if (list[i].matches(".*xerces-[^/]*jar$")) {
      continue;
    }
    lc.addFile(list[i]);
  }
  return new RootLoader(lc);
}

代码示例来源:origin: org.apache.ant/ant

private void collectFileListFromSourcePath() {
  for (String filename : src.list()) {
    final File srcDir = getProject().resolveFile(filename);
    if (!srcDir.exists()) {
      throw new BuildException("srcdir \""
                   + srcDir.getPath()
                   + "\" does not exist!", getLocation());
    }
    final DirectoryScanner ds = this.getDirectoryScanner(srcDir);
    scanDir(srcDir, destDir != null ? destDir : srcDir, ds.getIncludedFiles());
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Set the classpath to search for classes to load. This should not be
 * changed once the classloader starts to server classes
 *
 * @param classpath the search classpath consisting of directories and
 *        jar/zip files.
 */
public void setClassPath(final Path classpath) {
  pathComponents.removeAllElements();
  if (classpath != null) {
    for (String pathElement : classpath.concatSystemClasspath("ignore").list()) {
      try {
        addPathElement(pathElement);
      } catch (final BuildException e) {
        // ignore path elements which are invalid
        // relative to the project
      }
    }
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * convert all paths to URLs
 *
 * @return the paths as a separated list of URLs
 */
private String pathsToURL() {
  if (paths.isEmpty()) {
    return "";
  }
  int count = 0;
  StringBuilder urls = new StringBuilder();
  for (Path path : paths) {
    for (String element : path.list()) {
      File f = new File(element);
      validateFile(f);
      String asUrl = toURL(f);
      urls.append(asUrl);
      log(asUrl, Project.MSG_DEBUG);
      urls.append(separator);
      count++;
    }
  }
  //at this point there is one trailing space to remove, if the list is not empty.
  return stripTrailingSeparator(urls, count);
}

代码示例来源:origin: checkstyle/checkstyle

final String[] resources = path.list();
log(pathIndex + ") Scanning path " + path, Project.MSG_VERBOSE);
final List<File> allFiles = new ArrayList<>();

代码示例来源:origin: apache/groovy

protected GroovyClassLoader createClassLoader() {
  GroovyClassLoader gcl =
      AccessController.doPrivileged(
          new PrivilegedAction<GroovyClassLoader>() {
            @Override
            public GroovyClassLoader run() {
              return new GroovyClassLoader(ClassLoader.getSystemClassLoader(), config);
            }
          });
  Path path = getClasspath();
  if (path != null) {
    final String[] filePaths = path.list();
    for (int i = 0; i < filePaths.length; i++) {
      String filePath = filePaths[i];
      gcl.addClasspath(filePath);
    }
  }
  return gcl;
}

代码示例来源:origin: org.apache.ant/ant

private void collectFileListFromModulePath() {
  final FileUtils fu = FileUtils.getFileUtils();
  for (String pathElement : moduleSourcepath.list()) {
    boolean valid = false;
    for (Map.Entry<String, Collection<File>> modules : resolveModuleSourcePathElement(
      getProject().getBaseDir(), pathElement).entrySet()) {
      final String moduleName = modules.getKey();
      for (File srcDir : modules.getValue()) {
        if (srcDir.exists()) {
          valid = true;
          final DirectoryScanner ds = getDirectoryScanner(srcDir);
          final String[] files = ds.getIncludedFiles();
          scanDir(srcDir, fu.resolveFile(destDir, moduleName), files);
        }
      }
    }
    if (!valid) {
      throw new BuildException("modulesourcepath \""
                   + pathElement
                   + "\" does not exist!", getLocation());
    }
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Returns all path elements defined by this and nested path objects.
 * @return list of path elements.
 */
public String[] list() {
  if (isReference()) {
    return ((Path) getCheckedRef()).list();
  }
  return assertFilesystemOnly(union) == null
    ? new String[0] : union.list();
}

代码示例来源:origin: spotbugs/spotbugs

/**
 * Check that all required attributes have been set.
 */
protected void checkParameters() {
  if (homeDir == null && classpath == null) {
    throw new BuildException("either home attribute or " + "classpath attributes "
        + " must be defined for task <" + getTaskName() + "/>", getLocation());
  }
  if (pluginList != null) {
    // Make sure that all plugins are actually Jar files.
    String[] pluginFileList = pluginList.list();
    for (String pluginFile : pluginFileList) {
      if (!pluginFile.endsWith(".jar")) {
        throw new BuildException("plugin file " + pluginFile + " is not a Jar file " + "in task <" + getTaskName()
        + "/>", getLocation());
      }
    }
  }
  for (SystemProperty systemProperty : systemPropertyList) {
    if (systemProperty.getName() == null || systemProperty.getValue() == null) {
      throw new BuildException("systemProperty elements must have name and value attributes");
    }
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Emulation of extdirs feature in Java &gt;= 1.2.
 * This method adds all files in the given
 * directories (but not in sub-directories!) to the classpath,
 * so that you don't have to specify them all one by one.
 * @param extdirs - Path to append files to
 */
public void addExtdirs(Path extdirs) {
  if (extdirs == null) {
    String extProp = System.getProperty("java.ext.dirs");
    if (extProp != null) {
      extdirs = new Path(getProject(), extProp);
    } else {
      return;
    }
  }
  for (String d : extdirs.list()) {
    File dir = resolveFile(getProject(), d);
    if (dir.exists() && dir.isDirectory()) {
      FileSet fs = new FileSet();
      fs.setDir(dir);
      fs.setIncludes("*");
      addFileset(fs);
    }
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Fulfill the ResourceCollection contract. The Iterator returned
 * will throw ConcurrentModificationExceptions if ResourceCollections
 * are added to this container while the Iterator is in use.
 * @return a "fail-fast" Iterator.
 */
@Override
public final synchronized Iterator<Resource> iterator() {
  if (isReference()) {
    return ((Path) getCheckedRef()).iterator();
  }
  dieOnCircularReference();
  if (getPreserveBC()) {
    return new FileResourceIterator(getProject(), null, list());
  }
  return union == null ? Collections.<Resource> emptySet().iterator()
    : assertFilesystemOnly(union).iterator();
}

代码示例来源:origin: apache/groovy

String[] list = src.list();
for (int i = 0; i < list.length; i++) {
  File basedir = getProject().resolveFile(list[i]);

代码示例来源:origin: org.apache.ant/ant

/**
 * Execute the task.
 * @throws BuildException if errors occur.
 */
@Override
public void execute() throws BuildException {
  if (sources == null) {
   throw new BuildException(
     "At least one set of source resources must be specified");
  }
  if (targets == null) {
   throw new BuildException(
     "At least one set of target files must be specified");
  }
  //no sources = nothing to compare; no targets = nothing to delete:
  if (!sources.isEmpty() && !targets.isEmpty() && !uptodate(sources, targets)) {
    log("Deleting all target files.", Project.MSG_VERBOSE);
    if (verbose) {
      for (String t : targets.list()) {
        log("Deleting " + t);
      }
    }
    Delete delete = new Delete();
    delete.bindToOwner(this);
    delete.add(targets);
    delete.perform();
  }
}

代码示例来源:origin: checkstyle/checkstyle

/** This test is created to satisfy pitest, it is hard to emulate Reference by Id. */
@Test
public void testSetClasspathRef1() {
  final CheckstyleAntTask antTask = new CheckstyleAntTask();
  final Project project = new Project();
  antTask.setClasspath(new Path(project, "firstPath"));
  antTask.setClasspathRef(new Reference(project, "idXX"));
  try {
    assertNotNull("Classpath should not be null",
        Whitebox.getInternalState(antTask, "classpath"));
    final Path classpath = Whitebox.getInternalState(antTask, "classpath");
    classpath.list();
    fail("Exception is expected");
  }
  catch (BuildException ex) {
    assertEquals("unexpected exception message",
        "Reference idXX not found.", ex.getMessage());
  }
}

相关文章