1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar;
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.apache.maven.plugins.annotations.Parameter;
28
29 import com.github.maven_nar.cpptasks.CCTask;
30 import com.github.maven_nar.cpptasks.CUtil;
31 import com.github.maven_nar.cpptasks.types.CommandLineArgument;
32 import com.github.maven_nar.cpptasks.types.LibrarySet;
33 import com.github.maven_nar.cpptasks.types.LinkerArgument;
34
35
36
37
38
39
40 public class Java {
41
42
43
44
45 @Parameter(required = true)
46 private boolean include = false;
47
48
49
50
51
52
53 @Parameter
54 private List includePaths;
55
56
57
58
59 @Parameter(required = true)
60 private boolean link = false;
61
62
63
64
65
66
67 @Parameter
68 private String runtimeDirectory;
69
70
71
72
73 @Parameter(defaultValue = "jvm")
74 private String runtime = "jvm";
75
76 private AbstractCompileMojo mojo;
77
78 public Java() {
79 }
80
81 public final void addIncludePaths(final CCTask task, final String outType)
82 throws MojoFailureException, MojoExecutionException {
83 if (this.include || this.mojo.getJavah().getJniDirectory().exists()) {
84 if (this.includePaths != null) {
85 for (final Object includePath : this.includePaths) {
86 final String path = (String) includePath;
87 task.createIncludePath().setPath(new File(this.mojo.getJavaHome(this.mojo.getAOL()), path).getPath());
88 }
89 } else {
90 final String prefix = this.mojo.getAOL().getKey() + ".java.";
91 final String includes = NarProperties.getInstance(this.mojo.getMavenProject()).getProperty(prefix + "include");
92 if (includes != null) {
93 final String[] path = includes.split(";");
94 for (final String element : path) {
95 task.createIncludePath().setPath(new File(this.mojo.getJavaHome(this.mojo.getAOL()), element).getPath());
96 }
97 }
98 }
99 }
100 }
101
102 public final void addRuntime(final CCTask task, final File javaHome, final String os, final String prefix)
103 throws MojoFailureException {
104 if (this.link) {
105 if (os.equals(OS.MACOSX)) {
106 final CommandLineArgument.LocationEnum end = new CommandLineArgument.LocationEnum();
107 end.setValue("end");
108
109
110 final LinkerArgument framework = new LinkerArgument();
111 framework.setValue("-framework");
112 framework.setLocation(end);
113 task.addConfiguredLinkerArg(framework);
114
115 final LinkerArgument javavm = new LinkerArgument();
116 javavm.setValue("JavaVM");
117 javavm.setLocation(end);
118 task.addConfiguredLinkerArg(javavm);
119 } else {
120 if (this.runtimeDirectory == null) {
121 this.runtimeDirectory = NarProperties.getInstance(this.mojo.getMavenProject()).getProperty(
122 prefix + "runtimeDirectory");
123 if (this.runtimeDirectory == null) {
124 throw new MojoFailureException("NAR: Please specify a <RuntimeDirectory> as part of <Java>");
125 }
126 }
127 this.mojo.getLog().debug("Using Java Runtime Directory: " + this.runtimeDirectory);
128
129 final LibrarySet libset = new LibrarySet();
130 libset.setProject(this.mojo.getAntProject());
131 libset.setLibs(new CUtil.StringArrayBuilder(this.runtime));
132 libset.setDir(new File(javaHome, this.runtimeDirectory));
133 task.addLibset(libset);
134 }
135 }
136 }
137
138 public final void setAbstractCompileMojo(final AbstractCompileMojo mojo) {
139 this.mojo = mojo;
140 }
141 }