You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2010/05/04 10:48:42 UTC

svn commit: r940772 - in /tuscany/sandbox/kgoodson/SourceExplore/src/main/java: sourcehash/HashSPISource.java sourcehash/package.html spiversioning/ spiversioning/SPIVersioning.java

Author: kelvingoodson
Date: Tue May  4 08:48:42 2010
New Revision: 940772

URL: http://svn.apache.org/viewvc?rev=940772&view=rev
Log:
utilities for tracking spi changes

Added:
    tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/
    tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java   (with props)
Modified:
    tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java
    tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html

Modified: tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java?rev=940772&r1=940771&r2=940772&view=diff
==============================================================================
--- tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java (original)
+++ tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java Tue May  4 08:48:42 2010
@@ -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

Modified: tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html
URL: http://svn.apache.org/viewvc/tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html?rev=940772&r1=940771&r2=940772&view=diff
==============================================================================
--- tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html (original)
+++ tuscany/sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html Tue May  4 08:48:42 2010
@@ -2,7 +2,7 @@
 <html>
 <head>
 </head>
-<body bgcolor="white">
+<body>
 
 Produces and XML file containing md5sums for files in a file system hierarchy.
 

Added: tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java?rev=940772&view=auto
==============================================================================
--- tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java (added)
+++ tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java Tue May  4 08:48:42 2010
@@ -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

Propchange: tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date