diff --git a/utilities/buildutils/lib/jarjar-1.1.jar b/utilities/buildutils/lib/jarjar-1.1.jar new file mode 100644 index 000000000..352c00a42 Binary files /dev/null and b/utilities/buildutils/lib/jarjar-1.1.jar differ diff --git a/utilities/buildutils/src/com/tonicsystems/jarjar/KlugedDepFind.java b/utilities/buildutils/src/com/tonicsystems/jarjar/KlugedDepFind.java new file mode 100644 index 000000000..6ed1e64d8 --- /dev/null +++ b/utilities/buildutils/src/com/tonicsystems/jarjar/KlugedDepFind.java @@ -0,0 +1,93 @@ +/** + * Copyright 2007 Google Inc. + * + * 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. + */ + +/** + * This class is created to work around a known bug in JarJar which did not get fixed in release 1.1. + * See the comments in edu.cornell.mannlib.vitro.utilities.jarlist.JarLister + */ + +package com.tonicsystems.jarjar; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import com.tonicsystems.jarjar.asm.ClassReader; +import com.tonicsystems.jarjar.ext_util.ClassHeaderReader; +import com.tonicsystems.jarjar.ext_util.ClassPathEntry; +import com.tonicsystems.jarjar.ext_util.ClassPathIterator; +import com.tonicsystems.jarjar.ext_util.RuntimeIOException; + +public class KlugedDepFind { + private File curDir = new File(System.getProperty("user.dir")); + + public void setCurrentDirectory(File curDir) { + this.curDir = curDir; + } + + public void run(String from, String to, DepHandler handler) + throws IOException { + try { + ClassHeaderReader header = new ClassHeaderReader(); + Map classes = new HashMap(); + ClassPathIterator cp = new ClassPathIterator(curDir, to, null); + try { + while (cp.hasNext()) { + ClassPathEntry entry = cp.next(); + InputStream in = entry.openStream(); + try { + header.read(in); + classes.put(header.getClassName(), entry.getSource()); + } catch (Exception e) { + System.err.println("Error reading " + entry.getName() + + ": " + e.getMessage()); + } finally { + in.close(); + } + } + } finally { + cp.close(); + } + + handler.handleStart(); + cp = new ClassPathIterator(curDir, from, null); + try { + while (cp.hasNext()) { + ClassPathEntry entry = cp.next(); + InputStream in = entry.openStream(); + try { + new ClassReader(in).accept(new DepFindVisitor(classes, + entry.getSource(), handler), + ClassReader.SKIP_DEBUG + | ClassReader.EXPAND_FRAMES); + } catch (Exception e) { + System.err.println("Error reading " + entry.getName() + + ": " + e.getMessage()); + } finally { + in.close(); + } + } + } finally { + cp.close(); + } + handler.handleEnd(); + } catch (RuntimeIOException e) { + throw (IOException) e.getCause(); + } + } +} diff --git a/utilities/buildutils/src/edu/cornell/mannlib/vitro/utilities/jarlist/JarLister.java b/utilities/buildutils/src/edu/cornell/mannlib/vitro/utilities/jarlist/JarLister.java new file mode 100644 index 000000000..a9de1ec87 --- /dev/null +++ b/utilities/buildutils/src/edu/cornell/mannlib/vitro/utilities/jarlist/JarLister.java @@ -0,0 +1,175 @@ +/* $This file is distributed unnownder the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.utilities.jarlist; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import com.tonicsystems.jarjar.AbstractDepHandler; +import com.tonicsystems.jarjar.DepHandler; +import com.tonicsystems.jarjar.KlugedDepFind; + +/** + * This takes the place of the JarJar main routine, in doing a Find operation. + * + * One thing this lets us do is to call KlugedDepFind instead of DepFind. + * KlugedDepFind was created because JarJar had a known bug that wasn't fixed in + * the latest release. (see http://code.google.com/p/jarjar/issues/detail?id=6). + * I had to put KlugedDepFind into the com.tonicsystems.jarjar package so it + * wauld have access to DepFindVisitor, which is package-private. + * + * The other thing we can do is to provide a custom DepHandler which records the + * dependencies directly instead of writing them to a file which we would need + * to parse. Since we have the dependencies in a data structure, it's easy to + * walk the tree and find out what JARs are required, even through several + * layers of dependency. + * + * When calling this, pass 2 arguments. The first is the path to the JAR which + * contains the Vitro (or VIVO) classes. The second is the path to the directory + * that contains the JARs. (shouldn't end with a slash) + * + * There is a list of JARs which we know we need but which aren't shown by the + * analysis. For example, the MySQL driver is loaded dynamically by name, so an + * analysis of the class files in the JARs won't show that it is used. For now, + * these known dependencies are hard-coded, but it would be nice to read them + * from a data file instead. + */ +public class JarLister { + /** + *
+	 * 
+	 * What I originally wanted to do was this:
+	 * 
+	 * 
+	 *   
+	 *     
+	 *     
+	 *     
+	 *     
+	 *     
+	 *   
+	 * 
+	 * 
+	 * I ended up with this instead:
+	 * 
+	 * 
+	 *   
+	 *     
+	 *     
+	 *     
+	 *   
+	 * 
+	 * 
+	 * 
+ */ + + private static final String[] KNOWN_DEPENDENCIES = { + "mysql-connector-java-5.1.16-bin.jar", "commons-logging-1.1.1.jar" }; + + private final String topJar; + private final String libDirectory; + + private final Map> dependencyMap = new HashMap>(); + private final Set dependencySet = new TreeSet(); + + public JarLister(String[] args) { + topJar = args[0]; + libDirectory = args[1]; + } + + public void runDepFind() throws IOException { + DepHandler handler = new AbstractDepHandler(DepHandler.LEVEL_JAR) { + @Override + public void handle(String from, String to) { + addToMap(from, to); + } + }; + + String fullPath = topJar + ":" + libDirectory + "/*"; + + new KlugedDepFind().run(fullPath, fullPath, handler); + } + + private void addToMap(String fromPath, String toPath) { + String fromName = new File(fromPath).getName(); + String toName = new File(toPath).getName(); + + if (!dependencyMap.containsKey(fromName)) { + dependencyMap.put(fromName, new HashSet()); + } + dependencyMap.get(fromName).add(toName); + // System.out.println("Adding " + fromName + " ==> " + toName); + } + + public void populateDependencySet() { + String topJarName = new File(topJar).getName(); + addDependenciesFor(topJarName); + + for (String known : KNOWN_DEPENDENCIES) { + dependencySet.add(known); + addDependenciesFor(known); + } + } + + private void addDependenciesFor(String name) { + if (!dependencyMap.containsKey(name)) { + return; + } + for (String depend : dependencyMap.get(name)) { + if (!dependencySet.contains(depend)) { + dependencySet.add(depend); + // System.out.println("Depend: " + depend); + addDependenciesFor(depend); + } + } + } + + public void dumpDependencySet(PrintWriter w) { + w.println("--------------------"); + w.println("Known required JARs"); + w.println("--------------------"); + for (String d : KNOWN_DEPENDENCIES) { + w.println(" " + d); + } + w.println(); + + w.println("--------------------"); + w.println("Dependent JARs"); + w.println("--------------------"); + for (String d : dependencySet) { + w.println(" " + d); + } + w.println(); + + File libDir = new File(libDirectory); + SortedSet unused = new TreeSet(Arrays.asList(libDir + .list())); + unused.removeAll(dependencySet); + + w.println("--------------------"); + w.println("Unused JARs"); + w.println("--------------------"); + for (String d : unused) { + w.println(" " + d); + } + w.println(); + } + + public static void main(String[] args) throws IOException { + JarLister jl = new JarLister(args); + jl.runDepFind(); + jl.populateDependencySet(); + + PrintWriter output = new PrintWriter(System.out, true); + jl.dumpDependencySet(output); + output.close(); + } +} diff --git a/webapp/build.xml b/webapp/build.xml index 36ce04617..b75089964 100644 --- a/webapp/build.xml +++ b/webapp/build.xml @@ -97,22 +97,14 @@ deploy - Deploy the application directly into the Tomcat webapps directory. - - - - - - - - + + + + + + + + @@ -138,20 +130,11 @@ deploy - Deploy the application directly into the Tomcat webapps directory. - - - - - - - - - - - - - - - - - --> - + - + - + @@ -210,21 +192,11 @@ deploy - Deploy the application directly into the Tomcat webapps directory. ================================= --> - + - + @@ -233,20 +205,11 @@ deploy - Deploy the application directly into the Tomcat webapps directory. target: test ================================= --> - + - + @@ -263,10 +226,7 @@ deploy - Deploy the application directly into the Tomcat webapps directory. - + @@ -282,8 +242,7 @@ deploy - Deploy the application directly into the Tomcat webapps directory. - + @@ -329,9 +288,7 @@ deploy - Deploy the application directly into the Tomcat webapps directory. - + @@ -357,11 +314,21 @@ deploy - Deploy the application directly into the Tomcat webapps directory. At release time, applies license text to source files. ================================= --> - + + + + + + + + + +