@ Override public void execute ( ) throws BuildException { // // At first it might seem appropriate to use the Project object from the calling Ant instance as the // Project object used by the AntBuilder object and hence GantBuilder object associated with the Gant // instance we are going to create here. However, if we just use that Project object directly then // there are problems with proper annotation of the lines of output, so it isn't really an option. // Therefore create a new Project instance and set the things appropriately from the original Project // object. // // Issues driving things here are GANT-50 and GANT-80. GANT-50 is about having the correct base // directory for operations, GANT-80 is about ensuring that all output generation actually generated // observable output. // // NB As this class is called Gant, we have to use fully qualified name to get to the Gant main class. // final Project antProject = getOwningTarget ( ) . getProject ( ) ; final Project newProject = new Project ( ) ; newProject . init ( ) ; // Deal with GANT-80 by getting all the the loggers from the Ant instance Project object and adding // them to the new Project Object. This was followed up by GANT-91 so the code was amended to copying // over all listeners except the class loader if present. for ( final Object o : antProject . getBuildListeners ( ) ) { final BuildListener listener = ( BuildListener ) o ; if ( ! ( listener instanceof AntClassLoader ) ) { newProject . addBuildListener ( listener ) ; } } // Deal with GANT-50 by getting the base directory from the Ant instance Project object and use it for // the new Project object. GANT-93 leads to change in the way the Gant file is extracted. newProject . setBaseDir ( antProject . getBaseDir ( ) ) ; // Deal with GANT-110 by using the strategy proposed by Eric Van Dewoestine. if ( inheritAll ) { addAlmostAll ( newProject , antProject ) ; } final File gantFile = newProject . resolveFile ( file ) ; if ( ! gantFile . exists ( ) ) { throw new BuildException ( "Gantfile does not exist." , getLocation ( ) ) ; } final GantBuilder ant = new GantBuilder ( newProject ) ; final Map < String , String > environmentParameter = new HashMap < String , String > ( ) ; environmentParameter . put ( "environment" , "environment" ) ; ant . invokeMethod ( "property" , new Object [ ] { environmentParameter } ) ; final GantBinding binding = new GantBinding ( ) ; binding . forcedSettingOfVariable ( "ant" , ant ) ; for ( final Definition definition : definitions ) { final Map < String , String > definitionParameter = new HashMap < String , String > ( ) ; definitionParameter . put ( "name" , definition . getName ( ) ) ; definitionParameter . put ( "value" , definition . getValue ( ) ) ; ant . invokeMethod ( "property" , new Object [ ] { definitionParameter } ) ; } final gant . Gant gant = new gant . Gant ( binding ) ; gant . loadScript ( gantFile ) ; final List < String > targetsAsStrings = new ArrayList < String > ( ) ; for ( final GantTarget g : targets ) { targetsAsStrings . add ( g . getValue ( ) ) ; } final int returnCode = gant . processTargets ( targetsAsStrings ) ; if ( returnCode != 0 ) { throw new BuildException ( "Gant execution failed with return code " + returnCode + ' ' , getLocation ( ) ) ; } }
Load the file and then execute it .