You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/11/15 18:12:24 UTC
[maven-deploy-plugin] branch master updated: [MDEPLOY-292] Require Java 8
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 600bda7 [MDEPLOY-292] Require Java 8
600bda7 is described below
commit 600bda797b81c8bdbaa80cbb6e8bc633d0c1cbcb
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri May 6 11:24:04 2022 +0200
[MDEPLOY-292] Require Java 8
---
pom.xml | 6 +--
.../maven/plugins/deploy/DeployFileMojo.java | 59 ++++------------------
.../maven/plugins/deploy/DeployFileMojoTest.java | 11 ++--
.../plugins/deploy/DeployFileMojoUnitTest.java | 9 ++--
.../maven/plugins/deploy/DeployMojoTest.java | 33 ++++++------
.../org/apache/maven/plugins/deploy/Utils.java | 1 +
.../deploy/stubs/ArtifactRepositoryStub.java | 2 +-
.../plugins/deploy/stubs/DeployArtifactStub.java | 4 +-
8 files changed, 44 insertions(+), 81 deletions(-)
diff --git a/pom.xml b/pom.xml
index c6b619e..d0a221d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@ under the License.
</distributionManagement>
<properties>
- <javaVersion>7</javaVersion>
+ <javaVersion>8</javaVersion>
<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 -->
@@ -232,10 +232,6 @@ under the License.
<goals>
<goal>deploy</goal>
</goals>
- <properties>
- <!-- e.g. ensure that Java7 picks up TLSv1.2 when connecting with Central -->
- <https.protocols>${https.protocols}</https.protocols>
- </properties>
</configuration>
</plugin>
</plugins>
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 5d95043..11bb285 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.Enumeration;
import java.util.Objects;
import java.util.jar.JarEntry;
@@ -179,14 +179,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() )
@@ -196,41 +191,23 @@ 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 );
- }
}
}
@@ -243,20 +220,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
{
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 d853870..0700dfb 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;
@@ -151,14 +152,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);
}
@@ -285,7 +286,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 a7bbd8b..0edf72f 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
@@ -70,13 +70,14 @@ public class DeployFileMojoUnitTest
this.model = model;
}
- protected Model readModel(File pomFile) throws MojoExecutionException {
+ protected Model readModel(File pomFile)
+ {
return model;
}
}
@Test
- public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
+ public void testProcessPomFromPomFileWithParent1()
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -92,7 +93,7 @@ public class DeployFileMojoUnitTest
}
@Test
- public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
+ public void testProcessPomFromPomFileWithParent2()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, null, "artifact", null, null, parent );
@@ -108,7 +109,7 @@ public class DeployFileMojoUnitTest
}
@Test
- 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 f34abd0..54bc16f 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -29,6 +29,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 java.util.concurrent.ConcurrentHashMap;
@@ -62,13 +63,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();
private MavenSession session;
@@ -180,8 +181,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" );
@@ -202,7 +203,7 @@ public class DeployMojoTest
File[] files = localRepo.listFiles();
- for (File file2 : files) {
+ for (File file2 : Objects.requireNonNull( files ) ) {
addFileToList(file2, fileList);
}
@@ -211,8 +212,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" );
@@ -238,7 +239,7 @@ public class DeployMojoTest
files = remoteRepo.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
@@ -349,8 +350,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" );
@@ -372,7 +373,7 @@ public class DeployMojoTest
File[] files = remoteRepo.listFiles();
- for (File file : files) {
+ for (File file : Objects.requireNonNull( files ) ) {
addFileToList(file, fileList);
}
@@ -467,8 +468,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" );
@@ -506,7 +507,7 @@ public class DeployMojoTest
File[] files = remoteRepo.listFiles();
- for (File file1 : files) {
+ for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
@@ -720,7 +721,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/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()