preparing for EJC integration: implement more specific StandardJavaFileManager

This commit is contained in:
Eugene Zhuravlev
2012-07-03 16:06:27 +02:00
parent 86daffebc1
commit 6e276d798e
2 changed files with 53 additions and 19 deletions
@@ -17,7 +17,7 @@ import java.util.Set;
* @author Eugene Zhuravlev
* Date: 9/24/11
*/
class JavacFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
class JavacFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> implements StandardJavaFileManager{
private final Context myContext;
private Map<File, Set<File>> myOutputsMap = Collections.emptyMap();
@@ -37,26 +37,36 @@ class JavacFileManager extends ForwardingJavaFileManager<StandardJavaFileManager
myContext = context;
}
public boolean setOutputDirectories(final Map<File, Set<File>> outputDirToSrcRoots) {
public void setOutputDirectories(final Map<File, Set<File>> outputDirToSrcRoots) throws IOException{
for (File outputDir : outputDirToSrcRoots.keySet()) {
// this will validate output dirs
if (!setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(outputDir))) {
return false;
}
setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(outputDir));
}
myOutputsMap = outputDirToSrcRoots;
return true;
}
public boolean setLocation(Location location, Iterable<? extends File> path) {
try {
getStdManager().setLocation(location, path);
}
catch (IOException e) {
myContext.reportMessage(Diagnostic.Kind.ERROR, e.getMessage());
return false;
}
return true;
public void setLocation(Location location, Iterable<? extends File> path) throws IOException{
getStdManager().setLocation(location, path);
}
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
return getStdManager().getJavaFileObjectsFromFiles(files);
}
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
return getStdManager().getJavaFileObjects(files);
}
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
return getStdManager().getJavaFileObjectsFromStrings(names);
}
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
return getStdManager().getJavaFileObjects(names);
}
public Iterable<? extends File> getLocation(Location location) {
return getStdManager().getLocation(location);
}
public boolean isSameFile(FileObject a, FileObject b) {
@@ -213,4 +223,8 @@ class JavacFileManager extends ForwardingJavaFileManager<StandardJavaFileManager
throw new CompilationCanceledException();
}
}
public Context getContext() {
return myContext;
}
}
@@ -7,6 +7,7 @@ import org.jetbrains.jps.server.ClasspathBootstrap;
import javax.tools.*;
import java.io.File;
import java.io.IOException;
import java.util.*;
/**
@@ -41,19 +42,38 @@ public class JavacMain {
fileManager.handleOption("-bootclasspath", Collections.singleton("").iterator()); // this will clear cached stuff
fileManager.handleOption("-extdirs", Collections.singleton("").iterator()); // this will clear cached stuff
fileManager.setOutputDirectories(outputDirToRoots);
try {
fileManager.setOutputDirectories(outputDirToRoots);
}
catch (IOException e) {
fileManager.getContext().reportMessage(Diagnostic.Kind.ERROR, e.getMessage());
return false;
}
if (!classpath.isEmpty()) {
if (!fileManager.setLocation(StandardLocation.CLASS_PATH, classpath)) {
try {
fileManager.setLocation(StandardLocation.CLASS_PATH, classpath);
}
catch (IOException e) {
fileManager.getContext().reportMessage(Diagnostic.Kind.ERROR, e.getMessage());
return false;
}
}
if (!platformClasspath.isEmpty()) {
if (!fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, platformClasspath)) {
try {
fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, platformClasspath);
}
catch (IOException e) {
fileManager.getContext().reportMessage(Diagnostic.Kind.ERROR, e.getMessage());
return false;
}
}
if (!sourcePath.isEmpty()) {
if (!fileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePath)) {
try {
fileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePath);
}
catch (IOException e) {
fileManager.getContext().reportMessage(Diagnostic.Kind.ERROR, e.getMessage());
return false;
}
}