diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/PlexusContainerManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/PlexusContainerManager.java index ed164c42a..947e27087 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/PlexusContainerManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/PlexusContainerManager.java @@ -49,7 +49,6 @@ import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; @@ -71,6 +70,7 @@ import org.eclipse.m2e.core.embedder.IComponentLookup; import org.eclipse.m2e.core.embedder.IMavenConfiguration; import org.eclipse.m2e.core.internal.Messages; +import org.eclipse.m2e.internal.maven.compat.ExtensionResolutionExceptionFacade; /** @@ -180,14 +180,8 @@ public IMavenPlexusContainer aquire(File basedir) throws Exception { containerMap.put(canonicalDirectory, plexusContainer); } catch(ExtensionResolutionException e) { //TODO how can we create an error marker on the extension file? - CoreExtension extension = e.getExtension(); File file = new File(directory, IMavenPlexusContainer.EXTENSIONS_FILENAME); - throw new PlexusContainerException( - "can't create plexus container for basedir = " + basedir.getAbsolutePath() + " because the extension " - + extension.getGroupId() + ":" + extension.getArtifactId() + ":" + extension.getVersion() - + " can't be loaded (defined in " - + file.getAbsolutePath() + ").", - e); + new ExtensionResolutionExceptionFacade(e).throwForFile(file); } } return plexusContainer; diff --git a/org.eclipse.m2e.maven.runtime/src/main/java/org/eclipse/m2e/internal/maven/compat/ExtensionResolutionExceptionFacade.java b/org.eclipse.m2e.maven.runtime/src/main/java/org/eclipse/m2e/internal/maven/compat/ExtensionResolutionExceptionFacade.java new file mode 100644 index 000000000..949c6ad15 --- /dev/null +++ b/org.eclipse.m2e.maven.runtime/src/main/java/org/eclipse/m2e/internal/maven/compat/ExtensionResolutionExceptionFacade.java @@ -0,0 +1,52 @@ +/******************************************************************************** + * Copyright (c) 2025 Christoph Läubrich and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christoph Läubrich - initial API and implementation + ********************************************************************************/ + +package org.eclipse.m2e.internal.maven.compat; + +import java.io.File; + +import org.apache.maven.cli.internal.ExtensionResolutionException; +import org.apache.maven.cli.internal.extension.model.CoreExtension; +import org.codehaus.plexus.PlexusContainerException; + +/** + * Facade for {@link ExtensionResolutionException} to avoid direct usage that might change in Maven 4. + * This facade wraps the exception and provides a method to throw it as a PlexusContainerException + * with appropriate context information. + */ +public class ExtensionResolutionExceptionFacade { + + private final ExtensionResolutionException exception; + + public ExtensionResolutionExceptionFacade(ExtensionResolutionException exception) { + if(exception == null) { + throw new IllegalArgumentException("exception cannot be null"); + } + this.exception = exception; + } + + /** + * Throws a PlexusContainerException with information about the failed extension and the file where it was defined. + * + * @param file the extensions file where the failed extension was defined + * @throws PlexusContainerException always thrown with details about the failed extension + */ + public void throwForFile(File file) throws PlexusContainerException { + CoreExtension extension = exception.getExtension(); + throw new PlexusContainerException( + "can't create plexus container because the extension " + extension.getGroupId() + ":" + + extension.getArtifactId() + ":" + extension.getVersion() + " can't be loaded (defined in " + + file.getAbsolutePath() + ").", + exception); + } +}