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-7375] prevent potential NPE in Metadata.merge(...) #645

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions maven-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ under the License.
<artifactId>maven-repository-metadata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata-builder</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions maven-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata-builder</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.io.MetadataReader;
import org.apache.maven.artifact.repository.metadata.validator.MetadataValidator;
import org.apache.maven.artifact.repository.metadata.validator.MetadataValidator.Level;
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.BuildPluginManager;
Expand All @@ -38,6 +40,7 @@
import org.apache.maven.plugin.prefix.PluginPrefixRequest;
import org.apache.maven.plugin.prefix.PluginPrefixResolver;
import org.apache.maven.plugin.prefix.PluginPrefixResult;
import org.apache.maven.repository.internal.RepositoryListenerMetadataProblemCollector;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryEvent.EventType;
Expand Down Expand Up @@ -68,13 +71,18 @@ public class DefaultPluginPrefixResolver implements PluginPrefixResolver {
private final BuildPluginManager pluginManager;
private final RepositorySystem repositorySystem;
private final MetadataReader metadataReader;
private final MetadataValidator metadataValidator;

@Inject
public DefaultPluginPrefixResolver(
BuildPluginManager pluginManager, RepositorySystem repositorySystem, MetadataReader metadataReader) {
BuildPluginManager pluginManager,
RepositorySystem repositorySystem,
MetadataReader metadataReader,
MetadataValidator metadataValidator) {
this.pluginManager = pluginManager;
this.repositorySystem = repositorySystem;
this.metadataReader = metadataReader;
this.metadataValidator = metadataValidator;
}

public PluginPrefixResult resolve(PluginPrefixRequest request) throws NoPluginFoundForPrefixException {
Expand Down Expand Up @@ -230,7 +238,12 @@ private PluginPrefixResult resolveFromRepository(
Map<String, ?> options = Collections.singletonMap(MetadataReader.IS_STRICT, Boolean.FALSE);

Metadata pluginGroupMetadata = metadataReader.read(metadata.getFile(), options);

metadataValidator.validate(
pluginGroupMetadata,
Level.GROUP_ID,
null,
new RepositoryListenerMetadataProblemCollector(
request.getRepositorySession(), repository, trace, metadata));
List<org.apache.maven.artifact.repository.metadata.Plugin> plugins = pluginGroupMetadata.getPlugins();

if (plugins != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.artifact.repository.metadata.io.MetadataReader;
import org.apache.maven.artifact.repository.metadata.validator.MetadataValidator;
import org.apache.maven.artifact.repository.metadata.validator.MetadataValidator.Level;
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MavenPluginManager;
Expand All @@ -45,6 +47,7 @@
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.plugin.version.PluginVersionResult;
import org.apache.maven.repository.internal.RepositoryListenerMetadataProblemCollector;
import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryEvent.EventType;
import org.eclipse.aether.RepositoryListener;
Expand Down Expand Up @@ -78,17 +81,20 @@ public class DefaultPluginVersionResolver implements PluginVersionResolver {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final RepositorySystem repositorySystem;
private final MetadataReader metadataReader;
private final MetadataValidator metadataValidator;
private final MavenPluginManager pluginManager;
private final VersionScheme versionScheme;

@Inject
public DefaultPluginVersionResolver(
RepositorySystem repositorySystem,
MetadataReader metadataReader,
MetadataValidator metadataValidator,
MavenPluginManager pluginManager,
VersionScheme versionScheme) {
this.repositorySystem = repositorySystem;
this.metadataReader = metadataReader;
this.metadataValidator = metadataValidator;
this.pluginManager = pluginManager;
this.versionScheme = versionScheme;
}
Expand Down Expand Up @@ -280,7 +286,11 @@ private void mergeMetadata(
Map<String, ?> options = Collections.singletonMap(MetadataReader.IS_STRICT, Boolean.FALSE);

Metadata repoMetadata = metadataReader.read(metadata.getFile(), options);

metadataValidator.validate(
repoMetadata,
Level.GROUP_ID,
null,
new RepositoryListenerMetadataProblemCollector(session, repository, trace, metadata));
mergeMetadata(versions, repoMetadata, repository);
} catch (IOException e) {
invalidMetadata(session, trace, metadata, repository, e);
Expand Down
60 changes: 60 additions & 0 deletions maven-repository-metadata-builder/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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>

<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>4.0.0-alpha-8-SNAPSHOT</version>
</parent>

<artifactId>maven-repository-metadata-builder</artifactId>

<name>Maven Repository Metadata Builder</name>
<description>The repository metadata builder</description>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
</dependency>
<!-- not needed as this only contains the validators for now
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-builder-support</artifactId>
</dependency>-->

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Loading