Java源码示例:org.apache.maven.toolchain.Toolchain
示例1
private Toolchain getToolchain()
{
Toolchain tc = null;
try
{
if ( session != null ) // session is null in tests..
{
ToolchainManager toolchainManager =
(ToolchainManager) session.getContainer().lookup( ToolchainManager.ROLE );
if ( toolchainManager != null )
{
tc = toolchainManager.getToolchainFromBuildContext( toolchain, session );
}
}
}
catch ( ComponentLookupException componentLookupException )
{
// just ignore, could happen in pre-2.0.9 builds..
}
return tc;
}
示例2
private File getJavaExecutable() throws MojoExecutionException {
if (javaExecutable != null) {
getLog().debug("Plugin configuration set the 'javaExecutable' parameter to " + javaExecutable);
} else {
Toolchain tc = toolchainManager.getToolchainFromBuildContext("jdk", mavenSession);
if (tc != null) {
getLog().info("Using toolchain " + tc + " to find the java executable");
javaExecutable = tc.findTool("java");
} else {
getLog().debug("The java executable is set to default value");
javaExecutable = SystemUtils.getJavaHome() + File.separator + "bin" + File.separator + "java";
}
}
String exe = SystemUtils.IS_OS_WINDOWS && !javaExecutable.endsWith(".exe") ? ".exe" : "";
File javaExe = new File(javaExecutable + exe);
if (!javaExe.isFile()) {
throw new MojoExecutionException("The java executable '" + javaExe + "' doesn't exist or is not a file."
+ " Verify the <javaExecutable/> parameter or toolchain configuration.");
}
getLog().info("The java executable is " + javaExe.getAbsolutePath());
return javaExe;
}
示例3
private String getBootClassPath() {
Toolchain toolchain = toolchainManager.getToolchainFromBuildContext("jdk", session);
if (toolchain instanceof DefaultJavaToolChain) {
DefaultJavaToolChain javaToolChain = (DefaultJavaToolChain) toolchain;
getLog().info("Using toolchain " + javaToolChain);
if (javaSourceVersion != null) {
JavaVersion version = JavaVersion.fromQualifier(javaSourceVersion);
if (version.isAtLeast(JavaVersion.JAVA9)) {
return ""; // bootclasspath only supported on Java8 and older
}
}
String[] includes = { "jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*" };
String[] excludes = new String[0];
Xpp3Dom config = (Xpp3Dom) javaToolChain.getModel().getConfiguration();
if (config != null) {
Xpp3Dom bootClassPath = config.getChild("bootClassPath");
if (bootClassPath != null) {
Xpp3Dom includeParent = bootClassPath.getChild("includes");
if (includeParent != null) {
includes = getValues(includeParent.getChildren("include"));
}
Xpp3Dom excludeParent = bootClassPath.getChild("excludes");
if (excludeParent != null) {
excludes = getValues(excludeParent.getChildren("exclude"));
}
}
}
return scanBootclasspath(javaToolChain.getJavaHome(), includes, excludes);
}
return "";
}
示例4
/** Replies the boot classpath.
*
* @return the boot classpath.
* @throws IOException in case of error.
*/
protected String getBootClassPath() throws IOException {
final Toolchain toolchain = this.toolchainManager.getToolchainFromBuildContext("jdk", this.session); //$NON-NLS-1$
if (toolchain instanceof JavaToolchain && toolchain instanceof ToolchainPrivate) {
final JavaToolchain javaToolChain = (JavaToolchain) toolchain;
final ToolchainPrivate privateJavaToolChain = (ToolchainPrivate) toolchain;
String[] includes = {"jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] excludes = new String[0];
final Xpp3Dom config = (Xpp3Dom) privateJavaToolChain.getModel().getConfiguration();
if (config != null) {
final Xpp3Dom bootClassPath = config.getChild("bootClassPath"); //$NON-NLS-1$
if (bootClassPath != null) {
final Xpp3Dom includeParent = bootClassPath.getChild("includes"); //$NON-NLS-1$
if (includeParent != null) {
includes = getValues(includeParent.getChildren("include")); //$NON-NLS-1$
}
final Xpp3Dom excludeParent = bootClassPath.getChild("excludes"); //$NON-NLS-1$
if (excludeParent != null) {
excludes = getValues(excludeParent.getChildren("exclude")); //$NON-NLS-1$
}
}
}
try {
return scanBootclasspath(Objects.toString(this.reflect.invoke(javaToolChain, "getJavaHome")), includes, excludes); //$NON-NLS-1$
} catch (Exception e) {
throw new IOException(e.getLocalizedMessage(), e);
}
}
return ""; //$NON-NLS-1$
}
示例5
private String getBootClassPath() throws MojoExecutionException {
// Bootclasspath is only supported on Java8 and older
final String sourceVersionStr = getSourceVersion();
if (!Strings.isEmpty(sourceVersionStr)) {
final JavaVersion sourceVersion = JavaVersion.fromQualifier(sourceVersionStr);
if (sourceVersion != null && sourceVersion.isAtLeast(JavaVersion.JAVA9)) {
return ""; //$NON-NLS-1$
}
}
final Toolchain toolchain = this.toolchainManager.getToolchainFromBuildContext("jdk", this.mavenHelper.getSession()); //$NON-NLS-1$
if (toolchain instanceof JavaToolchain && toolchain instanceof ToolchainPrivate) {
final JavaToolchain javaToolChain = (JavaToolchain) toolchain;
final ToolchainPrivate privateJavaToolChain = (ToolchainPrivate) toolchain;
getLog().info(MessageFormat.format(Messages.AbstractSarlBatchCompilerMojo_5, javaToolChain));
String[] includes = {"jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] excludes = new String[0];
final Xpp3Dom config = (Xpp3Dom) privateJavaToolChain.getModel().getConfiguration();
if (config != null) {
final Xpp3Dom bootClassPath = config.getChild("bootClassPath"); //$NON-NLS-1$
if (bootClassPath != null) {
final Xpp3Dom includeParent = bootClassPath.getChild("includes"); //$NON-NLS-1$
if (includeParent != null) {
includes = getValues(includeParent.getChildren("include")); //$NON-NLS-1$
}
final Xpp3Dom excludeParent = bootClassPath.getChild("excludes"); //$NON-NLS-1$
if (excludeParent != null) {
excludes = getValues(excludeParent.getChildren("exclude")); //$NON-NLS-1$
}
}
}
try {
return scanBootclasspath(Objects.toString(this.reflect.invoke(javaToolChain, "getJavaHome")), includes, excludes); //$NON-NLS-1$
} catch (Exception e) {
throw new MojoExecutionException(e.getLocalizedMessage(), e);
}
}
return ""; //$NON-NLS-1$
}