org.apache.tools.ant.Project类的使用及代码示例

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

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

Project介绍

[英]Central representation of an Ant project. This class defines an Ant project with all of its targets, tasks and various other properties. It also provides the mechanism to kick off a build using a particular target name.

This class also encapsulates methods which allow files to be referred to using abstract path names which are translated to native system file paths at runtime.
[中]蚂蚁项目的中心表示。此类定义了一个Ant项目及其所有目标、任务和各种其他属性。它还提供了使用特定目标名称启动构建的机制。
此类还封装了一些方法,这些方法允许使用抽象路径名引用文件,这些抽象路径名在运行时被转换为本机系统文件路径。

代码示例

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

private static void parseClassPath(Manifest manifest, File archive, List<File> paths, String attributeName, String separator) throws IOException {
  String classPath = manifest.getMainAttributes().getValue(attributeName);
  if(classPath==null) return; // attribute not found
  for (String s : classPath.split(separator)) {
    File file = resolve(archive, s);
    if(file.getName().contains("*")) {
      // handle wildcard
      FileSet fs = new FileSet();
      File dir = file.getParentFile();
      fs.setDir(dir);
      fs.setIncludes(file.getName());
      for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) {
        paths.add(new File(dir,included));
      }
    } else {
      if(!file.exists())
        throw new IOException("No such file: "+file);
      paths.add(file);
    }
  }
}

代码示例来源:origin: org.testng/testng

/** Executes the target, if any, that user designates executing before failing the test */
private void executeHaltTarget(int exitValue) {
 if(m_onHaltTarget != null) {
  if(m_outputDir != null) {
   getProject().setProperty("testng.outputdir", m_outputDir.getAbsolutePath());
  }
  getProject().setProperty("testng.returncode", String.valueOf(exitValue));
  Target t= getProject().getTargets().get(m_onHaltTarget);
  if(t != null) {
   t.execute();
  }
 }
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * @return Factory method to create new Project instances
 */
@SuppressWarnings("unchecked")
protected static Project createAntProject() {
  final Project project = new Project();
  final ProjectHelper helper = ProjectHelper.getProjectHelper();
  project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
  helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty
  addMicronautConsoleBuildListener(project);
  project.init();
  project.getBaseDir();
  return project;
}

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

/**
 * Prints the description of a project (if there is one) to
 * <code>System.out</code>.
 *
 * @param project The project to display a description of.
 *                Must not be <code>null</code>.
 */
private static void printDescription(final Project project) {
  if (project.getDescription() != null) {
   project.log(project.getDescription());
  }
}

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

public synchronized Object get(Object key) {
  return project.getProperties().get(key);
}

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

Commandline commandLine = new Commandline();
Project aProj = getProject();
  setViewPath(aProj.getBaseDir().getPath());
commandLine.setExecutable(getClearToolCommand());
commandLine.createArgument().setValue(COMMAND_UNCHECKOUT);
  getProject().log("Ignoring any errors that occur for: "
      + getViewPathBasename(), Project.MSG_VERBOSE);
if (Execute.isFailure(result) && getFailOnErr()) {
  throw new BuildException("Failed executing: " + commandLine,
    getLocation());

代码示例来源: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

/**
 * Run the command.
 * @param cmd the command line to use.
 * @param out the output stream handler to use.
 * @return the exit code of the command.
 */
protected int runCmd(Commandline cmd, ExecuteStreamHandler out) {
  try {
    Project aProj = getProject();
    Execute exe = new Execute(out);
    exe.setAntRun(aProj);
    exe.setWorkingDirectory(aProj.getBaseDir());
    exe.setCommandline(cmd.getCommandline());
    return exe.execute();
  } catch (IOException e) {
    String msg = "Failed executing: " + cmd.toString()
      + ". Exception: " + e.getMessage();
    throw new BuildException(msg, getLocation());
  }
}

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

if (StringUtils.isNotBlank(ruleSets)) {
    configuration.setRuleSets(project.replaceProperties(ruleSets));
  throw new BuildException(e.getMessage(), e);
  project.log("Setting suppress marker to be " + configuration.getSuppressMarker(), Project.MSG_VERBOSE);
  project.log("Sending a report to " + formatter, Project.MSG_VERBOSE);
  formatter.start(project.getBaseDir().toString());
  DirectoryScanner ds = fs.getDirectoryScanner(project);
  String[] srcFiles = ds.getIncludedFiles();
  for (String srcFile : srcFiles) {
    File file = new File(ds.getBasedir() + separator + srcFile);
    files.add(new FileDataSource(file));
  final String inputPaths = ds.getBasedir().getPath();
  configuration.setInputPaths(inputPaths);
project.log(problemCount + " problems found", Project.MSG_VERBOSE);
  project.setProperty(failuresPropertyName, String.valueOf(problemCount));
  project.log("Setting property " + failuresPropertyName + " to " + problemCount, Project.MSG_VERBOSE);
  throw new BuildException("Stopping build since PMD found " + problemCount + " rule violations in the code");

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

public synchronized boolean containsKey(Object key) {
  return project.getProperties().containsKey(key);
}

代码示例来源: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: jenkinsci/jenkins

/**
 * Runs Ant glob expansion.
 *
 * @return
 *      A set of relative file names from the base directory.
 */
@Nonnull
private static String[] glob(File dir, String includes, String excludes, boolean defaultExcludes) throws IOException {
  if(isAbsolute(includes))
    throw new IOException("Expecting Ant GLOB pattern, but saw '"+includes+"'. See http://ant.apache.org/manual/Types/fileset.html for syntax");
  FileSet fs = Util.createFileSet(dir,includes,excludes);
  fs.setDefaultexcludes(defaultExcludes);
  DirectoryScanner ds;
  try {
    ds = fs.getDirectoryScanner(new Project());
  } catch (BuildException x) {
    throw new IOException(x.getMessage());
  }
  String[] files = ds.getIncludedFiles();
  return files;
}

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

toExecute.createArgument().setValue("-tag");
      toExecute.createArgument().setValue(ta.getParameter());
    } else {
      for (String file : tagDefScanner.getIncludedFiles()) {
        final File tagDefFile = new File(tagDir, file);
        try (final BufferedReader in = new BufferedReader(
            new FileReader(tagDefFile))) {
          in.lines().forEach(line -> {
            toExecute.createArgument().setValue("-tag");
            toExecute.createArgument().setValue(line);
          });
        } catch (final IOException ioe) {
          throw new BuildException("Couldn't read tag file from "
              + tagDefFile.getAbsolutePath(), ioe);
    if (tagletInfo.getPath() != null) {
      final Path tagletPath = tagletInfo.getPath()
        .concatSystemClasspath("ignore");
      if (!tagletPath.isEmpty()) {
        toExecute.createArgument()
          .setValue("-tagletpath");
  : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE);
if (sourceArg != null) {
  toExecute.createArgument().setValue("-source");

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

BufferedWriter out = null;
  try {
    tmpFile = FileUtils.getFileUtils().createTempFile("jikes",
        "tmp", null, false, true);
    out = new BufferedWriter(new FileWriter(tmpFile));
                  "@" + tmpFile.getAbsolutePath()};
  } catch (IOException e) {
    throw new BuildException("Error creating temporary file",
                 e);
  } finally {
    FileUtils.close(out);
  Execute exe = new Execute(jop);
  exe.setAntRun(project);
  exe.setWorkingDirectory(project.getBaseDir());
  exe.setCommandline(commandArray);
  exe.execute();
} catch (IOException e) {
  throw new BuildException("Error running Jikes compiler", e);

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

srcDir = getProject().resolveFile(".");
  throw new BuildException("The dest attribute must be set.");
  throw new BuildException(
    "The ext attribute or a mapper must be set if src and dest dirs are the same.");
files = scanner.getIncludedFiles();
SourceFileScanner sfs = new SourceFileScanner(this);
files = sfs.restrict(files, srcDir, destDir, m);

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

validate();
if (classpath != null) {
  classpath = classpath.concatSystemClasspath("ignore");
  getProject().log("using user supplied classpath: " + classpath,
           Project.MSG_DEBUG);
} else {
  classpath = new Path(getProject());
  classpath = classpath.concatSystemClasspath("only");
  getProject().log("using system classpath: " + classpath,
           Project.MSG_DEBUG);
   AntClassLoader.newAntClassLoader(getProject().getCoreLoader(),
                   getProject(),
                   classpath, false)) {
    throw new BuildException("One of class or resource is required");
    getProject().setNewProperty(property, loc);

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

private void scan(String pattern) {
  LOGGER.fine("Scanning "+pattern+" for hs_err_pid files");
  pattern = pattern.replace("%p","*").replace("%%","%");
  File f = new File(pattern).getAbsoluteFile();
  if (!pattern.contains("*"))
    scanFile(f);
  else {// GLOB
    File commonParent = f;
    while (commonParent!=null && commonParent.getPath().contains("*")) {
      commonParent = commonParent.getParentFile();
    }
    if (commonParent==null) {
      LOGGER.warning("Failed to process "+f);
      return; // huh?
    }
    FileSet fs = Util.createFileSet(commonParent, f.getPath().substring(commonParent.getPath().length()+1), null);
    DirectoryScanner ds = fs.getDirectoryScanner(new Project());
    for (String child : ds.getIncludedFiles()) {
      scanFile(new File(commonParent,child));
    }
  }
}

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

/**
 * @return true if the property exists
 * @exception BuildException if the property attribute is not set
 */
@Override
public boolean eval() throws BuildException {
  if (property == null) {
    throw new BuildException(
      "No property specified for isset condition");
  }
  return getProject().getProperty(property) != null;
}

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

private void setupClassLoader() {
  try {
    if (auxClasspath != null) {
      project.log("Using auxclasspath: " + auxClasspath, Project.MSG_VERBOSE);
      configuration.prependClasspath(auxClasspath.toString());
    }
  } catch (IOException ioe) {
    throw new BuildException(ioe.getMessage(), ioe);
  }
}

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

fs.setCaseSensitive(caseSensitive);
DirectoryScanner ds = fs.getDirectoryScanner(new Project());
if(ds.getIncludedFilesCount()!=0) {
  String[] names = ds.getIncludedFiles();
  Arrays.sort(names,SHORTER_STRING_FIRST);
  for( String f : names) {

相关文章