Search in sources :

Example 6 with Toolchain

use of org.apache.maven.toolchain.Toolchain in project maven-plugins by apache.

the class AbstractJarsignerMojo method execute.

public final void execute() throws MojoExecutionException {
    if (!this.skip) {
        Toolchain toolchain = getToolchain();
        if (toolchain != null) {
            getLog().info("Toolchain in maven-jarsigner-plugin: " + toolchain);
            jarSigner.setToolchain(toolchain);
        }
        int processed = 0;
        if (this.archive != null) {
            processArchive(this.archive);
            processed++;
        } else {
            if (processMainArtifact) {
                processed += processArtifact(this.project.getArtifact()) ? 1 : 0;
            }
            if (processAttachedArtifacts && !Boolean.FALSE.equals(attachments)) {
                Collection<String> includes = new HashSet<String>();
                if (includeClassifiers != null) {
                    includes.addAll(Arrays.asList(includeClassifiers));
                }
                Collection<String> excludes = new HashSet<String>();
                if (excludeClassifiers != null) {
                    excludes.addAll(Arrays.asList(excludeClassifiers));
                }
                for (Object o : this.project.getAttachedArtifacts()) {
                    final Artifact artifact = (Artifact) o;
                    if (!includes.isEmpty() && !includes.contains(artifact.getClassifier())) {
                        continue;
                    }
                    if (excludes.contains(artifact.getClassifier())) {
                        continue;
                    }
                    processed += processArtifact(artifact) ? 1 : 0;
                }
            } else {
                if (verbose) {
                    getLog().info(getMessage("ignoringAttachments"));
                } else {
                    getLog().debug(getMessage("ignoringAttachments"));
                }
            }
            if (archiveDirectory != null) {
                String includeList = (includes != null) ? StringUtils.join(includes, ",") : null;
                String excludeList = (excludes != null) ? StringUtils.join(excludes, ",") : null;
                List<File> jarFiles;
                try {
                    jarFiles = FileUtils.getFiles(archiveDirectory, includeList, excludeList);
                } catch (IOException e) {
                    throw new MojoExecutionException("Failed to scan archive directory for JARs: " + e.getMessage(), e);
                }
                for (File jarFile : jarFiles) {
                    processArchive(jarFile);
                    processed++;
                }
            }
        }
        getLog().info(getMessage("processed", processed));
    } else {
        getLog().info(getMessage("disabled", null));
    }
}
Also used : Toolchain(org.apache.maven.toolchain.Toolchain) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 7 with Toolchain

use of org.apache.maven.toolchain.Toolchain in project maven-plugins by apache.

the class AbstractJLinkMojo method getToolchain.

private Toolchain getToolchain() {
    Toolchain tc = null;
    if (jdkToolchain != null) {
        // Maven 3.3.1 has plugin execution scoped Toolchain Support
        try {
            Method getToolchainsMethod = toolchainManager.getClass().getMethod("getToolchains", MavenSession.class, String.class, Map.class);
            @SuppressWarnings("unchecked") List<Toolchain> tcs = (List<Toolchain>) getToolchainsMethod.invoke(toolchainManager, session, "jdk", jdkToolchain);
            if (tcs != null && tcs.size() > 0) {
                tc = tcs.get(0);
            }
        } catch (NoSuchMethodException e) {
        // ignore
        } catch (SecurityException e) {
        // ignore
        } catch (IllegalAccessException e) {
        // ignore
        } catch (IllegalArgumentException e) {
        // ignore
        } catch (InvocationTargetException e) {
        // ignore
        }
    }
    if (tc == null) {
        tc = toolchainManager.getToolchainFromBuildContext("jdk", session);
    }
    return tc;
}
Also used : Toolchain(org.apache.maven.toolchain.Toolchain) List(java.util.List) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with Toolchain

use of org.apache.maven.toolchain.Toolchain in project maven-plugins by apache.

the class AbstractJModMojo method getJModExecutable.

protected String getJModExecutable() throws IOException {
    Toolchain tc = getToolchain();
    String jLinkExecutable = null;
    if (tc != null) {
        jLinkExecutable = tc.findTool("jmod");
    }
    String jLinkCommand = "jmod" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");
    File jLinkExe;
    if (StringUtils.isNotEmpty(jLinkExecutable)) {
        jLinkExe = new File(jLinkExecutable);
        if (jLinkExe.isDirectory()) {
            jLinkExe = new File(jLinkExe, jLinkCommand);
        }
        if (SystemUtils.IS_OS_WINDOWS && jLinkExe.getName().indexOf('.') < 0) {
            jLinkExe = new File(jLinkExe.getPath() + ".exe");
        }
        if (!jLinkExe.isFile()) {
            throw new IOException("The jlink executable '" + jLinkExe + "' doesn't exist or is not a file.");
        }
        return jLinkExe.getAbsolutePath();
    }
    // Really ?
    if (SystemUtils.IS_OS_AIX) {
        jLinkExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jLinkCommand);
    } else // CHECKSTYLE_OFF: MagicNumber
    if (SystemUtils.IS_OS_MAC_OSX && SystemUtils.JAVA_VERSION_FLOAT < 1.7f) // CHECKSTYLE_ON: MagicNumber
    {
        jLinkExe = new File(SystemUtils.getJavaHome() + File.separator + "bin", jLinkCommand);
    } else {
        jLinkExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", jLinkCommand);
    }
    // ----------------------------------------------------------------------
    if (!jLinkExe.exists() || !jLinkExe.isFile()) {
        Properties env = CommandLineUtils.getSystemEnvVars();
        String javaHome = env.getProperty("JAVA_HOME");
        if (StringUtils.isEmpty(javaHome)) {
            throw new IOException("The environment variable JAVA_HOME is not correctly set.");
        }
        if ((!new File(javaHome).getCanonicalFile().exists()) || (new File(javaHome).getCanonicalFile().isFile())) {
            throw new IOException("The environment variable JAVA_HOME=" + javaHome + " doesn't exist or is not a valid directory.");
        }
        jLinkExe = new File(javaHome + File.separator + "bin", jLinkCommand);
    }
    if (!jLinkExe.getCanonicalFile().exists() || !jLinkExe.getCanonicalFile().isFile()) {
        throw new IOException("The jlink executable '" + jLinkExe + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable.");
    }
    return jLinkExe.getAbsolutePath();
}
Also used : Toolchain(org.apache.maven.toolchain.Toolchain) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Example 9 with Toolchain

use of org.apache.maven.toolchain.Toolchain in project maven-plugins by apache.

the class AbstractJDepsMojo method getJDepsExecutable.

private String getJDepsExecutable() throws IOException {
    Toolchain tc = getToolchain();
    String jdepsExecutable = null;
    if (tc != null) {
        jdepsExecutable = tc.findTool("jdeps");
    }
    String jdepsCommand = "jdeps" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");
    File jdepsExe;
    if (StringUtils.isNotEmpty(jdepsExecutable)) {
        jdepsExe = new File(jdepsExecutable);
        if (jdepsExe.isDirectory()) {
            jdepsExe = new File(jdepsExe, jdepsCommand);
        }
        if (SystemUtils.IS_OS_WINDOWS && jdepsExe.getName().indexOf('.') < 0) {
            jdepsExe = new File(jdepsExe.getPath() + ".exe");
        }
        if (!jdepsExe.isFile()) {
            throw new IOException("The jdeps executable '" + jdepsExe + "' doesn't exist or is not a file.");
        }
        return jdepsExe.getAbsolutePath();
    }
    // For IBM's JDK 1.2
    if (SystemUtils.IS_OS_AIX) {
        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand);
    } else // CHECKSTYLE_OFF: MagicNumber
    if (SystemUtils.IS_OS_MAC_OSX && SystemUtils.JAVA_VERSION_FLOAT < 1.7f) // CHECKSTYLE_ON: MagicNumber
    {
        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + "bin", jdepsCommand);
    } else {
        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", jdepsCommand);
    }
    // ----------------------------------------------------------------------
    if (!jdepsExe.exists() || !jdepsExe.isFile()) {
        Properties env = CommandLineUtils.getSystemEnvVars();
        String javaHome = env.getProperty("JAVA_HOME");
        if (StringUtils.isEmpty(javaHome)) {
            throw new IOException("The environment variable JAVA_HOME is not correctly set.");
        }
        if ((!new File(javaHome).getCanonicalFile().exists()) || (new File(javaHome).getCanonicalFile().isFile())) {
            throw new IOException("The environment variable JAVA_HOME=" + javaHome + " doesn't exist or is not a valid directory.");
        }
        jdepsExe = new File(javaHome + File.separator + "bin", jdepsCommand);
    }
    if (!jdepsExe.getCanonicalFile().exists() || !jdepsExe.getCanonicalFile().isFile()) {
        throw new IOException("The jdeps executable '" + jdepsExe + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable.");
    }
    return jdepsExe.getAbsolutePath();
}
Also used : Toolchain(org.apache.maven.toolchain.Toolchain) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Aggregations

Toolchain (org.apache.maven.toolchain.Toolchain)9 File (java.io.File)6 IOException (java.io.IOException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 List (java.util.List)4 Properties (java.util.Properties)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Artifact (org.apache.maven.artifact.Artifact)1 IncrementalBuildHelper (org.apache.maven.shared.incremental.IncrementalBuildHelper)1 IncrementalBuildHelperRequest (org.apache.maven.shared.incremental.IncrementalBuildHelperRequest)1 Compiler (org.codehaus.plexus.compiler.Compiler)1 CompilerConfiguration (org.codehaus.plexus.compiler.CompilerConfiguration)1 CompilerException (org.codehaus.plexus.compiler.CompilerException)1 CompilerMessage (org.codehaus.plexus.compiler.CompilerMessage)1 CompilerNotImplementedException (org.codehaus.plexus.compiler.CompilerNotImplementedException)1 CompilerResult (org.codehaus.plexus.compiler.CompilerResult)1