[jboss-svn-commits] JBoss Common SVN: r3879 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 23 07:43:01 EST 2009
Author: aslak
Date: 2009-12-23 07:43:00 -0500 (Wed, 23 Dec 2009)
New Revision: 3879
Added:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAsset.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAssetTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummayInterfaceForTest.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummyClassForTest.java
Modified:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ManifestContainer.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Validate.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java
Log:
SHRINKWRAP-89 Added support method for adding SPI metadata to ManifestContainer
Modified: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ManifestContainer.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ManifestContainer.java 2009-12-23 10:13:31 UTC (rev 3878)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ManifestContainer.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -211,4 +211,22 @@
* @throws IllegalArgumentException if target is null
*/
T addManifestResource(Asset resource, Path target) throws IllegalArgumentException;
+
+ /**
+ * Adds a META-INF/services/ServiceInterfaceName {@link Asset} representing this service.
+ *
+ * Warning: this method does not add the specified classes to the archive.
+ *
+ * @param serviceInterface The Service Interface class
+ * @param serviceImpls The Service Interface Implementations
+ * @return This virtual archive
+ * @throws IllegalArgumentException if serviceInterface is null
+ * @throws IllegalArgumentException if serviceImpls is null or contain null values
+ */
+ /*
+ * TODO: The interface should have been like this:
+ * <X> T addServiceProvider(Class<X> serviceInterface, Class<? extends X>... serviceImpls) throws IllegalArgumentException;
+ * But due to how java generic works, this will cause a unsafe warning for the user.
+ */
+ T addServiceProvider(Class<?> serviceInterface, Class<?>... serviceImpls) throws IllegalArgumentException;
}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Validate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Validate.java 2009-12-23 10:13:31 UTC (rev 3878)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Validate.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -60,4 +60,19 @@
throw new IllegalArgumentException(message);
}
}
+
+ /**
+ * Checks that the specified array is not null or contain any null values.
+ *
+ * @param objects The object to check
+ * @param message The exception message
+ */
+ public static void notNullAndNoNullValues(final Object[] objects, final String message)
+ {
+ notNull(objects, message);
+ for(Object object : objects)
+ {
+ notNull(object, message);
+ }
+ }
}
Added: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAsset.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAsset.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.impl.base.asset;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.impl.base.Validate;
+
+/**
+ * ServiceProviderAsset
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ServiceProviderAsset implements Asset
+{
+ private Class<?>[] providerImpls;
+
+ /**
+ * Creates a newline separated text file off the providerImpls class names.
+ *
+ * @param providerImpls The Classes to use
+ * @throws IllegalArgumentException if providerImpls is null or contain null values
+ */
+ public ServiceProviderAsset(Class<?>... providerImpls)
+ {
+ Validate.notNullAndNoNullValues(providerImpls, "ProviderImpls must be specified and can not contain null values");
+ this.providerImpls = providerImpls;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.shrinkwrap.api.Asset#openStream()
+ */
+ @Override
+ public InputStream openStream()
+ {
+ StringBuilder content = new StringBuilder();
+ for(Class<?> providerImpl : providerImpls)
+ {
+ content.append(providerImpl.getName()).append('\n');
+ }
+ return new ByteArrayInputStream(content.toString().getBytes());
+ }
+}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2009-12-23 10:13:31 UTC (rev 3878)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -45,6 +45,7 @@
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
import org.jboss.shrinkwrap.impl.base.asset.DirectoryAsset;
import org.jboss.shrinkwrap.impl.base.asset.FileAsset;
+import org.jboss.shrinkwrap.impl.base.asset.ServiceProviderAsset;
import org.jboss.shrinkwrap.impl.base.asset.UrlAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
@@ -81,11 +82,6 @@
}
}
- /**
- * Filter pattern for inner classes
- */
- private static final String PATTERN_INNER_CLASS = "$.*";
-
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -469,6 +465,17 @@
return add(resource, location);
}
+ @Override
+ public T addServiceProvider(Class<?> serviceInterface, Class<?>... serviceImpls) throws IllegalArgumentException
+ {
+ Validate.notNull(serviceInterface, "ServiceInterface must be specified");
+ Validate.notNullAndNoNullValues(serviceImpls, "ServiceImpls must be specified and can not contain null values");
+
+ Asset asset = new ServiceProviderAsset(serviceImpls);
+ Path path = new BasicPath("services", serviceInterface.getName());
+ return addManifestResource(asset, path);
+ }
+
//-------------------------------------------------------------------------------------||
// Required Implementations - ResourceContainer ---------------------------------------||
//-------------------------------------------------------------------------------------||
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAssetTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAssetTestCase.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ServiceProviderAssetTestCase.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.impl.base.asset;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.impl.base.io.IOUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ * ServiceProviderAssetTestCase
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ServiceProviderAssetTestCase
+{
+
+ @Test
+ public void shouldCreateServiceProviderFile() throws Exception
+ {
+ Asset asset = new ServiceProviderAsset(TestImpl1.class, TestImpl2.class);
+
+ byte[] expectedContent = (TestImpl1.class.getName() + "\n" + TestImpl2.class.getName() + "\n").getBytes();
+ byte[] content = IOUtil.asByteArray(asset.openStream());
+
+ Assert.assertArrayEquals(expectedContent, content);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowExceptionOnNullArgumnet() throws Exception
+ {
+ new ServiceProviderAsset((Class<?>[])null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowExceptionOnNullArgumnetValue() throws Exception
+ {
+ new ServiceProviderAsset((Class<?>) null);
+ }
+
+ private interface TestIF {
+
+ }
+
+ private class TestImpl1 implements TestIF {
+
+ }
+
+ private class TestImpl2 implements TestIF {
+
+ }
+}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java 2009-12-23 10:13:31 UTC (rev 3878)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -38,6 +38,8 @@
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.impl.base.spec.donotchange.DummyClassA;
import org.jboss.shrinkwrap.impl.base.spec.donotchange.DummyClassParent;
+import org.jboss.shrinkwrap.impl.base.test.dummy.DummayInterfaceForTest;
+import org.jboss.shrinkwrap.impl.base.test.dummy.DummyClassForTest;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -253,6 +255,17 @@
"Archive should contain " + testPath,
getArchive().contains(testPath));
}
+
+ @Test
+ @ArchiveType(ManifestContainer.class)
+ public void testAddServiceProvider() throws Exception {
+ getManifestContainer().addServiceProvider(DummayInterfaceForTest.class, DummyClassForTest.class);
+
+ Path testPath = new BasicPath(getManifestPath(), "services/" + DummayInterfaceForTest.class.getName());
+ Assert.assertTrue(
+ "Archive should contain " + testPath,
+ getArchive().contains(testPath));
+ }
//-------------------------------------------------------------------------------------||
// Test Implementations - ResourceContainer -------------------------------------------||
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummayInterfaceForTest.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummayInterfaceForTest.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummayInterfaceForTest.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.impl.base.test.dummy;
+
+/**
+ * DummayInterfaceForTest
+ *
+ * Empty class to test class adding
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public interface DummayInterfaceForTest
+{
+
+}
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummyClassForTest.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummyClassForTest.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/dummy/DummyClassForTest.java 2009-12-23 12:43:00 UTC (rev 3879)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.shrinkwrap.impl.base.test.dummy;
+
+
+/**
+ * DummyClassForTest
+ *
+ * Empty class to test class adding
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class DummyClassForTest implements DummayInterfaceForTest
+{
+
+}
More information about the jboss-svn-commits
mailing list