Search in sources :

Example 1 with MavenEmbedderException

use of org.appformer.maven.integration.embedder.MavenEmbedderException in project kie-wb-common by kiegroup.

the class MavenBuildExecutor method executeMaven.

public static void executeMaven(final File pom, final PrintStream stdout, final PrintStream stderr, final Properties properties, final String... goals) {
    final PrintStream oldout = System.out;
    final PrintStream olderr = System.err;
    final Properties oldProperties = System.getProperties();
    if (properties != null) {
        properties.keySet().forEach((o) -> {
            if (properties.getProperty((String) o) != null) {
                System.setProperty((String) o, properties.getProperty((String) o));
            }
        });
    }
    final MavenEmbedder mavenEmbedder = newMavenEmbedder();
    try {
        if (stdout != null) {
            System.setOut(stdout);
        }
        if (stderr != null) {
            System.setErr(stderr);
        }
        final MavenRequest mavenRequest = MavenProjectLoader.createMavenRequest(false);
        mavenRequest.setGoals(Arrays.asList(goals));
        mavenRequest.setPom(pom.getAbsolutePath());
        final MavenExecutionResult result = mavenEmbedder.execute(mavenRequest);
        if (result.hasExceptions()) {
            for (Throwable t : result.getExceptions()) {
                LOG.error("Error Running Maven", t);
            }
            throw new BuildException("Maven found issues trying to build the pom file: " + pom.getAbsolutePath() + ". Look at the Error Logs for more information");
        }
    } catch (final MavenEmbedderException ex) {
        throw new BuildException("Maven coudn't build the project for pom file: " + pom.getAbsolutePath(), ex);
    } finally {
        System.setProperties(oldProperties);
        mavenEmbedder.dispose();
        System.setOut(oldout);
        System.setErr(olderr);
    }
}
Also used : PrintStream(java.io.PrintStream) MavenEmbedder(org.appformer.maven.integration.embedder.MavenEmbedder) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenEmbedderException(org.appformer.maven.integration.embedder.MavenEmbedderException) BuildException(org.guvnor.ala.exceptions.BuildException) Properties(java.util.Properties) MavenRequest(org.appformer.maven.integration.embedder.MavenRequest)

Example 2 with MavenEmbedderException

use of org.appformer.maven.integration.embedder.MavenEmbedderException in project kie-wb-common by kiegroup.

the class ArchetypeServiceImpl method add.

@Override
public void add(final GAV archetypeGav, final GAV templateGav) {
    checkNotNull("archetypeGav", archetypeGav);
    checkNotNull("templateGav", templateGav);
    appendTemplateSuffix(templateGav);
    checkArchetypeAlreadyAdded(templateGav);
    final Path workingDirectoryPath = createTempDirectory(templateGav.getArtifactId());
    final File workingDirectory = new File(workingDirectoryPath.toString());
    final FileSystemLock physicalLock = createLock(workingDirectory);
    try {
        physicalLock.lock();
        executeMaven(new ArchetypeGenerateCommand(workingDirectoryPath.toString(), archetypeGav, templateGav));
        checkModuleValid(workingDirectoryPath.resolve(templateGav.getArtifactId()));
        finishAddExternalArchetype(templateGav, workingDirectory);
    } catch (GitAPIException | MavenEmbedderException e) {
        LOGGER.error(String.format("Failed to add the archetype %s", templateGav), e);
    } finally {
        physicalLock.unlock();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) FileSystemLock(org.uberfire.java.nio.fs.jgit.FileSystemLock) MavenEmbedderException(org.appformer.maven.integration.embedder.MavenEmbedderException) ArchetypeGenerateCommand(org.kie.workbench.common.screens.archetype.mgmt.backend.maven.ArchetypeGenerateCommand) File(java.io.File)

Example 3 with MavenEmbedderException

use of org.appformer.maven.integration.embedder.MavenEmbedderException in project kie-wb-common by kiegroup.

the class ArchetypeServiceImplTest method executeMavenSuccessTest.

@Test
public void executeMavenSuccessTest() throws MavenEmbedderException {
    final AbstractMavenCommand command = mock(AbstractMavenCommand.class);
    doReturn(mock(MavenExecutionResult.class)).when(command).execute();
    try {
        service.executeMaven(command);
    } catch (Exception e) {
        fail("Should not have thrown any exception");
    }
}
Also used : MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) AbstractMavenCommand(org.kie.workbench.common.screens.archetype.mgmt.backend.maven.AbstractMavenCommand) MavenEmbedderException(org.appformer.maven.integration.embedder.MavenEmbedderException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ArchetypeAlreadyExistsException(org.kie.workbench.common.screens.archetype.mgmt.shared.exceptions.ArchetypeAlreadyExistsException) InvalidArchetypeException(org.kie.workbench.common.screens.archetype.mgmt.shared.exceptions.InvalidArchetypeException) MavenExecutionException(org.kie.workbench.common.screens.archetype.mgmt.shared.exceptions.MavenExecutionException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) Test(org.junit.Test)

Aggregations

MavenEmbedderException (org.appformer.maven.integration.embedder.MavenEmbedderException)3 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 File (java.io.File)1 PrintStream (java.io.PrintStream)1 Properties (java.util.Properties)1 MavenEmbedder (org.appformer.maven.integration.embedder.MavenEmbedder)1 MavenRequest (org.appformer.maven.integration.embedder.MavenRequest)1 WrongRepositoryStateException (org.eclipse.jgit.api.errors.WrongRepositoryStateException)1 BuildException (org.guvnor.ala.exceptions.BuildException)1 Test (org.junit.Test)1 AbstractMavenCommand (org.kie.workbench.common.screens.archetype.mgmt.backend.maven.AbstractMavenCommand)1 ArchetypeGenerateCommand (org.kie.workbench.common.screens.archetype.mgmt.backend.maven.ArchetypeGenerateCommand)1 ArchetypeAlreadyExistsException (org.kie.workbench.common.screens.archetype.mgmt.shared.exceptions.ArchetypeAlreadyExistsException)1 InvalidArchetypeException (org.kie.workbench.common.screens.archetype.mgmt.shared.exceptions.InvalidArchetypeException)1 MavenExecutionException (org.kie.workbench.common.screens.archetype.mgmt.shared.exceptions.MavenExecutionException)1 Path (org.uberfire.java.nio.file.Path)1 FileSystemLock (org.uberfire.java.nio.fs.jgit.FileSystemLock)1