[
https://issues.apache.org/jira/browse/MRESOLVER-273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17609119#comment-17609119
]
ASF GitHub Bot commented on MRESOLVER-273:
------------------------------------------
cstamas commented on code in PR #194:
URL: https://github.com/apache/maven-resolver/pull/194#discussion_r979380066
##########
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:
Not anymore (original class was basedir + filegav, now is only filegav)
> 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)