use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.
the class AddTranslations method execute.
public void execute() throws BuildException {
Map<String, String> externalFiles = getExternalFileLocations();
DirectoryScanner ds = getDirectoryScanner(dir);
String[] srcFiles = ds.getIncludedFiles();
for (int i = 0; i < srcFiles.length; i++) {
try {
addTranslationsFromFile(new File(dir, srcFiles[i]), externalFiles);
} catch (IOException ioe) {
if (verbose)
ioe.printStackTrace(System.out);
System.out.println("'" + srcFiles[i] + "' does not appear to " + "be a valid translations zipfile - skipping.");
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.
the class MergeJars method copyFileSet.
private void copyFileSet(FileSet fileset, ZipOutputStream out) throws IOException {
String prefix = null;
String fullPath = null;
if (fileset instanceof ZipFileSet) {
ZipFileSet zfs = (ZipFileSet) fileset;
fullPath = zfs.getFullpath(getProject());
prefix = zfs.getPrefix(getProject());
if (prefix != null && !prefix.endsWith("/"))
prefix = prefix + "/";
}
DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
String[] srcFiles = ds.getIncludedFiles();
if (fullPath != null && srcFiles.length > 1)
throw new BuildException("fullpath specified for fileset matching multiple files");
File dir = fileset.getDir(getProject());
for (int i = 0; i < srcFiles.length; i++) {
String filename = srcFiles[i];
File inputFile = new File(dir, filename);
FileInputStream in = new FileInputStream(inputFile);
filename = filename.replace(File.separatorChar, '/');
if (fullPath != null)
filename = fullPath;
else if (prefix != null)
filename = prefix + filename;
ZipEntry zipEntry = new ZipEntry(filename);
zipEntry.setTime(inputFile.lastModified());
copyFile(zipEntry, out, in);
}
}
use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.
the class PackageLaunchProfile method calculateContentToken.
private String calculateContentToken() throws IOException {
List<File> files = new ArrayList<File>();
for (FileSet fs : filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
for (String name : ds.getIncludedFiles()) files.add(new File(ds.getBasedir(), name));
}
if (files.isEmpty())
throw new BuildException("You must designate at least one file " + "to include in the launch profile.");
Collections.sort(files, FILENAME_SORTER);
Checksum ck = new Adler32();
for (File f : files) calcChecksum(f, ck);
return Long.toString(Math.abs(ck.getValue()), Character.MAX_RADIX);
}
use of org.apache.tools.ant.DirectoryScanner in project tomcat70 by apache.
the class CheckEol method execute.
/**
* Perform the check
*
* @throws BuildException if an error occurs during execution of
* this task.
*/
@Override
public void execute() throws BuildException {
Mode mode = null;
if ("\n".equals(eoln)) {
mode = Mode.LF;
} else if ("\r\n".equals(eoln)) {
mode = Mode.CRLF;
} else {
log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.", Project.MSG_VERBOSE);
return;
}
int count = 0;
List<CheckFailure> errors = new ArrayList<CheckFailure>();
// Step through each file and check.
for (FileSet fs : filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File basedir = ds.getBasedir();
String[] files = ds.getIncludedFiles();
if (files.length > 0) {
log("Checking line ends in " + files.length + " file(s)");
for (int i = 0; i < files.length; i++) {
File file = new File(basedir, files[i]);
log("Checking file '" + file + "' for correct line ends", Project.MSG_DEBUG);
try {
check(file, errors, mode);
} catch (IOException e) {
throw new BuildException("Could not check file '" + file.getAbsolutePath() + "'", e);
}
count++;
}
}
}
if (count > 0) {
log("Done line ends check in " + count + " file(s), " + errors.size() + " error(s) found.");
}
if (errors.size() > 0) {
String message = "The following files have wrong line ends: " + errors;
// We need to explicitly write the message to the log, because
// long BuildException messages may be trimmed. E.g. I observed
// this problem with Eclipse IDE 3.7.
log(message, Project.MSG_ERR);
throw new BuildException(message);
}
}
use of org.apache.tools.ant.DirectoryScanner in project georocket by georocket.
the class ImportCommand method doRun.
@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
long start = System.currentTimeMillis();
// resolve file patterns
Queue<String> queue = new ArrayDeque<>();
for (String p : patterns) {
// convert Windows backslashes to slashes (necessary for Files.newDirectoryStream())
if (SystemUtils.IS_OS_WINDOWS) {
p = FilenameUtils.separatorsToUnix(p);
}
// collect paths and glob patterns
List<String> roots = new ArrayList<>();
List<String> globs = new ArrayList<>();
String[] parts = p.split("/");
boolean rootParsed = false;
for (String part : parts) {
if (!rootParsed) {
if (hasGlobCharacter(part)) {
globs.add(part);
rootParsed = true;
} else {
roots.add(part);
}
} else {
globs.add(part);
}
}
if (globs.isEmpty()) {
// string does not contain a glob pattern at all
queue.add(p);
} else {
// string contains a glob pattern
if (roots.isEmpty()) {
// there are not paths in the string. start from the current
// working directory
roots.add(".");
}
// add all files matching the pattern
String root = String.join("/", roots);
String glob = String.join("/", globs);
Project project = new Project();
FileSet fs = new FileSet();
fs.setDir(new File(root));
fs.setIncludes(glob);
DirectoryScanner ds = fs.getDirectoryScanner(project);
Arrays.stream(ds.getIncludedFiles()).map(path -> Paths.get(root, path).toString()).forEach(queue::add);
}
}
if (queue.isEmpty()) {
error("given pattern didn't match any files");
return;
}
Vertx vertx = new Vertx(this.vertx);
GeoRocketClient client = createClient();
int queueSize = queue.size();
doImport(queue, client, vertx, exitCode -> {
client.close();
if (exitCode == 0) {
String m = "file";
if (queueSize > 1) {
m += "s";
}
System.out.println("Successfully imported " + queueSize + " " + m + " in " + DurationFormat.formatUntilNow(start));
}
handler.handle(exitCode);
});
}
Aggregations