Search in sources :

Example 1 with PropertySet

use of org.apache.tools.ant.types.PropertySet in project ant by apache.

the class EchoProperties method setPrefix.

/**
 * If the prefix is set, then only properties which start with this
 * prefix string will be recorded. If regex is not set and  if this
 * is never set, or it is set to an empty string or <tt>null</tt>,
 * then all properties will be recorded.
 *
 * <p>For example, if the attribute is set as:</p>
 * <pre>&lt;echoproperties  prefix="ant." /&gt;</pre>
 * then the property "ant.home" will be recorded, but "ant-example"
 * will not.
 *
 * @param  prefix  The new prefix value
 */
public void setPrefix(String prefix) {
    if (prefix != null && prefix.length() != 0) {
        this.prefix = prefix;
        PropertySet ps = new PropertySet();
        ps.setProject(getProject());
        ps.appendPrefix(prefix);
        addPropertyset(ps);
    }
}
Also used : PropertySet(org.apache.tools.ant.types.PropertySet)

Example 2 with PropertySet

use of org.apache.tools.ant.types.PropertySet in project ant by apache.

the class EchoProperties method setRegex.

/**
 * If the regex is set, then only properties whose names match it
 * will be recorded.  If prefix is not set and if this is never set,
 * or it is set to an empty string or <tt>null</tt>, then all
 * properties will be recorded.
 *
 * <p>For example, if the attribute is set as:</p>
 * <pre>&lt;echoproperties  prefix=".*ant.*" /&gt;</pre>
 * then the properties "ant.home" and "user.variant" will be recorded,
 * but "ant-example" will not.
 *
 * @param  regex  The new regex value
 *
 * @since Ant 1.7
 */
public void setRegex(String regex) {
    if (regex != null && !regex.isEmpty()) {
        this.regex = regex;
        PropertySet ps = new PropertySet();
        ps.setProject(getProject());
        ps.appendRegex(regex);
        addPropertyset(ps);
    }
}
Also used : PropertySet(org.apache.tools.ant.types.PropertySet)

Example 3 with PropertySet

use of org.apache.tools.ant.types.PropertySet in project ant by apache.

the class Ant method initializeProject.

/**
 * Attaches the build listeners of the current project to the new
 * project, configures a possible logfile, transfers task and
 * data-type definitions, transfers properties (either all or just
 * the ones specified as user properties to the current project,
 * depending on inheritall), transfers the input handler.
 */
private void initializeProject() {
    newProject.setInputHandler(getProject().getInputHandler());
    Iterator<BuildListener> iter = getBuildListeners();
    while (iter.hasNext()) {
        newProject.addBuildListener(iter.next());
    }
    if (output != null) {
        File outfile;
        if (dir != null) {
            outfile = FILE_UTILS.resolveFile(dir, output);
        } else {
            outfile = getProject().resolveFile(output);
        }
        try {
            out = new PrintStream(Files.newOutputStream(outfile.toPath()));
            DefaultLogger logger = new DefaultLogger();
            logger.setMessageOutputLevel(Project.MSG_INFO);
            logger.setOutputPrintStream(out);
            logger.setErrorPrintStream(out);
            newProject.addBuildListener(logger);
        } catch (IOException ex) {
            log("Ant: Can't set output to " + output);
        }
    }
    // set user-defined properties
    if (useNativeBasedir) {
        addAlmostAll(getProject().getUserProperties(), PropertyType.USER);
    } else {
        getProject().copyUserProperties(newProject);
    }
    if (!inheritAll) {
        // set Ant's built-in properties separately,
        // because they are not being inherited.
        newProject.initProperties();
    } else {
        // set all properties from calling project
        addAlmostAll(getProject().getProperties(), PropertyType.PLAIN);
    }
    for (PropertySet ps : propertySets) {
        addAlmostAll(ps.getProperties(), PropertyType.PLAIN);
    }
}
Also used : BuildListener(org.apache.tools.ant.BuildListener) PrintStream(java.io.PrintStream) PropertySet(org.apache.tools.ant.types.PropertySet) IOException(java.io.IOException) File(java.io.File) DefaultLogger(org.apache.tools.ant.DefaultLogger)

Aggregations

PropertySet (org.apache.tools.ant.types.PropertySet)3 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 BuildListener (org.apache.tools.ant.BuildListener)1 DefaultLogger (org.apache.tools.ant.DefaultLogger)1