[jboss-cvs] JBossAS SVN: r92363 - in projects/annotations/trunk: core/src/main/java/org/jboss/annotations and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 14 08:25:34 EDT 2009


Author: jesper.pedersen
Date: 2009-08-14 08:25:33 -0400 (Fri, 14 Aug 2009)
New Revision: 92363

Added:
   projects/annotations/trunk/indexer/
   projects/annotations/trunk/indexer/build.xml
   projects/annotations/trunk/indexer/src/
   projects/annotations/trunk/indexer/src/main/
   projects/annotations/trunk/indexer/src/main/java/
   projects/annotations/trunk/indexer/src/main/java/org/
   projects/annotations/trunk/indexer/src/main/java/org/jboss/
   projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/
   projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/
   projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/FileUtil.java
   projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/Main.java
   projects/annotations/trunk/indexer/src/main/resources/
   projects/annotations/trunk/indexer/src/main/resources/indexer-manifest.mf
Modified:
   projects/annotations/trunk/build.xml
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
Log:
[JBANN-4] [JBANN-6] Initial import of the indexer

Modified: projects/annotations/trunk/build.xml
===================================================================
--- projects/annotations/trunk/build.xml	2009-08-14 12:23:50 UTC (rev 92362)
+++ projects/annotations/trunk/build.xml	2009-08-14 12:25:33 UTC (rev 92363)
@@ -49,6 +49,7 @@
   <property name="lib.dir" value="${basedir}/lib" />
   <property name="build.dir" value="${basedir}/build" />
   <property name="build.core.dir" value="${build.dir}/core" />
+  <property name="build.indexer.dir" value="${build.dir}/indexer" />
   <property name="target.dir" value="${basedir}/target" />
   <property name="tools.dir" value="${basedir}/tools" />
   <property name="reports.dir" value="${basedir}/reports" />
@@ -148,6 +149,7 @@
        ================================= -->
   <target name="jars" depends="resolve">
     <ant dir="core" inheritRefs="true" target="jars"/>
+    <ant dir="indexer" inheritRefs="true" target="jars"/>
   </target>
   
   <!-- ================================= 
@@ -176,6 +178,7 @@
        ================================= -->
   <target name="docs" depends="jars">
     <ant dir="core" inheritRefs="true" target="docs"/>
+    <ant dir="indexer" inheritRefs="true" target="docs"/>
   </target>
   
   <!-- ================================= 

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java	2009-08-14 12:23:50 UTC (rev 92362)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java	2009-08-14 12:25:33 UTC (rev 92363)
@@ -23,6 +23,7 @@
 package org.jboss.annotations;
 
 import java.util.Collection;
+import java.util.Set;
 
 /**
  * An annotation repository
@@ -31,6 +32,12 @@
 public interface AnnotationRepository
 {
    /**
+    * Get the available annotation keys
+    * @return The fully qualified class names of the available annotations
+    */
+   public Set<String> getAvailableAnnotations();
+
+   /**
     * Does the repository contain references of the specified annotation
     * @param annotation The annotation class
     * @return True if the repository contains references

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-08-14 12:23:50 UTC (rev 92362)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-08-14 12:25:33 UTC (rev 92363)
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -38,7 +39,7 @@
 public class AnnotationRepositoryImpl implements AnnotationRepository
 {
    /** The repository */
-   private ConcurrentMap<String, Collection<Annotation>> repositoy;
+   private ConcurrentMap<String, Collection<Annotation>> repository;
 
    /**
     * Constructor
@@ -49,10 +50,19 @@
       if (data == null)
          throw new IllegalArgumentException("Data is null");
 
-      repositoy = new ConcurrentHashMap<String, Collection<Annotation>>(data);
+      repository = new ConcurrentHashMap<String, Collection<Annotation>>(data);
    }
 
    /**
+    * Get the available annotation keys
+    * @return The fully qualified class names of the available annotations
+    */
+   public Set<String> getAvailableAnnotations()
+   {
+      return Collections.unmodifiableSet(repository.keySet());
+   }
+
+   /**
     * Does the repository contain references of the specified annotation
     * @param annotation The annotation class
     * @return True if the repository contains references
@@ -75,7 +85,7 @@
       if (annotation == null)
          throw new IllegalArgumentException("Annotation is null");
 
-      return repositoy.containsKey(annotation);
+      return repository.containsKey(annotation);
    }
 
    /**
@@ -103,7 +113,7 @@
       if (annotation == null)
          throw new IllegalArgumentException("Annotation is null");
 
-      Collection<Annotation> l = repositoy.get(annotation);
+      Collection<Annotation> l = repository.get(annotation);
       
       if (l == null)
          return null;
@@ -118,7 +128,7 @@
    public int getSize()
    {
       int numberOfAnnotations = 0;
-      for (Collection<Annotation> l : repositoy.values())
+      for (Collection<Annotation> l : repository.values())
       {
          numberOfAnnotations += l.size();
       }
@@ -135,7 +145,7 @@
       if (annotation == null)
          throw new IllegalArgumentException("Annotation is null");
 
-      Collection<Annotation> l = repositoy.get(annotation.getName());
+      Collection<Annotation> l = repository.get(annotation.getName());
       
       if (l == null)
          return 0;

Added: projects/annotations/trunk/indexer/build.xml
===================================================================
--- projects/annotations/trunk/indexer/build.xml	                        (rev 0)
+++ projects/annotations/trunk/indexer/build.xml	2009-08-14 12:25:33 UTC (rev 92363)
@@ -0,0 +1,82 @@
+<!--
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.
+-->
+<project name="jboss-annotations-indexer" 
+         default="compile" 
+         xmlns:ivy="antlib:org.apache.ivy.ant">
+
+  <!-- ================================= 
+       Properties              
+       ================================= -->
+  <property name="build.indexer.dir" value="${build.dir}/indexer" />
+
+  <!-- ================================= 
+       Target: init
+       ================================= -->
+  <target name="init">
+    <mkdir dir="${build.indexer.dir}" />
+    <mkdir dir="${build.indexer.dir}/impl" />
+  </target>
+
+  <!-- ================================= 
+       Target: compile
+       ================================= -->
+  <target name="compile" depends="init">
+    <javac srcdir="src/main"
+           destdir="${build.indexer.dir}/impl"
+           classpathref="core.lib.path.id"
+           debug="${javac.debug}"
+           deprecation="${javac.deprecation}"
+           optimize="${javac.optimize}">
+      <compilerarg value="-Xlint"/>
+    </javac> 
+  </target>
+
+  <!-- ================================= 
+       Target: jars 
+       ================================= -->
+  <target name="jars" depends="compile">
+    <jar destfile="${target.dir}/jboss-annotations-indexer.jar"
+         manifest="src/main/resources/indexer-manifest.mf"
+         basedir="${build.indexer.dir}/impl"
+         excludes="**/*.java"/>
+  </target>
+
+  <!-- ================================= 
+       Target: docs
+       ================================= -->
+  <target name="docs">
+    <mkdir dir="${target.dir}/docs/indexer"/>
+    <javadoc packagenames="org.*"
+             sourcepath="src/main/java"
+             destdir="${target.dir}/docs/indexer"
+             author="true"
+             version="true"
+             windowtitle="JBoss Annotations - Indexer"
+             doctitle="JBoss Annotations - Indexer"
+             use="true"
+             classpathref="core.lib.path.id"
+             bottom="Copyright &#169; 2009 Red Hat Middleware LLC (http://www.jboss.com/)">
+      <link offline="true" href="http://java.sun.com/j2se/5/docs/api/" packagelistLoc="${java.home}/../docs/api"/>
+    </javadoc>
+  </target>
+
+</project>

Added: projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/FileUtil.java
===================================================================
--- projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/FileUtil.java	                        (rev 0)
+++ projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/FileUtil.java	2009-08-14 12:25:33 UTC (rev 92363)
@@ -0,0 +1,254 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-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.
+ */
+
+package org.jboss.annotations.indexer;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+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>
+ */
+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 = new FileInputStream(manifestFile);
+         manifest = new Manifest(fis);
+         fis.close();
+      }
+      else
+      {
+         log.fine("No META-INF/MANIFEST.MF found; creating one");
+         manifest = new Manifest();
+      }
+
+      FileOutputStream fos = new FileOutputStream(target);
+      JarOutputStream 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 = new FileInputStream(f);
+            while ((bytesRead = in.read(buffer)) != -1)
+               jos.write(buffer, 0, bytesRead);
+            in.close(); 
+         }
+      }
+
+      jos.flush();
+      jos.close();
+   }
+
+   /**
+    * 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);
+
+      target.mkdirs();
+
+      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 = new BufferedInputStream(jar.getInputStream(je));
+            OutputStream 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();
+            out.close();
+            in.close();
+         }
+         else
+         {
+            copy.mkdirs();
+         }
+      }
+
+      return target;
+   }
+
+   /**
+    * Recursive delete
+    * @param f The file handler
+    */
+   public static void recursiveDelete(File f)
+   {
+      if (f.exists())
+      {
+         File[] files = f.listFiles();
+         if (files != null)
+         {
+            for (int i = 0; i < files.length; i++)
+            {
+               if (files[i].isDirectory())
+               {
+                  recursiveDelete(files[i]);
+               } 
+               else
+               {
+                  files[i].delete();
+               }
+            }
+         }
+         f.delete();
+      }
+   }
+
+   /**
+    * Find all file entries for a directory
+    * @param file 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/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/Main.java
===================================================================
--- projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/Main.java	                        (rev 0)
+++ projects/annotations/trunk/indexer/src/main/java/org/jboss/annotations/indexer/Main.java	2009-08-14 12:25:33 UTC (rev 92363)
@@ -0,0 +1,316 @@
+/*
+ * 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.
+ */
+
+package org.jboss.annotations.indexer;
+
+import org.jboss.annotations.Annotation;
+import org.jboss.annotations.AnnotationRepository;
+import org.jboss.annotations.AnnotationScanner;
+import org.jboss.annotations.AnnotationScannerFactory;
+import org.jboss.annotations.AnnotationType;
+import org.jboss.annotations.impl.AbstractAnnotationScanner;
+import org.jboss.annotations.impl.Scan;
+import org.jboss.annotations.impl.XMLLoader;
+import org.jboss.annotations.xml.ClassType;
+import org.jboss.annotations.xml.ConstructorType;
+import org.jboss.annotations.xml.FieldType;
+import org.jboss.annotations.xml.JbossAnnotation;
+import org.jboss.annotations.xml.MethodType;
+import org.jboss.annotations.xml.ParameterType;
+import org.jboss.annotations.xml.ScanType;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.GZIPOutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+/**
+ * The JBoss Annotations Indexer
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Main
+{
+   private static Logger log = Logger.getLogger(Main.class.getName());
+
+   /**
+    * Constructor
+    */
+   public Main()
+   {
+   }
+
+   /**
+    * Generate binary
+    * @param f The JAR file
+    * @param directory The destination directory
+    * @exception Exception Thrown if an error occurs
+    */
+   public void generateBinary(File f, File directory) throws Exception
+   {
+      FileInputStream fis = new FileInputStream(f);
+
+      Scan scan = XMLLoader.loadJBossAnnotation(fis);
+
+      File file = new File(directory, AbstractAnnotationScanner.JBOSS_ANNOTATION_BINARY);
+      FileOutputStream fos = new FileOutputStream(file);
+      BufferedOutputStream bos = new BufferedOutputStream(fos);
+      GZIPOutputStream gos = new GZIPOutputStream(bos);
+      ObjectOutputStream oos = new ObjectOutputStream(gos);
+
+      oos.writeObject(scan);
+
+      oos.flush();
+      oos.close();
+   }
+
+   /**
+    * Generate XML
+    * @param f The JAR file
+    * @param directory The destination directory
+    * @return The XML file 
+    * @exception Exception Thrown if an error occurs
+    */
+   public File generateXML(File f, File directory) throws Exception
+   {
+      AnnotationScanner scanner = AnnotationScannerFactory.getDefault();
+      AnnotationRepository repository = scanner.scan(new URL[] {f.toURI().toURL()});
+
+      JbossAnnotation root = new JbossAnnotation();
+      root.setExcludeAll(Boolean.TRUE);
+
+      ScanType scanType = new ScanType();
+      root.setScan(scanType);
+
+      Set<String> keys = repository.getAvailableAnnotations();
+      if (keys.size() > 0)
+      {
+         root.setExcludeAll(Boolean.FALSE);
+
+         for (String key : keys)
+         {
+            Collection<Annotation> l = repository.getAnnotation(key);
+
+            for (Annotation a : l)
+            {
+               AnnotationType type = a.getType();
+               String className = a.getClassName();
+
+               ClassType ct = getClassType(className, scanType.getClazz());
+
+               if (type == AnnotationType.CLASS)
+               {
+                  // Nothing else to do
+               }
+               else if (type == AnnotationType.FIELD)
+               {
+                  FieldType ft = new FieldType();
+                  ft.setValue(a.getMemberName());
+                  ct.getField().add(ft);
+               }
+               else if (type == AnnotationType.CONSTRUCTOR)
+               {
+                  ConstructorType cont = new ConstructorType();
+
+                  if (a.getParameterTypes() != null)
+                  {
+                     for (String parameter : a.getParameterTypes())
+                     {
+                        ParameterType pt = new ParameterType();
+                        pt.setValue(parameter);
+                        cont.getParameter().add(pt);
+                     }
+                  }
+
+                  ct.getConstructor().add(cont);
+               }
+               else if (type == AnnotationType.METHOD)
+               {
+                  MethodType mt = new MethodType();
+                  mt.setName(a.getMemberName());
+
+                  if (a.getParameterTypes() != null)
+                  {
+                     for (String parameter : a.getParameterTypes())
+                     {
+                        ParameterType pt = new ParameterType();
+                        pt.setValue(parameter);
+                        mt.getParameter().add(pt);
+                     }
+                  }
+
+                  ct.getMethod().add(mt);
+               }
+            }
+         }
+      }
+
+      JAXBContext context = JAXBContext.newInstance("org.jboss.annotations.xml");
+      Marshaller marshaller = context.createMarshaller();
+      marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+      marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.jboss.org/annotations");
+
+      File output = new File(directory, AbstractAnnotationScanner.JBOSS_ANNOTATION_XML);
+      OutputStream os = new FileOutputStream(output);
+      os = new BufferedOutputStream(os);
+
+      marshaller.marshal(root, os);
+
+      os.flush();
+      os.close();
+
+      return output;
+   }
+
+   /**
+    * Get class type
+    * @param className The class name
+    * @param list The class type list
+    * @return The class type
+    */
+   private ClassType getClassType(String className, List<ClassType> list)
+   {
+      ClassType type = findClassType(className, list);
+
+      if (type == null)
+      {
+         type = new ClassType();
+         type.setName(className);
+         list.add(type);
+      }
+
+      return type;
+   }
+
+   /**
+    * Find a class type
+    * @param className The class name
+    * @param list The class type list
+    * @return The class type; <code>null</code> if the list doesn't contain a reference
+    */
+   private ClassType findClassType(String className, List<ClassType> list)
+   {
+      if (list != null)
+      {
+         for (ClassType ct : list)
+         {
+            if (ct.getName().equals(className))
+            {
+               return ct;
+            }
+         }
+      }
+
+      return null;
+   }
+
+   /**
+    * Usage
+    */
+   private static void usage()
+   {
+      System.out.println("Usage: Indexer <binary|xml|both> <input-jar> <output-jar>");
+   }
+
+   /**
+    * Main
+    * @param args The program arguments
+    */
+   public static void main(String[] args)
+   {
+      try
+      {
+         if (args.length == 3)
+         {
+            Main m = new Main();
+            
+            boolean binary = false;
+            boolean xml = false;
+
+            if ("binary".equalsIgnoreCase(args[0]))
+            {
+               binary = true;
+            }
+            else if ("xml".equalsIgnoreCase(args[0]))
+            {
+               xml = true;
+            }
+            else if ("both".equalsIgnoreCase(args[0]))
+            {
+               binary = true;
+               xml = true;
+            }
+
+            if (binary || xml)
+            {
+               File input = new File(args[1]);
+               File output = new File(args[2]);
+
+               File tmp = new File(System.getProperty("java.io.tmpdir"));
+
+               File root = FileUtil.extract(input, tmp);
+               File destination = new File(root, "META-INF");
+
+               File xmlFile = null;
+               if (xml)
+               {
+                  xmlFile = m.generateXML(input, destination);
+               }
+               else
+               {
+                  xmlFile = m.generateXML(input, tmp);
+               }
+
+               if (binary)
+                  m.generateBinary(xmlFile, destination);
+
+               FileUtil.compress(root, output);
+               
+               FileUtil.recursiveDelete(root);
+               
+               if (!xml)
+                  FileUtil.recursiveDelete(xmlFile);
+            }
+         }
+         else
+         {
+            usage();
+         }
+      }
+      catch (Throwable t)
+      {
+         log.log(Level.SEVERE, t.getMessage(), t);
+      }
+   }
+}

Added: projects/annotations/trunk/indexer/src/main/resources/indexer-manifest.mf
===================================================================
--- projects/annotations/trunk/indexer/src/main/resources/indexer-manifest.mf	                        (rev 0)
+++ projects/annotations/trunk/indexer/src/main/resources/indexer-manifest.mf	2009-08-14 12:25:33 UTC (rev 92363)
@@ -0,0 +1,6 @@
+Class-Path: jboss-annotations.jar activation.jar jaxb-api.jar jaxb-impl.jar stax-api.jar javassist.jar
+Main-Class: org.jboss.annotations.indexer.Main
+Implementation-Title: JBoss Annotations - Indexer
+Implementation-Vendor: Red Hat Middleware LLC
+Implementation-Vendor-Id: org.jboss
+Implementation-Version: 0.1




More information about the jboss-cvs-commits mailing list