You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2011/06/14 23:46:56 UTC
svn commit: r1135817 - in
/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools:
Daily.java examples/GenerateIndex.java
Author: rmannibucau
Date: Tue Jun 14 21:46:56 2011
New Revision: 1135817
URL: http://svn.apache.org/viewvc?rev=1135817&view=rev
Log:
adding some code in GenerateIndex (in progress)
Modified:
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/Daily.java
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java
Modified: openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/Daily.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/Daily.java?rev=1135817&r1=1135816&r2=1135817&view=diff
==============================================================================
--- openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/Daily.java (original)
+++ openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/Daily.java Tue Jun 14 21:46:56 2011
@@ -31,6 +31,6 @@ import org.apache.openejb.tools.examples
public class Daily {
public static void main(String[] args) {
- GenerateIndex.main(args);
+ GenerateIndex.main(args); // "/tmp/examples.zip" "/tmp/openejb" for example
}
}
Modified: openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java?rev=1135817&r1=1135816&r2=1135817&view=diff
==============================================================================
--- openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java (original)
+++ openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/examples/GenerateIndex.java Tue Jun 14 21:46:56 2011
@@ -16,6 +16,15 @@
*/
package org.apache.openejb.tools.examples;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import org.apache.log4j.Logger;
+
/**
* Most the examples do not have any documentation.
* <p/>
@@ -41,6 +50,13 @@ package org.apache.openejb.tools.example
* @version $Rev$ $Date$
*/
public class GenerateIndex {
+ private static final Logger LOGGER = Logger.getLogger(GenerateIndex.class);
+ private static final int BUFFER_SIZE = 1024;
+ private static final String EXTRACTED_EXAMPLES = "extracted";
+ private static final String GENERATED_EXAMPLES = "generated";
+ private static final String README_MD = "README.md";
+ private static final String POM_XML = "pom.xml";
+ private static final String INDEX_HTML = "index.html";
// A couple possible markdown processors in Java
// http://code.google.com/p/markdownj/wiki/Maven
@@ -58,16 +74,83 @@ public class GenerateIndex {
* @param args
*/
public static void main(String[] args) {
- // crack open the examples zip file
+ if (args.length < 1) {
+ LOGGER.info("Usage: <main> <examples-zip-location> <output-folder>");
+ return;
+ }
- // create a directory for each example
+ File extractedDir = new File(args[1], EXTRACTED_EXAMPLES);
+ File generatedDir = new File(args[1], GENERATED_EXAMPLES);
- // use the README.md markdown file to generate an index.html page
+ // crack open the examples zip file
+ extract(args[0], extractedDir.getPath());
- // If there is no README.md we should just generate a basic page
- // maybe something that includes the FooTest.java code and shows
- // shows that with links to other classes in the example
+ Collection<File> examples = listFolders(extractedDir, POM_XML);
+ for (File example : examples) {
+ // create a directory for each example
+ File generated = new File(generatedDir, example.getPath().replace(extractedDir.getPath(), ""));
+ generated.mkdirs();
+
+ File readme = new File(example, README_MD);
+ if (readme.exists()) {
+ // use the README.md markdown file to generate an index.html page
+
+ // TODO
+ } else {
+ // If there is no README.md we should just generate a basic page
+ // maybe something that includes the FooTest.java code and shows
+ // shows that with links to other classes in the example
+ LOGGER.warn("no " + README_MD + " for example " + example.getName() + " [" + example.getPath() + "]");
+
+ // TODO
+ }
+ }
// create an index for all example directories
+ Collection<File> indexes = listFolders(extractedDir, INDEX_HTML);
+ // TODO
+ }
+
+ private static Collection<File> listFolders(File extractedDir, String name) {
+ Collection<File> examples = new ArrayList<File>();
+ for (File file : extractedDir.listFiles()) {
+ if (file.isDirectory()) {
+ examples.addAll(listFolders(file, name));
+ } else if (name.equals(file.getName())) {
+ examples.add(file.getParentFile());
+ }
+ }
+ return examples;
+ }
+
+ public static void extract(String filename, String output) {
+ File extractHere = new File(output);
+ if (!extractHere.exists()) {
+ extractHere.mkdirs();
+ }
+
+ try {
+ // we'll read everything so ZipFile is useless
+ ZipInputStream zip = new ZipInputStream(new FileInputStream(filename));
+ byte[] buf = new byte[BUFFER_SIZE];
+ ZipEntry entry;
+ while ((entry = zip.getNextEntry()) != null) {
+ if (entry.isDirectory()) {
+ new File(output + File.separator + entry.getName()).mkdirs();
+ } else {
+ int count;
+ File file = new File(output + File.separator + entry.getName());
+ FileOutputStream fos = new FileOutputStream(file);
+ while ((count = zip.read(buf, 0, BUFFER_SIZE)) != -1) {
+ fos.write(buf, 0, count);
+ }
+ fos.flush();
+ fos.close();
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.error("can't unzip examples", e);
+ throw new RuntimeException("can't unzip " + filename);
+ }
}
}