You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/01/28 20:13:34 UTC
[maven-artifact-transfer] branch master updated: [MSHARED-678] -
Add null check for ProjectInstaller Interface
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git
The following commit(s) were added to refs/heads/master by this push:
new 4e3ac40 [MSHARED-678] - Add null check for ProjectInstaller Interface
4e3ac40 is described below
commit 4e3ac40f6f9448ae6df1e5bf549c9fab8bea2c2a
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sun Jan 28 21:13:07 2018 +0100
[MSHARED-678] - Add null check for ProjectInstaller Interface
---
.../shared/project/install/ProjectInstaller.java | 4 +-
.../install/internal/DefaultProjectInstaller.java | 23 ++++++--
.../internal/DefaultProjectInstallerTest.java | 69 ++++++++++++++++++++++
3 files changed, 90 insertions(+), 6 deletions(-)
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 aa078e2..0ddc46c 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
@@ -70,8 +70,10 @@ public interface ProjectInstaller
* @throws IOException In case of problems related to checksums.
* @throws ArtifactInstallerException In case of problems to install artifacts.
* @throws NoFileAssignedException If no file has been assigned to the project.
+ * @throws IllegalArgumentException in case of parameter <code>projectBuildingRequest</code> is <code>null</code> or
+ * parameter <code>projectInstallerRequest</code> is <code>null</code>.
*/
void install( ProjectBuildingRequest projectBuildingRequest, ProjectInstallerRequest projectInstallerRequest )
- throws IOException, ArtifactInstallerException, NoFileAssignedException;
+ throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException;
}
diff --git a/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java b/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java
index 227e537..5d277d3 100644
--- a/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java
+++ b/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java
@@ -68,13 +68,14 @@ public class DefaultProjectInstaller
* {@inheritDoc}
*/
@Override
- public void install( ProjectBuildingRequest buildingRequest, ProjectInstallerRequest request )
- throws IOException, ArtifactInstallerException, NoFileAssignedException
+ public void install( ProjectBuildingRequest buildingRequest, ProjectInstallerRequest installerRequest )
+ throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException
{
- MavenProject project = request.getProject();
- boolean createChecksum = request.isCreateChecksum();
- boolean updateReleaseInfo = request.isUpdateReleaseInfo();
+ validateParameters( buildingRequest, installerRequest );
+ MavenProject project = installerRequest.getProject();
+ boolean createChecksum = installerRequest.isCreateChecksum();
+ boolean updateReleaseInfo = installerRequest.isUpdateReleaseInfo();
Artifact artifact = project.getArtifact();
String packaging = project.getPackaging();
@@ -145,6 +146,18 @@ public class DefaultProjectInstaller
installChecksums( metadataFiles );
}
+ private void validateParameters( ProjectBuildingRequest buildingRequest, ProjectInstallerRequest installerRequest )
+ {
+ if ( buildingRequest == null )
+ {
+ throw new IllegalArgumentException( "The parameter buildingRequest is not allowed to be null." );
+ }
+ if ( installerRequest == null )
+ {
+ throw new IllegalArgumentException( "The parameter installerRequest is not allowed to be null." );
+ }
+ }
+
/**
* Installs the checksums for the specified artifact if this has been enabled in the plugin configuration. This
* method creates checksums for files that have already been installed to the local repo to account for on-the-fly
diff --git a/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java b/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java
new file mode 100644
index 0000000..7d1cc8e
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java
@@ -0,0 +1,69 @@
+package org.apache.maven.shared.project.install.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 java.io.IOException;
+
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
+import org.apache.maven.shared.project.NoFileAssignedException;
+import org.apache.maven.shared.project.install.ProjectInstaller;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Check the parameter contracts which have been made based on the interface {@link ProjectInstaller}.
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmabaise@apache.org</a>
+ */
+public class DefaultProjectInstallerTest
+{
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void installShouldReturnIllegalArgumentExceptionWhereBuildingRequestIsNull()
+ throws IOException, ArtifactInstallerException, NoFileAssignedException
+ {
+ DefaultProjectInstaller dai = new DefaultProjectInstaller();
+
+ thrown.expect( IllegalArgumentException.class );
+ thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
+ dai.install( null, null );
+ }
+
+ @Test
+ public void installShouldReturnIllegalArgumentExceptionWhereInstallerRequestIsNull()
+ throws IOException, ArtifactInstallerException, NoFileAssignedException
+ {
+ DefaultProjectInstaller dai = new DefaultProjectInstaller();
+
+ thrown.expect( IllegalArgumentException.class );
+ thrown.expectMessage( "The parameter installerRequest is not allowed to be null." );
+ ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
+ dai.install( pbr, null );
+ }
+
+
+
+}
--
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.