Example usage for org.apache.maven MavenExecutionException MavenExecutionException

List of usage examples for org.apache.maven MavenExecutionException MavenExecutionException

Introduction

In this page you can find the example usage for org.apache.maven MavenExecutionException MavenExecutionException.

Prototype

public MavenExecutionException(String message, Throwable cause) 

Source Link

Usage

From source file:com.rebaze.maven.payload.PayloadEventSpy.java

License:Open Source License

private File writeDependencyList(File f, List<String> sorted) throws MavenExecutionException {
    if (!f.getParentFile().exists()) {
        f.getParentFile().mkdirs();//from www  .  j a v a2s . com
    }

    try (BufferedWriter writer = new BufferedWriter(new FileWriter(f, true))) {
        for (String s : sorted) {
            writer.append(s);
            writer.newLine();
        }
    } catch (IOException e) {
        throw new MavenExecutionException("Problem writing payload file to " + f.getAbsolutePath(), e);
    }
    return f;
}

From source file:com.simpligility.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java

License:Open Source License

/**
 * Add the dependent library classes to the project classpath.
 *//* w ww  . j ava 2s  .co m*/
private void addClassesToClasspath(UnpackedLibHelper helper, MavenProject project, Artifact artifact)
        throws MavenExecutionException {
    // Work out where the dep will be extracted and calculate the file path to the classes jar.
    // This is location where the GenerateSourcesMojo will extract the classes.
    final File classesJar = helper.getUnpackedClassesJar(artifact);
    log.debug("Adding to classpath : " + classesJar);

    // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that
    // has a Mojo requiring dependency resolution I need to create a dummy classesJar here.
    classesJar.getParentFile().mkdirs();
    try {
        final ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(classesJar));
        zipOutputStream.putNextEntry(new ZipEntry("dummy"));
        zipOutputStream.close();
        log.debug("Created dummy " + classesJar.getName() + " exist=" + classesJar.exists());
    } catch (IOException e) {
        throw new MavenExecutionException("Could not add " + classesJar.getName() + " as dependency", e);
    }

    // Modify the classpath to use an extracted dex file.  This will overwrite
    // any exisiting dependencies with the same information.
    final Dependency dependency = createSystemScopeDependency(artifact, classesJar, null);
    final Dependency providedJar = findProvidedDependencies(dependency, project);
    if (providedJar != null) {
        project.getModel().removeDependency(providedJar);
    }
    project.getModel().addDependency(dependency);
}

From source file:com.tenderowls.opensource.haxemojos.components.HaxeLifecycleParticipant.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    super.afterProjectsRead(session);

    try {/*ww  w .j  a  v a 2s .c  om*/
        MavenProject project = session.getCurrentProject();
        bootstrap.initialize(project, session.getLocalRepository());
    } catch (Exception e) {
        throw new MavenExecutionException(e.getMessage(), e);
    }
}

From source file:fr.brouillard.oss.jgitver.cfg.ConfigurationLoader.java

License:Apache License

/**
 * Loads a Configuration object from the root directory.
 * @param rootDirectory the root directory of the maven project
 * @param logger the logger to report activity
 * @return a non null Configuration object from the file $rootDirectory/.mvn/jgitver.config.xml
 *     or a default one with default values if the configuration file does not exist
 * @throws MavenExecutionException if the file exists but cannot be read correctly
 *//*ww  w  . j a va  2s  .  co m*/
public static Configuration loadFromRoot(File rootDirectory, Logger logger) throws MavenExecutionException {
    JAXBContext jaxbContext;
    Unmarshaller unmarshaller;
    File extensionMavenCoreDirectory = new File(rootDirectory, ".mvn");
    File configurationXml = new File(extensionMavenCoreDirectory, "jgitver.config.xml");
    if (!configurationXml.canRead()) {
        logger.debug("no configuration file found under " + configurationXml
                + ", looking under backwards-compatible file name");
        configurationXml = new File(extensionMavenCoreDirectory, "jgtiver.config.xml");
        if (!configurationXml.canRead()) {
            logger.debug("no configuration file found under " + configurationXml + ", using defaults");
            return new Configuration();
        }
    }
    try {
        logger.info("using jgitver configuration file: " + configurationXml);
        jaxbContext = JAXBContext.newInstance(Configuration.class);
        unmarshaller = jaxbContext.createUnmarshaller();
        Configuration c = (Configuration) unmarshaller.unmarshal(new FileInputStream(configurationXml));
        return c;
    } catch (JAXBException | FileNotFoundException ex) {
        throw new MavenExecutionException("cannot read configuration file " + configurationXml, ex);
    }
}

From source file:fr.brouillard.oss.jgitver.JGitverExtension.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession mavenSession) throws MavenExecutionException {
    MavenProject rootProject = mavenSession.getTopLevelProject();
    List<MavenProject> projects = locateProjects(mavenSession, rootProject.getModules());

    Map<GAV, String> newProjectVersions = new LinkedHashMap<>();

    if (JGitverModelProcessor.class.isAssignableFrom(modelProcessor.getClass())) {
        JGitverModelProcessor jGitverModelProcessor = JGitverModelProcessor.class.cast(modelProcessor);
        JGitverModelProcessorWorkingConfiguration workingConfiguration = jGitverModelProcessor
                .getWorkingConfiguration();

        if (workingConfiguration == null) {
            logger.warn("");
            logger.warn("jgitver has changed!");
            logger.warn("");
            logger.warn(// w w w.  j  ava  2s  .  co m
                    "it now requires the usage of maven core extensions instead of standard plugin extensions.");
            logger.warn("The plugin must be now declared in a `.mvn/extensions.xml` file.");
            logger.warn("");
            logger.warn("    read https://github.com/jgitver/jgitver-maven-plugin for further information");
            logger.warn("");
            throw new MavenExecutionException("detection of jgitver old setting mechanism",
                    new IllegalStateException("jgitver must now use maven core extensions"));
        }

        newProjectVersions = workingConfiguration.getNewProjectVersions();
    } else {
        logger.info("jgitver-maven-plugin is about to change project(s) version(s)");

        String newVersion = null;
        try {
            newVersion = JGitverUtils
                    .calculateVersionForProject(rootProject, mavenSession.getUserProperties(), logger)
                    .getCalculatedVersion();
        } catch (IOException ex) {
            throw new MavenExecutionException("failure calculating version from git information", ex);
        }

        // Let's modify in memory resolved projects model
        for (MavenProject project : projects) {
            GAV projectGAV = GAV.from(project); // SUPPRESS CHECKSTYLE AbbreviationAsWordInName

            logger.debug("about to change in memory POM for: " + projectGAV);
            // First the project itself
            project.setVersion(newVersion);
            logger.debug("    version set to " + newVersion);
            VersionRange newVersionRange = VersionRange.createFromVersion(newVersion);
            project.getArtifact().setVersionRange(newVersionRange);
            logger.debug("    artifact version range set to " + newVersionRange);
            newProjectVersions.put(projectGAV, newVersion);

            // No need to worry about parent link, because model is in memory
        }

        try {
            JGitverUtils.attachModifiedPomFilesToTheProject(projects, newProjectVersions, mavenSession, logger);
        } catch (IOException | XmlPullParserException ex) {
            throw new MavenExecutionException("cannot attach updated POMs during project execution", ex);
        }
    }

    newProjectVersions.entrySet()
            .forEach(e -> logger.info("    " + e.getKey().toString() + " -> " + e.getValue()));
}

From source file:info.ronjenkins.maven.rtr.RTR.java

License:Apache License

private void executeSteps(final List<String> steps, final MavenSession session, final RTRComponents components)
        throws MavenExecutionException {
    SmartReactorStep step;//ww w . j a v a 2s  .  c om
    for (final String name : steps) {
        step = this.availableSteps.get(name);
        if (step == null) {
            throw new MavenExecutionException("Unable to find step '" + name + "' to execute",
                    new IllegalStateException());
        }
        step.execute(session, components);
    }
}

From source file:info.ronjenkins.maven.rtr.steps.RebuildProjectDependencyGraph.java

License:Apache License

@Override
public void execute(final MavenSession session, final RTRComponents components) throws MavenExecutionException {
    try {//from  w  w  w .j  a v  a  2s.c  om
        session.setProjectDependencyGraph(new DefaultProjectDependencyGraph(session.getProjects()));
    } catch (final CycleDetectedException | DuplicateProjectException e) {
        this.logger.error("");
        throw new MavenExecutionException("Could not assemble new project dependency graph", e);
    }
}

From source file:io.treefarm.plugins.haxe.components.HaxeLifecycleParticipant.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    try {//from   w w  w.  j a v a2s.  com
        MavenProject project = session.getCurrentProject();
        bootstrap.initialize(project, session.getLocalRepository());
    } catch (Exception e) {
        throw new MavenExecutionException(e.getMessage(), e);
    }
}

From source file:io.werval.maven.MavenDevShellSPI.java

License:Apache License

@Override
protected void doRebuild() throws DevShellRebuildException {
    System.out.println("Reload!");
    DefaultExecutor executor = new DefaultExecutor();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(output));
    try {//from   w ww. ja  v a 2s . co  m
        int exitValue = executor.execute(cmdLine);
        if (exitValue != 0) {
            throw new DevShellRebuildException(
                    new MavenExecutionException("Maven exited with a non-zero status: " + exitValue, pom));
        }
    } catch (Exception ex) {
        throw new DevShellRebuildException(ex, output.toString());
    }
}

From source file:it.session.maven.plugin.TilesMavenLifecycleParticipant.java

License:Apache License

protected void mergeTile(MavenProject currentProject, String propertyName,
        RepositorySystemSession repositorySystemSession) throws MavenExecutionException {
    String propertyValue = currentProject.getProperties().getProperty(propertyName);
    StringTokenizer propertyTokens = new StringTokenizer(propertyValue, ":");

    String groupId = propertyTokens.nextToken();
    String artifactId = propertyTokens.nextToken();
    String version = propertyTokens.nextToken();

    String currentTileInformation = String.format("'%s:%s:%s'", groupId, artifactId, version);

    try {/*w w w  .  j a  v a  2s .  c  o m*/
        File artifactFile = this.resolveArtifact(currentProject, groupId, artifactId, version,
                repositorySystemSession);

        Model tileModel = this.reader.read(new FileInputStream(artifactFile));
        this.modelMerger.merge(currentProject.getModel(), tileModel, false, null);

        //If invoked by tests, logger is null
        //@TODO properly inject logger on TilesMavenLifecycleParticipantTest.java
        if (logger != null) {
            logger.info(String.format("Loaded Maven Tile " + currentTileInformation));
        }

    } catch (FileNotFoundException e) {
        throw new MavenExecutionException("Error loading tiles " + currentTileInformation, e);
    } catch (XmlPullParserException e) {
        throw new MavenExecutionException("Error building tiles " + currentTileInformation, e);
    } catch (IOException e) {
        throw new MavenExecutionException("Error parsing tiles " + currentTileInformation, e);
    } catch (MojoExecutionException e) {
        throw new MavenExecutionException("Error retrieving tiles " + currentTileInformation, e);
    }
}