|
| 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