Search in sources :

Example 1 with NameEntry

use of org.apache.tools.ant.types.PatternSet.NameEntry in project gate-core by GateNLP.

the class PackageGappTask method copyDirectories.

/**
 * Copy directories as specified by the given map.
 *
 * @param copyMap map specifying the directories to copy and the
 *          target locations to which they should be copied.
 * @param minimalPlugin if true, treat the directory as a GATE plugin
 *          and copy just the minimal files needed for the plugin to
 *          work (creole.xml and any referenced jars).
 */
private void copyDirectories(Map<URL, URL> copyMap, boolean minimalPlugin) {
    for (Map.Entry<URL, URL> copyEntry : copyMap.entrySet()) {
        File source = Files.fileFromURL(copyEntry.getKey());
        if (!source.exists()) {
            return;
        }
        File dest = Files.fileFromURL(copyEntry.getValue());
        // set up a copy task to do the copying
        Copy copyTask = new Copy();
        copyTask.setProject(getProject());
        copyTask.setLocation(getLocation());
        copyTask.setTaskName(getTaskName());
        copyTask.setTodir(dest);
        // ensure the target directory exists
        dest.mkdirs();
        FileSet fileSet = new FileSet();
        copyTask.addFileset(fileSet);
        fileSet.setDir(source);
        if (minimalPlugin) {
            // just copy creole.xml and JARs
            NameEntry include = fileSet.createInclude();
            include.setName("creole.xml");
            URL creoleXml;
            try {
                creoleXml = new URL(copyEntry.getKey().toExternalForm() + "/creole.xml");
            } catch (MalformedURLException e) {
                throw new BuildException("Error creating URL for creole.xml in plugin " + copyEntry.getKey());
            }
            for (String jarString : getJars(creoleXml)) {
                NameEntry jarInclude = fileSet.createInclude();
                jarInclude.setName(jarString);
            }
        }
        // do the copying
        copyTask.init();
        copyTask.perform();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) FileSet(org.apache.tools.ant.types.FileSet) Copy(org.apache.tools.ant.taskdefs.Copy) NameEntry(org.apache.tools.ant.types.PatternSet.NameEntry) BuildException(org.apache.tools.ant.BuildException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) File(java.io.File) URL(java.net.URL)

Example 2 with NameEntry

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

the class IvyCacheFileset method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    if (setid == null) {
        throw new BuildException("setid is required in ivy cachefileset");
    }
    try {
        final List<ArtifactDownloadReport> artifactDownloadReports = getArtifactReports();
        if (artifactDownloadReports.isEmpty()) {
            // generate an empty fileset
            final FileSet emptyFileSet = new EmptyFileSet();
            emptyFileSet.setProject(getProject());
            getProject().addReference(setid, emptyFileSet);
            return;
        }
        // find a common base dir of the resolved artifacts
        final File baseDir = this.requireCommonBaseDir(artifactDownloadReports);
        final FileSet fileset = new FileSet();
        fileset.setDir(baseDir);
        fileset.setProject(getProject());
        // enroll each of the artifact files into the fileset
        for (final ArtifactDownloadReport artifactDownloadReport : artifactDownloadReports) {
            if (artifactDownloadReport.getLocalFile() == null) {
                continue;
            }
            final NameEntry ne = fileset.createInclude();
            ne.setName(getPath(baseDir, artifactDownloadReport.getLocalFile()));
        }
        getProject().addReference(setid, fileset);
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy cache fileset: " + ex, ex);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) BuildException(org.apache.tools.ant.BuildException) NameEntry(org.apache.tools.ant.types.PatternSet.NameEntry) File(java.io.File) BuildException(org.apache.tools.ant.BuildException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

File (java.io.File)2 BuildException (org.apache.tools.ant.BuildException)2 FileSet (org.apache.tools.ant.types.FileSet)2 NameEntry (org.apache.tools.ant.types.PatternSet.NameEntry)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 Copy (org.apache.tools.ant.taskdefs.Copy)1