-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompileMojo.java
More file actions
51 lines (40 loc) · 1.88 KB
/
CompileMojo.java
File metadata and controls
51 lines (40 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.github.bradleywood;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.bw.tl.util.CompileUtilities;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE)
public class CompileMojo extends AbstractMojo {
@Parameter(name = "sourceDirectory", defaultValue = "${project.basedir}/src/main/triton")
private String sourceDirectory;
@Parameter(defaultValue = "${project.compileClasspathElements}", required = true, readonly = true)
private List<String> classpath;
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true, readonly = true)
private String outputDirectory;
@Override
public void execute() throws CompilationFailureException {
try {
final Map<String, byte[]> classMap = CompileUtilities.compile(sourceDirectory, classpath);
if (classMap == null)
throw new CompilationFailureException();
for (final Map.Entry<String, byte[]> entry : classMap.entrySet()) {
final File file = new File(outputDirectory, entry.getKey().replace(".", "/") + ".class");
final File parent = file.getParentFile();
if (!parent.exists())
parent.mkdirs();
final FileOutputStream fos = new FileOutputStream(file);
fos.write(entry.getValue());
fos.close();
}
} catch (IOException e) {
throw new CompilationFailureException();
}
}
}