# HG changeset patch # User Jaroslav Tulach # Date 1218986152 -7200 # Node ID e1a7420cea38fb0e0799a3d2ef973584df4a78a3 # Parent cfc5a3fd5ae89fd893756b9c141634f13fce519b Generating .url files for each snippet, so the website can link to the hg web diff -r cfc5a3fd5ae8 -r e1a7420cea38 java/ant/src/org/apidesign/infra/ant/GrepCopy.java --- a/java/ant/src/org/apidesign/infra/ant/GrepCopy.java Tue Aug 12 13:47:15 2008 +0200 +++ b/java/ant/src/org/apidesign/infra/ant/GrepCopy.java Sun Aug 17 17:15:52 2008 +0200 @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.net.URL; import java.util.Map.Entry; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; @@ -12,6 +13,7 @@ public class GrepCopy extends Task { private GrepFilter filter = new GrepFilter(); private File dir; + private URL url; public GrepCopy() { } @@ -23,6 +25,10 @@ public void setTarget(File dir) { this.dir = dir; } + + public void setBaseURL(URL url) { + this.url = url; + } @Override public void execute() throws BuildException { @@ -35,11 +41,24 @@ FileWriter w = null; try { Entry en = (Entry) object; - File to = new File(dir, (String) en.getKey()); - to.getParentFile().mkdirs(); - w = new FileWriter(to); - w.write((String) en.getValue()); - w.close(); + String key = (String)en.getKey(); + { + File to = new File(dir, key); + to.getParentFile().mkdirs(); + w = new FileWriter(to); + w.write((String) en.getValue()); + w.close(); + } + + if (url != null) { + URL u = filter.getPath(url, key); + File to = new File(dir, key + ".url"); + to.getParentFile().mkdirs(); + w = new FileWriter(to); + w.write(u.toExternalForm()); + w.close(); + } + } catch (IOException ex) { throw new BuildException(ex); } diff -r cfc5a3fd5ae8 -r e1a7420cea38 java/ant/src/org/apidesign/infra/ant/GrepFilter.java --- a/java/ant/src/org/apidesign/infra/ant/GrepFilter.java Tue Aug 12 13:47:15 2008 +0200 +++ b/java/ant/src/org/apidesign/infra/ant/GrepFilter.java Sun Aug 17 17:15:52 2008 +0200 @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.Stack; @@ -26,6 +28,7 @@ private Pattern begin = Pattern.compile(".* BEGIN: *(\\p{Graph}+)[-\\> ]*"); private Pattern end = Pattern.compile(".* (END|FINISH): *(\\p{Graph}+)[-\\> ]*"); private boolean openoffice; + private Map paths = new HashMap(); public FileSet createFileSet() { @@ -111,6 +114,7 @@ throw new BuildException("Not closed section " + entry.getKey() + " in " + file); } entry.setValue(v.toString()); + paths.put(entry.getKey(), path); } } @@ -136,6 +140,10 @@ FilterSet filter = createFilterSet(); getProject().addReference(id, filter); } + + final URL getPath(URL root, String key) throws MalformedURLException { + return new URL(root, paths.get(key)); + } private String linize(String input) { if (!openoffice) { diff -r cfc5a3fd5ae8 -r e1a7420cea38 java/ant/test/org/apidesign/infra/ant/GrepCopyTest.java --- a/java/ant/test/org/apidesign/infra/ant/GrepCopyTest.java Tue Aug 12 13:47:15 2008 +0200 +++ b/java/ant/test/org/apidesign/infra/ant/GrepCopyTest.java Sun Aug 17 17:15:52 2008 +0200 @@ -81,6 +81,31 @@ assertEquals("public interface I {\n}\n", r); } + public void testURLGenerated() throws Exception { + String c1 = + "package ahoj;\n" + + "// BEGIN: xyz\n" + + "public interface I {\n" + + "// FINISH: xyz\n" + + " public void get();\n" + + "}" + + ""; + File src = createFile(1, "I.java", c1); + + + String c2 = + "@xyz@"; + File txt = createFile(2, "in.txt", c2); + + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.java", "-Dout.url=http://xyz/", "url"); + + String r = readFile("xyz"); + assertEquals("public interface I {\n}\n", r); + + String u = readFile("xyz.url"); + assertEquals("http://xyz/I.java", u); + } + public void testSpacesAtBeginingAreStripped() throws Exception { String c1 = "package ahoj;\n" + diff -r cfc5a3fd5ae8 -r e1a7420cea38 java/ant/test/org/apidesign/infra/ant/copy.xml --- a/java/ant/test/org/apidesign/infra/ant/copy.xml Tue Aug 12 13:47:15 2008 +0200 +++ b/java/ant/test/org/apidesign/infra/ant/copy.xml Sun Aug 17 17:15:52 2008 +0200 @@ -1,9 +1,9 @@ + + + - - - @@ -11,4 +11,11 @@ + + + + + + + diff -r cfc5a3fd5ae8 -r e1a7420cea38 samples/build.xml --- a/samples/build.xml Tue Aug 12 13:47:15 2008 +0200 +++ b/samples/build.xml Sun Aug 17 17:15:52 2008 +0200 @@ -55,7 +55,7 @@ - + diff -r cfc5a3fd5ae8 -r e1a7420cea38 samples/libs/build.xml.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/libs/build.xml.orig Sun Aug 17 17:15:52 2008 +0200 @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +