You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "michael-o (via GitHub)" <gi...@apache.org> on 2023/03/04 20:05:50 UTC

[GitHub] [maven-shade-plugin] michael-o commented on a diff in pull request #110: [MSHADE-400] Self-minimisation with custom entry points

michael-o commented on code in PR #110:
URL: https://github.com/apache/maven-shade-plugin/pull/110#discussion_r1125530205


##########
src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java:
##########
@@ -964,11 +992,16 @@ private List<Filter> getFilters()
 
         if ( minimizeJar )
         {
-            getLog().info( "Minimizing jar " + project.getArtifact() );
+            if ( entryPoints == null )
+            {
+                entryPoints = new HashSet<>();
+            }
+            getLog().info( "Minimizing jar " + project.getArtifact()
+                    + ( entryPoints.isEmpty() ? "" : ", entry points = " + entryPoints ) );

Review Comment:
   I think this is redudant since other parameters aren't logged at info as well and those who want to see all params this is possible in verbose mode.



##########
src/main/java/org/apache/maven/plugins/shade/filter/MinijarFilter.java:
##########
@@ -156,6 +204,43 @@ private void removeServices( final MavenProject project, final Clazzpath cp )
         while ( repeatScan );
     }
 
+    private boolean removeServicesFromDir( Clazzpath cp, Set<Clazz> neededClasses, String fileName )
+    {
+        final File servicesDir = new File( fileName, "META-INF/services/" );
+        if ( !servicesDir.isDirectory() )
+        {
+            return false;
+        }
+        final File[] serviceProviderConfigFiles = servicesDir.listFiles();
+        if ( serviceProviderConfigFiles == null || serviceProviderConfigFiles.length == 0 )
+        {
+            return false;
+        }
+
+        boolean repeatScan = false;
+        for ( File serviceProviderConfigFile : serviceProviderConfigFiles )
+        {
+            final String serviceClassName = serviceProviderConfigFile.getName();
+            final boolean isNeededClass = neededClasses.contains( cp.getClazz( serviceClassName ) );
+            if ( !isNeededClass )
+            {
+                continue;
+            }
+
+            try ( final BufferedReader configFileReader = new BufferedReader(
+                    new InputStreamReader( new FileInputStream( serviceProviderConfigFile ), UTF_8 ) ) )
+            {
+                // check whether the found classes use services in turn
+                repeatScan |= scanServiceProviderConfigFile( cp, configFileReader );
+            }
+            catch ( final IOException e )
+            {
+                log.warn( e.getMessage() );

Review Comment:
   I think this needs a decent message and in warn just the log the message and when in verbose mode also add the exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org