summaryrefslogtreecommitdiffstats
path: root/sandbox/kgoodson/SourceExplore
diff options
context:
space:
mode:
authorkelvingoodson <kelvingoodson@13f79535-47bb-0310-9956-ffa450edef68>2010-03-10 13:50:10 +0000
committerkelvingoodson <kelvingoodson@13f79535-47bb-0310-9956-ffa450edef68>2010-03-10 13:50:10 +0000
commit900d8f5b8d0ffbb2bf264d03d54771ace331a62c (patch)
treef5d6924c118098f73c1ea1c4f4026d0042fa6472 /sandbox/kgoodson/SourceExplore
parentef083f8a304dd324482cb3b62219e22f1ede3f14 (diff)
first working version
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@921350 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/kgoodson/SourceExplore')
-rw-r--r--sandbox/kgoodson/SourceExplore/src/main/java/HashSPISource.java110
-rw-r--r--sandbox/kgoodson/SourceExplore/src/main/resources/projects.xsd2
2 files changed, 103 insertions, 9 deletions
diff --git a/sandbox/kgoodson/SourceExplore/src/main/java/HashSPISource.java b/sandbox/kgoodson/SourceExplore/src/main/java/HashSPISource.java
index cfd9488a28..0567942f99 100644
--- a/sandbox/kgoodson/SourceExplore/src/main/java/HashSPISource.java
+++ b/sandbox/kgoodson/SourceExplore/src/main/java/HashSPISource.java
@@ -1,13 +1,23 @@
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.apache.tuscany.SourceExplore.ObjectFactory;
+import org.apache.tuscany.SourceExplore.Package;
import org.apache.tuscany.SourceExplore.Projects;
import org.apache.tuscany.SourceExplore.Projects2;
import org.apache.tuscany.SourceExplore.Projects2.Project;
@@ -20,15 +30,17 @@ public class HashSPISource {
ObjectFactory fac = new ObjectFactory();
+
+ String sourceRoot = "c:/Dev2/SCA";
+ String inputXML = "src/main/resources/projects.xml";
+
JAXBContext jaxbContext = JAXBContext
.newInstance("org.apache.tuscany.SourceExplore");
- Unmarshaller m = jaxbContext.createUnmarshaller();
-
-
+ Unmarshaller um = jaxbContext.createUnmarshaller();
- File inputFile = new File("src/main/resources/projects.xml").getAbsoluteFile();
- Projects p = (Projects)m.unmarshal(inputFile);
+ File inputFile = new File(inputXML).getAbsoluteFile();
+ Projects p = (Projects)um.unmarshal(inputFile);
List<JAXBElement<String>> data = p.getProjectOrPackage();
System.out.println(p);
@@ -38,11 +50,12 @@ public class HashSPISource {
for (int i = 0; i < data.size(); i++) {
+ Project proj = null;
if(!"project".equals(data.get(i).getName().getLocalPart())) {
throw new Exception("Expecting a project element " + i);
} else {
System.out.println("project: " + data.get(i).getValue());
- Project proj = fac.createProjects2Project();
+ proj = fac.createProjects2Project();
proj.setName(data.get(i).getValue());
p2.getProject().add(proj);
}
@@ -51,14 +64,95 @@ public class HashSPISource {
throw new Exception("Expecting a package element " + i);
} else {
System.out.println("package: " + data.get(i).getValue());
+ Package pkg = fac.createPackage();
+ pkg.setName(data.get(i).getValue());
+ proj.getPackage().add(pkg);
+ processPackage(sourceRoot, proj, pkg);
}
}
i--;
}
-
-
+ FileOutputStream fos = new FileOutputStream(new File("src/main/resources/out.xml").getAbsoluteFile());
+ Marshaller m = jaxbContext.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ m.marshal(p2, fos);
+ fos.close();
+
}
+ private static void processPackage(String sourceRoot, Project proj, Package pkg) {
+
+ ObjectFactory fac = new ObjectFactory();
+
+ String pkgPath = pkg.getName().replace('.', '/' );
+ String folderPath = sourceRoot +"/" + proj.getName() +"/src/main/java/" + pkgPath;
+ File folder = new File(folderPath);
+ File[] contents = folder.listFiles();
+
+ List<org.apache.tuscany.SourceExplore.File> files = pkg.getFile();
+ if(contents!= null) {
+ for (File file : contents) {
+ if(ofInterest(file)) {
+ org.apache.tuscany.SourceExplore.File f = fac.createFile();
+ f.setName(file.getPath());
+ String digest = md5(file);
+ f.setDigest(digest);
+ files.add(f);
+ }
+ System.out.println(file.getName());
+ }
+ }
+ }
+
+ 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);
+ System.out.println("MD5: " + output);
+ }
+ 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;
+ }
+
+ private static boolean ofInterest(File file) {
+ boolean result = false;
+
+ if(!result) result = file.getPath().endsWith(".java");
+ return result;
+ }
+
} \ No newline at end of file
diff --git a/sandbox/kgoodson/SourceExplore/src/main/resources/projects.xsd b/sandbox/kgoodson/SourceExplore/src/main/resources/projects.xsd
index bbdbd0414d..6ca98ed552 100644
--- a/sandbox/kgoodson/SourceExplore/src/main/resources/projects.xsd
+++ b/sandbox/kgoodson/SourceExplore/src/main/resources/projects.xsd
@@ -16,7 +16,7 @@
<element name="project">
<complexType>
<sequence maxOccurs="unbounded" minOccurs="0">
- <element name="package"><complexType></complexType></element>
+ <element name="package" type="tns:Package"></element>
</sequence>
<attribute name="name" type="string"></attribute>
</complexType>