Weld SVN: r6241 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery: handlers and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-05-18 10:48:15 -0400 (Tue, 18 May 2010)
New Revision: 6241
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/Scanner.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java
Log:
remove undeeded scanDirectories
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/Scanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/Scanner.java 2010-05-18 14:44:05 UTC (rev 6240)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/Scanner.java 2010-05-18 14:48:15 UTC (rev 6241)
@@ -16,7 +16,6 @@
*/
package org.jboss.weld.environment.se.discovery;
-import java.io.File;
/**
* The Scanner is used to find resources to be processed by Seam
@@ -28,12 +27,6 @@
*/
public interface Scanner
{
- /**
- * Recursively scan directories.
- *
- * @param directories An array of the roots of the directory trees to scan
- */
- public void scanDirectories(File[] directories);
/**
* Scan for structures which contain any of the given resources in their root
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-18 14:44:05 UTC (rev 6240)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-18 14:48:15 UTC (rev 6241)
@@ -16,8 +16,6 @@
*/
package org.jboss.weld.environment.se.discovery;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
@@ -26,14 +24,17 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.jboss.weld.environment.se.discovery.handlers.URLHandler;
+
import org.jboss.weld.environment.se.discovery.handlers.FileSystemURLHandler;
+import org.jboss.weld.environment.se.discovery.handlers.URLHandler;
import org.jboss.weld.environment.se.exceptions.ClasspathScanningException;
import org.jboss.weld.resources.spi.ResourceLoader;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
/**
* Implementation of {@link Scanner} which can scan a {@link URLClassLoader}
*
@@ -65,15 +66,6 @@
urlHandlers.put(type, handler);
}
- public void scanDirectories(File[] directories)
- {
- for (File directory : directories)
- {
- // can only use a file-based scanner to scan directories
- urlHandlers.get(FILE).handleDirectory(directory);
- }
- }
-
public void scanResources(String[] resources)
{
Multimap<String, String> paths = HashMultimap.create();
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java 2010-05-18 14:44:05 UTC (rev 6240)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java 2010-05-18 14:48:15 UTC (rev 6241)
@@ -25,6 +25,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+
import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
import org.jboss.weld.environment.se.discovery.Scanner;
import org.jboss.weld.resources.spi.ResourceLoader;
@@ -103,11 +104,6 @@
}
}
- public void handleDirectory(File file)
- {
- handleDirectory(file, null);
- }
-
protected void handleDirectory(File file, String path)
{
handleDirectory(file, path, new File[0]);
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java 2010-05-18 14:44:05 UTC (rev 6240)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java 2010-05-18 14:48:15 UTC (rev 6241)
@@ -16,7 +16,6 @@
*/
package org.jboss.weld.environment.se.discovery.handlers;
-import java.io.File;
import java.util.Collection;
/**
@@ -27,6 +26,4 @@
void handle(Collection<String> paths);
- void handleDirectory(File file);
-
}
13 years, 11 months
Weld SVN: r6239 - cdi-tck/branches/1.0/impl/src/main/resources.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-05-18 08:00:27 -0400 (Tue, 18 May 2010)
New Revision: 6239
Modified:
cdi-tck/branches/1.0/impl/src/main/resources/tck-tests-released.xml
Log:
CDITCK-160
Modified: cdi-tck/branches/1.0/impl/src/main/resources/tck-tests-released.xml
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/resources/tck-tests-released.xml 2010-05-18 11:32:13 UTC (rev 6238)
+++ cdi-tck/branches/1.0/impl/src/main/resources/tck-tests-released.xml 2010-05-18 12:00:27 UTC (rev 6239)
@@ -154,6 +154,13 @@
<exclude name="testApplicationContextShared" />
</methods>
</class>
+
+ <!-- CDITCK-160 -->
+ <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.newBean.NewEnterpriseBeanICTest">
+ <methods>
+ <exclude name="testNewBeanHasSameConstructor" />
+ </methods>
+ </class>
<!-- Issues in Weld (the RI) -->
13 years, 11 months
Weld SVN: r6238 - java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-18 07:32:13 -0400 (Tue, 18 May 2010)
New Revision: 6238
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
Log:
WELDSE-26: Previous commit for this issue broke simple jar support. This commit fixes.
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-17 13:30:55 UTC (rev 6237)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-18 11:32:13 UTC (rev 6238)
@@ -84,14 +84,9 @@
for (URL url : urlEnum)
{
- String urlPath;
- try
- {
- urlPath = URLDecoder.decode(url.toExternalForm(), "UTF-8");
- } catch (UnsupportedEncodingException ex)
- {
- throw new ClasspathScanningException("Error decoding URL using UTF-8");
- }
+ String urlPath = url.toExternalForm();
+
+ // determin resource type (eg: jar, file, bundle)
String urlType = "file";
int colonIndex = urlPath.indexOf(":");
if (colonIndex != -1)
@@ -99,20 +94,39 @@
urlType = urlPath.substring(0, colonIndex);
}
- // hack for /META-INF/beans.xml
- if (urlPath.indexOf('!') == -1)
+ // Extra built-in support for simple file-based resources
+ if ("file".equals(urlType) || "jar".equals(urlType))
{
- File dirOrArchive = new File(urlPath);
- if ((resourceName != null) && (resourceName.lastIndexOf('/') > 0))
+ // switch to using getPath() instead of toExternalForm()
+ urlPath = url.getPath();
+
+ if (urlPath.indexOf('!') > 0)
{
- dirOrArchive = dirOrArchive.getParentFile();
+ urlPath = urlPath.substring(0, urlPath.indexOf('!'));
+ } else
+ {
+ // hack for /META-INF/beans.xml
+ File dirOrArchive = new File(urlPath);
+ if ((resourceName != null) && (resourceName.lastIndexOf('/') > 0))
+ {
+ dirOrArchive = dirOrArchive.getParentFile();
+ }
+ urlPath = dirOrArchive.getParent();
}
- urlPath = dirOrArchive.getParent();
}
+ try
+ {
+ urlPath = URLDecoder.decode(urlPath, "UTF-8");
+ } catch (UnsupportedEncodingException ex)
+ {
+ throw new ClasspathScanningException("Error decoding URL using UTF-8");
+ }
+
log.debug("URL Type: " + urlType);
paths.put(urlType, urlPath);
+
}
}
for (String urlType : paths.keySet())
13 years, 11 months
Weld SVN: r6237 - java-se/trunk/src/main/java/org/jboss/weld/environment/se.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-17 09:30:55 -0400 (Mon, 17 May 2010)
New Revision: 6237
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
Log:
WELDSE-26: Renamed ClassHandler to URLHandler (part 3)
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-17 13:25:37 UTC (rev 6236)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-17 13:30:55 UTC (rev 6237)
@@ -113,7 +113,7 @@
* public class MyWeld extends Weld {
* @Override
* public void configureURLHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
- * scanner.setURLHandler("bundle", new MyOSGiURLHandler(bundleClassLoader));
+ * scanner.setURLHandler("bundle", new MyOSGiURLHandler(resourceLoader, discovery));
* }
* }
* </code>
13 years, 11 months
Weld SVN: r6236 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se: discovery and 1 other directory.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-17 09:25:37 -0400 (Mon, 17 May 2010)
New Revision: 6236
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
Log:
WELDSE-26: Renamed ClassHandler to URLHandler (part 2)
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-17 13:18:43 UTC (rev 6235)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-17 13:25:37 UTC (rev 6236)
@@ -84,7 +84,7 @@
final ResourceLoader resourceLoader = deployment.getServices().get(ResourceLoader.class);
URLScanner scanner = new URLScanner(resourceLoader, discovery);
- configureClassHandlers(scanner, resourceLoader, discovery);
+ configureURLHandlers(scanner, resourceLoader, discovery);
scanner.scanResources(new String[]
{
"META-INF/beans.xml"
@@ -106,19 +106,19 @@
}
/**
- * Clients can subclass and override this method to add custom class handlers
- * before weld boots up. For example, to set a custom class handler for OSGi bundles,
+ * Clients can subclass and override this method to add custom URL handlers
+ * before weld boots up. For example, to set a custom URL handler for OSGi bundles,
* you would subclass Weld like so:
* <code>
* public class MyWeld extends Weld {
* @Override
- * public void configureClassHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
- * scanner.setClassHandler("bundle", new MyOSGiClassHandler(bundleClassLoader));
+ * public void configureURLHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
+ * scanner.setURLHandler("bundle", new MyOSGiURLHandler(bundleClassLoader));
* }
* }
* </code>
*/
- public void configureClassHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
+ public void configureURLHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
{
}
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-17 13:18:43 UTC (rev 6235)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-17 13:25:37 UTC (rev 6236)
@@ -49,20 +49,20 @@
private static final String FILE = "file";
private static final String JAR = "jar";
- private final Map<String, URLHandler> classHandlers = new HashMap<String, URLHandler>();
+ private final Map<String, URLHandler> urlHandlers = new HashMap<String, URLHandler>();
private static final Logger log = LoggerFactory.getLogger(URLScanner.class);
public URLScanner(ResourceLoader resourceLoader, SEWeldDiscovery weldDiscovery)
{
super(resourceLoader, weldDiscovery);
URLHandler fileSysHandler = new FileSystemURLHandler(resourceLoader, weldDiscovery);
- classHandlers.put(FILE, fileSysHandler);
- classHandlers.put(JAR, fileSysHandler);
+ urlHandlers.put(FILE, fileSysHandler);
+ urlHandlers.put(JAR, fileSysHandler);
}
- public void setClassHandler(String type, URLHandler handler)
+ public void setURLHandler(String type, URLHandler handler)
{
- classHandlers.put(type, handler);
+ urlHandlers.put(type, handler);
}
public void scanDirectories(File[] directories)
@@ -70,7 +70,7 @@
for (File directory : directories)
{
// can only use a file-based scanner to scan directories
- classHandlers.get(FILE).handleDirectory(directory);
+ urlHandlers.get(FILE).handleDirectory(directory);
}
}
@@ -118,7 +118,7 @@
for (String urlType : paths.keySet())
{
Collection<String> urlPaths = paths.get(urlType);
- URLHandler handler = classHandlers.get(urlType);
+ URLHandler handler = urlHandlers.get(urlType);
if (handler == null)
{
throw new ClasspathScanningException("No handler defined for URL type: " + urlType);
13 years, 11 months
Weld SVN: r6235 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery: handlers and 1 other directory.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-17 09:18:43 -0400 (Mon, 17 May 2010)
New Revision: 6235
Added:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractURLHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java
Removed:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
Log:
WELDSE-26: Renamed ClassHandler to URLHandler
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-17 13:06:04 UTC (rev 6234)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -26,8 +26,8 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.jboss.weld.environment.se.discovery.handlers.ClassHandler;
-import org.jboss.weld.environment.se.discovery.handlers.FileSystemClassHandler;
+import org.jboss.weld.environment.se.discovery.handlers.URLHandler;
+import org.jboss.weld.environment.se.discovery.handlers.FileSystemURLHandler;
import org.jboss.weld.environment.se.exceptions.ClasspathScanningException;
import org.jboss.weld.resources.spi.ResourceLoader;
@@ -49,18 +49,18 @@
private static final String FILE = "file";
private static final String JAR = "jar";
- private final Map<String, ClassHandler> classHandlers = new HashMap<String, ClassHandler>();
+ private final Map<String, URLHandler> classHandlers = new HashMap<String, URLHandler>();
private static final Logger log = LoggerFactory.getLogger(URLScanner.class);
public URLScanner(ResourceLoader resourceLoader, SEWeldDiscovery weldDiscovery)
{
super(resourceLoader, weldDiscovery);
- ClassHandler fileSysHandler = new FileSystemClassHandler(resourceLoader, weldDiscovery);
+ URLHandler fileSysHandler = new FileSystemURLHandler(resourceLoader, weldDiscovery);
classHandlers.put(FILE, fileSysHandler);
classHandlers.put(JAR, fileSysHandler);
}
- public void setClassHandler(String type, ClassHandler handler)
+ public void setClassHandler(String type, URLHandler handler)
{
classHandlers.put(type, handler);
}
@@ -118,7 +118,7 @@
for (String urlType : paths.keySet())
{
Collection<String> urlPaths = paths.get(urlType);
- ClassHandler handler = classHandlers.get(urlType);
+ URLHandler handler = classHandlers.get(urlType);
if (handler == null)
{
throw new ClasspathScanningException("No handler defined for URL type: " + urlType);
Deleted: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java 2010-05-17 13:06:04 UTC (rev 6234)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -1,54 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
-
-import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
-import org.jboss.weld.resources.spi.ResourceLoader;
-
-/**
- *
- * @author Peter Royle
- */
-public abstract class AbstractClassHandler implements ClassHandler
-{
-
- private final ResourceLoader resourceLoader;
- private final SEWeldDiscovery weldDiscovery;
-
- public AbstractClassHandler(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
- {
- this.resourceLoader = resourceLoader;
- this.weldDiscovery = webBeanDiscovery;
- }
-
- /**
- * @return the resourceLoader
- */
- public ResourceLoader getResourceLoader()
- {
- return resourceLoader;
- }
-
- /**
- * @return the webBeanDiscovery
- */
- public SEWeldDiscovery getWeldDiscovery()
- {
- return weldDiscovery;
- }
-
-}
Copied: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractURLHandler.java (from rev 6234, java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java)
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractURLHandler.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractURLHandler.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -0,0 +1,54 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
+
+import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
+import org.jboss.weld.resources.spi.ResourceLoader;
+
+/**
+ *
+ * @author Peter Royle
+ */
+public abstract class AbstractURLHandler implements URLHandler
+{
+
+ private final ResourceLoader resourceLoader;
+ private final SEWeldDiscovery weldDiscovery;
+
+ public AbstractURLHandler(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
+ {
+ this.resourceLoader = resourceLoader;
+ this.weldDiscovery = webBeanDiscovery;
+ }
+
+ /**
+ * @return the resourceLoader
+ */
+ public ResourceLoader getResourceLoader()
+ {
+ return resourceLoader;
+ }
+
+ /**
+ * @return the webBeanDiscovery
+ */
+ public SEWeldDiscovery getWeldDiscovery()
+ {
+ return weldDiscovery;
+ }
+
+}
Deleted: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java 2010-05-17 13:06:04 UTC (rev 6234)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -1,32 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
-
-import java.io.File;
-import java.util.Collection;
-
-/**
- * Interface for handling class resolving.
- * @author Peter Royle
- */
-public interface ClassHandler {
-
- void handle(Collection<String> paths);
-
- void handleDirectory(File file);
-
-}
Deleted: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java 2010-05-17 13:06:04 UTC (rev 6234)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -1,175 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
-import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
-import org.jboss.weld.environment.se.discovery.Scanner;
-import org.jboss.weld.resources.spi.ResourceLoader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract base class for {@link Scanner} providing common functionality
- *
- * This class provides file-system orientated scanning
- *
- * @author Pete Muir
- *
- */
-public class FileSystemClassHandler extends AbstractClassHandler
-{
-
- private static final Logger log = LoggerFactory.getLogger(FileSystemClassHandler.class);
-
- public FileSystemClassHandler(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
- {
- super(resourceLoader, webBeanDiscovery);
- }
-
- public void handle(Collection<String> paths)
- {
- for (String urlPath : paths)
- {
- try
- {
- FileSystemClassHandler.log.trace("scanning: " + urlPath);
-
- if (urlPath.startsWith("file:"))
- {
- urlPath = urlPath.substring(5);
- }
- if (urlPath.indexOf('!') > 0)
- {
- urlPath = urlPath.substring(0, urlPath.indexOf('!'));
- }
-
- File file = new File(urlPath);
- if (file.isDirectory())
- {
- handleDirectory(file, null);
- } else
- {
- handleArchiveByFile(file);
- }
- } catch (IOException ioe)
- {
- FileSystemClassHandler.log.warn("could not read entries", ioe);
- }
- }
- }
-
- private void handleArchiveByFile(File file) throws IOException
- {
- try
- {
- log.trace("archive: " + file);
-
- String archiveUrl = "jar:" + file.toURI().toURL().toExternalForm() + "!/";
- ZipFile zip = new ZipFile(file);
- Enumeration<? extends ZipEntry> entries = zip.entries();
-
- while (entries.hasMoreElements())
- {
- ZipEntry entry = entries.nextElement();
- String name = entry.getName();
- handle(name, new URL(archiveUrl + name));
- }
- } catch (ZipException e)
- {
- throw new RuntimeException("Error handling file " + file, e);
- }
- }
-
- public void handleDirectory(File file)
- {
- handleDirectory(file, null);
- }
-
- protected void handleDirectory(File file, String path)
- {
- handleDirectory(file, path, new File[0]);
- }
-
- private void handleDirectory(File file, String path, File[] excludedDirectories)
- {
- for (File excludedDirectory : excludedDirectories)
- {
- if (file.equals(excludedDirectory))
- {
- log.trace("skipping excluded directory: " + file);
-
- return;
- }
- }
-
- log.trace("handling directory: " + file);
-
- for (File child : file.listFiles())
- {
- String newPath = (path == null) ? child.getName() : (path + '/' + child.getName());
-
- if (child.isDirectory())
- {
- handleDirectory(child, newPath, excludedDirectories);
- } else
- {
- try
- {
- handle(newPath, child.toURI().toURL());
- } catch (MalformedURLException e)
- {
- log.error("Error loading file " + newPath);
- }
- }
- }
- }
-
- protected void handle(String name, URL url)
- {
- if (name.endsWith(".class"))
- {
- String className = filenameToClassname(name);
- try
- {
- getWeldDiscovery().getWbClasses().add(getResourceLoader().classForName(className));
- } catch (NoClassDefFoundError e)
- {
- log.error("Error loading " + name, e);
- }
- } else if (name.endsWith("beans.xml"))
- {
- getWeldDiscovery().getWbUrls().add(url);
- }
- }
-
- /**
- * Convert a path to a class file to a class name
- */
- public static String filenameToClassname(String filename)
- {
- return filename.substring(0, filename.lastIndexOf(".class")).replace('/', '.').replace('\\', '.');
- }
-}
Copied: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java (from rev 6234, java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java)
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemURLHandler.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -0,0 +1,175 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
+import org.jboss.weld.environment.se.discovery.Scanner;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract base class for {@link Scanner} providing common functionality
+ *
+ * This class provides file-system orientated scanning
+ *
+ * @author Pete Muir
+ *
+ */
+public class FileSystemURLHandler extends AbstractURLHandler
+{
+
+ private static final Logger log = LoggerFactory.getLogger(FileSystemURLHandler.class);
+
+ public FileSystemURLHandler(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
+ {
+ super(resourceLoader, webBeanDiscovery);
+ }
+
+ public void handle(Collection<String> paths)
+ {
+ for (String urlPath : paths)
+ {
+ try
+ {
+ FileSystemURLHandler.log.trace("scanning: " + urlPath);
+
+ if (urlPath.startsWith("file:"))
+ {
+ urlPath = urlPath.substring(5);
+ }
+ if (urlPath.indexOf('!') > 0)
+ {
+ urlPath = urlPath.substring(0, urlPath.indexOf('!'));
+ }
+
+ File file = new File(urlPath);
+ if (file.isDirectory())
+ {
+ handleDirectory(file, null);
+ } else
+ {
+ handleArchiveByFile(file);
+ }
+ } catch (IOException ioe)
+ {
+ FileSystemURLHandler.log.warn("could not read entries", ioe);
+ }
+ }
+ }
+
+ private void handleArchiveByFile(File file) throws IOException
+ {
+ try
+ {
+ log.trace("archive: " + file);
+
+ String archiveUrl = "jar:" + file.toURI().toURL().toExternalForm() + "!/";
+ ZipFile zip = new ZipFile(file);
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+
+ while (entries.hasMoreElements())
+ {
+ ZipEntry entry = entries.nextElement();
+ String name = entry.getName();
+ handle(name, new URL(archiveUrl + name));
+ }
+ } catch (ZipException e)
+ {
+ throw new RuntimeException("Error handling file " + file, e);
+ }
+ }
+
+ public void handleDirectory(File file)
+ {
+ handleDirectory(file, null);
+ }
+
+ protected void handleDirectory(File file, String path)
+ {
+ handleDirectory(file, path, new File[0]);
+ }
+
+ private void handleDirectory(File file, String path, File[] excludedDirectories)
+ {
+ for (File excludedDirectory : excludedDirectories)
+ {
+ if (file.equals(excludedDirectory))
+ {
+ log.trace("skipping excluded directory: " + file);
+
+ return;
+ }
+ }
+
+ log.trace("handling directory: " + file);
+
+ for (File child : file.listFiles())
+ {
+ String newPath = (path == null) ? child.getName() : (path + '/' + child.getName());
+
+ if (child.isDirectory())
+ {
+ handleDirectory(child, newPath, excludedDirectories);
+ } else
+ {
+ try
+ {
+ handle(newPath, child.toURI().toURL());
+ } catch (MalformedURLException e)
+ {
+ log.error("Error loading file " + newPath);
+ }
+ }
+ }
+ }
+
+ protected void handle(String name, URL url)
+ {
+ if (name.endsWith(".class"))
+ {
+ String className = filenameToClassname(name);
+ try
+ {
+ getWeldDiscovery().getWbClasses().add(getResourceLoader().classForName(className));
+ } catch (NoClassDefFoundError e)
+ {
+ log.error("Error loading " + name, e);
+ }
+ } else if (name.endsWith("beans.xml"))
+ {
+ getWeldDiscovery().getWbUrls().add(url);
+ }
+ }
+
+ /**
+ * Convert a path to a class file to a class name
+ */
+ public static String filenameToClassname(String filename)
+ {
+ return filename.substring(0, filename.lastIndexOf(".class")).replace('/', '.').replace('\\', '.');
+ }
+}
Copied: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java (from rev 6234, java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java)
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/URLHandler.java 2010-05-17 13:18:43 UTC (rev 6235)
@@ -0,0 +1,32 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
+
+import java.io.File;
+import java.util.Collection;
+
+/**
+ * Interface for handling URL resolving.
+ * @author Peter Royle
+ */
+public interface URLHandler {
+
+ void handle(Collection<String> paths);
+
+ void handleDirectory(File file);
+
+}
13 years, 11 months
Weld SVN: r6234 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se: discovery and 2 other directories.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-17 09:06:04 -0400 (Mon, 17 May 2010)
New Revision: 6234
Added:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/exceptions/
java-se/trunk/src/main/java/org/jboss/weld/environment/se/exceptions/ClasspathScanningException.java
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
Log:
WELDSE-26: Some way towards plugability of URLScanner to handle arbitrary URLs in various environments. Existing file-system based scanning code has been extracted into a built-in plugin (FileSystemClassHandler) which is automatically registered to handle file:// and jar:// URLs. Custom implementations of ClassHandler can be created and registered programatically by subclassinf Weld and overriding customiseClassHandlers(...).
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-16 08:35:10 UTC (rev 6233)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -24,7 +24,10 @@
import org.jboss.weld.context.api.BeanStore;
import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.weld.environment.se.beans.InstanceManager;
+import org.jboss.weld.environment.se.discovery.SEBeanDeploymentArchive;
import org.jboss.weld.environment.se.discovery.SEWeldDeployment;
+import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
+import org.jboss.weld.environment.se.discovery.URLScanner;
import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.jboss.weld.manager.api.WeldManager;
import org.jboss.weld.resources.DefaultResourceLoader;
@@ -50,6 +53,8 @@
private Bootstrap bootstrap;
private BeanStore applicationBeanStore;
private WeldManager manager;
+ private SEWeldDiscovery discovery;
+ private SEBeanDeploymentArchive beanDeploymentArchive;
public Weld()
{
@@ -77,7 +82,13 @@
throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", ex);
}
- deployment.scan();
+ final ResourceLoader resourceLoader = deployment.getServices().get(ResourceLoader.class);
+ URLScanner scanner = new URLScanner(resourceLoader, discovery);
+ configureClassHandlers(scanner, resourceLoader, discovery);
+ scanner.scanResources(new String[]
+ {
+ "META-INF/beans.xml"
+ });
bootstrap.startContainer(Environments.SE, deployment, this.applicationBeanStore);
final BeanDeploymentArchive mainBeanDepArch = deployment.getBeanDeploymentArchives().get(0);
@@ -94,11 +105,28 @@
}
+ /**
+ * Clients can subclass and override this method to add custom class handlers
+ * before weld boots up. For example, to set a custom class handler for OSGi bundles,
+ * you would subclass Weld like so:
+ * <code>
+ * public class MyWeld extends Weld {
+ * @Override
+ * public void configureClassHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
+ * scanner.setClassHandler("bundle", new MyOSGiClassHandler(bundleClassLoader));
+ * }
+ * }
+ * </code>
+ */
+ public void configureClassHandlers(URLScanner scanner, ResourceLoader resourceLoader, SEWeldDiscovery discovery)
+ {
+ }
+
private SEWeldDeployment initDeployment()
{
- SEWeldDeployment deployment = new SEWeldDeployment()
- {
- };
+ discovery = new SEWeldDiscovery();
+ beanDeploymentArchive = new SEBeanDeploymentArchive(discovery);
+ SEWeldDeployment deployment = new SEWeldDeployment(beanDeploymentArchive);
configureDeployment(deployment);
// configure a ResourceLoader if one hasn't been already
if (deployment.getServices().get(ResourceLoader.class) == null)
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java 2010-05-16 08:35:10 UTC (rev 6233)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -16,51 +16,24 @@
*/
package org.jboss.weld.environment.se.discovery;
-import java.net.URL;
import org.jboss.weld.resources.spi.ResourceLoader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- * Abstract base class for {@link Scanner} providing common functionality
- *
- * This class provides file-system orientated scanning
- *
- * @author Pete Muir
- *
+ *
+ * @author Peter Royle
*/
public abstract class AbstractScanner implements Scanner
{
- private static final Logger log = LoggerFactory.getLogger(Scanner.class);
private final ResourceLoader resourceLoader;
- private final SEWeldDiscovery webBeanDiscovery;
+ private final SEWeldDiscovery weldDiscovery;
public AbstractScanner(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
{
this.resourceLoader = resourceLoader;
- this.webBeanDiscovery = webBeanDiscovery;
+ this.weldDiscovery = webBeanDiscovery;
}
- protected void handle(String name, URL url)
- {
- if (name.endsWith(".class"))
- {
- String className = filenameToClassname(name);
- try
- {
- webBeanDiscovery.getWbClasses().add(getResourceLoader().classForName(className));
- }
- catch (NoClassDefFoundError e)
- {
- log.error("Error loading " + name, e);
- }
- }
- else if (name.endsWith("beans.xml"))
- {
- webBeanDiscovery.getWbUrls().add(url);
- }
- }
public ResourceLoader getResourceLoader()
{
@@ -68,11 +41,11 @@
}
/**
- * Convert a path to a class file to a class name
+ * @return the webBeanDiscovery
*/
- public static String filenameToClassname(String filename)
+ public SEWeldDiscovery getWebBeanDiscovery()
{
- return filename.substring(0, filename.lastIndexOf(".class")).replace('/', '.').replace('\\', '.');
+ return weldDiscovery;
}
}
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java 2010-05-16 08:35:10 UTC (rev 6233)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -24,7 +24,6 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
-import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.ejb.spi.EjbDescriptor;
/**
@@ -43,22 +42,15 @@
/**
* @param deployment Used to gain access to the ResourceLoader, in case one is defined.
*/
- public SEBeanDeploymentArchive(Deployment deployment)
+ public SEBeanDeploymentArchive(SEWeldDiscovery discovery)
{
- this.wbDiscovery = new SEWeldDiscovery(deployment)
+ this.wbDiscovery = discovery;
{
};
this.serviceRegistry = new SimpleServiceRegistry();
}
/**
- * Perform the class scanning.
- */
- public void scan() {
- wbDiscovery.scan();
- }
-
- /**
* @return a collection of all Bean classes on the classpath.
*/
public Collection<Class<?>> getBeanClasses()
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java 2010-05-16 08:35:10 UTC (rev 6233)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -27,26 +27,19 @@
*
* @author Peter Royle
*/
-public abstract class SEWeldDeployment implements Deployment
+public class SEWeldDeployment implements Deployment
{
private final SEBeanDeploymentArchive beanDeploymentArchive;
private final List<BeanDeploymentArchive> archInCollection;
- public SEWeldDeployment()
+ public SEWeldDeployment(SEBeanDeploymentArchive beanDeploymentArchive)
{
- this.beanDeploymentArchive = new SEBeanDeploymentArchive(this);
+ this.beanDeploymentArchive = beanDeploymentArchive;
this.archInCollection = new ArrayList<BeanDeploymentArchive>(1);
this.archInCollection.add(this.beanDeploymentArchive);
}
/**
- * Perform the class scanning.
- */
- public void scan() {
- this.beanDeploymentArchive.scan();
- }
-
- /**
* {@inheritDoc}
*
* @return A collection containing the singular logical BeanDeploymentArchive
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-16 08:35:10 UTC (rev 6233)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -22,8 +22,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.jboss.weld.bootstrap.spi.Deployment;
-import org.jboss.weld.resources.spi.ResourceLoader;
/**
* The means by which beans are discovered on the classpath. This will only
@@ -33,16 +31,14 @@
* @author Pete Muir
* @author Ales Justin
*/
-public abstract class SEWeldDiscovery
+public class SEWeldDiscovery
{
- private final Deployment deployment;
private final Set<Class<?>> wbClasses;
private final Set<URL> wbUrls;
- public SEWeldDiscovery(Deployment deployment)
+ public SEWeldDiscovery()
{
- this.deployment = deployment;
this.wbClasses = new HashSet<Class<?>>();
this.wbUrls = new HashSet<URL>();
}
@@ -67,10 +63,4 @@
return wbUrls;
}
- public void scan()
- {
- Scanner scanner = new URLScanner(deployment.getServices().get(ResourceLoader.class), this);
- scanner.scanResources(new String[] { "META-INF/beans.xml" });
- }
-
}
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-16 08:35:10 UTC (rev 6233)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -16,19 +16,19 @@
*/
package org.jboss.weld.environment.se.discovery;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
+import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
+import java.util.HashMap;
+import java.util.Map;
+import org.jboss.weld.environment.se.discovery.handlers.ClassHandler;
+import org.jboss.weld.environment.se.discovery.handlers.FileSystemClassHandler;
+import org.jboss.weld.environment.se.exceptions.ClasspathScanningException;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.slf4j.Logger;
@@ -41,162 +41,91 @@
* @author Gavin King
* @author Norman Richards
* @author Pete Muir
+ * @author Peter Royle
*
*/
public class URLScanner extends AbstractScanner
{
+
+ private static final String FILE = "file";
+ private static final String JAR = "jar";
+ private final Map<String, ClassHandler> classHandlers = new HashMap<String, ClassHandler>();
private static final Logger log = LoggerFactory.getLogger(URLScanner.class);
- public URLScanner(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
+ public URLScanner(ResourceLoader resourceLoader, SEWeldDiscovery weldDiscovery)
{
- super(resourceLoader, webBeanDiscovery);
+ super(resourceLoader, weldDiscovery);
+ ClassHandler fileSysHandler = new FileSystemClassHandler(resourceLoader, weldDiscovery);
+ classHandlers.put(FILE, fileSysHandler);
+ classHandlers.put(JAR, fileSysHandler);
}
+ public void setClassHandler(String type, ClassHandler handler)
+ {
+ classHandlers.put(type, handler);
+ }
+
public void scanDirectories(File[] directories)
{
for (File directory : directories)
{
- handleDirectory(directory, null);
+ // can only use a file-based scanner to scan directories
+ classHandlers.get(FILE).handleDirectory(directory);
}
}
public void scanResources(String[] resources)
{
- Set<String> paths = new HashSet<String>();
-
+ Multimap<String, String> paths = HashMultimap.create();
for (String resourceName : resources)
{
- try
+ // grab all the URLs for this resource
+ Collection<URL> urlEnum = getResourceLoader().getResources(resourceName);
+ for (URL url : urlEnum)
{
- Collection<URL> urlEnum = getResourceLoader().getResources(resourceName);
- for (URL url : urlEnum)
+ String urlPath;
+ try
{
- String urlPath = url.getFile();
- urlPath = URLDecoder.decode(urlPath, "UTF-8");
-
- if (urlPath.startsWith("file:"))
- {
- urlPath = urlPath.substring(5);
- }
-
- if (urlPath.indexOf('!') > 0)
- {
- urlPath = urlPath.substring(0, urlPath.indexOf('!'));
- }
- else
- {
- File dirOrArchive = new File(urlPath);
-
- if ((resourceName != null) && (resourceName.lastIndexOf('/') > 0))
- {
- // for META-INF/components.xml
- dirOrArchive = dirOrArchive.getParentFile();
- }
-
- urlPath = dirOrArchive.getParent();
- }
-
- paths.add(urlPath);
+ urlPath = URLDecoder.decode(url.toExternalForm(), "UTF-8");
+ } catch (UnsupportedEncodingException ex)
+ {
+ throw new ClasspathScanningException("Error decoding URL using UTF-8");
}
- }
- catch (IOException ioe)
- {
- log.warn("could not read: " + resourceName, ioe);
- }
- }
-
- handle(paths);
- }
-
- protected void handle(Set<String> paths)
- {
- for (String urlPath : paths)
- {
- try
- {
- log.trace("scanning: " + urlPath);
-
- File file = new File(urlPath);
-
- if (file.isDirectory())
+ String urlType = "file";
+ int colonIndex = urlPath.indexOf(":");
+ if (colonIndex != -1)
{
- handleDirectory(file, null);
+ urlType = urlPath.substring(0, colonIndex);
}
- else
+
+ // hack for /META-INF/beans.xml
+ if (urlPath.indexOf('!') == -1)
{
- handleArchiveByFile(file);
+ File dirOrArchive = new File(urlPath);
+ if ((resourceName != null) && (resourceName.lastIndexOf('/') > 0))
+ {
+ dirOrArchive = dirOrArchive.getParentFile();
+ }
+ urlPath = dirOrArchive.getParent();
}
- }
- catch (IOException ioe)
- {
- log.warn("could not read entries", ioe);
- }
- }
- }
- private void handleArchiveByFile(File file) throws IOException
- {
- try
- {
- log.trace("archive: " + file);
+ log.debug("URL Type: " + urlType);
- String archiveUrl = "jar:" + file.toURI().toURL().toExternalForm() + "!/";
- ZipFile zip = new ZipFile(file);
- Enumeration<? extends ZipEntry> entries = zip.entries();
-
- while (entries.hasMoreElements())
- {
- ZipEntry entry = entries.nextElement();
- String name = entry.getName();
- handle(name, new URL(archiveUrl + name));
+ paths.put(urlType, urlPath);
}
}
- catch (ZipException e)
+ for (String urlType : paths.keySet())
{
- throw new RuntimeException("Error handling file " + file, e);
- }
- }
-
- private void handleDirectory(File file, String path)
- {
- handleDirectory(file, path, new File[0]);
- }
-
- private void handleDirectory(File file, String path, File[] excludedDirectories)
- {
- for (File excludedDirectory : excludedDirectories)
- {
- if (file.equals(excludedDirectory))
+ Collection<String> urlPaths = paths.get(urlType);
+ ClassHandler handler = classHandlers.get(urlType);
+ if (handler == null)
{
- log.trace("skipping excluded directory: " + file);
-
- return;
- }
- }
-
- log.trace("handling directory: " + file);
-
- for (File child : file.listFiles())
- {
- String newPath = (path == null) ? child.getName() : (path + '/' + child.getName());
-
- if (child.isDirectory())
+ throw new ClasspathScanningException("No handler defined for URL type: " + urlType);
+ } else
{
- handleDirectory(child, newPath, excludedDirectories);
+ handler.handle(urlPaths);
}
- else
- {
- try
- {
- handle(newPath, child.toURI().toURL());
- }
- catch (MalformedURLException e)
- {
- log.error("Error loading file " + newPath);
- }
- }
}
}
-
}
Added: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/AbstractClassHandler.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -0,0 +1,54 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
+
+import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
+import org.jboss.weld.resources.spi.ResourceLoader;
+
+/**
+ *
+ * @author Peter Royle
+ */
+public abstract class AbstractClassHandler implements ClassHandler
+{
+
+ private final ResourceLoader resourceLoader;
+ private final SEWeldDiscovery weldDiscovery;
+
+ public AbstractClassHandler(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
+ {
+ this.resourceLoader = resourceLoader;
+ this.weldDiscovery = webBeanDiscovery;
+ }
+
+ /**
+ * @return the resourceLoader
+ */
+ public ResourceLoader getResourceLoader()
+ {
+ return resourceLoader;
+ }
+
+ /**
+ * @return the webBeanDiscovery
+ */
+ public SEWeldDiscovery getWeldDiscovery()
+ {
+ return weldDiscovery;
+ }
+
+}
Added: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/ClassHandler.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -0,0 +1,32 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
+
+import java.io.File;
+import java.util.Collection;
+
+/**
+ * Interface for handling class resolving.
+ * @author Peter Royle
+ */
+public interface ClassHandler {
+
+ void handle(Collection<String> paths);
+
+ void handleDirectory(File file);
+
+}
Copied: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java (from rev 6232, java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java)
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/handlers/FileSystemClassHandler.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -0,0 +1,175 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.discovery.handlers;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import org.jboss.weld.environment.se.discovery.SEWeldDiscovery;
+import org.jboss.weld.environment.se.discovery.Scanner;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract base class for {@link Scanner} providing common functionality
+ *
+ * This class provides file-system orientated scanning
+ *
+ * @author Pete Muir
+ *
+ */
+public class FileSystemClassHandler extends AbstractClassHandler
+{
+
+ private static final Logger log = LoggerFactory.getLogger(FileSystemClassHandler.class);
+
+ public FileSystemClassHandler(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
+ {
+ super(resourceLoader, webBeanDiscovery);
+ }
+
+ public void handle(Collection<String> paths)
+ {
+ for (String urlPath : paths)
+ {
+ try
+ {
+ FileSystemClassHandler.log.trace("scanning: " + urlPath);
+
+ if (urlPath.startsWith("file:"))
+ {
+ urlPath = urlPath.substring(5);
+ }
+ if (urlPath.indexOf('!') > 0)
+ {
+ urlPath = urlPath.substring(0, urlPath.indexOf('!'));
+ }
+
+ File file = new File(urlPath);
+ if (file.isDirectory())
+ {
+ handleDirectory(file, null);
+ } else
+ {
+ handleArchiveByFile(file);
+ }
+ } catch (IOException ioe)
+ {
+ FileSystemClassHandler.log.warn("could not read entries", ioe);
+ }
+ }
+ }
+
+ private void handleArchiveByFile(File file) throws IOException
+ {
+ try
+ {
+ log.trace("archive: " + file);
+
+ String archiveUrl = "jar:" + file.toURI().toURL().toExternalForm() + "!/";
+ ZipFile zip = new ZipFile(file);
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+
+ while (entries.hasMoreElements())
+ {
+ ZipEntry entry = entries.nextElement();
+ String name = entry.getName();
+ handle(name, new URL(archiveUrl + name));
+ }
+ } catch (ZipException e)
+ {
+ throw new RuntimeException("Error handling file " + file, e);
+ }
+ }
+
+ public void handleDirectory(File file)
+ {
+ handleDirectory(file, null);
+ }
+
+ protected void handleDirectory(File file, String path)
+ {
+ handleDirectory(file, path, new File[0]);
+ }
+
+ private void handleDirectory(File file, String path, File[] excludedDirectories)
+ {
+ for (File excludedDirectory : excludedDirectories)
+ {
+ if (file.equals(excludedDirectory))
+ {
+ log.trace("skipping excluded directory: " + file);
+
+ return;
+ }
+ }
+
+ log.trace("handling directory: " + file);
+
+ for (File child : file.listFiles())
+ {
+ String newPath = (path == null) ? child.getName() : (path + '/' + child.getName());
+
+ if (child.isDirectory())
+ {
+ handleDirectory(child, newPath, excludedDirectories);
+ } else
+ {
+ try
+ {
+ handle(newPath, child.toURI().toURL());
+ } catch (MalformedURLException e)
+ {
+ log.error("Error loading file " + newPath);
+ }
+ }
+ }
+ }
+
+ protected void handle(String name, URL url)
+ {
+ if (name.endsWith(".class"))
+ {
+ String className = filenameToClassname(name);
+ try
+ {
+ getWeldDiscovery().getWbClasses().add(getResourceLoader().classForName(className));
+ } catch (NoClassDefFoundError e)
+ {
+ log.error("Error loading " + name, e);
+ }
+ } else if (name.endsWith("beans.xml"))
+ {
+ getWeldDiscovery().getWbUrls().add(url);
+ }
+ }
+
+ /**
+ * Convert a path to a class file to a class name
+ */
+ public static String filenameToClassname(String filename)
+ {
+ return filename.substring(0, filename.lastIndexOf(".class")).replace('/', '.').replace('\\', '.');
+ }
+}
Added: java-se/trunk/src/main/java/org/jboss/weld/environment/se/exceptions/ClasspathScanningException.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/exceptions/ClasspathScanningException.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/exceptions/ClasspathScanningException.java 2010-05-17 13:06:04 UTC (rev 6234)
@@ -0,0 +1,38 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.exceptions;
+
+/**
+ * @author Peter Royle
+ */
+public class ClasspathScanningException extends RuntimeException {
+
+ /**
+ * Creates a new instance of <code>ClasspathScanningException</code> without detail message.
+ */
+ public ClasspathScanningException() {
+ }
+
+
+ /**
+ * Constructs an instance of <code>ClasspathScanningException</code> with the specified detail message.
+ * @param msg the detail message.
+ */
+ public ClasspathScanningException(String msg) {
+ super(msg);
+ }
+}
13 years, 11 months
Weld SVN: r6233 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se: discovery and 1 other directories.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-16 04:35:10 -0400 (Sun, 16 May 2010)
New Revision: 6233
Removed:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
Log:
WELDSE-25: Remove final usage of Reflections and replace with ResourceLoader
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-14 12:49:32 UTC (rev 6232)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-16 08:35:10 UTC (rev 6233)
@@ -25,9 +25,10 @@
import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.weld.environment.se.beans.InstanceManager;
import org.jboss.weld.environment.se.discovery.SEWeldDeployment;
-import org.jboss.weld.environment.se.util.Reflections;
import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.jboss.weld.manager.api.WeldManager;
+import org.jboss.weld.resources.DefaultResourceLoader;
+import org.jboss.weld.resources.spi.ResourceLoader;
/**
* An alternative means of booting WeldContainer form an arbitrary main method within an
@@ -46,20 +47,12 @@
{
private static final String BOOTSTRAP_IMPL_CLASS_NAME = "org.jboss.weld.bootstrap.WeldBootstrap";
- private final Bootstrap bootstrap;
- private final BeanStore applicationBeanStore;
+ private Bootstrap bootstrap;
+ private BeanStore applicationBeanStore;
private WeldManager manager;
public Weld()
{
- try
- {
- bootstrap = Reflections.newInstance(BOOTSTRAP_IMPL_CLASS_NAME, Bootstrap.class);
- } catch (Exception e)
- {
- throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", e);
- }
- this.applicationBeanStore = new ConcurrentHashMapBeanStore();
}
/**
@@ -70,10 +63,20 @@
public WeldContainer initialize()
{
- SEWeldDeployment deployment = new SEWeldDeployment()
+ this.applicationBeanStore = new ConcurrentHashMapBeanStore();
+ SEWeldDeployment deployment = initDeployment();
+
+ try
{
- };
- configureDeployment(deployment);
+ bootstrap = (Bootstrap) deployment.getServices().get(ResourceLoader.class).classForName(BOOTSTRAP_IMPL_CLASS_NAME).newInstance();
+ } catch (InstantiationException ex)
+ {
+ throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", ex);
+ } catch (IllegalAccessException ex)
+ {
+ throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", ex);
+ }
+
deployment.scan();
bootstrap.startContainer(Environments.SE, deployment, this.applicationBeanStore);
@@ -91,6 +94,20 @@
}
+ private SEWeldDeployment initDeployment()
+ {
+ SEWeldDeployment deployment = new SEWeldDeployment()
+ {
+ };
+ configureDeployment(deployment);
+ // configure a ResourceLoader if one hasn't been already
+ if (deployment.getServices().get(ResourceLoader.class) == null)
+ {
+ deployment.getServices().add(ResourceLoader.class, new DefaultResourceLoader());
+ }
+ return deployment;
+ }
+
/**
* Clients can subclass and override this method to customise the deployment
* before weld boots up. For example, to add a custom ResourceLoader, you would
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-14 12:49:32 UTC (rev 6232)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-16 08:35:10 UTC (rev 6233)
@@ -21,9 +21,8 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import org.jboss.weld.bootstrap.spi.Deployment;
-import org.jboss.weld.resources.DefaultResourceLoader;
+import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.resources.spi.ResourceLoader;
/**
@@ -37,7 +36,6 @@
public abstract class SEWeldDiscovery
{
- private ResourceLoader resourceLoader;
private final Deployment deployment;
private final Set<Class<?>> wbClasses;
private final Set<URL> wbUrls;
@@ -71,21 +69,8 @@
public void scan()
{
- Scanner scanner = new URLScanner(resourceLoader(), this);
+ Scanner scanner = new URLScanner(deployment.getServices().get(ResourceLoader.class), this);
scanner.scanResources(new String[] { "META-INF/beans.xml" });
}
-
- public synchronized ResourceLoader resourceLoader() {
- if (this.resourceLoader == null)
- {
- ResourceLoader aResourceLoader = deployment.getServices().get(ResourceLoader.class);
- if (aResourceLoader == null)
- {
- aResourceLoader = new DefaultResourceLoader();
- }
- this.resourceLoader = aResourceLoader;
- }
- return this.resourceLoader;
- }
}
Deleted: java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java 2010-05-14 12:49:32 UTC (rev 6232)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/Reflections.java 2010-05-16 08:35:10 UTC (rev 6233)
@@ -1,62 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se.util;
-
-/**
- * Reflection utilities
- *
- * @author Pete Muir
- *
- */
-public abstract class Reflections
-{
-
- private Reflections()
- {
- // TODO Auto-generated constructor stub
- }
-
- public static <T> T newInstance(String className, Class<T> expectedType) throws InstantiationException, IllegalAccessException, ClassNotFoundException
- {
- return loadClass(className, expectedType).newInstance();
- }
-
- public static <T> Class<? extends T> loadClass(String className, Class<T> expectedType) throws ClassNotFoundException
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return Thread.currentThread().getContextClassLoader().loadClass(className).asSubclass(expectedType);
- }
- else
- {
- return Class.forName(className).asSubclass(expectedType);
- }
- }
-
- public static ClassLoader getClassLoader()
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
- return Thread.currentThread().getContextClassLoader();
- }
- else
- {
- return Reflections.class.getClassLoader();
- }
- }
-
-}
13 years, 11 months
Weld SVN: r6232 - in java-se/trunk/src: test/java/org/jboss/weld/environment/se/test and 1 other directory.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-14 08:49:32 -0400 (Fri, 14 May 2010)
New Revision: 6232
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/WeldManagerUtils.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/DecoratorsTest.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/InterceptorsTest.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/StartMainTest.java
Log:
WeldManagerUtils is still useful within Weld.class, but I have removed it from all of the tests, replaced by Weld.instance()
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/WeldManagerUtils.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/WeldManagerUtils.java 2010-05-14 12:25:01 UTC (rev 6231)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/util/WeldManagerUtils.java 2010-05-14 12:49:32 UTC (rev 6232)
@@ -25,7 +25,6 @@
/**
*
* @author Peter Royle
- * @deprecated This should be replaced with usages of Weld.instance()
*/
public class WeldManagerUtils
{
Modified: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/DecoratorsTest.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/DecoratorsTest.java 2010-05-14 12:25:01 UTC (rev 6231)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/DecoratorsTest.java 2010-05-14 12:49:32 UTC (rev 6232)
@@ -25,7 +25,6 @@
import org.jboss.weld.environment.se.test.decorators.AbstractDoor;
import org.jboss.weld.environment.se.test.decorators.CarDoorAlarm;
import org.jboss.weld.environment.se.test.decorators.HouseDoor;
-import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -46,7 +45,7 @@
WeldContainer weld = new Weld().initialize();
BeanManager manager = weld.getBeanManager();
- CarDoor carDoor = WeldManagerUtils.getInstanceByType(manager, CarDoor.class);
+ CarDoor carDoor = weld.instance().select(CarDoor.class).get();
Assert.assertNotNull(carDoor);
// the car door is alarmed
@@ -55,7 +54,7 @@
testDoor(carDoor);
Assert.assertTrue(CarDoorAlarm.alarmActivated);
- HouseDoor houseDoor = WeldManagerUtils.getInstanceByType(manager, HouseDoor.class);
+ HouseDoor houseDoor = weld.instance().select(HouseDoor.class).get();
Assert.assertNotNull(carDoor);
// the house door is not alarmed
Modified: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/InterceptorsTest.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/InterceptorsTest.java 2010-05-14 12:25:01 UTC (rev 6231)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/InterceptorsTest.java 2010-05-14 12:49:32 UTC (rev 6232)
@@ -24,7 +24,6 @@
import org.jboss.weld.environment.se.test.beans.InterceptorTestBean;
import org.jboss.weld.environment.se.test.interceptors.AggregatingInterceptor;
import org.jboss.weld.environment.se.test.interceptors.RecordingInterceptor;
-import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -44,7 +43,7 @@
WeldContainer weld = new Weld().initialize();
BeanManager manager = weld.getBeanManager();
- InterceptorTestBean intTestBean = WeldManagerUtils.getInstanceByType(manager, InterceptorTestBean.class);
+ InterceptorTestBean intTestBean = weld.instance().select(InterceptorTestBean.class).get();
Assert.assertNotNull(intTestBean);
intTestBean.doSomethingRecorded();
Modified: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/StartMainTest.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/StartMainTest.java 2010-05-14 12:25:01 UTC (rev 6231)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/StartMainTest.java 2010-05-14 12:49:32 UTC (rev 6232)
@@ -26,7 +26,6 @@
import org.jboss.weld.environment.se.test.beans.MainTestBean;
import org.jboss.weld.environment.se.test.beans.ObserverTestBean;
import org.jboss.weld.environment.se.test.beans.ParametersTestBean;
-import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -53,7 +52,7 @@
WeldContainer weld = new StartMain(args).go();
BeanManager manager = weld.getBeanManager();
- MainTestBean mainTestBean = WeldManagerUtils.getInstanceByType(manager, MainTestBean.class);
+ MainTestBean mainTestBean = weld.instance().select(MainTestBean.class).get();
Assert.assertNotNull(mainTestBean);
ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
@@ -79,7 +78,7 @@
WeldContainer weld = new StartMain(ARGS_EMPTY).go();
BeanManager manager = weld.getBeanManager();
- MainTestBean mainTestBean = WeldManagerUtils.getInstanceByType(manager, MainTestBean.class);
+ MainTestBean mainTestBean = weld.instance().select(MainTestBean.class).get();
Assert.assertNotNull(mainTestBean);
ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
13 years, 11 months
Weld SVN: r6231 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se: discovery and 1 other directory.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2010-05-14 08:25:01 -0400 (Fri, 14 May 2010)
New Revision: 6231
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
Log:
WELDSE-25: Added basic support for customising the deployment by subclassing the Weld class. Also updated URLScanner to use the configured or default ResourceLoader, rather than using Reflections.
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-14 11:26:08 UTC (rev 6230)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2010-05-14 12:25:01 UTC (rev 6231)
@@ -20,6 +20,7 @@
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.api.Environments;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.context.api.BeanStore;
import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.weld.environment.se.beans.InstanceManager;
@@ -69,9 +70,12 @@
public WeldContainer initialize()
{
- SEWeldDeployment deployment = new SEWeldDeployment()
+ SEWeldDeployment deployment = new SEWeldDeployment()
{
};
+ configureDeployment(deployment);
+ deployment.scan();
+
bootstrap.startContainer(Environments.SE, deployment, this.applicationBeanStore);
final BeanDeploymentArchive mainBeanDepArch = deployment.getBeanDeploymentArchives().get(0);
this.manager = bootstrap.getManager(mainBeanDepArch);
@@ -88,6 +92,24 @@
}
/**
+ * Clients can subclass and override this method to customise the deployment
+ * before weld boots up. For example, to add a custom ResourceLoader, you would
+ * subclass Weld like so:
+ * <code>
+ * public class MyWeld extends Weld {
+ * @Override
+ * protected void configureDeployment(Deployment deployment) {
+ * deployment.getServices().add(ResourceLoader.class, new OSGIResourceLoader());
+ * }
+ * }
+ * </code>
+ * @param deployment
+ */
+ protected void configureDeployment(Deployment deployment)
+ {
+ }
+
+ /**
* Shuts down Weld.
*/
public void shutdown()
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java 2010-05-14 11:26:08 UTC (rev 6230)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/AbstractScanner.java 2010-05-14 12:25:01 UTC (rev 6231)
@@ -17,6 +17,7 @@
package org.jboss.weld.environment.se.discovery;
import java.net.URL;
+import org.jboss.weld.resources.spi.ResourceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,12 +33,12 @@
{
private static final Logger log = LoggerFactory.getLogger(Scanner.class);
- private final ClassLoader classLoader;
+ private final ResourceLoader resourceLoader;
private final SEWeldDiscovery webBeanDiscovery;
- public AbstractScanner(ClassLoader classLoader, SEWeldDiscovery webBeanDiscovery)
+ public AbstractScanner(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
{
- this.classLoader = classLoader;
+ this.resourceLoader = resourceLoader;
this.webBeanDiscovery = webBeanDiscovery;
}
@@ -48,16 +49,12 @@
String className = filenameToClassname(name);
try
{
- webBeanDiscovery.getWbClasses().add(getClassLoader().loadClass(className));
+ webBeanDiscovery.getWbClasses().add(getResourceLoader().classForName(className));
}
catch (NoClassDefFoundError e)
{
log.error("Error loading " + name, e);
}
- catch (ClassNotFoundException e)
- {
- log.error("Error loading " + name, e);
- }
}
else if (name.endsWith("beans.xml"))
{
@@ -65,9 +62,9 @@
}
}
- public ClassLoader getClassLoader()
+ public ResourceLoader getResourceLoader()
{
- return classLoader;
+ return resourceLoader;
}
/**
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java 2010-05-14 11:26:08 UTC (rev 6230)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEBeanDeploymentArchive.java 2010-05-14 12:25:01 UTC (rev 6231)
@@ -24,6 +24,7 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.ejb.spi.EjbDescriptor;
/**
@@ -39,15 +40,25 @@
private final SEWeldDiscovery wbDiscovery;
private final ServiceRegistry serviceRegistry;
- public SEBeanDeploymentArchive()
+ /**
+ * @param deployment Used to gain access to the ResourceLoader, in case one is defined.
+ */
+ public SEBeanDeploymentArchive(Deployment deployment)
{
- wbDiscovery = new SEWeldDiscovery()
+ this.wbDiscovery = new SEWeldDiscovery(deployment)
{
};
- serviceRegistry = new SimpleServiceRegistry();
+ this.serviceRegistry = new SimpleServiceRegistry();
}
/**
+ * Perform the class scanning.
+ */
+ public void scan() {
+ wbDiscovery.scan();
+ }
+
+ /**
* @return a collection of all Bean classes on the classpath.
*/
public Collection<Class<?>> getBeanClasses()
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java 2010-05-14 11:26:08 UTC (rev 6230)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDeployment.java 2010-05-14 12:25:01 UTC (rev 6231)
@@ -29,17 +29,24 @@
*/
public abstract class SEWeldDeployment implements Deployment
{
- private final BeanDeploymentArchive beanDeploymentArchive;
+ private final SEBeanDeploymentArchive beanDeploymentArchive;
private final List<BeanDeploymentArchive> archInCollection;
public SEWeldDeployment()
{
- this.beanDeploymentArchive = new SEBeanDeploymentArchive();
+ this.beanDeploymentArchive = new SEBeanDeploymentArchive(this);
this.archInCollection = new ArrayList<BeanDeploymentArchive>(1);
this.archInCollection.add(this.beanDeploymentArchive);
}
/**
+ * Perform the class scanning.
+ */
+ public void scan() {
+ this.beanDeploymentArchive.scan();
+ }
+
+ /**
* {@inheritDoc}
*
* @return A collection containing the singular logical BeanDeploymentArchive
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-14 11:26:08 UTC (rev 6230)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/SEWeldDiscovery.java 2010-05-14 12:25:01 UTC (rev 6231)
@@ -21,8 +21,10 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import org.jboss.weld.bootstrap.spi.Deployment;
-import org.jboss.weld.environment.se.util.Reflections;
+import org.jboss.weld.resources.DefaultResourceLoader;
+import org.jboss.weld.resources.spi.ResourceLoader;
/**
* The means by which beans are discovered on the classpath. This will only
@@ -35,14 +37,16 @@
public abstract class SEWeldDiscovery
{
+ private ResourceLoader resourceLoader;
+ private final Deployment deployment;
private final Set<Class<?>> wbClasses;
private final Set<URL> wbUrls;
- public SEWeldDiscovery()
+ public SEWeldDiscovery(Deployment deployment)
{
+ this.deployment = deployment;
this.wbClasses = new HashSet<Class<?>>();
this.wbUrls = new HashSet<URL>();
- scan();
}
public Iterable<Class<?>> discoverWeldClasses()
@@ -65,10 +69,23 @@
return wbUrls;
}
- private void scan()
+ public void scan()
{
- Scanner scanner = new URLScanner(Reflections.getClassLoader(), this);
+ Scanner scanner = new URLScanner(resourceLoader(), this);
scanner.scanResources(new String[] { "META-INF/beans.xml" });
}
+ public synchronized ResourceLoader resourceLoader() {
+ if (this.resourceLoader == null)
+ {
+ ResourceLoader aResourceLoader = deployment.getServices().get(ResourceLoader.class);
+ if (aResourceLoader == null)
+ {
+ aResourceLoader = new DefaultResourceLoader();
+ }
+ this.resourceLoader = aResourceLoader;
+ }
+ return this.resourceLoader;
+ }
+
}
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-14 11:26:08 UTC (rev 6230)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery/URLScanner.java 2010-05-14 12:25:01 UTC (rev 6231)
@@ -22,12 +22,14 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+import org.jboss.weld.resources.spi.ResourceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,9 +47,9 @@
{
private static final Logger log = LoggerFactory.getLogger(URLScanner.class);
- public URLScanner(ClassLoader classLoader, SEWeldDiscovery webBeanDiscovery)
+ public URLScanner(ResourceLoader resourceLoader, SEWeldDiscovery webBeanDiscovery)
{
- super(classLoader, webBeanDiscovery);
+ super(resourceLoader, webBeanDiscovery);
}
public void scanDirectories(File[] directories)
@@ -66,11 +68,11 @@
{
try
{
- Enumeration<URL> urlEnum = getClassLoader().getResources(resourceName);
+ Collection<URL> urlEnum = getResourceLoader().getResources(resourceName);
- while (urlEnum.hasMoreElements())
+ for (URL url : urlEnum)
{
- String urlPath = urlEnum.nextElement().getFile();
+ String urlPath = url.getFile();
urlPath = URLDecoder.decode(urlPath, "UTF-8");
if (urlPath.startsWith("file:"))
13 years, 11 months