Search in sources :

Example 16 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project xtext-xtend by eclipse.

the class XtendProjectConfigurator method configure.

@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    addNature(request.getProject(), XtextProjectHelper.NATURE_ID, monitor);
    OutputConfiguration config = new XtendOutputConfigurationProvider().getOutputConfigurations().iterator().next();
    List<MojoExecution> executions = getMojoExecutions(request, monitor);
    SubMonitor progress = SubMonitor.convert(monitor, executions.size());
    for (MojoExecution execution : executions) {
        String goal = execution.getGoal();
        if (goal.equals("compile")) {
            readCompileConfig(config, request, execution, progress.split(1));
        } else if (goal.equals("testCompile")) {
            readTestCompileConfig(config, request, execution, progress.split(1));
        } else if (goal.equals("xtend-install-debug-info")) {
            readDebugInfoConfig(config, request, execution, progress.split(1));
        } else if (goal.equals("xtend-test-install-debug-info")) {
            readTestDebugInfoConfig(config, request, execution, progress.split(1));
        }
    }
    writePreferences(config, request.getProject());
}
Also used : MojoExecution(org.apache.maven.plugin.MojoExecution) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) SubMonitor(org.eclipse.core.runtime.SubMonitor) XtendOutputConfigurationProvider(org.eclipse.xtend.core.compiler.XtendOutputConfigurationProvider)

Example 17 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project meecrowave by apache.

the class MeecrowaveBundleMojoTest method bundle.

@Test
public void bundle() throws Exception {
    final File moduleBase = jarLocation(MeecrowaveBundleMojoTest.class).getParentFile().getParentFile();
    final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
    final File pom = new File(basedir, "pom.xml");
    final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(basedir);
    final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
    configuration.setRepositorySession(repositorySession);
    final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
    final Build build = new Build();
    final File buildDir = new File("target/" + getClass().getName() + "/build");
    build.setDirectory(buildDir.getAbsolutePath());
    project.setBuild(build);
    final MavenSession session = mojo.newMavenSession(project);
    final MojoExecution execution = mojo.newMojoExecution("bundle");
    execution.getConfiguration().addChild(new Xpp3Dom("enforceMeecrowave") {

        {
            setValue(Boolean.FALSE.toString());
        }
    });
    execution.getConfiguration().addChild(new Xpp3Dom("enforceCommonsCli") {

        {
            setValue(Boolean.FALSE.toString());
        }
    });
    execution.getConfiguration().addChild(new Xpp3Dom("conf") {

        {
            setValue("src/main/meecrowave/conf");
        }
    });
    execution.getConfiguration().addChild(new Xpp3Dom("webapp") {

        {
            setValue("src/main/webapp");
        }
    });
    mojo.executeMojo(session, project, execution);
    assertTrue(buildDir.exists());
    try (final ZipFile zip = new ZipFile(new File(buildDir, "test-meecrowave-distribution.zip"))) {
        assertTrue(zip.getEntry("test-distribution/docBase/sub/index.html") != null);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) ZipFile(java.util.zip.ZipFile) MojoExecution(org.apache.maven.plugin.MojoExecution) Build(org.apache.maven.model.Build) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 18 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project xtext-eclipse by eclipse.

the class XtextProjectConfigurator method configureLanguages.

private void configureLanguages(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    List<MojoExecution> executions = getMojoExecutions(request, monitor);
    SubMonitor progress = SubMonitor.convert(monitor, executions.size());
    for (MojoExecution execution : executions) {
        Languages languages = maven.getMojoParameterValue(request.getMavenProject(), execution, "languages", Languages.class, progress.split(1));
        if (languages != null) {
            ProjectScope projectPreferences = new ProjectScope(request.getProject());
            for (Language language : languages) {
                configureLanguage(projectPreferences, language, request);
            }
        }
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) MojoExecution(org.apache.maven.plugin.MojoExecution) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 19 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project meecrowave by apache.

the class MeecrowaveRunMojoTest method run.

@Test
public void run() throws Exception {
    final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
    final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
    final File pom = new File(basedir, "pom.xml");
    final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(basedir);
    final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
    configuration.setRepositorySession(repositorySession);
    final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
    final MavenSession session = mojo.newMavenSession(project);
    final int port;
    try (final ServerSocket serverSocket = new ServerSocket(0)) {
        port = serverSocket.getLocalPort();
    }
    final MojoExecution execution = mojo.newMojoExecution("run");
    execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {

        {
            setValue(Integer.toString(port));
        }
    });
    final InputStream in = System.in;
    final CountDownLatch latch = new CountDownLatch(1);
    System.setIn(new InputStream() {

        // just to not return nothing
        private int val = 2;

        @Override
        public int read() throws IOException {
            try {
                latch.await();
            } catch (final InterruptedException e) {
                Thread.interrupted();
                fail(e.getMessage());
            }
            return val--;
        }
    });
    final Thread runner = new Thread() {

        @Override
        public void run() {
            try {
                mojo.executeMojo(session, project, execution);
            } catch (final Exception e) {
                fail(e.getMessage());
            }
        }
    };
    try {
        runner.start();
        for (int i = 0; i < 120; i++) {
            try {
                assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
                latch.countDown();
                break;
            } catch (final Exception | AssertionError e) {
                Thread.sleep(500);
            }
        }
    } finally {
        runner.join(TimeUnit.MINUTES.toMillis(1));
        System.setIn(in);
        if (runner.isAlive()) {
            runner.interrupt();
            fail("Runner didn't terminate properly");
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) InputStream(java.io.InputStream) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) URL(java.net.URL) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) File(java.io.File) Test(org.junit.Test)

Example 20 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project liferay-ide by liferay.

the class MavenUtil method executeMojoGoal.

public static IStatus executeMojoGoal(IMavenProjectFacade facade, IMavenExecutionContext context, String goal, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    IMaven maven = MavenPlugin.getMaven();
    List<String> goals = Collections.singletonList(goal);
    MavenProject mavenProject = facade.getMavenProject(monitor);
    MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    Plugin plugin6x = getPlugin(facade, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
    String executionArtifactId = null;
    if (plugin6x != null) {
        executionArtifactId = ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_ARTIFACT_ID;
    } else {
        Plugin plugin7x = getPlugin(facade, ILiferayMavenConstants.SERVICE_BUILDER_PLUGIN_KEY, monitor);
        if (plugin7x != null) {
            executionArtifactId = ILiferayMavenConstants.SERVICE_BUILDER_PLUGIN_ARTIFACT_ID;
        }
    }
    MojoExecution liferayMojoExecution = getExecution(plan, executionArtifactId);
    if (liferayMojoExecution != null) {
        ResolverConfiguration configuration = facade.getResolverConfiguration();
        configuration.setResolveWorkspaceProjects(true);
        maven.execute(mavenProject, liferayMojoExecution, monitor);
    }
    MavenSession session = context.getSession();
    List<Throwable> exceptions = session.getResult().getExceptions();
    if (exceptions.size() == 1) {
        retval = LiferayMavenCore.createErrorStatus(exceptions.get(0));
    } else if (exceptions.size() > 1) {
        List<IStatus> statues = new ArrayList<>();
        for (Throwable t : exceptions) {
            statues.add(LiferayMavenCore.createErrorStatus(t));
        }
        IStatus firstStatus = statues.get(0);
        retval = new MultiStatus(LiferayMavenCore.PLUGIN_ID, IStatus.ERROR, statues.toArray(new IStatus[0]), firstStatus.getMessage(), firstStatus.getException());
    }
    if (retval == null) {
        return Status.OK_STATUS;
    }
    return retval;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) List(java.util.List) ArrayList(java.util.ArrayList) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven) Plugin(org.apache.maven.model.Plugin) MavenPlugin(org.eclipse.m2e.core.MavenPlugin)

Aggregations

MojoExecution (org.apache.maven.plugin.MojoExecution)33 MavenProject (org.apache.maven.project.MavenProject)22 MavenSession (org.apache.maven.execution.MavenSession)13 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)7 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)6 Plugin (org.apache.maven.model.Plugin)6 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 IMaven (org.eclipse.m2e.core.embedder.IMaven)5 ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)5 Path (java.nio.file.Path)4 MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 IMavenExecutionContext (org.eclipse.m2e.core.embedder.IMavenExecutionContext)4 Set (java.util.Set)3