Search in sources :

Example 1 with URLResource

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;
    }
}
Also used : URLResource(org.apache.tools.ant.types.resources.URLResource) MalformedURLException(java.net.MalformedURLException) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) URLResource(org.apache.tools.ant.types.resources.URLResource) BuildException(org.apache.tools.ant.BuildException) URL(java.net.URL)

Example 2 with URLResource

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;
}
Also used : URLResource(org.apache.tools.ant.types.resources.URLResource) MalformedURLException(java.net.MalformedURLException) FileResource(org.apache.tools.ant.types.resources.FileResource) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) URL(java.net.URL)

Example 3 with URLResource

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();
    }
}
Also used : URLResource(org.apache.tools.ant.types.resources.URLResource) ProjectHelper(org.apache.tools.ant.ProjectHelper) UnknownElement(org.apache.tools.ant.UnknownElement) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) URLConnection(java.net.URLConnection) ProjectHelperRepository(org.apache.tools.ant.ProjectHelperRepository) ComponentHelper(org.apache.tools.ant.ComponentHelper)

Example 4 with URLResource

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();
        }
    }
}
Also used : URLResource(org.apache.tools.ant.types.resources.URLResource) UnknownServiceException(java.net.UnknownServiceException) File(java.io.File) Test(org.junit.Test)

Aggregations

URLResource (org.apache.tools.ant.types.resources.URLResource)4 BuildException (org.apache.tools.ant.BuildException)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 FileResource (org.apache.tools.ant.types.resources.FileResource)2 IOException (java.io.IOException)1 URLConnection (java.net.URLConnection)1 UnknownServiceException (java.net.UnknownServiceException)1 ComponentHelper (org.apache.tools.ant.ComponentHelper)1 ProjectHelper (org.apache.tools.ant.ProjectHelper)1 ProjectHelperRepository (org.apache.tools.ant.ProjectHelperRepository)1 UnknownElement (org.apache.tools.ant.UnknownElement)1 Resource (org.apache.tools.ant.types.Resource)1 Test (org.junit.Test)1