You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2020/09/26 20:09:26 UTC
[maven-ear-plugin] branch master updated: [MEAR-278] extract
outdated resources code to dedicated methods
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 001b51b [MEAR-278] extract outdated resources code to dedicated methods
001b51b is described below
commit 001b51b2987b1905be821b009013117a5e24b68e
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Sep 26 22:09:18 2020 +0200
[MEAR-278] extract outdated resources code to dedicated methods
---
.../java/org/apache/maven/plugins/ear/EarMojo.java | 96 ++++++++++++----------
1 file changed, 54 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
index 3fe8118..3bc47ae 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
@@ -280,7 +280,7 @@ public class EarMojo
private MavenSession session;
private List<FileUtils.FilterWrapper> filterWrappers;
-
+
/**
* @since 2.9
*/
@@ -326,29 +326,8 @@ public class EarMojo
zipUnArchiver.setUseJvmChmod( useJvmChmod );
final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion( version );
-
- final Collection<String> outdatedResources = new ArrayList<>();
-
- if ( getWorkDirectory().exists() )
- {
- try
- {
- Files.walkFileTree( getWorkDirectory().toPath(), new SimpleFileVisitor<Path>()
- {
- @Override
- public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
- throws IOException
- {
- outdatedResources.add( getWorkDirectory().toPath().relativize( file ).toString() );
- return super.visitFile( file, attrs );
- }
- } );
- }
- catch ( IOException e )
- {
- getLog().warn( "Can't detect outdated resources", e );
- }
- }
+
+ final Collection<String> outdatedResources = initOutdatedResources();
// Initializes unpack types
List<String> unpackTypesList = createUnpackList();
@@ -360,7 +339,7 @@ public class EarMojo
try
{
File earSourceDir = earSourceDirectory;
-
+
if ( earSourceDir.exists() )
{
getLog().info( "Copy ear sources to " + getWorkDirectory().getAbsolutePath() );
@@ -402,31 +381,22 @@ public class EarMojo
{
outdatedResources.remove( Paths.get( "META-INF/jboss-app.xml" ).toString() );
}
-
- final long startTime = session.getStartTime().getTime();
-
- for ( String outdatedResource : outdatedResources )
- {
- if ( new File( getWorkDirectory(), outdatedResource ).lastModified() < startTime )
- {
- getLog().info( "deleting outdated resource " + outdatedResource );
- new File( getWorkDirectory(), outdatedResource ).delete();
- }
- }
- getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + " from the generated EAR." );
- getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated EAR." );
+ deleteOutdatedResources( outdatedResources );
- archiver.getArchiver().addDirectory( getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes() );
try
{
+ getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + " from the generated EAR." );
+ getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated EAR." );
+
+ archiver.getArchiver().addDirectory( getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes() );
+
archiver.createArchive( session, getProject(), archive );
}
catch ( ManifestException | IOException | DependencyResolutionRequiredException e )
{
throw new MojoExecutionException( "Error assembling EAR", e );
}
-
if ( classifier != null )
{
@@ -444,7 +414,7 @@ public class EarMojo
throws MojoExecutionException, MojoFailureException
{
final Path workingDir = getWorkDirectory().toPath();
-
+
try
{
for ( EarModule module : getModules() )
@@ -685,6 +655,7 @@ public class EarMojo
*
* @param source file to be unpacked
* @param destDir where to put the unpacked files
+ * @param outdatedResources currently outdated resources
* @throws ArchiverException a corrupt archive
* @throws NoSuchArchiverException if we don't have an appropriate archiver
* @throws IOException in case of a general IOException
@@ -781,7 +752,7 @@ public class EarMojo
if ( workDirectory.mkdirs() )
{
getLog().debug( "Created a temporary work directory: " + workDirectory.getAbsolutePath() );
-
+
// Unpack the archive to a temporary work directory
zipUnArchiver.setSourceFile( original );
zipUnArchiver.setDestDirectory( workDirectory );
@@ -934,4 +905,45 @@ public class EarMojo
return manifest;
}
}
+
+ private Collection<String> initOutdatedResources()
+ {
+ final Collection<String> outdatedResources = new ArrayList<>();
+
+ if ( getWorkDirectory().exists() )
+ {
+ try
+ {
+ Files.walkFileTree( getWorkDirectory().toPath(), new SimpleFileVisitor<Path>()
+ {
+ @Override
+ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
+ throws IOException
+ {
+ outdatedResources.add( getWorkDirectory().toPath().relativize( file ).toString() );
+ return super.visitFile( file, attrs );
+ }
+ } );
+ }
+ catch ( IOException e )
+ {
+ getLog().warn( "Can't detect outdated resources", e );
+ }
+ }
+ return outdatedResources;
+ }
+
+ private void deleteOutdatedResources( final Collection<String> outdatedResources )
+ {
+ final long startTime = session.getStartTime().getTime();
+
+ for ( String outdatedResource : outdatedResources )
+ {
+ if ( new File( getWorkDirectory(), outdatedResource ).lastModified() < startTime )
+ {
+ getLog().info( "deleting outdated resource " + outdatedResource );
+ new File( getWorkDirectory(), outdatedResource ).delete();
+ }
+ }
+ }
}