Index: lams_build/src/org/lamsfoundation/lams/build/Jar.java =================================================================== diff -u -r62bb87b924ab3c6a68e521ba546488602d5f93f2 -ra6bdb8aa6b2a1748716d1b7cd921484d1e4987b3 --- lams_build/src/org/lamsfoundation/lams/build/Jar.java (.../Jar.java) (revision 62bb87b924ab3c6a68e521ba546488602d5f93f2) +++ lams_build/src/org/lamsfoundation/lams/build/Jar.java (.../Jar.java) (revision a6bdb8aa6b2a1748716d1b7cd921484d1e4987b3) @@ -37,133 +37,153 @@ *

* View Source *

- * + * * @author Fei Yang */ public class Jar implements Comparable { - - static final String[] VERSION_ATT_NAMES = {"Implementation-Version","HttpUnit-Version","Hibernate-Version"}; - static final String[] VENDOR_ATT_NAMES = {"Implementation-Vendor"}; - static final String[] LICENSE_FILE_NAMES = {"LICENSE","LICENSE.txt"}; - static final String[] DESC_ATT_NAMES = {"Specification-Title"}; - static final String[] LICENSES = {"Apache License","Apache Software License","Joda Software License","GPL","LGPL"}; + static final String[] VERSION_ATT_NAMES = + { "Implementation-Version", "HttpUnit-Version", "Hibernate-Version" }; + + static final String[] VENDOR_ATT_NAMES = { "Implementation-Vendor" }; + + static final String[] LICENSE_FILE_NAMES = + { "LICENSE", "LICENSE.txt", "License", "License.txt", "license.txt" }; + + static final String[] DESC_ATT_NAMES = { "Specification-Title", "Implementation-Title" }; + + static final String[] LICENSES = + { "Apache License", "Apache Software License", "Joda Software License", "GPL", "LGPL", + "GNU General Public License", "GNU Lesser General Public License", + "Open Software License","Academic Free License" }; + String name; + String version; + String license; + String vendor; + String description; public int compareTo(Object o) { - return name.compareTo(((Jar)o).name); + return name.compareTo(((Jar) o).name); } - - static Jar buildJar(File file) throws IOException{ + + static Jar buildJar(File file) throws IOException { Jar jar = new Jar(); jar.name = file.getName(); JarFile jarFile = new JarFile(file); Manifest manifest = jarFile.getManifest(); Attributes mainAttributes = manifest.getMainAttributes(); - for(String versionAtt : VERSION_ATT_NAMES){ + for (String versionAtt : VERSION_ATT_NAMES) { jar.version = mainAttributes.getValue(versionAtt); - if(jar.version != null){ + if (jar.version != null) { int index = jar.version.indexOf(' '); - if(index!=-1) + if (index != -1) jar.version = jar.version.substring(0, index).trim(); break; } } - if(jar.version == null){//try parsing file name + if (jar.version == null) {// try parsing file name int index1 = jar.name.lastIndexOf('-'); - if(index1!=-1){ + if (index1 != -1) { int index2 = jar.name.indexOf(".jar"); - jar.version = jar.name.substring(index1+1, index2); + jar.version = jar.name.substring(index1 + 1, index2); int index = index1; - while(jar.version.indexOf('.')==-1){ + while (jar.version.indexOf('.') == -1) { String s = jar.name.substring(0, index); index = s.lastIndexOf('-'); - if(index==-1) + if (index == -1) break; - else{ - jar.version = jar.name.substring(index+1,index2); + else { + jar.version = jar.name.substring(index + 1, index2); } } + if(jar.version.indexOf('.') == -1){ + jar.version = null; + } } } - for(String vendorAtt:VENDOR_ATT_NAMES){ + for (String vendorAtt : VENDOR_ATT_NAMES) { jar.vendor = mainAttributes.getValue(vendorAtt); - if(jar.vendor!=null) + if (jar.vendor != null) break; } - for(String descAtt:DESC_ATT_NAMES){ + for (String descAtt : DESC_ATT_NAMES) { jar.description = mainAttributes.getValue(descAtt); - if(jar.description!=null) + if (jar.description != null) break; } ZipEntry licenseZipEntry = null; - for(String licenseFilename:LICENSE_FILE_NAMES){ - licenseZipEntry = jarFile.getEntry("META-INF/"+licenseFilename); - if(licenseZipEntry!=null) + for (String licenseFilename : LICENSE_FILE_NAMES) { + licenseZipEntry = jarFile.getEntry("META-INF/" + licenseFilename); + if(licenseZipEntry == null){ + licenseZipEntry = jarFile.getEntry(licenseFilename); + } + if (licenseZipEntry != null && !licenseZipEntry.isDirectory()) break; } - if(licenseZipEntry!=null){ - BufferedInputStream is = new BufferedInputStream(jarFile.getInputStream(licenseZipEntry)); + if (licenseZipEntry != null && !licenseZipEntry.isDirectory()) { + BufferedInputStream is = new BufferedInputStream(jarFile + .getInputStream(licenseZipEntry)); List bytes = new LinkedList(); byte b; - while((b=(byte)is.read())!=-1){ + while ((b = (byte) is.read()) != -1) { bytes.add(b); } byte[] bs = new byte[bytes.size()]; int i = 0; - for(Byte B : bytes){ + for (Byte B : bytes) { bs[i] = B; i++; } String licenseTxt = new String(bs); - //out.println(licenseTxt); - //out.println(); jar.license = parse(licenseTxt); - //out.println("License:"+jar.license); - //out.println(); is.close(); } - if(jar.version!=null) jar.version = cleanQuotes(jar.version); - if(jar.description!=null) jar.description = cleanQuotes(jar.description); - if(jar.vendor!=null) jar.vendor = cleanQuotes(jar.vendor); + if (jar.version != null) + jar.version = cleanQuotes(jar.version); + if (jar.description != null) + jar.description = cleanQuotes(jar.description); + if (jar.vendor != null) + jar.vendor = cleanQuotes(jar.vendor); return jar; } - - static String parse(String licenseTxt){ + + static String parse(String licenseTxt) { String licenseName = ""; int licenseIndex = -1; - for(String license:LICENSES){ + for (String license : LICENSES) { licenseIndex = licenseTxt.indexOf(license); - if(licenseIndex!=-1){ + if (licenseIndex != -1) { licenseName = license; break; } } int versionIndex = licenseTxt.indexOf("Version"); String version = ""; - if(versionIndex!=-1){ + if (versionIndex != -1) { int i = licenseTxt.indexOf(' ', versionIndex); - int i1 = licenseTxt.indexOf(',', i+1); - int i2 = licenseTxt.indexOf(' ', i+1); + int i1 = licenseTxt.indexOf(',', i + 1); + int i2 = licenseTxt.indexOf(' ', i + 1); version = licenseTxt.substring(i, Math.min(i1, i2)).trim(); } StringBuilder result = new StringBuilder(); - if(licenseName.length()>0){ + if (licenseName.length() > 0) { result.append(licenseName); - if(version.length()>0){ + if (version.length() > 0) { result.append(' ').append(version); } } return result.toString(); } - - static String cleanQuotes(String txt){ - if(txt.indexOf('"')!=-1&&txt.indexOf('"')==0&&txt.lastIndexOf('"')==txt.length()-1){ - txt = txt.substring(1, txt.length()-1); + + static String cleanQuotes(String txt) { + if (txt.indexOf('"') != -1 && txt.indexOf('"') == 0 + && txt.lastIndexOf('"') == txt.length() - 1) { + txt = txt.substring(1, txt.length() - 1); } return txt; } Index: lams_build/src/org/lamsfoundation/lams/build/JarFolder.java =================================================================== diff -u -r62bb87b924ab3c6a68e521ba546488602d5f93f2 -ra6bdb8aa6b2a1748716d1b7cd921484d1e4987b3 --- lams_build/src/org/lamsfoundation/lams/build/JarFolder.java (.../JarFolder.java) (revision 62bb87b924ab3c6a68e521ba546488602d5f93f2) +++ lams_build/src/org/lamsfoundation/lams/build/JarFolder.java (.../JarFolder.java) (revision a6bdb8aa6b2a1748716d1b7cd921484d1e4987b3) @@ -39,26 +39,26 @@ public class JarFolder implements Comparable { String name; + List jars = new LinkedList(); - - void add(Jar jar){ + + void add(Jar jar) { jars.add(jar); } + public int compareTo(Object o) { - return name.compareTo(((JarFolder)o).name); + return name.compareTo(((JarFolder) o).name); } - - static JarFolder buildJarFolder(File file) throws IOException{ + + static JarFolder buildJarFolder(File file) throws IOException { JarFolder folder = new JarFolder(); folder.name = file.getName(); - File[] jars = file.listFiles( - new FilenameFilter(){ - public boolean accept(File dir, String name) { - return name.endsWith(".jar"); - } - } - ); - for(File jar:jars){ + File[] jars = file.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".jar"); + } + }); + for (File jar : jars) { folder.add(Jar.buildJar(jar)); } return folder;