Search in sources :

Example 6 with Reference

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

the class IvyConfigureTest method getIvyInstance.

private Ivy getIvyInstance() {
    IvyTask task = new IvyTask() {

        public void doExecute() throws BuildException {
        }
    };
    task.setProject(project);
    task.init();
    Reference ref = new Reference(task.getProject(), configure.getSettingsId());
    // ref.setProject(project);
    task.setSettingsRef(ref);
    return task.getIvyInstance();
}
Also used : Reference(org.apache.tools.ant.types.Reference)

Example 7 with Reference

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

the class IvyTaskTest method testReferencedSettings.

@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"));
}
Also used : Project(org.apache.tools.ant.Project) Reference(org.apache.tools.ant.types.Reference) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) Ivy(org.apache.ivy.Ivy) Test(org.junit.Test)

Example 8 with Reference

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

the class CheckstyleAntTaskTest method testSetClasspathRef1.

/**
 * This test is created to satisfy pitest, it is hard to emulate Reference by Id.
 */
@Test
public void testSetClasspathRef1() {
    final CheckstyleAntTask antTask = new CheckstyleAntTask();
    final Project project = new Project();
    antTask.setClasspath(new Path(project, "firstPath"));
    antTask.setClasspathRef(new Reference(project, "idXX"));
    assertWithMessage("Classpath should not be null").that(TestUtil.<Path>getInternalState(antTask, "classpath")).isNotNull();
    final Path classpath = TestUtil.getInternalState(antTask, "classpath");
    final BuildException ex = assertThrows(BuildException.class, classpath::list, "BuildException is expected");
    assertWithMessage("unexpected exception message").that(ex.getMessage()).isEqualTo("Reference idXX not found.");
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Reference(org.apache.tools.ant.types.Reference) BuildException(org.apache.tools.ant.BuildException) Test(org.junit.jupiter.api.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