-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
file system decoupled in compilation progress
- Loading branch information
Showing
11 changed files
with
142 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/github/pfmiles/dropincc/impl/hotcompile/JavaMemCls.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.pfmiles.dropincc.impl.hotcompile; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.URI; | ||
|
||
import javax.tools.SimpleJavaFileObject; | ||
|
||
/** | ||
* Represents compiled java class files in the memory. | ||
* | ||
* @author pf-miles | ||
* | ||
*/ | ||
public class JavaMemCls extends SimpleJavaFileObject { | ||
|
||
private ByteArrayOutputStream bos; | ||
|
||
protected JavaMemCls(String name) { | ||
super(URI.create("string:///" + name.replaceAll("\\.", "/") + Kind.CLASS.extension), Kind.CLASS); | ||
this.bos = new ByteArrayOutputStream(); | ||
} | ||
|
||
public byte[] getClsBytes() { | ||
return this.bos.toByteArray(); | ||
} | ||
|
||
public OutputStream openOutputStream() throws IOException { | ||
return bos; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/github/pfmiles/dropincc/impl/hotcompile/MemClsFileManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.pfmiles.dropincc.impl.hotcompile; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import javax.tools.FileObject; | ||
import javax.tools.ForwardingJavaFileManager; | ||
import javax.tools.JavaFileObject; | ||
import javax.tools.JavaFileObject.Kind; | ||
import javax.tools.StandardJavaFileManager; | ||
|
||
/** | ||
* A forwarding file manager which is used to decouple the file system | ||
* dependency. That is, the compilation process write compiled class files into | ||
* memory instead of file system. | ||
* | ||
* @author pf-miles | ||
* | ||
*/ | ||
public class MemClsFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> { | ||
|
||
private Map<String, JavaMemCls> destFiles; | ||
|
||
protected MemClsFileManager(StandardJavaFileManager fileManager, Map<String, JavaMemCls> destFiles) { | ||
super(fileManager); | ||
this.destFiles = destFiles; | ||
} | ||
|
||
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { | ||
if (destFiles.containsKey(className)) { | ||
return destFiles.get(className); | ||
} else { | ||
JavaMemCls file = new JavaMemCls(className); | ||
this.destFiles.put(className, file); | ||
return file; | ||
} | ||
} | ||
|
||
public void close() throws IOException { | ||
super.close(); | ||
this.destFiles = null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters