Java Code Examples for org.apache.tools.ant.Project#setProperty()

The following examples show how to use org.apache.tools.ant.Project#setProperty() . 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: DeliverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for IVY-1111.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1111">IVY-1111</a>
 */
@Test
public void testIVY1111() throws Exception {
    Project project = ivyDeliver.getProject();
    project.setProperty("ivy.settings.file", "test/repositories/IVY-1111/ivysettings.xml");
    File ivyFile = new File(new URI(DeliverTest.class.getResource("ivy-1111.xml").toString()));

    resolve(ivyFile);

    ivyDeliver.setReplacedynamicrev(true);
    ivyDeliver.doExecute();

    String deliverContent = readFile(deliverDir.getAbsolutePath() + "/ivys/ivy-1.0.xml");
    assertFalse(deliverContent.contains("rev=\"latest.integration\""));
    assertTrue(deliverContent.contains("name=\"b\" rev=\"1.5\""));
}
 
Example 2
Source File: GroovycTest.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected void setUp() {
    project = new Project();
    project.init();
    ProjectHelper.getProjectHelper().parse(project, antFile);
    project.executeTarget("clean");

    String altJavaHome = System.getProperty("java.home");
    if (altJavaHome.lastIndexOf("jre") >= 0) {
        altJavaHome = altJavaHome.substring(0, altJavaHome.lastIndexOf("jre"));
    } else {
        altJavaHome = altJavaHome + File.separator + "jre";
    }
    try {
        File altFile = new File(altJavaHome);
        if (altFile.exists()) {
            project.setProperty("alt.java.home", altJavaHome);
        }
    } catch (Exception ignore) {
        // could be security, io, etc.
        // End result is as if .exists() returned null
    }
}
 
Example 3
Source File: IvyBuildNumberTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithBadChecksum() {
    Project project = TestHelper.newProject();
    project.setProperty("ivy.settings.file", "test/repositories/ivysettings-checksums.xml");

    buildNumber = new IvyBuildNumber();
    buildNumber.setProject(project);
    buildNumber.setOrganisation("org1");
    buildNumber.setModule("badivycs");
    buildNumber.setRevision("1.");
    buildNumber.execute();
    assertEquals("1.0", buildNumber.getProject().getProperty("ivy.revision"));
    assertEquals("1.1", buildNumber.getProject().getProperty("ivy.new.revision"));
    assertEquals("0", buildNumber.getProject().getProperty("ivy.build.number"));
    assertEquals("1", buildNumber.getProject().getProperty("ivy.new.build.number"));
}
 
Example 4
Source File: AntTaskUtils.java    From was-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static void copyProperties(MavenProject mavenProject, Project antProject) {
  copyProperties(mavenProject.getProperties(), antProject);

  // Set the POM file as the ant.file for the tasks run directly in Maven.
  antProject.setProperty("ant.file", mavenProject.getFile().getAbsolutePath());

  // Add some of the common maven properties
  antProject.setProperty(("project.groupId"), mavenProject.getGroupId());
  antProject.setProperty(("project.artifactId"), mavenProject.getArtifactId());
  antProject.setProperty(("project.name"), mavenProject.getName());
  if (mavenProject.getDescription() != null) {
    antProject.setProperty(("project.description"), mavenProject.getDescription());
  }
  antProject.setProperty(("project.version"), mavenProject.getVersion());
  antProject.setProperty(("project.packaging"), mavenProject.getPackaging());
  antProject.setProperty(("project.build.directory"), mavenProject.getBuild().getDirectory());
  antProject.setProperty(("project.build.outputDirectory"), mavenProject.getBuild().getOutputDirectory());
  antProject.setProperty(("project.build.testOutputDirectory"), mavenProject.getBuild().getTestOutputDirectory());
  antProject.setProperty(("project.build.sourceDirectory"), mavenProject.getBuild().getSourceDirectory());
  antProject.setProperty(("project.build.testSourceDirectory"), mavenProject.getBuild().getTestSourceDirectory());
}
 
Example 5
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * If <code>attributePropertyPrefix</code> is set then iterate over
 * all attributes in the main section and set the value for
 * corresponding property to the value of that attribute.
 *
 * The name of the attribute will be the property name without the
 * prefix and the value will be the property value.
 */
private void updatePropertiesFromMainSectionAttributeValues(Manifest mf)
{
  if (null!=attributePropertyPrefix) {
    final Project   project      = getProject();
    final Manifest.Section mainS = mf.getMainSection();
    for (@SuppressWarnings("unchecked")
    final Enumeration<String> ae = mainS.getAttributeKeys(); ae.hasMoreElements();) {
      final String key = ae.nextElement();
      final Manifest.Attribute attr = mainS.getAttribute(key);
      // Ensure that the default case is used for OSGi specified attributes
      final String propKey = attributePropertyPrefix
        + (osgiAttrNamesMap.containsKey(key)
           ? osgiAttrNamesMap.get(key) : attr.getName() );
      final String propVal = attr.getValue();
      log("setting '" +propKey +"'='"+propVal+"'.", Project.MSG_VERBOSE);
      project.setProperty(propKey,propVal);
    }
  }
}
 
Example 6
Source File: BuildOBRTaskTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolve() throws Exception {
    Project otherProject = TestHelper.newProject();
    otherProject.setProperty("ivy.settings.file", "test/test-repo/bundlerepo/ivysettings.xml");

    IvyResolve resolve = new IvyResolve();
    resolve.setProject(otherProject);
    resolve.setFile(new File("test/test-repo/ivy-test-buildobr.xml"));
    resolve.setResolveId("withResolveId");
    resolve.execute();

    File obrFile = new File("build/cache/obr.xml");

    buildObr.setProject(otherProject);
    buildObr.setResolveId("withResolveId");
    buildObr.setOut(obrFile);
    buildObr.execute();

    BundleRepoDescriptor obr = readObr(obrFile);

    assertEquals(1, CollectionUtils.toList(obr.getModules()).size());
}
 
Example 7
Source File: SelectToolTask.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void execute() {
    Project p = getProject();

    Properties props = readProperties(propertyFile);
    toolName = props.getProperty("tool.name");
    if (toolName != null) {
        toolArgs = props.getProperty(toolName + ".args", "");
    }

    if (toolProperty == null ||
        askIfUnset && (toolName == null
            || (argsProperty != null && toolArgs == null))) {
        showGUI(props);
    }

    // finally, return required values, if any
    if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
        p.setProperty(toolProperty, toolName);

        if (argsProperty != null && toolArgs != null)
            p.setProperty(argsProperty, toolArgs);
    }
}
 
Example 8
Source File: AntHarnessTest.java    From ExpectIt with Apache License 2.0 6 votes vote down vote up
private static Project newProject() throws IOException {
    setupBuildFile();
    Project project = new Project();
    project.setUserProperty("ant.file", buildFile.getAbsolutePath());
    project.init();
    DefaultLogger listener = new DefaultLogger();
    listener.setErrorPrintStream(System.err);
    listener.setOutputPrintStream(System.out);
    listener.setMessageOutputLevel(Project.MSG_INFO);
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference("ant.projectHelper", helper);
    project.setProperty("ftp.port", String.valueOf(ftpPort));
    project.setProperty("ssh.port", String.valueOf(sshPort));
    helper.parse(project, buildFile);
    project.addBuildListener(listener);
    return project;
}
 
Example 9
Source File: IvyInfoRepositoryTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    TestHelper.createCache();
    Project project = TestHelper.newProject();
    project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");

    info = new IvyInfo();
    info.setProject(project);
}
 
Example 10
Source File: MyBuildFileRule.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up to run the named project
 *
 * @param filename
 *        name of project file to run
 * @param logLevel
 *        Log level
 * @throws BuildException
 *         on error
 */
public void configureProject (final String filename, final int logLevel) throws BuildException
{
  logBuffer = new StringBuffer ();
  fullLogBuffer = new StringBuffer ();
  project = new Project ();
  project.init ();
  final File antFile = new File (System.getProperty ("root"), filename);
  project.setProperty ("ant.processid", ProcessUtil.getProcessId ("<Process>"));
  project.setProperty ("ant.threadname", Thread.currentThread ().getName ());
  project.setUserProperty ("ant.file", antFile.getAbsolutePath ());
  project.addBuildListener (new AntTestListener (logLevel));
  ProjectHelper.configureProject (project, antFile);
}
 
Example 11
Source File: SelectToolTask.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute() {
    Project p = getProject();

    Properties props = readProperties(propertyFile);
    toolName = props.getProperty("tool.name");
    toolBootstrap = props.getProperty("tool.bootstrap") != null;
    if (toolName != null) {
        toolArgs = props.getProperty(toolName + ".args", "");
    }

    if (toolProperty == null ||
        askIfUnset && (toolName == null
            || (argsProperty != null && toolArgs == null))) {
        showGUI(props);
    }

    // finally, return required values, if any
    if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
        p.setProperty(toolProperty, toolName);
        if (toolBootstrap)
            p.setProperty(bootstrapProperty, "true");

        if (argsProperty != null && toolArgs != null)
            p.setProperty(argsProperty, toolArgs);
    }
}
 
Example 12
Source File: IvyTaskTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferencedSettings() throws MalformedURLException {
    Project p = TestHelper.newProject();
    p.setProperty("myproperty", "myvalue");

    IvyAntSettings antSettings = new IvyAntSettings();
    antSettings.setProject(p);
    // antSettings.setId("mySettings");
    antSettings.setFile(new File("test/repositories/ivysettings.xml"));
    p.addReference("mySettings", antSettings);

    IvyTask task = new IvyTask() {
        public void doExecute() throws BuildException {
        }
    };
    task.setProject(p);
    task.setSettingsRef(new Reference(task.getProject(), "mySettings"));
    Ivy ivy = task.getIvyInstance();
    assertNotNull(ivy);
    IvySettings settings = ivy.getSettings();
    assertNotNull(settings);

    assertEquals(new File("build/cache").getAbsoluteFile(), settings.getDefaultCache());
    assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings
            .getVariables().getVariable("ivy.settings.file"));
    assertEquals(
        new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm(),
        settings.getVariables().getVariable("ivy.settings.url"));
    assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables()
            .getVariable("ivy.settings.dir"));
    assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
}
 
Example 13
Source File: SelectToolTask.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute() {
    Project p = getProject();

    Properties props = readProperties(propertyFile);
    toolName = props.getProperty("tool.name");
    toolBootstrap = props.getProperty("tool.bootstrap") != null;
    if (toolName != null) {
        toolArgs = props.getProperty(toolName + ".args", "");
    }

    if (toolProperty == null ||
        askIfUnset && (toolName == null
            || (argsProperty != null && toolArgs == null))) {
        showGUI(props);
    }

    // finally, return required values, if any
    if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
        p.setProperty(toolProperty, toolName);
        if (toolBootstrap)
            p.setProperty(bootstrapProperty, "true");

        if (argsProperty != null && toolArgs != null)
            p.setProperty(argsProperty, toolArgs);
    }
}
 
Example 14
Source File: CreateDependenciesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCompileTimeDependencies() throws Exception {
    CreateDependencies d = new CreateDependencies();
    
    Project prj = new Project();
    DirSet ds = new DirSet();
    File dependencies = new File(nb_all, "dependencies");

    ds.setProject(prj);
    ds.setDir(nb_all);
    prj.addReference("x", ds);
    prj.setProperty("nb_all", nb_all.getAbsolutePath());
    d.setProject(prj);
    d.getProject();
    d.setRefid("x");
    d.setDependencies(dependencies);
    d.setSourceDependencies(true);
    d.execute();

    assertFileContent(dependencies,
                      "This project's dependencies\n" +
                      "\n" +
                      "\n" +
                      "Runtime dependencies:\n" +
                      "=====================\n" +
                      "\n" +
                      "From: XC\n" +
                      "  - XA: XB (XD)\n" +
                      "    License: Test license\n" +
                      "\n" +
                      "\n" +
                      "Compile time dependencies:\n" +
                      "==========================\n" +
                      "\n" +
                      "From: XC2\n" +
                      "  - XA2: XB2 (XD2)\n" +
                      "    License: Test license2\n" +
                      "\n");
}
 
Example 15
Source File: SetProperty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the task. If the source property was specified, its value is
 * evaluated and set as the value of the target property. Otherwise the literal
 * string value is used.
 */
public void execute() {        
    final Project project = getProject();
    final String string = (source != null) ? 
        project.getProperty(Utils.resolveProperty(source, project)) : 
        value;
    final String resolved = Utils.resolveProperty(string, project);
    log("Setting " + property + " to " + resolved);
    project.setProperty(property, resolved);
}
 
Example 16
Source File: IvyResourcesTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    TestHelper.createCache();
    Project project = TestHelper.newProject();
    project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");
    project.setProperty("ivy.cache.dir", TestHelper.cache.getAbsolutePath());

    resources = new IvyResources();
    resources.setProject(project);
}
 
Example 17
Source File: TaskApplicationIniTimestamp.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public void execute() {
    Project project = getProject();
    String currentdir = project.getProperty("currentdir");
    File f = new File(currentdir+"/application.ini");
    Long datetime = f.lastModified();
    project.setProperty("current.application.ini.timestamp",datetime.toString());
}
 
Example 18
Source File: SelectToolTask.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute() {
    Project p = getProject();

    Properties props = readProperties(propertyFile);
    toolName = props.getProperty("tool.name");
    toolBootstrap = props.getProperty("tool.bootstrap") != null;
    if (toolName != null) {
        toolArgs = props.getProperty(toolName + ".args", "");
    }

    if (toolProperty == null ||
        askIfUnset && (toolName == null
            || (argsProperty != null && toolArgs == null))) {
        showGUI(props);
    }

    // finally, return required values, if any
    if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
        p.setProperty(toolProperty, toolName);
        if (toolBootstrap)
            p.setProperty(bootstrapProperty, "true");

        if (argsProperty != null && toolArgs != null)
            p.setProperty(argsProperty, toolArgs);
    }
}
 
Example 19
Source File: TaskGenerateUuid.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void execute() {
    Project project = getProject();
    UUID id = UUID.randomUUID();
    project.setProperty("build-id",id.toString());
}
 
Example 20
Source File: InsertModuleAllTargetsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clearWorkDir();

    String prop = System.getProperty("nb_all");
    assertNotNull("${nb_all} defined", prop);
    nball = new File(prop);
    
    File baseDir = new File(getWorkDir(), "basedir");
    baseDir.mkdirs();
    
    File destDir = new File(getWorkDir(), "destdir");
    destDir.mkdirs();
    
    p = new Project();
    p.init();
    p.setBaseDir(nball);
    p.setProperty("netbeans.dest.dir", destDir.getAbsolutePath());
    p.setProperty("nb_all", nball.getAbsolutePath());
    
    File clusters = new File(new File(nball, "nbbuild"), "cluster.properties");
    assertTrue("cluster.properties file exists", clusters.exists());
    
    Properties clusterProps = new Properties();
    try (FileInputStream is = new FileInputStream(clusters)) {
        clusterProps.load(is);
    }
    
    for (Entry<Object, Object> en : clusterProps.entrySet()) {
        String key = en.getKey().toString();
        String value = en.getValue().toString();
        while(true) {
            Matcher m = VARIABLE_SUBST.matcher(value);
            StringBuffer sb = new StringBuffer(value.length());
            boolean modified = false;
            while (m.find()) {
                modified = true;
                String searchKey = m.group(1);
                m.appendReplacement(sb, Matcher.quoteReplacement(clusterProps.getProperty(searchKey)));
            }
            m.appendTail(sb);
            value = sb.toString();
            if(! modified) {
                break;
            }
        }
        p.setProperty(key, value);
    }
}