Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.
*/
package org.eclipse.aether.internal.impl.synccontext.named;

import org.eclipse.aether.artifact.Artifact;

/**
* Artifact GAECV {@link NameMapper} extends {@link GAVNameMapper} and improves artifact name mapping selectivity by
* using all coordinates.
*
* @since 1.9.25
*/
public class GAECVNameMapper extends GAVNameMapper {
public GAECVNameMapper(
boolean fileSystemFriendly,
String artifactPrefix,
String artifactSuffix,
String metadataPrefix,
String metadataSuffix,
String fieldSeparator) {
super(fileSystemFriendly, artifactPrefix, artifactSuffix, metadataPrefix, metadataSuffix, fieldSeparator);
}

@Override
protected String getArtifactName(Artifact artifact) {
if (artifact.getClassifier().isEmpty()) {
return artifactPrefix
+ artifact.getGroupId()
+ fieldSeparator
+ artifact.getArtifactId()
+ fieldSeparator
+ artifact.getExtension()
+ fieldSeparator
+ artifact.getBaseVersion()
+ artifactSuffix;
} else {
return artifactPrefix
+ artifact.getGroupId()
+ fieldSeparator
+ artifact.getArtifactId()
+ fieldSeparator
+ artifact.getExtension()
+ fieldSeparator
+ artifact.getClassifier()
+ fieldSeparator
+ artifact.getBaseVersion()
+ artifactSuffix;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@
import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.named.NamedLockKey;
import org.eclipse.aether.util.PathUtils;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;

import static java.util.Objects.requireNonNull;

/**
* Artifact GAV {@link NameMapper}, uses artifact and metadata coordinates to name their corresponding locks. Is not
* considering local repository, only the artifact coordinates. May use custom prefixes and suffixes and separators,
* hence this instance may or may not be filesystem friendly (depends on strings used).
* <p>
* Note: in earlier Resolver 1.9.x versions this mapper was the default, but it changed to {@link GAECVNameMapper}
* in 1.9.25.
*/
public class GAVNameMapper implements NameMapper {
private final boolean fileSystemFriendly;
protected final boolean fileSystemFriendly;

private final String artifactPrefix;
protected final String artifactPrefix;

private final String artifactSuffix;
protected final String artifactSuffix;

private final String metadataPrefix;
protected final String metadataPrefix;

private final String metadataSuffix;
protected final String metadataSuffix;

private final String fieldSeparator;
protected final String fieldSeparator;

public GAVNameMapper(
boolean fileSystemFriendly,
Expand Down Expand Up @@ -78,61 +82,81 @@ public Collection<NamedLockKey> nameLocks(
TreeSet<NamedLockKey> keys = new TreeSet<>(Comparator.comparing(NamedLockKey::name));
if (artifacts != null) {
for (Artifact artifact : artifacts) {
keys.add(NamedLockKey.of(
getArtifactName(artifact, artifactPrefix, fieldSeparator, artifactSuffix),
getArtifactName(artifact, "", ":", "")));
keys.add(NamedLockKey.of(getArtifactName(artifact), ArtifactIdUtils.toBaseId(artifact)));
}
}

if (metadatas != null) {
for (Metadata metadata : metadatas) {
keys.add(NamedLockKey.of(
getMetadataName(metadata, fileSystemFriendly, metadataPrefix, fieldSeparator, metadataSuffix),
getMetadataName(metadata, false, "", ":", "")));
keys.add(NamedLockKey.of(getMetadataName(metadata), toMetadataId(metadata)));
}
}
return keys;
}

private static String getArtifactName(Artifact artifact, String prefix, String separator, String suffix) {
return prefix
protected String getArtifactName(Artifact artifact) {
return artifactPrefix
+ artifact.getGroupId()
+ separator
+ fieldSeparator
+ artifact.getArtifactId()
+ separator
+ fieldSeparator
+ artifact.getBaseVersion()
+ suffix;
+ artifactSuffix;
}

private static final String MAVEN_METADATA = "maven-metadata.xml";
protected static final String MAVEN_METADATA = "maven-metadata.xml";

private static String getMetadataName(
Metadata metadata, boolean fileSystemFriendly, String prefix, String separator, String suffix) {
String name = prefix;
protected String getMetadataName(Metadata metadata) {
String name = metadataPrefix;
if (!metadata.getGroupId().isEmpty()) {
name += metadata.getGroupId();
if (!metadata.getArtifactId().isEmpty()) {
name += separator + metadata.getArtifactId();
name += fieldSeparator + metadata.getArtifactId();
if (!metadata.getVersion().isEmpty()) {
name += separator + metadata.getVersion();
name += fieldSeparator + metadata.getVersion();
}
}
if (!MAVEN_METADATA.equals(metadata.getType())) {
name += separator
name += fieldSeparator
+ (fileSystemFriendly ? PathUtils.stringToPathSegment(metadata.getType()) : metadata.getType());
}
} else {
if (!MAVEN_METADATA.equals(metadata.getType())) {
name += (fileSystemFriendly ? PathUtils.stringToPathSegment(metadata.getType()) : metadata.getType());
}
}
return name + suffix;
return name + metadataSuffix;
}

protected String toMetadataId(Metadata metadata) {
String name = "";
if (!metadata.getGroupId().isEmpty()) {
name += metadata.getGroupId();
if (!metadata.getArtifactId().isEmpty()) {
name += ":" + metadata.getArtifactId();
if (!metadata.getVersion().isEmpty()) {
name += ":" + metadata.getVersion();
}
}
}
if (!metadata.getType().isEmpty()) {
name += (name.isEmpty() ? "" : ":") + metadata.getType();
}
return name;
}

/**
* @deprecated Use {@link NameMappers} to create name mappers instead.
*/
@Deprecated
public static NameMapper gav() {
return new GAVNameMapper(false, "artifact:", "", "metadata:", "", ":");
}

/**
* @deprecated Use {@link NameMappers} to create name mappers instead.
*/
@Deprecated
public static NameMapper fileGav() {
return new GAVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
/**
* As end-user "mappers" are actually configurations/compositions and are constructed from several NameMapper
* implementations, this helper class constructing them. This class also holds "names" used by service locator and
* Guice/Sisu as well.
* Guice/Sisu as well. Ideally, name mapper you want should exist here, constructing name mappers should not be
* needed (unless some very specific case or testing).
*
* @since 1.9.4
*/
public final class NameMappers {
private NameMappers() {}

public static final String STATIC_NAME = "static";

public static final String GAV_NAME = "gav";
Expand All @@ -34,6 +37,21 @@ public final class NameMappers {

public static final String FILE_HGAV_NAME = "file-hgav";

/**
* @since 1.9.25
*/
public static final String GAECV_NAME = "gaecv";

/**
* @since 1.9.25
*/
public static final String FILE_GAECV_NAME = "file-gaecv";

/**
* @since 1.9.25
*/
public static final String FILE_HGAECV_NAME = "file-hgaecv";

/**
* @since 1.9.6
*/
Expand All @@ -46,11 +64,47 @@ public static NameMapper staticNameMapper() {
}

public static NameMapper gavNameMapper() {
return GAVNameMapper.gav();
return gavNameMapper(false);
}

/**
* @since 1.9.25
*/
public static NameMapper gavNameMapper(boolean fileSystemFriendly) {
if (fileSystemFriendly) {
return new GAVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
} else {
return new GAVNameMapper(false, "artifact:", "", "metadata:", "", ":");
}
}

/**
* @since 1.9.25
*/
public static NameMapper gaecvNameMapper() {
return gaecvNameMapper(false);
}

/**
* @since 1.9.25
*/
public static NameMapper gaecvNameMapper(boolean fileSystemFriendly) {
if (fileSystemFriendly) {
return new GAECVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
} else {
return new GAECVNameMapper(false, "artifact:", "", "metadata:", "", ":");
}
}

public static NameMapper fileGavNameMapper() {
return new BasedirNameMapper(GAVNameMapper.fileGav());
return new BasedirNameMapper(gavNameMapper(true));
}

/**
* @since 1.9.25
*/
public static NameMapper fileGaecvNameMapper() {
return new BasedirNameMapper(gaecvNameMapper(true));
}

/**
Expand All @@ -61,10 +115,17 @@ public static NameMapper fileStaticNameMapper() {
}

public static NameMapper fileHashingGavNameMapper() {
return new BasedirNameMapper(new HashingNameMapper(GAVNameMapper.gav()));
return new BasedirNameMapper(new HashingNameMapper(gavNameMapper(false)));
}

/**
* @since 1.9.25
*/
public static NameMapper fileHashingGaecvNameMapper() {
return new BasedirNameMapper(new HashingNameMapper(gaecvNameMapper(false)));
}

public static NameMapper discriminatingNameMapper() {
return new DiscriminatingNameMapper(GAVNameMapper.gav());
return new DiscriminatingNameMapper(gavNameMapper(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapterFactory {
public static final String DEFAULT_FACTORY_NAME = FileLockNamedLockFactory.NAME;

public static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.FILE_GAV_NAME;
public static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.FILE_GAECV_NAME;

/**
* Name of the lock factory to use in session.
* Name of the lock factory to use in session. Out of the box supported ones are "file-lock", "rwlock-local",
* "semaphore-local", "noop". By adding extensions one can extend available lock factories (for example IPC locking).
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.String}
Expand All @@ -65,8 +66,8 @@ public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapt
public static final String CONFIG_PROP_FACTORY_KEY = NamedLockFactoryAdapter.CONFIG_PROPS_PREFIX + "factory";

/**
* Name of the name mapper to use in session. Out of the box supported ones are "static", "gav", "file-gav",
* "file-hgav", "file-static" and "discriminating".
* Name of the name mapper to use in session. Out of the box supported ones are "static", "gav", "gaecv", "file-gav",
* "file-gaecv", "file-hgav", "file-hgaecv", "file-static" and "discriminating".
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.String}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.
*/
package org.eclipse.aether.internal.impl.synccontext.named.providers;

import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;

/**
* The "file-gaecv" name mapper provider.
*
* @since 1.9.25
*/
@Singleton
@Named(NameMappers.FILE_GAECV_NAME)
public class FileGAECVNameMapperProvider implements Provider<NameMapper> {
private final NameMapper mapper;

public FileGAECVNameMapperProvider() {
this.mapper = NameMappers.fileGaecvNameMapper();
}

@Override
public NameMapper get() {
return mapper;
}
}
Loading