1 package org.apache.beehive.netui.xdoclet; 2 3 import org.apache.beehive.netui.compiler.typesystem.util.SourcePosition; 4 import org.apache.tools.ant.BuildException; 5 import xdoclet.DocletTask; 6 7 import java.io.File ; 8 import java.util.ArrayList ; 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 18 public class NetuiDocletTask extends DocletTask 19 { 20 private static HashMap _buildMessages = new HashMap (); 22 private static File _webappRoot = null; 23 24 25 26 30 protected void start() throws BuildException 31 { 32 try 33 { 34 assert _webappRoot != null; super.start(); 36 } 37 finally 38 { 39 _webappRoot = null; 40 41 boolean overallError = false; 43 if ( _buildMessages != null ) 44 { 45 Iterator i = _buildMessages.keySet().iterator(); 46 47 while ( i.hasNext() ) 48 { 49 String sourceFile = ( String ) i.next(); 50 List messages = ( List ) _buildMessages.get( sourceFile ); 51 int errorCount = 0; 52 int warningCount = 0; 53 54 for ( Iterator j = messages.iterator(); j.hasNext(); ) 55 { 56 BuildMessage message = ( BuildMessage ) j.next(); 57 System.err.println(); 58 System.err.print( sourceFile ); 59 System.err.print( ": " ); 60 61 if ( message.getLine() > 0 ) 62 { 63 String [] args = { new Integer ( message.getLine() ).toString() }; 64 System.err.println( XDocletCompilerUtils.getMessage( "compiler.line", args ) ); 65 } 66 67 if ( message.isError() ) 68 { 69 overallError = true; 70 ++errorCount; 71 } 72 else 73 { 74 System.err.print( XDocletCompilerUtils.getMessage( "compiler.warning", null ) ); 75 ++warningCount; 76 } 77 78 System.err.println( message.getMessage() ); 79 } 80 81 System.err.println( XDocletCompilerUtils.getMessage( "compiler.build.results", 82 new String []{ new Integer ( errorCount ).toString(), 83 new Integer ( warningCount ).toString(), 84 sourceFile } ) ); 85 } 86 } 87 88 _buildMessages = null; 89 90 if ( overallError ) 91 { 92 System.err.println( XDocletCompilerUtils.getMessage( "compiler.build.failed", null ) ); 93 throw new NetuiBuildException(); 94 } 95 } 96 } 97 98 public static void addError( String error, SourcePosition sourcePosition ) 99 { 100 assert sourcePosition != null; 101 String sourceFilePath = sourcePosition.file().getPath(); 102 int line = sourcePosition.line(); 103 addError( error, sourceFilePath, line ); 104 } 105 106 public static void addError( String error, String sourceFile, int line ) 107 { 108 List messages = ( List ) _buildMessages.get( sourceFile ); 109 110 if ( messages == null ) 111 { 112 messages = new ArrayList (); 113 _buildMessages.put( sourceFile, messages ); 114 } 115 116 messages.add( new BuildMessage( error, line, true ) ); 117 } 118 119 public static void addWarning( String warning, SourcePosition sourcePosition ) 120 { 121 assert sourcePosition != null; 122 String sourceFilePath = sourcePosition.file().getPath(); 123 int line = sourcePosition.line(); 124 addWarning( warning, sourceFilePath, line ); 125 } 126 127 public static void addWarning( String warning, String sourceFile, int line ) 128 { 129 List messages = ( List ) _buildMessages.get( sourceFile ); 130 131 if ( messages == null ) 132 { 133 messages = new ArrayList (); 134 _buildMessages.put( sourceFile, messages ); 135 } 136 137 messages.add( new BuildMessage( warning, line, false ) ); 138 } 139 140 private static class BuildMessage 141 { 142 private String _message; 143 private boolean _error; 144 private int _line; 145 146 public BuildMessage( String message, int line, boolean error ) 147 { 148 _message = message; 149 _error = error; 150 _line = line; 151 } 152 153 public final String getMessage() 154 { 155 return _message; 156 } 157 158 public final boolean isError() 159 { 160 return _error; 161 } 162 163 public final int getLine() 164 { 165 return _line; 166 } 167 } 168 169 174 protected void validateOptions() throws BuildException 175 { 176 if ( getDestDir() == null ) 179 { 180 setDestDir( new File ( "bogus" ) ); 181 } 182 super.validateOptions(); 183 } 184 185 public void setWebappRoot( File file ) 186 { 187 _webappRoot = file; 188 } 189 190 public static File getWebappRoot() 191 { 192 return _webappRoot; 193 } 194 195 } 196 | Popular Tags |