[MNG-8180] Back out from failing the build (#1645)

Just warn the user for now.

Port of accepted change from 3.9.x: https://github.com/apache/maven/pull/1642

---

https://issues.apache.org/jira/browse/MNG-8180
This commit is contained in:
Tamas Cservenak 2024-08-12 13:06:59 +02:00 committed by GitHub
parent da7c2110e4
commit ad04d2c1fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 127 deletions

View File

@ -41,6 +41,8 @@ import org.eclipse.aether.impl.MetadataGenerator;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.util.ConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Maven G level metadata generator.
@ -50,6 +52,8 @@ import org.eclipse.aether.util.ConfigUtils;
class PluginsMetadataGenerator implements MetadataGenerator {
private static final String PLUGIN_DESCRIPTOR_LOCATION = "META-INF/maven/plugin.xml";
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<Object, PluginsMetadata> processedPlugins;
private final Date timestamp;
@ -139,20 +143,20 @@ class PluginsMetadataGenerator implements MetadataGenerator {
// here groupId and artifactId cannot be null
return new PluginInfo(groupId, artifactId, goalPrefix, name);
} else {
throw new InvalidArtifactPluginMetadataException(
"Artifact " + artifact.getGroupId() + ":"
+ artifact.getArtifactId()
+ " JAR (to be installed/deployed) contains Maven Plugin metadata for plugin "
+ groupId + ":" + artifactId + "; coordinates are conflicting. "
+ "Most probably your JAR contains rogue Maven Plugin metadata, "
+ "possible causes may be: shaded in Maven Plugin or some rogue resource)");
logger.warn(
"Artifact {}:{}"
+ " JAR (about to be installed/deployed) contains Maven Plugin metadata for"
+ " conflicting coordinates: {}:{}."
+ " Your JAR contains rogue Maven Plugin metadata."
+ " Possible causes may be: shaded into this JAR some Maven Plugin or some rogue resource.",
artifact.getGroupId(),
artifact.getArtifactId(),
groupId,
artifactId);
}
}
}
} catch (Exception e) {
if (e instanceof InvalidArtifactPluginMetadataException iapme) {
throw iapme;
}
// here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent
}
}
@ -167,10 +171,4 @@ class PluginsMetadataGenerator implements MetadataGenerator {
}
return null;
}
public static final class InvalidArtifactPluginMetadataException extends IllegalArgumentException {
InvalidArtifactPluginMetadataException(String s) {
super(s);
}
}
}

View File

@ -41,6 +41,8 @@ import org.eclipse.aether.impl.MetadataGenerator;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.util.ConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Maven G level metadata generator.
@ -50,6 +52,8 @@ import org.eclipse.aether.util.ConfigUtils;
class PluginsMetadataGenerator implements MetadataGenerator {
private static final String PLUGIN_DESCRIPTOR_LOCATION = "META-INF/maven/plugin.xml";
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<Object, PluginsMetadata> processedPlugins;
private final Date timestamp;
@ -140,20 +144,20 @@ class PluginsMetadataGenerator implements MetadataGenerator {
// here groupId and artifactId cannot be null
return new PluginInfo(groupId, artifactId, goalPrefix, name);
} else {
throw new InvalidArtifactPluginMetadataException(
"Artifact " + artifact.getGroupId() + ":"
+ artifact.getArtifactId()
+ " JAR (to be installed/deployed) contains Maven Plugin metadata for plugin "
+ groupId + ":" + artifactId + "; coordinates are conflicting. "
+ "Most probably your JAR contains rogue Maven Plugin metadata, "
+ "possible causes may be: shaded in Maven Plugin or some rogue resource)");
logger.warn(
"Artifact {}:{}"
+ " JAR (about to be installed/deployed) contains Maven Plugin metadata for"
+ " conflicting coordinates: {}:{}."
+ " Your JAR contains rogue Maven Plugin metadata."
+ " Possible causes may be: shaded into this JAR some Maven Plugin or some rogue resource.",
artifact.getGroupId(),
artifact.getArtifactId(),
groupId,
artifactId);
}
}
}
} catch (Exception e) {
if (e instanceof InvalidArtifactPluginMetadataException iapme) {
throw iapme;
}
// here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent
}
}
@ -168,10 +172,4 @@ class PluginsMetadataGenerator implements MetadataGenerator {
}
return null;
}
public static final class InvalidArtifactPluginMetadataException extends IllegalArgumentException {
InvalidArtifactPluginMetadataException(String s) {
super(s);
}
}
}

View File

@ -18,19 +18,15 @@
*/
package org.apache.maven.repository.internal;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.collection.CollectResult;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
import org.eclipse.aether.resolution.ArtifactDescriptorResult;
import org.eclipse.aether.resolution.ArtifactRequest;
@ -211,30 +207,4 @@ class RepositorySystemTest extends AbstractRepositoryTestCase {
void testNewSyncContext() throws Exception {
// SyncContext newSyncContext( RepositorySystemSession session, boolean shared );
}
@Test
void testRoguePlugin() throws Exception {
Artifact artifact = new DefaultArtifact("ut.simple:rogue-plugin:1.0");
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.addRepository(newTestRepository());
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
checkArtifactResult(artifactResult, "rogue-plugin-1.0.jar");
InstallRequest installRequest = new InstallRequest();
installRequest.addArtifact(artifactResult.getArtifact());
DefaultRepositorySystemSession loc = new DefaultRepositorySystemSession(session);
loc.setLocalRepositoryManager(
system.newLocalRepositoryManager(session, new LocalRepository(Files.createTempDirectory("local"))));
try {
system.install(loc, installRequest);
fail("install should fail");
} catch (Exception e) {
assertInstanceOf(PluginsMetadataGenerator.InvalidArtifactPluginMetadataException.class, e);
assertTrue(e.getMessage().contains("coordinates are conflicting"));
}
}
}

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ut.simple</groupId>
<artifactId>rogue-plugin</artifactId>
<version>1.0</version>
<name>Simple Unit Test Rogue Plugin</name>
</project>

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<metadata xmlns="http://maven.apache.org/METADATA/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/METADATA/1.1.0 http://maven.apache.org/xsd/metadata-1.1.0.xsd">
<groupId>ut.simple</groupId>
<artifactId>rogue-plugin</artifactId>
<versioning>
<latest>1.0</latest>
<release>1.0</release>
<versions>
<version>1.0</version>
</versions>
<lastUpdated>20111123122038</lastUpdated>
</versioning>
</metadata>