Search in sources :

Example 1 with Reference

use of org.apache.tools.ant.types.Reference in project checkstyle by checkstyle.

the class CheckstyleAntTaskTest method testSetClasspathRef.

@Test
public void testSetClasspathRef() {
    final CheckstyleAntTask antTask = new CheckstyleAntTask();
    antTask.setClasspathRef(new Reference(new Project(), "id"));
    assertWithMessage("Classpath should not be null").that(TestUtil.<Path>getInternalState(antTask, "classpath")).isNotNull();
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Reference(org.apache.tools.ant.types.Reference) Test(org.junit.jupiter.api.Test)

Example 2 with Reference

use of org.apache.tools.ant.types.Reference in project flyway by flyway.

the class AbstractFlywayTask method prepareClassPath.

/**
     * Prepares the classpath this task runs in, so that it includes both the classpath for Flyway and the classpath for
     * the JDBC drivers and migrations.
     */
private void prepareClassPath() {
    Path classpath = (Path) getProject().getReference("flyway.classpath");
    if (classpath != null) {
        setClasspath(classpath);
    } else {
        Reference classpathRef = (Reference) getProject().getReference("flyway.classpathref");
        if (classpathRef != null) {
            setClasspathref(classpathRef);
        }
    }
    ClassLoader classLoader = new AntClassLoader(getClass().getClassLoader(), getProject(), classPath);
    Thread.currentThread().setContextClassLoader(classLoader);
}
Also used : Path(org.apache.tools.ant.types.Path) Reference(org.apache.tools.ant.types.Reference) AntClassLoader(org.apache.tools.ant.AntClassLoader) AntClassLoader(org.apache.tools.ant.AntClassLoader)

Example 3 with Reference

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

the class MultiRootFileSetTest method testEmptyElementIfIsReferenceAdditionalAttributes.

@Test
public void testEmptyElementIfIsReferenceAdditionalAttributes() {
    MultiRootFileSet f = new MultiRootFileSet();
    f.setProject(getProject());
    f.setBaseDirs("a");
    try {
        f.setRefid(new Reference(getProject(), "dummyref"));
        fail("Can add reference to multirootfileset " + " with elements from setBasedirs");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute " + "when using refid", be.getMessage());
    }
    f = new MultiRootFileSet();
    f.addConfiguredBaseDir(new FileResource(new File(".")));
    try {
        f.setRefid(new Reference(getProject(), "dummyref"));
        fail("Can add reference to multirootfileset" + " with elements from addConfiguredBaseDir");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute " + "when using refid", be.getMessage());
    }
    f = new MultiRootFileSet();
    f.setRefid(new Reference(getProject(), "dummyref"));
    try {
        f.setBaseDirs("a");
        fail("Can set basedirs in multirootfileset" + " that is a reference.");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute " + "when using refid", be.getMessage());
    }
    try {
        f.setCache(true);
        fail("Can set cache in multirootfileset" + " that is a reference.");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute " + "when using refid", be.getMessage());
    }
    try {
        f.setType(MultiRootFileSet.SetType.file);
        fail("Can set type in multirootfileset" + " that is a reference.");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute " + "when using refid", be.getMessage());
    }
    try {
        f.addConfiguredBaseDir(new FileResource(new File(".")));
        fail("Can add nested basedir in multirootfileset " + " that is a reference.");
    } catch (BuildException be) {
        assertEquals("You must not specify nested elements when using " + "refid", be.getMessage());
    }
}
Also used : Reference(org.apache.tools.ant.types.Reference) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) AbstractFileSetTest(org.apache.tools.ant.types.AbstractFileSetTest) Test(org.junit.Test)

Example 4 with Reference

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

the class ResourceListTest method testCircularReference.

@Test
public void testCircularReference() {
    ResourceList rl1 = new ResourceList();
    rl1.setProject(buildRule.getProject());
    rl1.setRefid(new Reference(buildRule.getProject(), "foo"));
    ResourceList rl2 = new ResourceList();
    rl2.setProject(buildRule.getProject());
    buildRule.getProject().addReference("foo", rl2);
    Union u = new Union();
    u.add(rl1);
    u.setProject(buildRule.getProject());
    rl2.add(u);
    try {
        rl2.size();
        fail("Can make ResourceList a Reference to itself.");
    } catch (BuildException be) {
        assertEquals("This data type contains a circular reference.", be.getMessage());
    }
}
Also used : Reference(org.apache.tools.ant.types.Reference) BuildException(org.apache.tools.ant.BuildException) Test(org.junit.Test)

Example 5 with Reference

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

the class ResourceListTest method testEmptyElementWithReference.

@Test
public void testEmptyElementWithReference() {
    ResourceList rl = new ResourceList();
    rl.setEncoding("foo");
    try {
        rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
        fail("Can add reference to ResourceList with encoding attribute set.");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute when using refid", be.getMessage());
    }
    rl = new ResourceList();
    rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
    try {
        rl.setEncoding("foo");
        fail("Can set encoding in ResourceList that is a reference");
    } catch (BuildException be) {
        assertEquals("You must not specify more than one attribute when using refid", be.getMessage());
    }
    rl = new ResourceList();
    rl.add(new FileResource(buildRule.getProject(), "."));
    try {
        rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
        fail("Can add reference to ResourceList with nested resource collection.");
    } catch (BuildException be) {
        assertEquals("You must not specify nested elements when using refid", be.getMessage());
    }
    rl = new ResourceList();
    rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
    try {
        rl.add(new FileResource(buildRule.getProject(), "."));
        fail("Can add reference to ResourceList with nested resource collection.");
    } catch (BuildException be) {
        assertEquals("You must not specify nested elements when using refid", be.getMessage());
    }
    rl = new ResourceList();
    rl.addFilterChain(new FilterChain());
    try {
        rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
        fail("Can add reference to ResourceList with nested filter chain.");
    } catch (BuildException be) {
        assertEquals("You must not specify nested elements when using refid", be.getMessage());
    }
    rl = new ResourceList();
    rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
    try {
        rl.addFilterChain(new FilterChain());
        fail("Can add reference to ResourceList with nested filter chain.");
    } catch (BuildException be) {
        assertEquals("You must not specify nested elements when using refid", be.getMessage());
    }
}
Also used : Reference(org.apache.tools.ant.types.Reference) FilterChain(org.apache.tools.ant.types.FilterChain) BuildException(org.apache.tools.ant.BuildException) Test(org.junit.Test)

Aggregations

Reference (org.apache.tools.ant.types.Reference)8 BuildException (org.apache.tools.ant.BuildException)4 Test (org.junit.Test)4 Project (org.apache.tools.ant.Project)3 Path (org.apache.tools.ant.types.Path)3 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 Ivy (org.apache.ivy.Ivy)1 IvySettings (org.apache.ivy.core.settings.IvySettings)1 AntClassLoader (org.apache.tools.ant.AntClassLoader)1 AbstractFileSetTest (org.apache.tools.ant.types.AbstractFileSetTest)1 FilterChain (org.apache.tools.ant.types.FilterChain)1