Skip to content

Commit

Permalink
Propagate Mojo-lookup errors and create test-case for eclipse-m2e#1150
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Dec 30, 2022
1 parent 7fca6de commit d6bea0b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
Empty file.
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 @@ -317,7 +317,8 @@ 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()) {
Expand All @@ -331,6 +332,7 @@ private static void executeMojo(MavenSession session, MojoExecution execution, I
lookup.lookup(BuildPluginManager.class).executeMojo(session, execution);
} catch(Exception ex) {
session.getResult().addException(ex);
throw new CoreException(Status.error("", ex));
} finally {
for(MavenProject project : session.getProjects()) {
project.setArtifactFilter(null);
Expand Down

0 comments on commit d6bea0b

Please sign in to comment.