fixed build console
[groovy.git] / build.gant
blob5b00fee3831643c8ea24e52f7a2edc07b2ba47b1
1 // -*- mode: groovy coding: utf-8 -*-
3 //  Gant build script for Groovy.
4 //
5 //  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
6 //  compliance with the License. You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //  Unless required by applicable law or agreed to in writing, software distributed under the License is
11 //  distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 //  implied. See the License for the specific language governing permissions and limitations under the License.
14 //  This work is copyright by the author(s) and is part of a greater work collectively copyright by Codehaus on
15 //  behalf of the Groovy community. See the NOTICE.txt file distributed with this work for additional information.
17 //  Author : Russel Winder
19 //  NB This build ignores the JDK 1.4 and retro issues, it assumes JDK1.5.
21 //  NB  This build ignores the uberbuild route provided by the Ant build, sticking only to the stagedcompile route.
23 ant.property ( file : 'local.build.properties' )
24 ant.property ( file : 'build.properties' )
26 //  coverage is a Boolean determining whether Cobertura is invoked for the testing. Check to see if a
27 //  -Dcoverage=... was set on the command line or a coverage =... was set in either of the build properties
28 //  file before declaring that no coverage state was specified.
30 try { coverage }
31 catch ( Exception e ) {
32   if ( ant.project.properties.coverage != null ) { coverage = ant.project.properties.coverage }
33   else { coverage = false }
36 //  If testCase is non-null then execute that as a single test, otherwise execute all tests.  Check to see
37 //  if a -DtestCase=... was set on the command line or a testCase =... was set in either of the build
38 //  properties file before declaring that no individual test case was specified.
40  try { testCase }
41  catch ( Exception e ) {
42    if ( ant.project.properties.testCase != null ) { testCase = ant.project.properties.testCase }
43    else { testCase = null }
44  }
46 includeTargets << new File ( 'config/gant/paths.groovy' )
48 includeTargets << gant.targets.Clean
49 cleanPattern << [ '**/*~' , groovyParserDirectory + '/Groovy*.*' ]
50 cleanPattern << [ 'JavaLexer.java' , '/JavaRecognizer.java' , '/JavaTokenTypes.java' , '/JavaTokenTypes.txt' , '/*.smap'].collect { item -> javaParserDirectory + item }
51 cleanDirectory << targetDirectory
53 target ( initialize : '' ) {
54   mavenAntTaskURI = 'urn:maven-artifact-ant'
55   typedef ( resource : 'org/apache/maven/artifact/ant/antlib.xml' , uri : mavenAntTaskURI ) {
56     classpath { fileset ( dir : bootstrapDirectory ,  includes : 'maven-ant-tasks-*.jar' ) }
57   }
58   "${mavenAntTaskURI}:pom" ( file :'pom.xml' , id : 'groovy.pom' )
59   //"${mavenAntTaskURI}:remoteRepository" ( id : 'mavenCentral' , url : 'http://repo1.maven.org/maven2' )
60   "${mavenAntTaskURI}:dependencies" ( useScope : 'compile' , filesetId : 'fs.compile.groovy' , pomRefId : 'groovy.pom' )
61   "${mavenAntTaskURI}:dependencies" ( useScope : 'runtime' , filesetId : 'fs.runtime.groovy' , pomRefId : 'groovy.pom' )
62   "${mavenAntTaskURI}:dependencies" ( useScope : 'test' , filesetId : 'fs.test.groovy' , pomRefId : 'groovy.pom' )
63   /*
64   delete ( dir : compileLibDirectory )
65   mkdir ( dir : compileLibDirectory )
66   copy ( todir : compileLibDirectory ) {
67     mapper ( type : 'flatten' )
68     fileset ( refid : 'fs.compile.groovy' )
69   }
70   path ( id : 'compilePath' ) {
71     fileset ( dir : compileLibDirectory , includes : '** /*.jar' )
72   }
73   copy ( todir : testLibDirectory ) {
74     mapper ( type : 'flatten' )
75     fileset ( refid : 'fs.test.groovy' )
76   }
77   path ( id : 'testLibPath' ) {
78     fileset ( dir : testLibDirectory , includes : '** /*.jar' )
79   }
80   copy ( todir : runtimeLibDirectory ) {
81     mapper ( type : 'flatten' )
82     fileset ( refid : 'fs.runtime.groovy' )
83   }
84   path ( id : 'runtimePath' ) {
85     fileset ( dir : runtimeLibDirectory , includes : '** /*.jar' )
86   }
88   path ( id : 'compilePath' ) { fileset ( refid : 'fs.compile.groovy' ) }
89   path ( id : 'testLibPath' ) { fileset ( refid : 'fs.test.groovy' ) }
90   path ( id : 'runtimePath' ) { fileset ( refid : 'fs.runtime.groovy' ) }  
93 target ( initializeGroovyc : '' ) {
94   path ( id : 'groovyMainClasses' ) {
95     pathelement ( path : mainClassesDirectory )
96     path ( refid : 'compilePath' )
97   }
98   taskdef ( name : 'groovyc' , classname : 'org.codehaus.groovy.ant.Groovyc' , classpathref : 'groovyMainClasses' )
101  target ( ensureGrammars : 'Ensure all the Antlr generated files are up to date.' ) {
102    depends ( initialize )
103    mkdir ( dir : groovyParserDirectory )
104    antlr ( target : antlrDirectory + '/groovy.g' , outputdirectory : groovyParserDirectory ) { classpath ( refid : 'compilePath' ) }
105    antlr ( target : javaParserDirectory + '/java.g' , outputdirectory : javaParserDirectory ) { classpath ( refid : 'compilePath' ) }
108 target ( checkstyle : 'Create the code style reports.' ) { }
110 target ( cleanTest : 'Clean and compile and test all the classes (or just one class if testCase property is defined).' ) { }
112 target ( compileExamples  : 'Compile the Java and Groovy code in the examples source directory.' ) { }
114 target ( compileMain : 'Compile the Java and Groovy code in the main source.' ) {
115   depends ( ensureGrammars )
116   mkdir ( dir : mainClassesDirectory )
117   //mkdir ( dir : toolsClassesDirectory )
118   //  Copy over all the resources.
119   copy ( todir : mainClassesDirectory ) {
120     fileset ( dir : mainSourceDirectory ) {
121       include ( name : 'groovy/ui/*.properties' )
122       include ( name : 'groovy/ui/**/*.png' )
123       include ( name : 'org/codehaus/groovy/tools/shell/**/*.properties' )
124       include ( name : 'org/codehaus/groovy/tools/shell/**/*.xml' )
125     }
126   }
127   // Start the initial compile.
128   javac ( srcdir : mainSourceDirectory , includeantruntime : 'false' , destdir : mainClassesDirectory ,
129           deprecation : 'on' , debug : 'yes' , source : '1.5' , target : '1.5' , fork : 'true' , classpathref : 'compilePath' ,
130           excludes : 'groovy/ui/**/*.java' )
131   //  The Groovyc class is now compiled so we can make use of it.
132   initializeGroovyc ( )
133   //  This compilation takes a lot of heap space, hence adding the extra.
134   groovyc ( srcdir : mainSourceDirectory , destdir : mainClassesDirectory , fork : 'true' , memorymaximumsize : ant.project.properties.groovycMain_mx ) {
135     classpath{  
136       pathelement ( path : mainClassesDirectory )
137       path ( refid : 'compilePath' )
138     }
139     javac ( deprecation : 'on' , debug : 'yes' , source : '1.5' , target : '1.5' )
140   }
141   message ( 'java' , 'Running DgmConverter.' )
142   java ( classname : 'org.codehaus.groovy.tools.DgmConverter' , fork : 'yes' , failonerror : 'true' ) {
143     classpath ( refid : 'compilePath' )
144     classpath ( path : mainClassesDirectory )
145   }
148 target ( compileTest : 'Compile the Java and Groovy code in the test source.' ) {
149   depends ( compileMain )
150   mkdir ( dir : testClassesDirectory )
151   //  This compilation takes a lot of heap space, hence adding the extra.
152   groovyc ( srcdir : testSourceDirectory , destdir : testClassesDirectory , //includes="${vm5GroovySourceFiles},${vm5JavaSourceFiles}"
153             fork : 'true' ,  memorymaximumsize : ant.project.properties.groovycTest_mx ) {
154     classpath {
155       pathelement ( path : testClassesDirectory )
156       path ( refid : 'groovyMainClasses' )
157       path ( refid : 'testLibPath' )
158     }
159     javac ( source : '1.5' , target : '1.5' , nowarn : 'on' )
160   }
163 target ( createJars : 'Build Groovy and create the jarfiles.' ) { }
165 target ( deploy : 'Deploy jars to maven repository.' ) { }
167 target ( dist : 'Alias to distribution for the lazy.' ) { }
169 target ( distribution : 'Create everything needed for a distribution.' ) { }
171 target ( doc : 'Create the documentation.' ) { }
173 target ( docGDK : 'Create the GDK documentation' ) { }
175 target (  install : 'Create an installation hierarchy in target/install.' ) { }
177 target ( installRepo : 'Deploy artifacts to local maven repository.' ) { }
179 target ( javadoc : 'Create the javadoc documentation.' ) { }
181 target ( test : 'Compile and test all the classes (or just one class if testCase property is defined).' ) {
182   depends ( compileTest )
183   if ( coverage ) {
184     mkdir ( dir : instrumentedClassesDirectory )
185     coberturaInstrument ( classesDirectory : mainClassesDirectory )
186   }
187   mkdir ( dir : junitRawDirectory )
188   junit ( printsummary : 'true' , fork : 'true' , includeantruntime : 'false' , failureproperty : 'testFailed' , maxmemory : ant.project.properties.groovyJUnit_mx , dir : ant.project.properties.basedir ) {
189     //jvmarg ( line : "-Xms${ant.project.properties.groovyJUnit_ms} -XX:PermSize=${ant.project.properties.groovyJUnit_permSize} -XX:MaxPermSize=${ant.project.properties.groovyJUnit_maxPermSize} ${ ( System.properties.'java.awt.headless' || ( System.properties.'os.name' == 'Mac OS X' ) ) ? '-Djava.awt.headless=true' : '' }" )
190     if ( testCase != null ) {
191       //
192       //  There is a search order "bug" in that the list of targets is searched before the list of things
193       //  possible in the AntBuilder.  How to avoid this and thence the infinite recursion.  For now put the
194       //  ant. in explicitly.
195       //
196       ant.test ( name : testCase , todir : junitRawDirectory )
197       formatter ( type : 'brief' , usefile : 'false' )
198     }
199     else {
200       formatter ( type : 'xml' )
201       formatter ( type : 'plain' , unless : 'noTextReports' )
202       batchtest ( todir : junitRawDirectory ) {
203         fileset ( dir : testClassesDirectory , includes : 'UberTest*.class' )
204       }
205     }
206     classpath {
207       if ( coverage ) { pathelement ( path : instrumentedClassesDirectory) }
208       pathelement ( path : 'src/test' )
209       path ( refid : 'groovyMainClasses' )
210       path ( refid : 'testLibPath' )
211       pathelement ( path : testClassesDirectory )
212       if ( coverage ) { path ( refid : 'coberturaPath' ) }
213     }
214   }
215   if ( testCase == null ) {
216     //mkdir ( dir : reportsDirectory )
217     mkdir ( dir : junitReportsDirectory )
218     junitreport ( tofile : "${junitRawDirectory}/Results.xml") {
219       fileset ( dir : junitRawDirectory , includes : 'TEST-*.xml' )
220       report ( format : 'frames' , todir : junitReportsDirectory )
221     }
222   }
225 setDefaultTarget ( createJars )