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/06 19:10:36 UTC
[maven-resolver] 01/01: [MRESOLVER-130] Move
GlobalSyncContextFactory to a separate module
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 542a11c38d697a76b01ede874f31cc0f0fa80a10
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 +++++++++
.../synccontext/GlobalSyncContextFactory.java | 20 ++---
pom.xml | 1 +
5 files changed, 133 insertions(+), 45 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-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 83%
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..3a77b4a 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,30 @@ 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 fair global locking
* based on {@link ReentrantReadWriteLock}. Explicit artifacts and metadata passed are ignored.
*/
-@Named
-@Singleton
-public class DefaultSyncContextFactory
+public class GlobalSyncContextFactory
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 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 )
+ GlobalSyncContext( Lock lock, boolean shared )
{
this.lock = lock;
this.shared = shared;
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>