aQute.lib.osgi.Jar类的使用及代码示例

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

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

Jar介绍

暂无

代码示例

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

  1. void applyPatch(String old, String patch, String newer) throws Exception {
  2. Jar a = new Jar(new File(old));
  3. Jar b = new Jar(new File(patch));
  4. Manifest bm = b.getManifest();
  5. String patchDelete = bm.getMainAttributes().getValue("Patch-Delete");
  6. String patchVersion = bm.getMainAttributes().getValue("Patch-Version");
  7. if (patchVersion == null) {
  8. error("To patch, you must provide a patch bundle.\nThe given " + patch
  9. + " bundle does not contain the Patch-Version header");
  10. return;
  11. }
  12. Collection<String> delete = split(patchDelete);
  13. Set<String> paths = new HashSet<String>(a.getResources().keySet());
  14. paths.removeAll(delete);
  15. for (String path : paths) {
  16. Resource br = b.getResource(path);
  17. if (br == null)
  18. b.putResource(path, a.getResource(path));
  19. }
  20. bm.getMainAttributes().putValue("Bundle-Version", patchVersion);
  21. b.write(new File(newer));
  22. a.close();
  23. b.close();
  24. }

代码示例来源:origin: io.fabric8.fab/fab-core

  1. public Set<String> getPackages() throws IOException {
  2. if (packages == null) {
  3. if (getExtension().equals("jar") || getExtension().equals("zip")) {
  4. aQute.lib.osgi.Jar jar = new aQute.lib.osgi.Jar(getJarFile());
  5. try {
  6. packages = new HashSet<String>(jar.getPackages());
  7. } finally {
  8. jar.close();
  9. }
  10. } else {
  11. return Collections.emptySet();
  12. }
  13. }
  14. return packages;
  15. }

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

  1. public boolean rename(String oldPath, String newPath) {
  2. Resource resource = remove(oldPath);
  3. if (resource == null)
  4. return false;
  5. return putResource(newPath, resource);
  6. }

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

  1. /**
  2. * Cleanup the manifest for writing. Cleaning up consists of adding a space
  3. * after any \n to prevent the manifest to see this newline as a delimiter.
  4. *
  5. * @param out
  6. * Output
  7. * @throws IOException
  8. */
  9. public void writeManifest(OutputStream out) throws Exception {
  10. writeManifest(getManifest(), out);
  11. }

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

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

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

  1. void createPatch(String old, String newer, String patch) throws Exception {
  2. Jar a = new Jar(new File(old));
  3. Manifest am = a.getManifest();
  4. Jar b = new Jar(new File(newer));
  5. Manifest bm = b.getManifest();
  6. Set<String> delete = newSet();
  7. for (String path : a.getResources().keySet()) {
  8. Resource br = b.getResource(path);
  9. if (br == null) {
  10. trace("DELETE %s", path);
  11. delete.add(path);
  12. } else {
  13. Resource ar = a.getResource(path);
  14. if (isEqual(ar, br)) {
  15. trace("UNCHANGED %s", path);
  16. b.remove(path);
  17. } else
  18. trace("UPDATE %s", path);
  19. }
  20. }
  21. bm.getMainAttributes().putValue("Patch-Delete", join(delete, ", "));
  22. bm.getMainAttributes().putValue("Patch-Version",
  23. am.getMainAttributes().getValue("Bundle-Version"));
  24. b.write(new File(patch));
  25. a.close();
  26. a.close();
  27. }

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

  1. /**
  2. * Release
  3. *
  4. * @param name
  5. * The respository name
  6. * @param test
  7. * Run testcases
  8. * @throws Exception
  9. */
  10. public void release(String name, boolean test) throws Exception {
  11. File[] jars = build(test);
  12. // If build fails jars will be null
  13. if (jars == null) {
  14. return;
  15. }
  16. for (File jar : jars) {
  17. Jar j = new Jar(jar);
  18. release(name, j);
  19. j.close();
  20. }
  21. }

代码示例来源:origin: org.fusesource.fabric/process-manager

  1. /**
  2. * Sets the executable class name in the given jar
  3. */
  4. protected void setMainClass(ProcessConfig config, File installDir, File jarFile, int id, String mainClass) throws Exception {
  5. File tmpFile = File.createTempFile("fuse-process-" + id, ".jar");
  6. Files.copy(jarFile, tmpFile);
  7. Jar jar = new Jar(tmpFile);
  8. Attributes attributes = jar.getManifest().getMainAttributes();
  9. attributes.putValue("Main-Class", mainClass);
  10. jar.write(jarFile);
  11. }

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

  1. public Jar getValidJar(URL url) throws Exception {
  2. InputStream in = url.openStream();
  3. try {
  4. Jar jar = new Jar(url.getFile().replace('/', '.'), in, System.currentTimeMillis());
  5. return getValidJar(jar, url.toString());
  6. } finally {
  7. in.close();
  8. }
  9. }

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

  1. public File saveBuild(Jar jar) throws Exception {
  2. try {
  3. String bsn = jar.getName();
  4. File f = getOutputFile(bsn);
  5. String msg = "";
  6. if (!f.exists() || f.lastModified() < jar.lastModified()) {
  7. reportNewer(f.lastModified(), jar);
  8. f.delete();
  9. if (!f.getParentFile().isDirectory())
  10. f.getParentFile().mkdirs();
  11. jar.write(f);
  12. getWorkspace().changedFile(f);
  13. } else {
  14. msg = "(not modified since " + new Date(f.lastModified()) + ")";
  15. }
  16. trace(jar.getName() + " (" + f.getName() + ") " + jar.getResources().size() + " " + msg);
  17. return f;
  18. } finally {
  19. jar.close();
  20. }
  21. }

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

  1. private void doExpand(Jar jar) throws IOException {
  2. if (getClasspath().size() == 0
  3. && (getProperty(EXPORT_PACKAGE) != null || getProperty(PRIVATE_PACKAGE) != null))
  4. warning("Classpath is empty. Private-Package and Export-Package can only expand from the classpath when there is one");
  5. Map<Instruction, Map<String, String>> privateMap = replaceWitInstruction(
  6. getHeader(PRIVATE_PACKAGE), PRIVATE_PACKAGE);
  7. Map<Instruction, Map<String, String>> exportMap = replaceWitInstruction(
  8. getHeader(EXPORT_PACKAGE), EXPORT_PACKAGE);
  9. if (isTrue(getProperty(Constants.UNDERTEST))) {
  10. privateMap.putAll(replaceWitInstruction(parseHeader(getProperty(
  11. Constants.TESTPACKAGES, "test;presence:=optional")),
  12. TESTPACKAGES));
  13. }
  14. if (!privateMap.isEmpty())
  15. doExpand(jar, "Private-Package, or -testpackages", privateMap, true);
  16. if (!exportMap.isEmpty()) {
  17. Jar exports = new Jar("exports");
  18. doExpand(exports, "Export-Package", exportMap, true);
  19. jar.addAll(exports);
  20. exports.close();
  21. }
  22. if (privateMap.isEmpty() && exportMap.isEmpty() && !isResourceOnly()) {
  23. warning("Neither Export-Package, Private-Package, -testpackages is set, therefore no packages will be included");
  24. }
  25. }

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

  1. try {
  2. File file = new File(args[i]);
  3. Jar jar = new Jar(file.getName(), file);
  4. try {
  5. for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
  6. String key = entry.getKey();
  7. Resource r = entry.getValue();
  8. jar.close();

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

  1. jar.write(out);
  2. } finally {
  3. out.close();
  4. trace("Submitted: %s to %s", jar.getName(), url);
  5. Jar result = new Jar(url.toExternalForm(), in);
  6. addClose(result);
  7. trace("Received: %s", result.getName());
  8. Resource errors = result.getResource("META-INF/errors");
  9. Resource warnings = result.getResource("META-INF/warnings");
  10. if (errors != null)
  11. parse(errors.openInputStream(), url.getFile(), getErrors());

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

  1. /**
  2. * Write out an entry, handling proper unicode and line length constraints
  3. *
  4. */
  5. private static void writeEntry(OutputStream out, String name, String value) throws IOException {
  6. int n = write(out, 0, name + ": ");
  7. n = write(out, n, value);
  8. write(out, 0, "\r\n");
  9. }

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

  1. /**
  2. * Make sure we have a manifest
  3. * @throws Exception
  4. */
  5. public void ensureManifest() throws Exception {
  6. if ( getManifest() != null)
  7. return;
  8. manifest = new Manifest();
  9. }

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

  1. /**
  2. * @param out
  3. * @param file
  4. * @throws IOException
  5. * @throws Exception
  6. */
  7. void doSingleFileLib(File file, Appendable out) throws IOException, Exception {
  8. Jar jar = new Jar(file);
  9. String bsn = jar.getBsn();
  10. System.out.println(bsn);
  11. String version = jar.getVersion();
  12. jar.close();
  13. if (bsn == null) {
  14. error("No valid bsn for %s", file);
  15. bsn = "not set";
  16. }
  17. if (version == null)
  18. version = "0";
  19. Version v = new Version(version);
  20. v = new Version(v.getMajor(), v.getMinor(), v.getMicro());
  21. out.append(bsn);
  22. out.append(";version=" + v + "\n"); // '[" + v + "," + v + "]'\n");
  23. }

代码示例来源:origin: io.fabric8.fab/fab-osgi

  1. public void run()
  2. {
  3. try
  4. {
  5. jar.write( pout );
  6. }
  7. catch( Exception e )
  8. {
  9. LOG.warn( "Bundle cannot be generated" );
  10. }
  11. finally
  12. {
  13. try
  14. {
  15. jar.close();
  16. pout.close();
  17. }
  18. catch( IOException ignore )
  19. {
  20. // if we get here something is very wrong
  21. LOG.error( "Bundle cannot be generated", ignore );
  22. }
  23. }
  24. }
  25. }.start();

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

  1. dirty = true;
  2. Manifest manifest = jar.getManifest();
  3. if (manifest == null)
  4. throw new IllegalArgumentException("No manifest in JAR: " + jar);
  5. if (!file.exists() || file.lastModified() < jar.lastModified()) {
  6. jar.write(file);
  7. reporter.progress("Updated " + file.getAbsolutePath());
  8. fireBundleAdded(jar, file);
  9. if (latest.exists() && latest.lastModified() < jar.lastModified()) {
  10. jar.write(latest);
  11. file = latest;

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

  1. out.println("Classpath used");
  2. for (Jar jar : getClasspath()) {
  3. out.printf("File : %s\n", jar.getSource());
  4. out.printf("File abs path : %s\n", jar.getSource()
  5. .getAbsolutePath());
  6. out.printf("Name : %s\n", jar.getName());
  7. Map<String, Map<String, Resource>> dirs = jar.getDirectories();
  8. for (Map.Entry<String, Map<String, Resource>> entry : dirs.entrySet()) {
  9. Map<String, Resource> dir = entry.getValue();
  10. dot.close();
  11. jar.close();

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

  1. public void write(OutputStream out) throws IOException {
  2. ZipOutputStream jout = nomanifest ? new ZipOutputStream(out) : new JarOutputStream(out);
  3. Set<String> done = new HashSet<String>();
  4. Set<String> directories = new HashSet<String>();
  5. if (doNotTouchManifest) {
  6. writeResource(jout, directories, "META-INF/MANIFEST.MF",
  7. getResource("META-INF/MANIFEST.MF"));
  8. done.add("META-INF/MANIFEST.MF");
  9. } else if (!nomanifest)
  10. doManifest(done, jout);
  11. for (Map.Entry<String, Resource> entry : getResources().entrySet()) {
  12. // Skip metainf contents
  13. if (!done.contains(entry.getKey()))
  14. writeResource(jout, directories, (String) entry.getKey(),
  15. (Resource) entry.getValue());
  16. }
  17. jout.finish();
  18. }

相关文章