Search in sources :

Example 76 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project tomee by apache.

the class ExecMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final boolean realAttach = attach;
    attach = false;
    zip = true;
    super.execute();
    try {
        createExecutableJar();
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    if (realAttach) {
        getLog().info("Attaching Exec TomEE binary");
        if (classifier != null) {
            projectHelper.attachArtifact(project, "jar", classifier, execFile);
        } else {
            projectHelper.attachArtifact(project, "jar", execFile);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LoaderRuntimeException(org.apache.openejb.loader.LoaderRuntimeException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 77 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project bnd by bndtools.

the class ResolverMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        DependencyResolver dependencyResolver = new DependencyResolver(project, repositorySession, resolver, system);
        FileSetRepository fileSetRepository = dependencyResolver.getFileSetRepository(project.getName(), bundles, useMavenDependencies);
        for (File runFile : bndruns) {
            resolve(runFile, fileSetRepository);
        }
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    if (errors > 0)
        throw new MojoExecutionException(errors + " errors found");
}
Also used : FileSetRepository(aQute.bnd.repository.fileset.FileSetRepository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ResolutionException(org.osgi.service.resolver.ResolutionException) DependencyResolver(aQute.bnd.maven.lib.resolve.DependencyResolver)

Example 78 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project bnd by bndtools.

the class BaselineMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
    List<RemoteRepository> aetherRepos = getRepositories(artifact);
    setupBase(artifact);
    try {
        if (base.getVersion() == null || base.getVersion().isEmpty()) {
            searchForBaseVersion(artifact, aetherRepos);
        }
        if (base.getVersion() != null && !base.getVersion().isEmpty()) {
            ArtifactResult artifactResult = locateBaseJar(aetherRepos);
            Reporter reporter;
            if (fullReport) {
                reporter = new ReporterAdapter(System.out);
                ((ReporterAdapter) reporter).setTrace(true);
            } else {
                reporter = new ReporterAdapter();
            }
            Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
            if (checkFailures(artifact, artifactResult, baseline)) {
                if (continueOnError) {
                    logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
                } else {
                    throw new MojoExecutionException("The baselining plugin detected versioning errors");
                }
            } else {
                logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
            }
        } else {
            if (failOnMissing) {
                throw new MojoExecutionException("Unable to locate a previous version of the artifact");
            } else {
                logger.warn("No previous version of {} could be found to baseline against", artifact);
            }
        }
    } catch (RepositoryException re) {
        throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
    } catch (Exception e) {
        throw new MojoExecutionException("An error occurred while calculating the baseline", e);
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) Baseline(aQute.bnd.differ.Baseline) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 79 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project bnd by bndtools.

the class IndexerMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    if (scopes == null || scopes.isEmpty()) {
        scopes = Arrays.asList("compile", "runtime");
    }
    logger.debug("Indexing dependencies with scopes: {}", scopes);
    logger.debug("Including Transitive dependencies: {}", includeTransitive);
    logger.debug("Local file URLs permitted: {}", localURLs);
    logger.debug("Adding mvn: URLs as alternative content: {}", addMvnURLs);
    DependencyResolver dependencyResolver = new DependencyResolver(project, session, resolver, system, scopes, includeTransitive, new RemotePostProcessor(session, system, metadataReader, localURLs));
    Map<File, ArtifactResult> dependencies = dependencyResolver.resolve();
    Map<String, ArtifactRepository> repositories = new HashMap<>();
    for (ArtifactRepository artifactRepository : project.getRemoteArtifactRepositories()) {
        logger.debug("Located an artifact repository {}", artifactRepository.getId());
        repositories.put(artifactRepository.getId(), artifactRepository);
    }
    ArtifactRepository deploymentRepo = project.getDistributionManagementArtifactRepository();
    if (deploymentRepo != null) {
        logger.debug("Located a deployment repository {}", deploymentRepo.getId());
        if (repositories.get(deploymentRepo.getId()) == null) {
            repositories.put(deploymentRepo.getId(), deploymentRepo);
        } else {
            logger.info("The configured deployment repository {} has the same id as one of the remote artifact repositories. It is assumed that these repositories are the same.", deploymentRepo.getId());
        }
    }
    RepositoryURLResolver repositoryURLResolver = new RepositoryURLResolver(repositories);
    MavenURLResolver mavenURLResolver = new MavenURLResolver();
    ResourcesRepository resourcesRepository = new ResourcesRepository();
    XMLResourceGenerator xmlResourceGenerator = new XMLResourceGenerator();
    logger.debug("Indexing artifacts: {}", dependencies.keySet());
    try {
        IO.mkdirs(outputFile.getParentFile());
        for (Entry<File, ArtifactResult> entry : dependencies.entrySet()) {
            File file = entry.getKey();
            ResourceBuilder resourceBuilder = new ResourceBuilder();
            resourceBuilder.addFile(entry.getKey(), repositoryURLResolver.resolver(file, entry.getValue()));
            if (addMvnURLs) {
                CapabilityBuilder c = new CapabilityBuilder(ContentNamespace.CONTENT_NAMESPACE);
                c.addAttribute(ContentNamespace.CONTENT_NAMESPACE, SHA256.digest(file).asHex());
                c.addAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, mavenURLResolver.resolver(file, entry.getValue()));
                c.addAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, file.length());
                c.addAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, MavenURLResolver.MIME);
                resourceBuilder.addCapability(c);
            }
            resourcesRepository.add(resourceBuilder.build());
        }
        if (includeJar && project.getPackaging().equals("jar")) {
            File current = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar");
            if (current.exists()) {
                ResourceBuilder resourceBuilder = new ResourceBuilder();
                resourceBuilder.addFile(current, current.toURI());
                resourcesRepository.add(resourceBuilder.build());
            }
        }
        xmlResourceGenerator.repository(resourcesRepository).save(outputFile);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    if (fail) {
        throw new MojoExecutionException("One or more URI lookups failed");
    }
    attach(outputFile, "osgi-index", "xml");
    if (includeGzip) {
        File gzipOutputFile = new File(outputFile.getPath() + ".gz");
        try {
            xmlResourceGenerator.save(gzipOutputFile);
        } catch (Exception e) {
            throw new MojoExecutionException("Unable to create the gzipped output file");
        }
        attach(gzipOutputFile, "osgi-index", "xml.gz");
    }
}
Also used : RemotePostProcessor(aQute.bnd.maven.lib.resolve.RemotePostProcessor) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyResolver(aQute.bnd.maven.lib.resolve.DependencyResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 80 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project camel by apache.

the class SpringBootAutoConfigurationMojo method writeSourceIfChanged.

private void writeSourceIfChanged(JavaClassSource source, String fileName) throws MojoFailureException {
    // project root folder
    File root = classesDirectory.getParentFile().getParentFile();
    File target = new File(root, "src/main/java/" + fileName);
    try {
        String header = "";
        if (includeLicenseHeader) {
            InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
            header = loadText(is);
        }
        String code = sourceToString(source);
        code = header + code;
        getLog().debug("Source code generated:\n" + code);
        if (target.exists()) {
            String existing = FileUtils.readFileToString(target);
            if (!code.equals(existing)) {
                FileUtils.write(target, code, false);
                getLog().info("Updated existing file: " + target);
            } else {
                getLog().debug("No changes to existing file: " + target);
            }
        } else {
            FileUtils.write(target, code);
            getLog().info("Created file: " + target);
        }
    } catch (Exception e) {
        throw new MojoFailureException("IOError with file " + target, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MojoFailureException(org.apache.maven.plugin.MojoFailureException) File(java.io.File) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

MojoFailureException (org.apache.maven.plugin.MojoFailureException)157 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)94 File (java.io.File)93 IOException (java.io.IOException)91 ArrayList (java.util.ArrayList)50 TreeSet (java.util.TreeSet)33 FileInputStream (java.io.FileInputStream)32 FileOutputStream (java.io.FileOutputStream)21 List (java.util.List)21 Map (java.util.Map)21 MavenProject (org.apache.maven.project.MavenProject)18 Set (java.util.Set)15 MalformedURLException (java.net.MalformedURLException)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 InputStream (java.io.InputStream)12 URLClassLoader (java.net.URLClassLoader)12 Matcher (java.util.regex.Matcher)12 Artifact (org.apache.maven.artifact.Artifact)12 AbstractMojo (org.apache.maven.plugin.AbstractMojo)12