You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2020/08/09 19:11:23 UTC

[maven-resolver] branch MRESOLVER-130 updated (542a11c -> c4c3ea6)

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

michaelo pushed a change to branch MRESOLVER-130
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git.


 discard 542a11c  [MRESOLVER-130] Move GlobalSyncContextFactory to a separate module
     new c4c3ea6  [MRESOLVER-130] Move GlobalSyncContextFactory to a separate module

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (542a11c)
            \
             N -- N -- N   refs/heads/MRESOLVER-130 (c4c3ea6)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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


Summary of changes:
 .../aether/internal/impl/TrackingFileManager.java  | 151 +++++++++++++++++++++
 .../synccontext/GlobalSyncContextFactory.java      |  10 +-
 2 files changed, 157 insertions(+), 4 deletions(-)
 create mode 100644 maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/TrackingFileManager.java


[maven-resolver] 01/01: [MRESOLVER-130] Move GlobalSyncContextFactory to a separate module

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

michaelo pushed a commit to branch MRESOLVER-130
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit c4c3ea667938620c72cc2c0ae5cd2cfec3d54dc8
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Thu Aug 6 20:50:27 2020 +0200

    [MRESOLVER-130] Move GlobalSyncContextFactory to a separate module
---
 .../internal/impl/DefaultSyncContextFactory.java   |  36 +----
 maven-resolver-synccontext-global/pom.xml          |  85 ++++++++++++
 .../internal/impl/DefaultSyncContextFactory.java   |  36 +++++
 .../aether/internal/impl/TrackingFileManager.java  | 151 +++++++++++++++++++++
 .../synccontext/GlobalSyncContextFactory.java      |  26 ++--
 pom.xml                                            |   1 +
 6 files changed, 288 insertions(+), 47 deletions(-)

diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
index be89735..01c861f 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
@@ -20,69 +20,41 @@ package org.eclipse.aether.internal.impl;
  */
 
 import java.util.Collection;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
 import org.eclipse.aether.impl.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Singleton;
 
 /**
- * A factory to create synchronization contexts. This default implementation uses fair global locking
- * based on {@link ReentrantReadWriteLock}. Explicit artifacts and metadata passed are ignored.
+ * A factory to create synchronization contexts. This default implementation actually does not provide any real
+ * synchronization but merely completes the repository system.
  */
 @Named
 @Singleton
 public class DefaultSyncContextFactory
     implements SyncContextFactory
 {
-    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock( true );
 
     public SyncContext newInstance( RepositorySystemSession session, boolean shared )
     {
-        return new DefaultSyncContext( shared ? lock.readLock() : lock.writeLock(), shared );
+        return new DefaultSyncContext();
     }
 
     static class DefaultSyncContext
         implements SyncContext
     {
-        private static final Logger LOGGER = LoggerFactory.getLogger( DefaultSyncContext.class );
-
-        private final Lock lock;
-        private final boolean shared;
-        private int lockHoldCount;
-
-        DefaultSyncContext( Lock lock, boolean shared )
-        {
-            this.lock = lock;
-            this.shared = shared;
-        }
 
         public void acquire( Collection<? extends Artifact> artifact, Collection<? extends Metadata> metadata )
         {
-            LOGGER.trace( "Acquiring global {} lock (currently held: {})",
-                          shared ? "read" : "write", lockHoldCount );
-            lock.lock();
-            lockHoldCount++;
         }
 
         public void close()
         {
-            while ( lockHoldCount != 0 )
-            {
-                LOGGER.trace( "Releasing global {} lock (currently held: {})",
-                              shared ? "read" : "write", lockHoldCount );
-                lock.unlock();
-                lockHoldCount--;
-            }
         }
 
     }
diff --git a/maven-resolver-synccontext-global/pom.xml b/maven-resolver-synccontext-global/pom.xml
new file mode 100644
index 0000000..f70fee1
--- /dev/null
+++ b/maven-resolver-synccontext-global/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.resolver</groupId>
+    <artifactId>maven-resolver</artifactId>
+    <version>1.5.1-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>maven-resolver-synccontext-global</artifactId>
+
+  <name>Maven Artifact Resolver Sync Context Global</name>
+  <description>
+      A sync context implementation using a global fair lock.
+  </description>
+
+  <properties>
+    <Automatic-Module-Name>org.apache.maven.resolver.synccontext.global</Automatic-Module-Name>
+    <Bundle-SymbolicName>${Automatic-Module-Name}</Bundle-SymbolicName>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.eclipse.sisu</groupId>
+        <artifactId>sisu-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestFile>${project.build.directory}/osgi/MANIFEST.MF</manifestFile>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java b/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
new file mode 100644
index 0000000..5386359
--- /dev/null
+++ b/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
@@ -0,0 +1,36 @@
+package org.eclipse.aether.internal.impl;
+
+/*
+ * 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 javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.synccontext.GlobalSyncContextFactory;
+
+/**
+ * This is a shim to override (shadow) the actual {@code DefaultSyncContextFactory}} via ext classpath.
+ */
+@Named
+@Singleton
+public class DefaultSyncContextFactory
+    extends GlobalSyncContextFactory
+{
+
+}
diff --git a/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/TrackingFileManager.java b/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/TrackingFileManager.java
new file mode 100644
index 0000000..ffc200f
--- /dev/null
+++ b/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/internal/impl/TrackingFileManager.java
@@ -0,0 +1,151 @@
+package org.eclipse.aether.internal.impl;
+
+/*
+ * 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.eclipse.aether.SyncContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Manages access to a properties file. This override drops internal synchronization becauses it
+ * relies on external synchronization provided by outer {@link SyncContext} instances.
+ */
+class TrackingFileManager
+{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( TrackingFileManager.class );
+
+    public Properties read( File file )
+    {
+        FileInputStream stream = null;
+        try
+        {
+            if ( !file.exists() )
+            {
+                return null;
+            }
+
+            stream = new FileInputStream( file );
+
+            Properties props = new Properties();
+            props.load( stream );
+
+            return props;
+        }
+        catch ( IOException e )
+        {
+            LOGGER.warn( "Failed to read tracking file {}", file, e );
+        }
+        finally
+        {
+            close( stream, file );
+        }
+
+        return null;
+    }
+
+    public Properties update( File file, Map<String, String> updates )
+    {
+        Properties props = new Properties();
+
+        File directory = file.getParentFile();
+        if ( !directory.mkdirs() && !directory.exists() )
+        {
+            LOGGER.warn( "Failed to create parent directories for tracking file {}", file );
+            return props;
+        }
+
+        RandomAccessFile raf = null;
+        try
+        {
+            raf = new RandomAccessFile( file, "rw" );
+
+            if ( file.canRead() )
+            {
+                byte[] buffer = new byte[(int) raf.length()];
+
+                raf.readFully( buffer );
+
+                ByteArrayInputStream stream = new ByteArrayInputStream( buffer );
+
+                props.load( stream );
+            }
+
+            for ( Map.Entry<String, String> update : updates.entrySet() )
+            {
+                if ( update.getValue() == null )
+                {
+                    props.remove( update.getKey() );
+                }
+                else
+                {
+                    props.setProperty( update.getKey(), update.getValue() );
+                }
+            }
+
+            ByteArrayOutputStream stream = new ByteArrayOutputStream( 1024 * 2 );
+
+            LOGGER.debug( "Writing tracking file {}", file );
+            props.store( stream, "NOTE: This is a Maven Resolver internal implementation file"
+                + ", its format can be changed without prior notice." );
+
+            raf.seek( 0 );
+            raf.write( stream.toByteArray() );
+            raf.setLength( raf.getFilePointer() );
+        }
+        catch ( IOException e )
+        {
+            LOGGER.warn( "Failed to write tracking file {}", file, e );
+        }
+        finally
+        {
+            close( raf, file );
+        }
+
+        return props;
+    }
+
+    private void close( Closeable closeable, File file )
+    {
+        if ( closeable != null )
+        {
+            try
+            {
+                closeable.close();
+            }
+            catch ( IOException e )
+            {
+                LOGGER.warn( "Error closing tracking file {}", file, e );
+            }
+        }
+    }
+
+}
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java b/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/synccontext/GlobalSyncContextFactory.java
similarity index 81%
copy from maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
copy to maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/synccontext/GlobalSyncContextFactory.java
index be89735..deae0ea 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
+++ b/maven-resolver-synccontext-global/src/main/java/org/eclipse/aether/synccontext/GlobalSyncContextFactory.java
@@ -1,4 +1,4 @@
-package org.eclipse.aether.internal.impl;
+package org.eclipse.aether.synccontext;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -23,8 +23,6 @@ import java.util.Collection;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import javax.inject.Named;
-
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
@@ -33,34 +31,32 @@ import org.eclipse.aether.metadata.Metadata;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.inject.Singleton;
-
 /**
- * A factory to create synchronization contexts. This default implementation uses fair global locking
+ * A factory to create synchronization contexts. This implementation uses global locking
  * based on {@link ReentrantReadWriteLock}. Explicit artifacts and metadata passed are ignored.
+ * <br>
+ * This factory is considered experimental.
  */
-@Named
-@Singleton
-public class DefaultSyncContextFactory
+public class GlobalSyncContextFactory
     implements SyncContextFactory
 {
-    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock( true );
+    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
 
     public SyncContext newInstance( RepositorySystemSession session, boolean shared )
     {
-        return new DefaultSyncContext( shared ? lock.readLock() : lock.writeLock(), shared );
+        return new GlobalSyncContext( shared ? lock.readLock() : lock.writeLock(), shared );
     }
 
-    static class DefaultSyncContext
+    static class GlobalSyncContext
         implements SyncContext
     {
-        private static final Logger LOGGER = LoggerFactory.getLogger( DefaultSyncContext.class );
+        private static final Logger LOGGER = LoggerFactory.getLogger( GlobalSyncContext.class );
 
         private final Lock lock;
         private final boolean shared;
         private int lockHoldCount;
 
-        DefaultSyncContext( Lock lock, boolean shared )
+        private GlobalSyncContext( Lock lock, boolean shared )
         {
             this.lock = lock;
             this.shared = shared;
@@ -76,7 +72,7 @@ public class DefaultSyncContextFactory
 
         public void close()
         {
-            while ( lockHoldCount != 0 )
+            while ( lockHoldCount > 0 )
             {
                 LOGGER.trace( "Releasing global {} lock (currently held: {})",
                               shared ? "read" : "write", lockHoldCount );
diff --git a/pom.xml b/pom.xml
index 757d117..2f7c4b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,7 @@
     <module>maven-resolver-transport-http</module>
     <module>maven-resolver-transport-wagon</module>
     <module>maven-resolver-demos</module>
+    <module>maven-resolver-synccontext-global</module>
   </modules>
 
   <dependencyManagement>