bmarwell commented on a change in pull request #16:
URL: https://github.com/apache/maven-jlink-plugin/pull/16#discussion_r526677178



##########
File path: src/main/java9/org/apache/maven/plugins/jlink/JLinkExecutor.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.plugins.jlink;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.toolchain.Toolchain;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Optional;
+import java.util.spi.ToolProvider;
+
+/**
+ * JDK9+ executor for jlink.
+ *
+ * <p>This implementation uses the JDK9+ Toolprovider SPI to find and execute 
jlink.
+ * This way, no fork needs to be created.</p>
+ */
+class JLinkExecutor extends AbstractJLinkToolchainExecutor
+{
+    private final ToolProvider toolProvider;
+
+    public JLinkExecutor( Toolchain toolchain, Log log ) throws IOException
+    {
+        super( toolchain, log );
+        this.toolProvider = getJLinkExecutable();
+    }
+
+    protected final ToolProvider getJLinkExecutable()
+    {
+        return ToolProvider
+                .findFirst( "jlink" )
+                .orElseThrow( () -> new IllegalStateException( "No jlink tool 
found." ) );
+    }
+
+    @Override
+    public int executeJlink( List<String> jlinkArgs ) throws 
MojoExecutionException
+    {
+        if (getToolchain().isPresent())
+        {
+            return super.executeJlink( jlinkArgs );
+        }
+
+        if ( getLog().isDebugEnabled() )
+        {
+            // no quoted arguments ???
+            getLog().debug( this.toolProvider.name() + " " + jlinkArgs );
+        }
+
+        try ( ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
+              PrintWriter err = new PrintWriter( baosErr );
+              ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
+              PrintWriter out = new PrintWriter( baosOut ) )

Review comment:
       Yes, I agree. This is also something for a new PR. I did chose 
`PrintWriter` on purpose here, as the original code contained a `PrintStream` 
with the same behaviour. Let’s open another JIRA issue for that and fix this in 
another PR. 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to