public List<Jar> getClasspath() { if (firstUse) { firstUse = false; String cp = getProperty(CLASSPATH); if (cp != null) for (String s : split(cp)) { Jar jar = getJarFromName(s, "getting classpath"); if (jar != null) addClasspath(jar); } } return classpath; }
/** * Check if manadatory properties are present, otherwise generate default. * * @param analyzer bnd analyzer * @param jar bnd jar * @param symbolicName bundle symbolic name */ private static void checkMandatoryProperties( final Analyzer analyzer, final Jar jar, final String symbolicName ) { final String importPackage = analyzer.getProperty( Analyzer.IMPORT_PACKAGE ); if( importPackage == null || importPackage.trim().length() == 0 ) { analyzer.setProperty( Analyzer.IMPORT_PACKAGE, "*;resolution:=optional" ); } final String exportPackage = analyzer.getProperty( Analyzer.EXPORT_PACKAGE ); if( exportPackage == null || exportPackage.trim().length() == 0 ) { analyzer.setProperty( Analyzer.EXPORT_PACKAGE, analyzer.calculateExportsFromContents( jar ) ); } final String localSymbolicName = analyzer.getProperty( Analyzer.BUNDLE_SYMBOLICNAME, symbolicName ); analyzer.setProperty( Analyzer.BUNDLE_SYMBOLICNAME, generateSymbolicName( localSymbolicName ) ); }
public void setClasspath(String[] classpath) { for (int i = 0; i < classpath.length; i++) { Jar jar = getJarFromName(classpath[i], " setting classpath"); if (jar != null) addClasspath(jar); } }
/** * * @return */ boolean isResourceOnly() { return isTrue(getProperty(RESOURCEONLY)); }
return false; } else { Analyzer analyzer = new Analyzer(); try { analyzer.setPedantic(isPedantic()); analyzer.setJar(bundle); Jar dot = analyzer.getJar(); analyzer.setProperties(properties); analyzer.putAll(additional, false); if (analyzer.getProperty(Analyzer.IMPORT_PACKAGE) == null) analyzer.setProperty(Analyzer.IMPORT_PACKAGE, "*;resolution:=optional"); if (analyzer.getProperty(Analyzer.BUNDLE_SYMBOLICNAME) == null) { Pattern p = Pattern.compile("(" + Verifier.SYMBOLICNAME.pattern() + ")(-[0-9])?.*\\.jar"); analyzer.setProperty(Analyzer.BUNDLE_SYMBOLICNAME, base); if (analyzer.getProperty(Analyzer.EXPORT_PACKAGE) == null) { String export = analyzer.calculateExportsFromContents(dot); analyzer.setProperty(Analyzer.EXPORT_PACKAGE, export); analyzer.setClasspath(classpath); analyzer.mergeManifest(dot.getManifest());
if (!analyzed) { analyzed = true; classpathExports = newHashMap(); activator = getProperty(BUNDLE_ACTIVATOR); bundleClasspath = parseHeader(getProperty(BUNDLE_CLASSPATH)); analyzeClasspath(); classspace = analyzeBundleClasspath(dot, bundleClasspath, contained, referred, uses); for (AnalyzerPlugin plugin : getPlugins(AnalyzerPlugin.class)) { if (plugin instanceof AnalyzerPlugin) { AnalyzerPlugin analyzer = (AnalyzerPlugin) plugin; boolean reanalyze = analyzer.analyzeJar(this); if (reanalyze) classspace = analyzeBundleClasspath(dot, bundleClasspath, contained, referred, uses); } catch (Exception e) { error("Plugin Analyzer " + analyzer + " throws exception " + e); e.printStackTrace(); error("The default package '.' is not permitted by the Import-Package syntax. \n" + " This can be caused by compile errors in Eclipse because Eclipse creates \n" + "valid class files regardless of compile errors.\n" + "The following package(s) import from the default package " + getUsedBy("."));
Map<String, Map<String, String>> values = new Analyzer().parseHeader(value); for (String packageName : packages) { Map<String, String> map = values.get(packageName);
properties.put(Analyzer.PLUGIN, ANALYZER_PLUGIN_NAMES); final Analyzer analyzer = new Analyzer(); analyzer.setJar(jar); analyzer.setProperties(properties); try { File file = toFile(value); analyzer.addClasspath(file); } catch (IOException e) { LOG.warn("Failed to get File for " + value + ". " + e, e); analyzer.mergeManifest(manifest); analyzer.calcManifest(); Map<String, Map<String, String>> values = new Analyzer().parseHeader(importPackages); Map<String, Map<String, String>> exports = new Analyzer().parseHeader(exportPackages); for (Map.Entry<String, Map<String, String>> entry : exports.entrySet()) { String packageName = entry.getKey();
analyze(); Manifest manifest = new Manifest(); Attributes main = manifest.getMainAttributes(); .equalsIgnoreCase(getProperty(NOEXTRAHEADERS)); main.putValue(TOOL, "Bnd-" + getVersion()); main.putValue(BND_LASTMODIFIED, "" + System.currentTimeMillis()); String exportHeader = printClauses(exports, "uses:|include:|exclude:|mandatory:|" + IMPORT_DIRECTIVE, true); Map<String, Map<String, String>> temp = removeKeys(imports, "java."); if (!temp.isEmpty()) { main.putValue(IMPORT_PACKAGE, printClauses(temp, "resolution:")); } else { main.remove(IMPORT_PACKAGE); temp = newMap(contained); temp.keySet().removeAll(exports.keySet()); main.putValue(PRIVATE_PACKAGE, printClauses(temp, "")); else main.remove(PRIVATE_PACKAGE); main.putValue(IGNORE_PACKAGE, printClauses(ignored, "")); } else { main.remove(IGNORE_PACKAGE);
analyze(); Manifest manifest = new Manifest(); Attributes main = manifest.getMainAttributes(); boolean noExtraHeaders = "true".equalsIgnoreCase(getProperty(NOEXTRAHEADERS)); System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")"); main.putValue(TOOL, "Bnd-" + getBndVersion()); main.putValue(BND_LASTMODIFIED, "" + System.currentTimeMillis()); String exportHeader = printClauses(exports, true); Map<String, Map<String, String>> temp = removeKeys(imports, "java."); if (!temp.isEmpty()) { main.putValue(IMPORT_PACKAGE, printClauses(temp)); } else { main.remove(IMPORT_PACKAGE); temp = newMap(contained); temp.keySet().removeAll(exports.keySet()); main.putValue(PRIVATE_PACKAGE, printClauses(temp)); else main.remove(PRIVATE_PACKAGE); main.putValue(IGNORE_PACKAGE, printClauses(ignored)); } else { main.remove(IGNORE_PACKAGE);
/** * Specifically for Maven * * @param properties * the properties */ public static Properties getManifest(File dirOrJar) throws Exception { Analyzer analyzer = new Analyzer(); try { analyzer.setJar(dirOrJar); Properties properties = new Properties(); properties.put(IMPORT_PACKAGE, "*"); properties.put(EXPORT_PACKAGE, "*"); analyzer.setProperties(properties); Manifest m = analyzer.calcManifest(); Properties result = new Properties(); for (Iterator<Object> i = m.getMainAttributes().keySet().iterator(); i.hasNext();) { Attributes.Name name = (Attributes.Name) i.next(); result.put(name.toString(), m.getMainAttributes().getValue(name)); } return result; } finally { analyzer.close(); } }
Analyzer analyzer = new Analyzer(); analyzer.setPedantic(isPedantic()); analyzer.setJar(jar); analyzer.analyze(); if ((options & USES) != 0) { out.println("[USES]"); printMapOfSets(new TreeMap<String, Set<String>>(analyzer.getUses())); out.println(); printMapOfSets(invertMapOfCollection(analyzer.getUses()));
Map<String, Map<String, String>> namesection = parseHeader(getProperties().getProperty( NAMESECTION)); Set<Entry<Instruction, Map<String, String>>> instructions = Instruction setProperty("@", next.getKey()); try { String processed = getReplacer().process(property.getValue()); attrs.putValue(property.getKey(), processed); } finally { unsetProperty("@"); warning("The instruction %s in %s did not match any resources", instr.getKey(), NAMESECTION);
return; exportVersion = cleanupVersion(exportVersion); String importRange = currentAttributes.get(VERSION_ATTRIBUTE); boolean impl = isTrue(currentAttributes.get(PROVIDE_DIRECTIVE)); try { setProperty("@", exportVersion); importRange = cleanupVersion(importRange); importRange = getReplacer().process(importRange); } else importRange = getVersionPolicy(impl); unsetProperty("@");
public boolean analyzeJar(Analyzer analyzer) throws Exception { Map<String, Map<String, String>> map = analyzer.parseHeader(analyzer .getProperty(Constants.METATYPE)); Jar jar = analyzer.getJar(); for (String name : map.keySet()) { Collection<Clazz> metatypes = analyzer.getClasses("", QUERY.ANNOTATION.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; } }
protected void begin() { super.begin(); updateModified(getBndLastModified(), "bnd last modified"); String doNotCopy = getProperty(DONOTCOPY); if (doNotCopy != null) Analyzer.doNotCopy = Pattern.compile(doNotCopy); verifyManifestHeadersCase(getProperties()); }
/** * Add the uses clauses. This method iterates over the exports and cal * * @param exports * @param uses * @throws MojoExecutionException */ void doUses(Map<String, Map<String, String>> exports, Map<String, Set<String>> uses, Map<String, Map<String, String>> imports) { if ("true".equalsIgnoreCase(getProperty(NOUSES))) return; for (Iterator<String> i = exports.keySet().iterator(); i.hasNext();) { String packageName = i.next(); setProperty(CURRENT_PACKAGE, packageName); try { doUses(packageName, exports, uses, imports); } finally { unsetProperty(CURRENT_PACKAGE); } } }
/** * Find some more information about imports in manifest and other places. */ void augmentImports() { for (String packageName : imports.keySet()) { setProperty(CURRENT_PACKAGE, packageName); try { Map<String, String> importAttributes = imports.get(packageName); Map<String, String> exporterAttributes = classpathExports.get(packageName); if (exporterAttributes == null) exporterAttributes = exports.get(packageName); if (exporterAttributes != null) { augmentVersion(importAttributes, exporterAttributes); augmentMandatory(importAttributes, exporterAttributes); if (exporterAttributes.containsKey(IMPORT_DIRECTIVE)) importAttributes.put(IMPORT_DIRECTIVE, exporterAttributes.get(IMPORT_DIRECTIVE)); } fixupAttributes(importAttributes); removeAttributes(importAttributes); } finally { unsetProperty(CURRENT_PACKAGE); } } }
/** * Analyzer has an empty default but the builder has a * as default. * * @return */ protected String getImportPackages() { return getProperty(IMPORT_PACKAGE); }