You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/04/29 21:45:17 UTC
svn commit: r1477295 - in
/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo:
extender/internal/processor/ConfigurationProcessor.java util/StreamUtils.java
Author: clement
Date: Mon Apr 29 19:45:17 2013
New Revision: 1477295
URL: http://svn.apache.org/r1477295
Log:
Ignore inner classes during @Configuration scanning
Added:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java
Modified:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java?rev=1477295&r1=1477294&r2=1477295&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ConfigurationProcessor.java Mon Apr 29 19:45:17 2013
@@ -30,6 +30,7 @@ import org.osgi.framework.Bundle;
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 java.util.*;
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 @@ public class ConfigurationProcessor impl
* 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 @@ public class ConfigurationProcessor impl
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 @@ public class ConfigurationProcessor impl
// return hasConfigurationAnnotation(bundle, parentUrl, classLoader);
// }
} finally {
- is.close();
+ closeQuietly(is);
}
}
Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java?rev=1477295&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/StreamUtils.java Mon Apr 29 19:45:17 2013
@@ -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.
+ }
+ }
+
+}