You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2007/10/25 15:07:47 UTC
svn commit: r588222 [1/2] - in
/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src:
main/java/org/apache/maven/jxr/java/src/
test/java/org/apache/maven/jxr/java/src/
Author: vsiveton
Date: Thu Oct 25 06:07:38 2007
New Revision: 588222
URL: http://svn.apache.org/viewvc?rev=588222&view=rev
Log:
o added Javasrc class with main to encapsulate pass1 and pass2
o removed main method in pass classes
o added abstract class for pass classes
o added options class to wrap all Javasrc options
o updated test case
Added:
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java (with props)
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java (with props)
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java (with props)
Modified:
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcTask.java
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/Pass1.java
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/Pass2.java
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/test/java/org/apache/maven/jxr/java/src/JavaSrcTaskTest.java
Added: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java?rev=588222&view=auto
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java (added)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java Thu Oct 25 06:07:38 2007
@@ -0,0 +1,124 @@
+package org.apache.maven.jxr.java.src;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.util.StringTokenizer;
+
+/**
+ * Abstract class for Pass.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public abstract class AbstractPass
+{
+ protected static final String DEFAULT_EXCLUDES = "**/*~,**/#*#,**/.#*,**/%*%,**/._*,**/CVS,**/CVS/**,"
+ + "**/.cvsignore,**/SCCS,**/SCCS/**,**/vssver.scc,**/.svn,**/.svn/**,**/.DS_Store";
+
+ private JavaSrcOptions options;
+
+ /**
+ * Default constructor
+ *
+ * @param options object
+ */
+ public AbstractPass( JavaSrcOptions options )
+ {
+ if ( options == null )
+ {
+ throw new IllegalArgumentException( "options could not be null" );
+ }
+ this.options = options;
+ }
+
+ /**
+ * @return the output dir
+ * @see JavaSrcOptions#getDestDir()
+ */
+ protected String getDestDir()
+ {
+ return this.options.getDestDir();
+ }
+
+ /**
+ * @return the source dir
+ * @see JavaSrcOptions#getSrcDir()
+ */
+ protected String getSrcDir()
+ {
+ return this.options.getSrcDir();
+ }
+
+ /**
+ * Getter for the javasrc options
+ *
+ * @return the options
+ */
+ protected JavaSrcOptions getOptions()
+ {
+ return this.options;
+ }
+
+ /**
+ * Returns the path to the top level of the source hierarchy from the files
+ * og\f a given class.
+ *
+ * @param packageName the package to get the backup path for
+ * @return
+ * @returns the path from the package to the top level, as a string
+ */
+ protected static String getBackupPath( String packageName )
+ {
+ StringTokenizer st = new StringTokenizer( packageName, "." );
+ String backup = "";
+ int dirs = 0;
+
+ dirs = st.countTokens();
+ for ( int j = 0; j < dirs; j++ )
+ {
+ backup = backup + "../";
+ }
+
+ return backup;
+ }
+
+ protected static void println( String description )
+ {
+ System.out.print( "\n" );
+ System.out.print( description );
+ }
+
+ /**
+ * Method createDirs
+ *
+ * @param f
+ */
+ protected static void createDirs( File f )
+ {
+ String parentDir = f.getParent();
+ File directory = new File( parentDir );
+
+ if ( !directory.exists() )
+ {
+ directory.mkdirs();
+ }
+ }
+}
Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/AbstractPass.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java?rev=588222&view=auto
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java (added)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java Thu Oct 25 06:07:38 2007
@@ -0,0 +1,370 @@
+package org.apache.maven.jxr.java.src;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Creates a set of HTML pages out of Java source code.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class JavaSrc
+{
+ /** Field USAGE */
+ public static final String USAGE = "Usage: java " + JavaSrcOptions.getOptions() + "\n " + JavaSrc.class.getName();
+
+ /**
+ * Default location for css
+ */
+ private static final String DEFAULT_CSS_NAME = "styles.css";
+
+ private static final String RESOURCE_CSS_DIR = "org/apache/maven/jxr/java/src/css";
+
+ private JavaSrcOptions options = JavaSrcOptions.getInstance();
+
+ /**
+ * Private constructor
+ */
+ private JavaSrc()
+ {
+ // nop
+ }
+
+ /**
+ * Default constructor
+ *
+ * @param srcDir the source directory
+ * @param destDir the output directoy
+ * @throws IllegalArgumentException if any
+ */
+ public JavaSrc( File srcDir, File destDir )
+ {
+ setSrcDir( srcDir );
+ setDestDir( destDir );
+ }
+
+ /**
+ * @return the output dir
+ * @see JavaSrcOptions#getDestDir()
+ */
+ public File getDestDir()
+ {
+ return new File( this.options.getDestDir() );
+ }
+
+ /**
+ * @return the source dir
+ * @see JavaSrcOptions#getSrcDir()
+ */
+ public File getSrcDir()
+ {
+ return new File( this.options.getSrcDir() );
+ }
+
+ /**
+ * Getter for the options
+ *
+ * @return the options
+ */
+ public JavaSrcOptions getOptions()
+ {
+ return this.options;
+ }
+
+ /**
+ * Main entry point for JavaSrc.
+ *
+ * @param args CLI arguments.
+ */
+ public static void main( String[] args )
+ {
+ JavaSrc main = new JavaSrc();
+
+ try
+ {
+ main.initializeRequiredOptions();
+ main.initializeOptionalOptions();
+ }
+ catch ( IllegalArgumentException e )
+ {
+ System.out.println( "Error when parsing options:" );
+ System.out.println( USAGE );
+ return;
+ }
+
+ try
+ {
+ main.pass();
+ }
+ catch ( IOException e )
+ {
+ System.out.println( "IOException: " + e.getMessage() );
+ }
+ catch ( OutOfMemoryError e )
+ {
+ System.out.println( "Out Of Memory: add JVM property -Xms=**m and -Xmx=**m" );
+ }
+ catch ( Throwable t )
+ {
+ t.printStackTrace();
+ }
+ }
+
+ /**
+ * @throws IOException if any
+ */
+ public void pass()
+ throws IOException
+ {
+ Pass1 p1 = new Pass1( getOptions() );
+ p1.run();
+
+ Pass2 p2 = new Pass2( getOptions() );
+ p2.run();
+
+ copyDefaultStylesheet( getDestDir() );
+ }
+
+ // ----------------------------------------------------------------------
+ // private methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Setter for the destDir
+ *
+ * @param destDir the destDir to set
+ * @throws IllegalArgumentException if any
+ */
+ private void setDestDir( File destDir )
+ {
+ if ( destDir == null )
+ {
+ throw new IllegalArgumentException( "destDir is required." );
+ }
+ if ( destDir.exists() && !destDir.isDirectory() )
+ {
+ throw new IllegalArgumentException( "Dest directory is a file." );
+ }
+ if ( !destDir.exists() && !destDir.mkdirs() )
+ {
+ throw new IllegalArgumentException( "Cannot create the dest directory." );
+ }
+
+ getOptions().setDestDir( destDir.getAbsolutePath() );
+ }
+
+ /**
+ * Setter for the srcDir
+ *
+ * @param srcDir the srcDir to set
+ * @throws IllegalArgumentException if any
+ */
+ private void setSrcDir( File srcDir )
+ {
+ if ( srcDir == null )
+ {
+ throw new IllegalArgumentException( "srcDir is required." );
+ }
+ if ( !srcDir.exists() )
+ {
+ throw new IllegalArgumentException( "srcDir doesn't exist." );
+ }
+ if ( !srcDir.isDirectory() )
+ {
+ throw new IllegalArgumentException( "srcDir is not a directory." );
+ }
+
+ getOptions().setSrcDir( srcDir.getAbsolutePath() );
+ }
+
+ /**
+ * Initialize required fields
+ *
+ * @throws IllegalArgumentException if any
+ * @see JavaSrc#main(String[])
+ */
+ private void initializeRequiredOptions()
+ {
+ String srcDir = System.getProperty( "srcDir" );
+ if ( StringUtils.isEmpty( srcDir ) )
+ {
+ throw new IllegalArgumentException( "srcDir should be not null" );
+ }
+ setSrcDir( new File( srcDir ) );
+
+ String destDir = System.getProperty( "destDir" );
+ if ( StringUtils.isEmpty( destDir ) )
+ {
+ throw new IllegalArgumentException( "destDir should be not null" );
+ }
+ setDestDir( new File( destDir ) );
+ }
+
+ /**
+ * Initialize optional fields
+ *
+ * @throws IllegalArgumentException if any
+ * @see JavaSrc#main(String[])
+ */
+ private void initializeOptionalOptions()
+ {
+ String bottom = System.getProperty( "bottom" );
+ if ( StringUtils.isNotEmpty( bottom ) )
+ {
+ getOptions().setBottom( bottom );
+ }
+
+ String docencoding = System.getProperty( "docencoding" );
+ if ( StringUtils.isNotEmpty( docencoding ) )
+ {
+ getOptions().setDocencoding( docencoding );
+ }
+
+ String doctitle = System.getProperty( "doctitle" );
+ if ( StringUtils.isNotEmpty( doctitle ) )
+ {
+ getOptions().setDoctitle( doctitle );
+ }
+
+ String encoding = System.getProperty( "encoding" );
+ if ( StringUtils.isNotEmpty( encoding ) )
+ {
+ getOptions().setEncoding( encoding );
+ }
+
+ String footer = System.getProperty( "footer" );
+ if ( StringUtils.isNotEmpty( footer ) )
+ {
+ getOptions().setFooter( footer );
+ }
+
+ String header = System.getProperty( "header" );
+ if ( StringUtils.isNotEmpty( header ) )
+ {
+ getOptions().setHeader( header );
+ }
+
+ String packagesheader = System.getProperty( "packagesheader" );
+ if ( StringUtils.isNotEmpty( packagesheader ) )
+ {
+ getOptions().setPackagesheader( packagesheader );
+ }
+
+ String recurseStr = System.getProperty( "recurse" );
+ if ( recurseStr != null )
+ {
+ recurseStr = recurseStr.trim();
+ if ( recurseStr.equalsIgnoreCase( "off" ) || recurseStr.equalsIgnoreCase( "false" )
+ || recurseStr.equalsIgnoreCase( "no" ) || recurseStr.equalsIgnoreCase( "0" ) )
+ {
+ getOptions().setRecurse( false );
+ }
+ }
+
+ String stylesheetfile = System.getProperty( "stylesheetfile" );
+ if ( StringUtils.isNotEmpty( stylesheetfile ) )
+ {
+ getOptions().setStylesheetfile( stylesheetfile );
+ }
+
+ String top = System.getProperty( "top" );
+ if ( StringUtils.isNotEmpty( top ) )
+ {
+ getOptions().setTop( top );
+ }
+
+ String verboseStr = System.getProperty( "verbose" );
+ if ( verboseStr != null )
+ {
+ verboseStr = verboseStr.trim();
+ if ( verboseStr.equalsIgnoreCase( "on" ) || verboseStr.equalsIgnoreCase( "true" )
+ || verboseStr.equalsIgnoreCase( "yes" ) || verboseStr.equalsIgnoreCase( "1" ) )
+ {
+ getOptions().setVerbose( true );
+ }
+ }
+
+ String windowtitle = System.getProperty( "windowtitle" );
+ if ( StringUtils.isNotEmpty( windowtitle ) )
+ {
+ getOptions().setWindowtitle( windowtitle );
+ }
+ }
+
+ /**
+ * Method that copy the <code>DEFAULT_STYLESHEET_NAME</code> file from the current class
+ * loader to the <code>outputDirectory</code>.
+ *
+ * @param outputDirectory the output directory
+ * @throws IOException if any
+ * @see #DEFAULT_CSS_NAME
+ */
+ private void copyDefaultStylesheet( File outputDirectory )
+ throws IOException
+ {
+ if ( outputDirectory == null || !outputDirectory.exists() )
+ {
+ throw new IOException( "The outputDirectory " + outputDirectory + " doesn't exists." );
+ }
+
+ InputStream is = getStream( RESOURCE_CSS_DIR + "/" + DEFAULT_CSS_NAME );
+
+ if ( is == null )
+ {
+ throw new IOException( "The resource " + DEFAULT_CSS_NAME + " doesn't exists." );
+ }
+
+ File outputFile = new File( outputDirectory, DEFAULT_CSS_NAME );
+
+ if ( !outputFile.getParentFile().exists() )
+ {
+ outputFile.getParentFile().mkdirs();
+ }
+
+ FileOutputStream w = new FileOutputStream( outputFile );
+
+ IOUtil.copy( is, w );
+
+ IOUtil.close( is );
+
+ IOUtil.close( w );
+ }
+
+ /**
+ * Returns an input stream for reading the specified resource from the
+ * current class loader.
+ *
+ * @param resource the resource
+ * @return InputStream An input stream for reading the resource, or <tt>null</tt>
+ * if the resource could not be found
+ */
+ private InputStream getStream( String resource )
+ {
+ return getClass().getClassLoader().getResourceAsStream( resource );
+ }
+}
Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrc.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java?rev=588222&view=auto
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java (added)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java Thu Oct 25 06:07:38 2007
@@ -0,0 +1,437 @@
+package org.apache.maven.jxr.java.src;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.lang.reflect.Field;
+
+/**
+ * Bean with all options supported by <code>JavaSrc</code> class.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class JavaSrcOptions
+{
+ /** Singleton pattern */
+ private static JavaSrcOptions singleton;
+
+ /** Specifies the text to be placed at the bottom of each output file. */
+ private String bottom;
+
+ /** Output dir, required. */
+ private String destDir;
+
+ /** Specifies the encoding of the generated HTML files. */
+ private String docencoding;
+
+ /** Specifies the title to be placed near the top of the overview summary file. */
+ private String doctitle;
+
+ /** Source file encoding name. */
+ private String encoding;
+
+ /** Specifies the footer text to be placed at the bottom of each output file. */
+ private String footer;
+
+ /** Specifies the header text to be placed at the top of each output file. */
+ private String header;
+
+ /** Specifies the text for upper left frame. */
+ private String packagesheader;
+
+ /** Specify recursive pass, true by default. */
+ private boolean recurse = true;
+
+ /** Source dir, required. */
+ private String srcDir;
+
+ /** Specifies the path of an alternate HTML stylesheet file. */
+ private String stylesheetfile;
+
+ /** Specifies the top text to be placed at the top of each output file. */
+ private String top;
+
+ /** Specify verbose information */
+ private boolean verbose;
+
+ /** Specifies the title to be placed in the HTML title tag. */
+ private String windowtitle;
+
+ // TODO add no* options a la javadoc
+
+ private JavaSrcOptions()
+ {
+ // nop
+ }
+
+ /**
+ * @return a singleton instance of <code>Configuration</code>.
+ */
+ public static JavaSrcOptions getInstance()
+ {
+ if ( singleton == null )
+ {
+ singleton = new JavaSrcOptions();
+ }
+
+ return singleton;
+ }
+
+ /**
+ * @return all required and optional options
+ */
+ public static String getOptions()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ // Required options
+ sb.append( "-DsrcDir=... " );
+ sb.append( "-DdestDir=... " );
+ sb.append( "\n" );
+
+ // Optional options
+ Field[] fields = JavaSrcOptions.class.getDeclaredFields();
+ for ( int i = 0; i < fields.length; i++ )
+ {
+ String name = fields[i].getName();
+ if ( ( name.indexOf( "class" ) != -1 ) || ( name.indexOf( "singleton" ) != -1 )
+ || ( name.equals( "destDir" ) || name.equals( "srcDir" ) ) )
+ {
+ continue;
+ }
+
+ sb.append( " " );
+ sb.append( "[-D" );
+ sb.append( fields[i].getName() );
+ sb.append( "=..." );
+ sb.append( "]" );
+
+ if ( ( i + 1 ) < fields.length - 1 )
+ {
+ sb.append( "\n" );
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Getter for the bottom
+ *
+ * @return the bottom
+ */
+ public String getBottom()
+ {
+ return this.bottom;
+ }
+
+ /**
+ * Getter for the destDir
+ *
+ * @return the destDir
+ */
+ public String getDestDir()
+ {
+ return this.destDir;
+ }
+
+ /**
+ * Getter for the docencoding
+ *
+ * @return the docencoding
+ */
+ public String getDocencoding()
+ {
+ return this.docencoding;
+ }
+
+ /**
+ * Getter for the doctitle
+ *
+ * @return the doctitle
+ */
+ public String getDoctitle()
+ {
+ return this.doctitle;
+ }
+
+ /**
+ * Getter for the encoding
+ *
+ * @return the encoding
+ */
+ public String getEncoding()
+ {
+ return encoding;
+ }
+
+ /**
+ * Getter for the footer
+ *
+ * @return the footer
+ */
+ public String getFooter()
+ {
+ return this.footer;
+ }
+
+ /**
+ * Getter for the header
+ *
+ * @return the header
+ */
+ public String getHeader()
+ {
+ return this.header;
+ }
+
+ /**
+ * Getter for the packagesheader
+ *
+ * @return the packagesheader
+ */
+ public String getPackagesheader()
+ {
+ return this.packagesheader;
+ }
+
+ /**
+ * Getter for the srcDir
+ *
+ * @return the srcDir
+ */
+ public String getSrcDir()
+ {
+ return srcDir;
+ }
+
+ /**
+ * Getter for the stylesheetfile
+ *
+ * @return the stylesheetfile
+ */
+ public String getStylesheetfile()
+ {
+ return this.stylesheetfile;
+ }
+
+ /**
+ * Getter for the top
+ *
+ * @return the top
+ */
+ public String getTop()
+ {
+ return this.top;
+ }
+
+ /**
+ * Getter for the windowtitle
+ *
+ * @return the windowtitle
+ */
+ public String getWindowtitle()
+ {
+ return this.windowtitle;
+ }
+
+ /**
+ * Getter for the recurse
+ *
+ * @return the recurse
+ */
+ public boolean isRecurse()
+ {
+ return recurse;
+ }
+
+ /**
+ * Getter for the verbose
+ *
+ * @return the verbose
+ */
+ public boolean isVerbose()
+ {
+ return verbose;
+ }
+
+ /**
+ * Setter for the bottom
+ *
+ * @param bottom the bottom to set
+ */
+ public void setBottom( String bottom )
+ {
+ this.bottom = bottom;
+ }
+
+ /**
+ * Setter for the destDir
+ *
+ * @param destDir the destDir to set
+ */
+ public void setDestDir( String destDir )
+ {
+ this.destDir = destDir;
+ }
+
+ /**
+ * Setter for the docencoding
+ *
+ * @param docencoding the docencoding to set
+ */
+ public void setDocencoding( String docencoding )
+ {
+ this.docencoding = docencoding;
+ }
+
+ /**
+ * Setter for the doctitle
+ *
+ * @param doctitle the doctitle to set
+ */
+ public void setDoctitle( String doctitle )
+ {
+ this.doctitle = doctitle;
+ }
+
+ /**
+ * Setter for the encoding
+ *
+ * @param encoding the encoding to set
+ */
+ public void setEncoding( String encoding )
+ {
+ this.encoding = encoding;
+ }
+
+ /**
+ * Setter for the footer
+ *
+ * @param footer the footer to set
+ */
+ public void setFooter( String footer )
+ {
+ this.footer = footer;
+ }
+
+ /**
+ * Setter for the header
+ *
+ * @param header the header to set
+ */
+ public void setHeader( String header )
+ {
+ this.header = header;
+ }
+
+ /**
+ * Setter for the packagesheader
+ *
+ * @param packagesheader the packagesheader to set
+ */
+ public void setPackagesheader( String packagesheader )
+ {
+ this.packagesheader = packagesheader;
+ }
+
+ /**
+ * Setter for the recurse
+ *
+ * @param recurse the recurse to set
+ */
+ public void setRecurse( boolean recurse )
+ {
+ this.recurse = recurse;
+ }
+
+ /**
+ * Setter for the srcDir
+ *
+ * @param srcDir the srcDir to set
+ */
+ public void setSrcDir( String srcDir )
+ {
+ this.srcDir = srcDir;
+ }
+
+ /**
+ * Setter for the stylesheetfile
+ *
+ * @param stylesheetfile the stylesheetfile to set
+ */
+ public void setStylesheetfile( String stylesheetfile )
+ {
+ this.stylesheetfile = stylesheetfile;
+ }
+
+ /**
+ * Setter for the top
+ *
+ * @param top the top to set
+ */
+ public void setTop( String top )
+ {
+ this.top = top;
+ }
+
+ /**
+ * Setter for the verbose
+ *
+ * @param verbose the verbose to set
+ */
+ public void setVerbose( boolean verbose )
+ {
+ this.verbose = verbose;
+ }
+
+ /**
+ * Setter for the windowtitle
+ *
+ * @param windowtitle the windowtitle to set
+ */
+ public void setWindowtitle( String windowtitle )
+ {
+ this.windowtitle = windowtitle;
+ }
+
+ /** {@inheritDoc} */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "Configuration[" );
+ buffer.append( " bottom = " ).append( bottom );
+ buffer.append( " destDir = " ).append( destDir );
+ buffer.append( " docencoding = " ).append( docencoding );
+ buffer.append( " doctitle = " ).append( doctitle );
+ buffer.append( " encoding = " ).append( encoding );
+ buffer.append( " footer = " ).append( footer );
+ buffer.append( " header = " ).append( header );
+ buffer.append( " packagesheader = " ).append( packagesheader );
+ buffer.append( " recurse = " ).append( recurse );
+ buffer.append( " srcDir = " ).append( srcDir );
+ buffer.append( " stylesheetfile = " ).append( stylesheetfile );
+ buffer.append( " top = " ).append( top );
+ buffer.append( " verbose = " ).append( verbose );
+ buffer.append( " windowtitle = " ).append( windowtitle );
+ buffer.append( "]" );
+ return buffer.toString();
+ }
+}
Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcOptions.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcTask.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcTask.java?rev=588222&r1=588221&r2=588222&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcTask.java (original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/JavaSrcTask.java Thu Oct 25 06:07:38 2007
@@ -20,22 +20,13 @@
*/
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.util.FileNameMapper;
-import org.apache.tools.ant.util.GlobPatternMapper;
-import org.apache.tools.ant.util.SourceFileScanner;
-import org.codehaus.plexus.util.IOUtil;
/**
- * Runs the javasrc converter as a task inside
- * the well known build tool "ant" (see ant.apache.org).
+ * Runs the Javasrc converter as an Ant task inside.
*
* @see <a href="http://ant.apache.org">http://ant.apache.org</a>
* @version $Id$
@@ -43,27 +34,47 @@
public class JavaSrcTask
extends MatchingTask
{
- /**
- * Default location for css
- */
- private static final String DEFAULT_CSS_NAME = "styles.css";
+ /** Specifies the text to be placed at the bottom of each output file. */
+ private String bottom;
- private static final String RESOURCE_CSS_DIR = "org/apache/maven/jxr/java/src/css";
+ /** Output dir, required. */
+ private File destDir;
- /** Field srcDir */
- private File srcDir;
+ /** Specifies the encoding of the generated HTML files. */
+ private String docencoding;
- /** Field destDir */
- private File destDir;
+ /** Specifies the title to be placed near the top of the overview summary file. */
+ private String doctitle;
- /** Field recurse */
+ /** Source file encoding name. */
+ private String encoding;
+
+ /** Specifies the footer text to be placed at the bottom of each output file. */
+ private String footer;
+
+ /** Specifies the header text to be placed at the top of each output file. */
+ private String header;
+
+ /** Specifies the text for upper left frame. */
+ private String packagesheader;
+
+ /** Specify recursive pass, true by default. */
private boolean recurse = true;
- /** Field title */
- private String title = "JavaSrc";
+ /** Source dir, required. */
+ private File srcDir;
- /** Field verbose */
- private boolean verbose = false;
+ /** Specifies the path of an alternate HTML stylesheet file. */
+ private String stylesheetfile;
+
+ /** Specifies the top text to be placed at the top of each output file. */
+ private String top;
+
+ /** Specify verbose information */
+ private boolean verbose;
+
+ /** Specifies the title to be placed in the HTML title tag. */
+ private String windowtitle;
/**
* Constructor for JavaSrcTask.
@@ -74,234 +85,322 @@
}
/**
- * Returns the directory where the Java sources are stored.
- *
- * @return String directory name
+ * @throws BuildException
+ * @see org.apache.tools.ant.Task#execute()
*/
- public File getSrcDir()
+ public void execute()
+ throws BuildException
{
- return srcDir;
+ try
+ {
+ JavaSrc javaSrc = new JavaSrc( getSrcDir(), getDestDir() );
+
+ javaSrc.getOptions().setBottom( bottom );
+ javaSrc.getOptions().setDocencoding( docencoding );
+ javaSrc.getOptions().setDoctitle( doctitle );
+ javaSrc.getOptions().setEncoding( encoding );
+ javaSrc.getOptions().setFooter( footer );
+ javaSrc.getOptions().setHeader( header );
+ javaSrc.getOptions().setPackagesheader( packagesheader );
+ javaSrc.getOptions().setRecurse( recurse );
+ javaSrc.getOptions().setStylesheetfile( stylesheetfile );
+ javaSrc.getOptions().setTop( top );
+ javaSrc.getOptions().setVerbose( verbose );
+ javaSrc.getOptions().setWindowtitle( windowtitle );
+
+ javaSrc.pass();
+ }
+ catch ( IllegalArgumentException e )
+ {
+ throw new BuildException( "IllegalArgumentException: " + e.getMessage(), e, getLocation() );
+ }
+ catch ( IOException e )
+ {
+ throw new BuildException( "IOException: " + e.getMessage(), e, getLocation() );
+ }
}
+ // ----------------------------------------------------------------------
+ // Task parameters
+ // ----------------------------------------------------------------------
+
/**
- * Sets the directory where the Java sources are stored.
+ * Getter for the bottom
*
- * @param javaDir directory name
+ * @return the bottom
*/
- public void setSrcDir( File javaDir )
+ public String getBottom()
{
- this.srcDir = javaDir;
+ return this.bottom;
}
/**
- * Returns the directory where the HTML output is written.
+ * Getter for the destDir
*
- * @return String directory name
+ * @return the destDir
*/
public File getDestDir()
{
- return destDir;
+ return this.destDir;
}
/**
- * Sets the directory where the HTML output is written.
+ * Getter for the docencoding
*
- * @param htmlDir directory name
+ * @return the docencoding
*/
- public void setDestDir( File htmlDir )
+ public String getDocencoding()
{
- this.destDir = htmlDir;
+ return this.docencoding;
}
/**
- * @throws BuildException
- * @see org.apache.tools.ant.Task#execute()
+ * Getter for the doctitle
+ *
+ * @return the doctitle
*/
- public void execute()
- throws BuildException
+ public String getDoctitle()
{
- if ( getDestDir() == null )
- {
- throw new BuildException( "Missing mandatory attribute 'dest'.", getLocation() );
- }
- if ( getDestDir().exists() && !getDestDir().isDirectory() )
- {
- throw new BuildException( "Dest directory is a file.", getLocation() );
- }
- if ( !getDestDir().exists() && !getDestDir().mkdirs() )
- {
- throw new BuildException( "Cannot create the dest directory.", getLocation() );
- }
-
- if ( srcDir == null )
- {
- // We directly change the user variable, because it
- // shouldn't lead to problems
- srcDir = this.getProject().resolveFile( "." );
- log( "No src dir specified, using " + srcDir.getAbsolutePath() + " instead of" );
- }
-
- // find the files/directories
- DirectoryScanner dirScanner = getDirectoryScanner( srcDir );
-
- // get a list of files to work on
- String[] allSourceFiles = dirScanner.getIncludedFiles();
- SourceFileScanner sourceScanner = new SourceFileScanner( this );
- FileNameMapper sourceToOutMapper = new GlobPatternMapper();
+ return this.doctitle;
+ }
- sourceToOutMapper.setFrom( "*" );
- sourceToOutMapper.setTo( "*.java" );
+ /**
+ * Getter for the encoding
+ *
+ * @return the encoding
+ */
+ public String getEncoding()
+ {
+ return encoding;
+ }
- String[] sourceFilesToProcess = sourceScanner.restrict( allSourceFiles, srcDir, destDir, sourceToOutMapper );
+ /**
+ * Getter for the footer
+ *
+ * @return the footer
+ */
+ public String getFooter()
+ {
+ return this.footer;
+ }
- if ( sourceFilesToProcess.length > 0 )
- {
- String files = ( ( sourceFilesToProcess.length == 1 ) ? " file" : " files" );
+ /**
+ * Getter for the header
+ *
+ * @return the header
+ */
+ public String getHeader()
+ {
+ return this.header;
+ }
- log( "Converting " + sourceFilesToProcess.length + files, Project.MSG_INFO );
- }
+ /**
+ * Getter for the packagesheader
+ *
+ * @return the packagesheader
+ */
+ public String getPackagesheader()
+ {
+ return this.packagesheader;
+ }
- for ( int i = 0; i < sourceFilesToProcess.length; ++i )
- {
- sourceFilesToProcess[i] = new File( srcDir, sourceFilesToProcess[i] ).getAbsolutePath();
- }
+ /**
+ * Getter for the srcDir
+ *
+ * @return the srcDir
+ */
+ public File getSrcDir()
+ {
+ return this.srcDir;
+ }
- Pass1 p1 = new Pass1();
+ /**
+ * Getter for the stylesheetfile
+ *
+ * @return the stylesheetfile
+ */
+ public String getStylesheetfile()
+ {
+ return this.stylesheetfile;
+ }
- p1.initializeDefaults();
- p1.setDestDir( destDir.getAbsolutePath() );
- p1.setRecurse( recurse );
- p1.setTitle( title );
- p1.setVerbose( verbose );
- p1.run( sourceFilesToProcess );
-
- Pass2 p2 = new Pass2();
-
- p2.initializeDefaults();
- p2.setDestDir( destDir.getAbsolutePath() );
- p2.setTitle( title );
- p2.setVerbose( verbose );
+ /**
+ * Getter for the top
+ *
+ * @return the top
+ */
+ public String getTop()
+ {
+ return this.top;
+ }
- try
- {
- p2.run( new String[] {} );
- copyDefaultStylesheet( getDestDir() );
- }
- catch ( IOException ioe )
- {
- throw new BuildException( ioe );
- }
+ /**
+ * Getter for the windowtitle
+ *
+ * @return the windowtitle
+ */
+ public String getWindowtitle()
+ {
+ return this.windowtitle;
}
/**
- * Method getRecurse
+ * Getter for the recurse
*
- * @return
+ * @return the recurse
*/
- public boolean getRecurse()
+ public boolean isRecurse()
{
return recurse;
}
/**
- * Method setRecurse
+ * Getter for the verbose
*
- * @param recurse
+ * @return the verbose
*/
- public void setRecurse( boolean recurse )
+ public boolean isVerbose()
{
- this.recurse = recurse;
+ return verbose;
}
/**
- * Method getTitle
+ * Setter for the bottom
*
- * @return
+ * @param bottom the bottom to set
*/
- public String getTitle()
+ public void setBottom( String bottom )
{
- return title;
+ this.bottom = bottom;
}
/**
- * Method setTitle
+ * Setter for the destDir
*
- * @param title
+ * @param destDir the destDir to set
*/
- public void setTitle( String title )
+ public void setDestDir( File destDir )
{
- this.title = title;
+ this.destDir = destDir;
}
/**
- * Method getVerbose
+ * Setter for the docencoding
*
- * @return
+ * @param docencoding the docencoding to set
*/
- public boolean getVerbose()
+ public void setDocencoding( String docencoding )
{
- return verbose;
+ this.docencoding = docencoding;
}
/**
- * Method setVerbose
+ * Setter for the doctitle
*
- * @param verbose
+ * @param doctitle the doctitle to set
*/
- public void setVerbose( boolean verbose )
+ public void setDoctitle( String doctitle )
{
- this.verbose = verbose;
+ this.doctitle = doctitle;
}
/**
- * Method that copy the <code>DEFAULT_STYLESHEET_NAME</code> file from the current class
- * loader to the <code>outputDirectory</code>.
+ * Setter for the encoding
*
- * @param outputDirectory the output directory
- * @throws java.io.IOException if any
- * @see #DEFAULT_CSS_NAME
+ * @param encoding the encoding to set
*/
- private void copyDefaultStylesheet( File outputDirectory )
- throws IOException
+ public void setEncoding( String encoding )
{
- if ( outputDirectory == null || !outputDirectory.exists() )
- {
- throw new IOException( "The outputDirectory " + outputDirectory + " doesn't exists." );
- }
+ this.encoding = encoding;
+ }
- InputStream is = getStream( RESOURCE_CSS_DIR + "/" + DEFAULT_CSS_NAME );
+ /**
+ * Setter for the footer
+ *
+ * @param footer the footer to set
+ */
+ public void setFooter( String footer )
+ {
+ this.footer = footer;
+ }
- if ( is == null )
- {
- throw new IOException( "The resource " + DEFAULT_CSS_NAME + " doesn't exists." );
- }
+ /**
+ * Setter for the header
+ *
+ * @param header the header to set
+ */
+ public void setHeader( String header )
+ {
+ this.header = header;
+ }
- File outputFile = new File( outputDirectory, DEFAULT_CSS_NAME );
+ /**
+ * Setter for the packagesheader
+ *
+ * @param packagesheader the packagesheader to set
+ */
+ public void setPackagesheader( String packagesheader )
+ {
+ this.packagesheader = packagesheader;
+ }
- if ( !outputFile.getParentFile().exists() )
- {
- outputFile.getParentFile().mkdirs();
- }
+ /**
+ * Setter for the recurse
+ *
+ * @param recurse the recurse to set
+ */
+ public void setRecurse( boolean recurse )
+ {
+ this.recurse = recurse;
+ }
- FileOutputStream w = new FileOutputStream( outputFile );
+ /**
+ * Setter for the srcDir
+ *
+ * @param srcDir the srcDir to set
+ */
+ public void setSrcDir( File srcDir )
+ {
+ this.srcDir = srcDir;
+ }
- IOUtil.copy( is, w );
+ /**
+ * Setter for the stylesheetfile
+ *
+ * @param stylesheetfile the stylesheetfile to set
+ */
+ public void setStylesheetfile( String stylesheetfile )
+ {
+ this.stylesheetfile = stylesheetfile;
+ }
- IOUtil.close( is );
+ /**
+ * Setter for the top
+ *
+ * @param top the top to set
+ */
+ public void setTop( String top )
+ {
+ this.top = top;
+ }
- IOUtil.close( w );
+ /**
+ * Setter for the verbose
+ *
+ * @param verbose the verbose to set
+ */
+ public void setVerbose( boolean verbose )
+ {
+ this.verbose = verbose;
}
/**
- * Returns an input stream for reading the specified resource from the
- * current class loader.
+ * Setter for the windowtitle
*
- * @param resource the resource
- * @return InputStream An input stream for reading the resource, or <tt>null</tt>
- * if the resource could not be found
+ * @param windowtitle the windowtitle to set
*/
- private InputStream getStream( String resource )
+ public void setWindowtitle( String windowtitle )
{
- return getClass().getClassLoader().getResourceAsStream( resource );
+ this.windowtitle = windowtitle;
}
}
Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/Pass1.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/Pass1.java?rev=588222&r1=588221&r2=588222&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/Pass1.java (original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/src/Pass1.java Thu Oct 25 06:07:38 2007
@@ -19,16 +19,6 @@
* under the License.
*/
-import org.apache.log4j.Logger;
-import org.apache.maven.jxr.java.src.symtab.HTMLTag;
-import org.apache.maven.jxr.java.src.symtab.HTMLTagContainer;
-import org.apache.maven.jxr.java.src.symtab.PackageDef;
-import org.apache.maven.jxr.java.src.symtab.SymbolTable;
-import org.apache.maven.jxr.java.src.util.JSCollections;
-import org.apache.maven.jxr.java.src.util.SkipCRInputStream;
-import org.apache.maven.jxr.java.src.xref.FileListener;
-import org.apache.maven.jxr.java.src.xref.JavaXref;
-
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -39,39 +29,36 @@
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
-import java.util.StringTokenizer;
+import java.util.Iterator;
+import java.util.List;
import java.util.Vector;
+import org.apache.log4j.Logger;
+import org.apache.maven.jxr.java.src.symtab.HTMLTag;
+import org.apache.maven.jxr.java.src.symtab.HTMLTagContainer;
+import org.apache.maven.jxr.java.src.symtab.PackageDef;
+import org.apache.maven.jxr.java.src.symtab.SymbolTable;
+import org.apache.maven.jxr.java.src.util.JSCollections;
+import org.apache.maven.jxr.java.src.util.SkipCRInputStream;
+import org.apache.maven.jxr.java.src.xref.FileListener;
+import org.apache.maven.jxr.java.src.xref.JavaXref;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+import antlr.ANTLRException;
+
/**
* Class Pass1
*
* @version $Id$
*/
public class Pass1
+ extends AbstractPass
implements FileListener
{
- /** Field DEFAULT_DIR */
- public static final String DEFAULT_DIR = ".";
-
- /** Field USAGE */
- public static final String USAGE = "Usage: java [-DdestDir=<doc dir>] [-Dtitle=<title>] [-Dverbose=true] "
- + "[-Drecurse=true] " + Pass1.class.getName() + " <source dir> [<source dir> <source dir> ...]";
-
/** Logger for this class */
private static final Logger log = Logger.getLogger( Pass1.class );
- /** Output dir */
- private String destDir;
-
- /** Title to be placed in the HTML title tag */
- private String title;
-
- /** Specify recursive pass */
- private boolean recurse;
-
- /** Specify verbose information */
- private boolean verbose;
-
int currentColumn;
int currentChar;
@@ -84,80 +71,18 @@
/**
* Constructor Pass1
+ *
+ * @param conf object
*/
- public Pass1()
+ public Pass1( JavaSrcOptions conf )
{
- // nop
+ super( conf );
}
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
- /**
- * @return the output dir
- */
- public String getDestDir()
- {
- return this.destDir;
- }
-
- /**
- * @param d a new output dir
- */
- public void setDestDir( String d )
- {
- this.destDir = d;
- }
-
- /**
- * @return the windows title
- */
- public String getTitle()
- {
- return this.title;
- }
-
- /**
- * @param t a new windows title
- */
- public void setTitle( String t )
- {
- this.title = t;
- }
-
- /**
- * @return recursive pass
- */
- public boolean isRecurse()
- {
- return this.recurse;
- }
-
- /**
- * @param recurse true to do a recursive pass, false otherwise
- */
- public void setRecurse( boolean recurse )
- {
- this.recurse = recurse;
- }
-
- /**
- * @return verbose information
- */
- public boolean isVerbose()
- {
- return this.verbose;
- }
-
- /**
- * @param verbose true to verbose information, false otherwise
- */
- public void setVerbose( boolean verbose )
- {
- this.verbose = verbose;
- }
-
/** {@inheritDoc} */
public void notify( String path )
{
@@ -166,184 +91,98 @@
}
/**
- * Main method to pass Java source files.
- *
- * @param args not null
- * @see #initializeDefaults()
- * @see #run(String[])
- * @throws Exception if any
+ * @throws IOException if any
*/
- public static void main( String args[] )
- throws Exception
- {
- Pass1 p1 = new Pass1();
-
- p1.initializeDefaults();
- p1.run( args );
- }
-
- /**
- * @param args not null
- * @throws IllegalArgumentException if args is null
- */
- public void run( String[] args )
+ public void run()
+ throws IOException
{
- if ( args == null )
- {
- throw new IllegalArgumentException( "args is required" );
- }
-
- // Use a try/catch block for parser exceptions
- try
- {
- // create a new symbol table
- SymbolTable symbolTable = SymbolTable.getSymbolTable();
+ List javaFiles = FileUtils.getFileNames( new File( getSrcDir() ), "**/*.java", DEFAULT_EXCLUDES, true );
- // if we have at least one command-line argument
- if ( args.length > 0 )
- {
- print( "Output dir: " + getDestDir() );
+ // create a new symbol table
+ SymbolTable symbolTable = SymbolTable.getSymbolTable();
- symbolTable.setOutDirPath( getDestDir() );
+ print( "Output dir: " + getDestDir() );
- println( "Parsing" );
+ symbolTable.setOutDirPath( getDestDir() );
- // for each directory/file specified on the command line
- for ( int i = 0; i < args.length; i++ )
- {
- JavaXref.doFile( new File( args[i] ), symbolTable, isRecurse(), this ); // parse it
- }
+ println( "Parsing" );
- println( "Resolving types" );
-
- // resolve the types of all symbols in the symbol table
- symbolTable.resolveTypes();
- symbolTable.resolveRefs();
- }
- else
+ // for each directory/file specified on the command line
+ for ( Iterator it = javaFiles.iterator(); it.hasNext(); )
+ {
+ String file = (String) it.next();
+ try
{
- println( USAGE );
- return;
+ JavaXref.doFile( new File( file ), symbolTable, getOptions().isRecurse(), this ); // parse it
}
-
- // Iterate through each package
- Hashtable packageTable = symbolTable.getPackages();
- Enumeration pEnum = packageTable.elements();
-
- println( "Persisting definitions" );
-
- while ( pEnum.hasMoreElements() )
+ catch ( ANTLRException e )
{
- PackageDef pDef = (PackageDef) pEnum.nextElement();
-
- printAdvancement( "Processing package " + pDef.getName() );
-
- // Generate tags for each package. We cannot do one class
- // at a time because more than one class might be in a
- // single file, and we write out each file only one time.
- HTMLTagContainer tagList = new HTMLTagContainer();
-
- pDef.generateTags( tagList );
-
- Hashtable fileTable = tagList.getFileTable();
- Enumeration enumList = fileTable.keys();
- Vector tempFileTags = new Vector();
-
- while ( enumList.hasMoreElements() )
- {
- tempFileTags.clear();
-
- File f = (File) enumList.nextElement();
-
- if ( inputFiles.contains( f.getAbsolutePath() ) )
- {
- Vector fileTags = (Vector) fileTable.get( f );
-
- tempFileTags.addAll( fileTags );
-
- // Generate the HTML tags for all references in this file
- // I.e. generate HTML mark-up of this .java file
- SymbolTable.createReferenceTags( f, tempFileTags );
- SymbolTable.getCommentTags( f, tempFileTags );
- SymbolTable.getLiteralTags( f, tempFileTags );
- SymbolTable.getKeywordTags( f, tempFileTags );
- createClassFiles( tempFileTags );
- }
- }
-
- // Create reference files
- // I.e. generate HTML mark-up of all definitions in this package's .java files
- // (no longer -- this happens in Pass2 now)
- // System.out.println("\nWriting definition HTML...");
- // pDef.generateReferenceFiles(getOutDir());
- pDef.persistDefinitions( getDestDir() );
+ throw new IOException( "ANTLRException: " + e.getMessage() );
}
-
- println( "Persisting references" );
-
- symbolTable.persistRefs( getDestDir() );
}
- catch ( Exception e )
- {
- log.error( "Exception: " + e.getMessage(), e );
- //System.exit(1); // make this behavior an option?
- }
- }
- /**
- * Initialize defaults fields
- */
- public void initializeDefaults()
- {
- String outdir = System.getProperty( "destDir" );
+ println( "Resolving types" );
- if ( outdir == null )
- {
- outdir = DEFAULT_DIR;
- }
+ // resolve the types of all symbols in the symbol table
+ symbolTable.resolveTypes();
+ symbolTable.resolveRefs();
- setDestDir( outdir );
+ // Iterate through each package
+ Hashtable packageTable = symbolTable.getPackages();
+ Enumeration pEnum = packageTable.elements();
- String t = System.getProperty( "title" );
+ println( "Persisting definitions" );
- if ( t == null )
+ while ( pEnum.hasMoreElements() )
{
- t = "Pass1: " + outdir;
- }
+ PackageDef pDef = (PackageDef) pEnum.nextElement();
- setTitle( t );
+ printAdvancement( "Processing package " + pDef.getName() );
- boolean doRecurse = true;
- String recurseStr = System.getProperty( "recurse" );
+ // Generate tags for each package. We cannot do one class
+ // at a time because more than one class might be in a
+ // single file, and we write out each file only one time.
+ HTMLTagContainer tagList = new HTMLTagContainer();
- if ( recurseStr != null )
- {
- recurseStr = recurseStr.trim();
+ pDef.generateTags( tagList );
- if ( recurseStr.equalsIgnoreCase( "off" ) || recurseStr.equalsIgnoreCase( "false" )
- || recurseStr.equalsIgnoreCase( "no" ) || recurseStr.equalsIgnoreCase( "0" ) )
+ Hashtable fileTable = tagList.getFileTable();
+ Enumeration enumList = fileTable.keys();
+ Vector tempFileTags = new Vector();
+
+ while ( enumList.hasMoreElements() )
{
- doRecurse = false;
- }
- }
+ tempFileTags.clear();
- setRecurse( doRecurse );
+ File f = (File) enumList.nextElement();
- boolean v = false;
- String verboseStr = System.getProperty( "verbose" );
+ if ( inputFiles.contains( f.getAbsolutePath() ) )
+ {
+ Vector fileTags = (Vector) fileTable.get( f );
- if ( verboseStr != null )
- {
- verboseStr = verboseStr.trim();
+ tempFileTags.addAll( fileTags );
- if ( verboseStr.equalsIgnoreCase( "on" ) || verboseStr.equalsIgnoreCase( "true" )
- || verboseStr.equalsIgnoreCase( "yes" ) || verboseStr.equalsIgnoreCase( "1" ) )
- {
- v = true;
+ // Generate the HTML tags for all references in this file
+ // I.e. generate HTML mark-up of this .java file
+ SymbolTable.createReferenceTags( f, tempFileTags );
+ SymbolTable.getCommentTags( f, tempFileTags );
+ SymbolTable.getLiteralTags( f, tempFileTags );
+ SymbolTable.getKeywordTags( f, tempFileTags );
+ createClassFiles( tempFileTags );
+ }
}
+
+ // Create reference files
+ // I.e. generate HTML mark-up of all definitions in this package's .java files
+ // (no longer -- this happens in Pass2 now)
+ // System.out.println("\nWriting definition HTML...");
+ // pDef.generateReferenceFiles(getOutDir());
+ pDef.persistDefinitions( getDestDir() );
}
- setVerbose( v );
+ println( "Persisting references" );
+
+ symbolTable.persistRefs( getDestDir() );
}
// ----------------------------------------------------------------------
@@ -351,58 +190,6 @@
// ----------------------------------------------------------------------
/**
- * Method createDirs
- *
- * @param f
- */
- private void createDirs( File f )
- {
- String parentDir = f.getParent();
- File directory = new File( parentDir );
-
- if ( !directory.exists() )
- {
- directory.mkdirs();
- }
- }
-
- /**
- * Method getBackupPath
- *
- * @param tagList
- * @param element
- * @return
- */
- private String getBackupPath( Object[] tagList, int element )
- {
- HTMLTag t = (HTMLTag) tagList[element];
- String packageName = t.getPackageName();
-
- if ( packageName.equals( "" ) )
- {
- File tempFile = t.getFile();
- int i = Math.min( element + 1, tagList.length );
- HTMLTag tempTag = (HTMLTag) tagList[i];
-
- while ( tempTag.getFile().equals( tempFile ) && ( i < tagList.length ) )
- {
- if ( ( tempTag.getPackageName() != null ) && ( tempTag.getPackageName().length() > 0 ) )
- {
- packageName = tempTag.getPackageName();
-
- break;
- }
-
- i++;
-
- tempTag = (HTMLTag) tagList[i];
- }
- }
-
- return getBackupPath( packageName );
- }
-
- /**
* Method createClassFile
*
* @param tagList
@@ -469,10 +256,15 @@
HTMLOutputWriter output = new LineOutputWriter( new BufferedOutputStream( new FileOutputStream( f ) ) );
String backup = getBackupPath( tagList, element );
+ String encoding = ( StringUtils.isNotEmpty( getOptions().getDocencoding() ) ? getOptions()
+ .getDocencoding() : System.getProperty( "file.encoding" ) );
+
String header = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
+ "<html>\n"
+ "<head>\n"
- + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"
+ + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
+ + encoding
+ + "\">\n"
+ "<title>"
+ packageName
+ "."
@@ -484,6 +276,11 @@
+ "</head>\n"
+ "<body>\n";
+ if ( StringUtils.isNotEmpty( getOptions().getTop() ) )
+ {
+ header += getOptions().getTop() + "<hr>\n";
+ }
+
output.write( header, 0, header.length() );
// "'<A HREF=\"./"+htmlPackagePath+"/classList.html\" TARGET=\"packageFrame\">" + packageName + "</A>: " + SymbolTable.getClassList(t.getFile()) + "');\n"+
@@ -594,7 +391,6 @@
}
currentChar = input.read();
-
currentColumn++;
i++;
}
@@ -640,7 +436,6 @@
}
currentChar = input.read();
-
currentColumn++;
}
@@ -696,7 +491,6 @@
}
currentChar = input.read();
-
currentColumn++;
}
@@ -725,7 +519,6 @@
}
currentChar = input.read();
-
currentColumn++;
i++;
}
@@ -756,7 +549,6 @@
}
currentChar = input.read();
-
currentColumn++;
i++;
}
@@ -794,9 +586,16 @@
try
{
output = createClassFile( sortedList, 0 );
- input = new LineNumberReader(
- new InputStreamReader(
- new SkipCRInputStream( new FileInputStream( javaFile ) ) ) );
+ SkipCRInputStream is = new SkipCRInputStream( new FileInputStream( javaFile ) );
+ if ( StringUtils.isNotEmpty( getOptions().getEncoding() ) )
+ {
+ input = new LineNumberReader( new InputStreamReader( is, getOptions().getEncoding() ) );
+ }
+ else
+ {
+
+ input = new LineNumberReader( new InputStreamReader( is ) );
+ }
currentChar = input.read();
currentColumn = 1;
}
@@ -838,11 +637,16 @@
// Open new file
javaFile = t.getFile();
- input = new LineNumberReader(
- new InputStreamReader(
- new SkipCRInputStream(
- new FileInputStream(
- javaFile ) ) ) );
+ SkipCRInputStream is = new SkipCRInputStream( new FileInputStream( javaFile ) );
+ if ( StringUtils.isNotEmpty( getOptions().getEncoding() ) )
+ {
+ input = new LineNumberReader( new InputStreamReader( is, getOptions().getEncoding() ) );
+ }
+ else
+ {
+
+ input = new LineNumberReader( new InputStreamReader( is ) );
+ }
output = createClassFile( sortedList, i );
currentColumn = 1;
currentChar = input.read();
@@ -896,20 +700,9 @@
}
}
- private void print( String description )
- {
- System.out.print( description );
- }
-
- private void println( String description )
- {
- System.out.print( "\n" );
- System.out.print( description );
- }
-
private void printAdvancement( String description )
{
- if ( isVerbose() )
+ if ( getOptions().isVerbose() )
{
System.out.println( description );
}
@@ -923,40 +716,44 @@
// Static methods
// ----------------------------------------------------------------------
+ private static void print( String description )
+ {
+ System.out.print( description );
+ }
+
/**
- * Returns the path to the top level of the source hierarchy from the files
- * og\f a given class.
+ * Method getBackupPath
*
- * @param packageName the package to get the backup path for
+ * @param tagList
+ * @param element
* @return
- * @returns the path from the package to the top level, as a string
*/
- private static String getBackupPath( String packageName )
+ private static String getBackupPath( Object[] tagList, int element )
{
- StringTokenizer st = new StringTokenizer( packageName, "." );
- String backup = "";
- int dirs = 0;
- String newPath = "";
+ HTMLTag t = (HTMLTag) tagList[element];
+ String packageName = t.getPackageName();
- if ( log.isDebugEnabled() )
+ if ( packageName.equals( "" ) )
{
- log.debug( "getBackupPath(String) - Package Name for BackupPath=" + packageName );
- }
+ File tempFile = t.getFile();
+ int i = Math.min( element + 1, tagList.length );
+ HTMLTag tempTag = (HTMLTag) tagList[i];
- dirs = st.countTokens();
+ while ( tempTag.getFile().equals( tempFile ) && ( i < tagList.length ) )
+ {
+ if ( ( tempTag.getPackageName() != null ) && ( tempTag.getPackageName().length() > 0 ) )
+ {
+ packageName = tempTag.getPackageName();
- for ( int j = 0; j < dirs; j++ )
- {
- backup = backup + "../";
- }
+ break;
+ }
- newPath = backup;
+ i++;
- if ( log.isDebugEnabled() )
- {
- log.debug( "getBackupPath(String) - Package Name for newPath=" + newPath );
+ tempTag = (HTMLTag) tagList[i];
+ }
}
- return ( newPath );
+ return getBackupPath( packageName );
}
}