use of org.apache.tools.ant.types.Resource in project randomizedtesting by randomizedtesting.
the class ExecutionTimesReport method mergeHints.
/**
* Read hints from all resources in a collection, retaining
* <code>suiteNames</code>. If <code>suiteNames</code> is null,
* everything is retained.
*/
public static Map<String, List<Long>> mergeHints(Collection<ResourceCollection> resources, Collection<String> suiteNames) {
final Map<String, List<Long>> hints = new HashMap<>();
for (ResourceCollection rc : resources) {
Iterator<Resource> i = rc.iterator();
while (i.hasNext()) {
InputStream is = null;
Resource r = i.next();
try {
is = r.getInputStream();
mergeHints(is, hints);
// Early prune the hints to those we have on the list.
if (suiteNames != null) {
hints.keySet().retainAll(suiteNames);
}
} catch (IOException e) {
throw new BuildException("Could not read hints from resource: " + r.getDescription(), e);
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
throw new BuildException("Could not close hints file: " + r.getDescription());
}
}
}
}
return hints;
}
use of org.apache.tools.ant.types.Resource in project lombok by rzwitserloot.
the class WebUpToDate method eval.
/**
* Evaluate (all) target and source file(s) to
* see if the target(s) is/are up-to-date.
* @return true if the target(s) is/are up-to-date
*/
public boolean eval() {
if (sourceFileSets.size() == 0 && sourceResources.size() == 0 && sourceFile == null) {
throw new BuildException("At least one srcfile or a nested <srcfiles> or <srcresources> element must be set.");
}
if ((sourceFileSets.size() > 0 || sourceResources.size() > 0) && sourceFile != null) {
throw new BuildException("Cannot specify both the srcfile attribute and a nested <srcfiles> or <srcresources> element.");
}
if (urlbase == null) {
throw new BuildException("The urlbase attribute must be set.");
}
// if the source file isn't there, throw an exception
if (sourceFile != null && !sourceFile.exists()) {
throw new BuildException(sourceFile.getAbsolutePath() + " not found.");
}
boolean upToDate = true;
if (sourceFile != null) {
Resource fileResource = new FileResource(sourceFile);
upToDate = isUpToDate(fileResource);
}
if (upToDate) {
Enumeration e = sourceFileSets.elements();
while (upToDate && e.hasMoreElements()) {
FileSet fs = (FileSet) e.nextElement();
Iterator it = fs.iterator();
while (upToDate && it.hasNext()) {
Resource r = (Resource) it.next();
upToDate = isUpToDate(r);
}
}
}
if (upToDate) {
Resource[] r = sourceResources.listResources();
for (int i = 0; upToDate && i < r.length; i++) {
upToDate = isUpToDate(r[i]);
}
}
return upToDate;
}
use of org.apache.tools.ant.types.Resource in project lombok by rzwitserloot.
the class WebUpToDate method isUpToDate.
private boolean isUpToDate(Resource r) throws BuildException {
String url = urlbase + r.getName();
Resource urlResource;
try {
urlResource = new URLResource(new URL(url));
} catch (MalformedURLException e) {
throw new BuildException("url is malformed: " + url, e);
}
if (SelectorUtils.isOutOfDate(r, urlResource, 20)) {
log(r.getName() + " is newer than " + url, Project.MSG_VERBOSE);
return false;
} else {
return true;
}
}
use of org.apache.tools.ant.types.Resource in project jslint4java by happygiraffe.
the class JSLintTask method execute.
/**
* Scan the specified directories for JavaScript files and lint them.
*/
@Override
public void execute() throws BuildException {
if (resources.size() == 0) {
// issue 53: this isn't a fail, just a notice.
log(NO_FILES_TO_LINT);
}
JSLint lint = makeLint();
applyOptions(lint);
for (ResultFormatter rf : formatters) {
rf.begin();
}
int failedCount = 0;
int totalErrorCount = 0;
for (Resource resource : resources.listResources()) {
try {
int errorCount = lintStream(lint, resource);
if (errorCount > 0) {
totalErrorCount += errorCount;
failedCount++;
}
} catch (IOException e) {
throw new BuildException(e);
}
}
for (ResultFormatter rf : formatters) {
rf.end();
}
if (failedCount != 0) {
String msg = failureMessage(failedCount, totalErrorCount);
if (haltOnFailure) {
throw new BuildException(msg);
} else {
log(msg);
if (failureProperty != null) {
getProject().setProperty(failureProperty, msg);
}
}
}
}
use of org.apache.tools.ant.types.Resource in project randomizedtesting by randomizedtesting.
the class JUnit4 method processTestResources.
/**
* Process test resources. If there are any test resources that are _not_ class files,
* this will cause a build error.
*/
private TestsCollection processTestResources() {
TestsCollection collection = new TestsCollection();
resources.setProject(getProject());
Iterator<Resource> iter = (Iterator<Resource>) resources.iterator();
boolean javaSourceWarn = false;
while (iter.hasNext()) {
final Resource r = iter.next();
if (!r.isExists())
throw new BuildException("Test class resource does not exist?: " + r.getName());
try {
if (r.getName().endsWith(".java")) {
String pathname = r.getName();
String className = pathname.substring(0, pathname.length() - ".java".length());
className = className.replace(File.separatorChar, '.').replace('/', '.').replace('\\', '.');
collection.add(new TestClass(className));
if (!javaSourceWarn) {
log("Source (.java) files used for naming source suites. This is discouraged, " + "use a resource collection pointing to .class files instead.", Project.MSG_INFO);
javaSourceWarn = true;
}
} else {
// Assume .class file.
InputStream is = r.getInputStream();
if (!is.markSupported()) {
is = new BufferedInputStream(is);
}
try {
is.mark(4);
if (is.read() != 0xca || is.read() != 0xfe || is.read() != 0xba || is.read() != 0xbe) {
throw new BuildException("File does not start with a class magic 0xcafebabe: " + r.getName() + ", " + r.getLocation());
}
is.reset();
// Hardcoded intentionally.
final String REPLICATE_CLASS = "com.carrotsearch.randomizedtesting.annotations.ReplicateOnEachVm";
final TestClass testClass = new TestClass();
ClassReader reader = new ClassReader(is);
ClassVisitor annotationVisitor = new ClassVisitor(Opcodes.ASM5) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
String className = Type.getType(desc).getClassName();
if (className.equals(REPLICATE_CLASS)) {
testClass.replicate = true;
}
return null;
}
};
reader.accept(annotationVisitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
testClass.className = reader.getClassName().replace('/', '.');
log("Test class parsed: " + r.getName() + " as " + testClass.className, Project.MSG_DEBUG);
collection.add(testClass);
} finally {
is.close();
}
}
} catch (IOException e) {
throw new BuildException("Could not read or parse as Java class: " + r.getName() + ", " + r.getLocation(), e);
}
}
String testClassFilter = Strings.emptyToNull(getProject().getProperty(SYSPROP_TESTCLASS()));
if (testClassFilter != null) {
ClassGlobFilter filter = new ClassGlobFilter(testClassFilter);
for (Iterator<TestClass> i = collection.testClasses.iterator(); i.hasNext(); ) {
if (!filter.shouldRun(Description.createSuiteDescription(i.next().className))) {
i.remove();
}
}
}
return collection;
}
Aggregations