[jboss-cvs] JBossAS SVN: r103955 - in projects/scanning/trunk: indexer/src/main and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 14 06:34:43 EDT 2010
Author: alesj
Date: 2010-04-14 06:34:42 -0400 (Wed, 14 Apr 2010)
New Revision: 103955
Added:
projects/scanning/trunk/indexer/src/main/java/org/
projects/scanning/trunk/indexer/src/main/java/org/jboss/
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/
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/
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/
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/FileUtil.java
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/HTMLWriter.java
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/PluginProvider.java
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/maven/
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/providers/
projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/providers/AnnotationPluginProvider.java
projects/scanning/trunk/indexer/src/main/resources/
projects/scanning/trunk/indexer/src/main/resources/indexer-manifest.mf
projects/scanning/trunk/indexer/src/main/resources/style.css
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IntrospectionReflectProvider.java
Modified:
projects/scanning/trunk/indexer/pom.xml
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java
Log:
Initial indexer support
Modified: projects/scanning/trunk/indexer/pom.xml
===================================================================
--- projects/scanning/trunk/indexer/pom.xml 2010-04-14 07:26:33 UTC (rev 103954)
+++ projects/scanning/trunk/indexer/pom.xml 2010-04-14 10:34:42 UTC (rev 103955)
@@ -22,6 +22,14 @@
<groupId>org.jboss.scanning</groupId>
<artifactId>scanning-impl</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-plugins</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ </dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
Added: 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 (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/Main.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.indexer;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.scanning.indexer.core.PluginProvider;
+import org.jboss.scanning.indexer.core.ScanUtils;
+
+/**
+ * The Scanning Indexer.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class Main
+{
+ private static Logger log = Logger.getLogger(Main.class.getName());
+
+ /**
+ * Usage
+ */
+ private static void usage()
+ {
+ System.out.println("Usage: Indexer <input-jar> <classpath?>");
+ }
+
+ /**
+ * Main.
+ * The output is file named <input-jar>.jar.mcs.
+ *
+ * @param args the program arguments
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ if (args.length < 1)
+ {
+ File input = new File(args[0]);
+
+ URL[] urls = new URL[args.length - 1];
+ // add the rest of classpath
+ for (int i = 0; i < args.length - 1; i++)
+ urls[i] = new File(args[i + 1]).toURI().toURL();
+
+ // TODO -- add scanning plugins
+ ScanUtils.scan(input, urls, Collections.<PluginProvider>emptySet());
+ }
+ else
+ {
+ usage();
+ }
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.SEVERE, t.getMessage(), t);
+ }
+ }
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/ant/IndexerTask.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.indexer.ant;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * The Scanning Indexer Ant task.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class IndexerTask extends Task
+{
+ private File input;
+ private URL[] cp;
+ private Set<String> providers;
+
+ /**
+ * Constructor
+ */
+ public IndexerTask()
+ {
+ input = null;
+ }
+
+ /**
+ * 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
+ {
+ }
+}
Added: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/FileUtil.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/FileUtil.java (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/FileUtil.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,328 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.indexer.core;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.logging.Logger;
+
+
+/**
+ * An utility for JAR type files.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class FileUtil
+{
+ private static Logger log = Logger.getLogger(FileUtil.class.getName());
+
+ /**
+ * Constructor
+ */
+ private FileUtil()
+ {
+ }
+
+ /**
+ * Compress a directory in a JAR layout to a file
+ * @param directory The directory
+ * @param target The JAR file
+ * @exception IOException Thrown if an error occurs
+ */
+ public static void compress(File directory, File target) throws IOException
+ {
+ if (directory == null)
+ throw new IllegalArgumentException("Directory is null");
+
+ if (target == null)
+ throw new IllegalArgumentException("Target is null");
+
+ if (target.exists())
+ recursiveDelete(target);
+
+ Manifest manifest = null;
+
+ File manifestFile = new File(directory, "META-INF/MANIFEST.MF");
+ if (manifestFile.exists())
+ {
+ FileInputStream fis = null;
+ try
+ {
+ fis = new FileInputStream(manifestFile);
+ manifest = new Manifest(fis);
+ }
+ finally
+ {
+ try
+ {
+ if (fis != null)
+ fis.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ else
+ {
+ log.fine("No META-INF/MANIFEST.MF found; creating one");
+ manifest = new Manifest();
+ }
+
+ JarOutputStream jos = null;
+
+ try
+ {
+ FileOutputStream fos = new FileOutputStream(target);
+ jos = new JarOutputStream(fos, manifest);
+
+ int bytesRead;
+ byte[] buffer = new byte[4096];
+
+ List<File> entries = findEntries(directory);
+
+ if (entries != null)
+ {
+ entries.remove(new File("META-INF/MANIFEST.MF"));
+
+ for (File file : entries)
+ {
+ File f = new File(directory, file.getPath());
+ JarEntry entry = new JarEntry(file.getPath());
+ jos.putNextEntry(entry);
+
+ FileInputStream in = null;
+ try
+ {
+ in = new FileInputStream(f);
+ while ((bytesRead = in.read(buffer)) != -1)
+ jos.write(buffer, 0, bytesRead);
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ jos.flush();
+ }
+ finally
+ {
+ try
+ {
+ if (jos != null)
+ jos.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ /**
+ * Extract a JAR type file
+ * @param file The file
+ * @param directory The directory where the file should be extracted
+ * @return The root of the extracted JAR file
+ * @exception IOException Thrown if an error occurs
+ */
+ public static File extract(File file, File directory) throws IOException
+ {
+ if (file == null)
+ throw new IllegalArgumentException("File is null");
+
+ if (directory == null)
+ throw new IllegalArgumentException("Directory is null");
+
+ File target = new File(directory, file.getName());
+
+ if (target.exists())
+ recursiveDelete(target);
+
+ if (!target.mkdirs())
+ throw new IOException("Could not create " + target);
+
+ JarFile jar = new JarFile(file);
+ Enumeration<JarEntry> entries = jar.entries();
+
+ while (entries.hasMoreElements())
+ {
+ JarEntry je = entries.nextElement();
+ File copy = new File(target, je.getName());
+
+ if (!je.isDirectory())
+ {
+ InputStream in = null;
+ OutputStream out = null;
+
+ try
+ {
+ in = new BufferedInputStream(jar.getInputStream(je));
+ out = new BufferedOutputStream(new FileOutputStream(copy));
+
+ byte[] buffer = new byte[4096];
+ for (;;)
+ {
+ int nBytes = in.read(buffer);
+ if (nBytes <= 0)
+ break;
+
+ out.write(buffer, 0, nBytes);
+ }
+ out.flush();
+ }
+ finally
+ {
+ try
+ {
+ if (out != null)
+ out.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+
+ try
+ {
+ if (in != null)
+ in.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ else
+ {
+ if (!copy.mkdirs())
+ throw new IOException("Could not create " + copy);
+ }
+ }
+
+ return target;
+ }
+
+ /**
+ * Recursive delete
+ * @param f The file handler
+ * @exception IOException Thrown if a file could not be deleted
+ */
+ public static void recursiveDelete(File f) throws IOException
+ {
+ if (f != null && f.exists())
+ {
+ File[] files = f.listFiles();
+ if (files != null)
+ {
+ for (File file : files)
+ {
+ if (file.isDirectory())
+ {
+ recursiveDelete(file);
+ }
+ else
+ {
+ if (!file.delete())
+ throw new IOException("Could not delete " + file);
+ }
+ }
+ }
+ if (!f.delete())
+ throw new IOException("Could not delete " + f);
+ }
+ }
+
+ /**
+ * Find all file entries for a directory
+ * @param root The root directory
+ * @return The list of files
+ */
+ private static List<File> findEntries(File root)
+ {
+ try
+ {
+ return getListing(root, root);
+ }
+ catch (Exception e)
+ {
+ log.severe(e.getMessage());
+ }
+
+ return null;
+ }
+
+ /**
+ * Recursively walk a directory tree and return a list of all files entries found
+ * @param root The root directory
+ * @param directory The current directory
+ * @return The list of files
+ * @exception Exception Thrown if an error occurs
+ */
+ private static List<File> getListing(File root, File directory) throws Exception
+ {
+ List<File> result = new ArrayList<File>();
+
+ File[] filesAndDirs = directory.listFiles();
+
+ if (filesAndDirs != null)
+ {
+ for (File file : filesAndDirs)
+ {
+ if (file.isDirectory())
+ {
+ List<File> deeperList = getListing(root, file);
+ result.addAll(deeperList);
+ }
+ else
+ {
+ String fileName = file.getPath().substring(root.getPath().length() + 1);
+ result.add(new File(fileName));
+ }
+ }
+ }
+
+ return result;
+ }
+}
Added: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/HTMLWriter.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/HTMLWriter.java (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/HTMLWriter.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,206 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.indexer.core;
+
+import java.io.*;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A HTML report generator.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class HTMLWriter
+{
+ private static Logger log = Logger.getLogger(HTMLWriter.class.getName());
+
+ /** New line character */
+ protected static final String NEW_LINE = System.getProperty("line.separator");
+
+ /**
+ * Constructor
+ */
+ private HTMLWriter()
+ {
+ }
+
+ /**
+ * Generate CSS files
+ * @param directory Where the reports go
+ */
+ public static void generateCSS(File directory)
+ {
+ byte buffer[] = new byte[8192];
+ int bytesRead;
+
+ InputStream is = null;
+ OutputStream os = null;
+ try
+ {
+ is = HTMLWriter.class.getClassLoader().getResourceAsStream("style.css");
+
+ if (is != null)
+ {
+ os = new FileOutputStream(directory.getAbsolutePath() + File.separator + "style.css");
+ while ((bytesRead = is.read(buffer)) != -1)
+ {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ os.flush();
+ }
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.SEVERE, t.getMessage(), t);
+ }
+ finally
+ {
+ try
+ {
+ if (is != null)
+ is.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+
+ try
+ {
+ if (os != null)
+ os.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ /**
+ * Generate report
+ * @param directory Where the reports go
+ * @param name The name of the report
+ * @param data The raw data
+ */
+ public static void generateReport(File directory, String name, Map<String, Collection<String>> data)
+ {
+ BufferedWriter bw = null;
+ try
+ {
+ FileWriter fw = new FileWriter(directory.getAbsolutePath() + File.separator + name + ".html");
+ bw = new BufferedWriter(fw, 8192);
+
+ bw.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" +
+ "\"http://www.w3.org/TR/html4/loose.dtd\">" + NEW_LINE);
+ bw.write("<html>" + NEW_LINE);
+ bw.write("<head>" + NEW_LINE);
+ bw.write(" <title>Scanning: " + name + "</title>" + NEW_LINE);
+ bw.write(" <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">" + NEW_LINE);
+ bw.write(" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">" + NEW_LINE);
+ bw.write("</head>" + NEW_LINE);
+ bw.write("<body>" + NEW_LINE);
+ bw.write(NEW_LINE);
+
+ bw.write("<h1>Scanning: " + name + "</h1>" + NEW_LINE);
+
+ bw.write("<table>" + NEW_LINE);
+
+ bw.write(" <tr>" + NEW_LINE);
+ bw.write(" <th>Annotation</th>" + NEW_LINE);
+ bw.write(" <th>Location</th>" + NEW_LINE);
+ bw.write(" </tr>" + NEW_LINE);
+
+ boolean odd = true;
+
+ for (Map.Entry<String, Collection<String>> entry : data.entrySet())
+ {
+
+ String annotation = entry.getKey();
+ Collection<String> classes = entry.getValue();
+
+ if (odd)
+ {
+ bw.write(" <tr class=\"rowodd\">" + NEW_LINE);
+ }
+ else
+ {
+ bw.write(" <tr class=\"roweven\">" + NEW_LINE);
+ }
+ bw.write(" <td>" + annotation + "</td>" + NEW_LINE);
+ bw.write(" <td>");
+
+ Iterator<String> cit = classes.iterator();
+ while (cit.hasNext())
+ {
+ bw.write(cit.next());
+
+ if (cit.hasNext())
+ {
+ bw.write(", ");
+ }
+ }
+
+ bw.write("</td>" + NEW_LINE);
+ bw.write(" </tr>" + NEW_LINE);
+
+ odd = !odd;
+ }
+
+ bw.write("</table>" + NEW_LINE);
+
+
+ bw.write(NEW_LINE);
+ bw.write("<p>" + NEW_LINE);
+ bw.write("<hr>" + NEW_LINE);
+ bw.write("Generated by: <a href=\"http://www.jboss.org/projects/jbossmc\">Scanning</a>" + NEW_LINE);
+ bw.write(NEW_LINE);
+ bw.write("</body>" + NEW_LINE);
+ bw.write("</html>" + NEW_LINE);
+
+ bw.flush();
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.SEVERE, t.getMessage(), t);
+ }
+ finally
+ {
+ try
+ {
+ if (bw != null)
+ bw.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+ }
+}
Added: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/PluginProvider.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/PluginProvider.java (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/PluginProvider.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,19 @@
+package org.jboss.scanning.indexer.core;
+
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Create scanning plugin from given Classloader.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface PluginProvider
+{
+ /**
+ * Create plugin.
+ *
+ * @param cl the classloader
+ * @return new plugin instance
+ */
+ ScanningPlugin create(ClassLoader cl);
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/core/ScanUtils.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.indexer.core;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.GZIPOutputStream;
+
+import org.jboss.scanning.plugins.DefaultScanner;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Scan utils.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+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() + ".mcs");
+ 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 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<PluginProvider> pluginProviders) throws Exception
+ {
+ URL root = input.toURI().toURL();
+ URL[] urls = new URL[cp.length + 1];
+ urls[0] = root;
+ System.arraycopy(cp, 0, urls, 1, cp.length);
+
+ URLClassLoader ucl = new URLClassLoader(urls);
+ Set<ScanningPlugin> plugins = new HashSet<ScanningPlugin>();
+ for (PluginProvider provider : pluginProviders)
+ plugins.add(provider.create(ucl));
+
+ DefaultScanner scaner = new DefaultScanner(ucl, root);
+ scaner.setPlugins(plugins);
+ scaner.setIgnoreIndexedHandles(true); // re-index
+
+ scaner.scan(); // do the actual scanning
+
+ // write handles to file
+ Map<ScanningPlugin, ScanningHandle> handles = scaner.getHandles();
+ File tmp = new File(System.getProperty("java.io.tmpdir"));
+ File jar = FileUtil.extract(input, tmp);
+ File destination = new File(jar, "META-INF");
+ store(destination, handles);
+ File output = new File(input.getName() + ".mcs");
+ FileUtil.compress(jar, output);
+ FileUtil.recursiveDelete(jar);
+ }
+}
Added: projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/providers/AnnotationPluginProvider.java
===================================================================
--- projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/providers/AnnotationPluginProvider.java (rev 0)
+++ projects/scanning/trunk/indexer/src/main/java/org/jboss/scanning/indexer/providers/AnnotationPluginProvider.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.indexer.providers;
+
+import org.jboss.scanning.annotations.plugins.AnnotationsScanningPlugin;
+import org.jboss.scanning.indexer.core.PluginProvider;
+import org.jboss.scanning.plugins.helpers.ClassResourceOwnerFinder;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.IntrospectionReflectProvider;
+import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AnnotationPluginProvider implements PluginProvider
+{
+ public ScanningPlugin create(ClassLoader cl)
+ {
+ ReflectProvider provider = new IntrospectionReflectProvider();
+ ResourceOwnerFinder finder = ClassResourceOwnerFinder.INSTANCE;
+ return new AnnotationsScanningPlugin(provider, finder, cl);
+ }
+}
Added: projects/scanning/trunk/indexer/src/main/resources/indexer-manifest.mf
===================================================================
--- projects/scanning/trunk/indexer/src/main/resources/indexer-manifest.mf (rev 0)
+++ projects/scanning/trunk/indexer/src/main/resources/indexer-manifest.mf 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,6 @@
+Class-Path: jboss-scanning-spi.jar javassist.jar // TODO
+Main-Class: org.jboss.scanning.indexer.Main
+Implementation-Title: JBoss Scanning - Indexer
+Implementation-Vendor: Red Hat Middleware LLC
+Implementation-Vendor-Id: org.jboss
+Implementation-Version: 1.0
Added: projects/scanning/trunk/indexer/src/main/resources/style.css
===================================================================
--- projects/scanning/trunk/indexer/src/main/resources/style.css (rev 0)
+++ projects/scanning/trunk/indexer/src/main/resources/style.css 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,147 @@
+/*
+ * Papaki
+ * Copyright (C) 2009 Red Hat Middleware LLC.
+ * All rights reserved.
+ *
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+html {
+ height: 100%;
+ min-height: 100%;
+ background-color : #ffffff;
+ color : #454545;
+ border-collapse : collapse;
+ border-style: none;
+ margin : 0px auto;
+ padding: 0px;
+}
+
+body {
+ background-color : #ffffff;
+ color : #454545;
+ margin : 0px auto;
+ text-align : left;
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size: 10pt;
+ border-collapse : collapse;
+ border-style: none;
+ padding: 5px;
+}
+
+p {
+ margin: 5px;
+}
+
+a {
+ color: #527fa8;
+}
+
+hr {
+ border-top: 1px solid #a4b2b9;
+ border-right: 0px solid #a4b2b9;
+ border-left: 0px solid #a4b2b9;
+ border-bottom: 0px solid #a4b2b9;
+ margin-bottom: 3px;
+}
+
+img {
+ border: 0px;
+}
+
+h1 {
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size : 14pt;
+ font-weight : bold;
+ background-color: white;
+ color: #50667c;
+}
+
+h2 {
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size : 11pt;
+ font-weight : bold;
+ background-color: white;
+ color: #50667c;
+}
+
+h3 {
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size : 11pt;
+ font-weight : bold;
+ background-color: white;
+ color: #50667c;
+}
+
+h4 {
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size : 10pt;
+ font-weight : bold;
+ background-color: white;
+ color: #50667c;
+}
+
+h5 {
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size : 10pt;
+ font-weight : bold;
+ background-color: white;
+ color: #50667c;
+}
+
+h6 {
+ font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+ font-size : 10pt;
+ font-weight : bold;
+ background-color: white;
+ color: #50667c;
+}
+
+table {
+ width: 100%;
+ border-collapse : collapse;
+ border-style: none;
+}
+
+tr th {
+ background-color: #d9e0e3;
+ font-size: 10pt;
+ font-weight: bold;
+ color: #5f6a6f;
+ text-align: left;
+ padding: 3px;
+}
+
+tr td {
+ font-size: 10pt;
+ font-weight: bold;
+ vertical-align: top;
+ text-align: left;
+ padding: 3px;
+}
+
+.roweven {
+ background-color: white;
+}
+
+.rowodd {
+ background-color: #eff4f7;
+}
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java 2010-04-14 07:26:33 UTC (rev 103954)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -23,6 +23,8 @@
package org.jboss.scanning.plugins;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import org.jboss.classloader.spi.filter.ClassFilter;
@@ -44,6 +46,7 @@
{
/** The class loader */
private ClassLoader classLoader;
+ private Map<ScanningPlugin, ScanningHandle> handles;
protected VirtualFile[] excludedRoots;
protected ClassFilter included;
@@ -53,8 +56,19 @@
{
super(roots);
this.classLoader = classLoader;
+ this.handles = new HashMap<ScanningPlugin, ScanningHandle>();
}
+ /**
+ * Get the handles.
+ *
+ * @return the handles
+ */
+ public Map<ScanningPlugin, ScanningHandle> getHandles()
+ {
+ return handles;
+ }
+
protected void scan(Set<ScanningPlugin> plugins) throws Exception
{
URL[] urls = getRoots();
@@ -83,7 +97,9 @@
protected ScanningHandle createHandle(ScanningPlugin plugin)
{
- return plugin.createHandle();
+ ScanningHandle handle = plugin.createHandle();
+ handles.put(plugin, handle); // remember the created handle
+ return handle;
}
public void setExcludedRoots(VirtualFile[] excludedRoots)
Copied: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IntrospectionReflectProvider.java (from rev 103689, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/JavassistReflectProvider.java)
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IntrospectionReflectProvider.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IntrospectionReflectProvider.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.plugins.visitor;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * JDK reflection based reflect provider.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class IntrospectionReflectProvider implements ReflectProvider
+{
+ private IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();
+
+ public TypeInfo getTypeInfo(ResourceContext resource) throws Throwable
+ {
+ return factory.getTypeInfo(resource.loadClass());
+ }
+}
\ No newline at end of file
Modified: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java 2010-04-14 07:26:33 UTC (rev 103954)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java 2010-04-14 10:34:42 UTC (rev 103955)
@@ -44,6 +44,7 @@
{
private Logger log = Logger.getLogger(getClass());
private URL[] roots;
+ private boolean ignoreIndexedHandles;
protected UrlScanner(URL... roots)
{
@@ -66,15 +67,18 @@
ScanningHandle handle = createHandle(plugin);
ScanningPluginWrapper wrapper = new ScanningPluginWrapper(plugin);
federatedPlugins.add(wrapper);
- String handleKey = plugin.getHandleKey();
- for (URL root : roots)
+ if (ignoreIndexedHandles == false)
{
- InputStream is = getInputStream(root, handleKey + SUFFIX);
- if (is != null)
+ String handleKey = plugin.getHandleKey();
+ for (URL root : roots)
{
- ScanningHandle pre = readHandle(is);
- handle.merge(pre);
- wrapper.addURL(root); // exclude this url -- we already have pre-existing handle
+ InputStream is = getInputStream(root, handleKey + SUFFIX);
+ if (is != null)
+ {
+ ScanningHandle pre = readHandle(is);
+ handle.merge(pre);
+ wrapper.addURL(root); // exclude this url -- we already have pre-existing handle
+ }
}
}
}
@@ -131,4 +135,14 @@
}
protected abstract ScanningHandle createHandle(ScanningPlugin plugin);
+
+ /**
+ * Don't use existing indexed handles.
+ *
+ * @param ignoreIndexedHandles the handles check flag
+ */
+ public void setIgnoreIndexedHandles(boolean ignoreIndexedHandles)
+ {
+ this.ignoreIndexedHandles = ignoreIndexedHandles;
+ }
}
More information about the jboss-cvs-commits
mailing list