ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: how to only do stuff if javac compiled something?
Date Fri, 14 Nov 2003 18:41:19 GMT
One may add a sequential to the javac task:
  <target name="init">
    <beanshelldef name="my.javac" classname="MyJavac">
      import org.apache.tools.ant.taskdefs.Javac;
      import org.apache.tools.ant.taskdefs.condition.Condition;
      import org.apache.tools.ant.taskdefs.Sequential;
      public class MyJavac extends Javac implements Condition {
        private String compileProperty;
        private boolean compiling = false;
        private Sequential sequential;
        public void setCompileProperty(String compileProperty) {
          this.compileProperty = compileProperty;
        }
        public boolean eval() {
           execute();
           return compiling;
        }
        public void addSequential(Sequential sequential) {
          this.sequential = sequential;
        }
        protected void compile() {
          if (compileList.length &gt; 0) {
             if (compileProperty != null) {
                getProject().setNewProperty(compileProperty, "true");
             }
             compiling = true;
          }
          super.compile();
          if (compiling &amp;&amp; sequential != null) {
             sequential.perform();
          }
        }
      }
    </beanshelldef>
  </target>

and use it like:
  <target name="if_seq" depends="init">
    <my.javac srcdir="src" destdir="classes">
      <sequential>
        <echo>test classes</echo>
        <echo>package classes</echo>
      </sequential>
    </my.javac>
  </target>

or as a condition:
  <target name="if_compile" depends="init">
    <ac:if>
      <my.javac srcdir="src" destdir="classes"/>
      <then>
        <echo>test classes</echo>
        <echo>package classes</echo>
      </then>
    </ac:if>
  </target>

Peter
On Friday 14 November 2003 18:07, peter reilly wrote:
> The easiest way I can think of is to extend/modify Javac
> and set a property if is actually calls the compiler
> which is done in Javac#compile().
>
> Using my beanshelldef task to extend javac in-line:
>
>  <project default="all">
>   <target name="init">
>     <beanshelldef name="my.javac" classname="MyJavac">
>       import org.apache.tools.ant.taskdefs.Javac;
>       public class MyJavac extends Javac {
>         private String compileProperty;
>         public void setCompileProperty(String compileProperty) {
>           this.compileProperty = compileProperty;
>         }
>         protected void compile() {
>           if (compileList.length &gt; 0) {
>              if (compileProperty != null) {
>                 getProject().setNewProperty(compileProperty, "true");
>              }
>           }
>           super.compile();
>         }
>       }
>     </beanshelldef>
>   </target>
>
>   <target name="compile_classes" depends="init">
>     <my.javac srcdir="src" destdir="classes"
>               compileProperty="classes.compiled"/>
>     <echo>compiled_classes is ${compiled_classes}</echo>
>   </target>
>
>   <target name="test_classes" depends="compile_classes"
> if="classes.compiled"> <echo>Test the classes</echo>
>   </target>
>
>   <target name="package_classes"
>                 depends="compile_classes" if="classes.compiled">
>     <echo>Package the classes</echo>
>   </target>
>
>   <target name="all"
> depends="compile_classes,test_classes,package_classes"/> </project>
>
> Peter
>
> On Friday 14 November 2003 17:36, Caoilte O'Connor wrote:
> > I have the following tasks,
> >
> > compile-X
> > test-X
> > package-X
> >
> > other tasks has dependencies on package-X.
> >
> >
> > When package-X gets called and no changes have been made to
> > the source the compile-X doesn't recompile but the test-X
> > and package-X still repeat their processes.
> >
> > Is there anyway I can adjust my compile-X command to call
> > the test-X and package-X directly, dependent on there being
> > some changed/new java files compiled? It would speed up
> > average usage enormously.
> >
> > thanks for any pointers,
> >
> > c
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


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


Mime
View raw message