Ignore inner classes during @Configuration scanning
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1477295 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java
index 9b1a351..e24bc4c 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java
@@ -30,6 +30,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.wiring.BundleWiring;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
@@ -39,6 +40,7 @@
import static org.apache.felix.ipojo.util.Reflection.fields;
import static org.apache.felix.ipojo.util.Reflection.methods;
+import static org.apache.felix.ipojo.util.StreamUtils.closeQuietly;
/**
* Processor looking for classes annotated with @Configuration and creating the corresponding instance declaration.
@@ -49,11 +51,17 @@
* The logger.
*/
private final Log m_logger;
+
/**
* Registry storing the bundle to components and instances declared within this bundle.
* Only instances are expected.
*/
private final Map<Bundle, ComponentsAndInstances> m_registry = new HashMap<Bundle, ComponentsAndInstances>();
+
+ /**
+ * Set to false to disable this processor.
+ * When an OSGi framework does not provide the wiring API, this processor is disabled.
+ */
private final boolean m_enabled;
/**
@@ -234,7 +242,13 @@
private boolean hasConfigurationAnnotation(Bundle bundle, URL url, ClassLoader classLoader) throws IOException {
InputStream is = url.openStream();
+
try {
+ // Exclude inner classes and classes containing $
+ if (url.toExternalForm().contains("$")) {
+ return false;
+ }
+
ClassReader reader = new ClassReader(is);
ConfigurationAnnotationScanner scanner = new ConfigurationAnnotationScanner();
reader.accept(scanner, 0);
@@ -258,7 +272,7 @@
// return hasConfigurationAnnotation(bundle, parentUrl, classLoader);
// }
} finally {
- is.close();
+ closeQuietly(is);
}
}
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java
new file mode 100644
index 0000000..9a91662
--- /dev/null
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.util;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+/**
+ * Utility method to handle streams.
+ */
+public class StreamUtils {
+
+ /**
+ * Closes a stream.
+ * It ignores the IOException that may occur while closing the stream.
+ * @param stream the stream to close.
+ */
+ public static void closeQuietly(Closeable stream) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Ignore.
+ }
+ }
+
+}