r1570 - in branches/jaxx-2.X/maven-jaxx-plugin/src/main: java/org/nuiton/jaxx/plugin resources
Author: tchemit Date: 2009-10-08 23:10:15 +0200 (Thu, 08 Oct 2009) New Revision: 1570 Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm Log: generate help search index (still does not works everywhere, a shame the code is from com.sun we do not have the source...) Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-10-08 19:10:44 UTC (rev 1569) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-10-08 21:10:15 UTC (rev 1570) @@ -18,18 +18,26 @@ *##%*/ package org.nuiton.jaxx.plugin; +import com.sun.java.help.search.Indexer; import java.io.BufferedReader; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import org.apache.maven.plugin.MojoFailureException; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; +import java.io.PrintStream; +import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Locale; import java.util.Properties; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; import org.nuiton.i18n.I18n; import org.nuiton.util.FileUtil; import org.nuiton.util.SortedProperties; @@ -82,7 +90,7 @@ /** * The template used to generate helpset file. * - * Must be an existing file or a ressource in classp-ath + * Must be an existing file or a ressource in class-path * * @parameter expression="${jaxx.helpsetTemplate}" default-value="/defaultHelpSet.hs.vm" * @required @@ -93,7 +101,7 @@ /** * The template used to generate helpset map file. * - * Must be an existing file or a ressource in classp-ath + * Must be an existing file or a ressource in class-path * * @parameter expression="${jaxx.mapTemplate}" default-value="/defaultMap.jhm.vm" * @required @@ -104,7 +112,7 @@ /** * The template used to generate helpset index file. * - * Must be an existing file or a ressource in classp-ath + * Must be an existing file or a ressource in class-path * * @parameter expression="${jaxx.indexTemplate}" default-value="/defaultIndex.xml.vm" * @required @@ -115,7 +123,7 @@ /** * The template used to generate helpset toc file. * - * Must be an existing file or a ressource in classp-ath + * Must be an existing file or a ressource in class-path * * @parameter expression="${jaxx.tocTemplate}" default-value="/defaultToc.xml.vm" * @required @@ -126,7 +134,7 @@ /** * The template used to generate helpset content file. * - * Must be an existing file or a ressource in classp-ath + * Must be an existing file or a ressource in class-path * * @parameter expression="${jaxx.contentTemplate}" default-value="/defaultContent.html.vm" * @required @@ -135,6 +143,15 @@ */ protected File contentTemplate; /** + * Flag to generate the search index. + * + * @parameter expression="${jaxx.generateSearch}" default-value="true" + * @required + * + * @since 1.3 + */ + protected boolean generateSearch; + /** * The help ids discovered in {@link #helpIdsStore} files. */ private Properties helpIds; @@ -192,7 +209,7 @@ } // load ids from idsStore file - + helpIds = new SortedProperties(); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(idsStore), getEncoding())); @@ -255,7 +272,7 @@ env.put("mapFileName", mapFileName); env.put("indexFileName", indexFileName); env.put("tocFileName", tocFileName); -// env.put("searchData", localePath + "/index"); + env.put("generateSearch", generateSearch); // --------------------------------------------------------------- // --- main helpset file ----------------------------------------- @@ -275,7 +292,7 @@ file = new File(localizedTarget, mapFileName); - Properties mergedHelpIds = generateMapFile(file, env); + generateMapFile(file, env); touchedFiles++; // --------------------------------------------------------------- @@ -284,7 +301,7 @@ file = new File(localizedTarget, indexFileName); - NodeItem indexRootItem = generateIndexFile(file, env); + generateIndexFile(file, env); touchedFiles++; // --------------------------------------------------------------- @@ -293,7 +310,7 @@ file = new File(localizedTarget, tocFileName); - NodeItem tocRootItem = generateTocFile(file, env); + generateTocFile(file, env); touchedFiles++; // --------------------------------------------------------------- @@ -302,6 +319,16 @@ touchedFiles += generateContentFiles(localizedTarget, env, localePath); + // --------------------------------------------------------------- + // --- generate search index ------------------------------------- + // --------------------------------------------------------------- + + if (generateSearch) { + + generateSearchIndex(localizedTarget, locale); + } + + } getLog().info(touchedFiles + " file(s) treated."); @@ -475,6 +502,35 @@ return rootItem; } + protected void generateSearchIndex(File localizedTarget, Locale locale) throws IllegalArgumentException, IOException, InvocationTargetException, SecurityException, IllegalAccessException, NoSuchMethodException { + + Method m = Indexer.class.getDeclaredMethod("main", String[].class); + File indexDir = new File(localizedTarget, "JavaHelpSearch"); + // remove old index + FileUtils.deleteDirectory(indexDir); + //copy resources to a tmp dir (without any VCS infos) + File tmpDir = new File(project.getBasedir(), "target" + File.separator + "jaxx-tmp" + File.separator + "indexer-" + locale + "-" + System.nanoTime()); + getLog().info("copy files to " + tmpDir + " for indexing them"); + FileUtils.copyDirectory(localizedTarget, tmpDir, "**/*", StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ",")); + List<String> params = new ArrayList<String>(); + params.add("-verbose"); + params.add("-db"); + params.add(indexDir.getAbsolutePath()); + params.add("-logfile"); + File logFile = new File(project.getBasedir(), "target" + File.separator + "generated-sources" + File.separator + "jaxx" + File.separator + "indexer-" + locale + ".log"); + params.add(logFile.getAbsolutePath()); + params.add(tmpDir.getAbsolutePath()); + PrintStream out = System.out; + PrintStream err = System.err; + try { + m.invoke(null, (Object) params.toArray(new String[params.size()])); + } finally { + System.setOut(out); + System.setErr(err); + } + getLog().info("Search Index generated"); + } + protected NodeItem generateTocFile(File file, Properties env) throws Exception { NodeItem rootItem = null; Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-10-08 19:10:44 UTC (rev 1569) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-10-08 21:10:15 UTC (rev 1570) @@ -386,7 +386,7 @@ return; } - getLog().info("Detects " + files.length + " modify jaxx file(s). "); + getLog().info("Detects " + files.length + " modified jaxx file(s). "); try { Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm 2009-10-08 19:10:44 UTC (rev 1569) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm 2009-10-08 21:10:15 UTC (rev 1570) @@ -31,13 +31,13 @@ <data>$localePath/$indexFileName</data> </view> -#if ( $searchData ) +#if ( $generateSearch ) <view> <name>Search</name> <label>Search</label> <type>javax.help.SearchView</type> <data engine="com.sun.java.help.search.DefaultSearchEngine"> - $searchData + $localePath/JavaHelpSearch </data> </view> #end
participants (1)
-
tchemit@users.nuiton.org