use of org.apache.maven.plugin.BuildPluginManager in project m2e-code-quality by m2e-code-quality.
the class AbstractMavenPluginProjectConfigurator method getResourceResolver.
public static ResourceResolver getResourceResolver(final MojoExecution mojoExecution, final MavenSession session, final IPath projectLocation) throws CoreException {
// call for side effect of ensuring that the realm is set in the
// descriptor.
final IMaven mvn = MavenPlugin.getMaven();
final List<IPath> pluginDepencyProjectLocations = new ArrayList<>();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IMavenProjectRegistry mavenProjectRegistry = MavenPlugin.getMavenProjectRegistry();
final IMavenProjectFacade[] projects = mavenProjectRegistry.getProjects();
final List<Dependency> dependencies = mojoExecution.getPlugin().getDependencies();
for (final Dependency dependency : dependencies) {
for (final IMavenProjectFacade projectFacade : projects) {
final IProject project = projectFacade.getProject();
if (!project.isAccessible()) {
LOG.debug("Project registry contains closed project {}", project);
// logic, closed projects should not be there
continue;
}
final ArtifactKey artifactKey = projectFacade.getArtifactKey();
if (artifactKey.getGroupId().equals(dependency.getGroupId()) && artifactKey.getArtifactId().equals(dependency.getArtifactId()) && artifactKey.getVersion().equals(dependency.getVersion())) {
final IResource outputLocation = root.findMember(projectFacade.getOutputLocation());
if (outputLocation != null) {
pluginDepencyProjectLocations.add(outputLocation.getLocation());
}
}
}
}
try {
// we want just the classpath of the Mojo to load resources from it
BuildPluginManager buildPluginManager = ((MavenImpl) mvn).lookupComponent(BuildPluginManager.class);
ClassRealm pluginRealm = buildPluginManager.getPluginRealm(session, mojoExecution.getMojoDescriptor().getPluginDescriptor());
return new ResourceResolver(pluginRealm, projectLocation, pluginDepencyProjectLocations);
} catch (PluginResolutionException | PluginManagerException e) {
throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(AbstractMavenPluginProjectConfigurator.class).getSymbolicName(), "Failed to access classpath of mojo " + mojoExecution.getMojoDescriptor().getId(), e));
}
}
use of org.apache.maven.plugin.BuildPluginManager in project vertx-maven-plugin by reactiverse.
the class MojoUtils method compile.
/**
* Execute the Maven Compiler Plugin to compile java sources.
*
* @param project the project
* @param mavenSession the session
* @param buildPluginManager the build plugin manager
* @throws Exception if the compilation fails for any reason
*/
public static void compile(MavenProject project, MavenSession mavenSession, BuildPluginManager buildPluginManager) throws Exception {
Optional<Plugin> mvnCompilerPlugin = project.getBuildPlugins().stream().filter(plugin -> A_MAVEN_COMPILER_PLUGIN.equals(plugin.getArtifactId())).findFirst();
String pluginVersion = properties.getProperty(V_MAVEN_COMPILER_PLUGIN);
if (mvnCompilerPlugin.isPresent()) {
pluginVersion = mvnCompilerPlugin.get().getVersion();
}
Optional<Xpp3Dom> optConfiguration = buildConfiguration(project, A_MAVEN_COMPILER_PLUGIN, GOAL_COMPILE);
if (optConfiguration.isPresent()) {
Xpp3Dom configuration = optConfiguration.get();
executeMojo(plugin(G_MAVEN_COMPILER_PLUGIN, A_MAVEN_COMPILER_PLUGIN, pluginVersion), goal(GOAL_COMPILE), configuration, executionEnvironment(project, mavenSession, buildPluginManager));
}
}
Aggregations