ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii DefaultNative2Ascii.java KaffeNative2Ascii.java Native2AsciiAdapterFactory.java SunNative2Ascii.java Native2AsciiAdapter.java
Date Mon, 31 Jan 2005 11:48:25 GMT
bodewig     2005/01/31 03:48:25

  Modified:    .        build.xml
               src/main/org/apache/tools/ant/taskdefs/optional
                        Native2Ascii.java
               src/main/org/apache/tools/ant/taskdefs/optional/native2ascii
                        Native2AsciiAdapter.java
  Added:       src/main/org/apache/tools/ant/taskdefs/optional/native2ascii
                        DefaultNative2Ascii.java KaffeNative2Ascii.java
                        Native2AsciiAdapterFactory.java
                        SunNative2Ascii.java
  Log:
  Support Kaffe in native2ascii, make it a full facade task later
  
  Revision  Changes    Path
  1.451     +1 -2      ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/ant/build.xml,v
  retrieving revision 1.450
  retrieving revision 1.451
  diff -u -r1.450 -r1.451
  --- build.xml	28 Jan 2005 20:11:48 -0000	1.450
  +++ build.xml	31 Jan 2005 11:48:24 -0000	1.451
  @@ -162,9 +162,8 @@
          Kaffe for example -->
     <selector id="needs.sun.tools">
       <or>
  -      <filename name="${optional.package}/Native2Ascii*"/>
         <filename name="${optional.package}/Javah*"/>
  -      <filename name="${optional.package}/native2ascii/*"/>
  +      <filename name="${optional.package}/native2ascii/Sun*"/>
       </or>
     </selector>
   
  
  
  
  1.23      +26 -20    ant/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java
  
  Index: Native2Ascii.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Native2Ascii.java	6 Dec 2004 19:27:13 -0000	1.22
  +++ Native2Ascii.java	31 Jan 2005 11:48:25 -0000	1.23
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2000-2004 The Apache Software Foundation
  + * Copyright  2000-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -22,6 +22,8 @@
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.taskdefs.MatchingTask;
  +import org.apache.tools.ant.taskdefs.optional.native2ascii.Native2AsciiAdapter;
  +import org.apache.tools.ant.taskdefs.optional.native2ascii.Native2AsciiAdapterFactory;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.Mapper;
   import org.apache.tools.ant.util.FileNameMapper;
  @@ -55,6 +57,15 @@
       }
   
       /**
  +     * The value of the reverse attribute.
  +     *
  +     * @since Ant 1.6.3
  +     */
  +    public boolean getReverse() {
  +        return reverse;
  +    }
  +
  +    /**
        * Set the encoding to translate to/from.
        * If unset, the default encoding for the JVM is used.
        *
  @@ -66,6 +77,15 @@
       }
   
       /**
  +     * The value of the reverse attribute.
  +     *
  +     * @since Ant 1.6.3
  +     */
  +    public String getEncoding() {
  +        return encoding;
  +    }
  +
  +    /**
        * Set the source directory in which to find files to convert.
        *
        * @param srcDir directory to find input file in.
  @@ -181,29 +201,15 @@
        * @param srcName name of the input file.
        * @param destName name of the input file.
        */
  -    private void convert(String srcName, String destName) throws BuildException {
  -
  -        Commandline cmd = new Commandline();  // Command line to run
  +    private void convert(String srcName, String destName) 
  +        throws BuildException {
           File srcFile;                         // File to convert
           File destFile;                        // where to put the results
   
  -        // Set up the basic args (this could be done once, but
  -        // it's cleaner here)
  -        if (reverse) {
  -            cmd.createArgument().setValue("-reverse");
  -        }
  -
  -        if (encoding != null) {
  -            cmd.createArgument().setValue("-encoding");
  -            cmd.createArgument().setValue(encoding);
  -        }
  -
           // Build the full file names
           srcFile = new File(srcDir, srcName);
           destFile = new File(destDir, destName);
   
  -        cmd.createArgument().setFile(srcFile);
  -        cmd.createArgument().setFile(destFile);
           // Make sure we're not about to clobber something
           if (srcFile.equals(destFile)) {
               throw new BuildException("file " + srcFile
  @@ -223,9 +229,9 @@
           }
   
           log("converting " + srcName, Project.MSG_VERBOSE);
  -        sun.tools.native2ascii.Main n2a
  -            = new sun.tools.native2ascii.Main();
  -        if (!n2a.convert(cmd.getArguments())) {
  +        Native2AsciiAdapter ad = 
  +            Native2AsciiAdapterFactory.getAdapter(null, this);
  +        if (!ad.convert(this, srcFile, destFile)) {
               throw new BuildException("conversion failed");
           }
       }
  
  
  
  1.3       +18 -2     ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/Native2AsciiAdapter.java
  
  Index: Native2AsciiAdapter.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/Native2AsciiAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Native2AsciiAdapter.java	28 Jan 2005 16:51:10 -0000	1.2
  +++ Native2AsciiAdapter.java	31 Jan 2005 11:48:25 -0000	1.3
  @@ -14,11 +14,27 @@
    *  limitations under the License.
    *
    */
  -package org.apache.tools.ant.taskdef.optional.native2ascii;
  +package org.apache.tools.ant.taskdefs.optional.native2ascii;
   
   import java.io.File;
  +import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
   
  +/**
  + * Interface for an adapter to a native2ascii implementation.
  + *
  + * @since Ant 1.6.3
  + */
   public interface Native2AsciiAdapter {
  -    boolean convert(Native2Ascii args, File srcFile, File destFile);
  +    /**
  +     * Convert the encoding of srcFile writing to destFile.
  +     *
  +     * @param args Task that holds command line arguments and allows
  +     * the implementation to send messages to Ant's logging system
  +     * @param srcFile the source to convert
  +     * @param destFile where to send output to
  +     * @return whether the conversion has been successful.
  +     */
  +    boolean convert(Native2Ascii args, File srcFile, File destFile)
  +        throws BuildException;
   }
  \ No newline at end of file
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/DefaultNative2Ascii.java
  
  Index: DefaultNative2Ascii.java
  ===================================================================
  /*
   * Copyright  2005 The Apache Software Foundation
   *
   *  Licensed 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.
   *
   */
  package org.apache.tools.ant.taskdefs.optional.native2ascii;
  
  import java.io.File;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
  import org.apache.tools.ant.types.Commandline;
  
  /**
   * encapsulates the handling common to diffent Native2Asciiadapter
   * implementations.
   *
   * @since Ant 1.6.3
   */
  public abstract class DefaultNative2Ascii implements Native2AsciiAdapter {
  
      public DefaultNative2Ascii() {
      }
  
      /**
       * Splits the task into setting up the command line switches
       * (delegated to {@link #setup setup}), adding the file names
       * (delegated to {@link addFiles addFiles}) and running the tool
       * (delegated to {@link #run run}).
       */
      public final boolean convert(Native2Ascii args, File srcFile,
                                   File destFile) throws BuildException {
          Commandline cmd = new Commandline();
          setup(cmd, args);
          addFiles(cmd, args, srcFile, destFile);
          return run(cmd, args);
      }
      
      /**
       * Sets up the initial command line.
       *
       * <p>only the -encoding argument gets handled here.</p>
       *
       * @param cmd Command line to add to
       * @param args provides the user-setting and access to Ant's
       * logging system.
       */
      protected void setup(Commandline cmd, Native2Ascii args)
          throws BuildException {
          if (args.getEncoding() != null) {
              cmd.createArgument().setValue("-encoding");
              cmd.createArgument().setValue(args.getEncoding());
          }
      }
  
      /**
       * Adds source and dest files to the command line.
       *
       * <p>This implementation adds them without any leading
       * qualifiers, source first.</p>
       *
       * @param cmd Command line to add to
       * @param log provides access to Ant's logging system.
       * @param src the source file
       * @param dest the destination file
       */
      protected void addFiles(Commandline cmd, ProjectComponent log, File src,
                              File dest) throws BuildException {
          cmd.createArgument().setFile(src);
          cmd.createArgument().setFile(dest);
      }
  
      /**
       * Executes the command.
       *
       * @param cmd Command line to execute
       * @param log provides access to Ant's logging system.
       * @return whether execution was successful
       */
      protected abstract boolean run(Commandline cmd, ProjectComponent log)
          throws BuildException;
  }
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/KaffeNative2Ascii.java
  
  Index: KaffeNative2Ascii.java
  ===================================================================
  /*
   * Copyright  2005 The Apache Software Foundation
   *
   *  Licensed 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.
   *
   */
  package org.apache.tools.ant.taskdefs.optional.native2ascii;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.taskdefs.ExecuteJava;
  import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
  import org.apache.tools.ant.types.Commandline;
  
  /**
   * Adapter to kaffe.tools.native2ascii.Native2Ascii.
   *
   * @since Ant 1.6.3
   */
  public final class KaffeNative2Ascii extends DefaultNative2Ascii {
  
      /**
       * Identifies this adapter.
       */
      public static final String IMPLEMENTATION_NAME = "kaffe";
  
      protected void setup(Commandline cmd, Native2Ascii args)
          throws BuildException {
          if (args.getReverse()) {
              throw new BuildException("-reverse is not supported by Kaffe");
          }
          super.setup(cmd, args);
      }
  
      protected boolean run(Commandline cmd, ProjectComponent log)
          throws BuildException {
          ExecuteJava ej = new ExecuteJava();
          cmd.setExecutable("kaffe.tools.native2ascii.Native2Ascii");
          ej.setJavaCommand(cmd);
          ej.execute(log.getProject());
          // otherwise ExecuteJava has thrown an exception
          return true;
      }
  }
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/Native2AsciiAdapterFactory.java
  
  Index: Native2AsciiAdapterFactory.java
  ===================================================================
  /*
   * Copyright  2005 The Apache Software Foundation
   *
   *  Licensed 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.
   *
   */
  package org.apache.tools.ant.taskdefs.optional.native2ascii;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.util.JavaEnvUtils;
  
  /**
   * Creates the Native2AsciiAdapter based on the user choice and
   * potentially the VM vendor.
   *
   * @since Ant 1.6.3
   */
  public class Native2AsciiAdapterFactory {
  
      /**
       * Determines the default choice of adapter based on the VM
       * vendor.
       *
       * @return the default choice of adapter based on the VM
       * vendor
       */
      public static String getDefault() {
          if (JavaEnvUtils.isKaffe()) {
              return KaffeNative2Ascii.IMPLEMENTATION_NAME;
          }
          return SunNative2Ascii.IMPLEMENTATION_NAME;
      }
  
      /**
       * Creates the Native2AsciiAdapter based on the user choice and *
       * potentially the VM vendor.
       *
       * @param choice the user choice (if any).
       * @param log a ProjectComponent instance used to access Ant's
       * logging system.
       * @return The adapter to use.
       */
      public static Native2AsciiAdapter getAdapter(String choice,
                                                   ProjectComponent log)
          throws BuildException {
          if ((JavaEnvUtils.isKaffe() && choice == null)
              || KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
              return new KaffeNative2Ascii();
          } else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) {
              return new SunNative2Ascii();
          } else if (choice != null) {
              return resolveClassName(choice);
          }
  
          // This default has been good enough until Ant 1.6.3, so stick
          // with it
          return new SunNative2Ascii();
      }
  
      /**
       * Tries to resolve the given classname into a native2ascii adapter.
       * Throws a fit if it can't.
       *
       * @param className The fully qualified classname to be created.
       * @throws BuildException This is the fit that is thrown if className
       * isn't an instance of Native2AsciiAdapter.
       */
      private static Native2AsciiAdapter resolveClassName(String className)
          throws BuildException {
          try {
              Class c = Class.forName(className);
              Object o = c.newInstance();
              return (Native2AsciiAdapter) o;
          } catch (ClassNotFoundException cnfe) {
              throw new BuildException("Can't load " + className, cnfe);
          } catch (ClassCastException cce) {
              throw new BuildException(className 
                                       + " is not a Native2Ascii adapter", cce);
          } catch (Throwable t) {
              // for all other possibilities
              throw new BuildException(className + " caused an interesting "
                                       + "exception.", t);
          }
      }
  }
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/SunNative2Ascii.java
  
  Index: SunNative2Ascii.java
  ===================================================================
  /*
   * Copyright  2005 The Apache Software Foundation
   *
   *  Licensed 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.
   *
   */
  package org.apache.tools.ant.taskdefs.optional.native2ascii;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
  import org.apache.tools.ant.types.Commandline;
  
  /**
   * Adapter to sun.tools.native2ascii.Main.
   *
   * @since Ant 1.6.3
   */
  public final class SunNative2Ascii extends DefaultNative2Ascii {
  
      /**
       * Identifies this adapter.
       */
      public static final String IMPLEMENTATION_NAME = "sun";
  
      protected void setup(Commandline cmd, Native2Ascii args)
          throws BuildException {
          if (args.getReverse()) {
              cmd.createArgument().setValue("-reverse");
          }
          super.setup(cmd, args);
      }
  
      protected boolean run(Commandline cmd, ProjectComponent log)
          throws BuildException {
          sun.tools.native2ascii.Main n2a = new sun.tools.native2ascii.Main();
          return n2a.convert(cmd.getArguments());
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message