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());
}
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);
}
}
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);
}
}
}
}
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");
}
}
}
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;
}
Aggregations