org.apache.maven.toolchain.Toolchain Java Examples

The following examples show how to use org.apache.maven.toolchain.Toolchain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecMojo.java    From exec-maven-plugin with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AbstractCodegenMojo.java    From cxf with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: AbstractXtendCompilerMojo.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 "";
}
 
Example #4
Source File: AbstractDocumentationMojo.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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$
}
 
Example #5
Source File: AbstractSarlBatchCompilerMojo.java    From sarl with Apache License 2.0 5 votes vote down vote up
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$
}