Search in sources :

Example 26 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.

the class DownloadLicensesMojo method execute.

@java.lang.Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        init();
        addDependenciesToLicenseMap();
        final int timeoutMillis = (int) TimeUnit.SECONDS.toMillis(timeoutSecs);
        //noinspection ResultOfMethodCallIgnored
        downloadDir.mkdirs();
        AtomicInteger counter = new AtomicInteger();
        getLicenseMap().values().parallelStream().forEach(entry -> {
            final int i = counter.incrementAndGet();
            final String url = entry.getLicense().getUrl();
            String fileName = entry.getLicense().getContentFile(false);
            doDownload(timeoutMillis, i, url, fileName);
        });
    } catch (IOException | ProjectBuildingException e) {
        throw new MojoExecutionException("Unexpected exception: " + e, e);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException)

Example 27 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.

the class ToolchainMojo method selectToolchain.

protected boolean selectToolchain(String type, Map<String, String> params) throws MojoExecutionException {
    getLog().info("Required toolchain: " + getToolchainRequirementAsString(type, params));
    int typeFound = 0;
    try {
        ToolchainPrivate[] tcs = getToolchains(type);
        for (ToolchainPrivate tc : tcs) {
            if (!type.equals(tc.getType())) {
                // useful because of MNG-5716
                continue;
            }
            typeFound++;
            if (tc.matchesRequirements(params)) {
                getLog().info("Found matching toolchain for type " + type + ": " + tc);
                // store matching toolchain to build context
                toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);
                return true;
            }
        }
    } catch (MisconfiguredToolchainException ex) {
        throw new MojoExecutionException("Misconfigured toolchains.", ex);
    }
    getLog().error("No toolchain " + ((typeFound == 0) ? "found" : ("matched from " + typeFound + " found")) + " for type " + type);
    return false;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ToolchainPrivate(org.apache.maven.toolchain.ToolchainPrivate) MisconfiguredToolchainException(org.apache.maven.toolchain.MisconfiguredToolchainException)

Example 28 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.

the class ExcludeViolationsFromFile method loadExcludeFromFailuresData.

@Override
public void loadExcludeFromFailuresData(final String excludeFromFailureFile) throws MojoExecutionException {
    if (StringUtils.isEmpty(excludeFromFailureFile)) {
        return;
    }
    File file = new File(excludeFromFailureFile);
    if (!file.exists()) {
        return;
    }
    final Properties props = new Properties();
    try (FileInputStream fileInputStream = new FileInputStream(new File(excludeFromFailureFile))) {
        props.load(fileInputStream);
    } catch (final IOException e) {
        throw new MojoExecutionException("Cannot load properties file " + excludeFromFailureFile, e);
    }
    for (final Entry<Object, Object> propEntry : props.entrySet()) {
        final Set<String> excludedRuleSet = new HashSet<>();
        final String className = propEntry.getKey().toString();
        final String[] excludedRules = propEntry.getValue().toString().split(",");
        for (final String excludedRule : excludedRules) {
            excludedRuleSet.add(excludedRule.trim());
        }
        excludeFromFailureClasses.put(className, excludedRuleSet);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 29 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.

the class PmdReport method executePmd.

private void executePmd() throws MavenReportException {
    if (renderer != null) {
        // PMD has already been run
        getLog().debug("PMD has already been run - skipping redundant execution.");
        return;
    }
    try {
        excludeFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
    } catch (MojoExecutionException e) {
        throw new MavenReportException("Unable to load exclusions", e);
    }
    // configure ResourceManager
    locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath());
    locator.addSearchPath("url", "");
    locator.setOutputDirectory(targetDirectory);
    renderer = new PmdCollectingRenderer();
    PMDConfiguration pmdConfiguration = getPMDConfiguration();
    String[] sets = new String[rulesets.length];
    try {
        for (int idx = 0; idx < rulesets.length; idx++) {
            String set = rulesets[idx];
            getLog().debug("Preparing ruleset: " + set);
            RuleSetReferenceId id = new RuleSetReferenceId(set);
            File ruleset = locator.getResourceAsFile(id.getRuleSetFileName(), getLocationTemp(set));
            if (null == ruleset) {
                throw new MavenReportException("Could not resolve " + set);
            }
            sets[idx] = ruleset.getAbsolutePath();
        }
    } catch (ResourceNotFoundException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (FileResourceCreationException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
    pmdConfiguration.setRuleSets(StringUtils.join(sets, ","));
    try {
        if (filesToProcess == null) {
            filesToProcess = getFilesToProcess();
        }
        if (filesToProcess.isEmpty() && !"java".equals(language)) {
            getLog().warn("No files found to process. Did you add your additional source folders like javascript?" + " (see also build-helper-maven-plugin)");
        }
    } catch (IOException e) {
        throw new MavenReportException("Can't get file list", e);
    }
    String encoding = getSourceEncoding();
    if (StringUtils.isEmpty(encoding) && !filesToProcess.isEmpty()) {
        getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
        encoding = ReaderFactory.FILE_ENCODING;
    }
    pmdConfiguration.setSourceEncoding(encoding);
    List<DataSource> dataSources = new ArrayList<>(filesToProcess.size());
    for (File f : filesToProcess.keySet()) {
        dataSources.add(new FileDataSource(f));
    }
    if (sets.length > 0) {
        processFilesWithPMD(pmdConfiguration, dataSources);
    } else {
        getLog().debug("Skipping PMD execution as no rulesets are defined.");
    }
    if (renderer.hasErrors()) {
        if (!skipPmdError) {
            getLog().error("PMD processing errors:");
            getLog().error(renderer.getErrorsAsString());
            throw new MavenReportException("Found " + renderer.getErrors().size() + " PMD processing errors");
        }
        getLog().warn("There are " + renderer.getErrors().size() + " PMD processing errors:");
        getLog().warn(renderer.getErrorsAsString());
    }
    removeExcludedViolations(renderer.getViolations());
    // so the "check" goals can check for violations
    if (isXml() && renderer != null) {
        writeNonHtml(renderer.asReport());
    }
    if (benchmark) {
        try (PrintStream benchmarkFileStream = new PrintStream(benchmarkOutputFilename)) {
            (new TextReport()).generate(Benchmarker.values(), benchmarkFileStream);
        } catch (FileNotFoundException fnfe) {
            getLog().error("Unable to generate benchmark file: " + benchmarkOutputFilename, fnfe);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) RuleSetReferenceId(net.sourceforge.pmd.RuleSetReferenceId) FileResourceCreationException(org.codehaus.plexus.resource.loader.FileResourceCreationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TextReport(net.sourceforge.pmd.benchmark.TextReport) DataSource(net.sourceforge.pmd.util.datasource.DataSource) FileDataSource(net.sourceforge.pmd.util.datasource.FileDataSource) FileDataSource(net.sourceforge.pmd.util.datasource.FileDataSource) ResourceNotFoundException(org.codehaus.plexus.resource.loader.ResourceNotFoundException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration)

Example 30 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project maven-plugins by apache.

the class JLinkMojo method deleteOutputDirectoryIfItAlreadyExists.

private void deleteOutputDirectoryIfItAlreadyExists() throws MojoExecutionException {
    if (outputDirectory.exists()) {
        // otherwise JLink will fail with a message "Error: directory already exists: ..."
        try {
            getLog().debug("Deleting existing " + outputDirectory.getAbsolutePath());
            FileUtils.forceDelete(outputDirectory);
        } catch (IOException e) {
            getLog().error("IOException", e);
            throw new MojoExecutionException("Failure during deletion of " + outputDirectory.getAbsolutePath() + " occured.");
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1221 IOException (java.io.IOException)656 File (java.io.File)572 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)151 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)57 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38