View Javadoc
1 /* FOREGEJ - FOrmatting REfactoring GEnerating Java 2 * 3 * Copyright (C) 2003 Andreas Arrgard 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 package com.octagroup.foregej.ant; 20 import java.io.File; 21 import java.io.IOException; 22 import java.util.StringTokenizer; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.DirectoryScanner; 25 import org.apache.tools.ant.Task; 26 import org.apache.tools.ant.types.FileSet; 27 import antlr.RecognitionException; 28 import antlr.TokenStreamException; 29 import com.octagroup.foregej.java.lang.ast.CompilationUnit; 30 import com.octagroup.foregej.java.tools.ToolRunner; 31 import com.octagroup.foregej.java.util.CompilationUnitStore; 32 /*** 33 * This ANT task is used to trigger a set of tools in the Foregej system. 34 */ 35 public class ToolTask extends Task 36 { 37 /*** 38 * the files to process 39 */ 40 private FileSet files_=null; 41 /*** 42 * Sets the files to process. 43 * 44 * @param fs the files to process. 45 */ 46 public void addSrc(FileSet fs) 47 { 48 files_=fs; 49 } 50 /*** 51 * Sets the tools to use. 52 * 53 * @param tools 54 */ 55 public void setTools(String tools) 56 { 57 try{ 58 StringTokenizer st=new StringTokenizer(tools, ",", false); 59 while(st.hasMoreTokens()){ 60 String toolName=st.nextToken(); 61 Class tool=Class.forName("com.octagroup.foregej.java.tools."+toolName.toLowerCase()+"."+toolName+"Tool"); 62 ToolRunner.getInstance().addTool(tool); 63 } 64 }catch (ClassNotFoundException e) { 65 throw new BuildException("Failed to load tool:ClassNotFoundException:"+e.getMessage()); 66 } 67 } 68 /*** 69 * Performs the work 70 */ 71 public void execute() 72 { 73 try{ 74 if(files_==null) { 75 throw new BuildException("Must supply some source files..."); 76 } 77 DirectoryScanner ds=files_.getDirectoryScanner(getProject()); 78 String[] files=ds.getIncludedFiles(); 79 CompilationUnitStore compilationUnitStore=CompilationUnitStore.getInstance(); 80 compilationUnitStore.setBaseDir(ds.getBasedir()); 81 for(int i=0; i<files.length; i++){ 82 File source=new File(ds.getBasedir(), files[i]); 83 CompilationUnit cu=compilationUnitStore.getCompilationUnit(source); 84 ToolRunner.getInstance().process(cu); 85 } 86 compilationUnitStore.flush(); 87 }catch (RecognitionException e) { 88 e.printStackTrace(); 89 throw new BuildException(e); 90 }catch (TokenStreamException e) { 91 e.printStackTrace(); 92 throw new BuildException(e); 93 }catch (IOException e) { 94 e.printStackTrace(); 95 throw new BuildException(e); 96 } 97 } 98 }

This page was automatically generated by Maven