001 /* 002 * Copyright 2005 Stephen J. McConnell 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.tools.tasks; 020 021 import java.io.File; 022 023 import net.dpml.library.info.Scope; 024 025 import net.dpml.tools.Context; 026 027 import org.apache.tools.ant.Project; 028 import org.apache.tools.ant.types.Path; 029 030 /** 031 * Cleanup of generated target directory. 032 * 033 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 034 * @version 1.2.0 035 */ 036 public class BuildTask extends GenericTask 037 { 038 /** 039 * Compiles main and test classes resulting in the creation of the 040 * target/classes/main and target/classes/test directories. 041 */ 042 public void execute() 043 { 044 // If a target/build/main or target/build/test exists then we should be 045 // triggering content compilation. Compilation requires project input 046 // with respect to javac source selection and subsequent rmic 047 // postprocessing (both of which can be expressed as process data associated 048 // with the target/build/main and target/build/test directories). In addition 049 // there may be additional processes that need to be triggered (such as 050 // type compilation which consumes compiled classes). 051 052 Context context = getContext(); 053 if( context.getTargetBuildMainDirectory().exists() ) 054 { 055 // we need to add in here the aquisition of javac task 056 // parameters based on transformation directives associated 057 // with the target/classes/main directory 058 059 Project project = context.getProject(); 060 final JavacTask task = new JavacTask( context ); 061 task.setProject( project ); 062 task.init(); 063 task.execute(); 064 } 065 066 // conditionaly compile test classes 067 068 File source = context.getTargetBuildTestDirectory(); 069 if( source.exists() ) 070 { 071 // we need to add in here the aquisition of javac task 072 // parameters based on transformation directives associated 073 // with the target/classes/main directory 074 075 Project project = context.getProject(); 076 final JavacTask task = new JavacTask( context ); 077 task.setProject( project ); 078 File destination = context.getTargetClassesTestDirectory(); 079 task.setSrc( source ); 080 task.setDest( destination ); 081 Path path = context.getPath( Scope.TEST ); 082 File main = context.getTargetClassesMainDirectory(); 083 if( main.exists() ) 084 { 085 path.createPathElement().setLocation( main ); 086 } 087 task.setClasspath( path ); 088 task.init(); 089 task.execute(); 090 } 091 } 092 }