use of org.apache.felix.scrplugin.description.ClassDescription in project felix by apache.
the class ClassScanner method getComponentDescriptors.
/**
* Returns a map of component descriptors which may be extended by the java
* sources.
* <p>
* This method calls the {@link #getDependencies()} method and checks for
* any Service-Component descriptors in the returned files.
* <p>
* This method may be overwritten by extensions of this class.
*
* @throws SCRDescriptorException May be thrown if an error occurs
* gathering the component descriptors.
*/
private Map<String, ClassDescription> getComponentDescriptors() throws SCRDescriptorException {
if (loadedDependencies == null) {
loadedDependencies = new HashMap<String, ClassDescription>();
final Collection<File> dependencies = this.project.getDependencies();
for (final File artifact : dependencies) {
try {
this.log.debug("Trying to get scrinfo from artifact " + artifact);
// First try to read the private scr info file from previous scr generator versions
InputStream scrInfoFile = null;
try {
scrInfoFile = this.getFile(artifact, ABSTRACT_DESCRIPTOR_ARCHIV_PATH);
if (scrInfoFile != null) {
this.readServiceComponentDescriptor(scrInfoFile, artifact.toString() + ':' + ABSTRACT_DESCRIPTOR_ARCHIV_PATH);
continue;
}
this.log.debug("Artifact has no scrinfo file (it's optional): " + artifact);
} catch (final IOException ioe) {
throw new SCRDescriptorException("Unable to get scrinfo from artifact", artifact.toString(), ioe);
} finally {
if (scrInfoFile != null) {
try {
scrInfoFile.close();
} catch (final IOException ignore) {
}
}
}
this.log.debug("Trying to get manifest from artifact " + artifact);
final Manifest manifest = this.getManifest(artifact);
if (manifest != null) {
// read Service-Component entry
if (manifest.getMainAttributes().getValue(SERVICE_COMPONENT) != null) {
final String serviceComponent = manifest.getMainAttributes().getValue(SERVICE_COMPONENT);
this.log.debug("Found Service-Component: " + serviceComponent + " in artifact " + artifact);
final StringTokenizer st = new StringTokenizer(serviceComponent, ",");
while (st.hasMoreTokens()) {
final String entry = st.nextToken().trim();
if (entry.length() > 0) {
this.readServiceComponentDescriptor(artifact, entry);
}
}
} else {
this.log.debug("Artifact has no service component entry in manifest " + artifact);
}
} else {
this.log.debug("Unable to get manifest from artifact " + artifact);
}
} catch (IOException ioe) {
throw new SCRDescriptorException("Unable to get manifest from artifact", artifact.toString(), ioe);
}
}
}
return this.loadedDependencies;
}
use of org.apache.felix.scrplugin.description.ClassDescription in project felix by apache.
the class ClassScanner method readServiceComponentDescriptor.
/**
* Parses the descriptors read from the given input stream. This method may
* be called by the {@link #getComponentDescriptors()} method to parse the
* descriptors gathered in an implementation dependent way.
*
* @throws SCRDescriptorException If an error occurs reading the
* descriptors from the stream.
*/
private void readServiceComponentDescriptor(final InputStream file, final String location) throws SCRDescriptorException {
final List<ClassDescription> list = ComponentDescriptorIO.read(file, this.project.getClassLoader(), iLog, location);
if (list != null) {
for (final ClassDescription cd : list) {
final String name;
if (cd.getDescribedClass() == null) {
name = cd.getDescription(ComponentDescription.class).getName();
} else {
name = cd.getDescribedClass().getName();
}
loadedDependencies.put(name, cd);
}
}
}
use of org.apache.felix.scrplugin.description.ClassDescription in project felix by apache.
the class ClassScanner method scanSources.
/**
* Scan all source class files for annotations and process them.
*/
public List<ClassDescription> scanSources() throws SCRDescriptorFailureException, SCRDescriptorException {
final List<ClassDescription> result = new ArrayList<ClassDescription>();
for (final Source src : project.getSources()) {
if (src.getFile().getName().equals("package-info.java")) {
log.debug("Skipping file " + src.getClassName());
continue;
}
log.debug("Scanning class " + src.getClassName());
try {
// load the class
final Class<?> annotatedClass = project.getClassLoader().loadClass(src.getClassName());
this.process(annotatedClass, src, result);
} catch (final SCRDescriptorFailureException e) {
throw e;
} catch (final SCRDescriptorException e) {
throw e;
} catch (final ClassNotFoundException e) {
log.warn("ClassNotFoundException: " + e.getMessage());
} catch (final NoClassDefFoundError e) {
log.warn("NoClassDefFoundError: " + e.getMessage());
} catch (final Throwable t) {
throw new SCRDescriptorException("Unable to load compiled class: " + src.getClassName(), src.getFile().toString(), t);
}
}
return result;
}
Aggregations