Skip to content

Commit

Permalink
Change PlatformArtifactFactory to only emit classifier strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ascopes committed Apr 6, 2024
1 parent b786eff commit ec1e66a
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
public final class BinaryPluginResolver {

private final MavenDependencyPathResolver dependencyResolver;
private final PlatformArtifactFactory platformDependencyFactory;
private final PlatformClassifierFactory platformClassifierFactory;
private final SystemPathBinaryResolver systemPathResolver;
private final UrlResourceFetcher urlResourceFetcher;

@Inject
public BinaryPluginResolver(
MavenDependencyPathResolver dependencyResolver,
PlatformArtifactFactory platformDependencyFactory,
PlatformClassifierFactory platformClassifierFactory,
SystemPathBinaryResolver systemPathResolver,
UrlResourceFetcher urlResourceFetcher
) {
this.dependencyResolver = dependencyResolver;
this.platformDependencyFactory = platformDependencyFactory;
this.platformClassifierFactory = platformClassifierFactory;
this.systemPathResolver = systemPathResolver;
this.urlResourceFetcher = urlResourceFetcher;
}
Expand Down Expand Up @@ -78,13 +78,10 @@ private ResolvedPlugin resolveMavenPlugin(
MavenSession session,
MavenArtifact plugin
) throws ResolutionException {
plugin = platformDependencyFactory.createArtifact(
plugin.getGroupId().orElse(null),
plugin.getArtifactId().orElse(null),
plugin.getVersion().orElse(null),
plugin.getType().orElse("exe"),
plugin.getClassifier().orElse(null)
);
var artifactId = plugin.getArtifactId().orElse(null);
var classifier = plugin.getClassifier()
.orElseGet(() -> platformClassifierFactory.getClassifier(artifactId));
plugin.setClassifier(classifier);

// Only one dependency should ever be returned here.
var path = dependencyResolver.resolveOne(session, plugin, DependencyResolutionDepth.DIRECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,26 @@

package io.github.ascopes.protobufmavenplugin.dependency;

import static java.util.Objects.requireNonNullElse;
import static java.util.Objects.requireNonNullElseGet;

import io.github.ascopes.protobufmavenplugin.MavenArtifact;
import io.github.ascopes.protobufmavenplugin.platform.HostSystem;
import javax.inject.Inject;
import javax.inject.Named;
import org.jspecify.annotations.Nullable;

/**
* Factory that can produce dependencies marked with platform-specific classifiers.
* Factory that can produce classifiers for dependencies based on the current platform.
*
* @author Ashley Scopes
*/
@Named
public final class PlatformArtifactFactory {
public final class PlatformClassifierFactory {

private final HostSystem hostSystem;

@Inject
public PlatformArtifactFactory(HostSystem hostSystem) {
public PlatformClassifierFactory(HostSystem hostSystem) {
this.hostSystem = hostSystem;
}

public MavenArtifact createArtifact(
String groupId,
String artifactId,
String version,
@Nullable String extension,
@Nullable String classifier
) {
var artifact = new MavenArtifact();
artifact.setGroupId(groupId);
artifact.setArtifactId(artifactId);
artifact.setVersion(version);
artifact.setType(requireNonNullElse(extension, "exe"));
artifact.setClassifier(requireNonNullElseGet(
classifier,
() -> getPlatformExecutableClassifier(artifactId)
));
return artifact;
}

private String getPlatformExecutableClassifier(String artifactId) {
public String getClassifier(String artifactId) {
var rawOs = hostSystem.getOperatingSystem();
var rawArch = hostSystem.getCpuArchitecture();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.github.ascopes.protobufmavenplugin.dependency;

import io.github.ascopes.protobufmavenplugin.DependencyResolutionDepth;
import io.github.ascopes.protobufmavenplugin.MavenArtifact;
import io.github.ascopes.protobufmavenplugin.platform.FileUtils;
import io.github.ascopes.protobufmavenplugin.platform.HostSystem;
import java.io.IOException;
Expand Down Expand Up @@ -44,21 +45,21 @@ public final class ProtocResolver {

private final HostSystem hostSystem;
private final MavenDependencyPathResolver dependencyResolver;
private final PlatformArtifactFactory platformArtifactFactory;
private final PlatformClassifierFactory platformClassifierFactory;
private final SystemPathBinaryResolver systemPathResolver;
private final UrlResourceFetcher urlResourceFetcher;

@Inject
public ProtocResolver(
HostSystem hostSystem,
MavenDependencyPathResolver dependencyResolver,
PlatformArtifactFactory platformArtifactFactory,
PlatformClassifierFactory platformClassifierFactory,
SystemPathBinaryResolver systemPathResolver,
UrlResourceFetcher urlResourceFetcher
) {
this.hostSystem = hostSystem;
this.dependencyResolver = dependencyResolver;
this.platformArtifactFactory = platformArtifactFactory;
this.platformClassifierFactory = platformClassifierFactory;
this.systemPathResolver = systemPathResolver;
this.urlResourceFetcher = urlResourceFetcher;
}
Expand Down Expand Up @@ -107,13 +108,12 @@ private Path resolveFromMavenRepositories(
);
}

var artifact = platformArtifactFactory.createArtifact(
GROUP_ID,
ARTIFACT_ID,
version,
null,
null
);
var artifact = new MavenArtifact();
artifact.setGroupId(GROUP_ID);
artifact.setArtifactId(ARTIFACT_ID);
artifact.setVersion(version);
artifact.setType("exe");
artifact.setClassifier(platformClassifierFactory.getClassifier(ARTIFACT_ID));

return dependencyResolver.resolveOne(session, artifact, DependencyResolutionDepth.DIRECT)
.iterator()
Expand Down

This file was deleted.

Loading

0 comments on commit ec1e66a

Please sign in to comment.