Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong realm used when executing mojos #1161

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo-bar-content
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.util.Collection;

import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.m2e.core.embedder.IComponentLookup;
Expand Down Expand Up @@ -82,6 +84,16 @@ public void testReloadExtensionAfterDeletion() throws Exception {
assertEquals("my.bundle", project1.getName());
}

@Test
public void testCopyResourcesWithMVNFolder() throws Exception {
IProject project = importProject("resources/projects/resourcesWithMVNFolder/pom.xml");
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
WorkspaceHelpers.assertNoErrors(project);
IFile file = project.getFile("target/classes/file.txt");
assertTrue(file.exists());
assertEquals("foo-bar-content", new String(file.getContents().readAllBytes()));
}

private IProject importPomlessProject(String rootProject, String... poms) throws IOException, CoreException {
IProject[] projects = importProjects("resources/projects/" + rootProject + "/", poms,
new ResolverConfiguration(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.DependencyContext;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.MojoExecutor;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.LegacySupport;
Expand Down Expand Up @@ -317,20 +318,26 @@ public MavenExecutionResult execute(MavenExecutionRequest request) {
}
}

private static void executeMojo(MavenSession session, MojoExecution execution, IComponentLookup lookup) {
private static void executeMojo(MavenSession session, MojoExecution execution, IComponentLookup lookup)
throws CoreException {
Map<MavenProject, Set<Artifact>> artifacts = new HashMap<>();
Map<MavenProject, MavenProjectMutableState> snapshots = new HashMap<>();
for(MavenProject project : session.getProjects()) {
artifacts.put(project, new LinkedHashSet<>(project.getArtifacts()));
snapshots.put(project, MavenProjectMutableState.takeSnapshot(project));
}
MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(), execution.getExecutionId());
try {
MavenProject currentProject = session.getCurrentProject();
LifecycleExecutionPlanCalculator executionPlanCalculator = lookup.lookup(LifecycleExecutionPlanCalculator.class);
executionPlanCalculator.setupMojoExecution(session, currentProject, clone);
MojoExecutor mojoExecutor = lookup.lookup(MojoExecutor.class);
DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session, List.of(execution));
mojoExecutor.ensureDependenciesAreResolved(execution.getMojoDescriptor(), session, dependencyContext);
lookup.lookup(BuildPluginManager.class).executeMojo(session, execution);
DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session, List.of(clone));
mojoExecutor.ensureDependenciesAreResolved(clone.getMojoDescriptor(), session, dependencyContext);
BuildPluginManager buildPluginManager = lookup.lookup(BuildPluginManager.class);
buildPluginManager.executeMojo(session, clone);
} catch(Exception ex) {
session.getResult().addException(ex);
throw new CoreException(Status.error("Failed to execute mojo " + clone, ex));
} finally {
for(MavenProject project : session.getProjects()) {
project.setArtifactFilter(null);
Expand Down