ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs JavacTest.java
Date Mon, 15 Apr 2002 12:32:12 GMT
bodewig     02/04/15 05:32:12

  Modified:    src/main/org/apache/tools/ant/taskdefs Javac.java
               src/testcases/org/apache/tools/ant/taskdefs JavacTest.java
  Added:       src/main/org/apache/tools/ant/util/facade
                        FacadeTaskHelper.java
                        ImplementationSpecificArgument.java
  Log:
  Factor some facade task support stuff out from <javac>.
  
  Revision  Changes    Path
  1.96      +31 -63    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- Javac.java	14 Apr 2002 11:16:12 -0000	1.95
  +++ Javac.java	15 Apr 2002 12:32:12 -0000	1.96
  @@ -63,6 +63,7 @@
   import org.apache.tools.ant.util.GlobPatternMapper;
   import org.apache.tools.ant.util.JavaEnvUtils;
   import org.apache.tools.ant.util.SourceFileScanner;
  +import org.apache.tools.ant.util.facade.FacadeTaskHelper;
   import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
   import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
   
  @@ -103,7 +104,7 @@
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
    *
  - * @version $Revision: 1.95 $
  + * @version $Revision: 1.96 $
    *
    * @since Ant 1.1
    *
  @@ -135,7 +136,7 @@
       private boolean nowarn = false;
       private String memoryInitialSize;
       private String memoryMaximumSize;
  -    private Vector implementationSpecificArgs = new Vector();
  +    private FacadeTaskHelper facade = null;
   
       protected boolean failOnError = true;
       protected boolean listFiles = false;
  @@ -144,14 +145,14 @@
       private String source;
       private String debugLevel;
   
  -    /**
  -     * The compiler set via the compiler attribute.
  -     *
  -     * <p>default is null</p>
  -     *
  -     * @since Ant 1.5
  -     */
  -    private String compiler = null;
  +    public Javac() {
  +        if (JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_1 &&
  +            JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_2) {
  +            facade = new FacadeTaskHelper("modern");
  +        } else {
  +            facade = new FacadeTaskHelper("classic");
  +        }
  +    }
   
       /**
        * Get the value of debugLevel.
  @@ -604,7 +605,7 @@
       public ImplementationSpecificArgument createCompilerArg() {
           ImplementationSpecificArgument arg =
               new ImplementationSpecificArgument();
  -        implementationSpecificArgs.addElement(arg);
  +        facade.addImplementationArgument(arg);
           return arg;
       }
   
  @@ -613,19 +614,10 @@
        * @return array of command line arguments, guaranteed to be non-null.
        */
       public String[] getCurrentCompilerArgs() {
  -        Vector args = new Vector();
  -        for (Enumeration enum = implementationSpecificArgs.elements();
  -             enum.hasMoreElements();) {
  -            ImplementationSpecificArgument arg = 
  -                ((ImplementationSpecificArgument) enum.nextElement());
  -            String[] curr = arg.getParts();
  -            for (int i = 0; i < curr.length; i++) {
  -                args.addElement(curr[i]);
  -            }
  -        }
  -        String[] res = new String[args.size()];
  -        args.copyInto(res);
  -        return res;
  +        // make sure facade knows about magic properties and fork setting
  +        getCompiler();
  +
  +        return facade.getArgs();
       }
   
       /**
  @@ -708,7 +700,7 @@
        * @since Ant 1.5
        */
       public void setCompiler(String compiler) {
  -        this.compiler = compiler;
  +        facade.setImplementation(compiler);
       }
   
       /**
  @@ -720,33 +712,19 @@
        * @since Ant 1.5
        */
       public String getCompiler() {
  -        String compilerImpl = 
  -            this.compiler != null ? this.compiler 
  -                                  : project.getProperty("build.compiler");
  +        facade.setMagicValue(getProject().getProperty("build.compiler"));
  +        String compilerImpl = facade.getImplementation();
   
           if (fork) {
  -            if (compilerImpl != null) {
  -                if (isJdkCompiler(compilerImpl)) {
  -                    log("Since fork is true, ignoring compiler setting.",
  -                        Project.MSG_WARN);
  -                    compilerImpl = "extJavac";
  -                }
  -                else {
  -                    log("Since compiler setting isn't classic or modern,"
  -                        + "ignoring fork setting.", Project.MSG_WARN);
  -                }
  -            }
  -            else {
  +            if (isJdkCompiler(compilerImpl)) {
  +                log("Since fork is true, ignoring compiler setting.",
  +                    Project.MSG_WARN);
  +                facade.setImplementation("extJavac");
                   compilerImpl = "extJavac";
               }
  -        }
  -
  -        if (compilerImpl == null) {
  -            if (JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_1 &&
  -                JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_2) {
  -                compilerImpl = "modern";
  -            } else {
  -                compilerImpl = "classic";
  +            else {
  +                log("Since compiler setting isn't classic or modern,"
  +                    + "ignoring fork setting.", Project.MSG_WARN);
               }
           }
           return compilerImpl;
  @@ -816,25 +794,15 @@
       }
   
       /**
  -     * Adds an "implementation" attribute to Commandline$Attribute
  -     * used to filter command line attributes based on the current
  +     * Adds an "compiler" attribute to Commandline$Attribute used to
  +     * filter command line attributes based on the current
        * implementation.
        */
  -    public class ImplementationSpecificArgument
  -        extends Commandline.Argument {
  -
  -        private String impl;
  +    public class ImplementationSpecificArgument extends 
  +        org.apache.tools.ant.util.facade.ImplementationSpecificArgument {
   
           public void setCompiler(String impl) {
  -            this.impl = impl;
  -        }
  -
  -        public String[] getParts() {
  -            if (impl == null || impl.equals(getCompiler())) {
  -                return super.getParts();
  -            } else {
  -                return new String[0];
  -            }
  +            super.setImplementation(impl);
           }
       }
   
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/util/facade/FacadeTaskHelper.java
  
  Index: FacadeTaskHelper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.util.facade;
  
  import java.util.Enumeration;
  import java.util.Vector;
  
  /**
   * Helper class for facade implementations - encapsulates treatment of
   * explicit implementation choices, magic properties and
   * implementation specific command line arguments.
   *
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   *
   * @version $Revision: 1.1 $
   *
   * @since Ant 1.5
   */
  public class FacadeTaskHelper {
  
      /**
       * Command line arguments.
       */
      private Vector args = new Vector();
  
      /**
       * The explicitly chosen implementation.
       */
      private String userChoice;
  
      /**
       * The magic property to consult.
       */
      private String magicValue;
  
      /**
       * The default value.
       */
      private String defaultValue;
  
      /**
       * @param defaultValue The default value for the implementation.
       * Must not be null.
       */
      public FacadeTaskHelper(String defaultValue) {
          this(defaultValue, null);
      }
  
      /**
       * @param defaultValue The default value for the implementation.
       * Must not be null.
       * @param magic the value of a magic property that may hold a user
       * choice.  May be null.
       */
      public FacadeTaskHelper(String defaultValue, String magicValue) {
          this.defaultValue = defaultValue;
          this.magicValue = magicValue;
      }
  
      /**
       * Used to set the value of the magic property.
       */
      public void setMagicValue(String magicValue) {
          this.magicValue = magicValue;
      }
  
      /**
       * Used for explicit user choices.
       */
      public void setImplementation(String userChoice) {
          this.userChoice = userChoice;
      }
  
      /**
       * Retrieves the implementation.
       */
      public String getImplementation() {
          return userChoice != null ? userChoice
                                    : (magicValue != null ? magicValue
                                                          : defaultValue);
      }
  
      /**
       * Command line argument.
       */
      public void addImplementationArgument(ImplementationSpecificArgument arg) {
          args.addElement(arg);
      }
  
      /**
       * Retrieves the command line arguments enabled for the current
       * facade implementation.
       */
      public String[] getArgs() {
          Vector tmp = new Vector(args.size());
          for (Enumeration enum = args.elements(); enum.hasMoreElements();) {
              ImplementationSpecificArgument arg = 
                  ((ImplementationSpecificArgument) enum.nextElement());
              String[] curr = arg.getParts(getImplementation());
              for (int i = 0; i < curr.length; i++) {
                  tmp.addElement(curr[i]);
              }
          }
          String[] res = new String[tmp.size()];
          tmp.copyInto(res);
          return res;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/util/facade/ImplementationSpecificArgument.java
  
  Index: ImplementationSpecificArgument.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.util.facade;
  
  import org.apache.tools.ant.types.Commandline;
  
  /**
   * Extension of Commandline.Argument with a new attribute that choses
   * a specific implementation of the facade.
   *
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   *
   * @version $Revision: 1.1 $
   *
   * @since Ant 1.5
   */
  public class ImplementationSpecificArgument extends Commandline.Argument {
      private String impl;
  
      public ImplementationSpecificArgument() {
          super();
      }
  
      public void setImplementation(String impl) {
          this.impl = impl;
      }
  
      public final String[] getParts(String chosenImpl) {
          if (impl == null || impl.equals(chosenImpl)) {
              return super.getParts();
          } else {
              return new String[0];
          }
      }
  }
  
  
  
  1.6       +3 -2      jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java
  
  Index: JavacTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JavacTest.java	25 Mar 2002 10:37:03 -0000	1.5
  +++ JavacTest.java	15 Apr 2002 12:32:12 -0000	1.6
  @@ -62,7 +62,7 @@
    * Testcase for <javac>.
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  - * @version $Revision: 1.5 $ $Date: 2002/03/25 10:37:03 $
  + * @version $Revision: 1.6 $ $Date: 2002/04/15 12:32:12 $
    */
   public class JavacTest extends TestCase {
   
  @@ -184,7 +184,8 @@
           assertEquals("extJavac", compiler);
   
           // check build.compiler provides defaults
  -        javac.setFork(false);
  +        javac = new Javac();
  +        javac.setProject(project);
           project.setNewProperty("build.compiler", "jikes");
           compiler = javac.getCompiler();
           assertNotNull(compiler);
  
  
  

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


Mime
View raw message