Search in sources :

Example 86 with Project

use of org.apache.tools.ant.Project in project ant by apache.

the class PropertySet method getEffectiveProperties.

private Map<String, Object> getEffectiveProperties() {
    final Project prj = getProject();
    final Map<String, Object> result;
    if (prj == null) {
        result = getAllSystemProperties();
    } else {
        final PropertyHelper ph = PropertyHelper.getPropertyHelper(prj);
        result = prj.getPropertyNames().stream().map(n -> new AbstractMap.SimpleImmutableEntry<>(n, ph.getProperty(n))).filter(kv -> kv.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
    // quick & dirty, to make nested mapped p-sets work:
    for (PropertySet set : setRefs) {
        result.putAll(set.getPropertyMap());
    }
    return result;
}
Also used : Properties(java.util.Properties) Iterator(java.util.Iterator) RegexpMatcher(org.apache.tools.ant.util.regexp.RegexpMatcher) Set(java.util.Set) HashMap(java.util.HashMap) BuildException(org.apache.tools.ant.BuildException) FileNameMapper(org.apache.tools.ant.util.FileNameMapper) Collectors(java.util.stream.Collectors) Stack(java.util.Stack) ArrayList(java.util.ArrayList) RegexpMatcherFactory(org.apache.tools.ant.util.regexp.RegexpMatcherFactory) HashSet(java.util.HashSet) PropertyResource(org.apache.tools.ant.types.resources.PropertyResource) AbstractMap(java.util.AbstractMap) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) MappedResource(org.apache.tools.ant.types.resources.MappedResource) Map(java.util.Map) Optional(java.util.Optional) Project(org.apache.tools.ant.Project) PropertyHelper(org.apache.tools.ant.PropertyHelper) Project(org.apache.tools.ant.Project) PropertyHelper(org.apache.tools.ant.PropertyHelper)

Example 87 with Project

use of org.apache.tools.ant.Project in project ant by apache.

the class ManifestTest method testLongLine.

/**
 * Tets long line wrapping
 */
@Test
public void testLongLine() throws IOException, ManifestException {
    Project p = buildRule.getProject();
    p.setUserProperty("test.longline", LONG_LINE);
    p.setUserProperty("test.long68name", LONG_68_NAME);
    p.setUserProperty("test.long70name", LONG_70_NAME);
    p.setUserProperty("test.notlongname", NOT_LONG_NAME);
    p.setUserProperty("test.value", VALUE);
    buildRule.executeTarget("testLongLine");
    Manifest manifest = getManifest(expandedManifest);
    Manifest.Section mainSection = manifest.getMainSection();
    String classpath = mainSection.getAttributeValue("class-path");
    assertEquals("Class-Path attribute was not set correctly - ", LONG_LINE, classpath);
    assertEquals("LONG_68_NAME_VALUE_MISMATCH", VALUE, mainSection.getAttributeValue(LONG_68_NAME));
    assertEquals("LONG_70_NAME_VALUE_MISMATCH", VALUE, mainSection.getAttributeValue(LONG_70_NAME));
    assertEquals("NOT_LONG_NAME_VALUE_MISMATCH", VALUE, mainSection.getAttributeValue(NOT_LONG_NAME));
    Set<String> set = new HashSet<>();
    try (FileReader fin = new FileReader(expandedManifest)) {
        BufferedReader in = new BufferedReader(fin);
        String read = in.readLine();
        while (read != null) {
            set.add(read);
            read = in.readLine();
        }
        in.close();
    }
    assertTrue("Manifest file should have contained string ", set.remove(" NOT_LONG"));
    assertTrue("Manifest file should have contained string ", set.remove(" NG"));
    assertTrue("Manifest file should have contained string ", set.remove(LONG_70_NAME + ": "));
    assertTrue("Manifest file should have contained string ", set.remove(NOT_LONG_NAME + ": NOT_LO"));
}
Also used : Project(org.apache.tools.ant.Project) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Matchers.containsString(org.hamcrest.Matchers.containsString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 88 with Project

use of org.apache.tools.ant.Project in project ant by apache.

the class EchoTest method setUp.

@Before
public void setUp() {
    Project p = new Project();
    p.init();
    logger = new EchoTestLogger();
    p.addBuildListener(logger);
    echo = new Echo();
    echo.setProject(p);
}
Also used : Project(org.apache.tools.ant.Project) Before(org.junit.Before)

Example 89 with Project

use of org.apache.tools.ant.Project in project exist by eXist-db.

the class BaseTaskTest method taskAvailable.

@Test
public void taskAvailable() {
    final Project project = buildFileRule.getProject();
    project.setProperty(PROP_ANT_TEST_DATA_TASK_NAME, taskName);
    buildFileRule.executeTarget("taskAvailable");
    final String result = project.getProperty(PROP_ANT_TEST_DATA_RESULT);
    assertTrue(Boolean.parseBoolean(result));
}
Also used : Project(org.apache.tools.ant.Project) Test(org.junit.Test)

Example 90 with Project

use of org.apache.tools.ant.Project in project exist by eXist-db.

the class ServerTaskTest method backup.

@Test
public void backup() throws IOException {
    final Project project = buildFileRule.getProject();
    final Path backupDir = temporaryFolder.newFolder().toPath();
    project.setProperty(PROP_ANT_TEST_DATA_BACKUP_DIR, backupDir.toAbsolutePath().toString());
    buildFileRule.executeTarget("backup");
    assertTrue(Files.exists(backupDir.resolve("db").resolve("__contents__.xml")));
}
Also used : Path(java.nio.file.Path) Project(org.apache.tools.ant.Project) Test(org.junit.Test)

Aggregations

Project (org.apache.tools.ant.Project)331 File (java.io.File)125 Test (org.junit.Test)107 BuildException (org.apache.tools.ant.BuildException)66 Path (org.apache.tools.ant.types.Path)44 IOException (java.io.IOException)38 Before (org.junit.Before)36 FileSet (org.apache.tools.ant.types.FileSet)24 Commandline (org.apache.tools.ant.types.Commandline)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 Path (java.nio.file.Path)14 DefaultLogger (org.apache.tools.ant.DefaultLogger)14 Test (org.junit.jupiter.api.Test)14 Matchers.containsString (org.hamcrest.Matchers.containsString)13 ZipFile (java.util.zip.ZipFile)12 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)12 Delete (org.apache.tools.ant.taskdefs.Delete)12 Properties (java.util.Properties)9 ProjectHelper (org.apache.tools.ant.ProjectHelper)9 ArrayList (java.util.ArrayList)8