slawekjaranowski commented on a change in pull request #565:
URL: https://github.com/apache/maven/pull/565#discussion_r725203766



##########
File path: 
maven-core/src/main/java/org/apache/maven/plugin/internal/MojoLog.java
##########
@@ -0,0 +1,203 @@
+package org.apache.maven.plugin.internal;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.logging.Log;
+import org.slf4j.Logger;
+
+import javax.inject.Provider;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Mojo {@link Log} implementation that lazily creates {@link Logger} 
instances. To achieve "lazyness" it uses
+ * {@link Provider} for logger, but guarantees that {@link Provider#get()} is 
invoked only once, and once got
+ * Logger instance is reused.
+ *
+ * @since TBD
+ */
+public class MojoLog
+    implements Log
+{
+    private final Provider<Logger> loggerProvider;
+
+    public MojoLog( Provider<Logger> loggerProvider )
+    {
+        this.loggerProvider = memoize( loggerProvider );
+    }
+
+    private Logger getLogger()
+    {
+        return loggerProvider.get();
+    }
+
+    private String toString( CharSequence content )
+    {
+        if ( content == null )
+        {
+            return "";
+        }
+        else
+        {
+            return content.toString();
+        }
+    }
+
+    @Override
+    public void debug( CharSequence content )
+    {
+        getLogger().debug( toString( content ) );
+    }
+
+    @Override
+    public void debug( CharSequence format, Object... arguments )
+    {
+        if ( getLogger().isDebugEnabled() )

Review comment:
       why  such protection only in two place

##########
File path: 
maven-plugin-api/src/main/java/org/apache/maven/plugin/logging/Log.java
##########
@@ -46,6 +45,16 @@
      */
     void debug( CharSequence content );
 
+    /**
+     * Send a message to the user in the <b>debug</b> error level using given 
format and arguments. In format use
+     * {@code {}} as placeholders for objects passed in as arguments. No 
argument is converted to string is
+     * given level is not enabled.
+     *
+     * @param format
+     * @param arguments
+     */
+    void debug( CharSequence format, Object... arguments );

Review comment:
       will other methods (warn, info, error) have also such signature?
   What if last argument will be of `Throwable` type?

##########
File path: maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
##########
@@ -192,11 +199,20 @@ public MavenExecutionResult getResult()
 
     // Backward compat
 
+    /**
+     * Returns the plugin context for given key ({@link 
PluginDescriptor#getPluginLookupKey()} and
+     * {@link MavenProject}, never returns {@code null} as if context not 
present, creates it.
+     *
+     * <strong>Implementation note:</strong> while this method return type is 
{@link Map}, the returned map instance
+     * implements {@link ConcurrentMap} as well.
+     *
+     */
     public Map<String, Object> getPluginContext( PluginDescriptor plugin, 
MavenProject project )

Review comment:
       why not use `computeIfAbsent` in this method?
   can this method be call in concurrency?




-- 
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: [email protected]

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


Reply via email to