Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse McConnell2013-05-01 19:18:55 +0000
committerJesse McConnell2013-05-01 19:18:55 +0000
commita1b780c2847ddc71dd53998bb5dd8b961ba48e4c (patch)
treeb6789c8aeefb95608c58ae9369bb99903af97034 /jetty-xslt-tools
parent24d3894926def314e01ad2b3e4a5bc1414f13cdd (diff)
downloadorg.eclipse.jetty.toolchain-a1b780c2847ddc71dd53998bb5dd8b961ba48e4c.tar.gz
org.eclipse.jetty.toolchain-a1b780c2847ddc71dd53998bb5dd8b961ba48e4c.tar.xz
org.eclipse.jetty.toolchain-a1b780c2847ddc71dd53998bb5dd8b961ba48e4c.zip
add simple caching
Diffstat (limited to 'jetty-xslt-tools')
-rw-r--r--jetty-xslt-tools/pom.xml36
-rw-r--r--jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/AbstractFetchException.java61
-rw-r--r--jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtension.java29
-rw-r--r--jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/SourceFetchExtension.java17
-rw-r--r--jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtensionTest.java2
-rw-r--r--jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/SourceFetchExtensionTest.java2
6 files changed, 119 insertions, 28 deletions
diff --git a/jetty-xslt-tools/pom.xml b/jetty-xslt-tools/pom.xml
index 7f9f2b2..18e8bee 100644
--- a/jetty-xslt-tools/pom.xml
+++ b/jetty-xslt-tools/pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.toolchain</groupId>
@@ -14,6 +15,19 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -21,12 +35,22 @@
<version>4.8.1</version>
</dependency>
<dependency>
- <groupId>com.google.code.javaparser</groupId>
- <artifactId>javaparser</artifactId>
- <version>1.0.8</version>
-</dependency>
+ <groupId>com.google.code.javaparser</groupId>
+ <artifactId>javaparser</artifactId>
+ <version>1.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.toolchain</groupId>
+ <artifactId>jetty-test-helper</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>9.0.2.v20130417</version>
+ </dependency>
</dependencies>
- <scm>
+ <scm>
<connection>scm:git:http://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.toolchain.git</connection>
<developerConnection>scm:git:ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.toolchain.git</developerConnection>
<url>http://git.eclipse.org/c/jetty/org.eclipse.jetty.toolchain.git/tree/jetty-xslt-tools</url>
diff --git a/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/AbstractFetchException.java b/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/AbstractFetchException.java
new file mode 100644
index 0000000..12d5fd7
--- /dev/null
+++ b/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/AbstractFetchException.java
@@ -0,0 +1,61 @@
+package org.eclipse.jetty.xslt.tools;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+
+import org.eclipse.jetty.toolchain.test.FS;
+import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
+import org.eclipse.jetty.util.IO;
+
+public class AbstractFetchException
+{
+
+ private static File _fetchCache;
+
+ static
+ {
+ _fetchCache = MavenTestingUtils.getTargetTestingDir("fetch-cache");
+ _fetchCache.mkdirs();
+ }
+
+ protected static File checkCache(String resource)
+ {
+ String original = resource;
+
+ File test = new File(_fetchCache, mangle(resource));
+
+ if ( test.exists() )
+ {
+ System.out.println("In Cache: " + original );
+ return test;
+ }
+ else
+ {
+ System.out.println("Not Cached: " + original );
+ return null;
+ }
+ }
+
+ protected static File cache(String filename, InputStream stream) throws Exception
+ {
+ File toCache = new File(_fetchCache, mangle(filename));
+
+ //System.out.println(toCache.getAbsolutePath());
+
+ FS.touch(toCache);
+
+ IO.copy(stream,new FileOutputStream(toCache));
+
+ return toCache;
+ }
+
+ protected static String mangle(String toMangle)
+ {
+ toMangle = toMangle.replace(":","_");
+ toMangle = toMangle.replace("/","_");
+
+ return toMangle;
+ }
+} \ No newline at end of file
diff --git a/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtension.java b/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtension.java
index e51a569..d95f7bd 100644
--- a/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtension.java
+++ b/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtension.java
@@ -23,34 +23,33 @@ import japa.parser.ast.CompilationUnit;
import japa.parser.ast.body.MethodDeclaration;
import japa.parser.ast.visitor.VoidVisitorAdapter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.net.URL;
-public class JavaSourceFetchExtension
+public class JavaSourceFetchExtension extends AbstractFetchException
{
public static String fetch( String location, String method ) throws Exception
{
-
- if ( method == null || "".equals(method) )
+ File fetchFile = checkCache( location );
+
+ if ( fetchFile == null )
{
- System.out.println("Fetch: " + location.trim());
-
URL url = new URL(location);
+ fetchFile = cache(location,url.openStream());
+ }
+
- // String source = IO.toString(url.openStream());
-
- CompilationUnit cu = JavaParser.parse(url.openStream());
+ if ( method == null || "".equals(method) )
+ {
+ CompilationUnit cu = JavaParser.parse(new FileInputStream(fetchFile));
return cu.toString();
}
else
{
- System.out.println("Fetch: " + location.trim() + " / " + method.trim() );
-
- URL url = new URL(location);
-
- // String source = IO.toString(url.openStream());
-
- CompilationUnit cu = JavaParser.parse(url.openStream());
+ CompilationUnit cu = JavaParser.parse(new FileInputStream(fetchFile));
// visit and print the methods names
MethodVisitor mv = new MethodVisitor(method);
diff --git a/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/SourceFetchExtension.java b/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/SourceFetchExtension.java
index 8d9105a..f45fb53 100644
--- a/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/SourceFetchExtension.java
+++ b/jetty-xslt-tools/src/main/java/org/eclipse/jetty/xslt/tools/SourceFetchExtension.java
@@ -18,6 +18,8 @@
package org.eclipse.jetty.xslt.tools;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -29,18 +31,23 @@ import java.io.Writer;
import java.net.URL;
-public class SourceFetchExtension
+public class SourceFetchExtension extends AbstractFetchException
{
/* ------------------------------------------------------------------- */
public static int bufferSize = 64*1024;
public static String fetch( String location ) throws Exception
- {
- System.out.println("Fetch: " + location.trim());
-
+ {
+
+ File fetchFile = checkCache( location );
+
+ if ( fetchFile == null )
+ {
URL url = new URL(location);
+ fetchFile = cache(location,url.openStream());
+ }
- return toString(url.openStream());
+ return toString(new FileInputStream(fetchFile));
}
/* ------------------------------------------------------------ */
diff --git a/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtensionTest.java b/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtensionTest.java
index 5dcc86e..18f4043 100644
--- a/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtensionTest.java
+++ b/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/JavaSourceFetchExtensionTest.java
@@ -33,7 +33,7 @@ public class JavaSourceFetchExtensionTest
Assert.assertNotNull(src);
- System.out.println(src);
+ //System.out.println(src);
}
}
diff --git a/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/SourceFetchExtensionTest.java b/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/SourceFetchExtensionTest.java
index 3574f5a..d248988 100644
--- a/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/SourceFetchExtensionTest.java
+++ b/jetty-xslt-tools/src/test/java/org/eclipse/jetty/xslt/tools/SourceFetchExtensionTest.java
@@ -33,7 +33,7 @@ public class SourceFetchExtensionTest
Assert.assertNotNull(src);
- System.out.println(src);
+ //System.out.println(src);
}
}

Back to the top