Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 68640 Details for
Bug 188796
[jsr199] Using JSR199 to extend ECJ
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Testcase that works with javac but fails with ecj
LoggingCompiler.java (text/plain), 6.42 KB, created by
talper
on 2007-05-24 15:02:22 EDT
(
hide
)
Description:
Testcase that works with javac but fails with ecj
Filename:
MIME Type:
Creator:
talper
Created:
2007-05-24 15:02:22 EDT
Size:
6.42 KB
patch
obsolete
>package example; > >import java.io.File; >import java.io.FileFilter; >import java.io.IOException; >import java.io.PrintStream; >import java.io.PrintWriter; >import java.util.Arrays; >import java.util.Iterator; >import java.util.LinkedList; >import java.util.List; >import java.util.Set; > >import javax.tools.FileObject; >import javax.tools.ForwardingJavaFileManager; >import javax.tools.JavaCompiler; >import javax.tools.JavaFileObject; >import javax.tools.StandardJavaFileManager; >import javax.tools.JavaCompiler.CompilationTask; >import javax.tools.JavaFileObject.Kind; > >import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler; > >public class LoggingCompiler { > > public static void main(String[] args) throws Exception { > if(args==null || args.length<2 || args.length>3) { > System.out.println("Usage: LoggingCompiler <source dir> <classpath> [-useECJ]"); > System.exit(1); > } > JavaCompiler compiler = null; > boolean useECJ = false; > String srcDir = args[0]; > String cp = args[1]; > if(args.length==3 && "-useECJ".equals(args[2])) > useECJ = true; > if(useECJ) > compiler = new EclipseCompiler(new PrintWriter(System.out), new PrintWriter(System.err), false); > else > compiler = javax.tools.ToolProvider.getSystemJavaCompiler(); > StandardJavaFileManager stdJFileManager = compiler.getStandardFileManager(null, null, null); > ForwardingJavaFileManager<StandardJavaFileManager> myFileManager = new LoggingFileManager(stdJFileManager, System.out); > List<JavaFileObject> compilationUnits = new LinkedList<JavaFileObject>(); > addSources(compilationUnits, new File(srcDir), stdJFileManager); > Iterable<String> options = new LinkedList<String>(Arrays.asList("-classpath",cp)); > CompilationTask ct = compiler.getTask(new PrintWriter(System.out), myFileManager, null, options, null, compilationUnits); > > if(ct.call()) > System.out.println("Compile successful."); > else > System.out.println("Compile failed."); > > } > > private static void addSources(List<JavaFileObject> compilationUnits, File dir, StandardJavaFileManager stdJFileManager) { > File [] sourceFiles = dir.listFiles(new FileFilter() { > public boolean accept(File pathname) { > if(pathname.isFile() && pathname.getName().matches(".+\\.[jJ][aA][vV][aA]")) > return true; > return false; > } > }); > for(JavaFileObject fileObject : stdJFileManager.getJavaFileObjectsFromFiles(Arrays.asList(sourceFiles))) { > compilationUnits.add(fileObject); > } > File [] childDirs = dir.listFiles(new FileFilter() { > public boolean accept(File pathname) { > return pathname.isDirectory(); > } > }); > for(File nextDir : childDirs) { > addSources(compilationUnits, nextDir, stdJFileManager); > } > } > >} > >class LoggingFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> { > > private static int instanceCounter = 0; > private int instance; > private PrintStream out; > public LoggingFileManager(StandardJavaFileManager fileManager, PrintStream out) { > super(fileManager); > instance = LoggingFileManager.instanceCounter++; > this.out = out; > } > > private void log(String method, Object ... args) { > out.print("LFM" + instance + ": " + method + "("); > if(args!=null && args.length>0) { > boolean firstArg = true; > for(Object arg : args) { > if(firstArg) > firstArg = false; > else > out.print(", "); > out.print(arg.toString()); > } > } > out.println(")"); > } > > private void logReturn(Object retValue) { > out.print("LFM" + instance + ": -ret- "); > out.println(retValue.toString()); > } > > @Override > public void close() throws IOException { > log("close"); > super.close(); > } > > @Override > public void flush() throws IOException { > log("flush"); > super.flush(); > } > > @Override > public ClassLoader getClassLoader(Location location) { > log("getClassLoader", location); > ClassLoader ret = super.getClassLoader(location); > logReturn(ret); > return ret; > } > > @Override > public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { > log("getFileForInput", location, packageName, relativeName); > FileObject ret = super.getFileForInput(location, packageName, relativeName); > logReturn(ret); > return ret; > } > > @Override > public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { > log("getFileForOutput", location, packageName, relativeName, sibling); > FileObject ret = super.getFileForOutput(location, packageName, relativeName, sibling); > logReturn(ret); > return ret; > } > > @Override > public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException { > log("getJavaFileForInput", location, className, kind); > JavaFileObject ret = super.getJavaFileForInput(location, className, kind); > logReturn(ret); > return ret; > } > > @Override > public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { > log("getJavaFileForOutput", location, className, kind, sibling); > JavaFileObject ret = super.getJavaFileForOutput(location, className, kind, sibling); > logReturn(ret); > return ret; > } > > @Override > public boolean handleOption(String current, Iterator<String> remaining) { > log("handleOption", current, remaining); > boolean ret = super.handleOption(current, remaining); > logReturn(ret); > return ret; > } > > @Override > public boolean hasLocation(Location location) { > log("hasLocation", location); > boolean ret = super.hasLocation(location); > logReturn(ret); > return ret; > } > > @Override > public String inferBinaryName(Location location, JavaFileObject file) { > log("inferBinaryName", location, file); > String ret = super.inferBinaryName(location, file); > logReturn(ret); > return ret; > } > > @Override > public boolean isSameFile(FileObject a, FileObject b) { > log("isSameFile", a, b); > boolean ret = super.isSameFile(a, b); > logReturn(ret); > return ret; > } > > @Override > public int isSupportedOption(String option) { > log("isSupportedOption", option); > int ret = super.isSupportedOption(option); > logReturn(ret); > return ret; > } > > @Override > public Iterable<JavaFileObject> list(Location arg0, String arg1, Set<Kind> arg2, boolean arg3) throws IOException { > log("list", arg0, arg1, arg2, arg3); > Iterable<JavaFileObject> ret = super.list(arg0, arg1, arg2, arg3); > logReturn(ret); > return ret; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 188796
: 68640 |
247682
|
251465
|
251466
|
251467
|
251468
|
251547
|
251601