Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8180] Fail install/deploy if rogue Maven Plugin metadata found #1612

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Complete the UT
  • Loading branch information
cstamas committed Jul 11, 2024
commit 734cf47918b9ffe7fb37efd19a428a74b7460389
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

Expand Down Expand Up @@ -132,14 133,34 @@ private PluginInfo extractPluginInfo(Artifact artifact) {
String artifactId = root.getChild("artifactId").getValue();
String goalPrefix = root.getChild("goalPrefix").getValue();
String name = root.getChild("name").getValue();
return new PluginInfo(groupId, artifactId, goalPrefix, name);
// sanity check: plugin descriptor extracted from artifact must have same GA
if (Objects.equals(artifact.getGroupId(), groupId)
&& Objects.equals(artifact.getArtifactId(), artifactId)) {
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)");
}
}
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
// here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent
}
}
}
return null;
}

public static final class InvalidArtifactPluginMetadataException extends IllegalArgumentException {
InvalidArtifactPluginMetadataException(String s) {
super(s);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 146,11 @@ private PluginInfo extractPluginInfo(Artifact artifact) {
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)");
} }
}
}
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
// here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 227,8 @@ void testRoguePlugin() throws Exception {
installRequest.addArtifact(artifactResult.getArtifact());

DefaultRepositorySystemSession loc = new DefaultRepositorySystemSession(session);
loc.setLocalRepositoryManager(system.newLocalRepositoryManager(
session, new LocalRepository(Files.createTempDirectory("local"))));
loc.setLocalRepositoryManager(
system.newLocalRepositoryManager(session, new LocalRepository(Files.createTempDirectory("local"))));
try {
system.install(loc, installRequest);
fail("install should fail");
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 1,31 @@
<?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>
Original file line number Diff line number Diff line change
@@ -0,0 1,34 @@
<?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>