summaryrefslogtreecommitdiffstats
path: root/sandbox/kgoodson/SourceExplore
diff options
context:
space:
mode:
authorkelvingoodson <kelvingoodson@13f79535-47bb-0310-9956-ffa450edef68>2010-05-04 08:48:42 +0000
committerkelvingoodson <kelvingoodson@13f79535-47bb-0310-9956-ffa450edef68>2010-05-04 08:48:42 +0000
commitec53f38f059f0808f622586a50c7e771c655800e (patch)
tree529b86afffa84e058bf38d4c3a71231a023bab03 /sandbox/kgoodson/SourceExplore
parenteb67dee32e2a34ff6fcb562909426ca5d241e566 (diff)
utilities for tracking spi changes
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@940772 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/kgoodson/SourceExplore')
-rw-r--r--sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/HashSPISource.java2
-rw-r--r--sandbox/kgoodson/SourceExplore/src/main/java/sourcehash/package.html2
-rw-r--r--sandbox/kgoodson/SourceExplore/src/main/java/spiversioning/SPIVersioning.java161
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