Author: rmannibucau
Date: Fri Jul 1 17:47:33 2011
New Revision: 1142007
URL: http://svn.apache.org/viewvc?rev=1142007&view=rev
Log:
fixing cdi tests i broke last commit
Added:
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/util/
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/util/ZipUtil.java
Modified:
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/Archive.java
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
Modified:
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/Archive.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/Archive.java?rev=1142007&r1=1142006&r2=1142007&view=diff
==============================================================================
---
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/Archive.java
(original)
+++
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/Archive.java
Fri Jul 1 17:47:33 2011
@@ -1,146 +1,151 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.openejb.tck.impl;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.fail;
-
-/**
- * @version $Rev$ $Date$
- */
-public class Archive {
-
- private final String name;
-
- private final InputStream in;
-
-
- public Archive(Iterable<URL> urls, Iterable<Class<?>> classes) {
-
- try {
- ClassLoader loader = Archive.class.getClassLoader();
-
- // Create the ZIP file
- final ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
-
- final ZipOutputStream out = new ZipOutputStream(new
BufferedOutputStream(byteArrayOutputStream));
-
- this.name = name(classes);
-
- for (Class clazz : classes) {
-
- String name = clazz.getName().replace(".", "/") + ".class";
- // cla zz.getName().replace('.', File.separatorChar) +
".class"; // shouldn't work under windows
-
- URL resource = loader.getResource(name);
- if (resource == null) {
- String path = clazz.getProtectionDomain().getCodeSource()
+ "!" + name;
- try {
- resource = new URL(path);
- } catch (MalformedURLException mue) {
- fail("can't find " + clazz.getName() + " neither from
" + name + " nor from " + path);
- }
- }
- assertNotNull(resource);
- InputStream in = new
BufferedInputStream(resource.openStream());
-
- // Add ZIP entry to output stream.
- out.putNextEntry(new ZipEntry(name));
-
- int i;
- while ((i = in.read()) != -1) {
- out.write(i);
- }
-
- // Complete the entry
- out.closeEntry();
- }
-
- boolean willBeDeployed = false;
- int i;
- for (final URL url : urls) {
-
- final String fileName = new File(url.getFile()).getName();
- final String name = "META-INF/" + fileName;
-
- out.putNextEntry(new ZipEntry(name));
-
- final InputStream in = new
BufferedInputStream(url.openStream());
-
- while ((i = in.read()) != -1) {
- out.write(i);
- }
-
- in.close();
-
- willBeDeployed = willBeDeployed
- || "persistence.xml".equals(fileName)
- || "ejb-jar.xml".equals(fileName) ||
"beans.xml".equals(fileName)
- || "application.xml".equals(fileName) ||
"application-client.xml".equals(fileName); // TODO: put eveything in a list:
org.apache.openejb.config.DeploymentLoader.discoverModuleType()
- }
-
- if (!willBeDeployed) { // force it to be a module
- out.putNextEntry(new ZipEntry("META-INF/beans.xml"));
- final InputStream in = new ByteArrayInputStream("<beans
/>".getBytes());
-
- while ((i = in.read()) != -1) {
- out.write(i);
- }
-
- in.close();
- }
-
- // Complete the ZIP file
- out.close();
-
- this.in = new
ByteArrayInputStream(byteArrayOutputStream.toByteArray());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- public String getName() {
- return name;
- }
-
- public InputStream getIn() {
- return in;
- }
-
- private String name(Iterable<Class<?>> classes) {
- for (Class<?> clazz : classes) {
- if (clazz.getName().endsWith("AbstractJSR299Test")) continue;
- if (clazz.getName().endsWith("Test")) {
- return clazz.getName() + ".jar";
- }
- }
-
- return "test-archive.jar";
- }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or
+ * more
+ * contributor license agreements. See the NOTICE file
+ * distributed with
+ * this work for additional information regarding copyright
+ * ownership.
+ * The ASF licenses this file to You under the Apache License,
+ * Version 2.0
+ * (the "License"); you may not use this file except in
+ * compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software
+ * distributed under the License is distributed on an "AS IS"
+ * BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied.
+ * See the License for the specific language governing
+ * permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.tck.impl;
+
+import org.apache.openejb.tck.util.ZipUtil;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.fail;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Archive {
+
+ private final String name;
+
+ private final InputStream in;
+
+
+ public Archive(Iterable<URL> urls, Iterable<Class<?>>
+ classes) {
+
+ try {
+ ClassLoader loader = Archive.class.getClassLoader();
+
+ // Create the ZIP file
+ final ByteArrayOutputStream byteArrayOutputStream =
+ new ByteArrayOutputStream();
+
+ final ZipOutputStream out = new ZipOutputStream(new
+ BufferedOutputStream(byteArrayOutputStream));
+
+ this.name = name(classes);
+
+ for (Class clazz : classes) {
+
+ String name = clazz.getName().replace(".", "/")
+ + ".class";
+ // cla zz.getName().replace('.',
+ // File.separatorChar) + ".class"; // shouldn't
+ // work under windows
+
+ URL resource = loader.getResource(name);
+ if (resource == null) {
+ String path =
+ clazz.getProtectionDomain().getCodeSource() + "!"
+ name;
+ try {
+ resource = new URL(path);
+ } catch (MalformedURLException mue) {
+ fail("can't find " + clazz.getName() + "neither from"
+ name + " nor from" + path);
+ }
+ }
+ assertNotNull(resource);
+ InputStream in = new
BufferedInputStream(resource.openStream());
+ // Add ZIP entry to output stream.
+ out.putNextEntry(new ZipEntry(name));
+ ZipUtil.copy(in, out);
+
+ // Complete the entry
+ out.closeEntry();
+ }
+
+ for (final URL url : urls) {
+
+ final String fileName = new
+ File(url.getFile()).getName();
+ final String name = "META-INF/" + fileName;
+
+ out.putNextEntry(new ZipEntry(name));
+
+ final InputStream in = new
+ BufferedInputStream(url.openStream());
+
+ ZipUtil.copy(in, out);
+
+ in.close();
+ }
+
+ if (System.getProperty("force.deployment") != null) {
+ out.putNextEntry(new ZipEntry("META-INF/beans.xml"));
+ final InputStream in = new ByteArrayInputStream("<beans
/>".getBytes());
+ ZipUtil.copy(in, out);
+ in.close();
+ }
+
+ // Complete the ZIP file
+ out.close();
+
+ this.in = new
+ ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public InputStream getIn() {
+ return in;
+ }
+
+ private String name(Iterable<Class<?>> classes) {
+ for (Class<?> clazz : classes) {
+ if (clazz.getName().endsWith("AbstractJSR299Test"))
+ continue;
+ if (clazz.getName().endsWith("Test")) {
+ return clazz.getName() + ".jar";
+ }
+ }
+
+ return "test-archive.jar";
+ }
+}
+
Modified:
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java?rev=1142007&r1=1142006&r2=1142007&view=diff
==============================================================================
---
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
(original)
+++
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
Fri Jul 1 17:47:33 2011
@@ -20,6 +20,7 @@ import org.apache.openejb.OpenEJB;
import org.apache.openejb.assembler.classic.Assembler;
import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.tck.util.ZipUtil;
import org.apache.openejb.util.SetAccessible;
import org.apache.webbeans.config.WebBeansContext;
import org.jboss.testharness.api.DeploymentException;
@@ -176,20 +177,20 @@ public class ContainersImpl implements C
zout.putNextEntry(new ZipEntry(entryName));
- copy(src, zout);
+ ZipUtil.copy(src, zout);
}
for (Map.Entry<String, URL> entry : resources.entrySet()) {
zout.putNextEntry(new ZipEntry(entry.getKey()));
- copy(entry.getValue().openStream(), zout);
+ ZipUtil.copy(entry.getValue().openStream(), zout);
}
- if (!resources.containsKey("META-INF/beans.xml")) { // force it to
be a module
+ if (System.getProperty("force.deployment") != null) {
zout.putNextEntry(new ZipEntry("META-INF/beans.xml"));
final InputStream in = new ByteArrayInputStream("<beans
/>".getBytes());
- copy(in, zout);
+ ZipUtil.copy(in, zout);
in.close();
}
@@ -212,14 +213,6 @@ public class ContainersImpl implements C
fileOutputStream.close();
}
- private static void copy(InputStream from, OutputStream to) throws
IOException {
- byte[] buffer = new byte[1024];
- int length = 0;
- while ((length = from.read(buffer)) != -1) {
- to.write(buffer, 0, length);
- }
- }
-
public static void close(Closeable closeable) throws IOException {
if (closeable == null) return;
try {
Added:
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/util/ZipUtil.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/util/ZipUtil.java?rev=1142007&view=auto
==============================================================================
---
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/util/ZipUtil.java
(added)
+++
openejb/trunk/openejb3/tck/tck-common/src/main/java/org/apache/openejb/tck/util/ZipUtil.java
Fri Jul 1 17:47:33 2011
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.tck.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+public final class ZipUtil {
+ private ZipUtil() {
+ // no-op
+ }
+
+ public static void copy(InputStream from, OutputStream to) throws
IOException {
+ byte[] buffer = new byte[1024];
+ int length = 0;
+ while ((length = from.read(buffer)) != -1) {
+ to.write(buffer, 0, length);
+ }
+ }
+}