View Javadoc

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  package org.apache.commons.jci.compilers;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  public final class JavacJavaCompilerSettings extends JavaCompilerSettings {
24  
25      private boolean optimize;
26      private String memMax;
27      private String memInitial;
28      private String[] customArguments;
29  
30      public JavacJavaCompilerSettings() {    	
31      }
32      
33      public JavacJavaCompilerSettings( final JavaCompilerSettings pSettings ) {
34      	super(pSettings);
35      }
36      
37      
38      public void setCustomArguments( final String[] pCustomArguments ) {
39      	customArguments = pCustomArguments;
40      }
41      
42      public String[] getCustomArguments() {
43      	return customArguments;
44      }
45      
46      
47      public void setMaxMemory( final String pMemMax ) {
48      	memMax = pMemMax;
49      }
50      
51      public String getMaxMemory() {
52      	return memMax;
53      }
54      
55      
56      public void setInitialMemory( final String pMemInitial ) {
57      	memInitial = pMemInitial;
58      }
59      
60      public String getInitialMemory() {
61      	return memInitial;
62      }
63  
64      
65      public boolean isOptimize() {
66          return optimize;
67      }
68  
69      public void setOptimize( final boolean pOptimize ) {
70          optimize = pOptimize;
71      }
72  
73      
74      
75      /** @deprecated */
76      public List getCustomCompilerArguments() {
77      	final List list = new ArrayList();
78      	for (int i = 0; i < customArguments.length; i++) {
79  			list.add(customArguments[i]);
80  		}
81      	return list;    	
82      }
83  
84      /** @deprecated */
85      public void setCustomCompilerArguments(List customCompilerArguments) {
86      	customArguments = (String[]) customCompilerArguments.toArray(new String[customCompilerArguments.size()]);
87      }
88  
89      /** @deprecated */
90      public String getMaxmem() {
91          return memMax;
92      }
93  
94      /** @deprecated */
95      public void setMaxmem(String maxmem) {
96          this.memMax = maxmem;
97      }
98  
99      /** @deprecated */
100     public String getMeminitial() {
101         return memInitial;
102     }
103 
104     /** @deprecated */
105     public void setMeminitial(String meminitial) {
106         this.memInitial = meminitial;
107     }
108 
109     
110     
111     
112     String[] toNativeSettings() {
113     	
114     	final List args = new ArrayList();
115 
116     	if (isOptimize()) {
117     		args.add("-O");
118     	}
119 
120     	if (isDebug()) {
121     		args.add("-g");
122     	}
123 
124     	if (isDeprecations()) {
125     		args.add("-deprecation");
126     	}
127 
128     	if (!isWarnings() && !isDeprecations()) {
129     		args.add("-nowarn");
130     	}
131 
132     	if (getMaxMemory() != null) {
133     		args.add("-J-Xmx" + getMaxMemory());
134     	}
135 
136     	if (getInitialMemory() != null) {
137     		args.add("-J-Xms" + getInitialMemory());
138     	}
139 
140     	args.add("-target");
141     	args.add(getTargetVersion());
142 
143     	args.add("-source");
144     	args.add(getSourceVersion());
145 
146     	args.add("-encoding");
147     	args.add(getSourceEncoding());
148 
149     	if (customArguments != null) {
150 	    	for (int i = 0; i < customArguments.length; i++) {
151 				args.add(customArguments[i]);
152 			}
153     	}
154 
155     	return (String[])args.toArray(new String[args.size()]);
156     }
157 }