Package org.apache.tools.ant.types

Examples of org.apache.tools.ant.types.Resource


     * @throws BuildException The exception raised during task execution.
     * @todo validate the source file is valid before opening, print a better error message
     * @todo add a verbose level log message listing the name of the file being loaded
     */
    public void execute() throws BuildException {
        Resource r = getResource();

        if (r == null) {
            throw new BuildException("XmlProperty task requires a source resource");
        }
        try {
            log("Loading " + src, Project.MSG_VERBOSE);

            if (r.isExists()) {

              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setValidating(validate);
              factory.setNamespaceAware(false);
              DocumentBuilder builder = factory.newDocumentBuilder();
View Full Code Here


     * @throws BuildException on error
     */
    public void execute() throws BuildException {
        validate();

        Resource s = getSrcResource();
        if (!s.isExists()) {
            log("Nothing to do: " + s.toString()
                + " doesn't exist.");
        } else if (zipFile.lastModified() < s.getLastModified()) {
            log("Building: " + zipFile.getAbsolutePath());
            pack();
        } else {
            log("Nothing to do: " + zipFile.getAbsolutePath()
                + " is up to date.");
View Full Code Here

            throw new BuildException(
                "You must specify one or more nested resource collections");
        }
        if (resources.size() > 1) {
            Iterator<Resource> i = resources.iterator();
            Resource r1 = (Resource) i.next();
            Resource r2 = null;

            while (i.hasNext()) {
                r2 = (Resource) i.next();
                try {
                    if (!ResourceUtils.contentEquals(r1, r2, asText)) {
                        return false;
                    }
                } catch (IOException ioe) {
                    throw new BuildException("when comparing resources "
                        + r1.toString() + " and " + r2.toString(), ioe);
                }
                r1 = r2;
            }
        }
        return true;
View Full Code Here

                          files);
            }
        } else { // non-file resources
            Iterator<Resource> iter = rc.iterator();
            while (upToDate && iter.hasNext()) {
                Resource r = iter.next();
                upToDate = archiveIsUpToDate(r);
            }
        }
        return upToDate;
    }
View Full Code Here

        if (neTargets > 0) {
            log(neTargets + " nonexistent targets", Project.MSG_VERBOSE);
            logMissing(missingTargets, "target");
            return false;
        }
        Resource oldestTarget = getOldest(targets);
        logWithModificationTime(oldestTarget, "oldest target file");

        logFuture(sources, datesel);

        NonExistent missingSources = new NonExistent(sources);
        int neSources = missingSources.size();
        if (neSources > 0) {
            log(neSources + " nonexistent sources", Project.MSG_VERBOSE);
            logMissing(missingSources, "source");
            return false;
        }
        Resource newestSource = (Resource) getNewest(sources);
        logWithModificationTime(newestSource, "newest source");
        return oldestTarget.getLastModified() >= newestSource.getLastModified();
    }
View Full Code Here

        Iterator<Resource> i = rc.iterator();
        if (!i.hasNext()) {
            return null;

        }
        Resource xest = i.next();
        while (i.hasNext()) {
            Resource next = i.next();
            if (c.compare(xest, next) < 0) {
                xest = next;
            }
        }
        return xest;
View Full Code Here

        if (getLocation() == null || getLocation().getFileName() == null) {
            throw new BuildException("Unable to get location of import task");
        }

        Union resourcesToImport = new Union(getProject(), resources);
        Resource fromFileAttribute = getFileAttributeResource();
        if (fromFileAttribute != null) {
            resources.add(fromFileAttribute);
        }
        for (Resource r : resourcesToImport) {
            importResource(helper, r);
View Full Code Here

        }
       
        @SuppressWarnings("unchecked")
        final Iterator<Resource> iter = (Iterator<Resource>) apiSignatures.iterator();
        while (iter.hasNext()) {
          final Resource r = iter.next();
          if (r instanceof StringResource) {
            final String s = ((StringResource) r).getValue();
            if (s != null && s.trim().length() > 0) {
              log("Reading inline API signatures...", Project.MSG_INFO);
              checker.parseSignaturesString(s);
            }
          } else {
            log("Reading API signatures: " + r, Project.MSG_INFO);
            checker.parseSignaturesFile(r.getInputStream());
          }
        }
      } catch (IOException ioe) {
        throw new BuildException("IO problem while reading files with API signatures: " + ioe);
      } catch (ParseException pe) {
        throw new BuildException("Parsing signatures failed: " + pe.getMessage());
      }
       
      if (checker.hasNoSignatures()) {
        throw new BuildException("No API signatures found; use signaturesFile=, <signaturesFileSet/>, <bundledSignatures/> or inner text to define those!");
      }

      log("Loading classes to check...", Project.MSG_INFO);
      try {
        @SuppressWarnings("unchecked")
        final Iterator<Resource> iter = (Iterator<Resource>) classFiles.iterator();
        boolean foundClass = false;
        while (iter.hasNext()) {
          final Resource r = iter.next();
          final String name = r.getName();
          if (restrictClassFilename && name != null && !name.endsWith(".class")) {
            continue;
          }
          checker.addClassToCheck(r.getInputStream());
          foundClass = true;
        }
        if (!foundClass) {
          if (ignoreEmptyFileset) {
            log("There is no <fileset/> or other resource collection given, or the collection does not contain any class files to check.", Project.MSG_WARN);
View Full Code Here

            scripts = new Union();
            scripts.add(new FileResource(script));
        }
       
        for (final Iterator it=scripts.iterator();it.hasNext();) {
            final Resource resource = (Resource) it.next();
            try {
                final Runner runner = new Runner();
               
                try {
                   
                    final InputStream inputStream = resource.getInputStream();
                    final String name = resource.getName();
                    builder.addProtocolLines(name == null ? "[Unknown]" : name, inputStream, runner.getTestElements());
                    runner.runSessions(host);
                   
                } catch (UnsupportedOperationException e) {
                    log("Resource cannot be read: " + resource.getName(), Project.MSG_WARN);
                }
            } catch (IOException e) {
                throw new BuildException("Cannot load script " + resource.getName(), e);
            } catch (Exception e) {
                log(e.getMessage(), Project.MSG_ERR);
                throw new BuildException("[FAILURE] in script " + resource.getName() + "\n" + e.getMessage(), e);
            }
           
        }
   
    }
View Full Code Here

        super.tearDown();
        fakeServer.stop();
    }

    public void testIgnoreUnsupportedResource() throws Exception {
        final Resource unsupportedResource = new StringResource() {
            public InputStream getInputStream() {
                throw new UnsupportedOperationException();
            }
        };
        stubResourceCollection.add(unsupportedResource);
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.types.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.