use of org.apache.tools.ant.types.resources.URLResource 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.resources.URLResource in project ant by apache.
the class ImportTask method getFileAttributeResource.
private Resource getFileAttributeResource() {
if (file != null) {
if (isExistingAbsoluteFile(file)) {
return new FileResource(FILE_UTILS.normalize(file));
}
File buildFile = new File(getLocation().getFileName()).getAbsoluteFile();
if (buildFile.exists()) {
File buildFileParent = new File(buildFile.getParent());
File importedFile = FILE_UTILS.resolveFile(buildFileParent, file);
return new FileResource(importedFile);
}
// maybe this import tasks is inside an imported URL?
try {
URL buildFileURL = new URL(getLocation().getFileName());
URL importedFile = new URL(buildFileURL, file);
return new URLResource(importedFile);
} catch (MalformedURLException ex) {
log(ex.toString(), Project.MSG_VERBOSE);
}
throw new BuildException("failed to resolve %s relative to %s", file, getLocation().getFileName());
}
return null;
}
use of org.apache.tools.ant.types.resources.URLResource in project ant by apache.
the class Antlib method createAntlib.
/**
* Static method to read an ant lib definition from
* a url.
*
* @param project the current project
* @param antlibUrl the url to read the definitions from
* @param uri the uri that the antlib is to be placed in
* @return the ant lib task
*/
public static Antlib createAntlib(Project project, URL antlibUrl, String uri) {
// Check if we can contact the URL
try {
URLConnection conn = antlibUrl.openConnection();
conn.setUseCaches(false);
conn.connect();
} catch (IOException ex) {
throw new BuildException("Unable to find " + antlibUrl, ex);
}
ComponentHelper helper = ComponentHelper.getComponentHelper(project);
helper.enterAntLib(uri);
URLResource antlibResource = new URLResource(antlibUrl);
try {
// Should be safe to parse
ProjectHelper parser = null;
Object p = project.getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
if (p instanceof ProjectHelper) {
parser = (ProjectHelper) p;
if (!parser.canParseAntlibDescriptor(antlibResource)) {
parser = null;
}
}
if (parser == null) {
ProjectHelperRepository helperRepository = ProjectHelperRepository.getInstance();
parser = helperRepository.getProjectHelperForAntlib(antlibResource);
}
UnknownElement ue = parser.parseAntlibDescriptor(project, antlibResource);
// Check name is "antlib"
if (!TAG.equals(ue.getTag())) {
throw new BuildException("Unexpected tag " + ue.getTag() + " expecting " + TAG, ue.getLocation());
}
Antlib antlib = new Antlib();
antlib.setProject(project);
antlib.setLocation(ue.getLocation());
antlib.setTaskName("antlib");
antlib.init();
ue.configure(antlib);
return antlib;
} finally {
helper.exitAntLib();
}
}
use of org.apache.tools.ant.types.resources.URLResource in project ant by apache.
the class ResourceOutputTest method testurloutput.
@Test
public void testurloutput() throws IOException {
File f = project.resolveFile("testurloutput");
try {
FILE_UTILS.createNewFile(f);
testoutput(new URLResource(f));
fail("should have caught UnknownServiceException");
} catch (UnknownServiceException e) {
// TODO assert exception message
} finally {
if (!f.delete()) {
f.deleteOnExit();
}
}
}
Aggregations