[weld-commits] Weld SVN: r6235 - in java-se/trunk/src/main/java/org/jboss/weld/environment/se/discovery: handlers and 1 other directory.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Mon May 17 09:18:44 EDT 2010
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);
+
+}
More information about the weld-commits
mailing list