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/05/06 14:28:56 UTC
svn commit: r1479545 - in /felix/trunk/ipojo:
manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/
manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/
manipulator/manipulator/src/m...
Author: clement
Date: Mon May 6 12:28:55 2013
New Revision: 1479545
URL: http://svn.apache.org/r1479545
Log:
Fix FELIX-4052
https://issues.apache.org/jira/browse/FELIX-4052
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/components/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/components/InstantiatedComponent.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiatedComponent.java
Modified:
felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProvider.java
felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java
felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProvider.java?rev=1479545&r1=1479544&r2=1479545&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProvider.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProvider.java Mon May 6 12:28:55 2013
@@ -108,7 +108,7 @@ public class AnnotationMetadataProvider
// Instantiate ?
Element instance = collector.getInstanceMetadata();
if (instance != null) {
- m_reporter.trace("Declaring an empty instance of %s", instance.getAttribute("component"));
+ m_reporter.trace("Declaring an instance of %s", instance.getAttribute("component"));
metadata.add(instance);
}
}
Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java?rev=1479545&r1=1479544&r2=1479545&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java Mon May 6 12:28:55 2013
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.manipulat
import org.apache.felix.ipojo.manipulator.Reporter;
import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.BindingRegistry;
+import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.FieldVisitor;
@@ -74,7 +75,7 @@ public class ClassMetadataCollector exte
}
/**
- * Build metadata. May be {@literal null} if no "component type" was found.
+ * Build instance metadata. May be {@literal null} if no "component type" was found.
* @return Build metadata. May be {@literal null} if no "component type" was found.
*/
public Element getInstanceMetadata() {
@@ -167,6 +168,13 @@ public class ClassMetadataCollector exte
componentMetadata = workbench.build();
instanceMetadata = workbench.getInstance();
+
+ // If we have an instance declared and the component metadata has a name, we update the component's attribute
+ // of the instance (https://issues.apache.org/jira/browse/FELIX-4052).
+ if (componentMetadata != null && componentMetadata.containsAttribute("name") && instanceMetadata != null) {
+ // Update the component attribute
+ instanceMetadata.addAttribute(new Attribute("component", componentMetadata.getAttribute("name")));
+ }
}
}
Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java?rev=1479545&r1=1479544&r2=1479545&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java Mon May 6 12:28:55 2013
@@ -57,7 +57,8 @@ public class InstantiateVisitor extends
* @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
*/
public void visitEnd() {
- // TODO Is this really the classname that we need here ? Or the component's name ?
+ // We set the instance's component attribute to the class name, if the component type has a custom name,
+ // we will update it.
instance.addAttribute(new Attribute("component", workbench.getType().getClassName()));
workbench.setInstance(instance);
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/components/InstantiatedComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/components/InstantiatedComponent.java?rev=1479545&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/components/InstantiatedComponent.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/components/InstantiatedComponent.java Mon May 6 12:28:55 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.runtime.core.test.components.components;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
+
+/**
+ * A component using factory name and instantiate.
+ */
+@Component(name = "MyInstantiatedComponent")
+@Instantiate
+public class InstantiatedComponent {
+
+ // Do nothing.
+}
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java?rev=1479545&r1=1479544&r2=1479545&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java Mon May 6 12:28:55 2013
@@ -19,42 +19,12 @@
package org.apache.felix.ipojo.runtime.core.test.annotations;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.CompositeOption;
import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
import org.ow2.chameleon.testing.helpers.BaseTest;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
/**
* Bootstrap the test from this project
@@ -71,8 +41,7 @@ public class Common extends BaseTest {
public CompositeOption eventadmin() {
return new DefaultCompositeOption(
mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.2.10"),
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.eventadmin",
- "1.8.0").versionAsInProject());
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.eventadmin").versionAsInProject());
}
}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiatedComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiatedComponent.java?rev=1479545&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiatedComponent.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiatedComponent.java Mon May 6 12:28:55 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.runtime.core.test.annotations;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+/**
+ * Checks that a component setting a name and using the @Instantiate annotation creates the instance correctly.
+ * It reproduce {@link https://issues.apache.org/jira/browse/FELIX-4052}
+ */
+public class TestInstantiatedComponent extends Common {
+
+ @Test
+ public void testInstanceCreation() {
+ // This is the expected name.
+ Architecture architecture = osgiHelper.getServiceObject(Architecture.class,
+ "(architecture.instance=MyInstantiatedComponent-0)");
+
+ assertNotNull(architecture);
+ assertEquals(ComponentInstance.VALID, architecture.getInstanceDescription().getState());
+ }
+
+}