You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/09/28 12:15:46 UTC

svn commit: r1176810 - /openejb/trunk/sandbox/legal/src/main/java/org/apache/openejb/tools/legal/Main.java

Author: dblevins
Date: Wed Sep 28 10:15:46 2011
New Revision: 1176810

URL: http://svn.apache.org/viewvc?rev=1176810&view=rev
Log:
support optionally crawing the file system

Modified:
    openejb/trunk/sandbox/legal/src/main/java/org/apache/openejb/tools/legal/Main.java

Modified: openejb/trunk/sandbox/legal/src/main/java/org/apache/openejb/tools/legal/Main.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/legal/src/main/java/org/apache/openejb/tools/legal/Main.java?rev=1176810&r1=1176809&r2=1176810&view=diff
==============================================================================
--- openejb/trunk/sandbox/legal/src/main/java/org/apache/openejb/tools/legal/Main.java (original)
+++ openejb/trunk/sandbox/legal/src/main/java/org/apache/openejb/tools/legal/Main.java Wed Sep 28 10:15:46 2011
@@ -67,12 +67,13 @@ public class Main {
     private final File content;
     private Reports reports;
     private Map<String, String> licenses = new HashMap<String, String>();
+    private String filter;
 
 
     public Main(String... args) throws Exception {
         client = new DefaultHttpClient();
 
-        this.staging = new URI(args[0]);
+        this.staging = getURI(args[0]);
 
         String name = new File(this.staging.getPath()).getName();
 
@@ -95,6 +96,7 @@ public class Main {
 
         this.reports = new Reports();
 
+        this.filter = System.getProperty("filter", "org/apache/openejb");
         final URL style = this.getClass().getClassLoader().getResource("legal/style.css");
         IOUtil.copy(style.openStream(), new File(local, "style.css"));
 
@@ -103,6 +105,16 @@ public class Main {
         licenses("cddl-1.0");
     }
 
+    private URI getURI(String arg) throws URISyntaxException {
+        final URI uri = new URI(arg);
+        if (arg.startsWith("file:")) {
+            File file = new File(uri);
+            file = file.getAbsoluteFile();
+            return file.toURI();
+        }
+        return uri;
+    }
+
     private void licenses(String s) throws IOException {
         URL aslURL = this.getClass().getClassLoader().getResource("licenses/" + s + ".txt");
         licenses.put(s, IOUtil.slurp(aslURL).trim());
@@ -301,13 +313,27 @@ public class Main {
     }
 
     private void prepare() throws URISyntaxException, IOException {
+        final Set<File> files = new HashSet<File>();
 
-        final Set<URI> resources = crawl(staging);
+        if (staging.toString().startsWith("http")) {
+            final Set<URI> resources = crawl(staging);
 
-        final Set<File> files = new HashSet<File>();
+            for (URI uri : resources) {
+                files.add(download(uri));
+            }
+        } else if (staging.toString().startsWith("file:")) {
+            File file = new File(staging);
+            List<File> collect = collect(file, new FileFilter() {
+                @Override
+                public boolean accept(File pathname) {
+                    String path = pathname.getAbsolutePath();
+                    return path.matches(filter) && isValidArchive(path);
+                }
+            });
 
-        for (URI uri : resources) {
-            files.add(download(uri));
+            for (File f : collect) {
+                files.add(copy(f));
+            }
         }
 
         for (File file : files) {
@@ -527,6 +553,20 @@ public class Main {
         return file;
     }
 
+    private File copy(File src) throws IOException {
+        final URI uri = src.toURI();
+
+        final File file = getFile(uri);
+
+        log.info("Copy " + uri);
+
+        mkparent(file);
+
+        IOUtil.copy(IOUtil.read(src), file);
+
+        return file;
+    }
+
     private static class LegalFilter implements FileFilter {
 
         private static final NoticeFilter notice = new NoticeFilter();
@@ -746,7 +786,7 @@ public class Main {
                     continue;
                 }
 
-                if (!uri.getPath().matches(".*(jar|zip|war|ear|tar.gz)")) continue;
+                if (!isValidArchive(uri.getPath())) continue;
 
                 resources.add(uri);
 
@@ -762,4 +802,8 @@ public class Main {
         }
         return resources;
     }
+
+    private boolean isValidArchive(String path) {
+        return path.matches(".*\\.(jar|zip|war|ear|tar.gz)");
+    }
 }