Search in sources :

Example 56 with Path

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

the class IvyRetrieve method doExecute.

@SuppressWarnings("deprecation")
@Override
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (!getAllowedLogOptions().contains(getLog())) {
        throw new BuildException("invalid option for 'log': " + getLog() + ". Available options are " + getAllowedLogOptions());
    }
    pattern = getProperty(pattern, getSettings(), "ivy.retrieve.pattern");
    try {
        final Filter<Artifact> artifactFilter = getArtifactFilter();
        final RetrieveOptions retrieveOptions = (RetrieveOptions) new RetrieveOptions().setLog(getLog());
        retrieveOptions.setConfs(splitToArray(getConf())).setDestArtifactPattern(pattern).setDestIvyPattern(ivypattern).setArtifactFilter(artifactFilter).setSync(sync).setOverwriteMode(getOverwriteMode()).setUseOrigin(isUseOrigin()).setMakeSymlinks(symlink).setResolveId(getResolveId()).setMapper(mapper == null ? null : new MapperAdapter(mapper));
        // only set this if the user has explicitly enabled this deprecated option
        if (symlinkmass) {
            retrieveOptions.setMakeSymlinksInMass(symlinkmass);
        }
        final RetrieveReport report = getIvyInstance().retrieve(getResolvedMrid(), retrieveOptions);
        int targetsCopied = report.getNbrArtifactsCopied();
        boolean haveTargetsBeenCopied = targetsCopied > 0;
        getProject().setProperty("ivy.nb.targets.copied", String.valueOf(targetsCopied));
        getProject().setProperty("ivy.targets.copied", String.valueOf(haveTargetsBeenCopied));
        if (getPathId() != null) {
            Path path = new Path(getProject());
            getProject().addReference(getPathId(), path);
            for (File file : report.getRetrievedFiles()) {
                path.createPathElement().setLocation(file);
            }
        }
        if (getSetId() != null) {
            FileSet fileset = new FileSet();
            fileset.setProject(getProject());
            getProject().addReference(getSetId(), fileset);
            fileset.setDir(report.getRetrieveRoot());
            for (File file : report.getRetrievedFiles()) {
                PatternSet.NameEntry ne = fileset.createInclude();
                ne.setName(getPath(report.getRetrieveRoot(), file));
            }
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to ivy retrieve: " + ex, ex);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) FileSet(org.apache.tools.ant.types.FileSet) RetrieveOptions(org.apache.ivy.core.retrieve.RetrieveOptions) Artifact(org.apache.ivy.core.module.descriptor.Artifact) BuildException(org.apache.tools.ant.BuildException) RetrieveReport(org.apache.ivy.core.retrieve.RetrieveReport) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) PatternSet(org.apache.tools.ant.types.PatternSet)

Example 57 with Path

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

the class IvyBuildListTest method getFiles.

private String[] getFiles(IvyBuildList buildlist) {
    buildlist.setReference("ordered.build.files");
    buildlist.execute();
    Object o = buildlist.getProject().getReference("ordered.build.files");
    assertNotNull(o);
    assertTrue(o instanceof Path);
    Path path = (Path) o;
    String[] files = path.list();
    assertNotNull(files);
    return files;
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 58 with Path

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

the class IvyCachePathTest method testInline1.

@Test
public void testInline1() {
    // we first resolve another ivy file
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
    resolve.execute();
    assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
    // then we resolve a dependency directly
    path.setOrganisation("org1");
    path.setModule("mod1.2");
    path.setRevision("2.0");
    path.setInline(true);
    path.setPathid("simple-pathid");
    path.execute();
    Object ref = project.getReference("simple-pathid");
    assertNotNull(ref);
    assertTrue(ref instanceof Path);
    Path p = (Path) ref;
    assertEquals(1, p.size());
    assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), new File(p.list()[0]).getAbsolutePath());
}
Also used : Path(org.apache.tools.ant.types.Path) File(java.io.File) Test(org.junit.Test)

Example 59 with Path

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

the class IvyCachePathTest method testWithResolveIdWithoutResolve.

@Test
public void testWithResolveIdWithoutResolve() {
    Project otherProject = TestHelper.newProject();
    otherProject.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(otherProject);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    resolve.setResolveId("withResolveId");
    resolve.execute();
    // resolve another ivy file
    resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
    resolve.execute();
    path.setResolveId("withResolveId");
    path.setPathid("withresolveid-pathid");
    path.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    path.execute();
    Object ref = project.getReference("withresolveid-pathid");
    assertNotNull(ref);
    assertTrue(ref instanceof Path);
    Path p = (Path) ref;
    assertEquals(1, p.size());
    assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), new File(p.list()[0]).getAbsolutePath());
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) File(java.io.File) Test(org.junit.Test)

Example 60 with Path

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

the class IvyCachePathTest method testEmptyConf.

@Test
public void testEmptyConf() {
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-108.xml");
    path.setPathid("emptyconf-pathid");
    path.setConf("empty");
    path.execute();
    Object ref = project.getReference("emptyconf-pathid");
    assertNotNull(ref);
    assertTrue(ref instanceof Path);
    Path p = (Path) ref;
    assertEquals(0, p.size());
}
Also used : Path(org.apache.tools.ant.types.Path) Test(org.junit.Test)

Aggregations

Path (org.apache.tools.ant.types.Path)175 File (java.io.File)81 BuildException (org.apache.tools.ant.BuildException)57 Test (org.junit.Test)49 Project (org.apache.tools.ant.Project)28 IOException (java.io.IOException)27 Commandline (org.apache.tools.ant.types.Commandline)21 ArrayList (java.util.ArrayList)15 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)12 AntClassLoader (org.apache.tools.ant.AntClassLoader)9 GroovyClassLoader (groovy.lang.GroovyClassLoader)8 URL (java.net.URL)8 StringTokenizer (java.util.StringTokenizer)8 Reference (org.apache.tools.ant.types.Reference)8 Java (org.apache.tools.ant.taskdefs.Java)7 FileSet (org.apache.tools.ant.types.FileSet)7 Resource (org.apache.tools.ant.types.Resource)7 FileWriter (java.io.FileWriter)6 List (java.util.List)6 Execute (org.apache.tools.ant.taskdefs.Execute)6