Beispiel #1
0
 /**
  * Obtains the java executable from the Maven Toolchain.
  *
  * @param session
  * @param toolchainManager
  * @param type The type of tool chain to look for in maven.
  * @param name The name of the executable file that would be called in in the path.
  * @return
  * @throws MojoExecutionException
  */
 public static String getExecutable(
     MavenSession session, ToolchainManager toolchainManager, String type, String name)
     throws MojoExecutionException {
   Toolchain toolchain = toolchainManager.getToolchainFromBuildContext(type, session);
   if (toolchain != null) {
     String tool = toolchain.findTool(name);
     if (Strings.isValid(tool)) {
       return tool;
     } else {
       throw new MojoExecutionException(
           "Unable to find 'java' executable for toolchain: " + toolchain);
     }
   }
   return name;
 }
 // TODO remove the part with ToolchainManager lookup once we depend on
 // 3.0.9 (have it as prerequisite). Define as regular component field then.
 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("jdk", session);
       }
     }
   } catch (ComponentLookupException componentLookupException) {
     // just ignore, could happen in pre-3.0.9 builds..
   }
   return tc;
 }