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 committed May 6, 2022
1 parent 6eb066e commit fdafd16
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 93 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
69 changes: 13 additions & 56 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.ArrayList;
import java.util.Enumeration;
import java.util.List;
Expand Down Expand Up @@ -217,14 +217,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 @@ -234,41 +229,24 @@ 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 @@ -281,20 +259,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 Expand Up @@ -343,7 +307,7 @@ public void execute()
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 )
{
Expand Down Expand Up @@ -471,14 +435,7 @@ public void execute()
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 );
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>() );

/**
*/
Expand Down Expand Up @@ -203,7 +203,7 @@ else if ( addedDeployRequest )
}

private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
throws MojoFailureException, MojoExecutionException
throws MojoExecutionException
{
try
{
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 @@ -150,14 +151,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 @@ -282,7 +283,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 @@ -41,9 +41,7 @@ public static void main( String[] args )

public static Test suite()
{
TestSuite suite = new TestSuite( DeployFileMojoUnitTest.class );

return suite;
return new TestSuite( DeployFileMojoUnitTest.class );
}

MockDeployFileMojo mojo;
Expand All @@ -67,7 +65,7 @@ public void tearDown()
mojo = null;
}

class MockDeployFileMojo extends DeployFileMojo {
static class MockDeployFileMojo extends DeployFileMojo {
private Model model;

public MockDeployFileMojo(Model model) {
Expand All @@ -78,12 +76,13 @@ public void setModel(Model model) {
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" ) );

Expand All @@ -98,7 +97,7 @@ public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
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 );
Expand All @@ -113,7 +112,7 @@ public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException

}

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 @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -169,8 +170,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 @@ -191,7 +192,7 @@ public void testBasicDeploy()

File[] files = localRepo.listFiles();

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

Expand All @@ -200,8 +201,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 @@ -227,7 +228,7 @@ public void testBasicDeploy()

files = remoteRepo.listFiles();

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

Expand Down Expand Up @@ -330,8 +331,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 @@ -353,7 +354,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 @@ -439,8 +440,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 @@ -478,7 +479,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 @@ -725,7 +726,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 @@ -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
}
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

0 comments on commit fdafd16

Please sign in to comment.