26
26
import java .io .Writer ;
27
27
import java .nio .file .Files ;
28
28
import java .nio .file .Path ;
29
+ import java .nio .file .Paths ;
29
30
import java .nio .file .StandardCopyOption ;
30
31
import java .util .ArrayList ;
31
32
import java .util .List ;
@@ -97,23 +98,23 @@ public class DeployFileMojo
97
98
* File to be deployed.
98
99
*/
99
100
@ Parameter ( property = "file" , required = true )
100
- File file ;
101
+ Path file ;
101
102
102
103
/**
103
104
* The bundled API docs for the artifact.
104
105
*
105
106
* @since 2.6
106
107
*/
107
108
@ Parameter ( property = "javadoc" )
108
- File javadoc ;
109
+ Path javadoc ;
109
110
110
111
/**
111
112
* The bundled sources for the artifact.
112
113
*
113
114
* @since 2.6
114
115
*/
115
116
@ Parameter ( property = "sources" )
116
- File sources ;
117
+ Path sources ;
117
118
118
119
/**
119
120
* Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter
@@ -133,7 +134,7 @@ public class DeployFileMojo
133
134
* Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.
134
135
*/
135
136
@ Parameter ( property = "pomFile" )
136
- File pomFile ;
137
+ Path pomFile ;
137
138
138
139
/**
139
140
* Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.
@@ -174,15 +175,15 @@ void initProperties()
174
175
Path deployedPom ;
175
176
if ( pomFile != null )
176
177
{
177
- deployedPom = pomFile . toPath () ;
178
+ deployedPom = pomFile ;
178
179
processModel ( readModel ( deployedPom ) );
179
180
}
180
181
else
181
182
{
182
183
deployedPom = readingPomFromJarFile ();
183
184
if ( deployedPom != null )
184
185
{
185
- pomFile = deployedPom . toFile () ;
186
+ pomFile = deployedPom ;
186
187
}
187
188
}
188
189
@@ -197,7 +198,7 @@ private Path readingPomFromJarFile()
197
198
Pattern pomEntry = Pattern .compile ( "META-INF/maven/.*/pom\\ .xml" );
198
199
try
199
200
{
200
- try ( JarFile jarFile = new JarFile ( file ) )
201
+ try ( JarFile jarFile = new JarFile ( file . toFile () ) )
201
202
{
202
203
JarEntry entry = jarFile .stream ()
203
204
.filter ( e -> pomEntry .matcher ( e .getName () ).matches () )
@@ -209,7 +210,7 @@ private Path readingPomFromJarFile()
209
210
210
211
try ( InputStream pomInputStream = jarFile .getInputStream ( entry ) )
211
212
{
212
- String base = file .getName ();
213
+ String base = file .getFileName (). toString ();
213
214
if ( base .indexOf ( '.' ) > 0 )
214
215
{
215
216
base = base .substring ( 0 , base .lastIndexOf ( '.' ) );
@@ -225,7 +226,7 @@ private Path readingPomFromJarFile()
225
226
}
226
227
else
227
228
{
228
- logger .info ( "pom.xml not found in " + file .getName () );
229
+ logger .info ( "pom.xml not found in " + file .getFileName () );
229
230
}
230
231
}
231
232
}
@@ -240,9 +241,9 @@ private Path readingPomFromJarFile()
240
241
public void execute ()
241
242
throws MojoException
242
243
{
243
- if ( !file .exists () )
244
+ if ( !Files .exists ( file ) )
244
245
{
245
- String message = "The specified file '" + file . getPath () + "' does not exist" ;
246
+ String message = "The specified file '" + file + "' does not exist" ;
246
247
logger .error ( message );
247
248
throw new MojoException ( message );
248
249
}
@@ -259,7 +260,7 @@ public void execute()
259
260
Path deployedPom ;
260
261
if ( pomFile != null )
261
262
{
262
- deployedPom = pomFile . toPath () ;
263
+ deployedPom = pomFile ;
263
264
processModel ( readModel ( deployedPom ) );
264
265
}
265
266
else
@@ -287,13 +288,13 @@ public void execute()
287
288
Artifact artifact = session .createArtifact ( groupId , artifactId , version , classifier ,
288
289
isFilePom ? "pom" : getExtension ( file ), packaging );
289
290
290
- if ( file .equals ( getLocalRepositoryFile ( artifact ). toFile () ) )
291
+ if ( file .equals ( getLocalRepositoryFile ( artifact ) ) )
291
292
{
292
293
throw new MojoException ( "Cannot deploy artifact from the local repository: " + file );
293
294
}
294
295
295
296
ArtifactManager artifactManager = session .getService ( ArtifactManager .class );
296
- artifactManager .setPath ( artifact , file . toPath () );
297
+ artifactManager .setPath ( artifact , file );
297
298
deployables .add ( artifact );
298
299
299
300
@@ -324,14 +325,14 @@ public void execute()
324
325
if ( sources != null )
325
326
{
326
327
Artifact sourcesArtifact = session .createArtifact ( groupId , artifactId , version , "sources" , "jar" , null );
327
- artifactManager .setPath ( sourcesArtifact , sources . toPath () );
328
+ artifactManager .setPath ( sourcesArtifact , sources );
328
329
deployables .add ( sourcesArtifact );
329
330
}
330
331
331
332
if ( javadoc != null )
332
333
{
333
334
Artifact javadocArtifact = session .createArtifact ( groupId , artifactId , version , "javadoc" , "jar" , null );
334
- artifactManager .setPath ( javadocArtifact , javadoc . toPath () );
335
+ artifactManager .setPath ( javadocArtifact , javadoc );
335
336
deployables .add ( javadocArtifact );
336
337
}
337
338
@@ -378,21 +379,21 @@ public void execute()
378
379
{
379
380
nci = classifiers .length ();
380
381
}
381
- File file = new File ( files .substring ( fi , nfi ) );
382
- if ( !file . isFile ( ) )
382
+ Path file = Paths . get ( files .substring ( fi , nfi ) );
383
+ if ( !Files . isRegularFile ( file ) )
383
384
{
384
385
// try relative to the project basedir just in case
385
- file = new File ( files .substring ( fi , nfi ) );
386
+ file = Paths . get ( files .substring ( fi , nfi ) );
386
387
}
387
- if ( file . isFile ( ) )
388
+ if ( Files . isRegularFile ( file ) )
388
389
{
389
390
String extension = getExtension ( file );
390
391
String type = types .substring ( ti , nti ).trim ();
391
392
392
393
Artifact deployable = session .createArtifact (
393
394
artifact .getGroupId (), artifact .getArtifactId (), artifact .getVersion (),
394
395
classifiers .substring ( ci , nci ).trim (), extension , type );
395
- artifactManager .setPath ( deployable , file . toPath () );
396
+ artifactManager .setPath ( deployable , file );
396
397
deployables .add ( deployable );
397
398
}
398
399
else
@@ -583,7 +584,7 @@ void setPackaging( String packaging )
583
584
this .packaging = packaging ;
584
585
}
585
586
586
- void setPomFile ( File pomFile )
587
+ void setPomFile ( Path pomFile )
587
588
{
588
589
this .pomFile = pomFile ;
589
590
}
@@ -608,7 +609,7 @@ String getPackaging()
608
609
return packaging ;
609
610
}
610
611
611
- File getFile ()
612
+ Path getFile ()
612
613
{
613
614
return file ;
614
615
}
@@ -640,9 +641,9 @@ private static int countCommas( String str )
640
641
/**
641
642
* Get file extension, honoring various {@code tar.xxx} combinations.
642
643
*/
643
- private String getExtension ( final File file )
644
+ private String getExtension ( final Path file )
644
645
{
645
- String filename = file .getName ();
646
+ String filename = file .getFileName (). toString ();
646
647
int lastDot = filename .lastIndexOf ( '.' );
647
648
if ( lastDot > 0 && lastDot < filename .length () - 1 )
648
649
{
0 commit comments