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

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

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

Jar介绍

暂无

代码示例

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

  1. /**
  2. * @see aQute.bnd.service.diff.Differ#diff(aQute.lib.resource.Jar,
  3. * aQute.lib.resource.Jar)
  4. */
  5. public Tree tree(File newer) throws Exception {
  6. Jar jnewer = new Jar(newer);
  7. try {
  8. return tree(jnewer);
  9. }
  10. finally {
  11. jnewer.close();
  12. }
  13. }

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

  1. public void setTranslation(Jar jar) throws Exception {
  2. Manifest m = jar.getManifest();
  3. if (m == null)
  4. return;
  5. String path = m.getMainAttributes()
  6. .getValue(Constants.BUNDLE_LOCALIZATION);
  7. if (path == null)
  8. path = org.osgi.framework.Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
  9. path += ".properties";
  10. Resource propsResource = jar.getResource(path);
  11. if (propsResource != null) {
  12. try (InputStream in = propsResource.openInputStream()) {
  13. translation.load(in);
  14. }
  15. }
  16. }

代码示例来源:origin: reficio/p2-maven-plugin

  1. private void populateJar(Analyzer analyzer, File outputFile) throws Exception {
  2. Jar jar = analyzer.getJar();
  3. jar.setManifest(analyzer.calcManifest());
  4. try {
  5. jar.write(outputFile);
  6. } finally {
  7. jar.close();
  8. }
  9. }

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

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

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

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

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

  1. protected String getName(Jar jar) throws Exception {
  2. String name = jar.getBsn();
  3. if (name == null) {
  4. name = jar.getName();
  5. if (name.equals("dot") && jar.getSource() != null)
  6. name = jar.getSource()
  7. .getName();
  8. }
  9. String version = jar.getVersion();
  10. if (version == null)
  11. version = "0.0.0";
  12. return name + "-" + version;
  13. }

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

  1. public boolean analyzeJar(Analyzer analyzer) throws Exception {
  2. Jar jar = analyzer.getJar();
  3. Map<String,Resource> dir = jar.getDirectories().get(root);
  4. if (dir == null || dir.isEmpty()) {
  5. Resource resource = jar.getResource(root);
  6. if (resource != null)
  7. process(analyzer, root, resource);
  8. return false;
  9. }
  10. for (Iterator<Map.Entry<String,Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
  11. Map.Entry<String,Resource> entry = i.next();
  12. String path = entry.getKey();
  13. Resource resource = entry.getValue();
  14. if (paths.matcher(path).matches()) {
  15. process(analyzer, path, resource);
  16. }
  17. }
  18. return false;
  19. }

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

  1. String findPath(String name, String[] args, boolean fullPathName) {
  2. if (args.length > 3) {
  3. warning("Invalid nr of arguments to " + name + " " + Arrays.asList(args) + ", syntax: ${" + name
  4. + " (; reg-expr (; replacement)? )? }");
  5. return null;
  6. String del = "";
  7. Pattern expr = Pattern.compile(regexp);
  8. for (Iterator<String> e = dot.getResources().keySet().iterator(); e.hasNext();) {
  9. String path = e.next();
  10. if (!fullPathName) {
  11. Matcher m = expr.matcher(path);
  12. if (m.matches()) {
  13. if (replace != null)
  14. path = m.replaceAll(replace);

代码示例来源:origin: org.apache.felix/maven-bundle-plugin

  1. Analyzer analyzer = getAnalyzer( project, dependencyGraph, instructions, new Properties(), getClasspath( project, dependencyGraph ) );
  2. Jar osgiJar = new Jar( project.getArtifactId(), project.getArtifact().getFile() );
  3. "Using existing OSGi bundle for " + project.getGroupId() + ":" + project.getArtifactId() + ":"
  4. + project.getVersion() );
  5. String exportHeader = osgiJar.getManifest().getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE );
  6. exportedPackages = analyzer.parseHeader( exportHeader ).keySet();
  7. FileUtils.copyFile( project.getArtifact().getFile(), outputFile );
  8. exportedPackages = analyzer.getExports().keySet();
  9. Manifest manifest = analyzer.getJar().getManifest();
  10. osgiJar.setManifest( manifest );
  11. osgiJar.write( outputFile );
  12. analyzer.close();
  13. osgiJar.close();

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

  1. Parameters namesection = parseHeader(getProperties().getProperty(NAMESECTION));
  2. Instructions instructions = new Instructions(namesection);
  3. Set<String> resources = new HashSet<String>(dot.getResources().keySet());
  4. Attributes attrs = manifest.getAttributes(path);
  5. if (attrs == null) {
  6. attrs = new Attributes();
  7. manifest.getEntries().put(path, attrs);
  8. setProperty("@", path);
  9. try {
  10. String processed = getReplacer().process(property.getValue());
  11. attrs.putValue(property.getKey(), processed);

代码示例来源:origin: org.apache.felix/maven-bundle-plugin

  1. private boolean isOsgi( Jar jar ) throws Exception
  2. {
  3. if ( jar.getManifest() != null )
  4. {
  5. return jar.getManifest().getMainAttributes().getValue( Analyzer.BUNDLE_NAME ) != null;
  6. }
  7. return false;
  8. }

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

  1. this.analyzer = analyzer;
  2. Manifest manifest = analyzer.getJar().getManifest();
  3. if (manifest != null && manifest.getMainAttributes().getValue(Constants.BUNDLE_MANIFESTVERSION) != null) {
  4. exports = new Packages();
  5. for (Map.Entry<String,Attrs> entry : OSGiHeader.parseHeader(
  6. manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE)).entrySet())
  7. exports.put(analyzer.getPackageRef(entry.getKey()), entry.getValue());
  8. } else
  9. exports = analyzer.getContained();
  10. for (Clazz c : analyzer.getClassspace().values()) {
  11. if (c.isPublic() || c.isProtected()) {
  12. PackageRef packageName = c.getClassName().getPackageRef();

代码示例来源:origin: org.apache.felix/maven-bundle-plugin

  1. public static void writeManifest( Analyzer analyzer, File outputFile, boolean niceManifest,
  2. boolean exportScr, File scrLocation, BuildContext buildContext, Log log ) throws Exception
  3. Properties properties = analyzer.getProperties();
  4. Jar jar = analyzer.getJar();
  5. Manifest manifest = jar.getManifest();
  6. if ( outputFile.exists() && properties.containsKey( "Merge-Headers" ) )
  7. manifest = new Manifest();
  8. InputStream inputStream = new FileInputStream( outputFile );
  9. try
  10. manifest.read( inputStream );
  11. Instructions instructions = new Instructions( ExtList.from( analyzer.getProperty("Merge-Headers") ) );
  12. mergeManifest( instructions, manifest, analyzerManifest );

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

  1. public String getVersion() throws Exception {
  2. check();
  3. Manifest m = getManifest();
  4. if (m == null)
  5. return null;
  6. String s = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
  7. if (s == null)
  8. return null;
  9. return s.trim();
  10. }

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

  1. public void setManifest(File file) throws IOException {
  2. check();
  3. FileInputStream fin = new FileInputStream(file);
  4. try {
  5. Manifest m = new Manifest(fin);
  6. setManifest(m);
  7. }
  8. finally {
  9. fin.close();
  10. }
  11. }

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

  1. public Manifest getManifest() throws Exception {
  2. check();
  3. if (manifest == null) {
  4. Resource manifestResource = getResource(manifestName);
  5. if (manifestResource != null) {
  6. try (InputStream in = manifestResource.openInputStream()) {
  7. manifest = new Manifest(in);
  8. }
  9. }
  10. }
  11. return manifest;
  12. }

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

  1. /**
  2. * Add all the resources in the given jar that match the given filter.
  3. *
  4. * @param sub the jar
  5. * @param filter a pattern that should match the resoures in sub to be added
  6. */
  7. public boolean addAll(Jar sub, Instruction filter, String destination) {
  8. check();
  9. boolean dupl = false;
  10. for (String name : sub.getResources()
  11. .keySet()) {
  12. if (manifestName.equals(name))
  13. continue;
  14. if (filter == null || filter.matches(name) ^ filter.isNegated())
  15. dupl |= putResource(Processor.appendPath(destination, name), sub.getResource(name), true);
  16. }
  17. return dupl;
  18. }

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

  1. /**
  2. * Visit each class on the class path.
  3. *
  4. * @param visitor the visitor
  5. */
  6. public void visit(ClassVisitor visitor) throws Exception {
  7. try (Analyzer analyzer = new Analyzer()) {
  8. for (File f : entries) {
  9. try (Jar jar = new Jar(f)) {
  10. for (String path : jar.getResources()
  11. .keySet()) {
  12. if (path.endsWith(".class")) {
  13. Resource r = jar.getResource(path);
  14. Clazz c = new Clazz(analyzer, path, r);
  15. c.parseClassFile();
  16. visitor.visit(c);
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }

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

  1. public boolean analyzeJar(Analyzer analyzer) throws Exception {
  2. Parameters map = analyzer.parseHeader(analyzer.getProperty(Constants.METATYPE));
  3. Jar jar = analyzer.getJar();
  4. for (String name : map.keySet()) {
  5. Collection<Clazz> metatypes = analyzer.getClasses("", QUERY.ANNOTATED.toString(), Meta.OCD.class.getName(), //
  6. QUERY.NAMED.toString(), name //
  7. );
  8. for (Clazz c : metatypes) {
  9. jar.putResource("OSGI-INF/metatype/" + c.getFQN() + ".xml", new MetaTypeReader(c, analyzer));
  10. }
  11. }
  12. return false;
  13. }
  14. }

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

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

相关文章