diff options
Diffstat (limited to 'sandbox/kgoodson')
3 files changed, 163 insertions, 2 deletions
diff --git a/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java b/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java index 6ac7067e46..c2c009015e 100644 --- a/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java +++ b/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java @@ -33,7 +33,7 @@ public class HashSPISource { ObjectFactory fac = new ObjectFactory(); - String sourceRoot = "c:/Dev2/SCA"; + String sourceRoot = "c:/Dev3/SCA"; String inputXML = "src/main/resources/projects.xml"; JAXBContext jaxbContext = JAXBContext diff --git a/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html b/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html index 57353774be..1e2386f116 100644 --- a/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html +++ b/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html @@ -2,7 +2,7 @@ <html> <head> </head> -<body bgcolor="white"> +<body> Produces and XML file containing md5sums for files in a file system hierarchy. diff --git a/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java b/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java new file mode 100644 index 0000000000..536a55f13e --- /dev/null +++ b/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java @@ -0,0 +1,161 @@ +package spiversioning; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + + + +public class SPIVersioning { + + /** + * alter this to your own environment. The format must match the systems canonical filename form. + */ + static final String sourceRoot = "C:\\Dev3\\SCA\\modules\\"; + + public static void main(String[] args) throws Throwable { + + + File root = new File(sourceRoot); + File rootf =root.getAbsoluteFile(); + File[] contents = rootf.listFiles(); + + SPIVersioning hs = new SPIVersioning(); + + System.out.println("<spifiles>"); + for (File file : contents) { + hs.analyseProjectDir(file); + } + System.out.println("</spifiles>"); + + + } + + private void analyseProjectDir(File pdir) { + + try { + File javaSrc = new File(pdir.getAbsolutePath() + "/src/main/java"); + File jsrcdir = javaSrc.getAbsoluteFile(); + File[] pkgRoots = jsrcdir.listFiles(); + + + for (File proot : pkgRoots) { + analyzeJavaFiles(proot); + } + + } catch (Exception e) { + // TODO: handle exception + } + + + + } + + String fileToString (File f) throws java.io.IOException{ + StringBuffer sb = new StringBuffer(1000); + BufferedReader reader = new BufferedReader(new FileReader(f)); + char[] buf = new char[1024]; + int count = 0; + while((count=reader.read(buf)) != -1){ + String readData = String.valueOf(buf, 0, count); + sb.append(readData); + buf = new char[1024]; + } + reader.close(); + return sb.toString(); + } + + static class PkgDirFilter implements FileFilter { + + public boolean accept(File pathname) { + boolean rv = false; + if (pathname.isDirectory()) { + rv = true; + } else if(pathname.getName().endsWith(".java")) { + rv = true; + } else if (pathname.getName().equals("package.html")) { + rv = true; + } + + return rv; + } + + } + private void analyzeJavaFiles(File proot) throws Exception { + + + File[] filesOfInterest = proot.listFiles(new PkgDirFilter()); + for (File file : filesOfInterest) { + if(file.isDirectory()) { + analyzeJavaFiles(file); + } else if (file.getName().equals("package.html")) { + // TODO decide if this means every java file in this package is implicitly spi + } else { + String fcontents = fileToString(file); + if(fcontents.contains("@tuscany.spi.extension")) { + String digest = md5(file); + String cpath = file.getCanonicalPath(); + cpath = cpath.replace(sourceRoot, ""); + System.out.println(" <file path=\""+cpath+"\" md5=\"" +digest + "\"/>"); + } + + + } + + } + + } + + private static String md5(File f) { + MessageDigest digest = null; + try { + digest = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + InputStream is = null; + String output = null; + try { + is = new FileInputStream(f); + } catch (FileNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + byte[] buffer = new byte[8192]; + int read = 0; + try { + while( (read = is.read(buffer)) > 0) { + digest.update(buffer, 0, read); + } + byte[] md5sum = digest.digest(); + BigInteger bigInt = new BigInteger(1, md5sum); + output = bigInt.toString(16); + } + catch(IOException e) { + throw new RuntimeException("Unable to process file for MD5", e); + } + finally { + try { + is.close(); + } + catch(IOException e) { + throw new RuntimeException("Unable to close input stream for MD5 calculation", e); + } + } + return output; + } + + + + +}
\ No newline at end of file |