Map<String,Map<String,String>> serviceComponents = newMap(); String header = getProperty(SERVICE_COMPONENT); Parameters sc = parseHeader(header); componentEntry(serviceComponents, name, info); error("Invalid " + Constants.SERVICE_COMPONENT + " header: %s %s, throws %s", name, info, e); throw e;
private void createComponentResource(Map<String, Map<String, String>> components, String name, Map<String, String> info) throws Exception { // We can override the name in the parameters if (info.containsKey(COMPONENT_NAME)) name = info.get(COMPONENT_NAME); // Assume the impl==name, but allow override String impl = name; if (info.containsKey(COMPONENT_IMPLEMENTATION)) impl = info.get(COMPONENT_IMPLEMENTATION); TypeRef implRef = analyzer.getTypeRefFromFQN(impl); // Check if such a class exists analyzer.referTo(implRef); boolean designate = designate(name, info.get(COMPONENT_DESIGNATE), false) || designate(name, info.get(COMPONENT_DESIGNATEFACTORY), true); // If we had a designate, we want a default configuration policy of // require. if (designate && info.get(COMPONENT_CONFIGURATION_POLICY) == null) info.put(COMPONENT_CONFIGURATION_POLICY, "require"); // We have a definition, so make an XML resources Resource resource = createComponentResource(name, impl, info); String pathSegment = analyzer.validResourcePath(name, "Invalid component name"); analyzer.getJar() .putResource("OSGI-INF/" + pathSegment + ".xml", resource); components.put("OSGI-INF/" + pathSegment + ".xml", EMPTY); }
Collection<String> dynamic = new ArrayList<String>(split(info.get(COMPONENT_DYNAMIC))); Collection<String> optional = new ArrayList<String>(split(info.get(COMPONENT_OPTIONAL))); Collection<String> multiple = new ArrayList<String>(split(info.get(COMPONENT_MULTIPLE))); Collection<String> descriptors = split(info.get(COMPONENT_DESCRIPTORS)); if (referenceName.endsWith(":")) { if (!SET_COMPONENT_DIRECTIVES.contains(referenceName)) error("Unrecognized directive in Service-Component header: " + referenceName); continue; error("Invalid Interface Name for references in Service Component: " + referenceName + "=" + interfaceName); continue; error("The bind method %s for %s not defined", bind, referenceName); error("The unbind method %s for %s not defined", unbind, referenceName);
createComponentResource(serviceComponents, name, info); } else { annotated(serviceComponents, c, info); checkAnnotationsFeasible(name); else for (Clazz c : annotatedComponents) { annotated(serviceComponents, c, info); createComponentResource(serviceComponents, name, info); else error("Set to %s but entry %s is not an FQN ", NOANNOTATIONS, name);
createComponentResource(serviceComponents, name, info); } else { annotated(serviceComponents, c, info); checkAnnotationsFeasible(name); else for (Clazz c : annotatedComponents) { annotated(serviceComponents, c, info); createComponentResource(serviceComponents, name, info); else error("Set to %s but entry %s is not an FQN ", NOANNOTATIONS, name);
createComponentResource(serviceComponents, name, info); } else { annotated(serviceComponents, c, info); checkAnnotationsFeasible(name); else for (Clazz c : annotatedComponents) { annotated(serviceComponents, c, info); createComponentResource(serviceComponents, name, info); else error("Set to %s but entry %s is not an FQN ", NOANNOTATIONS, name);
Collection<String> properties = split(info.get(COMPONENT_PROPERTIES)); for (Iterator<String> p = properties.iterator(); p.hasNext();) { String clause = p.next(); int n = clause.indexOf('='); if (n <= 0) { error("Not a valid property in service component: " + clause); } else { String type = null; pw.print("'"); } else { warning("Invalid property type '" + type + "' for property " + name);
createComponentResource(serviceComponents, name, info); } else { annotated(serviceComponents, c, info); checkAnnotationsFeasible(name); else for (Clazz c : annotatedComponents) { annotated(serviceComponents, c, info); createComponentResource(serviceComponents, name, info); else error("Set to %s but entry %s is not an FQN ", NOANNOTATIONS, name);
private void reportInvalidUseOfServiceComponentHeader(String name) throws Exception, IOException { SetLocation warning = warning(Constants.SERVICE_COMPONENT + " is normally generated by bnd. If you want to point at specific component XML files (wildcards are allowed, see findEntries) make sure it ends in '.xml'. Found %s", name); FileLine where = getHeader(Pattern.compile(Constants.SERVICE_COMPONENT), Pattern.compile(Pattern.quote(name))); if (where != null) { SetLocation loc = error(Constants.SERVICE_COMPONENT + " refers to %s that is annotated with the deprecated bnd Component annotation. Support for this was removed in 4.0.0 because they were taken over by OSGi. Please update to the comparable OSGi annotations", clazz.getFQN()); String source = analyzer.getSourceFileFor(cname); if (source != null) { File f = getFile(source); if (f.isFile()) { Pattern pattern = Pattern.compile("^.*@.*Component.*$", Pattern.CASE_INSENSITIVE); where = findHeader(f, pattern); if (where != null) { where.set(loc);
private void reportInvalidUseOfServiceComponentHeader(String name) throws Exception, IOException { SetLocation warning = warning(Constants.SERVICE_COMPONENT + " is normally generated by bnd. If you want to point at specific component XML files (wildcards are allowed, see findEntries) make sure it ends in '.xml'. Found %s", name); FileLine where = getHeader(Pattern.compile(Constants.SERVICE_COMPONENT), Pattern.compile(Pattern.quote(name))); if (where != null) { SetLocation loc = error(Constants.SERVICE_COMPONENT + " refers to %s that is annotated with the deprecated bnd Component annotation. Support for this was removed in 4.0.0 because they were taken over by OSGi. Please update to the comparable OSGi annotations", clazz.getFQN()); String source = analyzer.getSourceFileFor(cname); if (source != null) { File f = getFile(source); if (f.isFile()) { Pattern pattern = Pattern.compile("^.*@.*Component.*$", Pattern.CASE_INSENSITIVE); where = findHeader(f, pattern); if (where != null) { where.set(loc);
createComponentResource(serviceComponents, name, info); else { reportInvalidUseOfServiceComponentHeader(name);
createComponentResource(serviceComponents, name, info); else { reportInvalidUseOfServiceComponentHeader(name);
Map<String,Map<String,String>> serviceComponents = newMap(); String header = getProperty(SERVICE_COMPONENT); Parameters sc = parseHeader(header); componentEntry(serviceComponents, name, info); error("Invalid " + Constants.SERVICE_COMPONENT + " header: %s %s, throws %s", name, info, e); throw e;
Map<String, Map<String, String>> serviceComponents = newMap(); String header = getProperty(SERVICE_COMPONENT); Parameters sc = parseHeader(header); componentEntry(serviceComponents, name, info); error("Invalid " + Constants.SERVICE_COMPONENT + " header: %s %s, throws %s", name, info, e); throw e;
Map<String,Map<String,String>> serviceComponents = newMap(); String header = getProperty(SERVICE_COMPONENT); Parameters sc = parseHeader(header); componentEntry(serviceComponents, name, info); error("Invalid Service-Component header: %s %s, throws %s", name, info, e); throw e;
Map<String, Map<String, String>> serviceComponents = newMap(); String header = getProperty(SERVICE_COMPONENT); Map<String, Map<String, String>> sc = parseHeader(header); componentEntry(serviceComponents, name, info); error("Invalid Service-Component header: %s %s, throws %s", name, info, e);
Map<String, Map<String, String>> serviceComponents = newMap(); String header = getProperty(SERVICE_COMPONENT); Parameters sc = parseHeader(header); componentEntry(serviceComponents, name, info); error("Invalid " + Constants.SERVICE_COMPONENT + " header: %s %s, throws %s", name, info, e); throw e;
/** * Check if annotations are actually feasible looking at the class * format. If the class format does not provide annotations then it is * no use specifying annotated components. * * @param name * @return * @throws Exception */ private Collection<Clazz> checkAnnotationsFeasible(String name) throws Exception { Collection<Clazz> not = analyzer.getClasses("", QUERY.NAMED.toString(), name // ); if (not.isEmpty()) { if ("*".equals(name)) return not; error("Specified %s but could not find any class matching this pattern", name); } for (Clazz c : not) { if (c.getFormat().hasAnnotations()) return not; } warning("Wildcards are used (%s) requiring annotations to decide what is a component. Wildcard maps to classes that are compiled with java.target < 1.5. Annotations were introduced in Java 1.5", name); return not; }
/** * Check if annotations are actually feasible looking at the class * format. If the class format does not provide annotations then it is * no use specifying annotated components. * * @param name * @return * @throws Exception */ private Collection<Clazz> checkAnnotationsFeasible(String name) throws Exception { Collection<Clazz> not = analyzer.getClasses("", QUERY.NAMED.toString(), name // ); if (not.isEmpty()) { if ("*".equals(name)) return not; error("Specified %s but could not find any class matching this pattern", name); } for (Clazz c : not) { if (c.getFormat().hasAnnotations()) return not; } warning("Wildcards are used (%s) requiring annotations to decide what is a component. Wildcard maps to classes that are compiled with java.target < 1.5. Annotations were introduced in Java 1.5", name); return not; }
private void createComponentResource(Map<String,Map<String,String>> components, String name, Map<String,String> info) throws Exception { // We can override the name in the parameters if (info.containsKey(COMPONENT_NAME)) name = info.get(COMPONENT_NAME); // Assume the impl==name, but allow override String impl = name; if (info.containsKey(COMPONENT_IMPLEMENTATION)) impl = info.get(COMPONENT_IMPLEMENTATION); TypeRef implRef = analyzer.getTypeRefFromFQN(impl); // Check if such a class exists analyzer.referTo(implRef); boolean designate = designate(name, info.get(COMPONENT_DESIGNATE), false) || designate(name, info.get(COMPONENT_DESIGNATEFACTORY), true); // If we had a designate, we want a default configuration policy of // require. if (designate && info.get(COMPONENT_CONFIGURATION_POLICY) == null) info.put(COMPONENT_CONFIGURATION_POLICY, "require"); // We have a definition, so make an XML resources Resource resource = createComponentResource(name, impl, info); String pathSegment = analyzer.validResourcePath(name, "Invalid component name"); analyzer.getJar().putResource("OSGI-INF/" + pathSegment + ".xml", resource); components.put("OSGI-INF/" + pathSegment + ".xml", EMPTY); }