Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 9802 invoked from network); 6 Jan 2002 02:16:41 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Jan 2002 02:16:41 -0000 Received: (qmail 3431 invoked by uid 97); 6 Jan 2002 02:16:40 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 3394 invoked by uid 97); 6 Jan 2002 02:16:36 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 3371 invoked by uid 97); 6 Jan 2002 02:16:35 -0000 Date: 6 Jan 2002 02:16:25 -0000 Message-ID: <20020106021625.79360.qmail@icarus.apache.org> From: donaldp@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional ClassArgument.java Javah.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N donaldp 02/01/05 18:16:24 Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional Javah.java Added: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional ClassArgument.java Log: Cleanup class and move ClassArgument to top level class Revision Changes Path 1.16 +92 -175 jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java Index: Javah.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Javah.java 30 Dec 2001 10:46:58 -0000 1.15 +++ Javah.java 6 Jan 2002 02:16:24 -0000 1.16 @@ -12,12 +12,10 @@ import java.util.Iterator; import java.util.StringTokenizer; import org.apache.avalon.excalibur.util.StringUtil; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.JavaVersion; -import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Reference; /** * Task to generate JNI header files using javah. This task can take the @@ -53,267 +51,209 @@ * richard.beton@physics.org */ -public class Javah extends Task +public class Javah + extends AbstractLogEnabled { - private final static String FAIL_MSG = "Compile failed, messages should have been provided."; - private ArrayList classes = new ArrayList( 2 ); - private Path classpath = null; - private File outputFile = null; - private boolean verbose = false; - private boolean force = false; - private boolean old = false; - private boolean stubs = false; - private Path bootclasspath; - private String cls; - private File destDir; - - /** - * Adds a reference to a CLASSPATH defined elsewhere. - * - * @param r The new BootClasspathRef value - */ - public void setBootClasspathRef( Reference r ) - { - createBootclasspath().setRefid( r ); - } + private ArrayList m_classes = new ArrayList( 2 ); + private Path m_classpath; + private File m_outputFile; + private boolean m_verbose; + private boolean m_force; + private boolean m_old; + private boolean m_stubs; + private Path m_bootclasspath; + private String m_cls; + private File m_destDir; - public void setBootclasspath( Path src ) + public void setBootclasspath( final Path bootclasspath ) + throws TaskException { - if( bootclasspath == null ) + if( m_bootclasspath == null ) { - bootclasspath = src; + m_bootclasspath = bootclasspath; } else { - bootclasspath.append( src ); + m_bootclasspath.append( bootclasspath ); } } - public void setClass( String cls ) + public void setClass( final String cls ) { - this.cls = cls; + m_cls = cls; } - public void setClasspath( Path src ) + public void setClasspath( final Path classpath ) + throws TaskException { - if( classpath == null ) + if( m_classpath == null ) { - classpath = src; + m_classpath = classpath; } else { - classpath.append( src ); + m_classpath.append( classpath ); } } /** - * Adds a reference to a CLASSPATH defined elsewhere. - * - * @param r The new ClasspathRef value - */ - public void setClasspathRef( Reference r ) - { - createClasspath().setRefid( r ); - } - - /** * Set the destination directory into which the Java source files should be * compiled. * * @param destDir The new Destdir value */ - public void setDestdir( File destDir ) + public void setDestdir( final File destDir ) { - this.destDir = destDir; + m_destDir = destDir; } /** * Set the force-write flag. - * - * @param force The new Force value */ - public void setForce( boolean force ) + public void setForce( final boolean force ) { - this.force = force; + m_force = force; } /** * Set the old flag. - * - * @param old The new Old value */ - public void setOld( boolean old ) + public void setOld( final boolean old ) { - this.old = old; + m_old = old; } - ///** - // * Sets the extension directories that will be used during the - // * compilation. - // */ - //public void setExtdirs(Path extdirs) { - // if (this.extdirs == null) { - // this.extdirs = extdirs; - // } else { - // this.extdirs.append(extdirs); - // } - //} - - ///** - // * Maybe creates a nested classpath element. - // */ - //public Path createExtdirs() { - // if (extdirs == null) { - // extdirs = new Path(project); - // } - // return extdirs.createPath(); - //} - /** * Set the output file name. - * - * @param outputFile The new OutputFile value */ - public void setOutputFile( File outputFile ) + public void setOutputFile( final File outputFile ) { - this.outputFile = outputFile; + m_outputFile = outputFile; } /** * Set the stubs flag. - * - * @param stubs The new Stubs value */ - public void setStubs( boolean stubs ) + public void setStubs( final boolean stubs ) { - this.stubs = stubs; + m_stubs = stubs; } /** * Set the verbose flag. - * - * @param verbose The new Verbose value */ - public void setVerbose( boolean verbose ) + public void setVerbose( final boolean verbose ) { - this.verbose = verbose; + m_verbose = verbose; } public Path createBootclasspath() { - if( bootclasspath == null ) + if( m_bootclasspath == null ) { - bootclasspath = new Path(); + m_bootclasspath = new Path(); } - return bootclasspath.createPath(); + return m_bootclasspath.createPath(); } public ClassArgument createClass() { - ClassArgument ga = new ClassArgument(); - classes.add( ga ); + final ClassArgument ga = new ClassArgument(); + setupLogger( ga ); + m_classes.add( ga ); return ga; } public Path createClasspath() { - if( classpath == null ) + if( m_classpath == null ) { - classpath = new Path(); + m_classpath = new Path(); } - return classpath.createPath(); + return m_classpath.createPath(); } /** * Executes the task. - * - * @exception TaskException Description of Exception */ public void execute() throws TaskException { - // first off, make sure that we've got a srcdir + validate(); - if( ( cls == null ) && ( classes.size() == 0 ) ) + if( m_classpath == null ) { - throw new TaskException( "class attribute must be set!" ); + m_classpath = Path.systemClasspath; } - if( ( cls != null ) && ( classes.size() > 0 ) ) - { - throw new TaskException( "set class attribute or class element, not both." ); - } + doClassicCompile(); + } - if( destDir != null ) + private void validate() throws TaskException + { + if( ( m_cls == null ) && ( m_classes.size() == 0 ) ) { - if( !destDir.isDirectory() ) - { - throw new TaskException( "destination directory \"" + destDir + "\" does not exist or is not a directory" ); - } - if( outputFile != null ) - { - throw new TaskException( "destdir and outputFile are mutually exclusive" ); - } + final String message = "class attribute must be set!"; + throw new TaskException( message ); } - if( classpath == null ) + if( ( m_cls != null ) && ( m_classes.size() > 0 ) ) { - classpath = Path.systemClasspath; + final String message = "set class attribute or class element, not both."; + throw new TaskException( message ); } - String compiler = getProject().getProperty( "build.compiler" ); - if( compiler == null ) + if( m_destDir != null ) { - if( JavaVersion.JAVA1_2 != JavaVersion.getCurrentJavaVersion() ) + if( !m_destDir.isDirectory() ) { - compiler = "modern"; + final String message = "destination directory \"" + m_destDir + + "\" does not exist or is not a directory"; + throw new TaskException( message ); } - else + if( m_outputFile != null ) { - compiler = "classic"; + final String message = "destdir and outputFile are mutually exclusive"; + throw new TaskException( message ); } } - - doClassicCompile(); } /** * Logs the compilation parameters, adds the files to compile and logs the * &qout;niceSourceList" - * - * @param cmd Description of Parameter */ - protected void logAndAddFilesToCompile( Commandline cmd ) + private void logAndAddFilesToCompile( final Commandline cmd ) { int n = 0; getLogger().debug( "Compilation args: " + cmd.toString() ); StringBuffer niceClassList = new StringBuffer(); - if( cls != null ) + if( m_cls != null ) { - StringTokenizer tok = new StringTokenizer( cls, ",", false ); + final StringTokenizer tok = new StringTokenizer( m_cls, ",", false ); while( tok.hasMoreTokens() ) { - String aClass = tok.nextToken().trim(); + final String aClass = tok.nextToken().trim(); cmd.createArgument().setValue( aClass ); niceClassList.append( " " + aClass + StringUtil.LINE_SEPARATOR ); n++; } } - Iterator enum = classes.iterator(); + final Iterator enum = m_classes.iterator(); while( enum.hasNext() ) { - ClassArgument arg = (ClassArgument)enum.next(); - String aClass = arg.getName(); + final ClassArgument arg = (ClassArgument)enum.next(); + final String aClass = arg.getName(); cmd.createArgument().setValue( aClass ); niceClassList.append( " " + aClass + StringUtil.LINE_SEPARATOR ); n++; } - StringBuffer prefix = new StringBuffer( "Class" ); + final StringBuffer prefix = new StringBuffer( "Class" ); if( n > 1 ) { prefix.append( "es" ); @@ -326,65 +266,62 @@ /** * Does the command line argument processing common to classic and modern. - * - * @return Description of the Returned Value */ private Commandline setupJavahCommand() + throws TaskException { - Commandline cmd = new Commandline(); + final Commandline cmd = new Commandline(); - if( destDir != null ) + if( m_destDir != null ) { cmd.createArgument().setValue( "-d" ); - cmd.createArgument().setFile( destDir ); + cmd.createArgument().setFile( m_destDir ); } - if( outputFile != null ) + if( m_outputFile != null ) { cmd.createArgument().setValue( "-o" ); - cmd.createArgument().setFile( outputFile ); + cmd.createArgument().setFile( m_outputFile ); } - if( classpath != null ) + if( m_classpath != null ) { cmd.createArgument().setValue( "-classpath" ); - cmd.createArgument().setPath( classpath ); + cmd.createArgument().setPath( m_classpath ); } - if( verbose ) + if( m_verbose ) { cmd.createArgument().setValue( "-verbose" ); } - if( old ) + if( m_old ) { cmd.createArgument().setValue( "-old" ); } - if( force ) + if( m_force ) { cmd.createArgument().setValue( "-force" ); } - if( stubs ) + if( m_stubs ) { - if( !old ) + if( !m_old ) { - throw new TaskException( "stubs only available in old mode." ); + final String message = "stubs only available in old mode."; + throw new TaskException( message ); } cmd.createArgument().setValue( "-stubs" ); } - if( bootclasspath != null ) + if( m_bootclasspath != null ) { cmd.createArgument().setValue( "-bootclasspath" ); - cmd.createArgument().setPath( bootclasspath ); + cmd.createArgument().setPath( m_bootclasspath ); } logAndAddFilesToCompile( cmd ); return cmd; } - // XXX - // we need a way to not use the current classpath. - /** * Peforms a compile using the classic compiler that shipped with JDK 1.1 * and 1.2. @@ -431,26 +368,6 @@ { throw new TaskException( "Error starting javah: ", ex ); } - } - } - - public class ClassArgument - { - private String name; - - public ClassArgument() - { - } - - public void setName( String name ) - { - this.name = name; - getLogger().info( "ClassArgument.name=" + name ); - } - - public String getName() - { - return name; } } } 1.1 jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ClassArgument.java Index: ClassArgument.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.tools.ant.taskdefs.optional; import org.apache.avalon.framework.logger.AbstractLogEnabled; public class ClassArgument extends AbstractLogEnabled { private String m_name; public void setName( String name ) { m_name = name; getLogger().info( "ClassArgument.name=" + name ); } public String getName() { return m_name; } } -- To unsubscribe, e-mail: For additional commands, e-mail: