Java 类org.apache.tools.ant.util.StringUtils 实例源码

项目:kawa-mirror    文件:Kawac.java   
/**
 * Add the file names to the Commandline. Log them in verbose mode.
 * @param cmd the Commandline to be executed
 */
private void logAndAddFilesToCompile(Commandline cmd) {
  log("Compilation " + cmd.describeArguments(),
      Project.MSG_VERBOSE);

  StringBuffer niceSourceList = new StringBuffer("File");
  if (compileList.length != 1) {
    niceSourceList.append("s");
  }
  niceSourceList.append(" to be compiled:");
  niceSourceList.append(StringUtils.LINE_SEP);

  for (int i = 0; i < compileList.length; i++) {
    String arg = compileList[i].getAbsolutePath();
    cmd.createArgument().setValue(arg);
    niceSourceList.append("    ");
    niceSourceList.append(arg);
    niceSourceList.append(StringUtils.LINE_SEP);
  }
  log(niceSourceList.toString(), Project.MSG_VERBOSE);
}
项目:kawa-fork    文件:Kawac.java   
/**
 * Add the file names to the Commandline. Log them in verbose mode.
 * @param cmd the Commandline to be executed
 */
private void logAndAddFilesToCompile(Commandline cmd) {
  log("Compilation " + cmd.describeArguments(),
      Project.MSG_VERBOSE);

  StringBuffer niceSourceList = new StringBuffer("File");
  if (compileList.length != 1) {
    niceSourceList.append("s");
  }
  niceSourceList.append(" to be compiled:");
  niceSourceList.append(StringUtils.LINE_SEP);

  for (int i = 0; i < compileList.length; i++) {
    String arg = compileList[i].getAbsolutePath();
    cmd.createArgument().setValue(arg);
    niceSourceList.append("    ");
    niceSourceList.append(arg);
    niceSourceList.append(StringUtils.LINE_SEP);
  }
  log(niceSourceList.toString(), Project.MSG_VERBOSE);
}
项目:ai2-kawa    文件:Kawac.java   
/**
 * Add the file names to the Commandline. Log them in verbose mode.
 * @param cmd the Commandline to be executed
 */
private void logAndAddFilesToCompile(Commandline cmd) {
  log("Compilation " + cmd.describeArguments(),
      Project.MSG_VERBOSE);

  StringBuffer niceSourceList = new StringBuffer("File");
  if (compileList.length != 1) {
    niceSourceList.append("s");
  }
  niceSourceList.append(" to be compiled:");
  niceSourceList.append(StringUtils.LINE_SEP);

  for (int i = 0; i < compileList.length; i++) {
    String arg = compileList[i].getAbsolutePath();
    cmd.createArgument().setValue(arg);
    niceSourceList.append("    ");
    niceSourceList.append(arg);
    niceSourceList.append(StringUtils.LINE_SEP);
  }
  log(niceSourceList.toString(), Project.MSG_VERBOSE);
}
项目:scylla-tools-java    文件:CassandraBriefJUnitResultFormatter.java   
/**
 * The whole testsuite started.
 * @param suite the test suite
 */
public void startTestSuite(JUnitTest suite) {
    if (output == null) {
        return; // Quick return - no output do nothing.
    }
    StringBuffer sb = new StringBuffer("Testsuite: ");
    String n = suite.getName();
    if (n != null && !tag.isEmpty())
        n = n + "-" + tag;
    sb.append(n);
    sb.append(StringUtils.LINE_SEP);
    try {
        output.write(sb.toString());
        output.flush();
    } catch (IOException ex) {
        throw new BuildException(ex);
    }
}
项目:kawa    文件:Kawac.java   
/**
 * Add the file names to the Commandline. Log them in verbose mode.
 * @param cmd the Commandline to be executed
 */
private void logAndAddFilesToCompile(Commandline cmd) {
  log("Compilation " + cmd.describeArguments(),
      Project.MSG_VERBOSE);

  StringBuffer niceSourceList = new StringBuffer("File");
  if (compileList.length != 1) {
    niceSourceList.append("s");
  }
  niceSourceList.append(" to be compiled:");
  niceSourceList.append(StringUtils.LINE_SEP);

  for (int i = 0; i < compileList.length; i++) {
    String arg = compileList[i].getAbsolutePath();
    cmd.createArgument().setValue(arg);
    niceSourceList.append("    ");
    niceSourceList.append(arg);
    niceSourceList.append(StringUtils.LINE_SEP);
  }
  log(niceSourceList.toString(), Project.MSG_VERBOSE);
}
项目:ant    文件:BigProjectLogger.java   
/**
 * {@inheritDoc}
 *
 * @param event An event with any relevant extra information. Must not be <code>null</code>.
 */
public void subBuildStarted(BuildEvent event) {
    String name = extractNameOrDefault(event);
    Project project = event.getProject();

    File base = project == null ? null : project.getBaseDir();
    String path =
        (base == null)
        ? "With no base directory"
        : "In " + base.getAbsolutePath();
    printMessage(StringUtils.LINE_SEP + getHeader()
            + StringUtils.LINE_SEP + "Entering project " + name
                    + StringUtils.LINE_SEP + path
                    + StringUtils.LINE_SEP + getFooter(),
            out,
            event.getPriority());
}
项目:ant    文件:NoBannerLogger.java   
/**
 * Logs a message for a target if it is of an appropriate
 * priority, also logging the name of the target if this
 * is the first message which needs to be logged for the
 * target.
 *
 * @param event A BuildEvent containing message information.
 *              Must not be <code>null</code>.
 */
public void messageLogged(BuildEvent event) {

    if (event.getPriority() > msgOutputLevel
        || null == event.getMessage()
        || "".equals(event.getMessage().trim())) {
            return;
    }

    synchronized (this) {
        if (null != targetName) {
            out.println(StringUtils.LINE_SEP + targetName + ":");
            targetName = null;
        }
    }

    super.messageLogged(event);
}
项目:ant    文件:Commandline.java   
/**
 * Return a String that describes the arguments suitable for
 * verbose output before a call to <code>Runtime.exec(String[])</code>.
 *
 * @param args the command line to describe as an array of strings.
 * @param offset ignore entries before this index.
 * @return a string that describes the arguments
 *
 * @since Ant 1.5
 */
protected static String describeArguments(String[] args, int offset) {
    if (args == null || args.length <= offset) {
        return "";
    }
    StringBuilder buf = new StringBuilder("argument");
    if (args.length > offset) {
        buf.append("s");
    }
    buf.append(":").append(StringUtils.LINE_SEP);
    for (int i = offset; i < args.length; i++) {
        buf.append("\'").append(args[i]).append("\'")
            .append(StringUtils.LINE_SEP);
    }
    buf.append(DISCLAIMER);
    return buf.toString();
}
项目:ant    文件:DefaultLogger.java   
static void throwableMessage(StringBuffer m, Throwable error, boolean verbose) {
    while (error instanceof BuildException) { // #43398
        Throwable cause = error.getCause();
        if (cause == null) {
            break;
        }
        String msg1 = error.toString();
        String msg2 = cause.toString();
        if (msg1.endsWith(msg2)) {
            m.append(msg1.substring(0, msg1.length() - msg2.length()));
            error = cause;
        } else {
            break;
        }
    }
    if (verbose || !(error instanceof BuildException)) {
        m.append(StringUtils.getStackTrace(error));
    } else {
        m.append(error).append(lSep);
    }
}
项目:ant    文件:DefaultLogger.java   
/**
 * Prints whether the build succeeded or failed,
 * any errors the occurred during the build, and
 * how long the build took.
 *
 * @param event An event with any relevant extra information.
 *              Must not be <code>null</code>.
 */
public void buildFinished(BuildEvent event) {
    Throwable error = event.getException();
    StringBuffer message = new StringBuffer();
    if (error == null) {
        message.append(StringUtils.LINE_SEP);
        message.append(getBuildSuccessfulMessage());
    } else {
        message.append(StringUtils.LINE_SEP);
        message.append(getBuildFailedMessage());
        message.append(StringUtils.LINE_SEP);
        throwableMessage(message, error, Project.MSG_VERBOSE <= msgOutputLevel);
    }
    message.append(StringUtils.LINE_SEP);
    message.append("Total time: ");
    message.append(formatTime(System.currentTimeMillis() - startTime));

    String msg = message.toString();
    if (error == null) {
        printMessage(msg, out, Project.MSG_VERBOSE);
    } else {
        printMessage(msg, err, Project.MSG_ERR);
    }
    log(msg);
}
项目:ant    文件:RecorderEntry.java   
/**
 * @see org.apache.tools.ant.BuildListener#buildFinished(BuildEvent)
 * {@inheritDoc}.
 */
public void buildFinished(BuildEvent event) {
    log("< BUILD FINISHED", Project.MSG_DEBUG);

    if (record && out != null) {
        Throwable error = event.getException();

        if (error == null) {
            out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL");
        } else {
            out.println(StringUtils.LINE_SEP + "BUILD FAILED"
                        + StringUtils.LINE_SEP);
            error.printStackTrace(out); //NOSONAR
        }
    }
    cleanup();
}
项目:ant    文件:Redirector.java   
/**
 * Set a property from a ByteArrayOutputStream
 *
 * @param baos
 *            contains the property value.
 * @param propertyName
 *            the property name.
 *
 * @exception IOException
 *                if the value cannot be read form the stream.
 */
private void setPropertyFromBAOS(final ByteArrayOutputStream baos,
        final String propertyName) throws IOException {

    final BufferedReader in = new BufferedReader(new StringReader(Execute
            .toString(baos)));
    String line = null;
    final StringBuffer val = new StringBuffer();
    while ((line = in.readLine()) != null) {
        if (val.length() != 0) {
            val.append(StringUtils.LINE_SEP);
        }
        val.append(line);
    }
    managingTask.getProject().setNewProperty(propertyName, val.toString());
}
项目:ant    文件:FailureRecorder.java   
private void writeJavaClass() {
    try {
        File sourceFile = new File(getLocationName() + ".java");
        verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'");

        if (sourceFile.exists() && !sourceFile.delete()) {
            throw new IOException("could not delete " + sourceFile);
        }
        writer = new BufferedWriter(new FileWriter(sourceFile));

        createClassHeader();
        createSuiteMethod();
        createClassFooter();

    } catch (IOException e) {
        log(StringUtils.getStackTrace(e));
    } finally {
        FileUtils.close(writer);
    }
}
项目:ant    文件:CCMCreateTask.java   
/**
 * read the output stream to retrieve the new task number.
 * @param is InputStream
 * @throws IOException on error
 */
@Override
public void setProcessOutputStream(InputStream is) throws IOException {
    try (BufferedReader reader =
        new BufferedReader(new InputStreamReader(is))) {
        String buffer = reader.readLine();
        if (buffer != null) {
            log("buffer:" + buffer, Project.MSG_DEBUG);
            String taskstring = buffer.substring(buffer.indexOf(' ')).trim();
            taskstring = taskstring.substring(0, taskstring.lastIndexOf(' ')).trim();
            setTask(taskstring);
            log("task is " + getTask(), Project.MSG_DEBUG);
        }
    } catch (NullPointerException npe) {
        log("error procession stream, null pointer exception", Project.MSG_ERR);
        log(StringUtils.getStackTrace(npe), Project.MSG_ERR);
        throw new BuildException(npe);
    } catch (Exception e) {
        log("error procession stream " + e.getMessage(), Project.MSG_ERR);
        throw new BuildException(e.getMessage());
    }

}
项目:ant    文件:Javah.java   
/**
 * Logs the compilation parameters, adds the files to compile and logs the
 * &quot;niceSourceList&quot;
 * @param cmd the command line to add parameters to.
 */
protected void logAndAddFilesToCompile(Commandline cmd) {
    log("Compilation " + cmd.describeArguments(),
        Project.MSG_VERBOSE);

    String[] c = getClasses();
    StringBuilder message = new StringBuilder("Class");
    if (c.length > 1) {
        message.append("es");
    }
    message.append(" to be compiled:");
    message.append(StringUtils.LINE_SEP);
    for (String element : c) {
        cmd.createArgument().setValue(element);
        message.append("    ").append(element).append(StringUtils.LINE_SEP);
    }
    log(message.toString(), Project.MSG_VERBOSE);
}
项目:ant    文件:Concat.java   
/**
 * Reset state to default.
 */
public void reset() {
    append = false;
    forceOverwrite = true;
    dest = null;
    encoding = null;
    outputEncoding = null;
    fixLastLine = false;
    filterChains = null;
    footer = null;
    header = null;
    binary = false;
    outputWriter = null;
    textBuffer = null;
    eolString = StringUtils.LINE_SEP;
    rc = null;
    ignoreEmpty = true;
    force = false;
}
项目:ant    文件:AbstractCvsTask.java   
private String executeToString(Execute execute) {

        String cmdLine = Commandline.describeCommand(execute
                .getCommandline());
        StringBuilder buf = removeCvsPassword(cmdLine);

        String newLine = StringUtils.LINE_SEP;
        String[] variableArray = execute.getEnvironment();

        if (variableArray != null) {
            buf.append(newLine);
            buf.append(newLine);
            buf.append("environment:");
            buf.append(newLine);
            for (int z = 0; z < variableArray.length; z++) {
                buf.append(newLine);
                buf.append("\t");
                buf.append(variableArray[z]);
            }
        }

        return buf.toString();
    }
项目:ant    文件:HasFreeSpace.java   
/**
 * Evaluate the condition.
 * @return true if there enough free space.
 * @throws BuildException if there is a problem.
 */
@Override
public boolean eval() throws BuildException {
    validate();
    try {
        if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) {
            //reflection to avoid bootstrap/build problems
            File fs = new File(partition);
            ReflectWrapper w = new ReflectWrapper(fs);
            long free = w.<Long> invoke("getFreeSpace").longValue();
            return free >= StringUtils.parseHumanSizes(needed);
        }
        throw new BuildException(
            "HasFreeSpace condition not supported on Java5 or less.");
    } catch (Exception e) {
        throw new BuildException(e);
    }
}
项目:ant    文件:XSLTProcess.java   
/**
 * Get the Liaison implementation to use in processing.
 *
 * @return an instance of the XSLTLiaison interface.
 */
protected XSLTLiaison getLiaison() {
    // if processor wasn't specified, use TraX.
    if (liaison == null) {
        if (processor != null) {
            try {
                resolveProcessor(processor);
            } catch (final Exception e) {
                handleError(e);
            }
        } else {
            try {
                resolveProcessor(PROCESSOR_TRAX);
            } catch (final Throwable e1) {
                log(StringUtils.getStackTrace(e1), Project.MSG_ERR);
                handleError(e1);
            }
        }
    }
    return liaison;
}
项目:ant    文件:ModifiedSelectorTest.java   
public void writeProperties(String line) {
    if (!isConfigured) {
        setUp();
    }
    File dir = getProject().getBaseDir();
    File file = new File(dir, propfile);
    try {
        FileWriter out = new FileWriter(file.getAbsolutePath(), true);
        out.write(line);
        out.write(StringUtils.LINE_SEP);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:ant-easyant-core    文件:MetaBuildExecutor.java   
private void printSubBuildsInOrder(Project project) {
    // print all sub modules and order in which they will
    // be executed
    String sortedModules = project.getProperty("ivy.sorted.modules");
    if (sortedModules != null && !sortedModules.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        sb.append(DEMARKER).append(StringUtils.LINE_SEP);
        sb.append("Build Order for Sub Modules").append(StringUtils.LINE_SEP);
        sb.append(DEMARKER).append(StringUtils.LINE_SEP);
        String[] subModules = sortedModules.split("\\,");
        for (String subModule : subModules) {
            sb.append(" * ").append(subModule.trim()).append(StringUtils.LINE_SEP);
        }
        sb.append(DEMARKER);
        project.log(sb.toString());
    }
}
项目:ant-easyant-tasks    文件:DebugPrompt.java   
public void prompt(String message) {
    InputRequest ir = new InputRequest("Debugger> ");
    InputHandler ih = new DefaultInputHandler();
    String command = null;
    project.log(StringUtils.LINE_SEP
            + "-------- Ant Command Line Debugger --------"
            + StringUtils.LINE_SEP + StringUtils.LINE_SEP);

    // print a friendly message to allow the user to understand why this
    // breakpoint occurred
    project.log(message);
    project.log("");
    // keep accepting inputs, until the user enters the return command
    do {
        ih.handleInput(ir);
        command = ir.getInput();
        commandHandler.handleCommand(command);
        project.log(""); // log a new line
    } while (!"return".equals(command));

    // resume build execution on this
    project.log(StringUtils.LINE_SEP
            + "--------- Resuming Ant Execution ----------"
            + StringUtils.LINE_SEP);
}
项目:datasource    文件:OntologyUtil.java   
public String getLabel(OWLClass cls) {
    Set<OWLAnnotation> annotations = cls.getAnnotations(ont);
    for (OWLAnnotation annotation : annotations) {
        if (annotation.getProperty().isLabel()) {
            String s = annotation.getValue().toString();
            s = StringUtils.removePrefix(s, "\"");
            s = StringUtils.removeSuffix(s, "\"^^xsd:string");
            return s;
        }
    }

    return null;
}
项目:datasource    文件:OntologyUtil.java   
public String getNamespace(OWLClass cls) {
    Set<OWLAnnotation> annotations = cls.getAnnotations(ont);
    for (OWLAnnotation annotation : annotations) {
        String propertyUri = getAnnotationPropertyUri(annotation);
        if (propertyUri.equals(NAMESPACE_PROP_ALT) || propertyUri.equals(NAMESPACE_PROP)) {
            String s = annotation.getValue().toString();
            s = StringUtils.removePrefix(s, "\"");
            s = StringUtils.removeSuffix(s, "\"^^xsd:string");
            return s;
        }
    }

    return null;
}
项目:ant    文件:ProfileLogger.java   
private void logFinish(BuildEvent event, Date start, String name) {
    Date now = new Date();
    String msg;
    if (start != null) {
        long diff = now.getTime() - start.getTime();
        msg = StringUtils.LINE_SEP + name + ": finished " + now + " ("
                + diff + "ms)";
    } else {
        msg = StringUtils.LINE_SEP + name + ": finished " + now
                + " (unknown duration, start not detected)";
    }
    printMessage(msg, out, event.getPriority());
    log(msg);
}
项目:ant    文件:BigProjectLogger.java   
/** {@inheritDoc} */
public void subBuildFinished(BuildEvent event) {
    String name = extractNameOrDefault(event);
    String failed = event.getException() != null ? "failing " : "";
    printMessage(StringUtils.LINE_SEP + getHeader()
            + StringUtils.LINE_SEP + "Exiting " + failed + "project "
            + name
            + StringUtils.LINE_SEP + getFooter(),
            out,
            event.getPriority());
}
项目:ant    文件:ClassfileSet.java   
/**
 * Return the DirectoryScanner associated with this FileSet.
 *
 * @param p the project used to resolve dirs, etc.
 *
 * @return a dependency scanner.
 */
@Override
public DirectoryScanner getDirectoryScanner(Project p) {
    if (isReference()) {
        return getRef(p).getDirectoryScanner(p);
    }
    dieOnCircularReference(p);
    DirectoryScanner parentScanner = super.getDirectoryScanner(p);
    DependScanner scanner = new DependScanner(parentScanner);
    final Vector<String> allRootClasses = new Vector<>(rootClasses);
    for (FileSet additionalRootSet : rootFileSets) {
        DirectoryScanner additionalScanner
            = additionalRootSet.getDirectoryScanner(p);
        String[] files = additionalScanner.getIncludedFiles();
        for (int i = 0; i < files.length; ++i) {
            if (files[i].endsWith(".class")) {
                String classFilePath = StringUtils.removeSuffix(files[i], ".class");
                String className
                    = classFilePath.replace('/', '.').replace('\\', '.');
                allRootClasses.addElement(className);
            }
        }
        scanner.addBasedir(additionalRootSet.getDir(p));
    }
    scanner.setBasedir(getDir(p));
    scanner.setRootClasses(allRootClasses);
    scanner.scan();
    return scanner;
}
项目:ant    文件:DefaultLogger.java   
/**
 * Logs a message to say that the target has started if this
 * logger allows information-level messages.
 *
 * @param event An event with any relevant extra information.
 *              Must not be <code>null</code>.
  */
public void targetStarted(BuildEvent event) {
    if (Project.MSG_INFO <= msgOutputLevel
        && !event.getTarget().getName().equals("")) {
        String msg = StringUtils.LINE_SEP
            + event.getTarget().getName() + ":";
        printMessage(msg, out, event.getPriority());
        log(msg);
    }
}
项目:ant    文件:Project.java   
/**
 * Send a &quot;message logged&quot; event to the build listeners
 * for this project.
 *
 * @param event    The event to send. This should be built up with the
 *                 appropriate task/target/project by the caller, so that
 *                 this method can set the message and priority, then send
 *                 the event. Must not be <code>null</code>.
 * @param message  The message to send. Should not be <code>null</code>.
 * @param priority The priority of the message.
 */
private void fireMessageLoggedEvent(final BuildEvent event, String message,
                                    final int priority) {

    if (message == null) {
        message = String.valueOf(message);
    }
    if (message.endsWith(StringUtils.LINE_SEP)) {
        final int endIndex = message.length() - StringUtils.LINE_SEP.length();
        event.setMessage(message.substring(0, endIndex), priority);
    } else {
        event.setMessage(message, priority);
    }
    if (isLoggingMessage.get() != Boolean.FALSE) {
        /*
         * One of the Listeners has attempted to access
         * System.err or System.out.
         *
         * We used to throw an exception in this case, but
         * sometimes Listeners can't prevent it(like our own
         * Log4jListener which invokes getLogger() which in
         * turn wants to write to the console).
         *
         * @see http://marc.theaimsgroup.com/?t=110538624200006&r=1&w=2
         *
         * We now (Ant 1.6.3 and later) simply swallow the message.
         */
        return;
    }
    try {
        isLoggingMessage.set(Boolean.TRUE);
        final BuildListener[] currListeners = listeners;
        for (int i = 0; i < currListeners.length; i++) {
            currListeners[i].messageLogged(event);
        }
    } finally {
        isLoggingMessage.set(Boolean.FALSE);
    }
}
项目:ant    文件:Echo.java   
/**
 * Does the work.
 *
 * @exception BuildException if something goes wrong with the build
 */
public void execute() throws BuildException {
    final String msg = "".equals(message) ? StringUtils.LINE_SEP : message;
    try {
        ResourceUtils
                .copyResource(new StringResource(msg), output == null
                              ? new LogOutputResource(this, logLevel)
                              : output,
                              null, null, false, false, append, null,
                              "".equals(encoding) ? null : encoding,
                              getProject(), force);
    } catch (IOException ioe) {
        throw new BuildException(ioe, getLocation());
    }
}
项目:ant    文件:RecorderEntry.java   
/**
 * @see org.apache.tools.ant.BuildListener#targetStarted(BuildEvent)
 * {@inheritDoc}.
 */
public void targetStarted(BuildEvent event) {
    log(">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG);
    log(StringUtils.LINE_SEP + event.getTarget().getName() + ":",
        Project.MSG_INFO);
    targetStartTime = System.currentTimeMillis();
}
项目:ant    文件:BriefJUnitResultFormatter.java   
/**
 * The whole testsuite started.
 * @param suite the test suite
 */
@Override
public void startTestSuite(JUnitTest suite) {
    if (output == null) {
        return; // Quick return - no output do nothing.
    }
    try {
        output
            .write(new StringBuilder("Testsuite: ").append(suite.getName())
                .append(StringUtils.LINE_SEP).toString());
        output.flush();
    } catch (IOException ex) {
        throw new BuildException(ex);
    }
}
项目:ant    文件:PlainJUnitResultFormatter.java   
/**
 * The whole testsuite started.
 * @param suite the test suite
 * @throws BuildException if unable to write the output
 */
@Override
public void startTestSuite(JUnitTest suite) throws BuildException {
    if (out == null) {
        return; // Quick return - no output do nothing.
    }
    try {
        out.write(new StringBuilder("Testsuite: ").append(suite.getName())
            .append(StringUtils.LINE_SEP).toString().getBytes());
        out.flush();
    } catch (IOException ex) {
        throw new BuildException("Unable to write output", ex);
    }
}
项目:ant    文件:Image.java   
/**
 * Executes the Task.
 * @throws BuildException on error.
 */
@Override
public void execute() throws BuildException {

    validateAttributes();

    try {
        File dest = (destDir != null) ? destDir : srcDir;

        int writeCount = 0;

        // build mapper
        final FileNameMapper mapper = mapperElement == null
            ? new IdentityMapper() : mapperElement.getImplementation();

        // deal with specified srcDir
        if (srcDir != null) {
            writeCount += processDir(srcDir,
                super.getDirectoryScanner(srcDir).getIncludedFiles(), dest,
                mapper);
        }
        // deal with the filesets
        for (FileSet fs : filesets) {
            writeCount += processDir(fs.getDir(getProject()),
                fs.getDirectoryScanner(getProject()).getIncludedFiles(),
                dest, mapper);
        }

        if (writeCount > 0) {
            log("Processed " + writeCount + (writeCount == 1 ? " image." : " images."));
        }

    } catch (Exception err) {
        log(StringUtils.getStackTrace(err), Project.MSG_ERR);
        throw new BuildException(err.getMessage());
    }
}
项目:ant    文件:KeySubst.java   
/**
 * Do the execution.
 * @throws BuildException on error
 */
public void execute() throws BuildException {
    log("!! KeySubst is deprecated. Use Filter + Copy instead. !!");
    log("Performing Substitutions");
    if (source == null || dest == null) {
        log("Source and destinations must not be null");
        return;
    }
    BufferedReader br = null;
    BufferedWriter bw = null;
    try {
        br = new BufferedReader(new FileReader(source));
        dest.delete();
        bw = new BufferedWriter(new FileWriter(dest));

        String line = null;
        String newline = null;
        line = br.readLine();
        while (line != null) {
            if (line.length() == 0) {
                bw.newLine();
            } else {
                newline = KeySubst.replace(line, replacements);
                bw.write(newline);
                bw.newLine();
            }
            line = br.readLine();
        }
        bw.flush();
    } catch (IOException ioe) {
        log(StringUtils.getStackTrace(ioe), Project.MSG_ERR);
    } finally {
        FileUtils.close(bw);
        FileUtils.close(br);
    }
}
项目:ant    文件:Available.java   
/**
 * Entry point when operating as a task.
 *
 * @exception BuildException if the task is not configured correctly.
 */
@Override
public void execute() throws BuildException {
    if (property == null) {
        throw new BuildException("property attribute is required",
                                 getLocation());
    }

    isTask = true;
    try {
        if (eval()) {
            PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject());
            Object oldvalue = ph.getProperty(property);
            if (null != oldvalue && !oldvalue.equals(value)) {
                log("DEPRECATED - <available> used to override an existing"
                    + " property."
                    + StringUtils.LINE_SEP
                    + "  Build file should not reuse the same property"
                    + " name for different values.",
                    Project.MSG_WARN);
            }
            // NB: this makes use of Project#setProperty rather than Project#setNewProperty
            //     due to backwards compatibility reasons
            ph.setProperty(property, value, true);
        }
    } finally {
        isTask = false;
    }
}
项目:ant    文件:DefaultExcludes.java   
/**
 * Does the work.
 *
 * @exception BuildException if something goes wrong with the build
 */
@Override
public void execute() throws BuildException {
    if (!defaultrequested && "".equals(add) && "".equals(remove) && !echo) {
        throw new BuildException(
            "<defaultexcludes> task must set at least one attribute (echo=\"false\" doesn't count since that is the default");
    }
    if (defaultrequested) {
        DirectoryScanner.resetDefaultExcludes();
    }
    if (!"".equals(add)) {
        DirectoryScanner.addDefaultExclude(add);
    }
    if (!"".equals(remove)) {
        DirectoryScanner.removeDefaultExclude(remove);
    }
    if (echo) {
        StringBuilder message
            = new StringBuilder("Current Default Excludes:");
        message.append(StringUtils.LINE_SEP);
        for (String exclude : DirectoryScanner.getDefaultExcludes()) {
            message.append("  ");
            message.append(exclude);
            message.append(StringUtils.LINE_SEP);
        }
        log(message.toString(), logLevel);
    }
}
项目:ant    文件:SQLExec.java   
public int lastDelimiterPosition(StringBuffer buf, String currentLine) {
    if (strictDelimiterMatching) {
        if ((delimiterType.equals(DelimiterType.NORMAL)
                && StringUtils.endsWith(buf, delimiter))
                || (delimiterType.equals(DelimiterType.ROW)
                && currentLine.equals(delimiter))) {
            return buf.length() - delimiter.length();
        }
        // no match
        return -1;
    }
    String d = delimiter.trim().toLowerCase(Locale.ENGLISH);
    if (DelimiterType.NORMAL.equals(delimiterType)) {
        // still trying to avoid wasteful copying, see
        // StringUtils.endsWith
        int endIndex = delimiter.length() - 1;
        int bufferIndex = buf.length() - 1;
        while (bufferIndex >= 0 && Character.isWhitespace(buf.charAt(bufferIndex))) {
            --bufferIndex;
        }
        if (bufferIndex < endIndex) {
            return -1;
        }
        while (endIndex >= 0) {
            if (buf.substring(bufferIndex, bufferIndex + 1).toLowerCase(Locale.ENGLISH)
                    .charAt(0) != d.charAt(endIndex)) {
                return -1;
            }
            bufferIndex--;
            endIndex--;
        }
        return bufferIndex + 1;
    }
    return currentLine.trim().toLowerCase(Locale.ENGLISH).equals(d)
        ? buf.length() - currentLine.length() : -1;
}
项目:ant    文件:SetPermissions.java   
@Override
public void execute() {
    if (resources == null) {
        throw new BuildException("At least one resource-collection is required");
    }
    Resource currentResource = null;
    try {
        for (Resource r : resources) {
            currentResource = r;
            try {
                PermissionUtils.setPermissions(r, permissions, this::posixPermissionsNotSupported);
            } catch (IOException ioe) {
                maybeThrowException(ioe, "Failed to set permissions on '%s' due to %s", r, ioe.getMessage());
            }
        }
    } catch (ClassCastException cce) {
        maybeThrowException(null,
            "some specified permissions are not of type PosixFilePermission: %s",
            StringUtils.join(permissions, ", "));
    } catch (SecurityException se) {
        maybeThrowException(null,
            "the SecurityManager denies role accessUserInformation or write access for SecurityManager.checkWrite for resource '%s'",
            currentResource);
    } catch (BuildException be) {
        // maybe thrown by callback method this::posixPermissionsNotSupported.
        maybeThrowException(be, be.getMessage());
    }
}
项目:ant    文件:Rmic.java   
/**
 * Move the generated source file(s) to the base directory
 *
 * @throws org.apache.tools.ant.BuildException When error
 * copying/removing files.
 */
private void moveGeneratedFile(File baseDir, File sourceBaseFile, String classname,
                               RmicAdapter adapter) throws BuildException {
    String classFileName = classname.replace('.', File.separatorChar)
        + ".class";
    String[] generatedFiles = adapter.getMapper().mapFileName(classFileName);

    for (String generatedFile : generatedFiles) {
        if (!generatedFile.endsWith(".class")) {
            // don't know how to handle that - a IDL file doesn't
            // have a corresponding Java source for example.
            continue;
        }
        String sourceFileName =
            StringUtils.removeSuffix(generatedFile, ".class") + ".java";

        File oldFile = new File(baseDir, sourceFileName);
        if (!oldFile.exists()) {
            // no source file generated, nothing to move
            continue;
        }

        File newFile = new File(sourceBaseFile, sourceFileName);
        try {
            if (filtering) {
                FILE_UTILS.copyFile(oldFile, newFile,
                                    new FilterSetCollection(getProject()
                                                            .getGlobalFilterSet()));
            } else {
                FILE_UTILS.copyFile(oldFile, newFile);
            }
            oldFile.delete();
        } catch (IOException ioe) {
            throw new BuildException("Failed to copy " + oldFile + " to "
                + newFile + " due to " + ioe.getMessage(), ioe,
                getLocation());
        }
    }
}