Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java Wed Jan 7 19:37:42 2015 @@ -55,6 +55,7 @@ public class ManagedPersistenceUnitInfoI private final PersistenceUnitInfoImpl info; + @SuppressWarnings("rawtypes") public ManagedPersistenceUnitInfoImpl(Bundle persistenceBundle, ParsedPersistenceUnit unit, ServiceReference providerRef) {
Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java Wed Jan 7 19:37:42 2015 @@ -45,6 +45,7 @@ import org.osgi.framework.ServiceReferen import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@SuppressWarnings("rawtypes") public class PersistenceUnitInfoImpl implements PersistenceUnitInfo { private final Bundle bundle; Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties Wed Jan 7 19:37:42 2015 @@ -201,4 +201,8 @@ xa.datasource.non.tx=The persistence uni # {1} The symbolic name of the persistence bundle. # {2} The version of the persistence bundle. # {3} The jndi name of the datasource -not.a.datasource=The persistence unit {0} in persistence bundle {1}/{2} uses a JNDI name {3} that looks up an Objet that is not a DataSource or XADataSource. \ No newline at end of file +not.a.datasource=The persistence unit {0} in persistence bundle {1}/{2} uses a JNDI name {3} that looks up an Objet that is not a DataSource or XADataSource. +# {0} Method name not found +# {1} The persistence unit name +wrong.JPA.version="Method {0} is not implemented by delegate {1}. Probably you want use JPA 2.1 but you are installed JPA 2.0." + \ No newline at end of file Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java Wed Jan 7 19:37:42 2015 @@ -23,7 +23,6 @@ package org.apache.aries.jpa.container; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.BufferedWriter; @@ -48,7 +47,6 @@ import javax.persistence.EntityManagerFa import javax.persistence.spi.PersistenceProvider; import javax.persistence.spi.PersistenceUnitInfo; -import org.apache.aries.jpa.container.impl.CountingEntityManagerFactory; import org.apache.aries.jpa.container.impl.EntityManagerFactoryManager; import org.apache.aries.jpa.container.impl.PersistenceBundleManager; import org.apache.aries.mocks.BundleContextMock; @@ -70,6 +68,7 @@ import org.osgi.framework.ServiceRegistr import org.osgi.framework.Version; import org.osgi.service.jdbc.DataSourceFactory; +@SuppressWarnings({"rawtypes", "unchecked"}) public class PersistenceBundleLifecycleTest { private Bundle persistenceBundle; @@ -363,7 +362,7 @@ public class PersistenceBundleLifecycleT mgr.stop(extenderBundle.getBundleContext()); - Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close")); + assertCloseCalled(); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); } @@ -406,7 +405,6 @@ public class PersistenceBundleLifecycleT //Now try Resolving Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED); mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), o); - testSuccessfulCreationEvent(ref, extenderContext, 1); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); @@ -446,7 +444,7 @@ public class PersistenceBundleLifecycleT testSuccessfulCreationEvent(ref, extenderContext, 1); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); - Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close")); + assertCloseCalled(); } @Test @@ -480,18 +478,17 @@ public class PersistenceBundleLifecycleT //Check we didn't get the Provider, and there is no Service in the registry Skeleton.getSkeleton(extenderContext).assertNotCalled(new MethodCall(BundleContext.class, "getService", ServiceReference.class)); - Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close")); + assertCloseCalled(); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); //Now resolve the bundle again and check we get another EMF created Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED); mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), getTrackedObject()); - //We will have created the EMF a total of 2 times - testSuccessfulCreationEvent(ref, extenderContext, 2); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); } + @Test public void testBundleChangedUnresolved() throws Exception { @@ -522,7 +519,7 @@ public class PersistenceBundleLifecycleT //Check we didn't get the Provider, and there is no Service in the registry Skeleton.getSkeleton(extenderContext).assertNotCalled(new MethodCall(BundleContext.class, "getService", ServiceReference.class)); - Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close")); + assertCloseCalled(); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); } @@ -545,11 +542,15 @@ public class PersistenceBundleLifecycleT reg.unregister(); - Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close")); + assertCloseCalled(); BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName()); mgr.modifiedBundle(persistenceBundle, null, getTrackedObject()); } + +private void assertCloseCalled() { + Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close")); +} @Test public void testInstalledWithBadXML() throws Exception @@ -561,10 +562,8 @@ public class PersistenceBundleLifecycleT Hashtable<String,String> hash1 = new Hashtable<String, String>(); hash1.put("javax.persistence.provider", "no.such.Provider"); - ServiceRegistration reg = persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , + persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , pp, hash1 ); - ServiceReference ref = reg.getReference(); - setupPersistenceBundle("file3", ""); mgr.start(extenderContext); @@ -656,7 +655,7 @@ public class PersistenceBundleLifecycleT Hashtable<String,Object> hash2 = new Hashtable<String, Object>(); hash2.put("javax.persistence.provider", "do.not.use.this.Provider"); hash2.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); - ServiceRegistration reg2 = persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , + persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , pp2, hash2 ); setupPersistenceBundle("file6", ""); @@ -690,7 +689,7 @@ public class PersistenceBundleLifecycleT Hashtable<String,Object> hash2 = new Hashtable<String, Object>(); hash2.put("javax.persistence.provider", "do.not.use.this.Provider"); hash2.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); - ServiceRegistration reg2 = persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , + persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , pp2, hash2 ); setupPersistenceBundle("file7", ""); @@ -715,18 +714,15 @@ public class PersistenceBundleLifecycleT Hashtable<String,String> hash1 = new Hashtable<String, String>(); hash1.put("javax.persistence.provider", "no.such.Provider"); - ServiceRegistration reg = persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , + persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , pp, hash1 ); - ServiceReference ref = reg.getReference(); PersistenceProvider pp2 = Skeleton.newMock(PersistenceProvider.class); Hashtable<String,Object> hash2 = new Hashtable<String, Object>(); hash2.put("javax.persistence.provider", "do.not.use.this.Provider"); hash2.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); - ServiceRegistration reg2 = persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , + persistenceBundle.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()} , pp2, hash2 ); - ServiceReference ref2 = reg2.getReference(); - setupPersistenceBundle("file8", ""); mgr.start(extenderContext); @@ -965,7 +961,7 @@ public class PersistenceBundleLifecycleT QuiesceCallback cbk = Skeleton.newMock(QuiesceCallback.class); - QuiesceParticipant p = (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + QuiesceParticipant p = getQuiesceParticipant(ctx); p.quiesce(cbk, Collections.singletonList(persistenceBundle)); @@ -974,7 +970,7 @@ public class PersistenceBundleLifecycleT Skeleton.getSkeleton(cbk).assertCalledExactNumberOfTimes(new MethodCall(QuiesceCallback.class, "bundleQuiesced", Bundle[].class), 1); } - + /** * Quiesce a JPA bundle that is not active * @throws Exception @@ -994,7 +990,7 @@ public class PersistenceBundleLifecycleT QuiesceCallback cbk = Skeleton.newMock(QuiesceCallback.class); - QuiesceParticipant p = (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + QuiesceParticipant p = getQuiesceParticipant(ctx); p.quiesce(cbk, Collections.singletonList(persistenceBundle)); @@ -1031,7 +1027,7 @@ public class PersistenceBundleLifecycleT QuiesceCallback cbk = Skeleton.newMock(QuiesceCallback.class); - QuiesceParticipant p = (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + QuiesceParticipant p = getQuiesceParticipant(ctx); p.quiesce(cbk, Collections.singletonList(persistenceBundle)); @@ -1077,7 +1073,7 @@ public class PersistenceBundleLifecycleT QuiesceCallback cbk = Skeleton.newMock(QuiesceCallback.class); - QuiesceParticipant p = (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + QuiesceParticipant p = getQuiesceParticipant(ctx); p.quiesce(cbk, Collections.singletonList(extenderBundle)); @@ -1105,7 +1101,7 @@ public class PersistenceBundleLifecycleT QuiesceCallback cbk = Skeleton.newMock(QuiesceCallback.class); - QuiesceParticipant p = (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + QuiesceParticipant p = getQuiesceParticipant(ctx); p.quiesce(cbk, Collections.singletonList(extenderBundle)); @@ -1162,7 +1158,7 @@ public class PersistenceBundleLifecycleT QuiesceCallback cbk = Skeleton.newMock(QuiesceCallback.class); - QuiesceParticipant p = (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + QuiesceParticipant p = getQuiesceParticipant(ctx); p.quiesce(cbk, Collections.singletonList(extenderBundle)); @@ -1398,27 +1394,18 @@ public class PersistenceBundleLifecycleT } private void registerVersionedPersistenceProviders() { - providerP100 = Skeleton.newMock(PersistenceProvider.class); providerP101 = Skeleton.newMock(PersistenceProvider.class); providerP110 = Skeleton.newMock(PersistenceProvider.class); providerP111 = Skeleton.newMock(PersistenceProvider.class); - ServiceRegistration reg; - Hashtable<String,String> hash1 = new Hashtable<String, String>(); hash1.put("javax.persistence.provider", "no.such.Provider"); - reg = providerBundleP100.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()}, - providerP100, hash1 ); - - reg = providerBundleP101.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()}, - providerP101, hash1 ); - - reg = providerBundleP110.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()}, - providerP110, hash1 ); - - reg = providerBundleP111.getBundleContext().registerService(new String[] {PersistenceProvider.class.getName()}, - providerP111, hash1 ); + String[] ifs = new String[] {PersistenceProvider.class.getName()}; + providerBundleP100.getBundleContext().registerService(ifs, providerP100, hash1 ); + providerBundleP101.getBundleContext().registerService(ifs, providerP101, hash1 ); + providerBundleP110.getBundleContext().registerService(ifs, providerP110, hash1 ); + providerBundleP111.getBundleContext().registerService(ifs,providerP111, hash1 ); } @@ -1479,20 +1466,13 @@ public class PersistenceBundleLifecycleT Skeleton.getSkeleton(provider).assertCalledExactNumberOfTimes(new MethodCall(PersistenceProvider.class, "createContainerEntityManagerFactory", PersistenceUnitInfo.class, Map.class), numEMFs); - for(ServiceReference emf : refs) - assertSame("The EMF came from the wrong provider", Skeleton.getSkeleton(provider), Skeleton.getSkeleton(unwrap(persistenceBundleContext.getService(emf)))); + //for(ServiceReference emf : refs) + // assertSame("The EMF came from the wrong provider", Skeleton.getSkeleton(provider), Skeleton.getSkeleton(unwrap(persistenceBundleContext.getService(emf)))); //More than one provider was instantiated Skeleton.getSkeleton(extenderContext).assertCalledExactNumberOfTimes(new MethodCall(BundleContext.class, "getService", ServiceReference.class), 1); } - private Object unwrap(Object o) throws Exception { - Field f = CountingEntityManagerFactory.class.getDeclaredField("delegate"); - f.setAccessible(true); - - return f.get(o); - } - private void assertCorrectPersistenceProviderUsed (BundleContext extenderContext, PersistenceProvider provider) throws Exception { assertCorrectPersistenceProviderUsed(extenderContext, provider, 1); @@ -1505,5 +1485,11 @@ public class PersistenceBundleLifecycleT return map.get(persistenceBundle); } + + + private QuiesceParticipant getQuiesceParticipant(BundleContext ctx) { + return (QuiesceParticipant) ctx.getService(ctx.getServiceReference(QuiesceParticipant.class.getName())); + } + } Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java Wed Jan 7 19:37:42 2015 @@ -40,6 +40,7 @@ import org.apache.aries.unittest.mocks.S import org.junit.Test; import org.osgi.framework.Bundle; +@SuppressWarnings({"rawtypes", "unchecked"}) public class PersistenceXMLParsingTest { @@ -228,7 +229,7 @@ public class PersistenceXMLParsingTest Bundle b = Skeleton.newMock(Bundle.class); - Collection<? extends ParsedPersistenceUnit> parsedUnits = new PersistenceDescriptorParserImpl().parse(b, descriptor); + new PersistenceDescriptorParserImpl().parse(b, descriptor); fail("Parsing should not succeed"); } finally { @@ -338,7 +339,7 @@ public class PersistenceXMLParsingTest Bundle b = Skeleton.newMock(Bundle.class); - Collection<? extends ParsedPersistenceUnit> parsedUnits = new PersistenceDescriptorParserImpl().parse(b, descriptor); + new PersistenceDescriptorParserImpl().parse(b, descriptor); fail("should throw"); } finally { Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/weaving/JPAWeavingHookTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/weaving/JPAWeavingHookTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/weaving/JPAWeavingHookTest.java (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/weaving/JPAWeavingHookTest.java Wed Jan 7 19:37:42 2015 @@ -46,13 +46,13 @@ import org.osgi.framework.wiring.BundleC import org.osgi.framework.wiring.BundleRevision; import org.osgi.framework.wiring.BundleWiring; +@SuppressWarnings({"rawtypes", "unchecked"}) public class JPAWeavingHookTest { private Bundle b1; private ClassTransformer ct1a; - @Before public void setup() { b1 = Skeleton.newMock(new BundleMock("bundle1", new Hashtable()), Bundle.class); Modified: aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java (original) +++ aries/branches/subsystemsR6/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java Wed Jan 7 19:37:42 2015 @@ -35,6 +35,7 @@ public final class AriesFrameworkUtil * * @param reg The {@link ServiceRegistration}, may be null */ + @SuppressWarnings("rawtypes") public static void safeUnregisterService(ServiceRegistration reg) { if(reg != null) { Modified: aries/branches/subsystemsR6/jpa/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/jpa/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/jpa/pom.xml (original) +++ aries/branches/subsystemsR6/jpa/pom.xml Wed Jan 7 19:37:42 2015 @@ -39,9 +39,9 @@ <module>jpa-container</module> <module>jpa-container-context</module> <module>jpa-blueprint-aries</module> - <!-- <module>jpa-container-eclipselink-adapter</module> --> + <module>jpa-container-eclipselink-adapter</module> <module>jpa-container-testbundle</module> - <!-- <module>jpa-container-testbundle-eclipselink</module> --> + <module>jpa-container-testbundle-eclipselink</module> <module>jpa-container-advancedtestbundle</module> <module>jpa-container-itest</module> <module>jpa-blueprint-testbundle</module> Modified: aries/branches/subsystemsR6/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/pom.xml (original) +++ aries/branches/subsystemsR6/pom.xml Wed Jan 7 19:37:42 2015 @@ -53,7 +53,6 @@ <module>ejb</module> <module>jmx</module> <module>jpa</module> - <module>jpa20</module> <module>spi-fly</module> <module>samples</module> <module>esa-maven-plugin</module> Modified: aries/branches/subsystemsR6/proxy/proxy-bundle/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-bundle/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-bundle/pom.xml (original) +++ aries/branches/subsystemsR6/proxy/proxy-bundle/pom.xml Wed Jan 7 19:37:42 2015 @@ -79,7 +79,7 @@ <dependency> <groupId>org.apache.aries.proxy</groupId> <artifactId>org.apache.aries.proxy.impl</artifactId> - <version>1.0.4-SNAPSHOT</version> + <version>1.0.5-SNAPSHOT</version> <scope>provided</scope> </dependency> <dependency> Modified: aries/branches/subsystemsR6/proxy/proxy-impl/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/pom.xml (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/pom.xml Wed Jan 7 19:37:42 2015 @@ -32,7 +32,7 @@ <artifactId>org.apache.aries.proxy.impl</artifactId> <packaging>bundle</packaging> <name>Apache Aries Proxy Service</name> - <version>1.0.4-SNAPSHOT</version> + <version>1.0.5-SNAPSHOT</version> <description> This bundle contains the proxy service implementation for Apache Aries </description> Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java Wed Jan 7 19:37:42 2015 @@ -44,6 +44,8 @@ import org.osgi.framework.Bundle; public final class AsmProxyManager extends AbstractProxyManager implements ProxyManager { + static final ClassLoader bootClassLoader = new ClassLoader(Object.class.getClassLoader()) { /* boot class loader */}; + public Object createNewProxy(Bundle clientBundle, Collection<Class<?>> classes, Callable<Object> dispatcher, InvocationListener listener) throws UnableToProxyException { @@ -111,6 +113,9 @@ public final class AsmProxyManager exten // If we could generate a proper constructor this would not be necessary, but since we have to rely // on the generated serialization constructor to bypass the JVM verifier, we don't have much choice ClassLoader classLoader = classToProxy.getClassLoader(); + if (classLoader == null) { + classLoader = bootClassLoader; + } boolean allVisible = true; for (Class<?> clazz : classes) { try { Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java Wed Jan 7 19:37:42 2015 @@ -26,26 +26,40 @@ import org.slf4j.LoggerFactory; public class ProxyUtils { - private static Logger LOGGER = LoggerFactory.getLogger(ProxyUtils.class); - public static final int JAVA_CLASS_VERSION = new BigDecimal(System.getProperty("java.class.version")).intValue(); - private static int weavingJavaVersion = -1; // initialise an invalid number - /** - * Get the java version to be woven at. - * @return - */ - public static int getWeavingJavaVersion() { - if (weavingJavaVersion == -1 ) { - if (JAVA_CLASS_VERSION >= Opcodes.V1_7) { - LOGGER.debug("Weaving to Java 7"); - weavingJavaVersion = Opcodes.V1_7; - } else if (JAVA_CLASS_VERSION == Opcodes.V1_6){ - LOGGER.debug("Weaving to Java 6"); - weavingJavaVersion = Opcodes.V1_6; - } else if (JAVA_CLASS_VERSION == Opcodes.V1_5) { - LOGGER.debug("Weaving to Java 5"); - weavingJavaVersion = Opcodes.V1_5; - } // no need to list all Opcodes as Aries should only work with java5 or above. - } - return weavingJavaVersion; - } + private static Logger LOGGER = LoggerFactory.getLogger(ProxyUtils.class); + public static final int JAVA_CLASS_VERSION = new BigDecimal(System.getProperty("java.class.version")).intValue(); + private static int weavingJavaVersion = -1; // initialise an invalid number + + /** + * Get the java version to be woven at. + * @return + */ + public static int getWeavingJavaVersion() { + if (weavingJavaVersion == -1 ) { + //In order to avoid an inconsistent stack error the version of the woven byte code needs to match + //the level of byte codes in the original class + switch(JAVA_CLASS_VERSION) { + case Opcodes.V1_8: + LOGGER.debug("Weaving to Java 8"); + weavingJavaVersion = Opcodes.V1_8; + break; + case Opcodes.V1_7: + LOGGER.debug("Weaving to Java 7"); + weavingJavaVersion = Opcodes.V1_7; + break; + case Opcodes.V1_6: + LOGGER.debug("Weaving to Java 6"); + weavingJavaVersion = Opcodes.V1_6; + break; + case Opcodes.V1_5: + LOGGER.debug("Weaving to Java 5"); + weavingJavaVersion = Opcodes.V1_5; + break; + default: + //aries should work with Java 5 or above - also will highlight when a higher level (and unsupported) level of Java is released + throw new IllegalArgumentException("Invalid Java version " + JAVA_CLASS_VERSION); + } + } + return weavingJavaVersion; + } } Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java Wed Jan 7 19:37:42 2015 @@ -206,13 +206,13 @@ public abstract class AbstractWovenProxy * The name of this class * @param loader * The ClassLoader loading this class - */ - public AbstractWovenProxyAdapter(ClassVisitor writer, String className, - ClassLoader loader) { - super(Opcodes.ASM4, writer); - typeBeingWoven = Type.getType("L" + className.replace('.', '/') + ";"); - //By default we expect to see methods from a concrete class - currentMethodDeclaringType = typeBeingWoven; + */ + public AbstractWovenProxyAdapter(ClassVisitor writer, String className, + ClassLoader loader) { + super(Opcodes.ASM5, writer); + typeBeingWoven = Type.getType("L" + className.replace('.', '/') + ";"); + //By default we expect to see methods from a concrete class + currentMethodDeclaringType = typeBeingWoven; currentMethodDeclaringTypeIsInterface = false; this.loader = loader; } @@ -355,13 +355,13 @@ public abstract class AbstractWovenProxy currentMethodDeclaringType, currentMethodDeclaringTypeIsInterface); } else if (name.equals("<clinit>")){ //there is an existing clinit method, change the fields we use - //to write our init code to static_init_UUID instead - staticInitMethod = new Method("static_init_" + UU_ID, Type.VOID_TYPE, NO_ARGS); - staticInitMethodFlags = staticInitMethodFlags | ACC_FINAL; - methodVisitorToReturn = new AdviceAdapter(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, - exceptions), access, name, desc){ - @Override - protected void onMethodEnter() + //to write our init code to static_init_UUID instead + staticInitMethod = new Method("static_init_" + UU_ID, Type.VOID_TYPE, NO_ARGS); + staticInitMethodFlags = staticInitMethodFlags | ACC_FINAL; + methodVisitorToReturn = new AdviceAdapter(Opcodes.ASM5, cv.visitMethod(access, name, desc, signature, + exceptions), access, name, desc){ + @Override + protected void onMethodEnter() { //add into the <clinit> a call to our synthetic static_init_UUID invokeStatic(typeBeingWoven, staticInitMethod); Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyMethodAdapter.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyMethodAdapter.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyMethodAdapter.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyMethodAdapter.java Wed Jan 7 19:37:42 2015 @@ -26,13 +26,13 @@ import static org.apache.aries.proxy.imp import static org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter.NO_ARGS; import static org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter.OBJECT_TYPE; import static org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter.THROWABLE_INAME; -import static org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter.WOVEN_PROXY_IFACE_TYPE; -import static org.objectweb.asm.Opcodes.ACONST_NULL; -import static org.objectweb.asm.Opcodes.IFNE; -import static org.objectweb.asm.Opcodes.ASM4; - -import java.util.Arrays; - +import static org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter.WOVEN_PROXY_IFACE_TYPE; +import static org.objectweb.asm.Opcodes.ACONST_NULL; +import static org.objectweb.asm.Opcodes.IFNE; +import static org.objectweb.asm.Opcodes.ASM5; + +import java.util.Arrays; + import org.apache.aries.proxy.InvocationListener; import org.apache.aries.proxy.impl.NLS; import org.objectweb.asm.Label; @@ -177,13 +177,13 @@ public abstract class AbstractWovenProxy * @param proxyType - the type being woven that contains this method */ public AbstractWovenProxyMethodAdapter(MethodVisitor mv, int access, String name, String desc, - String methodStaticFieldName, Method currentTransformMethod, Type typeBeingWoven, - Type methodDeclaringType, boolean isMethodDeclaringTypeInterface, boolean isDefaultMethod) - { - super(ASM4, mv, access, name, desc); - this.methodStaticFieldName = methodStaticFieldName; - this.currentTransformMethod = currentTransformMethod; - returnType = currentTransformMethod.getReturnType(); + String methodStaticFieldName, Method currentTransformMethod, Type typeBeingWoven, + Type methodDeclaringType, boolean isMethodDeclaringTypeInterface, boolean isDefaultMethod) + { + super(ASM5, mv, access, name, desc); + this.methodStaticFieldName = methodStaticFieldName; + this.currentTransformMethod = currentTransformMethod; + returnType = currentTransformMethod.getReturnType(); isVoid = returnType.getSort() == Type.VOID; this.typeBeingWoven = typeBeingWoven; this.methodDeclaringType = methodDeclaringType; Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java Wed Jan 7 19:37:42 2015 @@ -34,13 +34,13 @@ public class ConstructorFinder extends C { return hasNoArgsConstructor; } - - public ConstructorFinder() - { - super(Opcodes.ASM4); - } - - @Override + + public ConstructorFinder() + { + super(Opcodes.ASM5); + } + + @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/MethodCopyingClassAdapter.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/MethodCopyingClassAdapter.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/MethodCopyingClassAdapter.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/MethodCopyingClassAdapter.java Wed Jan 7 19:37:42 2015 @@ -60,13 +60,13 @@ final class MethodCopyingClassAdapter ex private final AbstractWovenProxyAdapter wovenProxyAdapter; - public MethodCopyingClassAdapter(AbstractWovenProxyAdapter awpa, ClassLoader definingLoader, - Class<?> superToCopy, Type overridingClassType, Set<Method> knownMethods, - Map<String, TypeMethod> transformedMethods) { - super(Opcodes.ASM4); - this.wovenProxyAdapter = awpa; - this.superToCopy = superToCopy; - this.overridingClassType = overridingClassType; + public MethodCopyingClassAdapter(AbstractWovenProxyAdapter awpa, ClassLoader definingLoader, + Class<?> superToCopy, Type overridingClassType, Set<Method> knownMethods, + Map<String, TypeMethod> transformedMethods) { + super(Opcodes.ASM5); + this.wovenProxyAdapter = awpa; + this.superToCopy = superToCopy; + this.overridingClassType = overridingClassType; this.knownMethods = knownMethods; this.transformedMethods = transformedMethods; @@ -167,13 +167,13 @@ final class MethodCopyingClassAdapter ex private final Type superType; /** The method we are weaving */ private final Method currentTransformMethod; - - public CopyingMethodAdapter(GeneratorAdapter mv, Type superType, - Method currentTransformMethod) { - super(Opcodes.ASM4); - this.mv = mv; - this.superType = superType; - this.currentTransformMethod = currentTransformMethod; + + public CopyingMethodAdapter(GeneratorAdapter mv, Type superType, + Method currentTransformMethod) { + super(Opcodes.ASM5); + this.mv = mv; + this.superType = superType; + this.currentTransformMethod = currentTransformMethod; } //TODO might not work for attributes Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java Wed Jan 7 19:37:42 2015 @@ -32,13 +32,13 @@ public final class OSGiFriendlyClassVisi private final boolean inlineJSR; - - public OSGiFriendlyClassVisitor(ClassVisitor cv, int arg1) { - - super(Opcodes.ASM4, cv); - - inlineJSR = arg1 == ClassWriter.COMPUTE_FRAMES; - } + + public OSGiFriendlyClassVisitor(ClassVisitor cv, int arg1) { + + super(Opcodes.ASM5, cv); + + inlineJSR = arg1 == ClassWriter.COMPUTE_FRAMES; + } Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java Wed Jan 7 19:37:42 2015 @@ -66,7 +66,7 @@ public class ProxySubclassAdapter extend public ProxySubclassAdapter(ClassVisitor writer, String newClassName, ClassLoader loader) { // call the superclass constructor - super(Opcodes.ASM4, writer); + super(Opcodes.ASM5, writer); // the writer is now the cv in the superclass of ClassAdapter LOGGER.debug(Constants.LOG_ENTRY, "ProxySubclassAdapter", new Object[] { this, writer, @@ -146,7 +146,16 @@ public class ProxySubclassAdapter extend // So what we do is build up the calling of the superclasses constructor using nulls and default values. This means that the // class bytes can be verified by the JVM, and then in the ProxySubclassGenerator, we load the class without invoking the // constructor. - Method constructor = Method.getMethod(constructors[0].toGenericString()); + String constructorString = constructors[0].toGenericString(); + Method constructor = null; + if (constructorString.indexOf(")") != -1) { + //If constructor throws two or more exceptions, getMethod(String) will report a StringIndexOutOfBounds exception, + //so attempt to remove exceptions + constructor = Method.getMethod(constructorString.substring(0, constructorString.indexOf(")") + 1)); + } else { + //As a backup, just pass in the generic string as before + constructor = Method.getMethod(constructorString); + } Type[] argTypes = constructor.getArgumentTypes(); if (argTypes.length == 0) { Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java Wed Jan 7 19:37:42 2015 @@ -44,13 +44,13 @@ public class ProxySubclassHierarchyAdapt private Collection<String> methodsToImplement = null; private static Logger LOGGER = LoggerFactory.getLogger(ProxySubclassHierarchyAdapter.class); - - ProxySubclassHierarchyAdapter(ProxySubclassAdapter adapter, Collection<String> methodsToImplement) - { - super(Opcodes.ASM4); - LOGGER.debug(Constants.LOG_ENTRY, "ProxySubclassHeirarchyAdapter", new Object[] { - this, adapter, methodsToImplement }); - + + ProxySubclassHierarchyAdapter(ProxySubclassAdapter adapter, Collection<String> methodsToImplement) + { + super(Opcodes.ASM5); + LOGGER.debug(Constants.LOG_ENTRY, "ProxySubclassHeirarchyAdapter", new Object[] { + this, adapter, methodsToImplement }); + this.methodsToImplement = methodsToImplement; this.adapter = adapter; Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java Wed Jan 7 19:37:42 2015 @@ -58,13 +58,13 @@ final class InterfaceCombiningClassAdapt * @param className * @param loader * @param interfaces - */ - InterfaceCombiningClassAdapter(String className, - ClassLoader loader, Class<?> superclass, Collection<Class<?>> interfaces) { - super(Opcodes.ASM4); - writer = new OSGiFriendlyClassWriter(ClassWriter.COMPUTE_FRAMES, loader); - ClassVisitor cv = new OSGiFriendlyClassVisitor(writer, ClassWriter.COMPUTE_FRAMES); - adapter = new InterfaceUsingWovenProxyAdapter(cv, className, loader); + */ + InterfaceCombiningClassAdapter(String className, + ClassLoader loader, Class<?> superclass, Collection<Class<?>> interfaces) { + super(Opcodes.ASM5); + writer = new OSGiFriendlyClassWriter(ClassWriter.COMPUTE_FRAMES, loader); + ClassVisitor cv = new OSGiFriendlyClassVisitor(writer, ClassWriter.COMPUTE_FRAMES); + adapter = new InterfaceUsingWovenProxyAdapter(cv, className, loader); this.interfaces = interfaces; this.superclass = superclass; Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java Wed Jan 7 19:37:42 2015 @@ -36,6 +36,7 @@ import org.apache.aries.proxy.UnableToPr import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.Opcodes; import org.osgi.framework.Bundle; +import org.osgi.framework.wiring.BundleWiring; /** * This class is used to aggregate several interfaces into a real class which implements all of them @@ -44,15 +45,15 @@ import org.osgi.framework.Bundle; * To be safely used as a supertype the superclass should be a WovenProxy. */ public final class InterfaceProxyGenerator extends ClassVisitor implements Opcodes { - - public InterfaceProxyGenerator() - { - super(Opcodes.ASM4); - - } - - private static final Map<Bundle, WeakReference<ProxyClassLoader>> cache = - new WeakHashMap<Bundle, WeakReference<ProxyClassLoader>>(128); + + public InterfaceProxyGenerator() + { + super(Opcodes.ASM5); + + } + + private static final Map<BundleWiring, WeakReference<ProxyClassLoader>> cache = + new WeakHashMap<BundleWiring, WeakReference<ProxyClassLoader>>(128); /** * Generate a new proxy instance implementing the supplied interfaces and using the supplied @@ -65,7 +66,7 @@ public final class InterfaceProxyGenerat * @return * @throws UnableToProxyException */ - public static final Object getProxyInstance(Bundle client, Class<?> superclass, + public static Object getProxyInstance(Bundle client, Class<?> superclass, Collection<Class<?>> ifaces, Callable<Object> dispatcher, InvocationListener listener) throws UnableToProxyException{ if(superclass != null && (superclass.getModifiers() & Modifier.FINAL) != 0) @@ -76,24 +77,25 @@ public final class InterfaceProxyGenerat SortedSet<Class<?>> interfaces = createSet(ifaces); synchronized (cache) { - WeakReference<ProxyClassLoader> ref = cache.get(client); + BundleWiring wiring = client == null ? null : (BundleWiring)client.adapt(BundleWiring.class); + WeakReference<ProxyClassLoader> ref = cache.get(wiring); if(ref != null) pcl = ref.get(); if (pcl != null && pcl.isInvalid(interfaces)) { pcl = null; - cache.remove(client); + cache.remove(wiring); } if(pcl == null) { pcl = new ProxyClassLoader(client); - cache.put(client, new WeakReference<ProxyClassLoader>(pcl)); + cache.put(wiring, new WeakReference<ProxyClassLoader>(pcl)); } } - + Class<?> c = pcl.createProxyClass(superclass, interfaces); - + try { Constructor<?> con = c.getDeclaredConstructor(Callable.class, InvocationListener.class); con.setAccessible(true); Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java Wed Jan 7 19:37:42 2015 @@ -17,13 +17,13 @@ * under the License. */ package org.apache.aries.proxy.impl.weaving; - -import java.lang.reflect.Modifier; - -import static org.objectweb.asm.Opcodes.ASM4; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; + +import java.lang.reflect.Modifier; + +import static org.objectweb.asm.Opcodes.ASM5; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; import org.objectweb.asm.commons.SerialVersionUIDAdder; class SyntheticSerialVerUIDAdder extends SerialVersionUIDAdder { @@ -39,13 +39,13 @@ class SyntheticSerialVerUIDAdder extends /** * Set to true if the class already has SVUID. */ - private boolean hasSVUID; - - public SyntheticSerialVerUIDAdder(WovenProxyAdapter cv) { - super(ASM4, cv); - wpa = cv; - } - + private boolean hasSVUID; + + public SyntheticSerialVerUIDAdder(WovenProxyAdapter cv) { + super(ASM5, cv); + wpa = cv; + } + // The following visit and visitField methods are workaround since ASM4 does not supply the javadoced method isHasSVUID() by mistake. // When the method isHasSVUId() or similar methods available, we can remove the following two methods. Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java Wed Jan 7 19:37:42 2015 @@ -80,13 +80,13 @@ public class Synthesizer public static class CustomClassVisitor extends ClassVisitor { - - public CustomClassVisitor( ClassVisitor cv) - { - super(Opcodes.ASM4, cv); - - } - @Override + + public CustomClassVisitor( ClassVisitor cv) + { + super(Opcodes.ASM5, cv); + + } + @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java Wed Jan 7 19:37:42 2015 @@ -27,10 +27,12 @@ import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; import java.io.Closeable; +import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Dictionary; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -45,6 +47,9 @@ import org.apache.aries.util.ClassLoader import org.junit.Before; import org.junit.Test; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.framework.wiring.BundleRevision; +import org.osgi.framework.wiring.BundleWiring; public class InterfaceProxyingTest { @@ -67,12 +72,34 @@ public class InterfaceProxyingTest { list = o; } } - + private Bundle testBundle; - + + /** + * Extended BundleMock which handles update() and adapt() methods + */ + public static class BundleMockEx extends BundleMock { + private BundleWiring currentWiring = Skeleton.newMock(BundleWiring.class); + + public BundleMockEx(String name, Dictionary<?, ?> properties) { + super(name, properties); + } + + public <A> A adapt(Class<A> type) { + if (type == BundleWiring.class) { + return (A) currentWiring; + } + return null; + } + + public void update() throws BundleException { + this.currentWiring = Skeleton.newMock(BundleWiring.class); + } + } + @Before public void setup() { - testBundle = Skeleton.newMock(new BundleMock("test", + testBundle = Skeleton.newMock(new BundleMockEx("test", new Hashtable<Object, Object>()), Bundle.class); } @@ -249,25 +276,35 @@ public class InterfaceProxyingTest { TestClassLoader loader = new TestClassLoader(); skel.setReturnValue(new MethodCall(ClassLoaderProxy.class, "getClassLoader"), loader); skel.setReturnValue(new MethodCall(Bundle.class, "getLastModified"), 10l); - + skel.setReturnValue(new MethodCall(Bundle.class, "adapt", BundleWiring.class), Skeleton.newMock(BundleWiring.class)); + Class<?> clazz = loader.loadClass("org.apache.aries.blueprint.proxy.TestInterface"); Object proxy = InterfaceProxyGenerator.getProxyInstance(bundle, null, Arrays.<Class<?>>asList(clazz), constantly(null), null); assertTrue(clazz.isInstance(proxy)); + + ClassLoader parent1 = proxy.getClass().getClassLoader().getParent(); /* Now again but with a changed classloader as if the bundle had refreshed */ TestClassLoader loaderToo = new TestClassLoader(); skel.setReturnValue(new MethodCall(ClassLoaderProxy.class, "getClassLoader"), loaderToo); skel.setReturnValue(new MethodCall(Bundle.class, "getLastModified"), 20l); + + // let's change the returned revision + skel.setReturnValue(new MethodCall(Bundle.class, "adapt", BundleWiring.class), Skeleton.newMock(BundleWiring.class)); Class<?> clazzToo = loaderToo.loadClass("org.apache.aries.blueprint.proxy.TestInterface"); Object proxyToo = InterfaceProxyGenerator.getProxyInstance(bundle, null, Arrays.<Class<?>>asList(clazzToo), constantly(null), null); assertTrue(clazzToo.isInstance(proxyToo)); + + ClassLoader parent2= proxyToo.getClass().getClassLoader().getParent(); + + // parents should be different, as the are the classloaders of different bundle revisions + assertTrue(parent1 != parent2); } - - + protected void assertCalled(TestListener listener, boolean pre, boolean post, boolean ex) { assertEquals(pre, listener.preInvoke); assertEquals(post, listener.postInvoke); Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java Wed Jan 7 19:37:42 2015 @@ -55,6 +55,7 @@ import org.apache.aries.util.ClassLoader import org.junit.BeforeClass; import org.junit.Test; import org.osgi.framework.Bundle; +import org.osgi.framework.wiring.BundleWiring; public class WovenProxyGeneratorTest extends AbstractProxyTest @@ -496,10 +497,13 @@ public class WovenProxyGeneratorTest ext @Test public void testWovenClassPlusInterfaces() throws Exception { Bundle b = (Bundle) Skeleton.newMock(new Class<?>[] {Bundle.class, ClassLoaderProxy.class}); - + BundleWiring bw = (BundleWiring) Skeleton.newMock(BundleWiring.class); + Skeleton.getSkeleton(b).setReturnValue(new MethodCall( ClassLoaderProxy.class, "getClassLoader"), weavingLoader); - + Skeleton.getSkeleton(b).setReturnValue(new MethodCall( + ClassLoaderProxy.class, "adapt", BundleWiring.class), bw); + Object toCall = new AsmProxyManager().createDelegatingProxy(b, Arrays.asList( getProxyClass(ProxyTestClassAbstract.class), Callable.class), new Callable() { Modified: aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java (original) +++ aries/branches/subsystemsR6/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java Wed Jan 7 19:37:42 2015 @@ -49,6 +49,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.osgi.framework.Bundle; +import org.osgi.framework.wiring.BundleWiring; /** * This class uses the {@link ProxySubclassGenerator} to test @@ -64,13 +65,17 @@ public class WovenProxyPlusSubclassGener private Callable<Object> testCallable = null; private static Bundle testBundle; - + private static BundleWiring testBundleWiring; + @BeforeClass public static void createTestBundle() { testBundle = (Bundle) Skeleton.newMock(new Class<?>[] {Bundle.class, ClassLoaderProxy.class}); - + testBundleWiring = (BundleWiring) Skeleton.newMock(BundleWiring.class); + Skeleton.getSkeleton(testBundle).setReturnValue(new MethodCall( ClassLoaderProxy.class, "getClassLoader"), weavingLoader); + Skeleton.getSkeleton(testBundle).setReturnValue(new MethodCall( + ClassLoaderProxy.class, "adapt", BundleWiring.class), testBundleWiring); } //Avoid running four weaving tests that don't apply to us Modified: aries/branches/subsystemsR6/proxy/proxy-itests/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/proxy/proxy-itests/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/proxy/proxy-itests/pom.xml (original) +++ aries/branches/subsystemsR6/proxy/proxy-itests/pom.xml Wed Jan 7 19:37:42 2015 @@ -75,7 +75,7 @@ <groupId>org.apache.aries.proxy</groupId> <artifactId>org.apache.aries.proxy.impl</artifactId> <scope>test</scope> - <version>1.0.4-SNAPSHOT</version> + <version>1.0.5-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.aries</groupId> Modified: aries/branches/subsystemsR6/subsystem/subsystem-api/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-api/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-api/pom.xml (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-api/pom.xml Wed Jan 7 19:37:42 2015 @@ -72,6 +72,12 @@ <artifactId>org.osgi.annotation</artifactId> <version>6.0.0</version> </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.enterprise</artifactId> + <version>5.0.0</version> + <scope>provided</scope> + </dependency> </dependencies> <build> Modified: aries/branches/subsystemsR6/subsystem/subsystem-bundle/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-bundle/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-bundle/pom.xml (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-bundle/pom.xml Wed Jan 7 19:37:42 2015 @@ -71,7 +71,7 @@ <dependency> <groupId>org.apache.aries.subsystem</groupId> <artifactId>org.apache.aries.subsystem.core</artifactId> - <version>1.0.1-SNAPSHOT</version> + <version>1.2.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.aries</groupId> Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/pom.xml (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/pom.xml Wed Jan 7 19:37:42 2015 @@ -32,7 +32,7 @@ <artifactId>org.apache.aries.subsystem.core</artifactId> <packaging>bundle</packaging> <name>Apache Aries Subsystem Core</name> - <version>1.0.1-SNAPSHOT</version> + <version>1.2.0-SNAPSHOT</version> <description>Subsystems Core.</description> <scm> @@ -51,7 +51,7 @@ org.apache.aries.application.*;resolution:=optional, * </aries.osgi.import> - <aries.osgi.export.pkg/> + <aries.osgi.export.pkg /> <aries.osgi.private.pkg> org.apache.aries.subsystem.core.* </aries.osgi.private.pkg> Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/Grammar.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/Grammar.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/Grammar.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/Grammar.java Wed Jan 7 19:37:42 2015 @@ -15,17 +15,17 @@ package org.apache.aries.subsystem.core. public interface Grammar { -// section: *header +newline -// nonempty-section: +header +newline -// newline: CR LF | LF | CR (not followed by LF) -// header: name : value -// name: alphanum *headerchar -// value: SPACE *otherchar newline *continuation -// continuation: SPACE *otherchar newline -// alphanum: {A-Z} | {a-z} | {0-9} -// headerchar: alphanum | - | _ +// section: *header +newline +// nonempty-section: +header +newline +// newline: CR LF | LF | CR (not followed by LF) +// header: name : value +// name: alphanum *headerchar +// value: SPACE *otherchar newline *continuation +// continuation: SPACE *otherchar newline +// alphanum: {A-Z} | {a-z} | {0-9} +// headerchar: alphanum | - | _ // otherchar: any UTF-8 character except NUL, CR and LF - + // public static final String ALPHA = "[A-Za-z]"; // public static final String DIGIT = "[0-9]"; // public static final String ALPHANUM = ALPHA + '|' + DIGIT; @@ -39,16 +39,16 @@ public interface Grammar { // public static final String HEADER = NAME + ':' + VALUE; // public static final String SECTION = "(?:" + HEADER + ")*(?:" + NEWLINE + ")+"; // public static final String NONEMPTY_SECTION = "(?:" + HEADER + ")+(?:" + NEWLINE + ")+"; - -// manifest-file: main-section newline *individual-section -// main-section: version-info newline *main-attribute -// version-info: Manifest-Version : version-number -// version-number : digit+{.digit+}* -// main-attribute: (any legitimate main attribute) newline -// individual-section: Name : value newline *perentry-attribute -// perentry-attribute: (any legitimate perentry attribute) newline + +// manifest-file: main-section newline *individual-section +// main-section: version-info newline *main-attribute +// version-info: Manifest-Version : version-number +// version-number : digit+{.digit+}* +// main-attribute: (any legitimate main attribute) newline +// individual-section: Name : value newline *perentry-attribute +// perentry-attribute: (any legitimate perentry attribute) newline // digit: {0-9} - + // public static final String VERSION_NUMBER = DIGIT + "+(?:\\." + DIGIT + "+)*"; // public static final String VERSION_INFO = "Manifest-Version: " + VERSION_NUMBER; // public static final String MAIN_ATTRIBUTE = HEADER + NEWLINE; @@ -56,7 +56,7 @@ public interface Grammar { // public static final String PERENTRY_ATTRIBUTE = HEADER + NEWLINE; // public static final String INDIVIDUAL_SECTION = "Name: " + VALUE + NEWLINE + "(?:" + PERENTRY_ATTRIBUTE + ")*"; // public static final String MANIFEST_FILE = MAIN_SECTION + NEWLINE + "(?:" + INDIVIDUAL_SECTION + ")*"; - + // digit ::= [0..9] // alpha ::= [a..zA..Z] // alphanum ::= alpha | digit @@ -72,7 +72,7 @@ public interface Grammar { // path-sep ::= / // header ::= clause ( , clause ) * // clause ::= path ( ; path ) * ( ; parameter ) * - + public static final String DIGIT = "[0-9]"; public static final String ALPHA = "[A-Za-z]"; public static final String ALPHANUM = DIGIT + '|' + ALPHA; @@ -93,7 +93,7 @@ public interface Grammar { public static final String HEADERCHAR = ALPHANUM + "|_|-"; public static final String NAME = ALPHANUM + "(?:" + HEADERCHAR + ")*"; public static final String HEADER = NAME + ": " + CLAUSE + "(?:," + CLAUSE + ")*"; - + /* * jletter ::= a character for which the method Character.isJavaIdentifierStart(int) returns true * jletterordigit::= a character for which the method Character.isJavaIdentifierPart(int) returns true @@ -104,7 +104,7 @@ public interface Grammar { * import ::= package-names ( ';' parameter )* * package-names ::= package-name ( ';' package-name )* // See 1.3.2 */ - + public static final String JLETTER = "\\p{javaJavaIdentifierStart}"; public static final String JLETTERORDIGIT = "\\p{javaJavaIdentifierPart}"; public static final String IDENTIFIER = JLETTER + "(?:" + JLETTERORDIGIT + ")*"; @@ -114,32 +114,33 @@ public interface Grammar { public static final String PACKAGENAMES = PACKAGENAME + "\\s*(?:\\;\\s*" + PACKAGENAME + ")*"; public static final String IMPORT = PACKAGENAMES + "(?:;\\s*(?:" + PARAMETER + "))*"; public static final String IMPORTPACKAGE = IMPORT + "(?:\\,\\s*" + IMPORT + ")*"; - + public static final String NAMESPACE = SYMBOLICNAME; public static final String REQUIREMENT = NAMESPACE + "(?:;\\s*(?:" + PARAMETER + "))*"; public static final String REQUIRE_CAPABILITY = REQUIREMENT + "(?:,\\s*(?:" + REQUIREMENT + "))*"; - + public static final String BUNDLE_DESCRIPTION = SYMBOLICNAME + "(?:;\\s*(?:" + PARAMETER + "))*"; public static final String REQUIRE_BUNDLE = BUNDLE_DESCRIPTION + "(?:,\\s*(?:" + BUNDLE_DESCRIPTION + "))*"; - + public static final String EXPORT = PACKAGENAMES + "(?:;\\s*(?:" + PARAMETER + "))*"; public static final String EXPORT_PACKAGE = EXPORT + "(?:,\\s*(?:" + EXPORT + "))*"; - + public static final String SCALAR = "String|Version|Long|Double"; public static final String LIST = "List<(?:" + SCALAR + ")>"; public static final String TYPE = "(?:" + SCALAR + ")|" + LIST; public static final String TYPED_ATTR = EXTENDED + "(?:\\:" + TYPE + ")?=(?:" + ARGUMENT + ')'; public static final String CAPABILITY = NAMESPACE + "(?:;\\s*(?:(?:" + DIRECTIVE + ")|(?:" + TYPED_ATTR + ")))*"; public static final String PROVIDE_CAPABILITY = CAPABILITY + "(?:,\\s*(?:" + CAPABILITY + "))*"; - + public static final String OBJECTCLASS = PACKAGENAME; - public static final String SERVICE = OBJECTCLASS + "(?:;\\s*(?:" + PARAMETER + "))*"; - public static final String SUBSYSTEM_EXPORTSERVICE = SERVICE + "(?:,\\s*(?:" + SERVICE + "))*"; - public static final String SUBSYSTEM_IMPORTSERVICE = SERVICE + "(?:,\\s*(?:" + SERVICE + "))*"; - + public static final String SERVICE_OR_WILDCARD = "(" + OBJECTCLASS + "|[*])(?:;\\s*(?:" + PARAMETER + "))*"; + public static final String SUBSYSTEM_IMPORTEXPORTSERVICE = SERVICE_OR_WILDCARD + "(?:,\\s*(?:" + SERVICE_OR_WILDCARD + "))*"; + public static final String SUBSYSTEM_EXPORTSERVICE = SUBSYSTEM_IMPORTEXPORTSERVICE; + public static final String SUBSYSTEM_IMPORTSERVICE = SUBSYSTEM_IMPORTEXPORTSERVICE; + public static final String RESOURCE = SYMBOLICNAME + "(?:;\\s*(?:" + PARAMETER + "))*"; public static final String PREFERRED_PROVIDER = RESOURCE + "(?:,\\s*(?:" + RESOURCE + "))*"; - + /* * number ::= digit+ * version ::= major( '.' minor ( '.' micro ( '.' qualifier )? )? )? @@ -153,7 +154,7 @@ public interface Grammar { * floor ::= version * ceiling ::= version */ - + public static final String NUMBER = DIGIT + '+'; public static final String MAJOR = NUMBER; public static final String MINOR = NUMBER; Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemExportServiceHeader.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemExportServiceHeader.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemExportServiceHeader.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemExportServiceHeader.java Wed Jan 7 19:37:42 2015 @@ -36,19 +36,19 @@ import org.osgi.service.subsystem.Subsys public class SubsystemExportServiceHeader implements Header<SubsystemExportServiceHeader.Clause> { public static class Clause implements org.apache.aries.subsystem.core.archive.Clause { public static final String DIRECTIVE_FILTER = Constants.FILTER_DIRECTIVE; - - private static final Pattern PATTERN_OBJECTCLASS = Pattern.compile('(' + Grammar.OBJECTCLASS + ")(?=;|\\z)"); + + private static final Pattern PATTERN_OBJECTCLASS_OR_STAR = Pattern.compile("((" + Grammar.OBJECTCLASS + ")|[*])(?=;|\\z)"); private static final Pattern PATTERN_PARAMETER = Pattern.compile('(' + Grammar.PARAMETER + ")(?=;|\\z)"); - + private static void fillInDefaults(Map<String, Parameter> parameters) { // No defaults. } - + private final String path; private final Map<String, Parameter> parameters = new HashMap<String, Parameter>(); - + public Clause(String clause) { - Matcher main = PATTERN_OBJECTCLASS.matcher(clause); + Matcher main = PATTERN_OBJECTCLASS_OR_STAR.matcher(clause); if (!main.find()) throw new IllegalArgumentException("Missing objectClass path: " + clause); path = main.group(); @@ -59,7 +59,7 @@ public class SubsystemExportServiceHeade } fillInDefaults(parameters); } - + @Override public Attribute getAttribute(String name) { Parameter result = parameters.get(name); @@ -101,7 +101,7 @@ public class SubsystemExportServiceHeade directives.trimToSize(); return directives; } - + public String getObjectClass() { return path; } @@ -115,12 +115,12 @@ public class SubsystemExportServiceHeade public Collection<Parameter> getParameters() { return Collections.unmodifiableCollection(parameters.values()); } - + @Override public String getPath() { return path; } - + public List<Capability> toCapabilities(Resource resource) throws InvalidSyntaxException { List<Capability> capabilities = resource.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE); if (capabilities.isEmpty()) @@ -133,7 +133,7 @@ public class SubsystemExportServiceHeade result.trimToSize(); return result; } - + @Override public String toString() { StringBuilder builder = new StringBuilder() @@ -143,11 +143,11 @@ public class SubsystemExportServiceHeade } return builder.toString(); } - + private Filter computeFilter() throws InvalidSyntaxException { return FrameworkUtil.createFilter(computeFilterString()); } - + private String computeFilterString() { Directive directive = getDirective(DIRECTIVE_FILTER); return new StringBuilder() @@ -161,13 +161,13 @@ public class SubsystemExportServiceHeade .toString(); } } - + public static final String NAME = SubsystemConstants.SUBSYSTEM_EXPORTSERVICE; - - private static final Pattern PATTERN = Pattern.compile('(' + Grammar.SERVICE + ")(?=,|\\z)"); - + + private static final Pattern PATTERN = Pattern.compile("(" + Grammar.SUBSYSTEM_EXPORTSERVICE + ")(?=,|\\z)"); + private final Set<Clause> clauses = new HashSet<Clause>(); - + public SubsystemExportServiceHeader(String value) { Matcher matcher = PATTERN.matcher(value); while (matcher.find()) @@ -175,7 +175,7 @@ public class SubsystemExportServiceHeade if (clauses.isEmpty()) throw new IllegalArgumentException("A " + NAME + " header must have at least one clause"); } - + @Override public Collection<SubsystemExportServiceHeader.Clause> getClauses() { return Collections.unmodifiableSet(clauses); @@ -190,14 +190,14 @@ public class SubsystemExportServiceHeade public String getValue() { return toString(); } - + public List<Capability> toCapabilities(Resource resource) throws InvalidSyntaxException { List<Capability> result = new ArrayList<Capability>(); for (Clause clause : clauses) result.addAll(clause.toCapabilities(resource)); return result; } - + @Override public String toString() { StringBuilder builder = new StringBuilder(); Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemImportServiceHeader.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemImportServiceHeader.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemImportServiceHeader.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemImportServiceHeader.java Wed Jan 7 19:37:42 2015 @@ -35,10 +35,10 @@ public class SubsystemImportServiceHeade public static final String DIRECTIVE_EFFECTIVE = Constants.EFFECTIVE_DIRECTIVE; public static final String DIRECTIVE_FILTER = Constants.FILTER_DIRECTIVE; public static final String DIRECTIVE_RESOLUTION = Constants.RESOLUTION_DIRECTIVE; - - private static final Pattern PATTERN_NAMESPACE = Pattern.compile('(' + Grammar.NAMESPACE + ")(?=;|\\z)"); + + private static final Pattern PATTERN_OBJECTCLASS_OR_STAR = Pattern.compile("((" + Grammar.OBJECTCLASS + ")|[*])(?=;|\\z)"); private static final Pattern PATTERN_PARAMETER = Pattern.compile('(' + Grammar.PARAMETER + ")(?=;|\\z)"); - + private static void fillInDefaults(Map<String, Parameter> parameters) { Parameter parameter = parameters.get(DIRECTIVE_EFFECTIVE); if (parameter == null) @@ -47,12 +47,12 @@ public class SubsystemImportServiceHeade if (parameter == null) parameters.put(DIRECTIVE_RESOLUTION, ResolutionDirective.MANDATORY); } - + private final String path; private final Map<String, Parameter> parameters = new HashMap<String, Parameter>(); - + public Clause(String clause) { - Matcher matcher = PATTERN_NAMESPACE.matcher(clause); + Matcher matcher = PATTERN_OBJECTCLASS_OR_STAR.matcher(clause); if (!matcher.find()) throw new IllegalArgumentException("Missing namespace path: " + clause); path = matcher.group(); @@ -63,13 +63,13 @@ public class SubsystemImportServiceHeade } fillInDefaults(parameters); } - + public Clause(Requirement requirement) { path = requirement.getNamespace(); for (Entry<String, String> directive : requirement.getDirectives().entrySet()) parameters.put(directive.getKey(), DirectiveFactory.createDirective(directive.getKey(), directive.getValue())); } - + @Override public Attribute getAttribute(String name) { Parameter result = parameters.get(name); @@ -126,11 +126,11 @@ public class SubsystemImportServiceHeade public String getPath() { return path; } - + public SubsystemImportServiceRequirement toRequirement(Resource resource) { return new SubsystemImportServiceRequirement(this, resource); } - + @Override public String toString() { StringBuilder builder = new StringBuilder() @@ -141,12 +141,11 @@ public class SubsystemImportServiceHeade return builder.toString(); } } - + public static final String NAME = SubsystemConstants.SUBSYSTEM_IMPORTSERVICE; - - // TODO Subsystem-ImportService currently does not have its own grammar, but it's similar to Require-Capability. - private static final Pattern PATTERN = Pattern.compile('(' + Grammar.REQUIREMENT + ")(?=,|\\z)"); - + + private static final Pattern PATTERN = Pattern.compile("(" + Grammar.SUBSYSTEM_IMPORTSERVICE + ")(?=,|\\z)"); + private static Collection<Clause> processHeader(String header) { Matcher matcher = PATTERN.matcher(header); Set<Clause> clauses = new HashSet<Clause>(); @@ -154,19 +153,19 @@ public class SubsystemImportServiceHeade clauses.add(new Clause(matcher.group())); return clauses; } - + private final Set<Clause> clauses; - + public SubsystemImportServiceHeader(String value) { this(processHeader(value)); } - + public SubsystemImportServiceHeader(Collection<Clause> clauses) { if (clauses.isEmpty()) throw new IllegalArgumentException("A " + NAME + " header must have at least one clause"); this.clauses = new HashSet<Clause>(clauses); } - + @Override public Collection<SubsystemImportServiceHeader.Clause> getClauses() { return Collections.unmodifiableSet(clauses); @@ -181,7 +180,7 @@ public class SubsystemImportServiceHeade public String getValue() { return toString(); } - + @Override public List<SubsystemImportServiceRequirement> toRequirements(Resource resource) { List<SubsystemImportServiceRequirement> requirements = new ArrayList<SubsystemImportServiceRequirement>(clauses.size()); @@ -189,7 +188,7 @@ public class SubsystemImportServiceHeade requirements.add(clause.toRequirement(resource)); return requirements; } - + @Override public String toString() { StringBuilder builder = new StringBuilder(); Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java Wed Jan 7 19:37:42 2015 @@ -19,6 +19,8 @@ import java.util.Dictionary; import java.util.HashSet; import java.util.Hashtable; +import org.apache.aries.subsystem.ContentHandler; +import org.apache.aries.subsystem.core.content.ConfigAdminContentHandler; import org.apache.aries.util.filesystem.IDirectoryFinder; import org.eclipse.equinox.region.RegionDigraph; import org.osgi.framework.BundleActivator; @@ -49,24 +51,25 @@ public class Activator implements Bundle public static final String LOG_EXIT = "Method exit: {}, returning {}"; private static Activator instance; - + public static synchronized Activator getInstance() { logger.debug(LOG_ENTRY, "getInstance"); checkInstance(); logger.debug(LOG_EXIT, "getInstance", instance); return instance; } - + private static synchronized void checkInstance() { logger.debug(LOG_ENTRY, "checkInstance"); if (instance == null) throw new IllegalStateException("The activator has not been initialized or has been shutdown"); logger.debug(LOG_EXIT, "checkInstance"); } - + // @GuardedBy("this") private BundleEventHook bundleEventHook; private volatile BundleContext bundleContext; + private volatile ConfigAdminContentHandler configAdminHandler; private volatile Coordinator coordinator; private volatile Object modelledResourceManager; private volatile ServiceModeller serviceModeller; @@ -76,18 +79,18 @@ public class Activator implements Bundle private ServiceTracker<?,?> serviceTracker; private volatile Subsystems subsystems; - + private final Collection<ServiceRegistration<?>> registrations = new HashSet<ServiceRegistration<?>>(); private final Collection<IDirectoryFinder> finders = Collections.synchronizedSet(new HashSet<IDirectoryFinder>()); - + public BundleContext getBundleContext() { return bundleContext; } - + public Coordinator getCoordinator() { return coordinator; } - + public ServiceModeller getServiceModeller() { return serviceModeller; } @@ -95,26 +98,26 @@ public class Activator implements Bundle public RegionDigraph getRegionDigraph() { return regionDigraph; } - + public Collection<IDirectoryFinder> getIDirectoryFinders() { return Collections.unmodifiableCollection(finders); } - + public Resolver getResolver() { return resolver; } - + public Subsystems getSubsystems() { return subsystems; } - + public SubsystemServiceRegistrar getSubsystemServiceRegistrar() { logger.debug(LOG_ENTRY, "getSubsystemServiceRegistrar"); SubsystemServiceRegistrar result = registrar; logger.debug(LOG_EXIT, "getSubsystemServiceRegistrar", result); return result; } - + public org.apache.aries.subsystem.core.repository.Repository getSystemRepository() { return new SystemRepository(getSubsystems().getRootSubsystem()); } @@ -136,7 +139,7 @@ public class Activator implements Bundle bundleContext = null; logger.debug(LOG_EXIT, "stop"); } - + private void activate() { if (isActive() || !hasRequiredServices()) return; @@ -146,13 +149,17 @@ public class Activator implements Bundle subsystems = new Subsystems(); registerBundleEventHook(); registrations.add(bundleContext.registerService(ResolverHookFactory.class, new SubsystemResolverHookFactory(subsystems), null)); + Dictionary<String, Object> handlerProps = new Hashtable<String, Object>(); + handlerProps.put(ContentHandler.CONTENT_TYPE_PROPERTY, ConfigAdminContentHandler.CONTENT_TYPES); + configAdminHandler = new ConfigAdminContentHandler(bundleContext); + registrations.add(bundleContext.registerService(ContentHandler.class, configAdminHandler, handlerProps)); registrar = new SubsystemServiceRegistrar(bundleContext); BasicSubsystem root = subsystems.getRootSubsystem(); bundleEventHook.activate(); root.start(); registerWovenClassListener(); } - + private void deactivate() { if (!isActive()) return; @@ -166,12 +173,13 @@ public class Activator implements Bundle logger.debug("Service had already been unregistered", e); } } + configAdminHandler.shutDown(); bundleEventHook.processPendingEvents(); synchronized (Activator.class) { instance = null; } } - + private <T> T findAlternateServiceFor(Class<T> service) { Object[] services = serviceTracker.getServices(); if (services == null) @@ -181,11 +189,11 @@ public class Activator implements Bundle return service.cast(alternate); return null; } - + private Filter generateServiceFilter() throws InvalidSyntaxException { return FrameworkUtil.createFilter(generateServiceFilterString()); } - + private String generateServiceFilterString() { return new StringBuilder("(|(") .append(org.osgi.framework.Constants.OBJECTCLASS).append('=') @@ -201,26 +209,26 @@ public class Activator implements Bundle .append(org.osgi.framework.Constants.OBJECTCLASS).append('=') .append(IDirectoryFinder.class.getName()).append("))").toString(); } - + private boolean hasRequiredServices() { return coordinator != null && regionDigraph != null && resolver != null; } - + private boolean isActive() { synchronized (Activator.class) { return instance != null && getSubsystems() != null; } } - + private void registerBundleEventHook() { Dictionary<String, Object> properties = new Hashtable<String, Object>(1); properties.put(org.osgi.framework.Constants.SERVICE_RANKING, Integer.MAX_VALUE); bundleEventHook = new BundleEventHook(); registrations.add(bundleContext.registerService(EventHook.class, bundleEventHook, properties)); } - + private void registerWovenClassListener() { registrations.add( bundleContext.registerService( @@ -319,6 +327,6 @@ public class Activator implements Bundle } } } - + /* End ServiceTrackerCustomizer methods */ }
