[jboss-cvs] JBossAS SVN: r103968 - in projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer: ant and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 14 09:17:12 EDT 2010
Author: alesj
Date: 2010-04-14 09:17:12 -0400 (Wed, 14 Apr 2010)
New Revision: 103968
Modified:
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Constants.java
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Main.java
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/ant/IndexerTask.java
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/ScanUtils.java
Log:
NPE checks.
Modified: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Constants.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Constants.java 2010-04-14 13:08:42 UTC (rev 103967)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Constants.java 2010-04-14 13:17:12 UTC (rev 103968)
@@ -1,9 +1,6 @@
package org.jboss.scanning.indexer;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
@@ -42,6 +39,9 @@
*/
public static Set<String> applyAliases(String... providers)
{
+ if (providers == null)
+ return Collections.emptySet();
+
Set<String> set = new HashSet<String>();
for (String provider : providers)
set.add(applyAlias(provider));
Modified: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Main.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Main.java 2010-04-14 13:08:42 UTC (rev 103967)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Main.java 2010-04-14 13:17:12 UTC (rev 103968)
@@ -67,7 +67,7 @@
for (int i = 0; i < urls.length; i++)
urls[i] = new File(args[i + offset]).toURI().toURL();
- ScanUtils.scan(input, urls, Constants.applyAliases(providers));
+ ScanUtils.scan(input, Constants.applyAliases(providers), urls);
}
else
{
Modified: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/ant/IndexerTask.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/ant/IndexerTask.java 2010-04-14 13:08:42 UTC (rev 103967)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/ant/IndexerTask.java 2010-04-14 13:17:12 UTC (rev 103968)
@@ -24,8 +24,10 @@
import java.io.File;
import java.net.URL;
-import java.util.Set;
+import org.jboss.scanning.indexer.Constants;
+import org.jboss.scanning.indexer.core.ScanUtils;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
@@ -39,40 +41,52 @@
{
private File input;
private URL[] cp;
- private Set<String> providers;
+ private String[] providers;
/**
- * Constructor
- */
- public IndexerTask()
- {
- input = null;
- }
+ * Execute Ant task.
+ *
+ * @exception BuildException If an error occurs
+ */
+ public void execute() throws BuildException
+ {
+ try
+ {
+ ScanUtils.scan(input, Constants.applyAliases(providers), cp);
+ }
+ catch (Exception e)
+ {
+ throw new BuildException(e);
+ }
+ }
- /**
- * Get the input file
- * @return The file
- */
public File getInput()
{
return input;
}
- /**
- * Set the input file
- * @param f The file
- */
public void setInput(File f)
{
input = f;
}
- /**
- * Execute Ant task.
- *
- * @exception BuildException If an error occurs
- */
- public void execute() throws BuildException
+ public URL[] getCp()
{
+ return cp;
}
+
+ public void setCp(URL[] cp)
+ {
+ this.cp = cp;
+ }
+
+ public String[] getProviders()
+ {
+ return providers;
+ }
+
+ public void setProviders(String[] providers)
+ {
+ this.providers = providers;
+ }
}
Modified: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/ScanUtils.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/ScanUtils.java 2010-04-14 13:08:42 UTC (rev 103967)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/ScanUtils.java 2010-04-14 13:17:12 UTC (rev 103968)
@@ -48,51 +48,24 @@
public class ScanUtils
{
/**
- * Store attachments.
- *
- * @param directory The destination directory
- * @param handles the handles we scanned
- * @exception Exception Thrown if an error occurs
- */
- public static void store(File directory, Map<ScanningPlugin, ScanningHandle> handles) throws Exception
- {
- if (handles == null)
- throw new IllegalArgumentException("Null handles");
-
- if (directory == null || directory.exists() == false)
- throw new IllegalArgumentException("Directory is null or doesn't exist");
-
- for (Map.Entry<ScanningPlugin, ScanningHandle> entry : handles.entrySet())
- {
- File file = new File(directory, entry.getKey().getHandleKey() + Scanner.SUFFIX);
- FileOutputStream fos = new FileOutputStream(file);
- BufferedOutputStream bos = new BufferedOutputStream(fos);
- GZIPOutputStream gos = new GZIPOutputStream(bos);
- ObjectOutputStream oos = new ObjectOutputStream(gos);
- try
- {
- oos.writeObject(entry.getValue());
- oos.flush();
- }
- finally
- {
- oos.close();
- }
- }
- }
-
- /**
* Scan the input with given classpath.
* The input is added as part of classpath,
* hence no need to explicitly include it.
*
* @param input the input jar
+ * @param pluginProviders the providers for plugins used while scanning
* @param cp the classpath
- * @param pluginProviders the providers for plugins used while scanning
* @throws Exception for any error
*/
- public static void scan(File input, URL[] cp, Set<String> pluginProviders) throws Exception
+ public static void scan(File input, Set<String> pluginProviders, URL[] cp) throws Exception
{
+ if (input == null)
+ throw new IllegalArgumentException("Null input");
+ if (pluginProviders == null || pluginProviders.isEmpty())
+ throw new IllegalArgumentException("Null or empty providers");
+ if (cp == null)
+ cp = new URL[0];
+
URL root = input.toURI().toURL();
URL[] urls = new URL[cp.length + 1];
urls[0] = root;
@@ -131,7 +104,7 @@
* @return new plugin instance
* @throws Exception for any error
*/
- private static ScanningPlugin createPlugin(String provider, URLClassLoader ucl) throws Exception
+ protected static ScanningPlugin createPlugin(String provider, URLClassLoader ucl) throws Exception
{
Class<?> clazz = ucl.loadClass(provider);
if (ScanningPlugin.class.isAssignableFrom(clazz))
@@ -156,4 +129,38 @@
else
throw new IllegalArgumentException("Cannot create plugin from " + provider);
}
+
+ /**
+ * Store attachments.
+ *
+ * @param directory The destination directory
+ * @param handles the handles we scanned
+ * @exception Exception Thrown if an error occurs
+ */
+ protected static void store(File directory, Map<ScanningPlugin, ScanningHandle> handles) throws Exception
+ {
+ if (handles == null)
+ throw new IllegalArgumentException("Null handles");
+
+ if (directory == null || directory.exists() == false)
+ throw new IllegalArgumentException("Directory is null or doesn't exist");
+
+ for (Map.Entry<ScanningPlugin, ScanningHandle> entry : handles.entrySet())
+ {
+ File file = new File(directory, entry.getKey().getHandleKey() + Scanner.SUFFIX);
+ FileOutputStream fos = new FileOutputStream(file);
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
+ GZIPOutputStream gos = new GZIPOutputStream(bos);
+ ObjectOutputStream oos = new ObjectOutputStream(gos);
+ try
+ {
+ oos.writeObject(entry.getValue());
+ oos.flush();
+ }
+ finally
+ {
+ oos.close();
+ }
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list