1 16 package org.outerj.daisy.tools.licensecheck; 17 18 import java.io.File ; 19 import java.io.FileReader ; 20 import java.io.BufferedReader ; 21 import java.util.Set ; 22 import java.util.HashSet ; 23 24 public class LicenseCheck { 25 private static Set extensions = new HashSet (); 26 static { 27 extensions.add("java"); 28 extensions.add("xsl"); 29 extensions.add("js"); 30 extensions.add("xml"); 31 } 32 private static Set exclusions = new HashSet (); 33 static { 34 exclusions.add("target"); 35 exclusions.add(".svn"); 36 } 37 38 public static void main(String [] args) throws Exception { 39 new LicenseCheck().run(); 40 } 41 42 public void run() throws Exception { 43 File file = new File ("."); 44 System.out.println("Will print names of files with missing license header, if any."); 45 checkRecursive(file); 46 } 47 48 private void checkRecursive(File directory) throws Exception { 49 File [] files = directory.listFiles(); 50 for (int i = 0; i < files.length; i++) { 51 File file = files[i]; 52 if (!exclusions.contains(file.getName())) { 53 if (file.isDirectory()) { 54 checkRecursive(file); 55 } else { 56 String name = file.getName(); 57 int pos = name.lastIndexOf('.'); 58 if (pos != -1) { 59 String extension = name.substring(pos + 1); 60 if (extensions.contains(extension)) { 61 if (!hasLicenseHeader(file)) { 62 System.out.println(file.getAbsolutePath()); 63 } 64 } 65 } 66 } 67 } 68 } 69 } 70 71 private boolean hasLicenseHeader(File file) throws Exception { 72 BufferedReader reader = new BufferedReader (new FileReader (file)); 73 try { 74 String line = null; 75 int count = 0; 76 while ((line = reader.readLine()) != null) { 77 if (line.indexOf("Licensed under the Apache License") != -1 78 || line.indexOf("no Daisy license") != -1) 79 return true; 80 count++; 81 if (count > 15) break; 83 } 84 85 return false; 86 } finally { 87 reader.close(); 88 } 89 } 90 } 91 | Popular Tags |