2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.nbbuild;
47
import org.apache.tools.ant.* ;
48
import org.apache.tools.ant.taskdefs.* ;
49
import org.apache.tools.ant.types.FileSet;
50
import org.apache.tools.ant.types.Path;
52
/** This task runs the JHIndexer task multiple times, once for each
53
* language, and automatically creates the appropriate regular
54
* expressions to choose the files for each language. This task
55
* greatly reduces the amount of Ant code required to run JHIndexer
56
* especially when there are helpsets for multiple languages in the
57
* same directory tree.
59
* @author Jerry Huth (email: jerry@solidstep.com)
61
public class LocJHIndexer extends MatchingTask {
63
protected File basedir = null ;
64
protected String dbdir = null ;
65
protected String locales = null ;
66
protected String jhall = null ;
68
/** Specify a regular expression to find <samp>jhall.jar</samp>
69
* (JavaHelp tools library).
71
public void setJhall( String jhall) {
75
/** Get the jhall jar file to use. */
76
protected String getJhall() {
80
// Use the attribute if specified. //
86
// Else look for the global property. //
87
prop = getProject().getProperty("locjhindexer.jhall");
96
/** Set the location of the docs helpsets' base dir. */
97
public void setBasedir( File dir) {
101
/** Set the name of the search database directory (which is under
102
* <samp>basedir/<locale></samp>)
104
public void setDbdir( String dir) {
108
/** Set a comma-separated list of locales which have helpsets. */
109
public void setLocales( String s) {
113
/** Get the locales for which we'll look for helpsets. */
114
protected String getLocales() {
115
if( locales != null) {
118
return(getProject().getProperty("locjhindexer.locales"));
121
public void execute() throws BuildException {
122
String locs = getLocales() ;
123
String helpset_locs = null ;
124
StringTokenizer tokenizer = null ;
127
if( getJhall() == null)
128
throw new BuildException( "Must specify the jhall attribute") ;
129
if( dbdir == null || dbdir.trim().equals( ""))
130
throw new BuildException( "Must specify the dbdir attribute") ;
132
throw new BuildException( "Must specify the basedir attribute") ;
133
if( locs == null || locs.trim().equals( ""))
134
throw new BuildException( "Must specify the locales attribute") ;
136
// I couldn't get it to work unless I explicitly added the task def here. //
137
getProject().addTaskDefinition("jhindexer", JHIndexer.class);
139
// For each locale. //
140
tokenizer = new StringTokenizer( locs, ", ") ;
141
while( tokenizer.hasMoreTokens()) {
142
loc = tokenizer.nextToken() ;
144
// If there's a helpset for this locale. //
145
if( hasHelpset( loc)) {
147
// Add it to the list of locales that have helpsets. //
148
if( helpset_locs == null) {
149
helpset_locs = new String( loc) ;
152
helpset_locs += "," + loc ;
157
// For each locale. //
158
if( helpset_locs != null) {
159
tokenizer = new StringTokenizer( helpset_locs, ", ") ;
160
while( tokenizer.hasMoreTokens()) {
161
loc = tokenizer.nextToken() ;
163
// Run the JHIndexer for this locale. //
169
/** See if there's a helpset for this locale. */
170
protected boolean hasHelpset( String loc) {
171
boolean ret = false ;
172
LocHelpsetFilter filter = new LocHelpsetFilter( loc) ;
175
files = basedir.listFiles( filter) ;
176
if( files != null && files.length > 0) {
183
// Run JHIndexer for the given locale. //
184
protected void RunForLocale( String locale) throws BuildException {
185
JHIndexer jhindexer ;
187
jhindexer = (JHIndexer) getProject().createTask("jhindexer");
190
jhindexer.setIncludes( locale + "/**/*.htm*") ;
191
jhindexer.setExcludes( locale + "/" + dbdir + "/" + "," +
192
locale + "/credits.htm*") ;
193
jhindexer.setBasedir( new File( basedir + "/")) ;
194
jhindexer.setDb( new File( basedir + "/" + locale + "/" + dbdir)) ;
195
jhindexer.setLocale( locale) ;
196
setJHLib( jhindexer) ;
198
jhindexer.execute() ;
201
protected void setJHLib( JHIndexer jhindexer) {
202
String jhlib, dir, regexp ;
206
LinkedList<String> dirs, regexps ;
210
// For each regular expression. //
211
dirs = new LinkedList<String>() ;
212
regexps = new LinkedList<String>() ;
214
st = new StringTokenizer( jhlib, " \n,") ;
215
while( st.hasMoreTokens()) {
216
regexp = st.nextToken() ;
218
// Break the regular expression up into directory and file //
220
idx = regexp.lastIndexOf( "/") ;
221
dir = regexp.substring( 0, idx) ;
222
file = new File( dir) ;
225
regexps.add( regexp.substring( idx+1)) ;
229
if( dirs.size() > 0) {
230
path = jhindexer.createClasspath() ;
231
for( i = 0; i < dirs.size(); i++) {
233
regexp = regexps.get( i) ;
235
fs.setDir( new File( dir)) ;
236
fs.setIncludes( regexp) ;
237
path.addFileset( fs) ;
241
throw new BuildException( "jhall not found.") ;
245
protected class LocHelpsetFilter implements FilenameFilter {
246
protected String locale = null ;
248
public LocHelpsetFilter( String loc) {
252
public boolean accept(File dir,
254
return( name.endsWith( "_" + locale + ".hs")) ;