cstamas commented on a change in pull request #131:
URL: https://github.com/apache/maven-resolver/pull/131#discussion_r724224501



##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/FileLockNamedLockFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * 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.RepositorySystemSession;
+import org.eclipse.aether.named.support.FileLockNamedLockFactorySupport;
+import org.eclipse.aether.named.support.NamedLockSupport;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A {@link SessionAwareNamedLockFactory} that uses advisory file locking.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileLockNamedLockFactory.NAME )
+public class FileLockNamedLockFactory
+    extends FileLockNamedLockFactorySupport
+    implements SessionAwareNamedLockFactory
+{
+    public static final String NAME = "file-lock";
+
+    private final ConcurrentHashMap<String, Path> baseDirs;
+
+    public FileLockNamedLockFactory()
+    {
+        this.baseDirs = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public NamedLockSupport getLock( final RepositorySystemSession session, 
final String name )
+    {
+        File localRepositoryBasedir = 
session.getLocalRepository().getBasedir();
+        Path baseDir = baseDirs.computeIfAbsent(

Review comment:
       Purpose is to get canonical file only once, to cache it.

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/FileLockNamedLockFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * 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.RepositorySystemSession;
+import org.eclipse.aether.named.support.FileLockNamedLockFactorySupport;
+import org.eclipse.aether.named.support.NamedLockSupport;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A {@link SessionAwareNamedLockFactory} that uses advisory file locking.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileLockNamedLockFactory.NAME )
+public class FileLockNamedLockFactory
+    extends FileLockNamedLockFactorySupport
+    implements SessionAwareNamedLockFactory
+{
+    public static final String NAME = "file-lock";
+
+    private final ConcurrentHashMap<String, Path> baseDirs;
+
+    public FileLockNamedLockFactory()
+    {
+        this.baseDirs = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public NamedLockSupport getLock( final RepositorySystemSession session, 
final String name )
+    {
+        File localRepositoryBasedir = 
session.getLocalRepository().getBasedir();
+        Path baseDir = baseDirs.computeIfAbsent(
+            localRepositoryBasedir.getPath(), k ->
+            {
+                try
+                {
+                    return new File( localRepositoryBasedir, ".locks" 
).getCanonicalFile().toPath();

Review comment:
       That's why is in computeIfAbsent, to calculate it only once.

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/FileLockNamedLockFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * 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.RepositorySystemSession;
+import org.eclipse.aether.named.support.FileLockNamedLockFactorySupport;
+import org.eclipse.aether.named.support.NamedLockSupport;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A {@link SessionAwareNamedLockFactory} that uses advisory file locking.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileLockNamedLockFactory.NAME )
+public class FileLockNamedLockFactory
+    extends FileLockNamedLockFactorySupport
+    implements SessionAwareNamedLockFactory
+{
+    public static final String NAME = "file-lock";
+
+    private final ConcurrentHashMap<String, Path> baseDirs;
+
+    public FileLockNamedLockFactory()
+    {
+        this.baseDirs = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public NamedLockSupport getLock( final RepositorySystemSession session, 
final String name )
+    {
+        File localRepositoryBasedir = 
session.getLocalRepository().getBasedir();
+        Path baseDir = baseDirs.computeIfAbsent(
+            localRepositoryBasedir.getPath(), k ->
+            {
+                try
+                {
+                    return new File( localRepositoryBasedir, ".locks" 
).getCanonicalFile().toPath();
+                }
+                catch ( IOException e )
+                {
+                    throw new UncheckedIOException( e );
+                }
+            }
+        );
+
+        String fileName = baseDir.resolve( name ).toAbsolutePath().toString();

Review comment:
       Yes, commit b5328161f298c62ad1b74d3f40d9ae50d7d5dd9e adds a "mapper" 
that is FS friendly, shamelessly stolen from Takari Local Repo project :smile: 
   Now, how to prevent "mis-configuration" is yet to be done.

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/FileLockNamedLockFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * 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.RepositorySystemSession;
+import org.eclipse.aether.named.support.FileLockNamedLockFactorySupport;
+import org.eclipse.aether.named.support.NamedLockSupport;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A {@link SessionAwareNamedLockFactory} that uses advisory file locking.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileLockNamedLockFactory.NAME )
+public class FileLockNamedLockFactory
+    extends FileLockNamedLockFactorySupport
+    implements SessionAwareNamedLockFactory
+{
+    public static final String NAME = "file-lock";
+
+    private final ConcurrentHashMap<String, Path> baseDirs;
+
+    public FileLockNamedLockFactory()
+    {
+        this.baseDirs = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public NamedLockSupport getLock( final RepositorySystemSession session, 
final String name )
+    {
+        File localRepositoryBasedir = 
session.getLocalRepository().getBasedir();
+        Path baseDir = baseDirs.computeIfAbsent(

Review comment:
       ... and it may change, if executes within mvnd for example :wink: 




-- 
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: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to