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.

---

https://issues.apache.org/jira/browse/MNG-7856
  • Loading branch information
cstamas committed Sep 5, 2023
1 parent c482de8 commit 1ac8be5
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 9 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 @@ -96,7 +96,7 @@ private Dependency convert(org.apache.maven.model.Dependency dependency, Artifac
}

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

Map<String, String> props = null;
if (system) {
Expand Down Expand Up @@ -136,7 +136,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 @@ -35,7 +35,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 @@ -91,12 +91,13 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
private final ArtifactDescriptorReaderDelegate artifactDescriptorReaderDelegate =
new ArtifactDescriptorReaderDelegate();

@Deprecated
public DefaultArtifactDescriptorReader() {
// enable no-arg constructor
}

@Inject
DefaultArtifactDescriptorReader(
public DefaultArtifactDescriptorReader(
RemoteRepositoryManager remoteRepositoryManager,
VersionResolver versionResolver,
VersionRangeResolver versionRangeResolver,
Expand All @@ -113,6 +114,7 @@ public DefaultArtifactDescriptorReader() {
setModelCacheFactory(modelCacheFactory);
}

@Deprecated
public void initService(ServiceLocator locator) {
setRemoteRepositoryManager(locator.getService(RemoteRepositoryManager.class));
setVersionResolver(locator.getService(VersionResolver.class));
Expand Down Expand Up @@ -165,6 +167,7 @@ public DefaultArtifactDescriptorReader setModelCacheFactory(ModelCacheFactory mo
return this;
}

@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 @@ -46,10 +46,12 @@ private DefaultModelCache(RepositorySystemSession session) {
this.cache = session.getCache();
}

@Override
public Object get(String groupId, String artifactId, String version, String tag) {
return cache.get(session, new Key(groupId, artifactId, version, tag));
}

@Override
public void put(String groupId, String artifactId, String version, String tag, Object data) {
cache.put(session, new Key(groupId, artifactId, version, tag), data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public class DefaultVersionRangeResolver implements VersionRangeResolver, Servic

private RepositoryEventDispatcher repositoryEventDispatcher;

@Deprecated
public DefaultVersionRangeResolver() {
// enable default constructor
}

@Inject
DefaultVersionRangeResolver(
public DefaultVersionRangeResolver(
MetadataResolver metadataResolver,
SyncContextFactory syncContextFactory,
RepositoryEventDispatcher repositoryEventDispatcher) {
Expand All @@ -91,6 +92,7 @@ public DefaultVersionRangeResolver() {
setRepositoryEventDispatcher(repositoryEventDispatcher);
}

@Deprecated
public void initService(ServiceLocator locator) {
setMetadataResolver(locator.getService(MetadataResolver.class));
setSyncContextFactory(locator.getService(SyncContextFactory.class));
Expand All @@ -114,6 +116,7 @@ public DefaultVersionRangeResolver setRepositoryEventDispatcher(
return this;
}

@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 @@ -86,12 +86,13 @@ public class DefaultVersionResolver implements VersionResolver, Service {

private RepositoryEventDispatcher repositoryEventDispatcher;

@Deprecated
public DefaultVersionResolver() {
// enable no-arg constructor
}

@Inject
DefaultVersionResolver(
public DefaultVersionResolver(
MetadataResolver metadataResolver,
SyncContextFactory syncContextFactory,
RepositoryEventDispatcher repositoryEventDispatcher) {
Expand All @@ -100,6 +101,7 @@ public DefaultVersionResolver() {
setRepositoryEventDispatcher(repositoryEventDispatcher);
}

@Deprecated
public void initService(ServiceLocator locator) {
setMetadataResolver(locator.getService(MetadataResolver.class));
setSyncContextFactory(locator.getService(SyncContextFactory.class));
Expand All @@ -123,6 +125,7 @@ public DefaultVersionResolver setRepositoryEventDispatcher(RepositoryEventDispat
}

@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 @@ -73,6 +73,7 @@ public void bind(Artifact artifact) {
artifacts.add(artifact);
}

@Override
public MavenMetadata setFile(File file) {
return new LocalSnapshotMetadata(metadata, file, legacyFormat, timestamp);
}
Expand Down Expand Up @@ -123,18 +124,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 @@ -52,6 +52,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 @@ -68,10 +69,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 @@ -104,6 +108,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 @@ -39,6 +39,7 @@
/**
* MavenResolverModule
*/
@Deprecated
public final class MavenResolverModule extends AbstractModule {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,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, boolean legacyForma
super(metadata, file, legacyFormat, timestamp);
}

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

@Override
public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
for (Artifact artifact : artifacts) {
if (artifact.isSnapshot()) {
Expand All @@ -81,6 +82,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 @@ -93,6 +95,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
Loading

0 comments on commit 1ac8be5

Please sign in to comment.