This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MSHARED-656 in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git
commit b702f0145ab0a0e183cc18cea408ba21843e2de9 Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Wed Jan 31 21:31:44 2018 +0100 Added argument checks. Added DefaultDependencyCollectorTest --- .../dependencies/collect/DependencyCollector.java | 6 ++ .../internal/DefaultDependencyCollector.java | 52 +++++++++- .../shared/project/deploy/ProjectDeployer.java | 2 +- .../shared/project/install/ProjectInstaller.java | 2 +- .../internal/DefaultDependencyCollectorTest.java | 115 +++++++++++++++++++++ 5 files changed, 170 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java b/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java index c7d6783..ce996ed 100644 --- a/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java +++ b/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java @@ -40,6 +40,8 @@ public interface DependencyCollector * @param root {@link Dependency} * @return {@link CollectorResult} * @throws DependencyCollectorException in case of an error. + * @throws IllegalArgumentException in case of parameter <code>buildingRequest</code> is <code>null</code> or + * parameter <code>root</code> is <code>null</code>. */ CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency root ) throws DependencyCollectorException; @@ -50,6 +52,8 @@ public interface DependencyCollector * @return {@link CollectorResult} * @throws DependencyCollectorException in case of an error which can be a component lookup error or * an error while trying to look up the dependencies. + * @throws IllegalArgumentException in case of parameter <code>buildingRequest</code> is <code>null</code> or + * parameter <code>root</code> is <code>null</code>. */ CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) throws DependencyCollectorException; @@ -60,6 +64,8 @@ public interface DependencyCollector * @return {@link CollectorResult} * @throws DependencyCollectorException in case of an error which can be a component lookup error or * an error while trying to look up the dependencies. + * @throws IllegalArgumentException in case of parameter <code>buildingRequest</code> is <code>null</code> or + * parameter <code>root</code> is <code>null</code>. */ CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Model root ) throws DependencyCollectorException; diff --git a/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java b/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java index 19bdc32..ed8f331 100644 --- a/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java +++ b/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java @@ -36,18 +36,21 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * This DependencyCollector passes the request to the proper Maven 3.x implementation - * + * * @author Robert Scholte */ @Component( role = DependencyCollector.class, hint = "default" ) -public class DefaultDependencyCollector implements DependencyCollector, Contextualizable +public class DefaultDependencyCollector + implements DependencyCollector, Contextualizable { private PlexusContainer container; - + @Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency root ) throws DependencyCollectorException { + validateParameters( buildingRequest, root ); + try { String hint = isMaven31() ? "maven31" : "maven3"; @@ -61,11 +64,13 @@ public class DefaultDependencyCollector implements DependencyCollector, Contextu throw new DependencyCollectorException( e.getMessage(), e ); } } - + @Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) throws DependencyCollectorException { + validateParameters( buildingRequest, root ); + try { String hint = isMaven31() ? "maven31" : "maven3"; @@ -79,11 +84,13 @@ public class DefaultDependencyCollector implements DependencyCollector, Contextu throw new DependencyCollectorException( e.getMessage(), e ); } } - + @Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Model root ) throws DependencyCollectorException { + validateParameters( buildingRequest, root ); + try { String hint = isMaven31() ? "maven31" : "maven3"; @@ -98,6 +105,41 @@ public class DefaultDependencyCollector implements DependencyCollector, Contextu } } + private void validateParameters( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) + { + validateBuildingRequest( buildingRequest ); + if ( root == null ) + { + throw new IllegalArgumentException( "The parameter root is not allowed to be null." ); + } + } + + private void validateParameters( ProjectBuildingRequest buildingRequest, Dependency root ) + { + validateBuildingRequest( buildingRequest ); + if ( root == null ) + { + throw new IllegalArgumentException( "The parameter root is not allowed to be null." ); + } + } + + private void validateParameters( ProjectBuildingRequest buildingRequest, Model root ) + { + validateBuildingRequest( buildingRequest ); + if ( root == null ) + { + throw new IllegalArgumentException( "The parameter root is not allowed to be null." ); + } + } + + private void validateBuildingRequest( ProjectBuildingRequest buildingRequest ) + { + if ( buildingRequest == null ) + { + throw new IllegalArgumentException( "The parameter buildingRequest is not allowed to be null." ); + } + } + /** * @return true if the current Maven version is Maven 3.1. */ diff --git a/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java b/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java index 98e131d..b09adeb 100644 --- a/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java +++ b/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java @@ -62,6 +62,6 @@ public interface ProjectDeployer */ void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest request, ArtifactRepository artifactRepository ) - throws NoFileAssignedException, IllegalArgumentException, ArtifactDeployerException; + throws NoFileAssignedException, ArtifactDeployerException; } diff --git a/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java b/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java index 8d92cf5..0fab22e 100644 --- a/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java +++ b/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java @@ -74,6 +74,6 @@ public interface ProjectInstaller * parameter <code>projectInstallerRequest</code> is <code>null</code>. */ void install( ProjectBuildingRequest projectBuildingRequest, ProjectInstallerRequest projectInstallerRequest ) - throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException; + throws IOException, ArtifactInstallerException, NoFileAssignedException; } diff --git a/src/test/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollectorTest.java b/src/test/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollectorTest.java new file mode 100644 index 0000000..5e48299 --- /dev/null +++ b/src/test/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollectorTest.java @@ -0,0 +1,115 @@ +package org.apache.maven.shared.dependencies.collect.internal; + +/* + * 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. + */ + +import static org.mockito.Mockito.mock; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; +import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; +import org.apache.maven.shared.dependencies.DependableCoordinate; +import org.apache.maven.shared.dependencies.collect.DependencyCollector; +import org.apache.maven.shared.dependencies.collect.DependencyCollectorException; +import org.apache.maven.shared.dependencies.collect.internal.DefaultDependencyCollector; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class DefaultDependencyCollectorTest +{ + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private DependencyCollector dc; + + @Before + public void setUp() + { + dc = new DefaultDependencyCollector(); + } + + @Test + public void collectDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterBuildingRequestIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dc.collectDependencies( null, (DependableCoordinate) null ); + } + + @Test + public void collectDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterRootIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter root is not allowed to be null." ); + + ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); + dc.collectDependencies( request, (DependableCoordinate) null ); + } + + @Test + public void collectDependenciesWithDependencyShouldFailWithIAEWhenParameterBuildingRequestIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dc.collectDependencies( null, (Dependency) null ); + } + + @Test + public void collectDependenciesWithDependencyShouldFailWithIAEWhenParameterRootIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter root is not allowed to be null." ); + + ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); + dc.collectDependencies( request, (Dependency) null ); + } + + @Test + public void collectDependenciesWithModelShouldFailWithIAEWhenParameterBuildingRequestIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dc.collectDependencies( null, (Model) null ); + } + + @Test + public void collectDependenciesWithModelShouldFailWithIAEWhenParameterRootIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter root is not allowed to be null." ); + + ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); + dc.collectDependencies( request, (Model) null ); + } + +} -- To stop receiving notification emails like this one, please contact khmarba...@apache.org.