You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2022/09/13 20:53:39 UTC
[maven-shade-plugin] branch JDK8_IMPROVEMENTS updated: WIP: Improved.
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch JDK8_IMPROVEMENTS
in repository https://gitbox.apache.org/repos/asf/maven-shade-plugin.git
The following commit(s) were added to refs/heads/JDK8_IMPROVEMENTS by this push:
new 0ed807f WIP: Improved.
0ed807f is described below
commit 0ed807f6e81f4dc331c926e0cb03b293648d15ab
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Tue Sep 13 22:53:34 2022 +0200
WIP: Improved.
---
.../plugins/shade/relocation/SimpleRelocator.java | 2 +-
.../shade/resource/GroovyResourceTransformer.java | 35 +++++-----------------
.../shade/resource/IncludeResourceTransformer.java | 10 +++----
3 files changed, 13 insertions(+), 34 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java b/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java
index 5d50d11..5087b5f 100644
--- a/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java
+++ b/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java
@@ -182,7 +182,7 @@ public class SimpleRelocator
private boolean isExcluded( String path )
{
- return excludes.stream().anyMatch( s -> SelectorUtils.matchPath( s, path, true ));
+ return excludes.stream().anyMatch( s -> SelectorUtils.matchPath( s, path, true ) );
}
public boolean canRelocatePath( String path )
diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java
index 1a8d61d..219ceaa 100644
--- a/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java
+++ b/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java
@@ -19,19 +19,17 @@ package org.apache.maven.plugins.shade.resource;
* under the License.
*/
-import org.apache.maven.plugins.shade.relocation.Relocator;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
+import org.apache.maven.plugins.shade.relocation.Relocator;
+
/**
* Aggregate Apache Groovy extension modules descriptors
*/
@@ -96,7 +94,7 @@ public class GroovyResourceTransformer
@Override
public boolean hasTransformedResource()
{
- return extensionClassesList.size() > 0 && staticExtensionClassesList.size() > 0;
+ return !( extensionClassesList.isEmpty() || staticExtensionClassesList.isEmpty() );
}
@Override
@@ -112,37 +110,18 @@ public class GroovyResourceTransformer
Properties desc = new Properties();
desc.put( "moduleName", extModuleName );
desc.put( "moduleVersion", extModuleVersion );
- if ( extensionClassesList.size() > 0 )
+ if ( !extensionClassesList.isEmpty() )
{
- desc.put( "extensionClasses", join( extensionClassesList ) );
+ desc.put( "extensionClasses", String.join( ",", extensionClassesList ) );
}
- if ( staticExtensionClassesList.size() > 0 )
+ if ( !staticExtensionClassesList.isEmpty() )
{
- desc.put( "staticExtensionClasses", join( staticExtensionClassesList ) );
+ desc.put( "staticExtensionClasses", String.join( ",", staticExtensionClassesList ) );
}
desc.store( os, null );
}
}
- private String join( Collection<String> strings )
- {
- Iterator<String> it = strings.iterator();
- switch ( strings.size() )
- {
- case 0:
- return "";
- case 1:
- return it.next();
- default:
- StringBuilder buff = new StringBuilder( it.next() );
- while ( it.hasNext() )
- {
- buff.append( "," ).append( it.next() );
- }
- return buff.toString();
- }
- }
-
public void setExtModuleName( String extModuleName )
{
this.extModuleName = extModuleName;
diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/IncludeResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/IncludeResourceTransformer.java
index dfe3326..40aae20 100644
--- a/src/main/java/org/apache/maven/plugins/shade/resource/IncludeResourceTransformer.java
+++ b/src/main/java/org/apache/maven/plugins/shade/resource/IncludeResourceTransformer.java
@@ -19,17 +19,17 @@ package org.apache.maven.plugins.shade.resource;
* under the License.
*/
-import org.apache.maven.plugins.shade.relocation.Relocator;
-import org.codehaus.plexus.util.IOUtil;
-
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
+import org.apache.maven.plugins.shade.relocation.Relocator;
+import org.codehaus.plexus.util.IOUtil;
+
/**
* A resource processor that allows the addition of an arbitrary file
* content into the shaded JAR.
@@ -68,7 +68,7 @@ public class IncludeResourceTransformer
JarEntry jarEntry = new JarEntry( resource );
jarEntry.setTime( time );
- try ( InputStream in = new FileInputStream( file ) )
+ try ( InputStream in = Files.newInputStream( file.toPath() ) )
{
jos.putNextEntry( jarEntry );
IOUtil.copy( in, jos );