org.apache.tools.ant.taskdefs.Property Java Examples

The following examples show how to use org.apache.tools.ant.taskdefs.Property. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Repeat.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Execute this task. */
public void execute () throws BuildException {        
    if ( values.isEmpty() ) {
        throw new BuildException("You must set at least one value!", getLocation());
    }

    if ( target == null ) {
        throw new BuildException("Target must be set!", getLocation());
    }

    for (String val : values) {
        log ("Process '" + val + "' location with '" + target + "' target ...", Project.MSG_VERBOSE);
        
        CallTarget antCall = (CallTarget) getProject().createTask("antcall");
        antCall.init();
        antCall.setLocation(getLocation());
        
        // ant.setDir (dir);
        antCall.setTarget (target);
        Property prop = antCall.createParam();
        prop.setName(name);
        prop.setValue(val);
        
        antCall.execute();
    }
}
 
Example #2
Source File: ModuleListParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void doScanSuite(Map<String,Entry> entries, File suite, Map<String,Object> properties, Project project) throws IOException {
    Project fakeproj = new Project();
    fakeproj.setBaseDir(suite); // in case ${basedir} is used somewhere
    Property faketask = new Property();
    faketask.setProject(fakeproj);
    faketask.setFile(new File(suite, "nbproject/private/private.properties".replace('/', File.separatorChar)));
    faketask.execute();
    faketask.setFile(new File(suite, "nbproject/project.properties".replace('/', File.separatorChar)));
    faketask.execute();
    String modulesS = fakeproj.getProperty("modules");
    if (modulesS == null) {
        throw new IOException("No definition of modules in " + suite);
    }
    String[] modules = Path.translatePath(fakeproj, modulesS);
    for (int i = 0; i < modules.length; i++) {
        File module = new File(modules[i]);
        if (!module.isDirectory()) {
            throw new IOException("No such module " + module + " referred to from " + suite);
        }
        if (!scanPossibleProject(module, entries, properties, null, ModuleType.SUITE, project, null)) {
            throw new IOException("No valid module found in " + module + " referred to from " + suite);
        }
    }
}
 
Example #3
Source File: SetCluster.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static String findClusterAndId(String propertyName, String[] clusterDir, Map<String, Object> properties, String path, Property faketask, final String fallback) throws BuildException {
    String id = null;
    clusterDir[0] = findClusterForAModule(propertyName, properties, path, clusterDir[0], faketask);
    if (clusterDir[0] == null && path.contains("/")) {
        final String shortPath = path.substring(path.lastIndexOf('/') + 1);
        clusterDir[0] = findClusterForAModule(propertyName, properties, shortPath, clusterDir[0], faketask);
        if (clusterDir[0] != null) {
            id = shortPath;
        }
    }
    if (clusterDir[0] == null) {
        if (fallback == null) {
            throw new BuildException("No default cluster location defined", faketask.getLocation());
        }

        clusterDir[0] = fallback;   // fallback
    }
    return id;
}
 
Example #4
Source File: SetCluster.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String findClusterForAModule(String propertyName, Map<String, Object> properties, String path, String clusterDir, Property faketask) throws BuildException {
    // not found, try indirect nbbuild/cluster.properties
    for (Map.Entry<String,Object> entry : properties.entrySet()) {
        String val = (String) entry.getValue();
        String[] modules = val.split(", *");
        if (Arrays.asList(modules).contains(path)) {
            String key = entry.getKey();
            clusterDir = (String) properties.get(key + ".dir");
            if (clusterDir != null) {
                faketask.setName(propertyName);
                faketask.setValue(clusterDir);
                faketask.execute();
                break;
            }
        }
    }
    return clusterDir;
}
 
Example #5
Source File: Repeat.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
/** Execute this task. */
public void execute () throws BuildException {        
    if ( values.isEmpty() ) {
        throw new BuildException("You must set at least one value!", getLocation());
    }

    if ( target == null ) {
        throw new BuildException("Target must be set!", getLocation());
    }

    for (String val : values) {
        log ("Process '" + val + "' location with '" + target + "' target ...", Project.MSG_VERBOSE);
        
        CallTarget antCall = (CallTarget) getProject().createTask("antcall");
        antCall.init();
        antCall.setLocation(getLocation());
        
        // ant.setDir (dir);
        antCall.setTarget (target);
        Property prop = antCall.createParam();
        prop.setName(name);
        prop.setValue(val);
        
        antCall.execute();
    }
}
 
Example #6
Source File: IvyAntVariableContainer.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the Ant Project used in this container with variables set in Ivy.
 *
 * All variables defined in Ivy will be set in the Ant project under two names:
 * <ul>
 * <li>the name of the variable</li>
 * <li>the name of the variable suffixed with a dot + the given id, if the given id is not null
 * </li>
 * </ul>
 *
 * @param id
 *            The identifier of the settings in which the variables have been set, which should
 *            be used as property names suffix
 */
public void updateProject(String id) {
    Map<String, String> r = new HashMap<>(super.getVariables());
    r.putAll(overwrittenProperties);
    for (Map.Entry<String, String> entry : r.entrySet()) {
        setPropertyIfNotSet(entry.getKey(), entry.getValue());
        if (id != null) {
            setPropertyIfNotSet(entry.getKey() + "." + id, entry.getValue());
        }
    }

    if (getEnvironmentPrefix() != null) {
        Property propTask = new Property();
        propTask.setProject(project);
        propTask.setEnvironment(getEnvironmentPrefix());
        propTask.init();
        propTask.execute();
    }
}
 
Example #7
Source File: CreateBundle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Properties readProperties(Vector <? extends Property> antProperties) throws IOException {
    Properties props = new Properties();
    for(Property prop : antProperties) {
        if(prop.getName()!=null) {
            if(prop.getValue()!=null) {
                props.setProperty(prop.getName(), prop.getValue());
            } else if(prop.getLocation()!=null) {
                props.setProperty(prop.getName(),
                        new File(prop.getLocation().getFileName()).getAbsolutePath());
            }
        } else if(prop.getFile()!=null || prop.getUrl()!=null) {
            InputStream is = null;
            try {
                is = (prop.getFile()!=null) ?
                    new FileInputStream(prop.getFile()) :
                    prop.getUrl().openStream();
                
                Properties loadedProps = new Properties();
                loadedProps.load(is);
                is.close();
                if ( prop.getPrefix() != null ) {
                    for(Object p : loadedProps.keySet()) {
                        props.setProperty(prop.getPrefix() + p,
                                loadedProps.getProperty(p.toString()));
                    }
                } else {
                    props.putAll(loadedProps);
                }
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        }
    }
    
    return props;
}
 
Example #8
Source File: IvyDeliver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void deliverDependency(ModuleRevisionId depMrid, String version, String status,
        String depStatus) {
    if (isNullOrEmpty(deliverTarget)) {
        return;
    }
    // call deliver target if any
    CallTarget ct = (CallTarget) getProject().createTask("antcall");
    ct.setOwningTarget(getOwningTarget());
    ct.init();
    ct.setTarget(deliverTarget);
    ct.setInheritAll(true);
    ct.setInheritRefs(true);
    Property param = ct.createParam();
    param.setName("dependency.name");
    param.setValue(depMrid.getName());
    param = ct.createParam();
    param.setName("dependency.published.status");
    param.setValue(status);
    param = ct.createParam();
    param.setName("dependency.published.version");
    param.setValue(version);
    param = ct.createParam();
    param.setName("dependency.version");
    param.setValue(depMrid.getRevision());
    param = ct.createParam();
    param.setName("dependency.status");
    param.setValue(depStatus == null ? "null" : depStatus);

    ct.perform();

    String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision()
            + ".delivered";
    getProject().setProperty(deliveredProperty, "true");
    appendDeliveryList(deliveredProperty + " = true");

    getProject().setProperty("recursive." + depMrid.getName() + ".delivered", "true");
    appendDeliveryList("recursive." + depMrid.getName() + ".delivered" + " = true");
}
 
Example #9
Source File: IvyDeliver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void loadDeliveryList() {
    Property property = (Property) getProject().createTask("property");
    property.setOwningTarget(getOwningTarget());
    property.init();
    property.setFile(deliveryList);
    property.perform();
}
 
Example #10
Source File: AntCallTrigger.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void progress(IvyEvent event) {
    Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
    if (project == null) {
        Message.info("ant call trigger can only be used from an ant build. Ignoring.");
        return;
    }
    if (onlyonce && isTriggered(event)) {
        Message.verbose("call already triggered for this event, skipping: " + event);
    } else {
        CallTarget call = new CallTarget();

        call.setProject(project);
        call.setTaskName("antcall");

        Map<String, String> attributes = event.getAttributes();
        String target = IvyPatternHelper.substituteTokens(getTarget(), attributes);
        call.setTarget(target);

        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            Property p = call.createParam();
            p.setName(prefix == null ? entry.getKey() : prefix + entry.getKey());
            p.setValue(entry.getValue() == null ? "" : entry.getValue());
        }

        Message.verbose("triggering ant call: target=" + target + " for " + event);
        call.execute();
        markTriggered(event);

        Message.debug("triggered ant call finished: target=" + target + " for " + event);
    }
}
 
Example #11
Source File: CreateBundle.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void addProperty(Property p) {
    properties.addElement(p);
}
 
Example #12
Source File: SubAntJUnitReport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** @see Ant#createProperty */
public Property createProperty() {
    init();
    return ant.createProperty();
}
 
Example #13
Source File: IvyAntSettings.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
void createIvyEngine(final ProjectComponent task) {
    Project project = task.getProject();
    Property prop = new Property() {
        public void execute() throws BuildException {
            addProperties(getDefaultProperties(task));
        }
    };
    prop.setProject(project);
    prop.init();
    prop.execute();

    IvyAntVariableContainer ivyAntVariableContainer = new IvyAntVariableContainer(project);
    IvySettings settings = new IvySettings(ivyAntVariableContainer);
    settings.setBaseDir(project.getBaseDir());

    if (file == null && url == null) {
        defineDefaultSettingFile(ivyAntVariableContainer, task);
    }

    if (antWorkspaceResolver != null) {
        settings.addConfigured(antWorkspaceResolver.getResolver());
    }

    Ivy ivy = Ivy.newInstance(settings);
    try {
        ivy.pushContext();
        AntMessageLogger.register(task, ivy);

        Message.showInfo();
        configureURLHandler();
        if (file != null) {
            if (!file.exists()) {
                throw new BuildException("settings file does not exist: " + file);
            }
            ivy.configure(file);
        } else {
            if (url == null) {
                throw new AssertionError(
                        "ivy setting should have either a file, either an url,"
                                + " and if not defineDefaultSettingFile must set it.");
            }
            ivy.configure(url);
        }
        ivyAntVariableContainer.updateProject(id);
        ivyEngine = ivy;
    } catch (ParseException | IOException e) {
        throw new BuildException("impossible to configure ivy:settings with given "
                + (file != null ? "file: " + file : "url: " + url) + " : " + e, e);
    } finally {
        ivy.popContext();
    }
}
 
Example #14
Source File: ProjectInfo.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * add property, this action occurs at parser time
 * @param property
 */
public void addProperty(Property property)
{
    properties.add(property);
}