3535
3636package org .scijava .util ;
3737
38+ import java .io .BufferedReader ;
3839import java .io .File ;
3940import java .io .FileInputStream ;
4041import java .io .FileOutputStream ;
4142import java .io .IOException ;
42- import java .io .ObjectInputStream ;
43- import java .io .ObjectOutputStream ;
43+ import java .io .InputStreamReader ;
44+ import java .io .PrintStream ;
4445import java .net .URL ;
4546import java .util .Enumeration ;
4647import java .util .HashSet ;
4950import java .util .zip .ZipEntry ;
5051import java .util .zip .ZipInputStream ;
5152
52- import net .java .sezpoz .impl .SerAnnotatedElement ;
53-
5453/**
5554 * Combines SezPoz annotations from all JAR files on the classpath.
5655 *
5756 * @author Curtis Rueden
5857 */
5958public class CombineAnnotations {
6059
61- private static final String PREFIX = "META-INF/annotations " ;
60+ private static final String PREFIX = "META-INF/json " ;
6261 private static final String OUTPUT_DIR = "src/main/assembly/all" ;
6362
6463 private final Set <String > annotationFiles ;
@@ -69,8 +68,7 @@ public CombineAnnotations() throws IOException {
6968
7069 /** Reads in annotations from all available resources and combines them. */
7170 public void combine () throws IOException , ClassNotFoundException {
72- final HashSet <SerAnnotatedElement > annotations =
73- new HashSet <SerAnnotatedElement >();
71+ final StringBuilder annotations = new StringBuilder ();
7472 final ClassLoader loader = ClassLoader .getSystemClassLoader ();
7573
7674 log ("" );
@@ -79,32 +77,28 @@ public void combine() throws IOException, ClassNotFoundException {
7977 new File (OUTPUT_DIR , PREFIX ).mkdirs ();
8078
8179 for (final String annotationFile : annotationFiles ) {
82- annotations .clear ( );
80+ annotations .setLength ( 0 );
8381
8482 // read in annotations from all classpath resources
8583 final Enumeration <URL > resources = loader .getResources (annotationFile );
8684 while (resources .hasMoreElements ()) {
8785 final URL resource = resources .nextElement ();
88- final ObjectInputStream ois =
89- new ObjectInputStream (resource .openStream ());
86+ final BufferedReader reader = new BufferedReader (new InputStreamReader (resource .openStream ()));
9087 while (true ) {
91- final SerAnnotatedElement el = ( SerAnnotatedElement ) ois . readObject ();
92- if (el == null ) break ;
93- annotations .add ( el );
88+ final String line = reader . readLine ();
89+ if (line == null ) break ;
90+ annotations .append ( line );
9491 }
95- ois .close ();
92+ reader .close ();
9693 }
9794
9895 // write out annotations to combined file on disk
9996 final File outputFile = new File (OUTPUT_DIR , annotationFile );
100- final ObjectOutputStream oos =
101- new ObjectOutputStream (new FileOutputStream (outputFile ));
102- for (final SerAnnotatedElement el : annotations ) {
103- oos .writeObject (el );
104- }
105- oos .writeObject (null );
106- oos .close ();
107- log (outputFile .getName () + ": " + annotations .size () + " items" );
97+ final PrintStream out =
98+ new PrintStream (new FileOutputStream (outputFile ));
99+ out .print (annotations .toString ());
100+ out .close ();
101+ log (outputFile .getName () + ": " + annotations .length () + " bytes" );
108102 }
109103 }
110104
0 commit comments