-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
483 additions
and
355 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import java.util.logging.Logger; | ||
|
||
import static technology.idlab.logging.LoggerKt.createLogger; | ||
|
||
public class Template { | ||
protected Logger logger = createLogger(); | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
package technology.idlab.compiler | ||
|
||
import technology.idlab.logging.createLogger | ||
import technology.idlab.logging.fatal | ||
import java.io.File | ||
import java.io.PrintWriter | ||
import javax.tools.DiagnosticCollector | ||
import javax.tools.JavaFileObject | ||
import javax.tools.ToolProvider | ||
|
||
class Compiler { | ||
private val logger = createLogger() | ||
private val compiler = | ||
ToolProvider.getSystemJavaCompiler() ?: logger.fatal( | ||
"No Java compiler found.", | ||
) | ||
|
||
fun compile(file: File): ByteArray { | ||
logger.info(file.absolutePath) | ||
|
||
// Prepare compilation. | ||
val files = listOf(file) | ||
val fileManager = compiler.getStandardFileManager(null, null, null) | ||
val results = MemoryFileManager(fileManager) | ||
val compilationUnits = fileManager.getJavaFileObjectsFromFiles(files) | ||
val diagnosticCollector = DiagnosticCollector<JavaFileObject>() | ||
|
||
// Create a compilation task. | ||
val task = | ||
compiler.getTask( | ||
PrintWriter(System.out), | ||
results, | ||
diagnosticCollector, | ||
listOf("-d", ""), | ||
null, | ||
compilationUnits, | ||
) | ||
|
||
// Execute compilation. | ||
val success = task.call() | ||
|
||
// Write diagnostics to logger. | ||
diagnosticCollector.diagnostics.forEach { | ||
logger.info(it.toString()) | ||
} | ||
|
||
if (!success) { | ||
logger.fatal("Failure when compiling $file") | ||
} | ||
|
||
return results.get(file.nameWithoutExtension) | ||
} | ||
|
||
companion object { | ||
private val instance = Compiler() | ||
|
||
fun compile(file: File): ByteArray { | ||
return instance.compile(file) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.