NIHVIVO-2811 getting closer - working except for themes.
This commit is contained in:
parent
11239bf040
commit
a29d85db04
6 changed files with 77 additions and 156 deletions
Binary file not shown.
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.utilities.anttasks;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -3,14 +3,9 @@
|
|||
package edu.cornell.mannlib.vitro.utilities.anttasks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
import org.apache.tools.ant.types.Resource;
|
||||
import org.apache.tools.ant.types.ResourceCollection;
|
||||
import org.apache.tools.ant.types.resources.FileResource;
|
||||
|
||||
|
@ -18,40 +13,11 @@ import org.apache.tools.ant.types.resources.FileResource;
|
|||
* Include all files that are in the primary directory, but do not have matching
|
||||
* files in the blocking directory.
|
||||
*/
|
||||
public class DirDifferenceResourceCollection extends DataType implements
|
||||
ResourceCollection {
|
||||
private List<FileResource> files = null;
|
||||
private File primaryDir;
|
||||
public class DirDifferenceResourceCollection extends
|
||||
AbstractDirResourceCollection implements ResourceCollection {
|
||||
private File blockingDir;
|
||||
private boolean blockingOptional;
|
||||
|
||||
@Override
|
||||
public boolean isFilesystemOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insure that the list has been filled and return an iterator to the list.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<? extends Resource> iterator() {
|
||||
fillFilesList();
|
||||
return files.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insure that the list has been filled and return the size of the list.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
fillFilesList();
|
||||
return files.size();
|
||||
}
|
||||
|
||||
public void setPrimary(File primaryDir) {
|
||||
this.primaryDir = primaryDir;
|
||||
}
|
||||
|
||||
public void setBlocking(File blockingDir) {
|
||||
this.blockingDir = blockingDir;
|
||||
}
|
||||
|
@ -65,7 +31,8 @@ public class DirDifferenceResourceCollection extends DataType implements
|
|||
* primary directory that are not blocked by files with the same path under
|
||||
* the blocking directory.
|
||||
*/
|
||||
private void fillFilesList() {
|
||||
@Override
|
||||
protected void fillFilesList() {
|
||||
if (files != null) {
|
||||
return;
|
||||
}
|
||||
|
@ -75,33 +42,6 @@ public class DirDifferenceResourceCollection extends DataType implements
|
|||
|
||||
files = new ArrayList<FileResource>();
|
||||
includeUnblockedFiles(primaryDir, blockingDir);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The primary and blocking directory paths must be provided, and must point
|
||||
* to existing, readable directories.
|
||||
*/
|
||||
private void confirmValidDirectory(File dir, String label, boolean optional) {
|
||||
if (dir == null) {
|
||||
throw new BuildException(label + " directory not specified.");
|
||||
}
|
||||
if (!dir.exists()) {
|
||||
if (optional) {
|
||||
return;
|
||||
} else {
|
||||
throw new BuildException(label + " directory '" + dir.getPath()
|
||||
+ "' does not exist.");
|
||||
}
|
||||
}
|
||||
if (!dir.isDirectory()) {
|
||||
throw new BuildException(label + " directory '" + dir.getPath()
|
||||
+ "' is not a directory.");
|
||||
}
|
||||
if (!dir.canRead()) {
|
||||
throw new BuildException(label + " directory '" + dir.getPath()
|
||||
+ "' is not readable.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,48 +89,4 @@ public class DirDifferenceResourceCollection extends DataType implements
|
|||
return dir;
|
||||
}
|
||||
|
||||
private void includeAllFiles(File primary) {
|
||||
for (File file : primary.listFiles(new NonDirectoryFilter())) {
|
||||
files.add(buildResource(file));
|
||||
}
|
||||
for (File primarySubDir : primary.listFiles(new DirectoryFilter())) {
|
||||
includeAllFiles(primarySubDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All file resources are based on the original primary directory.
|
||||
*/
|
||||
private FileResource buildResource(File file) {
|
||||
String primaryBasePath = primaryDir.getAbsolutePath();
|
||||
String filePath = file.getAbsolutePath();
|
||||
if (!filePath.startsWith(primaryBasePath)) {
|
||||
throw new IllegalStateException("File is not a descendant "
|
||||
+ "of the primary directory: file='" + file
|
||||
+ "', primary='" + primaryDir + "'");
|
||||
}
|
||||
|
||||
String pathPart = filePath.substring(primaryBasePath.length());
|
||||
if (pathPart.startsWith(File.separator)) {
|
||||
pathPart = pathPart.substring(1);
|
||||
}
|
||||
|
||||
// System.out.println("Resource: b='" + primaryDir + "', name='" +
|
||||
// pathPart + "'");
|
||||
return new FileResource(primaryDir, pathPart);
|
||||
}
|
||||
|
||||
public class DirectoryFilter implements FileFilter {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return file.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
public class NonDirectoryFilter implements FileFilter {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return !file.isDirectory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.utilities.anttasks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.tools.ant.types.ResourceCollection;
|
||||
import org.apache.tools.ant.types.resources.FileResource;
|
||||
|
||||
/**
|
||||
* If the primary directory exists, include all files that are descendent from
|
||||
* it. Otherwise, don't complain but act as a collection of zero files.
|
||||
*/
|
||||
public class OptionalDirResourceCollection extends
|
||||
AbstractDirResourceCollection implements ResourceCollection {
|
||||
|
||||
/**
|
||||
* If the list hasn't already been filled, fill it with all files in the
|
||||
* primary directory that are not blocked by files with the same path under
|
||||
* the blocking directory.
|
||||
*/
|
||||
@Override
|
||||
protected void fillFilesList() {
|
||||
if (files != null) {
|
||||
return;
|
||||
}
|
||||
files = new ArrayList<FileResource>();
|
||||
|
||||
confirmValidDirectory(primaryDir, "The", true);
|
||||
|
||||
if (primaryDir.exists()) {
|
||||
includeAllFiles(primaryDir);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue