You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2022/05/06 09:24:16 UTC
[maven-deploy-plugin] 01/01: [MDEPLOY-292] Require Java 8
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MDEPLOY-292
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git
commit fdafd16a1fb3ea2ab4afe6f6c3fbd8f7161556de
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri May 6 11:24:04 2022 +0200
[MDEPLOY-292] Require Java 8
---
pom.xml | 2 +-
.../maven/plugins/deploy/DeployFileMojo.java | 69 ++++------------------
.../apache/maven/plugins/deploy/DeployMojo.java | 4 +-
.../maven/plugins/deploy/DeployFileMojoTest.java | 11 ++--
.../plugins/deploy/DeployFileMojoUnitTest.java | 15 +++--
.../maven/plugins/deploy/DeployMojoTest.java | 33 ++++++-----
.../org/apache/maven/plugins/deploy/Utils.java | 1 +
.../plugins/deploy/stubs/ArtifactDeployerStub.java | 2 -
.../deploy/stubs/ArtifactRepositoryStub.java | 2 +-
.../plugins/deploy/stubs/DeployArtifactStub.java | 4 +-
10 files changed, 50 insertions(+), 93 deletions(-)
diff --git a/pom.xml b/pom.xml
index 1284f13..8b1e3f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@ under the License.
<mavenVersion>3.2.5</mavenVersion>
<slf4jVersion>1.7.5</slf4jVersion> <!-- Keep in sync with resolver used in maven above -->
<resolverVersion>1.0.0.v20140518</resolverVersion> <!-- Keep in sync with resolver used in maven above -->
- <javaVersion>7</javaVersion>
+ <javaVersion>8</javaVersion>
<project.build.outputTimestamp>2021-12-27T14:11:19Z</project.build.outputTimestamp>
</properties>
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
index 12267e7..e2babda 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -21,12 +21,12 @@ package org.apache.maven.plugins.deploy;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@@ -217,14 +217,9 @@ public class DeployFileMojo
if ( pomFile == null )
{
boolean foundPom = false;
-
- JarFile jarFile = null;
- try
+ try ( JarFile jarFile = new JarFile( file ) )
{
Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
-
- jarFile = new JarFile( file );
-
Enumeration<JarEntry> jarEntries = jarFile.entries();
while ( jarEntries.hasMoreElements() )
@@ -234,41 +229,24 @@ public class DeployFileMojo
if ( pomEntry.matcher( entry.getName() ).matches() )
{
getLog().debug( "Using " + entry.getName() + " as pomFile" );
-
foundPom = true;
-
- InputStream pomInputStream = null;
- OutputStream pomOutputStream = null;
-
- try
+ String base = file.getName();
+ if ( base.indexOf( '.' ) > 0 )
{
- pomInputStream = jarFile.getInputStream( entry );
+ base = base.substring( 0, base.lastIndexOf( '.' ) );
+ }
+ pomFile = new File( file.getParentFile(), base + ".pom" );
- String base = file.getName();
- if ( base.indexOf( '.' ) > 0 )
+ try ( InputStream pomInputStream = jarFile.getInputStream( entry ) )
+ {
+ try ( OutputStream pomOutputStream = Files.newOutputStream( pomFile.toPath() ) )
{
- base = base.substring( 0, base.lastIndexOf( '.' ) );
+ IOUtil.copy( pomInputStream, pomOutputStream );
}
- pomFile = new File( file.getParentFile(), base + ".pom" );
-
- pomOutputStream = new FileOutputStream( pomFile );
-
- IOUtil.copy( pomInputStream, pomOutputStream );
-
- pomOutputStream.close();
- pomOutputStream = null;
pomInputStream.close();
- pomInputStream = null;
-
processModel( readModel( pomFile ) );
-
break;
}
- finally
- {
- IOUtil.close( pomInputStream );
- IOUtil.close( pomOutputStream );
- }
}
}
@@ -281,20 +259,6 @@ public class DeployFileMojo
{
// ignore, artifact not packaged by Maven
}
- finally
- {
- if ( jarFile != null )
- {
- try
- {
- jarFile.close();
- }
- catch ( IOException e )
- {
- // we did our best
- }
- }
- }
}
else
{
@@ -343,7 +307,7 @@ public class DeployFileMojo
throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
}
- List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
+ List<Artifact> deployableArtifacts = new ArrayList<>();
if ( classifier == null )
{
@@ -471,14 +435,7 @@ public class DeployFileMojo
throw new MojoExecutionException( "You must specify 'files' if you specify 'classifiers'" );
}
}
-
- List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
-
- for ( Artifact attached : attachedArtifacts )
- {
- deployableArtifacts.add( attached );
- }
-
+ deployableArtifacts.addAll( project.getAttachedArtifacts() );
try
{
warnIfAffectedPackagingAndMaven( packaging );
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index 4aaa971..7b14ef7 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -62,7 +62,7 @@ public class DeployMojo
private static final AtomicInteger READYPROJECTSCOUNTER = new AtomicInteger();
private static final List<ProjectDeployerRequest> DEPLOYREQUESTS =
- Collections.synchronizedList( new ArrayList<ProjectDeployerRequest>() );
+ Collections.synchronizedList( new ArrayList<>() );
/**
*/
@@ -203,7 +203,7 @@ public class DeployMojo
}
private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
- throws MojoFailureException, MojoExecutionException
+ throws MojoExecutionException
{
try
{
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
index 371838b..624f25f 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
@@ -43,7 +44,7 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
public class DeployFileMojoTest
extends AbstractMojoTestCase
{
- private String LOCAL_REPO = getBasedir() + "/target/local-repo";
+ private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
private List<String> expectedFiles;
@@ -150,14 +151,14 @@ public class DeployFileMojoTest
assertEquals( "POM was created from deploy:deploy-file", model.getDescription() );
//check the remote-repo
- expectedFiles = new ArrayList<String>();
- fileList = new ArrayList<String>();
+ expectedFiles = new ArrayList<>();
+ fileList = new ArrayList<>();
File repo = new File( remoteRepo, "deploy-file-test" );
File[] files = repo.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
@@ -282,7 +283,7 @@ public class DeployFileMojoTest
File[] files = file.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
index 6131f79..8bc1b83 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
@@ -41,9 +41,7 @@ public class DeployFileMojoUnitTest
public static Test suite()
{
- TestSuite suite = new TestSuite( DeployFileMojoUnitTest.class );
-
- return suite;
+ return new TestSuite( DeployFileMojoUnitTest.class );
}
MockDeployFileMojo mojo;
@@ -67,7 +65,7 @@ public class DeployFileMojoUnitTest
mojo = null;
}
- class MockDeployFileMojo extends DeployFileMojo {
+ static class MockDeployFileMojo extends DeployFileMojo {
private Model model;
public MockDeployFileMojo(Model model) {
@@ -78,12 +76,13 @@ public class DeployFileMojoUnitTest
this.model = model;
}
- protected Model readModel(File pomFile) throws MojoExecutionException {
+ protected Model readModel(File pomFile)
+ {
return model;
}
}
- public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
+ public void testProcessPomFromPomFileWithParent1()
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -98,7 +97,7 @@ public class DeployFileMojoUnitTest
checkMojoProperties("parentGroup", null, "parentVersion", null);
}
- public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
+ public void testProcessPomFromPomFileWithParent2()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, null, "artifact", null, null, parent );
@@ -113,7 +112,7 @@ public class DeployFileMojoUnitTest
}
- public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
+ public void testProcessPomFromPomFileWithParent3()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, null, "artifact", "version", null, parent );
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 6404f5a..cc0af15 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -27,6 +27,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -60,13 +61,13 @@ public class DeployMojoTest
private File localRepo;
- private String LOCAL_REPO = getBasedir() + "/target/local-repo";
+ private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
- private String REMOTE_REPO = getBasedir() + "/target/remote-repo";
+ private final String REMOTE_REPO = getBasedir() + "/target/remote-repo";
DeployArtifactStub artifact;
- MavenProjectStub project = new MavenProjectStub();
+ final MavenProjectStub project = new MavenProjectStub();
@Mock
private MavenSession session;
@@ -169,8 +170,8 @@ public class DeployMojoTest
mojo.execute();
//check the artifact in local repository
- List<String> expectedFiles = new ArrayList<String>();
- List<String> fileList = new ArrayList<String>();
+ List<String> expectedFiles = new ArrayList<>();
+ List<String> fileList = new ArrayList<>();
expectedFiles.add( "org" );
expectedFiles.add( "apache" );
@@ -191,7 +192,7 @@ public class DeployMojoTest
File[] files = localRepo.listFiles();
- for (File file2 : files) {
+ for (File file2 : Objects.requireNonNull( files ) ) {
addFileToList(file2, fileList);
}
@@ -200,8 +201,8 @@ public class DeployMojoTest
assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
//check the artifact in remote repository
- expectedFiles = new ArrayList<String>();
- fileList = new ArrayList<String>();
+ expectedFiles = new ArrayList<>();
+ fileList = new ArrayList<>();
expectedFiles.add( "org" );
expectedFiles.add( "apache" );
@@ -227,7 +228,7 @@ public class DeployMojoTest
files = remoteRepo.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
@@ -330,8 +331,8 @@ public class DeployMojoTest
mojo.execute();
- List<String> expectedFiles = new ArrayList<String>();
- List<String> fileList = new ArrayList<String>();
+ List<String> expectedFiles = new ArrayList<>();
+ List<String> fileList = new ArrayList<>();
expectedFiles.add( "org" );
expectedFiles.add( "apache" );
@@ -353,7 +354,7 @@ public class DeployMojoTest
File[] files = remoteRepo.listFiles();
- for (File file : files) {
+ for (File file : Objects.requireNonNull( files ) ) {
addFileToList(file, fileList);
}
@@ -439,8 +440,8 @@ public class DeployMojoTest
mojo.execute();
//check the artifacts in remote repository
- List<String> expectedFiles = new ArrayList<String>();
- List<String> fileList = new ArrayList<String>();
+ List<String> expectedFiles = new ArrayList<>();
+ List<String> fileList = new ArrayList<>();
expectedFiles.add( "org" );
expectedFiles.add( "apache" );
@@ -478,7 +479,7 @@ public class DeployMojoTest
File[] files = remoteRepo.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
@@ -725,7 +726,7 @@ public class DeployMojoTest
File[] files = file.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/Utils.java b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
index f4acbc9..be96342 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/Utils.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
@@ -30,6 +30,7 @@ import org.eclipse.aether.util.ChecksumUtils;
/**
* A utility class to assist testing.
+ * used in IntegrationTests like attach-jar-checksum-snapshot, attach-jar-checksum-snapshot
*
* @author Benjamin Bentmann
*/
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
index d0b47d4..4e4c6c1 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
@@ -33,14 +33,12 @@ public class ArtifactDeployerStub
@Override
public void deploy( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts )
- throws ArtifactDeployerException
{
// does nothing
}
@Override
public void deploy( ProjectBuildingRequest arg0, ArtifactRepository arg1, Collection<Artifact> arg2)
- throws ArtifactDeployerException
{
// does nothing
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
index 92db6c1..238c5f7 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
@@ -36,7 +36,7 @@ public class ArtifactRepositoryStub
private String url;
- private String basedir = System.getProperty( "basedir" );
+ private final String basedir = System.getProperty( "basedir" );
public ArtifactRepositoryStub()
{
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
index 24f31d5..8993ed9 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
@@ -101,7 +101,7 @@ public class DeployArtifactStub
{
if ( metadataMap == null )
{
- metadataMap = new HashMap<Object, ArtifactMetadata>();
+ metadataMap = new HashMap<>();
}
ArtifactMetadata m = metadataMap.get( metadata.getKey() );
@@ -117,7 +117,7 @@ public class DeployArtifactStub
public Collection<ArtifactMetadata> getMetadataList()
{
- return metadataMap == null ? Collections.<ArtifactMetadata>emptyList() : metadataMap.values();
+ return metadataMap == null ? Collections.emptyList() : metadataMap.values();
}
public boolean isRelease()