[
https://issues.apache.org/jira/browse/MRESOLVER-273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17609062#comment-17609062
]
ASF GitHub Bot commented on MRESOLVER-273:
------------------------------------------
michael-o commented on code in PR #194:
URL: https://github.com/apache/maven-resolver/pull/194#discussion_r979321613
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/FileGAVNameMapper.java:
##########
@@ -19,100 +19,32 @@
* under the License.
*/
-import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.metadata.Metadata;
-import org.eclipse.aether.named.support.FileSystemFriendly;
-
-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.util.Collection;
-import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
/**
- * A {@link NameMapper} that creates same name mapping as Takari Local
Repository does, with
- * {@code baseDir} (local repo). Part of code blatantly copies parts of the
Takari
- * {@code LockingSyncContext}.
- *
- * @see <a
href="https://github.com/takari/takari-local-repository/blob/24133e50a0478dccb5620ac2f2255187608f165b/src/main/java/io/takari/aether/concurrency/LockingSyncContext.java">Takari
- * LockingSyncContext.java</a>
+ * A file system friendly {@link NameMapper} that creates lock names out of
GAV that are file system friendly. The names
+ * (when considered as file names) are relative, but are unique to {@link
Artifact} and {@link Metadata} GAV
+ * coordinates.
*/
-@Singleton
-@Named( FileGAVNameMapper.NAME )
-public class FileGAVNameMapper
- implements NameMapper, FileSystemFriendly
+public class FileGAVNameMapper extends NameMapperSupport implements
FileSystemFriendlyNameMapper
{
- public static final String NAME = "file-gav";
+ private static final String SEPARATOR = "~";
private static final String LOCK_SUFFIX = ".resolverlock";
- private static final char SEPARATOR = '~';
-
- private final ConcurrentMap<String, Path> baseDirs;
-
- public FileGAVNameMapper()
- {
- this.baseDirs = new ConcurrentHashMap<>();
- }
-
@Override
- public TreeSet<String> nameLocks( final RepositorySystemSession session,
- final Collection<? extends Artifact>
artifacts,
- final Collection<? extends Metadata>
metadatas )
+ protected String getArtifactName( Artifact artifact )
{
- File localRepositoryBasedir =
session.getLocalRepository().getBasedir();
- // here we abuse concurrent hash map to make sure costly
getCanonicalFile is invoked only once
- Path baseDir = baseDirs.computeIfAbsent(
- localRepositoryBasedir.getPath(), k ->
- {
- try
- {
- return new File( localRepositoryBasedir, ".locks"
).getCanonicalFile().toPath();
- }
- catch ( IOException e )
- {
- throw new UncheckedIOException( e );
- }
- }
- );
-
- TreeSet<String> paths = new TreeSet<>();
- if ( artifacts != null )
- {
- for ( Artifact artifact : artifacts )
- {
- paths.add( getPath( baseDir, artifact ) + LOCK_SUFFIX );
- }
- }
- if ( metadatas != null )
- {
- for ( Metadata metadata : metadatas )
- {
- paths.add( getPath( baseDir, metadata ) + LOCK_SUFFIX );
- }
- }
- return paths;
- }
-
- private String getPath( final Path baseDir, final Artifact artifact )
- {
- // NOTE: Don't use LRM.getPath*() as those paths could be different
across processes, e.g. due to staging LRMs.
- String path = artifact.getGroupId()
- + SEPARATOR + artifact.getArtifactId()
- + SEPARATOR + artifact.getBaseVersion();
- return baseDir.resolve( path ).toAbsolutePath().toString();
+ return artifact.getGroupId()
+ + SEPARATOR + artifact.getArtifactId()
+ + SEPARATOR + artifact.getBaseVersion()
+ + LOCK_SUFFIX;
}
Review Comment:
This changes the semantics of this mapper. Can it be used in standalone at
all?
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/providers/FileHGAVNameMapperProvider.java:
##########
@@ -0,0 +1,54 @@
+package org.eclipse.aether.internal.impl.synccontext.named.providers;
+
+/*
+ * 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.Provider;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.internal.impl.synccontext.named.BaseDirNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.HashingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+
+/**
+ * The "file-hgav" name mapper provider.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileHGAVNameMapperProvider.NAME )
+public class FileHGAVNameMapperProvider implements Provider<NameMapper>
+{
+ public static final String NAME = "file-hgav";
Review Comment:
While I like the compact name `file-hgav` the class name should rather say
`Hashing`.
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/BaseDirNameMapper.java:
##########
@@ -0,0 +1,84 @@
+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 java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.support.FileSystemFriendly;
+import org.eclipse.aether.util.ConfigUtils;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper} class that is {@link FileSystemFriendly}: it
wraps another
+ * {@link FileSystemFriendlyNameMapper} and resolves the resulting "file
system friendly" names against local
+ * repository baseDir.
+ *
+ * @since TBD
+ */
+public class BaseDirNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_LOCKS_DIR_NAME =
"aether.syncContext.named.baseDir.locksDirName";
+
+ private final FileSystemFriendlyNameMapper delegate;
+
+ private final ConcurrentMap<String, Path> baseDirs;
+
+ public BaseDirNameMapper( final FileSystemFriendlyNameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ this.baseDirs = new ConcurrentHashMap<>();
+ }
+
+ @Override
+ public Collection<String> nameLocks( final RepositorySystemSession session,
+ final Collection<? extends Artifact>
artifacts,
+ final Collection<? extends Metadata>
metadatas )
+ {
+ final String locksDirName = ConfigUtils.getString( session, ".locks",
CONFIG_PROP_LOCKS_DIR_NAME );
Review Comment:
Question: Should a test enforce that this prop is solely a name and not:
* an absolute path
* a path with more than one component?
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/HashingNameMapper.java:
##########
@@ -0,0 +1,85 @@
+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 java.util.Collection;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.StringDigestUtil;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper}, that wraps another {@link NameMapper} and
hashes resulting strings. It makes use of
+ * fact that (proper) Hash will create unique fixed length string for each
different input string (so injection still
+ * stands). This mapper produces file system friendly names. Supports
different "depths" (0-4 inclusive) where the
+ * name will contain 0 to 4 level deep directories.
+ * <p>
+ * This mapper is usable in any scenario, but intent was to produce more
"compact" name mapper for file locking.
+ *
+ * @since TBD
+ */
+public class HashingNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_DEPTH =
"aether.syncContext.named.hashing.depth";
+
+ private final NameMapper delegate;
+
+ public HashingNameMapper( final NameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ }
+
+ @Override
+ public Collection<String> nameLocks( RepositorySystemSession session,
+ Collection<? extends Artifact>
artifacts,
+ Collection<? extends Metadata>
metadatas )
+ {
+ final int depth = ConfigUtils.getInteger( session, 2,
CONFIG_PROP_DEPTH );
+ if ( depth < 0 || depth > 4 )
+ {
+ throw new IllegalArgumentException( "allowed depth 0 and 4
(inclusive)" );
+ }
+ return delegate.nameLocks( session, artifacts, metadatas ).stream()
+ .map( n -> hashName( n, depth ) )
+ .collect( Collectors.toList() );
+ }
+
+ private String hashName( final String name, final int depth )
+ {
+ String hashedName = StringDigestUtil.sha1( name );
+ if ( depth == 0 )
+ {
+ return hashedName;
+ }
+ String prefix = "";
+ int i = 0;
+ while ( i < hashedName.length() && i / 2 < depth )
+ {
+ prefix += hashedName.substring( i, i + 2 ) + "/";
+ i += 2;
+ }
+ return prefix + hashedName;
+ }
+}
Review Comment:
Let me try to understand this: Instead of having flat hashes, you create
goups similar to what Git does with <hex>/<commit id>?
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/BaseDirNameMapper.java:
##########
@@ -0,0 +1,84 @@
+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 java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.support.FileSystemFriendly;
+import org.eclipse.aether.util.ConfigUtils;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper} class that is {@link FileSystemFriendly}: it
wraps another
+ * {@link FileSystemFriendlyNameMapper} and resolves the resulting "file
system friendly" names against local
+ * repository baseDir.
+ *
+ * @since TBD
+ */
+public class BaseDirNameMapper implements FileSystemFriendlyNameMapper
Review Comment:
Since local repo uses `basedir` and not `baseDir`, this class should do
accordingly for consistency reasons.
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/BaseDirNameMapper.java:
##########
@@ -0,0 +1,84 @@
+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 java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.support.FileSystemFriendly;
+import org.eclipse.aether.util.ConfigUtils;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper} class that is {@link FileSystemFriendly}: it
wraps another
+ * {@link FileSystemFriendlyNameMapper} and resolves the resulting "file
system friendly" names against local
+ * repository baseDir.
+ *
+ * @since TBD
+ */
+public class BaseDirNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_LOCKS_DIR_NAME =
"aether.syncContext.named.baseDir.locksDirName";
+
+ private final FileSystemFriendlyNameMapper delegate;
+
+ private final ConcurrentMap<String, Path> baseDirs;
+
+ public BaseDirNameMapper( final FileSystemFriendlyNameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ this.baseDirs = new ConcurrentHashMap<>();
+ }
+
+ @Override
+ public Collection<String> nameLocks( final RepositorySystemSession session,
+ final Collection<? extends Artifact>
artifacts,
+ final Collection<? extends Metadata>
metadatas )
+ {
+ final String locksDirName = ConfigUtils.getString( session, ".locks",
CONFIG_PROP_LOCKS_DIR_NAME );
+ final File localRepositoryBasedir =
session.getLocalRepository().getBasedir();
+ // here we abuse concurrent hash map to make sure costly
getCanonicalFile is invoked only once
+ final Path baseDir = baseDirs.computeIfAbsent(
localRepositoryBasedir.getPath(), k ->
+ {
+ try
+ {
+ return new File( localRepositoryBasedir, locksDirName
).getCanonicalFile().toPath();
Review Comment:
Why do you need the canonical path?
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/HashingNameMapper.java:
##########
@@ -0,0 +1,85 @@
+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 java.util.Collection;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.StringDigestUtil;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper}, that wraps another {@link NameMapper} and
hashes resulting strings. It makes use of
+ * fact that (proper) Hash will create unique fixed length string for each
different input string (so injection still
+ * stands). This mapper produces file system friendly names. Supports
different "depths" (0-4 inclusive) where the
+ * name will contain 0 to 4 level deep directories.
+ * <p>
+ * This mapper is usable in any scenario, but intent was to produce more
"compact" name mapper for file locking.
+ *
+ * @since TBD
+ */
+public class HashingNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_DEPTH =
"aether.syncContext.named.hashing.depth";
+
+ private final NameMapper delegate;
+
+ public HashingNameMapper( final NameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ }
+
+ @Override
+ public Collection<String> nameLocks( RepositorySystemSession session,
+ Collection<? extends Artifact>
artifacts,
+ Collection<? extends Metadata>
metadatas )
+ {
+ final int depth = ConfigUtils.getInteger( session, 2,
CONFIG_PROP_DEPTH );
+ if ( depth < 0 || depth > 4 )
+ {
+ throw new IllegalArgumentException( "allowed depth 0 and 4
(inclusive)" );
+ }
+ return delegate.nameLocks( session, artifacts, metadatas ).stream()
+ .map( n -> hashName( n, depth ) )
+ .collect( Collectors.toList() );
+ }
+
+ private String hashName( final String name, final int depth )
+ {
+ String hashedName = StringDigestUtil.sha1( name );
+ if ( depth == 0 )
+ {
+ return hashedName;
+ }
+ String prefix = "";
+ int i = 0;
+ while ( i < hashedName.length() && i / 2 < depth )
+ {
+ prefix += hashedName.substring( i, i + 2 ) + "/";
+ i += 2;
+ }
+ return prefix + hashedName;
Review Comment:
String builders should be used when loops are in play.
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/BaseDirNameMapper.java:
##########
@@ -0,0 +1,84 @@
+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 java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.support.FileSystemFriendly;
+import org.eclipse.aether.util.ConfigUtils;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper} class that is {@link FileSystemFriendly}: it
wraps another
+ * {@link FileSystemFriendlyNameMapper} and resolves the resulting "file
system friendly" names against local
+ * repository baseDir.
+ *
+ * @since TBD
+ */
+public class BaseDirNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_LOCKS_DIR_NAME =
"aether.syncContext.named.baseDir.locksDirName";
+
+ private final FileSystemFriendlyNameMapper delegate;
+
+ private final ConcurrentMap<String, Path> baseDirs;
+
+ public BaseDirNameMapper( final FileSystemFriendlyNameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ this.baseDirs = new ConcurrentHashMap<>();
+ }
+
+ @Override
+ public Collection<String> nameLocks( final RepositorySystemSession session,
+ final Collection<? extends Artifact>
artifacts,
+ final Collection<? extends Metadata>
metadatas )
+ {
+ final String locksDirName = ConfigUtils.getString( session, ".locks",
CONFIG_PROP_LOCKS_DIR_NAME );
+ final File localRepositoryBasedir =
session.getLocalRepository().getBasedir();
+ // here we abuse concurrent hash map to make sure costly
getCanonicalFile is invoked only once
+ final Path baseDir = baseDirs.computeIfAbsent(
localRepositoryBasedir.getPath(), k ->
+ {
+ try
+ {
+ return new File( localRepositoryBasedir, locksDirName
).getCanonicalFile().toPath();
+ }
+ catch ( IOException e )
+ {
+ throw new UncheckedIOException( e );
+ }
+ } );
+
+ return delegate.nameLocks( session, artifacts, metadatas ).stream()
+ .map( name -> baseDir.resolve( name
).toAbsolutePath().toString() )
Review Comment:
Won't canonical path be always absolute?
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/HashingNameMapper.java:
##########
@@ -0,0 +1,85 @@
+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 java.util.Collection;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.StringDigestUtil;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper}, that wraps another {@link NameMapper} and
hashes resulting strings. It makes use of
+ * fact that (proper) Hash will create unique fixed length string for each
different input string (so injection still
+ * stands). This mapper produces file system friendly names. Supports
different "depths" (0-4 inclusive) where the
+ * name will contain 0 to 4 level deep directories.
+ * <p>
+ * This mapper is usable in any scenario, but intent was to produce more
"compact" name mapper for file locking.
+ *
+ * @since TBD
+ */
+public class HashingNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_DEPTH =
"aether.syncContext.named.hashing.depth";
+
+ private final NameMapper delegate;
+
+ public HashingNameMapper( final NameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ }
+
+ @Override
+ public Collection<String> nameLocks( RepositorySystemSession session,
+ Collection<? extends Artifact>
artifacts,
+ Collection<? extends Metadata>
metadatas )
+ {
+ final int depth = ConfigUtils.getInteger( session, 2,
CONFIG_PROP_DEPTH );
+ if ( depth < 0 || depth > 4 )
+ {
+ throw new IllegalArgumentException( "allowed depth 0 and 4
(inclusive)" );
Review Comment:
"allowed depth between 0 and 4 (inclusive)"
now it sounds like the depts can be 0 OR 4
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/BaseDirNameMapper.java:
##########
@@ -0,0 +1,84 @@
+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 java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.support.FileSystemFriendly;
+import org.eclipse.aether.util.ConfigUtils;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Wrapping {@link NameMapper} class that is {@link FileSystemFriendly}: it
wraps another
+ * {@link FileSystemFriendlyNameMapper} and resolves the resulting "file
system friendly" names against local
+ * repository baseDir.
+ *
+ * @since TBD
+ */
+public class BaseDirNameMapper implements FileSystemFriendlyNameMapper
+{
+ private static final String CONFIG_PROP_LOCKS_DIR_NAME =
"aether.syncContext.named.baseDir.locksDirName";
+
+ private final FileSystemFriendlyNameMapper delegate;
+
+ private final ConcurrentMap<String, Path> baseDirs;
+
+ public BaseDirNameMapper( final FileSystemFriendlyNameMapper delegate )
+ {
+ this.delegate = requireNonNull( delegate );
+ this.baseDirs = new ConcurrentHashMap<>();
+ }
+
+ @Override
+ public Collection<String> nameLocks( final RepositorySystemSession session,
+ final Collection<? extends Artifact>
artifacts,
+ final Collection<? extends Metadata>
metadatas )
+ {
+ final String locksDirName = ConfigUtils.getString( session, ".locks",
CONFIG_PROP_LOCKS_DIR_NAME );
Review Comment:
I think since we use `.resolverlock` somewhere else, this dir should be
`.resolverlocks`. WDYT?
##########
maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapperTestSupport.java:
##########
@@ -41,9 +42,9 @@
protected RepositorySystemSession session;
@Before
- public void before()
+ public void before() throws IOException
{
- baseDir = "/home/maven/.m2/repository";
+ baseDir = new File("/home/maven/.m2/repository").getCanonicalPath();
Review Comment:
How will Java behave when the path isn't available?
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java:
##########
@@ -36,7 +36,13 @@
* locking happening. Never returns {@code null}. The resulting collection
MUST BE "stable" (always sorted by
* same criteria) to avoid deadlocks by acquiring locks in same order,
essentially disregarding the order of
* the input collections.
+ * <p>
+ * There is no requirement of any kind of "parity" between input element
count (sum of two collections, that is)
+ * and output collection size, just the returned upper size limit is
defined (sum of the passed in two collections
+ * size). If returned collection is empty, no locking will happen, if
single element, one lock will be used, if two
+ * then two named locks will be used etc.
Review Comment:
Good, this reflects the `static` name mapper.
> Create more compact File locking layout/mapper
> ----------------------------------------------
>
> Key: MRESOLVER-273
> URL: https://issues.apache.org/jira/browse/MRESOLVER-273
> Project: Maven Resolver
> Issue Type: Improvement
> Components: Resolver
> Reporter: Tamás Cservenák
> Assignee: Tamás Cservenák
> Priority: Major
> Fix For: resolver-next
>
>
> Current FileGAVNameMapper "mimics" loosely local reposiory layout, uses long
> paths, hence (relatively) big strings etc.
> More compact layout would be just to hash strings like "a:G:A:V" and
> "m:G[:A[:V]]" for artifacts and metadata instead, and create 2 level deep
> hashed storage.
> Problem with "loose" layout is that they do end up as files in OS, while
> these would be much shorter.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)