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);
}
}
Aggregations