aQute.lib.osgi.Jar.getResource()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(299)

本文整理了Java中aQute.lib.osgi.Jar.getResource()方法的一些代码示例,展示了Jar.getResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jar.getResource()方法的具体详情如下:
包路径:aQute.lib.osgi.Jar
类名称:Jar
方法名:getResource

Jar.getResource介绍

暂无

代码示例

代码示例来源:origin: biz.aQute/bnd

private void copyInfoResource(Jar source, Jar dest, String type) {
  if ( source.getResources().containsKey(type) && !dest.getResources().containsKey(type))
    dest.putResource(type, source.getResource(type));
}

代码示例来源:origin: biz.aQute/aQute.bnd

public Manifest getManifest() throws IOException {
  if (manifest == null) {
    Resource manifestResource = getResource("META-INF/MANIFEST.MF");
    if (manifestResource != null) {
      InputStream in = manifestResource.openInputStream();
      manifest = new Manifest(in);
      in.close();
    }
  }
  return manifest;
}

代码示例来源:origin: biz.aQute/aQute.bnd

/**
 * Add all the resources in the given jar that match the given filter.
 * 
 * @param sub
 *            the jar
 * @param filter
 *            a pattern that should match the resoures in sub to be added
 */
public boolean addAll(Jar sub, Pattern filter) {
  boolean dupl = false;
  for (String name : sub.getResources().keySet()) {
    if ("META-INF/MANIFEST.MF".equals(name))
      continue;
    if (filter == null || filter.matcher(name).matches())
      dupl |= putResource(name, sub.getResource(name), true);
  }
  return dupl;
}

代码示例来源:origin: biz.aQute/bnd

public Manifest getManifest() throws Exception {
  if (manifest == null) {
    Resource manifestResource = getResource("META-INF/MANIFEST.MF");
    if (manifestResource != null) {
      InputStream in = manifestResource.openInputStream();
      manifest = new Manifest(in);
      in.close();
    }
  }
  return manifest;
}

代码示例来源:origin: biz.aQute/aQute.bnd

public void write(OutputStream out) throws IOException {
  ZipOutputStream jout = nomanifest ? new ZipOutputStream(out) : new JarOutputStream(out);
  Set<String> done = new HashSet<String>();
  Set<String> directories = new HashSet<String>();
  if (doNotTouchManifest) {
    writeResource(jout, directories, "META-INF/MANIFEST.MF",
        getResource("META-INF/MANIFEST.MF"));
    done.add("META-INF/MANIFEST.MF");
  } else if (!nomanifest)
    doManifest(done, jout);
  for (Map.Entry<String, Resource> entry : getResources().entrySet()) {
    // Skip metainf contents
    if (!done.contains(entry.getKey()))
      writeResource(jout, directories, (String) entry.getKey(),
          (Resource) entry.getValue());
  }
  jout.finish();
}

代码示例来源:origin: biz.aQute/bnd

/**
 * Locate a resource on the class path.
 * 
 * @param path
 *            Path of the reosurce
 * @return A resource or <code>null</code>
 */
public Resource findResource(String path) {
  for (Jar entry : getClasspath()) {
    Resource r = entry.getResource(path);
    if (r != null)
      return r;
  }
  return null;
}

代码示例来源:origin: biz.aQute/bnd

public void write(OutputStream out) throws Exception {
  ZipOutputStream jout = nomanifest || doNotTouchManifest ? new ZipOutputStream(out)
      : new JarOutputStream(out);
  Set<String> done = new HashSet<String>();
  Set<String> directories = new HashSet<String>();
  if (doNotTouchManifest) {
    Resource r = getResource("META-INF/MANIFEST.MF");
    if (r != null) {
      writeResource(jout, directories, "META-INF/MANIFEST.MF", r);
      done.add("META-INF/MANIFEST.MF");
    }
  } else
    doManifest(done, jout);
  for (Map.Entry<String, Resource> entry : getResources().entrySet()) {
    // Skip metainf contents
    if (!done.contains(entry.getKey()))
      writeResource(jout, directories, (String) entry.getKey(),
          (Resource) entry.getValue());
  }
  jout.finish();
}

代码示例来源:origin: biz.aQute/bnd

public boolean analyzeJar(Analyzer analyzer) throws Exception {
  Jar jar = analyzer.getJar();
  Map<String,Resource> dir = jar.getDirectories().get(root);
  if (dir == null || dir.isEmpty()) {
    Resource resource  = jar.getResource(root);
    if ( resource != null )
      process(analyzer, root, resource);
    return false;
  }
  for (Iterator<Map.Entry<String,Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
    Map.Entry<String,Resource> entry = i.next();
    String path = entry.getKey();
    Resource resource = entry.getValue();
    if (paths.matcher(path).matches()) {
      process(analyzer, path, resource);
    }
  }
  return false;
}

代码示例来源:origin: biz.aQute/bnd

/**
 * Add all the resources in the given jar that match the given filter.
 * 
 * @param sub
 *            the jar
 * @param filter
 *            a pattern that should match the resoures in sub to be added
 */
public boolean addAll(Jar sub, Instruction filter, String destination) {
  boolean dupl = false;
  for (String name : sub.getResources().keySet()) {
    if ("META-INF/MANIFEST.MF".equals(name))
      continue;
    if (filter == null || filter.matches(name) != filter.isNegated())
      dupl |= putResource(Processor.appendPath(destination, name), sub.getResource(name),
          true);
  }
  return dupl;
}

代码示例来源:origin: biz.aQute/bnd

out.println(path);
Resource r = jar.getResource(path);
if (r != null) {
  InputStreamReader ir = new InputStreamReader(r.openInputStream(),

代码示例来源:origin: biz.aQute/bnd

void applyPatch(String old, String patch, String newer) throws Exception {
  Jar a = new Jar(new File(old));
  Jar b = new Jar(new File(patch));
  Manifest bm = b.getManifest();
  String patchDelete = bm.getMainAttributes().getValue("Patch-Delete");
  String patchVersion = bm.getMainAttributes().getValue("Patch-Version");
  if (patchVersion == null) {
    error("To patch, you must provide a patch bundle.\nThe given " + patch
        + " bundle does not contain the Patch-Version header");
    return;
  }
  Collection<String> delete = split(patchDelete);
  Set<String> paths = new HashSet<String>(a.getResources().keySet());
  paths.removeAll(delete);
  for (String path : paths) {
    Resource br = b.getResource(path);
    if (br == null)
      b.putResource(path, a.getResource(path));
  }
  bm.getMainAttributes().putValue("Bundle-Version", patchVersion);
  b.write(new File(newer));
  a.close();
  b.close();
}

代码示例来源:origin: biz.aQute/aQute.bnd

/**
 * Create the imports/exports by parsing
 * 
 * @throws IOException
 */
void analyzeClasspath() throws IOException {
  classpathExports = newHashMap();
  for (Iterator<Jar> c = getClasspath().iterator(); c.hasNext();) {
    Jar current = c.next();
    checkManifest(current);
    for (Iterator<String> j = current.getDirectories().keySet()
        .iterator(); j.hasNext();) {
      String dir = j.next();
      Resource resource = current.getResource(dir + "/packageinfo");
      if (resource != null) {
        InputStream in = resource.openInputStream();
        try {
          String version = parsePackageInfo(in);
          setPackageInfo(dir, "version", version);
        } finally {
          in.close();
        }
      }
    }
  }
}

代码示例来源:origin: biz.aQute/aQute.bnd

void applyPatch(String old, String patch, String newer) throws Exception {
  Jar a = new Jar(new File(old));
  Jar b = new Jar(new File(patch));
  Manifest bm = b.getManifest();
  String patchDelete = bm.getMainAttributes().getValue("Patch-Delete");
  String patchVersion = bm.getMainAttributes().getValue("Patch-Version");
  if (patchVersion == null) {
    error("To patch, you must provide a patch bundle.\nThe given "
        + patch
        + " bundle does not contain the Patch-Version header");
    return;
  }
  Collection<String> delete = split(patchDelete);
  Set<String> paths = new HashSet<String>(a.getResources().keySet());
  paths.removeAll(delete);
  for (String path : paths) {
    Resource br = b.getResource(path);
    if (br == null)
      b.putResource(path, a.getResource(path));
  }
  bm.getMainAttributes().putValue("Bundle-Version", patchVersion);
  b.write(new File(newer));
  a.close();
  b.close();
}

代码示例来源:origin: biz.aQute/bnd

/**
 * Create the imports/exports by parsing
 * 
 * @throws IOException
 */
void analyzeClasspath() throws Exception {
  classpathExports = newHashMap();
  for (Iterator<Jar> c = getClasspath().iterator(); c.hasNext();) {
    Jar current = c.next();
    checkManifest(current);
    for (Iterator<String> j = current.getDirectories().keySet().iterator(); j.hasNext();) {
      String dir = j.next();
      Resource resource = current.getResource(dir + "/packageinfo");
      if (resource != null) {
        InputStream in = resource.openInputStream();
        try {
          String version = parsePackageInfo(in);
          setPackageInfo(dir, VERSION_ATTRIBUTE, version);
        } finally {
          in.close();
        }
      }
    }
  }
}

代码示例来源:origin: biz.aQute/bnd

void createPatch(String old, String newer, String patch) throws Exception {
  Jar a = new Jar(new File(old));
  Manifest am = a.getManifest();
  Jar b = new Jar(new File(newer));
  Manifest bm = b.getManifest();
  Set<String> delete = newSet();
  for (String path : a.getResources().keySet()) {
    Resource br = b.getResource(path);
    if (br == null) {
      trace("DELETE    %s", path);
      delete.add(path);
    } else {
      Resource ar = a.getResource(path);
      if (isEqual(ar, br)) {
        trace("UNCHANGED %s", path);
        b.remove(path);
      } else
        trace("UPDATE    %s", path);
    }
  }
  bm.getMainAttributes().putValue("Patch-Delete", join(delete, ", "));
  bm.getMainAttributes().putValue("Patch-Version",
      am.getMainAttributes().getValue("Bundle-Version"));
  b.write(new File(patch));
  a.close();
  a.close();
}

代码示例来源:origin: biz.aQute/bnd

addClose(result);
trace("Received: %s", result.getName());
Resource errors = result.getResource("META-INF/errors");
Resource warnings = result.getResource("META-INF/warnings");
if (errors != null)
  parse(errors.openInputStream(), url.getFile(), getErrors());

代码示例来源:origin: biz.aQute/aQute.bnd

void createPatch(String old, String newer, String patch) throws Exception {
  Jar a = new Jar(new File(old));
  Manifest am = a.getManifest();
  Jar b = new Jar(new File(newer));
  Manifest bm = b.getManifest();
  Set<String> delete = newSet();
  for (String path : a.getResources().keySet()) {
    Resource br = b.getResource(path);
    if (br == null) {
      trace("DELETE    %s", path);
      delete.add(path);
    } else {
      Resource ar = a.getResource(path);
      if (isEqual(ar, br)) {
        trace("UNCHANGED %s", path);
        b.remove(path);
      } else
        trace("UPDATE    %s", path);
    }
  }
  bm.getMainAttributes().putValue("Patch-Delete", join(delete, ", "));
  bm.getMainAttributes().putValue("Patch-Version",
      am.getMainAttributes().getValue("Bundle-Version"));
  b.write(new File(patch));
  a.close();
  a.close();
}

代码示例来源:origin: biz.aQute/bnd

public String _sha1(String args[]) throws Exception {
    Macro.verifyCommand(args, _sha1Help,
        new Pattern[] { null, null, Pattern.compile("base64|hex") }, 2, 3);
    Digester<SHA1> digester = SHA1.getDigester();
    Resource r = dot.getResource(args[1]);
    if (r == null)
      throw new FileNotFoundException("From sha1, not found " + args[1]);

    IO.copy(r.openInputStream(), digester);
    return Base64.encodeBase64(digester.digest().digest());
  }
}

代码示例来源:origin: biz.aQute/bnd

public String _md5(String args[]) throws Exception {
  Macro.verifyCommand(args, _md5Help,
      new Pattern[] { null, null, Pattern.compile("base64|hex") }, 2, 3);
  Digester<MD5> digester = MD5.getDigester();
  Resource r = dot.getResource(args[1]);
  if (r == null)
    throw new FileNotFoundException("From " + digester + ", not found " + args[1]);
  IO.copy(r.openInputStream(), digester);
  boolean hex = args.length > 2 && args[2].equals("hex");
  if (hex)
    return Hex.toHexString(digester.digest().digest());
  else
    return Base64.encodeBase64(digester.digest().digest());
}

代码示例来源:origin: biz.aQute/bnd

String path = args[i++];
Resource r = j.getResource(path);
if (r == null)
  error("No such resource: %s in %s", path, f);

相关文章