Search in sources :

Example 21 with ResourceCollection

use of org.apache.tools.ant.types.ResourceCollection in project BroadleafCommerce by BroadleafCommerce.

the class DependencyLicenseCopy method execute.

@SuppressWarnings("unchecked")
public void execute() throws BuildException {
    super.execute();
    try {
        for (int i = 0; i < rcs.size(); i++) {
            ResourceCollection rc = (ResourceCollection) rcs.elementAt(i);
            Iterator<Resource> resources = rc.iterator();
            while (resources.hasNext()) {
                Resource r = (Resource) resources.next();
                if (!r.isExists()) {
                    continue;
                }
                if (r instanceof FileResource) {
                    FileResource fr = (FileResource) r;
                    String baseDir = fr.getBaseDir().getAbsolutePath();
                    String file = fr.getFile().getAbsolutePath();
                    file = file.substring(baseDir.length(), file.length());
                    String[] parts = file.split("/");
                    if (parts.length <= 1) {
                        parts = file.split("\\\\");
                    }
                    if (parts.length <= 1) {
                        throw new BuildException("Unable to recognize the path separator for src file: " + file);
                    }
                    String[] specificParts = new String[parts.length - 1];
                    System.arraycopy(parts, 0, specificParts, 0, specificParts.length);
                    String specificFilePart = StringUtils.join(specificParts, '/') + "/license.txt";
                    File specificFile = new File(licenseDir, specificFilePart);
                    File specificDestinationFile = new File(destDir, specificFilePart);
                    if (specificFile.exists()) {
                        fileUtils.copyFile(specificFile, specificDestinationFile);
                        continue;
                    }
                    String[] generalParts = new String[3];
                    System.arraycopy(parts, 0, generalParts, 0, 3);
                    String generalFilePart = StringUtils.join(generalParts, '/') + "/license.txt";
                    File generalFile = new File(licenseDir, generalFilePart);
                    if (generalFile.exists()) {
                        fileUtils.copyFile(generalFile, specificDestinationFile);
                        continue;
                    }
                    String[] moreGeneralParts = new String[2];
                    System.arraycopy(parts, 0, moreGeneralParts, 0, 2);
                    String moreGeneralFilePart = StringUtils.join(moreGeneralParts, '/') + "/license.txt";
                    File moreGeneralFile = new File(licenseDir, moreGeneralFilePart);
                    if (moreGeneralFile.exists()) {
                        fileUtils.copyFile(moreGeneralFile, specificDestinationFile);
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new BuildException(e);
    }
}
Also used : Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) FileResource(org.apache.tools.ant.types.resources.FileResource) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File) ResourceCollection(org.apache.tools.ant.types.ResourceCollection)

Aggregations

ResourceCollection (org.apache.tools.ant.types.ResourceCollection)21 Resource (org.apache.tools.ant.types.Resource)16 BuildException (org.apache.tools.ant.BuildException)15 ArrayList (java.util.ArrayList)9 FileResource (org.apache.tools.ant.types.resources.FileResource)8 File (java.io.File)7 IOException (java.io.IOException)6 FileSet (org.apache.tools.ant.types.FileSet)6 FileProvider (org.apache.tools.ant.types.resources.FileProvider)5 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)4 ZipResource (org.apache.tools.ant.types.resources.ZipResource)4 ArchiveResource (org.apache.tools.ant.types.resources.ArchiveResource)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Union (org.apache.tools.ant.types.resources.Union)2 ZipFile (org.apache.tools.zip.ZipFile)2 OverrideOnDemand (com.helger.commons.annotation.OverrideOnDemand)1 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)1