[webbeans-commits] Webbeans SVN: r1411 - in tck/trunk/impl/src: main/java/org/jboss/webbeans/tck/impl/packaging and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Feb 4 13:28:43 EST 2009
Author: pete.muir at jboss.org
Date: 2009-02-04 13:28:42 -0500 (Wed, 04 Feb 2009)
New Revision: 1411
Removed:
tck/trunk/impl/src/main/resources/org/jboss/webbeans/tck/impl/packaging/war/beans.xml
Modified:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/IntegratedContainers.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/packaging/ArtifactDescriptor.java
tck/trunk/impl/src/test/java/org/jboss/webbeans/tck/impl/test/packaging/ArtifactTest.java
Log:
Produce a JAR
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/IntegratedContainers.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/IntegratedContainers.java 2009-02-04 17:19:36 UTC (rev 1410)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/IntegratedContainers.java 2009-02-04 18:28:42 UTC (rev 1411)
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.List;
+import java.util.jar.JarInputStream;
import javax.inject.manager.Manager;
@@ -39,7 +40,7 @@
{
try
{
- return deploy(new TCKArtifactDescriptor(null).asJar());
+ return deploy(new JarInputStream(new TCKArtifactDescriptor(null).asJar()));
}
catch (IOException e)
{
@@ -51,7 +52,7 @@
{
try
{
- return deploy(enabledDeploymentTypes, new TCKArtifactDescriptor(null).asJar());
+ return deploy(enabledDeploymentTypes, new JarInputStream(new TCKArtifactDescriptor(null).asJar()));
}
catch (IOException e)
{
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/packaging/ArtifactDescriptor.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/packaging/ArtifactDescriptor.java 2009-02-04 17:19:36 UTC (rev 1410)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/packaging/ArtifactDescriptor.java 2009-02-04 18:28:42 UTC (rev 1411)
@@ -3,7 +3,10 @@
import static org.jboss.webbeans.tck.impl.util.Reflections.loadResourceAsStream;
import static org.jboss.webbeans.tck.impl.util.Reflections.loadResources;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -15,6 +18,8 @@
import java.util.Random;
import java.util.Set;
import java.util.jar.JarInputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import org.apache.log4j.Logger;
@@ -97,6 +102,53 @@
}
}
+
+ private static class Zipper
+ {
+
+ private final File root;
+
+ public Zipper(File root)
+ {
+ this.root = root;
+ }
+
+ public InputStream zip() throws IOException
+ {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream);
+ zip(root, zipOutputStream);
+ zipOutputStream.close();
+ return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+ }
+
+ private void zip(File directory, ZipOutputStream zipOutputStream) throws IOException
+ {
+ File[] children = directory.listFiles();
+ byte[] readBuffer = new byte[2156];
+ int bytesIn = 0;
+ //loop through dirList, and zip the files
+ for (File child : children)
+ {
+ if (child.isDirectory())
+ {
+ zip(child, zipOutputStream);
+ }
+ else
+ {
+ FileInputStream fis = new FileInputStream(child);
+ ZipEntry zipEntry = new ZipEntry(child.getPath().substring(root.getPath().length() + 1));
+ zipOutputStream.putNextEntry(zipEntry);
+ while((bytesIn = fis.read(readBuffer)) != -1)
+ {
+ zipOutputStream.write(readBuffer, 0, bytesIn);
+ }
+ fis.close();
+ }
+ }
+ }
+
+ }
public static final Random random = new Random(System.currentTimeMillis());
@@ -113,8 +165,8 @@
}
public JarInputStream asJar() throws IOException
- {
- return new JarInputStream(create().toURL().openStream());
+ {
+ return new JarInputStream(new Zipper(create()).zip());
}
public File create() throws IOException
Deleted: tck/trunk/impl/src/main/resources/org/jboss/webbeans/tck/impl/packaging/war/beans.xml
===================================================================
Modified: tck/trunk/impl/src/test/java/org/jboss/webbeans/tck/impl/test/packaging/ArtifactTest.java
===================================================================
--- tck/trunk/impl/src/test/java/org/jboss/webbeans/tck/impl/test/packaging/ArtifactTest.java 2009-02-04 17:19:36 UTC (rev 1410)
+++ tck/trunk/impl/src/test/java/org/jboss/webbeans/tck/impl/test/packaging/ArtifactTest.java 2009-02-04 18:28:42 UTC (rev 1411)
@@ -2,6 +2,10 @@
import java.io.File;
import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
import org.jboss.webbeans.tck.AbstractTest;
import org.jboss.webbeans.tck.impl.packaging.ArtifactDescriptor;
@@ -66,4 +70,23 @@
assert getPackageAsFile(AbstractTest.class.getPackage(), root).listFiles().length > 0;
}
+ @Test
+ public void testJarProduction() throws Exception
+ {
+ WarArtifactDescriptor war = new WarArtifactDescriptor(null, null);
+ war.getClasses().add(Cow.class);
+ JarInputStream is = war.asJar();
+ JarEntry entry;
+ List<String> fileNames = new ArrayList<String>();
+ while ((entry = is.getNextJarEntry()) != null)
+ {
+ fileNames.add(entry.getName());
+ }
+ assert fileNames.contains("META-INF/beans.xml");
+ assert fileNames.contains("WEB-INF/web.xml");
+ assert fileNames.contains("org/jboss/webbeans/tck/impl/test/packaging/Cow.class");
+ assert fileNames.contains("org/jboss/webbeans/tck/AbstractTest.class");
+ assert fileNames.contains("org/jboss/webbeans/tck/impl/util/Reflections.class");
+ }
+
}
More information about the weld-commits
mailing list