public void prepare(Analyzer analyzer) { if (name == null) analyzer.error("No name for a reference"); if (version == null) version = AnnotationReader.V1_1; }
/** * */ protected void doDeactivate() { if (!ACTIVATEDESCRIPTOR.matcher(methodDescriptor).matches()) analyzer.error( "Deactivate method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s", clazz, methodDescriptor); else { component.deactivate = method; } }
/** * */ protected void doActivate() { if (!ACTIVATEDESCRIPTOR.matcher(methodDescriptor).matches()) analyzer.error( "Activate method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s", clazz, methodDescriptor); else { component.activate = method; } }
/** * */ protected void doModified() { if (!ACTIVATEDESCRIPTOR.matcher(methodDescriptor).matches()) analyzer.error( "Modified method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s", clazz, methodDescriptor); else { component.modified = method; } } /**
/** * Set the classpath for this analyzer by file. * * @param classpath * @throws IOException */ public void setClasspath(File[] classpath) throws IOException { List<Jar> list = new ArrayList<Jar>(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].exists()) { Jar current = new Jar(classpath[i]); list.add(current); } else { error("Missing file on classpath: %s", classpath[i]); } } for (Iterator<Jar> i = list.iterator(); i.hasNext();) { addClasspath(i.next()); } }
/** * Set the classpath for this analyzer by file. * * @param classpath * @throws IOException */ public void setClasspath(File[] classpath) throws IOException { List<Jar> list = new ArrayList<Jar>(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].exists()) { Jar current = new Jar(classpath[i]); list.add(current); } else { error("Missing file on classpath: " + classpath[i]); } } for (Iterator<Jar> i = list.iterator(); i.hasNext();) { addClasspath(i.next()); } }
public void annotation(Annotation annotation) { try { Meta.OCD ocd = annotation.getAnnotation(Meta.OCD.class); Meta.AD ad = annotation.getAnnotation(Meta.AD.class); if (ocd != null) { this.ocdAnnotation = annotation; } if (ad != null) { assert method != null; methods.put(method, ad); } } catch (Exception e) { reporter.error("Error during annotation parsing %s : %s", clazz, e); e.printStackTrace(); } }
/** * Ensure that we are running on the correct bnd. */ void doRequireBnd() { Map<String, String> require = OSGiHeader.parseProperties(getProperty(REQUIRE_BND)); if (require == null || require.isEmpty()) return; Hashtable<String, String> map = new Hashtable<String, String>(); map.put(Constants.VERSION_FILTER, getBndVersion()); for (String filter : require.keySet()) { try { Filter f = new Filter(filter); if (f.match(map)) continue; error("%s fails %s", REQUIRE_BND, require.get(filter)); } catch (Exception t) { error("%s with value %s throws exception", t, REQUIRE_BND, require); } } }
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();) { String pack = r.next(); if (!QN.matcher(pack).matches()) analyzer .warning("Package does not seem a package in spring resource (" + path + "): " + pack); if (!analyzer.getReferred().containsKey(pack)) analyzer.getReferred().put(pack, new LinkedHashMap<String,String>()); } } catch (Exception e) { analyzer .error("Unexpected exception in processing spring resources(" + path + "): " + e); } }
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.interfce);
@SuppressWarnings("unchecked") public boolean analyzeJar(Analyzer analyzer) throws Exception { Jar jar = analyzer.getJar(); Map dir = (Map) jar.getDirectories().get("META-INF/spring"); if ( dir == null || dir.isEmpty()) return false; for (Iterator i = dir.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); String path = (String) entry.getKey(); Resource resource = (Resource) entry.getValue(); if (SPRING_SOURCE.matcher(path).matches()) { try { InputStream in = resource.openInputStream(); Set set = analyze(in); in.close(); for (Iterator r = set.iterator(); r.hasNext();) { String pack = (String) r.next(); if ( !QN.matcher(pack).matches()) analyzer.warning("Package does not seem a package in spring resource ("+path+"): " + pack ); if (!analyzer.getReferred().containsKey(pack)) analyzer.getReferred().put(pack, new LinkedHashMap()); } } catch( Exception e ) { analyzer.error("Unexpected exception in processing spring resources("+path+"): " + e ); } } } return false; }
return jar; } catch (Exception e) { error("Exception in parsing jar file for " + from + ": " + name + " " + e);
return jar; } catch (Exception e) { error("Exception in parsing jar file for " + from + ": " + name + " " + e);
void prepare(Analyzer analyzer) { for (ReferenceDef ref : references.values()) { ref.prepare(analyzer); if (ref.version.compareTo(version) > 0) version = ref.version; } if (implementation == null) analyzer.error("No Implementation defined for component " + name); else analyzer.referTo(implementation); name = implementation; if (service != null && service.length > 0) { for (String interfaceName : service) analyzer.referTo(interfaceName); } else if (servicefactory != null && servicefactory) analyzer.warning("The servicefactory:=true directive is set but no service is provided, ignoring it"); }
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.interfce, "");
public void annotation(Annotation annotation) { try { java.lang.annotation.Annotation a = annotation.getAnnotation(); if (a instanceof Component) doComponent((Component) a, annotation); else if (a instanceof Activate) doActivate(); else if (a instanceof Deactivate) doDeactivate(); else if (a instanceof Modified) doModified(); else if (a instanceof Reference) doReference((Reference) a, annotation); } catch (Exception e) { e.printStackTrace(); analyzer.error("During generation of a component on class %s, exception %s", clazz, e); } }
analyzer.error("Missing super class for DS annotations: " + Clazz.pathToFqn(extendsClass) + " from " + c.getFQN()); } else {
/** * Create a Metatype and Designate record out of the given * configurations. * * @param name * @param config */ private boolean designate(String name, String config, boolean factory) { if (config == null) return false; for (String c : Processor.split(config)) { Clazz clazz = analyzer.getClassspace().get(Clazz.fqnToPath(c)); if (clazz != null) { analyzer.referTo(c); MetaTypeReader r = new MetaTypeReader(clazz, analyzer); r.setDesignate(name, factory); String rname = "OSGI-INF/metatype/" + name + ".xml"; analyzer.getJar().putResource(rname, r); } else { analyzer.error( "Cannot find designated configuration class %s for component %s", c, name); } } return true; }