Skip to content

Commit

Permalink
[MNG-7856] Maven Resolver Provider ctor and other minor code changes (#…
Browse files Browse the repository at this point in the history
…1223)

Maven Resolver Provider gets similar change as other Resolver components had in MRESOLVER-386.

Also, some minor code updates like adding Override and other cosmetic stuff.

Forward port of 1ac8be5

---

https://issues.apache.org/jira/browse/MNG-7856
  • Loading branch information
cstamas committed Sep 5, 2023
1 parent 64b32c0 commit 9dd7b01
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

/**
* Populates Aether {@link ArtifactDescriptorResult} from Maven project {@link Model}.
*
* <p/>
* <strong>Note:</strong> This class is part of work in progress and can be changed or removed without notice.
* @since 3.2.4
*/
Expand Down Expand Up @@ -95,8 +95,8 @@ private Dependency convert(org.apache.maven.model.Dependency dependency, Artifac
stereotype = new DefaultArtifactType(dependency.getType());
}

boolean system =
dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0;
boolean system = dependency.getSystemPath() != null
&& !dependency.getSystemPath().isEmpty();

Map<String, String> props = null;
if (system) {
Expand Down Expand Up @@ -134,7 +134,7 @@ private void setArtifactProperties(ArtifactDescriptorResult result, Model model)
if (distMgmt != null) {
downloadUrl = distMgmt.getDownloadUrl();
}
if (downloadUrl != null && downloadUrl.length() > 0) {
if (downloadUrl != null && !downloadUrl.isEmpty()) {
Artifact artifact = result.getArtifact();
Map<String, String> props = new HashMap<>(artifact.getProperties());
props.put(ArtifactProperties.DOWNLOAD_URL, downloadUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ArtifactDescriptorUtils {
public static Artifact toPomArtifact(Artifact artifact) {
Artifact pomArtifact = artifact;

if (pomArtifact.getClassifier().length() > 0 || !"pom".equals(pomArtifact.getExtension())) {
if (!pomArtifact.getClassifier().isEmpty() || !"pom".equals(pomArtifact.getExtension())) {
pomArtifact =
new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public DefaultArtifactDescriptorReader(
this.modelCacheFactory = Objects.requireNonNull(modelCacheFactory, "modelCacheFactory cannot be null");
}

@Override
public ArtifactDescriptorResult readArtifactDescriptor(
RepositorySystemSession session, ArtifactDescriptorRequest request) throws ArtifactDescriptorException {
ArtifactDescriptorResult result = new ArtifactDescriptorResult(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ public void put(Source path, String tag, Object data) {
put(new SourceCacheKey(path, tag), data);
}

@Override
public Object get(String groupId, String artifactId, String version, String tag) {
return get(new GavCacheKey(groupId, artifactId, version, tag));
}

@Override
public void put(String groupId, String artifactId, String version, String tag, Object data) {
put(new GavCacheKey(groupId, artifactId, version, tag), data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public DefaultVersionRangeResolver(
this.versionScheme = Objects.requireNonNull(versionScheme, "versionScheme cannot be null");
}

@Override
public VersionRangeResult resolveVersionRange(RepositorySystemSession session, VersionRangeRequest request)
throws VersionRangeResolutionException {
VersionRangeResult result = new VersionRangeResult(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public DefaultVersionResolver(
}

@SuppressWarnings("checkstyle:methodlength")
@Override
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request)
throws VersionResolutionException {
RequestTrace trace = RequestTrace.newChild(request.getTrace(), request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void bind(Artifact artifact) {
artifacts.add(artifact);
}

@Override
public MavenMetadata setFile(File file) {
return new LocalSnapshotMetadata(metadata, file, timestamp);
}
Expand Down Expand Up @@ -113,18 +114,22 @@ private String getKey(String classifier, String extension) {
return classifier + ':' + extension;
}

@Override
public String getGroupId() {
return metadata.getGroupId();
}

@Override
public String getArtifactId() {
return metadata.getArtifactId();
}

@Override
public String getVersion() {
return metadata.getVersion();
}

@Override
public Nature getNature() {
return Nature.SNAPSHOT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class LocalSnapshotMetadataGenerator implements MetadataGenerator {
snapshots = new LinkedHashMap<>();
}

@Override
public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
for (Artifact artifact : artifacts) {
if (artifact.isSnapshot()) {
Expand All @@ -64,10 +65,12 @@ public Collection<? extends Metadata> prepare(Collection<? extends Artifact> art
return Collections.emptyList();
}

@Override
public Artifact transformArtifact(Artifact artifact) {
return artifact;
}

@Override
public Collection<? extends Metadata> finish(Collection<? extends Artifact> artifacts) {
return snapshots.values();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ protected MavenMetadata(Metadata metadata, File file, Date timestamp) {
this.timestamp = timestamp;
}

@Override
public String getType() {
return MAVEN_METADATA_XML;
}

@Override
public File getFile() {
return file;
}

@Override
public void merge(File existing, File result) throws RepositoryException {
Metadata recessive = read(existing);

Expand All @@ -75,6 +78,7 @@ public void merge(File existing, File result) throws RepositoryException {
merged = true;
}

@Override
public boolean isMerged() {
return merged;
}
Expand Down Expand Up @@ -102,6 +106,7 @@ private void write(File metadataFile, Metadata metadata) throws RepositoryExcept
}
}

@Override
public Map<String, String> getProperties() {
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/**
* MavenResolverModule
*/
@Deprecated
public final class MavenResolverModule extends AbstractModule {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,22 @@ protected String getKey(String classifier, String extension) {
return classifier + ':' + extension;
}

@Override
public String getGroupId() {
return metadata.getGroupId();
}

@Override
public String getArtifactId() {
return metadata.getArtifactId();
}

@Override
public String getVersion() {
return metadata.getVersion();
}

@Override
public Nature getNature() {
return Nature.SNAPSHOT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class RelocatedArtifact extends AbstractArtifact {
this.message = (message != null && message.length() > 0) ? message : null;
}

@Override
public String getGroupId() {
if (groupId != null) {
return groupId;
Expand All @@ -57,6 +58,7 @@ public String getGroupId() {
}
}

@Override
public String getArtifactId() {
if (artifactId != null) {
return artifactId;
Expand All @@ -65,6 +67,7 @@ public String getArtifactId() {
}
}

@Override
public String getVersion() {
if (version != null) {
return version;
Expand Down Expand Up @@ -101,22 +104,27 @@ public Artifact setProperties(Map<String, String> properties) {
return new RelocatedArtifact(artifact.setProperties(properties), groupId, artifactId, version, message);
}

@Override
public String getClassifier() {
return artifact.getClassifier();
}

@Override
public String getExtension() {
return artifact.getExtension();
}

@Override
public File getFile() {
return artifact.getFile();
}

@Override
public String getProperty(String key, String defaultValue) {
return artifact.getProperty(key, defaultValue);
}

@Override
public Map<String, String> getProperties() {
return artifact.getProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private RemoteSnapshotMetadata(Metadata metadata, File file, Date timestamp) {
super(metadata, file, timestamp);
}

@Override
public MavenMetadata setFile(File file) {
return new RemoteSnapshotMetadata(metadata, file, timestamp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class RemoteSnapshotMetadataGenerator implements MetadataGenerator {
}
}

@Override
public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
for (Artifact artifact : artifacts) {
if (artifact.isSnapshot()) {
Expand All @@ -77,6 +78,7 @@ public Collection<? extends Metadata> prepare(Collection<? extends Artifact> art
return snapshots.values();
}

@Override
public Artifact transformArtifact(Artifact artifact) {
if (artifact.isSnapshot() && artifact.getVersion().equals(artifact.getBaseVersion())) {
Object key = RemoteSnapshotMetadata.getKey(artifact);
Expand All @@ -89,6 +91,7 @@ public Artifact transformArtifact(Artifact artifact) {
return artifact;
}

@Override
public Collection<? extends Metadata> finish(Collection<? extends Artifact> artifacts) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,27 @@ public static Object getKey(Artifact artifact) {
return artifact.getGroupId() + ':' + artifact.getArtifactId();
}

@Override
public MavenMetadata setFile(File file) {
return new VersionsMetadata(artifact, file, timestamp);
}

@Override
public String getGroupId() {
return artifact.getGroupId();
}

@Override
public String getArtifactId() {
return artifact.getArtifactId();
}

@Override
public String getVersion() {
return "";
}

@Override
public Nature getNature() {
return artifact.isSnapshot() ? Nature.RELEASE_OR_SNAPSHOT : Nature.RELEASE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
*/
class VersionsMetadataGenerator implements MetadataGenerator {

private Map<Object, VersionsMetadata> versions;
private final Map<Object, VersionsMetadata> versions;

private Map<Object, VersionsMetadata> processedVersions;
private final Map<Object, VersionsMetadata> processedVersions;

private final Date timestamp;

Expand Down Expand Up @@ -75,14 +75,17 @@ private VersionsMetadataGenerator(RepositorySystemSession session, Collection<?
}
}

@Override
public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
return Collections.emptyList();
}

@Override
public Artifact transformArtifact(Artifact artifact) {
return artifact;
}

@Override
public Collection<? extends Metadata> finish(Collection<? extends Artifact> artifacts) {
for (Artifact artifact : artifacts) {
Object key = VersionsMetadata.getKey(artifact);
Expand Down

0 comments on commit 9dd7b01

Please sign in to comment.