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


Java Resource类代码示例

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


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

示例1: getResourcesToAdd

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
@Override
protected ArchiveState getResourcesToAdd(ResourceCollection[] rcs, File zipFile, boolean needsUpdate) throws BuildException {
  if (skipWriting) {
      // this pass is only there to construct the merged
      // manifest this means we claim an update was needed and
      // only include the manifests, skipping any uptodate
      // checks here defering them for the second run
      Resource[][] manifests = grabManifests(rcs);
      int count = 0;
      for (int i = 0; i < manifests.length; i++) {
          count += manifests[i].length;
      }
      log("found a total of " + count + " manifests in "
          + manifests.length + " resource collections",
          Project.MSG_VERBOSE);
      return new ArchiveState(true, manifests);
  }

  return super.getResourcesToAdd(rcs, zipFile, needsUpdate);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PatchedJar.java

示例2: isSelected

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public boolean isSelected(Resource r)
{
    if (!(r instanceof ZipResource))
    {
        return true;
    }
    
    ZipResource zip = (ZipResource)r;
    if (zip.getName().startsWith("META-INF"))
    {
        return false;
    }
    return true;
}
 
开发者ID:HuaweiBigData,项目名称:StreamCQL,代码行数:19,代码来源:JarResourceSelector.java

示例3: getUnixMode

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Determine a Resource's Unix mode or return the given default
 * value if not available.
 */
private int getUnixMode(final Resource r, final ZipFile zf, final int defaultMode) {

    int unixMode = defaultMode;
    if (zf != null) {
        final ZipEntry ze = zf.getEntry(r.getName());
        unixMode = ze.getUnixMode();
        if ((unixMode == 0 || unixMode == UnixStat.DIR_FLAG)
            && !preserve0Permissions) {
            unixMode = defaultMode;
        }
    } else if (r instanceof ArchiveResource) {
        unixMode = ((ArchiveResource) r).getMode();
    }
    return unixMode;
}
 
开发者ID:apache,项目名称:ant,代码行数:20,代码来源:Zip.java

示例4: resolveRefid

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
private void resolveRefid() {
    try {
        if (getProject() == null) {
            throw new BuildException("Cannot retrieve refid; project unset");
        }
        Object o = getProject().getReference(refid);
        if (!(o instanceof Resource)) {
            if (o instanceof ResourceCollection) {
                ResourceCollection rc = (ResourceCollection) o;
                if (rc.size() == 1) {
                    o = rc.iterator().next();
                }
            } else {
                throw new BuildException("Illegal value at '%s': %s", refid,
                    o);
            }
        }
        this.resource = (Resource) o;
    } finally {
        refid = null;
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:23,代码来源:ResourceContains.java

示例5: copyUsingStreams

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
private static void copyUsingStreams(final Resource source, final Resource dest,
                                     final boolean append, final Project project)
    throws IOException {

    if (areSame(source, dest)) {
        // copying the "same" file to itself will corrupt the file, so we skip it
        log(project, "Skipping (self) copy of " + source +  " to " + dest);
        return;
    }
    try (InputStream in = source.getInputStream();
         OutputStream out = getOutputStream(dest, append, project)) {

        final byte[] buffer = new byte[FileUtils.BUF_SIZE];
        int count = 0;
        do {
            out.write(buffer, 0, count);
            count = in.read(buffer, 0, buffer.length);
        } while (count != -1);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:21,代码来源:ResourceUtils.java

示例6: iterator

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Fulfill the ResourceCollection contract.
 * @return an Iterator of Resources.
 */
@Override
public final synchronized Iterator<Resource> iterator() {
    if (isReference()) {
        return ((AbstractResourceCollectionWrapper) getCheckedRef()).iterator();
    }
    dieOnCircularReference();
    return new FailFast(this, createIterator());
}
 
开发者ID:apache,项目名称:ant,代码行数:13,代码来源:AbstractResourceCollectionWrapper.java

示例7: execute

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/** {@inheritDoc}. */
public void execute() {
    if (length != null && adjust != null) {
        throw new BuildException(
                "length and adjust are mutually exclusive options");
    }
    if (length == null && adjust == null) {
        length = ZERO;
    }
    if (path == null) {
        throw new BuildException(NO_CHILD);
    }
    for (Resource r : path) {
        File f = r.as(FileProvider.class).getFile();
        if (shouldProcess(f)) {
            process(f);
        }
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:20,代码来源:Truncate.java

示例8: addDirectoryResource

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Add a directory entry to the archive using a specified
 * Unix-mode and the default mode for its parent directories (if
 * necessary).
 */
private void addDirectoryResource(final Resource r, String name, final String prefix,
                                  final File base, final ZipOutputStream zOut,
                                  final int defaultDirMode, final int thisDirMode)
    throws IOException {

    if (!name.endsWith("/")) {
        name = name + "/";
    }

    final int nextToLastSlash = name.lastIndexOf('/', name.length() - 2);
    if (nextToLastSlash != -1) {
        addParentDirs(base, name.substring(0, nextToLastSlash + 1),
                      zOut, prefix, defaultDirMode);
    }
    zipDir(r, zOut, prefix + name, thisDirMode,
           r instanceof ZipResource
           ? ((ZipResource) r).getExtraFields() : null);
}
 
开发者ID:apache,项目名称:ant,代码行数:24,代码来源:Zip.java

示例9: isSelected

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Return true if this Resource is selected.
 * @param r the Resource to check.
 * @return whether the Resource was selected.
 * @throws BuildException if an error occurs.
 */
public boolean isSelected(Resource r) {
    if ((clazz == null) == (type == null)) {
        throw new BuildException(ONE_ONLY);
    }
    Class<?> c = clazz;
    if (type != null) {
        if (project == null) {
            throw new BuildException(
                "No project set for InstanceOf ResourceSelector; the type attribute is invalid.");
        }
        AntTypeDefinition d = ComponentHelper.getComponentHelper(
            project).getDefinition(ProjectHelper.genComponentName(uri, type));
        if (d == null) {
            throw new BuildException("type %s not found.",type);
        }
        try {
            c = d.innerGetTypeClass();
        } catch (ClassNotFoundException e) {
            throw new BuildException(e);
        }
    }
    return c.isAssignableFrom(r.getClass());
}
 
开发者ID:apache,项目名称:ant,代码行数:30,代码来源:InstanceOf.java

示例10: setPermissions

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Sets permissions on a {@link Resource} - doesn't do anything
 * for unsupported resource types.
 *
 * <p>Supported types are:</p>
 * <ul>
 *  <li>any {@link FileProvider}</li>
 *  <li>{@link ArchiveResource}</li>
 * </ul>
 *
 * @param r the resource to set permissions for
 * @param permissions the permissions
 * @param posixNotSupportedCallback optional callback that is
 * invoked for a file provider resource if the file-system holding
 * the file doesn't support PosixFilePermissions. The Path
 * corresponding to the file is passed to the callback.
 * @throws IOException if something goes wrong
 */
public static void setPermissions(Resource r, Set<PosixFilePermission> permissions,
                                  Consumer<Path> posixNotSupportedCallback)
    throws IOException {
    FileProvider f = r.as(FileProvider.class);
    if (f != null) {
        Path p = f.getFile().toPath();
        PosixFileAttributeView view =
            Files.getFileAttributeView(p, PosixFileAttributeView.class);
        if (view != null) {
            view.setPermissions(permissions);
        } else if (posixNotSupportedCallback != null) {
            posixNotSupportedCallback.accept(p);
        }
    } else if (r instanceof ArchiveResource) {
        ((ArchiveResource) r).setMode(modeFromPermissions(permissions,
                                                          FileType.of(r)));
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:37,代码来源:PermissionUtils.java

示例11: isOneOf

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
private boolean isOneOf(Object o, Resource importedResource,
                        File importedFile, URL importedURL) {
    if (o.equals(importedResource) || o.equals(importedFile)
        || o.equals(importedURL)) {
        return true;
    }
    if (o instanceof Resource) {
        if (importedFile != null) {
            FileProvider fp = ((Resource) o).as(FileProvider.class);
            if (fp != null && fp.getFile().equals(importedFile)) {
                return true;
            }
        }
        if (importedURL != null) {
            URLProvider up = ((Resource) o).as(URLProvider.class);
            if (up != null && up.getURL().equals(importedURL)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:ant,代码行数:23,代码来源:ImportTask.java

示例12: getCollection

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Calculate the difference of the nested ResourceCollections.
 * @return a Collection of Resources.
 */
@Override
protected Collection<Resource> getCollection() {
    List<ResourceCollection> rcs = getResourceCollections();
    int size = rcs.size();
    if (size < 2) {
        throw new BuildException(
            "The difference of %d resource %s is undefined.", size,
            size == 1 ? "collection" : "collections");
    }
    Set<Resource> hs = new HashSet<>();
    List<Resource> al = new ArrayList<>();
    for (ResourceCollection rc : rcs) {
        for (Resource r : rc) {
            if (hs.add(r)) {
                al.add(r);
            } else {
                al.remove(r);
            }
        }
    }
    return al;
}
 
开发者ID:apache,项目名称:ant,代码行数:27,代码来源:Difference.java

示例13: compareTo

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Compare this FileResource to another Resource.
 * @param another the other Resource against which to compare.
 * @return a negative integer, zero, or a positive integer as this FileResource
 *         is less than, equal to, or greater than the specified Resource.
 */
@Override
public int compareTo(Resource another) {
    if (isReference()) {
        return getCheckedRef().compareTo(another);
    }
    if (this.equals(another)) {
        return 0;
    }
    FileProvider otherFP = another.as(FileProvider.class);
    if (otherFP != null) {
        File f = getFile();
        if (f == null) {
            return -1;
        }
        File of = otherFP.getFile();
        if (of == null) {
            return 1;
        }
        int compareFiles = f.compareTo(of);
        return compareFiles != 0 ? compareFiles
            : getName().compareTo(another.getName());
    }
    return super.compareTo(another);
}
 
开发者ID:apache,项目名称:ant,代码行数:31,代码来源:FileResource.java

示例14: 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

示例15: getProperties

import org.apache.tools.ant.types.Resource; //导入依赖的package包/类
/**
 * Returns properties from a specified properties file.
 *
 * @param resource The resource to load properties from.
 */
private Properties getProperties(Resource resource) {
    InputStream in = null;
    Properties props = new Properties();
    try {
        in = resource.getInputStream();
        props.load(in);
    } catch (IOException ioe) {
        if (getProject() != null) {
            getProject().log("getProperties failed, " + ioe.getMessage(), Project.MSG_ERR);
        } else {
            ioe.printStackTrace(); //NOSONAR
        }
    } finally {
        FileUtils.close(in);
    }

    return props;
}
 
开发者ID:apache,项目名称:ant,代码行数:24,代码来源:ReplaceTokens.java


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