Skip to content

Commit

Permalink
[MDEPLOY-292] Require Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz authored and slawekjaranowski committed Nov 15, 2022
1 parent 8bce035 commit 600bda7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 81 deletions.
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down Expand Up @@ -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>
Expand Down
59 changes: 11 additions & 48 deletions src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

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;
Expand Down Expand Up @@ -179,14 +179,9 @@ void initProperties()
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() )
Expand All @@ -196,41 +191,23 @@ void initProperties()
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 );
}
}
}

Expand All @@ -243,20 +220,6 @@ void initProperties()
{
// ignore, artifact not packaged by Maven
}
finally
{
if ( jarFile != null )
{
try
{
jarFile.close();
}
catch ( IOException e )
{
// we did our best
}
}
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -43,7 +44,7 @@
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;

Expand Down Expand Up @@ -151,14 +152,14 @@ public void testBasicDeployFile()
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);
}

Expand Down Expand Up @@ -285,7 +286,7 @@ private void addFileToList( File file, List<String> fileList )

File[] files = file.listFiles();

for (File file1 : files) {
for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ public void setModel(Model model) {
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" ) );

Expand All @@ -92,7 +93,7 @@ public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
}

@Test
public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
public void testProcessPomFromPomFileWithParent2()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, null, "artifact", null, null, parent );
Expand All @@ -108,7 +109,7 @@ public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
}

@Test
public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
public void testProcessPomFromPomFileWithParent3()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, null, "artifact", "version", null, parent );
Expand Down
33 changes: 17 additions & 16 deletions src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -180,8 +181,8 @@ public void testBasicDeploy()
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" );
Expand All @@ -202,7 +203,7 @@ public void testBasicDeploy()

File[] files = localRepo.listFiles();

for (File file2 : files) {
for (File file2 : Objects.requireNonNull( files ) ) {
addFileToList(file2, fileList);
}

Expand All @@ -211,8 +212,8 @@ public void testBasicDeploy()
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" );
Expand All @@ -238,7 +239,7 @@ public void testBasicDeploy()

files = remoteRepo.listFiles();

for (File file1 : files) {
for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}

Expand Down Expand Up @@ -349,8 +350,8 @@ public void testBasicDeployWithPackagingAsPom()

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" );
Expand All @@ -372,7 +373,7 @@ public void testBasicDeployWithPackagingAsPom()

File[] files = remoteRepo.listFiles();

for (File file : files) {
for (File file : Objects.requireNonNull( files ) ) {
addFileToList(file, fileList);
}

Expand Down Expand Up @@ -467,8 +468,8 @@ public void testDeployWithAttachedArtifacts()
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" );
Expand Down Expand Up @@ -506,7 +507,7 @@ public void testDeployWithAttachedArtifacts()

File[] files = remoteRepo.listFiles();

for (File file1 : files) {
for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}

Expand Down Expand Up @@ -720,7 +721,7 @@ private void addFileToList( File file, List<String> fileList )

File[] files = file.listFiles();

for (File file1 : files) {
for (File file1 : Objects.requireNonNull( files ) ) {
addFileToList(file1, fileList);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/apache/maven/plugins/deploy/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

/**
* A utility class to assist testing.
* used in IntegrationTests like attach-jar-checksum-snapshot, attach-jar-checksum-snapshot
*
* @author Benjamin Bentmann
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void addMetadata( ArtifactMetadata metadata )
{
if ( metadataMap == null )
{
metadataMap = new HashMap<Object, ArtifactMetadata>();
metadataMap = new HashMap<>();
}

ArtifactMetadata m = metadataMap.get( metadata.getKey() );
Expand All @@ -117,7 +117,7 @@ public void addMetadata( ArtifactMetadata metadata )

public Collection<ArtifactMetadata> getMetadataList()
{
return metadataMap == null ? Collections.<ArtifactMetadata>emptyList() : metadataMap.values();
return metadataMap == null ? Collections.emptyList() : metadataMap.values();
}

public boolean isRelease()
Expand Down

0 comments on commit 600bda7

Please sign in to comment.