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