KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > OPP > compiler > AbstractJavaCompiler


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: AbstractJavaCompiler.java,v 1.2.2.1 2004/01/11 20:42:34 per_nyfelt Exp $
8
package org.ozoneDB.tools.OPP.compiler;
9
10 import java.io.File JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 /**
17  * Abstract configuration interface for JDK build compilers.
18  *
19  * Date: 2003-sep-21
20  * Time: 15:04:09
21  */

22 public abstract class AbstractJavaCompiler implements JavaCompiler {
23     private String JavaDoc classpath;
24     private boolean optimize;
25     private boolean debug;
26     private boolean noWarn;
27     private boolean deprecation;
28     private File JavaDoc sourcePath;
29     private File JavaDoc outputPath;
30
31     public File JavaDoc getOutputPath() {
32         return outputPath;
33     }
34
35     public void setOutputPath(File JavaDoc outputPath) {
36         this.outputPath = outputPath;
37     }
38
39     public boolean isOptimize() {
40         return optimize;
41     }
42
43     public void setOptimize(boolean optimize) {
44         this.optimize = optimize;
45     }
46
47     public boolean isDebug() {
48         return debug;
49     }
50
51     public void setDebug(boolean debug) {
52         this.debug = debug;
53     }
54
55     public boolean isNoWarn() {
56         return noWarn;
57     }
58
59     public void setNoWarn(boolean noWarn) {
60         this.noWarn = noWarn;
61     }
62
63     public boolean isDeprecation() {
64         return deprecation;
65     }
66
67     public void setDeprecation(boolean deprecation) {
68         this.deprecation = deprecation;
69     }
70
71     public File JavaDoc getSourcePath() {
72         return sourcePath;
73     }
74
75     public void setSourcePath(File JavaDoc sourcePath) {
76         this.sourcePath = sourcePath;
77     }
78
79     public String JavaDoc getClasspath() {
80         return classpath;
81     }
82
83     public void setClasspath(String JavaDoc classpath) {
84         this.classpath = classpath;
85     }
86
87     protected String JavaDoc[] getArguments(Collection JavaDoc classes) {
88         return getArguments(null, classes);
89     }
90
91     /**
92      * Returns command line arguments from the compiler settings.
93      * @param command Compiler command, skipped if null.
94      * @param classes The number classes to compile
95      * @return The array of a arguments
96      */

97     protected String JavaDoc[] getArguments(String JavaDoc command, Collection JavaDoc classes) {
98         List JavaDoc arguments = new ArrayList JavaDoc(classes.size() + 10);
99         if (command != null) {
100             arguments.add(command);
101         }
102         if (classpath != null) {
103             arguments.add("-classpath");
104             arguments.add(getClasspath());
105         }
106         if (optimize) {
107             arguments.add("-O");
108         }
109         if (debug) {
110             arguments.add("-g");
111         } else {
112             arguments.add("-g:none");
113         }
114         if (noWarn) {
115             arguments.add("-noWarn");
116         }
117         if (deprecation) {
118             arguments.add("-deprecation");
119         }
120         if (sourcePath != null) {
121             arguments.add("-sourcepath");
122             arguments.add(sourcePath.toString());
123             //arguments.add(sourcePath.getAbsolutePath());
124
}
125         if (outputPath != null) {
126             arguments.add("-d");
127             arguments.add(outputPath.toString());
128             //arguments.add(outputPath.getAbsolutePath());
129
}
130         arguments.addAll(classes);
131         String JavaDoc retArgs[] = new String JavaDoc[arguments.size()];
132         int i = 0;
133         for (Iterator JavaDoc iter = arguments.iterator(); iter.hasNext(); i++) {
134             retArgs[i] = (String JavaDoc) iter.next();
135             //System.out.println(retArgs[i]);
136
}
137         return retArgs;
138     }
139 }
140
Popular Tags