michael-o commented on code in PR #194: URL: https://github.com/apache/maven-resolver/pull/194#discussion_r981054821
########## maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapperTestSupport.java: ########## @@ -0,0 +1,55 @@ +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.util.HashMap; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.LocalRepository; +import org.junit.Before; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Simple support class for {@link NameMapper} implementation UTs. + */ +public abstract class NameMapperTestSupport +{ + protected String baseDir; + + protected HashMap<String, Object> configProperties; + + protected RepositorySystemSession session; + + @Before + public void before() throws IOException + { + baseDir = new File("/home/maven/.m2/repository").getCanonicalPath(); Review Comment: For the same of portability I would use `System.getProperty( "user.dir" )` ########## maven-resolver-impl/src/site/markdown/synccontextfactory.md.vm: ########## @@ -78,8 +79,13 @@ Other configuration keys: - `aether.syncContext.named.static.name`, the value to use as static lock name, if `static` name mapper is used. If not set, defaults to "static". +- `aether.syncContext.named.basedir.locksDirName`, the directory within local repository to store the lock files. Review Comment: ...the relative directory... ########## maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapperTestSupport.java: ########## @@ -0,0 +1,55 @@ +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.util.HashMap; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.LocalRepository; +import org.junit.Before; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Simple support class for {@link NameMapper} implementation UTs. + */ +public abstract class NameMapperTestSupport +{ + protected String baseDir; + + protected HashMap<String, Object> configProperties; + + protected RepositorySystemSession session; + + @Before + public void before() throws IOException + { + baseDir = new File("/home/maven/.m2/repository").getCanonicalPath(); Review Comment: Nit picking: `baseDir` => `basedir` ########## 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: I knew that this would blow up: ``` PS C:\Entwicklung\Projekte\maven-resolver> c:\Temp\apache-maven-4.0.0-alpha-1-SNAPSHOT\bin\mvn.cmd --% -Daether.syncContext.named.factory=file-lock -Daether.syncContext.named.nameMapper=file-hgav install -Daether.syncContext.named.hashing.depth=1 -Daether.syncContext.named.basedir.locksDirName=C:\temp\sdfs [INFO] Scanning for projects... [ERROR] Internal error: java.io.UncheckedIOException: java.io.IOException: Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch -> [Help 1] org.apache.maven.InternalErrorException: Internal error: java.io.UncheckedIOException: java.io.IOException: Die Syntax ``` You must enforce this to be a relative dir. Let met try this ontop PR. -- 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