congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Resource
Code IndexAdd Tabnine to your IDE (free)

How to use
Resource
in
org.apache.tools.ant.types

Best Java code snippets using org.apache.tools.ant.types.Resource (Showing top 20 results out of 315)

Refine searchRefine arrow

  • BuildException
  • FileUtils
  • FileResource
origin: org.apache.ant/ant

/**
 * Load a properties resource.
 * @param propertyResource the resource to load the properties from.
 * @return loaded <code>Properties</code> object.
 * @throws BuildException if the resource could not be found or read.
 * @since Ant 1.8.0
 */
public Properties getProperties(Resource propertyResource)
  throws BuildException {
  Properties props = new Properties();
  try (InputStream in = propertyResource.getInputStream()) {
    props.load(in);
  } catch (IOException e) {
    throw new BuildException("Property resource (%s) cannot be loaded.",
      propertyResource.getName());
  }
  return props;
}
origin: org.apache.ant/ant

/**
 * The resource to expand; required.
 * @param src resource to expand
 */
public void setSrcResource(Resource src) {
  if (!src.isExists()) {
    throw new BuildException("the archive %s doesn't exist",
      src.getName());
  }
  if (src.isDirectory()) {
    throw new BuildException("the archive %s can't be a directory",
      src.getName());
  }
  FileProvider fp = src.as(FileProvider.class);
  if (fp != null) {
    source = fp.getFile();
  } else if (!supportsNonFileResources()) {
    throw new BuildException(
      "The source %s is not a FileSystem Only FileSystem resources are supported.",
      src.getName());
  }
  srcResource = src;
}
origin: org.apache.ant/ant

/**
 * Get the string representation of this Resource.
 * @return this Resource formatted as a String.
 * @since Ant 1.7
 */
@Override
public String toString() {
  if (isReference()) {
    return getCheckedRef().toString();
  }
  String n = getName();
  return n == null ? "(anonymous)" : n;
}
origin: org.apache.ant/ant

/**
 * The exists attribute tells whether a resource exists.
 * @return true if this resource exists.
 */
public boolean isExists() {
  if (isReference()) {
    return getCheckedRef().isExists();
  }
  //default true:
  return exists == null || exists;
}
origin: org.apache.ant/ant

/**
 * Fulfill the ResourceCollection contract.
 * @return whether this Resource is a FileProvider.
 * @since Ant 1.7
 */
@Override
public boolean isFilesystemOnly() {
  return (isReference() && getCheckedRef().isFilesystemOnly())
    || this.as(FileProvider.class) != null;
}
origin: org.apache.ant/ant

/**
 * Resource to write to.
 * @param output the Resource to write to.
 * @since Ant 1.8
 */
public void setOutput(Resource output) {
  if (this.output != null) {
    throw new BuildException("Cannot set > 1 output target");
  }
  this.output = output;
  FileProvider fp = output.as(FileProvider.class);
  this.file = fp != null ? fp.getFile() : null;
}
origin: org.apache.ant/ant

/**
 * Implement the gunzipping.
 */
@Override
protected void extract() {
  if (srcResource.getLastModified() > dest.lastModified()) {
    log("Expanding " + srcResource.getName() + " to "
          + dest.getAbsolutePath());
    try (OutputStream out = Files.newOutputStream(dest.toPath());
        GZIPInputStream zIn =
          new GZIPInputStream(srcResource.getInputStream())) {
      byte[] buffer = new byte[BUFFER_SIZE];
      int count = 0;
      do {
        out.write(buffer, 0, count);
        count = zIn.read(buffer, 0, buffer.length);
      } while (count != -1);
    } catch (IOException ioe) {
      String msg = "Problem expanding gzip " + ioe.getMessage();
      throw new BuildException(msg, ioe, getLocation());
    }
  }
}
origin: org.testng/testng

/**
 * Returns the list of files corresponding to the resource collection
 *
 * @param resources - A list of {@link ResourceCollection}
 * @return the list of files corresponding to the resource collection
 * @throws BuildException
 */
private List<String> getFiles(List<ResourceCollection> resources) throws BuildException {
 List<String> files= Lists.newArrayList();
 for (ResourceCollection rc : resources) {
  for (Resource o : rc) {
   if (o instanceof FileResource) {
    FileResource fr = ((FileResource) o);
    if (fr.isDirectory()) {
     throw new BuildException("Directory based FileResources are not supported.");
    }
    if (! fr.isExists()) {
     log("'" + fr.toLongString() + "' does not exist", Project.MSG_VERBOSE);
    }
    files.add(fr.getFile().getAbsolutePath());
   } else {
    log("Unsupported Resource type: " + o.toString(), Project.MSG_VERBOSE);
   }
  }
 }
 return files;
}
origin: org.apache.ant/ant

if (resource.isFilesystemOnly()) {
  File file = fileResource.getFile();
  String filename = fileResource.getName();
  File basedir = fileResource.getBaseDir();
  return isSelected(basedir, filename, file);
  FileUtils fu = FileUtils.getFileUtils();
  File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
  Resource tmpResource = new FileResource(tmpFile);
  ResourceUtils.copyResource(resource, tmpResource);
  boolean isSelected = isSelected(tmpFile.getParentFile(),
                  tmpFile.getName(),
                  resource.toLongString());
  tmpFile.delete();
  return isSelected;
} catch (UnsupportedOperationException uoe) {
  log("The resource '"
   + resource.getName()
   + "' does not provide an InputStream, so it is not checked. "
   + "According to 'selres' attribute value it is "
  return selectResourcesWithoutInputStream;
} catch (Exception e) {
  throw new BuildException(e);
origin: org.apache.ant/ant

/**
 * The resource to pack; required.
 * @param src resource to expand
 */
public void setSrcResource(Resource src) {
  if (src.isDirectory()) {
    throw new BuildException("the source can't be a directory");
  }
  if (src.as(FileProvider.class) != null || supportsNonFileResources()) {
    this.src = src;
  } else {
    throw new BuildException("Only FileSystem resources are supported.");
  }
}
origin: BroadleafCommerce/BroadleafCommerce

  while (resources.hasNext()) {
    Resource r = (Resource) resources.next();
    if (!r.isExists()) {
      continue;
      String baseDir = fr.getBaseDir().getAbsolutePath();
      String file = fr.getFile().getAbsolutePath();
      file = file.substring(baseDir.length(), file.length());
      String[] parts = file.split("/");
        throw new BuildException("Unable to recognize the path separator for src file: " + file);
      File specificDestinationFile = new File(destDir, specificFilePart);
      if (specificFile.exists()) {
        fileUtils.copyFile(specificFile, specificDestinationFile);
        continue;
      File generalFile = new File(licenseDir, generalFilePart);
      if (generalFile.exists()) {
        fileUtils.copyFile(generalFile, specificDestinationFile);
        continue;
      File moreGeneralFile = new File(licenseDir, moreGeneralFilePart);
      if (moreGeneralFile.exists()) {
        fileUtils.copyFile(moreGeneralFile, specificDestinationFile);
throw new BuildException(e);
origin: org.apache.ant/ant

  url = (URL) source;
} else if (source instanceof Resource) {
  FileProvider fp = ((Resource) source).as(FileProvider.class);
  if (fp != null) {
    buildFile = fp.getFile();
  } else {
    URLProvider up = ((Resource) source).as(URLProvider.class);
    if (up != null) {
      url = up.getURL();
  buildFile = FILE_UTILS.normalize(buildFile.getAbsolutePath());
  context.setBuildFile(buildFile);
  buildFileName = buildFile.toString();
    context.setBuildFile(url);
  } catch (MalformedURLException ex) {
    throw new BuildException(ex);
  throw new BuildException("Source " + source.getClass().getName()
               + " not supported by this plugin");
    uri = FILE_UTILS.toURI(buildFile.getAbsolutePath());
    inputStream = Files.newInputStream(buildFile.toPath());
  } else {
origin: org.apache.ant/ant

/**
 * Return true if this Resource is selected.
 * @param r the Resource to check.
 * @return whether the Resource was selected.
 */
public boolean isSelected(final Resource r) {
  if (type == null) {
    throw new BuildException("The type attribute is required.");
  }
  final int i = type.getIndex();
  return i == 2 || (r.isDirectory() ? i == 1 : i == 0);
}
origin: org.apache.ant/ant

  final List<Resource> v = new ArrayList<>();
  for (Resource rc : fromResources) {
    if (mapper.mapFileName(rc.getName()) != null) {
      v.add(rc);
} else {
  toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper,
      name -> new FileResource(toDir, name), granularity);
  final String[] mappedFiles = mapper.mapFileName(rc.getName());
  if (mappedFiles == null || mappedFiles.length == 0) {
    throw new BuildException("Can't copy a resource without a"
        + " name if the mapper doesn't"
        + " provide one.");
origin: org.apache.ant/ant

throws IOException {
if (!r.isExists()) {
  return;
if (r.isDirectory() && !vPath.endsWith("/")) {
  vPath += "/";
    throw new BuildException("Entry: " + vPath
        + " longer than " + TarConstants.NAMELEN
        + "characters.", getLocation());
te.setModTime(r.getLastModified());
if (!r.isDirectory()) {
  if (r.size() > TarConstants.MAXSIZE) {
    throw new BuildException(
      "Resource: " + r + " larger than "
      + TarConstants.MAXSIZE + " bytes.");
  te.setSize(r.getSize());
  tOut.putNextEntry(te);
  if (!r.isDirectory()) {
    in = r.getInputStream();
  FileUtils.close(in);
origin: org.apache.ant/ant

private ResourceCollection read(Resource r) {
  try (BufferedReader reader = new BufferedReader(open(r))) {
    Union streamResources = new Union();
    streamResources.setCache(true);
    reader.lines().map(this::parse).forEach(streamResources::add);
    return streamResources;
  } catch (final IOException ioe) {
    throw new BuildException("Unable to read resource " + r.getName()
                 + ": " + ioe, ioe, getLocation());
  }
}
origin: org.apache.ant/ant

if (resource.getSize() == 0) {
  return false;
  new InputStreamReader(resource.getInputStream()))) {
  String contents = FileUtils.safeReadFully(reader);
  String sub = substring;
  if (!casesensitive) {
  throw new BuildException("There was a problem accessing resource : " + resource);
origin: org.apache.ant/ant

  upToDate = check(fs.getDir(getProject()), getFileNames(fs));
} else if (!rc.isFilesystemOnly() && !supportsNonFileResources()) {
  throw new BuildException("only filesystem resources are supported");
} else if (rc.isFilesystemOnly()) {
  final Set<File> basedirs = new HashSet<>();
  for (final Resource res : rc) {
    final FileResource r = ResourceUtils
      .asFileResource(res.as(FileProvider.class));
    File base = r.getBaseDir();
    if (base == null) {
      base = Copy.NULL_FILE_PLACEHOLDER;
    List<String> files = basedirToFilesMap.computeIfAbsent(base, k -> new Vector<>());
    if (base == Copy.NULL_FILE_PLACEHOLDER) {
      files.add(r.getFile().getAbsolutePath());
    } else {
      files.add(r.getName());
origin: org.apache.ant/ant

/**
 * Return an InputStream for reading the contents of this Resource.
 * @return an InputStream object.
 * @throws IOException if the tar file cannot be opened,
 *         or the entry cannot be read.
 */
@Override
public InputStream getInputStream() throws IOException {
  if (isReference()) {
    return getCheckedRef().getInputStream();
  }
  Resource archive = getArchive();
  final TarInputStream i = new TarInputStream(archive.getInputStream());
  TarEntry te;
  while ((te = i.getNextEntry()) != null) {
    if (te.getName().equals(getName())) {
      return i;
    }
  }
  FileUtils.close(i);
  throw new BuildException("no entry " + getName() + " in "
               + getArchive());
}
origin: org.apache.ant/ant

throw new BuildException("Source file " + srcFile
    + " is not a file!", getLocation());
    OutputStream os = null;
    FileProvider fp =
      output.as(FileProvider.class);
    if (fp != null) {
      os = FileUtils.newOutputStream(fp.getFile().toPath(), append);
    } else {
      if (append) {
        Appendable a =
          output.as(Appendable.class);
        if (a != null) {
          os = a.getAppendOutputStream();
        os = output.getOutputStream();
        if (append) {
          log("Ignoring append=true for non-appendable"
  FileUtils.close(out);
setErrorProperty();
if ("abort".equals(onError)) {
  throw new BuildException(e, getLocation());
  FileUtils.close(getStatement());
} catch (SQLException ex) {
org.apache.tools.ant.typesResource

Javadoc

Describes a "File-like" resource (File, ZipEntry, etc.).

This class is meant to be used by classes needing to record path and date/time information about a file, a zip entry or some similar resource (URL, archive in a version control repository, ...).

Most used methods

  • getInputStream
    Get an InputStream for the Resource.
  • getName
    Name attribute will contain the path of a file relative to the root directory of its fileset or the
  • isExists
    The exists attribute tells whether a resource exists.
  • toString
    Get the string representation of this Resource.
  • isDirectory
    Tells if the resource is a directory.
  • as
    Returns a view of this resource that implements the interface given as the argument or null if there
  • getLastModified
    Tells the modification time in milliseconds since 01.01.1970 (the "epoch").
  • getOutputStream
    Get an OutputStream for the Resource.
  • getSize
    Get the size of this Resource.
  • isFilesystemOnly
    Fulfill the ResourceCollection contract.
  • setProject
  • toLongString
    Get a long String representation of this Resource. This typically should be the value of toString()
  • setProject,
  • toLongString,
  • <init>,
  • asOptional,
  • checkAttributesAllowed,
  • compareTo,
  • dieOnCircularReference,
  • equals,
  • getCheckedRef,
  • getDataTypeName

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • scheduleAtFixedRate (Timer)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now