Skip to content

Commit 600bda7

Browse files
slachiewiczslawekjaranowski
authored andcommitted
[MDEPLOY-292] Require Java 8
1 parent 8bce035 commit 600bda7

File tree

8 files changed

+44
-81
lines changed

8 files changed

+44
-81
lines changed

pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ under the License.
6363
</distributionManagement>
6464

6565
<properties>
66-
<javaVersion>7</javaVersion>
66+
<javaVersion>8</javaVersion>
6767
<mavenVersion>3.2.5</mavenVersion>
6868
<slf4jVersion>1.7.5</slf4jVersion> <!-- Keep in sync with resolver used in maven above -->
6969
<resolverVersion>1.0.0.v20140518</resolverVersion> <!-- Keep in sync with resolver used in maven above -->
@@ -232,10 +232,6 @@ under the License.
232232
<goals>
233233
<goal>deploy</goal>
234234
</goals>
235-
<properties>
236-
<!-- e.g. ensure that Java7 picks up TLSv1.2 when connecting with Central -->
237-
<https.protocols>${https.protocols}</https.protocols>
238-
</properties>
239235
</configuration>
240236
</plugin>
241237
</plugins>

src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
import java.io.File;
2323
import java.io.FileNotFoundException;
24-
import java.io.FileOutputStream;
2524
import java.io.IOException;
2625
import java.io.InputStream;
2726
import java.io.OutputStream;
2827
import java.io.Reader;
2928
import java.io.Writer;
29+
import java.nio.file.Files;
3030
import java.util.Enumeration;
3131
import java.util.Objects;
3232
import java.util.jar.JarEntry;
@@ -179,14 +179,9 @@ void initProperties()
179179
if ( pomFile == null )
180180
{
181181
boolean foundPom = false;
182-
183-
JarFile jarFile = null;
184-
try
182+
try ( JarFile jarFile = new JarFile( file ) )
185183
{
186184
Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
187-
188-
jarFile = new JarFile( file );
189-
190185
Enumeration<JarEntry> jarEntries = jarFile.entries();
191186

192187
while ( jarEntries.hasMoreElements() )
@@ -196,41 +191,23 @@ void initProperties()
196191
if ( pomEntry.matcher( entry.getName() ).matches() )
197192
{
198193
getLog().debug( "Using " + entry.getName() + " as pomFile" );
199-
200194
foundPom = true;
201-
202-
InputStream pomInputStream = null;
203-
OutputStream pomOutputStream = null;
204-
205-
try
195+
String base = file.getName();
196+
if ( base.indexOf( '.' ) > 0 )
206197
{
207-
pomInputStream = jarFile.getInputStream( entry );
198+
base = base.substring( 0, base.lastIndexOf( '.' ) );
199+
}
200+
pomFile = new File( file.getParentFile(), base + ".pom" );
208201

209-
String base = file.getName();
210-
if ( base.indexOf( '.' ) > 0 )
202+
try ( InputStream pomInputStream = jarFile.getInputStream( entry ) )
203+
{
204+
try ( OutputStream pomOutputStream = Files.newOutputStream( pomFile.toPath() ) )
211205
{
212-
base = base.substring( 0, base.lastIndexOf( '.' ) );
206+
IOUtil.copy( pomInputStream, pomOutputStream );
213207
}
214-
pomFile = new File( file.getParentFile(), base + ".pom" );
215-
216-
pomOutputStream = new FileOutputStream( pomFile );
217-
218-
IOUtil.copy( pomInputStream, pomOutputStream );
219-
220-
pomOutputStream.close();
221-
pomOutputStream = null;
222-
pomInputStream.close();
223-
pomInputStream = null;
224-
225208
processModel( readModel( pomFile ) );
226-
227209
break;
228210
}
229-
finally
230-
{
231-
IOUtil.close( pomInputStream );
232-
IOUtil.close( pomOutputStream );
233-
}
234211
}
235212
}
236213

@@ -243,20 +220,6 @@ void initProperties()
243220
{
244221
// ignore, artifact not packaged by Maven
245222
}
246-
finally
247-
{
248-
if ( jarFile != null )
249-
{
250-
try
251-
{
252-
jarFile.close();
253-
}
254-
catch ( IOException e )
255-
{
256-
// we did our best
257-
}
258-
}
259-
}
260223
}
261224
else
262225
{

src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.File;
2626
import java.util.ArrayList;
2727
import java.util.List;
28+
import java.util.Objects;
2829

2930
import org.apache.maven.execution.MavenSession;
3031
import org.apache.maven.model.Model;
@@ -43,7 +44,7 @@
4344
public class DeployFileMojoTest
4445
extends AbstractMojoTestCase
4546
{
46-
private String LOCAL_REPO = getBasedir() + "/target/local-repo";
47+
private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
4748

4849
private List<String> expectedFiles;
4950

@@ -151,14 +152,14 @@ public void testBasicDeployFile()
151152
assertEquals( "POM was created from deploy:deploy-file", model.getDescription() );
152153

153154
//check the remote-repo
154-
expectedFiles = new ArrayList<String>();
155-
fileList = new ArrayList<String>();
155+
expectedFiles = new ArrayList<>();
156+
fileList = new ArrayList<>();
156157

157158
File repo = new File( remoteRepo, "deploy-file-test" );
158159

159160
File[] files = repo.listFiles();
160161

161-
for (File file1 : files) {
162+
for (File file1 : Objects.requireNonNull( files ) ) {
162163
addFileToList(file1, fileList);
163164
}
164165

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

286287
File[] files = file.listFiles();
287288

288-
for (File file1 : files) {
289+
for (File file1 : Objects.requireNonNull( files ) ) {
289290
addFileToList(file1, fileList);
290291
}
291292
}

src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ public void setModel(Model model) {
7070
this.model = model;
7171
}
7272

73-
protected Model readModel(File pomFile) throws MojoExecutionException {
73+
protected Model readModel(File pomFile)
74+
{
7475
return model;
7576
}
7677
}
7778

7879
@Test
79-
public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
80+
public void testProcessPomFromPomFileWithParent1()
8081
{
8182
mojo.setPomFile( new File( "foo.bar" ) );
8283

@@ -92,7 +93,7 @@ public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
9293
}
9394

9495
@Test
95-
public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
96+
public void testProcessPomFromPomFileWithParent2()
9697
{
9798
mojo.setPomFile( new File( "foo.bar" ) );
9899
setMojoModel( mojo.model, null, "artifact", null, null, parent );
@@ -108,7 +109,7 @@ public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
108109
}
109110

110111
@Test
111-
public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
112+
public void testProcessPomFromPomFileWithParent3()
112113
{
113114
mojo.setPomFile( new File( "foo.bar" ) );
114115
setMojoModel( mojo.model, null, "artifact", "version", null, parent );

src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.ArrayList;
3030
import java.util.Collections;
3131
import java.util.List;
32+
import java.util.Objects;
3233
import java.util.Properties;
3334
import java.util.concurrent.ConcurrentHashMap;
3435

@@ -62,13 +63,13 @@ public class DeployMojoTest
6263

6364
private File localRepo;
6465

65-
private String LOCAL_REPO = getBasedir() + "/target/local-repo";
66+
private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
6667

67-
private String REMOTE_REPO = getBasedir() + "/target/remote-repo";
68+
private final String REMOTE_REPO = getBasedir() + "/target/remote-repo";
6869

6970
DeployArtifactStub artifact;
7071

71-
MavenProjectStub project = new MavenProjectStub();
72+
final MavenProjectStub project = new MavenProjectStub();
7273

7374
private MavenSession session;
7475

@@ -180,8 +181,8 @@ public void testBasicDeploy()
180181
mojo.execute();
181182

182183
//check the artifact in local repository
183-
List<String> expectedFiles = new ArrayList<String>();
184-
List<String> fileList = new ArrayList<String>();
184+
List<String> expectedFiles = new ArrayList<>();
185+
List<String> fileList = new ArrayList<>();
185186

186187
expectedFiles.add( "org" );
187188
expectedFiles.add( "apache" );
@@ -202,7 +203,7 @@ public void testBasicDeploy()
202203

203204
File[] files = localRepo.listFiles();
204205

205-
for (File file2 : files) {
206+
for (File file2 : Objects.requireNonNull( files ) ) {
206207
addFileToList(file2, fileList);
207208
}
208209

@@ -211,8 +212,8 @@ public void testBasicDeploy()
211212
assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
212213

213214
//check the artifact in remote repository
214-
expectedFiles = new ArrayList<String>();
215-
fileList = new ArrayList<String>();
215+
expectedFiles = new ArrayList<>();
216+
fileList = new ArrayList<>();
216217

217218
expectedFiles.add( "org" );
218219
expectedFiles.add( "apache" );
@@ -238,7 +239,7 @@ public void testBasicDeploy()
238239

239240
files = remoteRepo.listFiles();
240241

241-
for (File file1 : files) {
242+
for (File file1 : Objects.requireNonNull( files ) ) {
242243
addFileToList(file1, fileList);
243244
}
244245

@@ -349,8 +350,8 @@ public void testBasicDeployWithPackagingAsPom()
349350

350351
mojo.execute();
351352

352-
List<String> expectedFiles = new ArrayList<String>();
353-
List<String> fileList = new ArrayList<String>();
353+
List<String> expectedFiles = new ArrayList<>();
354+
List<String> fileList = new ArrayList<>();
354355

355356
expectedFiles.add( "org" );
356357
expectedFiles.add( "apache" );
@@ -372,7 +373,7 @@ public void testBasicDeployWithPackagingAsPom()
372373

373374
File[] files = remoteRepo.listFiles();
374375

375-
for (File file : files) {
376+
for (File file : Objects.requireNonNull( files ) ) {
376377
addFileToList(file, fileList);
377378
}
378379

@@ -467,8 +468,8 @@ public void testDeployWithAttachedArtifacts()
467468
mojo.execute();
468469

469470
//check the artifacts in remote repository
470-
List<String> expectedFiles = new ArrayList<String>();
471-
List<String> fileList = new ArrayList<String>();
471+
List<String> expectedFiles = new ArrayList<>();
472+
List<String> fileList = new ArrayList<>();
472473

473474
expectedFiles.add( "org" );
474475
expectedFiles.add( "apache" );
@@ -506,7 +507,7 @@ public void testDeployWithAttachedArtifacts()
506507

507508
File[] files = remoteRepo.listFiles();
508509

509-
for (File file1 : files) {
510+
for (File file1 : Objects.requireNonNull( files ) ) {
510511
addFileToList(file1, fileList);
511512
}
512513

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

721722
File[] files = file.listFiles();
722723

723-
for (File file1 : files) {
724+
for (File file1 : Objects.requireNonNull( files ) ) {
724725
addFileToList(file1, fileList);
725726
}
726727
}

src/test/java/org/apache/maven/plugins/deploy/Utils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
/**
3232
* A utility class to assist testing.
33+
* used in IntegrationTests like attach-jar-checksum-snapshot, attach-jar-checksum-snapshot
3334
*
3435
* @author Benjamin Bentmann
3536
*/

src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ArtifactRepositoryStub
3636

3737
private String url;
3838

39-
private String basedir = System.getProperty( "basedir" );
39+
private final String basedir = System.getProperty( "basedir" );
4040

4141
public ArtifactRepositoryStub()
4242
{

src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void addMetadata( ArtifactMetadata metadata )
101101
{
102102
if ( metadataMap == null )
103103
{
104-
metadataMap = new HashMap<Object, ArtifactMetadata>();
104+
metadataMap = new HashMap<>();
105105
}
106106

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

118118
public Collection<ArtifactMetadata> getMetadataList()
119119
{
120-
return metadataMap == null ? Collections.<ArtifactMetadata>emptyList() : metadataMap.values();
120+
return metadataMap == null ? Collections.emptyList() : metadataMap.values();
121121
}
122122

123123
public boolean isRelease()

0 commit comments

Comments
 (0)