01: /**
02: * Copyright 2007 Jens Dietrich Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
05: * Unless required by applicable law or agreed to in writing, software distributed under the
06: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
07: * either express or implied. See the License for the specific language governing permissions
08: * and limitations under the License.
09: */package nz.org.take.deployment.jsr199;
10:
11: import java.io.File;
12: import java.util.ArrayList;
13: import java.util.Arrays;
14: import java.util.List;
15:
16: import javax.tools.JavaFileObject;
17: import javax.tools.StandardJavaFileManager;
18: import javax.tools.ToolProvider;
19:
20: import nz.org.take.TakeException;
21: import nz.org.take.deployment.CompilerAdapter;
22:
23: /**
24: * Compiler adapter based on JSR199. This is the default adapter.
25: * The main reason to have alternative adapters is JDK1.5 compatibility.
26: * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
27: */
28:
29: public class JSR199CompilerAdapter implements CompilerAdapter {
30:
31: @Override
32: public void compile(String packageName, String srcFolder,
33: String binFolder) throws TakeException {
34: String javaFolder = srcFolder + packageName.replace('.', '/');
35:
36: File[] files = new File(javaFolder).listFiles();
37: List<File> sources = new ArrayList<File>();
38: for (File f : files) {
39: if (f.getAbsolutePath().endsWith(".java"))
40: sources.add(f);
41: }
42:
43: javax.tools.JavaCompiler compiler = ToolProvider
44: .getSystemJavaCompiler();
45: StandardJavaFileManager fileManager = compiler
46: .getStandardFileManager(null, null, null);
47: Iterable<? extends JavaFileObject> compilationUnits1 = fileManager
48: .getJavaFileObjectsFromFiles(sources);
49: String[] options = new String[] { "-d", binFolder };
50: compiler.getTask(null, fileManager, null,
51: Arrays.asList(options), null, compilationUnits1).call();
52:
53: }
54:
55: }
|