You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/03/13 09:46:18 UTC

[maven] branch MNG-7111 created (now bb39b72)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MNG-7111
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at bb39b72  Deadlock when reading pom

This branch includes the following new commits:

     new 3ef8ff2  Fix maven parallel builds
     new bb39b72  Deadlock when reading pom

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 02/02: Deadlock when reading pom

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7111
in repository https://gitbox.apache.org/repos/asf/maven.git

commit bb39b723ce97b78e50157eeea4be6645831153bc
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Mar 8 09:49:42 2021 +0100

    Deadlock when reading pom
---
 .../maven/model/building/DefaultModelBuilder.java  |  7 ++-
 .../model/building/DefaultTransformerContext.java  | 64 ++++++++++++++++++++--
 2 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 845480c..51d2b06 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1571,13 +1571,16 @@ public class DefaultModelBuilder
                 public Model getRawModel( String gId, String aId )
                 {
                     return context.modelByGA.computeIfAbsent( new DefaultTransformerContext.GAKey( gId, aId ),
-                                                              k -> findRawModel( gId, aId ) );
+                                                              k -> new DefaultTransformerContext.Holder() )
+                            .computeIfAbsent( () -> findRawModel( gId, aId ) );
                 }
 
                 @Override
                 public Model getRawModel( Path path )
                 {
-                    return context.modelByPath.computeIfAbsent( path, k -> findRawModel( path ) );
+                    return context.modelByPath.computeIfAbsent( path,
+                                                                k -> new DefaultTransformerContext.Holder() )
+                            .computeIfAbsent( () -> findRawModel( path ) );
                 }
 
                 private Model findRawModel( String groupId, String artifactId )
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
index 9c7da72..3c70b3c 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
@@ -23,6 +23,7 @@ import java.nio.file.Path;
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
 
 import org.apache.maven.model.Model;
 
@@ -35,9 +36,64 @@ class DefaultTransformerContext implements TransformerContext
 {
     final Map<String, String> userProperties = new ConcurrentHashMap<>();
 
-    final Map<Path, Model> modelByPath = new ConcurrentHashMap<>();
+    final Map<Path, Holder> modelByPath = new ConcurrentHashMap<>();
 
-    final Map<GAKey, Model> modelByGA = new ConcurrentHashMap<>();
+    final Map<GAKey, Holder> modelByGA = new ConcurrentHashMap<>();
+
+    public static class Holder
+    {
+        private volatile boolean set;
+        private volatile Model model;
+
+        Holder()
+        {
+        }
+
+        public static Model deref( Holder holder )
+        {
+            return holder != null ? holder.get() : null;
+        }
+
+        public Model get()
+        {
+            if ( !set )
+            {
+                synchronized ( this )
+                {
+                    if ( !set )
+                    {
+                        try
+                        {
+                            this.wait();
+                        }
+                        catch ( InterruptedException e )
+                        {
+                            // Ignore
+                        }
+                    }
+                }
+            }
+            return model;
+        }
+
+        public Model computeIfAbsent( Supplier<Model> supplier )
+        {
+            if ( !set )
+            {
+                synchronized ( this )
+                {
+                    if ( !set )
+                    {
+                        this.set = true;
+                        this.model = supplier.get();
+                        this.notifyAll();
+                    }
+                }
+            }
+            return model;
+        }
+
+    }
 
     @Override
     public String getUserProperty( String key )
@@ -48,13 +104,13 @@ class DefaultTransformerContext implements TransformerContext
     @Override
     public Model getRawModel( Path p )
     {
-        return modelByPath.get( p );
+        return Holder.deref( modelByPath.get( p ) );
     }
 
     @Override
     public Model getRawModel( String groupId, String artifactId )
     {
-        return modelByGA.get( new GAKey( groupId, artifactId ) );
+        return Holder.deref( modelByGA.get( new GAKey( groupId, artifactId ) ) );
     }
 
     static class GAKey


[maven] 01/02: Fix maven parallel builds

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-7111
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 3ef8ff2d36af27bb5d24f82caa8f752a9dae6e1e
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Feb 8 17:28:59 2021 +0100

    Fix maven parallel builds
---
 .../apache/maven/model/building/DefaultTransformerContext.java    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
index 080c62b..9c7da72 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
@@ -20,9 +20,9 @@ package org.apache.maven.model.building;
  */
 
 import java.nio.file.Path;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.maven.model.Model;
 
@@ -33,11 +33,11 @@ import org.apache.maven.model.Model;
  */
 class DefaultTransformerContext implements TransformerContext
 {
-    final Map<String, String> userProperties = new HashMap<>();
+    final Map<String, String> userProperties = new ConcurrentHashMap<>();
 
-    final Map<Path, Model> modelByPath = new HashMap<>();
+    final Map<Path, Model> modelByPath = new ConcurrentHashMap<>();
 
-    final Map<GAKey, Model> modelByGA = new HashMap<>();
+    final Map<GAKey, Model> modelByGA = new ConcurrentHashMap<>();
 
     @Override
     public String getUserProperty( String key )