Skip to content

Commit

Permalink
Issue #546 - Introduce IMavenProjectFacade.getMaven()
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Apr 4, 2022
1 parent 17f39a1 commit 66f578e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.IWorkspaceClassifierResolverManager;
Expand All @@ -41,6 +42,11 @@ public static MavenPlugin getDefault() {
return INSTANCE;
}

/**
* Use {@link IMavenProjectFacade#getMaven()} instead whenever possible
*
* @return a generic Maven instance (not customized by project).
*/
public static IMaven getMaven() {
return MavenPluginActivator.getDefault().getMaven();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.ArtifactRef;
import org.eclipse.m2e.core.embedder.ArtifactRepositoryRef;
Expand Down Expand Up @@ -528,4 +529,10 @@ public List<MojoExecution> getExecutionPlan(String lifecycle, IProgressMonitor m
Map<String, List<MojoExecution>> executionPlans = getExecutionPlans(monitor);
return executionPlans != null ? executionPlans.get(lifecycle) : null;
}

@Override
public IMaven getMaven() {
// TODO: if project has Maven customization (such as a .mvn, MAVEN_OPTS...)
return MavenPlugin.getMaven();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.ArtifactRef;
import org.eclipse.m2e.core.embedder.ArtifactRepositoryRef;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;

Expand Down Expand Up @@ -137,6 +138,13 @@ public interface IMavenProjectFacade {

Set<ArtifactRepositoryRef> getPluginArtifactRepositoryRefs();

/**
* Gets an access to a Maven instance, configured according to this project.
*
* @return a Maven instance, configured according to this project
*/
IMaven getMaven();

/**
* Returns fully setup MojoExecution instance bound to project build lifecycle that matches provided mojoExecutionKey.
* Returns null if no such mojo execution.
Expand All @@ -156,4 +164,5 @@ List<MojoExecution> getMojoExecutions(String groupId, String artifactId, IProgre
String getLifecycleMappingId();

Map<MojoExecutionKey, List<IPluginExecutionMetadata>> getMojoExecutionMapping();

}

0 comments on commit 66f578e

Please sign in to comment.