本文整理了Java中aQute.bnd.osgi.Analyzer
类的一些代码示例,展示了Analyzer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analyzer
类的具体详情如下:
包路径:aQute.bnd.osgi.Analyzer
类名称:Analyzer
暂无
代码示例来源:origin: reficio/p2-maven-plugin
private static Analyzer instantiateAnalyzer(ArtifactBundlerRequest request) throws Exception {
Analyzer analyzer = new Analyzer();
analyzer.setJar(getInputJarWithBlankManifest(request));
return analyzer;
}
代码示例来源:origin: reficio/p2-maven-plugin
private static void setPackageOptions(Analyzer analyzer) {
analyzer.setProperty(Analyzer.IMPORT_PACKAGE, "*;resolution:=optional");
String export = analyzer.calculateExportsFromContents(analyzer.getJar());
analyzer.setProperty(Analyzer.EXPORT_PACKAGE, export);
}
代码示例来源:origin: reficio/p2-maven-plugin
private void populateJar(Analyzer analyzer, File outputFile) throws Exception {
Jar jar = analyzer.getJar();
jar.setManifest(analyzer.calcManifest());
try {
jar.write(outputFile);
} finally {
jar.close();
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
/**
* @return {@code true} if the {@code -resourceonly} instruction is set,
* {@code false} otherwise
*/
boolean isResourceOnly() {
return isTrue(getProperty(RESOURCEONLY));
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
public void addClasspath(Collection<?> jars) throws IOException {
for (Object jar : jars) {
if (jar instanceof Jar)
addClasspath((Jar) jar);
else if (jar instanceof File)
addClasspath((File) jar);
else if (jar instanceof String)
addClasspath(getFile((String) jar));
else
error("Cannot convert to JAR to add to classpath %s. Not a File, Jar, or String", jar);
}
}
代码示例来源:origin: biz.aQute/bndlib
Matcher m = BINDNAME.matcher(method.getName());
if (m.matches())
def.name = m.group(2);
else
analyzer.error("Invalid name for bind method %s", method.getName());
def.service = Clazz.objectDescriptorToFQN(def.service);
} else {
Matcher m = BINDDESCRIPTOR.matcher(method.getDescriptor().toString());
if (m.matches()) {
def.service = Descriptors.binaryToFQN(m.group(3));
} else
analyzer.error(
"In component %s, multiple references with the same name: %s. Previous def: %s, this def: %s",
component.implementation, component.references.get(def.name), def.service, "");
代码示例来源:origin: biz.aQute/bndlib
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/bndlib
String bind = rdef.bind;
for (int i = 0; i < matches.length; i += 2) {
Matcher m = Pattern.compile(matches[i]).matcher(bind);
if (m.matches()) {
value = m.replaceFirst(matches[i + 1]);
break;
Matcher matcher = BINDDESCRIPTOR.matcher(descriptor);
if (matcher.matches()) {
String type = matcher.group(2);
if (rdef.service.equals(Clazz.objectDescriptorToFQN(type)) || type.equals("Ljava/util/Map;")
|| type.equals("Lorg/osgi/framework/ServiceReference;")) {
analyzer.error(
"A related method to %s from the reference %s has no proper prototype for class %s. Expected void %s(%s s [,Map m] | ServiceReference r)",
rdef.bind, value, component.implementation, value, rdef.service);
代码示例来源:origin: biz.aQute/bndlib
private void process(Analyzer analyzer, String path, Resource resource) {
try {
InputStream in = resource.openInputStream();
Set<String> set = analyze(in);
in.close();
for (Iterator<String> r = set.iterator(); r.hasNext();) {
PackageRef pack = analyzer.getPackageRef(r.next());
if (!QN.matcher(pack.getFQN()).matches())
analyzer.warning("Package does not seem a package in spring resource (" + path + "): " + pack);
if (!analyzer.getReferred().containsKey(pack))
analyzer.getReferred().put(pack);
}
}
catch (Exception e) {
analyzer.error("Unexpected exception in processing spring resources(" + path + "): " + e);
}
}
代码示例来源:origin: biz.aQute.bnd/bndlib
analyzer.error(
"AD for %s.%s uses an array of collections in return type (%s), Metatype allows either Vector or array",
clazz.getClassName().getFQN(), defined.getName(), defined.getType().getFQN());
Matcher m = COLLECTION.matcher(rtype);
if (m.matches()) {
rtype = Clazz.objectDescriptorToFQN(m.group(3));
ad.cardinality = Integer.MIN_VALUE;
TypeRef typeRef = analyzer.getTypeRefFromFQN(rtype);
try {
Clazz c = analyzer.findClass(typeRef);
if (c != null && c.isEnum()) {
parseOptionValues(c, ad.options);
analyzer.error(
"AD for %s.%s Can not parse option values from type (%s), %s",
clazz.getClassName().getFQN(), defined.getName(), defined.getType().getFQN(), e.getMessage());
代码示例来源:origin: biz.aQute.bnd/bndlib
Analyzer a = new Analyzer();
Clazz clazz = new Clazz(a, "", new URLResource(url));
Map<String,String> d = ComponentAnnotationReader.getDefinition(clazz);
Matcher matcher = REFERENCE.matcher(key);
if (matcher.matches()) {
Reference r = new Reference();
r.name = matcher.group(1);
r.set = findMethod(matcher.group(2));
r.unset = findMethod(matcher.group(3));
代码示例来源:origin: biz.aQute/bndlib
public boolean analyzeJar(Analyzer analyzer) throws Exception {
Jar jar = analyzer.getJar();
Map<String,Resource> dir = jar.getDirectories().get("META-INF/spring");
if (dir == null || dir.isEmpty())
return false;
for (Iterator<Entry<String,Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
Entry<String,Resource> entry = i.next();
String path = entry.getKey();
Resource resource = entry.getValue();
if (SPRING_SOURCE.matcher(path).matches()) {
try {
InputStream in = resource.openInputStream();
Set<CharSequence> set = analyze(in);
in.close();
for (Iterator<CharSequence> r = set.iterator(); r.hasNext();) {
PackageRef pack = analyzer.getPackageRef((String) r.next());
if (!QN.matcher(pack.getFQN()).matches())
analyzer.warning("Package does not seem a package in spring resource (" + path + "): "
+ pack);
if (!analyzer.getReferred().containsKey(pack))
analyzer.getReferred().put(pack, new Attrs());
}
}
catch (Exception e) {
analyzer.error("Unexpected exception in processing spring resources(" + path + "): " + e);
}
}
}
return false;
}
代码示例来源:origin: biz.aQute/bndlib
/**
*
*/
protected void doDeactivate() {
if (!LIFECYCLEDESCRIPTOR.matcher(method.getDescriptor().toString()).matches())
analyzer.error(
"Deactivate method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s",
clazz, method.getDescriptor());
else {
component.deactivate = method.getName();
}
}
代码示例来源:origin: biz.aQute/bndlib
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();
代码示例来源:origin: biz.aQute/bndlib
/**
* 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();
}
}
代码示例来源:origin: org.arquillian.liferay/arquillian-deployment-generator-bnd
try (Analyzer analyzer = new Analyzer()) {
bndFile = getBndFile(testClass);
analyzer.loadProperties(commonBndFile));
analyzerProperties.putAll(analyzer.loadProperties(bndFile));
analyzer.setProperties(analyzerProperties);
Jar jar = new Jar(
javaArchive.getName(), zipExporter.exportAsInputStream());
analyzer.setJar(jar);
Manifest firstPassManifest = new Manifest(
javaArchive.get(MANIFEST_PATH).getAsset().openStream());
firstPassManifest.getMainAttributes().remove(
new Attributes.Name("Import-Package"));
analyzer.mergeManifest(firstPassManifest);
Manifest manifest = analyzer.calcManifest();
manifest.write(baos);
代码示例来源:origin: org.apache.felix/maven-bundle-plugin
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 );
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
Parameters namesection = parseHeader(getProperties().getProperty(NAMESECTION));
Instructions instructions = new Instructions(namesection);
Set<String> resources = new HashSet<>(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);
} finally {
unsetProperty("@");
warning("The instruction %s in %s did not match any resources", instr.getKey(), NAMESECTION);
代码示例来源:origin: biz.aQute.bnd/bnd
Analyzer wrapper = new Analyzer(this);
try {
wrapper.use(this);
addClose(wrapper);
wrapper.addClasspath(f);
wrapper.setJar(file);
File outputFile = wrapper.getOutputFile(options.output());
if (outputFile.getCanonicalFile().equals(file.getCanonicalFile())) {
wrapper.setImportPackage("*;resolution:=optional");
wrapper.setExportPackage("*");
warning("Using defaults for wrap, which means no export versions");
wrapper.setProperties(p);
else {
error("No valid property file: %s", p);
wrapper.setBundleSymbolicName(options.bsn());
wrapper.setBundleVersion(options.version());
Manifest m = wrapper.calcManifest();
if (wrapper.isOk()) {
wrapper.getJar().setManifest(m);
wrapper.save(outputFile, options.force());
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
/**
* 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);
}
}
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!