public void setTranslation(Jar jar) throws Exception { Manifest m = jar.getManifest(); if (m == null) return; String path = m.getMainAttributes() .getValue(Constants.BUNDLE_LOCALIZATION); if (path == null) path = org.osgi.framework.Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME; path += ".properties"; Resource propsResource = jar.getResource(path); if (propsResource != null) { try (InputStream in = propsResource.openInputStream()) { translation.load(in); } } }
private void populateJar(Analyzer analyzer, File outputFile) throws Exception { Jar jar = analyzer.getJar(); jar.setManifest(analyzer.calcManifest()); try { jar.write(outputFile); } finally { jar.close(); } }
public boolean rename(String oldPath, String newPath) { check(); Resource resource = remove(oldPath); if (resource == null) return false; return putResource(newPath, resource); }
private void copyInfoResource(Jar source, Jar dest, String type) { if (source.getResources() .containsKey(type) && !dest.getResources() .containsKey(type)) dest.putResource(type, source.getResource(type)); }
protected String getName(Jar jar) throws Exception { String name = jar.getBsn(); if (name == null) { name = jar.getName(); if (name.equals("dot") && jar.getSource() != null) name = jar.getSource() .getName(); } String version = jar.getVersion(); if (version == null) version = "0.0.0"; return name + "-" + version; }
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; }
String findPath(String name, String[] args, boolean fullPathName) { if (args.length > 3) { warning("Invalid nr of arguments to " + name + " " + Arrays.asList(args) + ", syntax: ${" + name + " (; reg-expr (; replacement)? )? }"); return null; String del = ""; Pattern expr = Pattern.compile(regexp); for (Iterator<String> e = dot.getResources().keySet().iterator(); e.hasNext();) { String path = e.next(); if (!fullPathName) { Matcher m = expr.matcher(path); if (m.matches()) { if (replace != null) path = m.replaceAll(replace);
Analyzer analyzer = getAnalyzer( project, dependencyGraph, instructions, new Properties(), getClasspath( project, dependencyGraph ) ); Jar osgiJar = new Jar( project.getArtifactId(), project.getArtifact().getFile() ); "Using existing OSGi bundle for " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() ); String exportHeader = osgiJar.getManifest().getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE ); exportedPackages = analyzer.parseHeader( exportHeader ).keySet(); FileUtils.copyFile( project.getArtifact().getFile(), outputFile ); exportedPackages = analyzer.getExports().keySet(); Manifest manifest = analyzer.getJar().getManifest(); osgiJar.setManifest( manifest ); osgiJar.write( outputFile ); analyzer.close(); osgiJar.close();
Parameters namesection = parseHeader(getProperties().getProperty(NAMESECTION)); Instructions instructions = new Instructions(namesection); Set<String> resources = new HashSet<String>(dot.getResources().keySet()); Attributes attrs = manifest.getAttributes(path); if (attrs == null) { attrs = new Attributes(); manifest.getEntries().put(path, attrs); setProperty("@", path); try { String processed = getReplacer().process(property.getValue()); attrs.putValue(property.getKey(), processed);
private boolean isOsgi( Jar jar ) throws Exception { if ( jar.getManifest() != null ) { return jar.getManifest().getMainAttributes().getValue( Analyzer.BUNDLE_NAME ) != null; } return false; }
this.analyzer = analyzer; Manifest manifest = analyzer.getJar().getManifest(); if (manifest != null && manifest.getMainAttributes().getValue(Constants.BUNDLE_MANIFESTVERSION) != null) { exports = new Packages(); for (Map.Entry<String,Attrs> entry : OSGiHeader.parseHeader( manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE)).entrySet()) exports.put(analyzer.getPackageRef(entry.getKey()), entry.getValue()); } else exports = analyzer.getContained(); for (Clazz c : analyzer.getClassspace().values()) { if (c.isPublic() || c.isProtected()) { PackageRef packageName = c.getClassName().getPackageRef();
public static void writeManifest( Analyzer analyzer, File outputFile, boolean niceManifest, boolean exportScr, File scrLocation, BuildContext buildContext, Log log ) throws Exception Properties properties = analyzer.getProperties(); Jar jar = analyzer.getJar(); Manifest manifest = jar.getManifest(); if ( outputFile.exists() && properties.containsKey( "Merge-Headers" ) ) manifest = new Manifest(); InputStream inputStream = new FileInputStream( outputFile ); try manifest.read( inputStream ); Instructions instructions = new Instructions( ExtList.from( analyzer.getProperty("Merge-Headers") ) ); mergeManifest( instructions, manifest, analyzerManifest );
public String getVersion() throws Exception { check(); Manifest m = getManifest(); if (m == null) return null; String s = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION); if (s == null) return null; return s.trim(); }
public void setManifest(File file) throws IOException { check(); FileInputStream fin = new FileInputStream(file); try { Manifest m = new Manifest(fin); setManifest(m); } finally { fin.close(); } }
public Manifest getManifest() throws Exception { check(); if (manifest == null) { Resource manifestResource = getResource(manifestName); if (manifestResource != null) { try (InputStream in = manifestResource.openInputStream()) { manifest = new Manifest(in); } } } return manifest; }
/** * 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) { check(); boolean dupl = false; for (String name : sub.getResources() .keySet()) { if (manifestName.equals(name)) continue; if (filter == null || filter.matches(name) ^ filter.isNegated()) dupl |= putResource(Processor.appendPath(destination, name), sub.getResource(name), true); } return dupl; }
/** * Visit each class on the class path. * * @param visitor the visitor */ public void visit(ClassVisitor visitor) throws Exception { try (Analyzer analyzer = new Analyzer()) { for (File f : entries) { try (Jar jar = new Jar(f)) { for (String path : jar.getResources() .keySet()) { if (path.endsWith(".class")) { Resource r = jar.getResource(path); Clazz c = new Clazz(analyzer, path, r); c.parseClassFile(); visitor.visit(c); } } } } } }
public boolean analyzeJar(Analyzer analyzer) throws Exception { Parameters map = analyzer.parseHeader(analyzer.getProperty(Constants.METATYPE)); Jar jar = analyzer.getJar(); for (String name : map.keySet()) { Collection<Clazz> metatypes = analyzer.getClasses("", QUERY.ANNOTATED.toString(), Meta.OCD.class.getName(), // QUERY.NAMED.toString(), name // ); for (Clazz c : metatypes) { jar.putResource("OSGI-INF/metatype/" + c.getFQN() + ".xml", new MetaTypeReader(c, analyzer)); } } return false; } }
public File saveBuild(Jar jar) throws Exception { try { File f = getOutputFile(jar.getBsn(), jar.getVersion()); String msg = ""; if (!f.exists() || f.lastModified() < jar.lastModified()) { reportNewer(f.lastModified(), jar); f.delete(); File fp = f.getParentFile(); if (!fp.isDirectory()) { if (!fp.exists() && !fp.mkdirs()) { throw new IOException("Could not create directory " + fp); } } jar.write(f); getWorkspace().changedFile(f); } else { msg = "(not modified since " + new Date(f.lastModified()) + ")"; } trace(jar.getName() + " (" + f.getName() + ") " + jar.getResources().size() + " " + msg); return f; } finally { jar.close(); } }