KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > jsp > compilers > DefaultJspCompilerAdapter


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs.optional.jsp.compilers;
20
21 import java.io.File JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.util.Vector JavaDoc;
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.taskdefs.optional.jsp.JspC;
26 import org.apache.tools.ant.types.CommandlineJava;
27
28 /**
29  * This is the default implementation for the JspCompilerAdapter interface.
30  * This is currently very light on the ground since only one compiler type is
31  * supported.
32  *
33  */

34 public abstract class DefaultJspCompilerAdapter
35     implements JspCompilerAdapter {
36
37     private static String JavaDoc lSep = System.getProperty("line.separator");
38
39     /**
40      * Logs the compilation parameters, adds the files to compile and logs the
41      * "niceSourceList"
42      * @param jspc the compiler task for logging
43      * @param compileList the list of files to compile
44      * @param cmd the command line used
45      */

46     protected void logAndAddFilesToCompile(JspC jspc,
47                                            Vector JavaDoc compileList,
48                                            CommandlineJava cmd) {
49         jspc.log("Compilation " + cmd.describeJavaCommand(),
50                  Project.MSG_VERBOSE);
51
52         StringBuffer JavaDoc niceSourceList = new StringBuffer JavaDoc("File");
53         if (compileList.size() != 1) {
54             niceSourceList.append("s");
55         }
56         niceSourceList.append(" to be compiled:");
57
58         niceSourceList.append(lSep);
59
60         Enumeration JavaDoc e = compileList.elements();
61         while (e.hasMoreElements()) {
62             String JavaDoc arg = (String JavaDoc) e.nextElement();
63             cmd.createArgument().setValue(arg);
64             niceSourceList.append(" ");
65             niceSourceList.append(arg);
66             niceSourceList.append(lSep);
67         }
68
69         jspc.log(niceSourceList.toString(), Project.MSG_VERBOSE);
70     }
71
72     // CheckStyle:VisibilityModifier OFF - bc
73

74     /**
75      * our owner
76      */

77     protected JspC owner;
78
79     // CheckStyle:VisibilityModifier ON
80

81     /**
82      * set the owner
83      * @param owner the owner JspC compiler
84      */

85     public void setJspc(JspC owner) {
86         this.owner = owner;
87     }
88
89     /** get the owner
90      * @return the owner; should never be null
91      */

92     public JspC getJspc() {
93         return owner;
94     }
95
96
97     /**
98      * add an argument oneple to the argument list, if the value aint null
99      * @param cmd the command line
100      * @param argument The argument
101      */

102     protected void addArg(CommandlineJava cmd, String JavaDoc argument) {
103         if (argument != null && argument.length() != 0) {
104            cmd.createArgument().setValue(argument);
105         }
106     }
107
108
109     /**
110      * add an argument tuple to the argument list, if the value aint null
111      * @param cmd the command line
112      * @param argument The argument
113      * @param value the parameter
114      */

115     protected void addArg(CommandlineJava cmd, String JavaDoc argument, String JavaDoc value) {
116         if (value != null) {
117             cmd.createArgument().setValue(argument);
118             cmd.createArgument().setValue(value);
119         }
120     }
121
122     /**
123      * add an argument tuple to the arg list, if the file parameter aint null
124      * @param cmd the command line
125      * @param argument The argument
126      * @param file the parameter
127      */

128     protected void addArg(CommandlineJava cmd, String JavaDoc argument, File JavaDoc file) {
129         if (file != null) {
130             cmd.createArgument().setValue(argument);
131             cmd.createArgument().setFile(file);
132         }
133     }
134
135     /**
136      * ask if compiler can sort out its own dependencies
137      * @return true if the compiler wants to do its own
138      * depends
139      */

140     public boolean implementsOwnDependencyChecking() {
141         return false;
142     }
143
144     /**
145      * get our project
146      * @return owner project data
147      */

148     public Project getProject() {
149         return getJspc().getProject();
150     }
151 }
152
153
Popular Tags