当前位置: 首页>>代码示例>>Java>>正文


Java Resource.isExists方法代码示例

本文整理汇总了Java中org.apache.tools.ant.types.Resource.isExists方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.isExists方法的具体用法?Java Resource.isExists怎么用?Java Resource.isExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tools.ant.types.Resource的用法示例。


在下文中一共展示了Resource.isExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkEntry

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Validate settings and ensure that the represented "archive entry"
 * has been established.
 */
protected final synchronized void checkEntry() throws BuildException {
    dieOnCircularReference();
    if (haveEntry) {
        return;
    }
    String name = getName();
    if (name == null) {
        throw new BuildException("entry name not set");
    }
    Resource r = getArchive();
    if (r == null) {
        throw new BuildException("archive attribute not set");
    }
    if (!r.isExists()) {
        throw new BuildException("%s does not exist.", r);
    }
    if (r.isDirectory()) {
        throw new BuildException("%s denotes a directory.", r);
    }
    fetchEntry();
    haveEntry = true;
}
 
开发者ID:apache,项目名称:ant,代码行数:27,代码来源:ArchiveResource.java

示例2: grabNonFileSetResources

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Fetch all included and not excluded resources from the collections.
 *
 * <p>Included directories will precede included files.</p>
 * @param rcs an array of resource collections
 * @return the resources included
 * @since Ant 1.7
 */
protected Resource[][] grabNonFileSetResources(final ResourceCollection[] rcs) {
    final Resource[][] result = new Resource[rcs.length][];
    for (int i = 0; i < rcs.length; i++) {
        final List<Resource> dirs = new ArrayList<>();
        final List<Resource> files = new ArrayList<>();
        for (final Resource r : rcs[i]) {
            if (r.isDirectory()) {
                dirs.add(r);
            } else if (r.isExists()) {
                files.add(r);
            }
        }
        // make sure directories are in alpha-order - this also
        // ensures parents come before their children
        Collections.sort(dirs, Comparator.comparing(Resource::getName));
        final List<Resource> rs = new ArrayList<>(dirs);
        rs.addAll(files);
        result[i] = rs.toArray(new Resource[rs.size()]);
    }
    return result;
}
 
开发者ID:apache,项目名称:ant,代码行数:30,代码来源:Zip.java

示例3: touch

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private void touch(Resource r, long defaultTimestamp) {
    if (fileNameMapper == null) {
        FileProvider fp = r.as(FileProvider.class);
        if (fp != null) {
            // use this to create file and deal with non-writable files
            touch(fp.getFile(), defaultTimestamp);
        } else {
            r.as(Touchable.class).touch(defaultTimestamp);
        }
    } else {
        String[] mapped = fileNameMapper.mapFileName(r.getName());
        if (mapped != null && mapped.length > 0) {
            long modTime = defaultTimestamp;
            if (millis < 0 && r.isExists()) {
                modTime = r.getLastModified();
            }
            for (int i = 0; i < mapped.length; i++) {
                touch(getProject().resolveFile(mapped[i]), modTime);
            }
        }
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:23,代码来源:Touch.java

示例4: setSrcResource

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:ant,代码行数:24,代码来源:Unpack.java

示例5: execute

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * validate, then hand off to the subclass
 * @throws BuildException on error
 */
@Override
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.");
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:21,代码来源:Pack.java

示例6: expandResource

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * This method is to be overridden by extending unarchival tasks.
 *
 * @param srcR      the source resource
 * @param dir       the destination directory
 * @since Ant 1.7
 */
@Override
protected void expandResource(Resource srcR, File dir) {
    if (!srcR.isExists()) {
        throw new BuildException("Unable to untar "
                                 + srcR.getName()
                                 + " as the it does not exist",
                                 getLocation());
    }

    try (InputStream i = srcR.getInputStream()) {
        expandStream(srcR.getName(), i, dir);
    } catch (IOException ioe) {
        throw new BuildException("Error while expanding " + srcR.getName(),
                                 ioe, getLocation());
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:24,代码来源:Untar.java

示例7: processResources

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Styles all existing resources.
 *
 * @param stylesheet style sheet to use
 * @since Ant 1.7
 */
private void processResources(final Resource stylesheet) {
    for (final Resource r : resources) {
        if (!r.isExists()) {
            continue;
        }
        File base = baseDir;
        String name = r.getName();
        final FileProvider fp = r.as(FileProvider.class);
        if (fp != null) {
            final FileResource f = ResourceUtils.asFileResource(fp);
            base = f.getBaseDir();
            if (base == null) {
                name = f.getFile().getAbsolutePath();
            }
        }
        process(base, name, destDir, stylesheet);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:25,代码来源:XSLTProcess.java

示例8: compareContent

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Compare the content of two Resources. A nonexistent Resource's
 * content is "less than" that of an existing Resource; a directory-type
 * Resource's content is "less than" that of a file-type Resource.
 * @param r1 the Resource whose content is to be compared.
 * @param r2 the other Resource whose content is to be compared.
 * @param text true if the content is to be treated as text and
 *        differences in kind of line break are to be ignored.
 * @return a negative integer, zero, or a positive integer as the first
 *         argument is less than, equal to, or greater than the second.
 * @throws IOException if the Resources cannot be read.
 * @since Ant 1.7
 */
public static int compareContent(final Resource r1, final Resource r2, final boolean text) throws IOException {
    if (r1.equals(r2)) {
        return 0;
    }
    final boolean e1 = r1.isExists();
    final boolean e2 = r2.isExists();
    if (!(e1 || e2)) {
        return 0;
    }
    if (e1 != e2) {
        return e1 ? 1 : -1;
    }
    final boolean d1 = r1.isDirectory();
    final boolean d2 = r2.isDirectory();
    if (d1 && d2) {
        return 0;
    }
    if (d1 || d2) {
        return d1 ? -1 : 1;
    }
    return text ? textCompare(r1, r2) : binaryCompare(r1, r2);
}
 
开发者ID:apache,项目名称:ant,代码行数:36,代码来源:ResourceUtils.java

示例9: nextResource

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private void nextResource() throws IOException {
    closeCurrent();
    while (iter.hasNext()) {
        Resource r = iter.next();
        if (!r.isExists()) {
            continue;
        }
        log("Concatenating " + r.toLongString(), Project.MSG_VERBOSE);
        try {
            currentStream = new BufferedInputStream(r.getInputStream());
            return;
        } catch (IOException eyeOhEx) {
            if (!ignoreErrors) {
                log("Failed to get input stream for " + r, Project.MSG_ERR);
                throw eyeOhEx;
            }
        }
    }
    eof = true;
}
 
开发者ID:apache,项目名称:ant,代码行数:21,代码来源:ConcatResourceInputStream.java

示例10: processJars

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Process all JARs.
 */
private void processJars() {
  log("Starting scan.", verboseLevel);
  long start = System.currentTimeMillis();

  @SuppressWarnings("unchecked")
  Iterator<Resource> iter = (Iterator<Resource>) jarResources.iterator();
  int checked = 0;
  int errors = 0;
  while (iter.hasNext()) {
    final Resource r = iter.next();
    if (!r.isExists()) { 
      throw new BuildException("JAR resource does not exist: " + r.getName());
    }
    if (!(r instanceof FileResource)) {
      throw new BuildException("Only filesystem resource are supported: " + r.getName()
          + ", was: " + r.getClass().getName());
    }

    File jarFile = ((FileResource) r).getFile();
    if (! checkJarFile(jarFile) ) {
      errors++;
    }
    checked++;
  }

  log(String.format(Locale.ROOT, 
      "Scanned %d JAR file(s) for licenses (in %.2fs.), %d error(s).",
      checked, (System.currentTimeMillis() - start) / 1000.0, errors),
      errors > 0 ? Project.MSG_ERR : Project.MSG_INFO);
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:LicenseCheckTask.java

示例11: handleResources

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private void handleResources(Handler h) {
    for (Resource r : resources) {
        if (!r.isExists()) {
            log(r + " does not exist", Project.MSG_WARN);
        }
        if (r.isDirectory()) {
            log(r + " is a directory; length may not be meaningful", Project.MSG_WARN);
        }
        h.handle(r);
    }
    h.complete();
}
 
开发者ID:apache,项目名称:ant,代码行数:13,代码来源:Length.java

示例12: contentEquals

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Compares the contents of two Resources.
 *
 * @param r1 the Resource whose content is to be compared.
 * @param r2 the other Resource whose content is to be compared.
 * @param text true if the content is to be treated as text and
 *        differences in kind of line break are to be ignored.
 *
 * @return true if the content of the Resources is the same.
 *
 * @throws IOException if the Resources cannot be read.
 * @since Ant 1.7
 */
public static boolean contentEquals(final Resource r1, final Resource r2, final boolean text) throws IOException {
    if (r1.isExists() != r2.isExists()) {
        return false;
    }
    if (!r1.isExists()) {
        // two not existing files are equal
        return true;
    }
    // should the following two be switched?  If r1 and r2 refer to the same file,
    // isn't their content equal regardless of whether that file is a directory?
    if (r1.isDirectory() || r2.isDirectory()) {
        // don't want to compare directory contents for now
        return false;
    }
    if (r1.equals(r2)) {
        return true;
    }
    if (!text) {
        final long s1 = r1.getSize();
        final long s2 = r2.getSize();
        if (s1 != Resource.UNKNOWN_SIZE && s2 != Resource.UNKNOWN_SIZE
                && s1 != s2) {
            return false;
        }
    }
    return compareContent(r1, r2, text) == 0;
}
 
开发者ID:apache,项目名称:ant,代码行数:41,代码来源:ResourceUtils.java

示例13: execute

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void execute() throws BuildException {
    super.execute();
    try {
        for (int i = 0; i < rcs.size(); i++) {
            ResourceCollection rc = (ResourceCollection) rcs.elementAt(i);  
            Iterator<Resource> resources = rc.iterator();
            while (resources.hasNext()) {
                Resource r = (Resource) resources.next();
                if (!r.isExists()) {
                    continue;
                }
                if (r instanceof FileResource) {
                    FileResource fr = (FileResource) r;
                    String baseDir = fr.getBaseDir().getAbsolutePath();
                    String file = fr.getFile().getAbsolutePath();
                    file = file.substring(baseDir.length(), file.length());
                    String[] parts = file.split("/");
                    if (parts.length<=1) {
                        parts = file.split("\\\\");
                    }
                    if (parts.length <= 1) {
                        throw new BuildException("Unable to recognize the path separator for src file: " + file);
                    }
                    String[] specificParts = new String[parts.length-1];
                    System.arraycopy(parts, 0, specificParts, 0, specificParts.length);
                    String specificFilePart = StringUtils.join(specificParts, '/') + "/license.txt";
                    File specificFile = new File(licenseDir, specificFilePart);
                    File specificDestinationFile = new File(destDir, specificFilePart);
                    if (specificFile.exists()) {
                        fileUtils.copyFile(specificFile, specificDestinationFile);
                        continue;
                    }
                    
                    String[] generalParts = new String[3];
                    System.arraycopy(parts, 0, generalParts, 0, 3);
                    String generalFilePart = StringUtils.join(generalParts, '/') + "/license.txt";
                    File generalFile = new File(licenseDir, generalFilePart);
                    if (generalFile.exists()) {
                        fileUtils.copyFile(generalFile, specificDestinationFile);
                        continue;
                    }
                    
                    String[] moreGeneralParts = new String[2];
                    System.arraycopy(parts, 0, moreGeneralParts, 0, 2);
                    String moreGeneralFilePart = StringUtils.join(moreGeneralParts, '/') + "/license.txt";
                    File moreGeneralFile = new File(licenseDir, moreGeneralFilePart);
                    if (moreGeneralFile.exists()) {
                        fileUtils.copyFile(moreGeneralFile, specificDestinationFile);
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new BuildException(e);
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:58,代码来源:DependencyLicenseCopy.java

示例14: execute

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Execute the task.
 */
@Override
public void execute() throws BuildException {
  log("Starting scan.", verboseLevel);
  long start = System.currentTimeMillis();

  setupIvy();

  int numErrors = 0;
  if ( ! verifySortedCoordinatesPropertiesFile(centralizedVersionsFile)) {
    ++numErrors;
  }
  if ( ! verifySortedCoordinatesPropertiesFile(ignoreConflictsFile)) {
    ++numErrors;
  }
  collectDirectDependencies();
  if ( ! collectVersionConflictsToIgnore()) {
    ++numErrors;
  }

  int numChecked = 0;

  @SuppressWarnings("unchecked")
  Iterator<Resource> iter = (Iterator<Resource>)ivyXmlResources.iterator();
  while (iter.hasNext()) {
    final Resource resource = iter.next();
    if ( ! resource.isExists()) {
      throw new BuildException("Resource does not exist: " + resource.getName());
    }
    if ( ! (resource instanceof FileResource)) {
      throw new BuildException("Only filesystem resources are supported: " 
          + resource.getName() + ", was: " + resource.getClass().getName());
    }

    File ivyXmlFile = ((FileResource)resource).getFile();
    try {
      if ( ! checkIvyXmlFile(ivyXmlFile)) {
        ++numErrors;
      }
      if ( ! resolveTransitively(ivyXmlFile)) {
        ++numErrors;
      }
      if ( ! findLatestConflictVersions()) {
        ++numErrors;
      }
    } catch (Exception e) {
      throw new BuildException("Exception reading file " + ivyXmlFile.getPath() + " - " + e.toString(), e);
    }
    ++numChecked;
  }

  log("Checking for orphans in " + centralizedVersionsFile.getName(), verboseLevel);
  for (Map.Entry<String,Dependency> entry : directDependencies.entrySet()) {
    String coordinateKey = entry.getKey();
    if ( ! entry.getValue().directlyReferenced) {
      log("ORPHAN coordinate key '" + coordinateKey + "' in " + centralizedVersionsFile.getName()
          + " is not found in any " + IVY_XML_FILENAME + " file.",
          Project.MSG_ERR);
      ++numErrors;
    }
  }

  int numConflicts = emitConflicts();

  int messageLevel = numErrors > 0 ? Project.MSG_ERR : Project.MSG_INFO;
  log("Checked that " + centralizedVersionsFile.getName() + " and " + ignoreConflictsFile.getName()
      + " have lexically sorted '/org/name' keys and no duplicates or orphans.",
      messageLevel);
  log("Scanned " + numChecked + " " + IVY_XML_FILENAME + " files for rev=\"${/org/name}\" format.",
      messageLevel);
  log("Found " + numConflicts + " indirect dependency version conflicts.");
  log(String.format(Locale.ROOT, "Completed in %.2fs., %d error(s).",
                    (System.currentTimeMillis() - start) / 1000.0, numErrors),
      messageLevel);

  if (numConflicts > 0 || numErrors > 0) {
    throw new BuildException("Lib versions check failed. Check the logs.");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:82,代码来源:LibVersionsCheckTask.java

示例15: zipDir

import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
 * Add a directory to the zip stream.
 * @param dir  the directory to add to the archive
 * @param zOut the stream to write to
 * @param vPath the name this entry shall have in the archive
 * @param mode the Unix permissions to set.
 * @param extra ZipExtraFields to add
 * @throws IOException on error
 * @since Ant 1.8.0
 */
protected void zipDir(final Resource dir, final ZipOutputStream zOut, final String vPath,
                      final int mode, final ZipExtraField[] extra)
    throws IOException {
    if (doFilesonly) {
        logWhenWriting("skipping directory " + vPath
                       + " for file-only archive",
                       Project.MSG_VERBOSE);
        return;
    }
    if (addedDirs.get(vPath) != null) {
        // don't add directories we've already added.
        // no warning if we try, it is harmless in and of itself
        return;
    }

    logWhenWriting("adding directory " + vPath, Project.MSG_VERBOSE);
    addedDirs.put(vPath, vPath);

    if (!skipWriting) {
        final ZipEntry ze = new ZipEntry(vPath);

        // ZIPs store time with a granularity of 2 seconds, round up
        final int millisToAdd = roundUp ? ROUNDUP_MILLIS : 0;

        if (fixedModTime != null) {
            ze.setTime(modTimeMillis);
        } else if (dir != null && dir.isExists()) {
            ze.setTime(dir.getLastModified() + millisToAdd);
        } else {
            ze.setTime(System.currentTimeMillis() + millisToAdd);
        }
        ze.setSize(0);
        ze.setMethod(ZipEntry.STORED);
        // This is faintly ridiculous:
        ze.setCrc(EMPTY_CRC);
        ze.setUnixMode(mode);

        if (extra != null) {
            ze.setExtraFields(extra);
        }

        zOut.putNextEntry(ze);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:55,代码来源:Zip.java


注:本文中的org.apache.tools.ant.types.Resource.isExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。