Skip to content

Commit 363672e

Browse files
Copilotlaeubi
andcommitted
Add ExtensionResolutionExceptionFacade for Maven 3.x/4.x compatibility
Co-authored-by: laeubi <[email protected]>
1 parent 4963def commit 363672e

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/PlexusContainerManager.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.codehaus.plexus.DefaultPlexusContainer;
5050
import org.codehaus.plexus.PlexusConstants;
5151
import org.codehaus.plexus.PlexusContainer;
52-
import org.codehaus.plexus.PlexusContainerException;
5352
import org.codehaus.plexus.classworlds.ClassWorld;
5453
import org.codehaus.plexus.classworlds.realm.ClassRealm;
5554
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
@@ -71,6 +70,7 @@
7170
import org.eclipse.m2e.core.embedder.IComponentLookup;
7271
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
7372
import org.eclipse.m2e.core.internal.Messages;
73+
import org.eclipse.m2e.internal.maven.compat.ExtensionResolutionExceptionFacade;
7474

7575

7676
/**
@@ -180,14 +180,8 @@ public IMavenPlexusContainer aquire(File basedir) throws Exception {
180180
containerMap.put(canonicalDirectory, plexusContainer);
181181
} catch(ExtensionResolutionException e) {
182182
//TODO how can we create an error marker on the extension file?
183-
CoreExtension extension = e.getExtension();
184183
File file = new File(directory, IMavenPlexusContainer.EXTENSIONS_FILENAME);
185-
throw new PlexusContainerException(
186-
"can't create plexus container for basedir = " + basedir.getAbsolutePath() + " because the extension "
187-
+ extension.getGroupId() + ":" + extension.getArtifactId() + ":" + extension.getVersion()
188-
+ " can't be loaded (defined in "
189-
+ file.getAbsolutePath() + ").",
190-
e);
184+
new ExtensionResolutionExceptionFacade(e).throwForFile(file);
191185
}
192186
}
193187
return plexusContainer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 Christoph Läubrich and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
********************************************************************************/
13+
14+
package org.eclipse.m2e.internal.maven.compat;
15+
16+
import java.io.File;
17+
18+
import org.apache.maven.cli.internal.ExtensionResolutionException;
19+
import org.apache.maven.cli.internal.extension.model.CoreExtension;
20+
import org.codehaus.plexus.PlexusContainerException;
21+
22+
/**
23+
* Facade for {@link ExtensionResolutionException} to avoid direct usage that might change in Maven 4.
24+
* This facade wraps the exception and provides a method to throw it as a PlexusContainerException
25+
* with appropriate context information.
26+
*/
27+
public class ExtensionResolutionExceptionFacade {
28+
29+
private final ExtensionResolutionException exception;
30+
31+
public ExtensionResolutionExceptionFacade(ExtensionResolutionException exception) {
32+
if(exception == null) {
33+
throw new IllegalArgumentException("exception cannot be null");
34+
}
35+
this.exception = exception;
36+
}
37+
38+
/**
39+
* Throws a PlexusContainerException with information about the failed extension and the file where it was defined.
40+
*
41+
* @param file the extensions file where the failed extension was defined
42+
* @throws PlexusContainerException always thrown with details about the failed extension
43+
*/
44+
public void throwForFile(File file) throws PlexusContainerException {
45+
CoreExtension extension = exception.getExtension();
46+
throw new PlexusContainerException(
47+
"can't create plexus container because the extension " + extension.getGroupId() + ":"
48+
+ extension.getArtifactId() + ":" + extension.getVersion() + " can't be loaded (defined in "
49+
+ file.getAbsolutePath() + ").",
50+
exception);
51+
}
52+
}

0 commit comments

Comments
 (0)