Skip to content

Commit

Permalink
Rename SessionStub to SessionMock and add a real SessionStub
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 18, 2024
1 parent 07b5181 commit 74af24a
Show file tree
Hide file tree
Showing 6 changed files with 799 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class Foo {
@Singleton
@Priority(-10)
private InternalSession createSession() {
return SessionStub.getMockSession(getBasedir());
return SessionMock.getMockSession(getBasedir());
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.PluginContainer;
import org.apache.maven.internal.impl.DefaultVersionParser;
import org.apache.maven.repository.internal.DefaultModelVersionParser;
import org.eclipse.aether.util.version.GenericVersionScheme;

/**
* @author Olivier Lamy
Expand Down Expand Up @@ -156,10 +153,6 @@ public Path getBasedir() {
return basedir;
}

public void setBasedir(Path basedir) {
this.basedir = basedir;
}

@Override
public Optional<Project> getParent() {
return Optional.empty();
Expand All @@ -180,90 +173,74 @@ public Path getRootDirectory() {
return rootDirectory;
}

public void setGroupId(String groupId) {
//
// Setters
//

public ProjectStub setBasedir(Path basedir) {
this.basedir = basedir;
return this;
}

public ProjectStub setGroupId(String groupId) {
model = model.withGroupId(groupId);
return this;
}

public void setArtifactId(String artifactId) {
public ProjectStub setArtifactId(String artifactId) {
model = model.withArtifactId(artifactId);
return this;
}

public void setVersion(String version) {
public ProjectStub setVersion(String version) {
model = model.withVersion(version);
return this;
}

public void setName(String name) {
public ProjectStub setName(String name) {
model = model.withName(name);
return this;
}

public ProjectStub setDescription(String desc) {
model = model.withDescription(desc);
return this;
}

public void setPackaging(String packaging) {
public ProjectStub setPackaging(String packaging) {
model = model.withPackaging(packaging);
return this;
}

public void setMainArtifact(Artifact mainArtifact) {
public ProjectStub setMainArtifact(Artifact mainArtifact) {
this.mainArtifact = mainArtifact;
return this;
}

public void setPomPath(Path pomPath) {
public ProjectStub setPomPath(Path pomPath) {
this.pomPath = pomPath;
return this;
}

public void setTopProject(boolean topProject) {
public ProjectStub setTopProject(boolean topProject) {
this.topProject = topProject;
return this;
}

public void setMavenModel(org.apache.maven.model.Model model) {
public ProjectStub setMavenModel(org.apache.maven.model.Model model) {
this.model = model.getDelegate();
return this;
}

public void setRootDirectory(Path rootDirectory) {
public ProjectStub setRootDirectory(Path rootDirectory) {
this.rootDirectory = rootDirectory;
return this;
}

public void addProperty(String key, String value) {
properties.put(key, value);
}

class ProjectArtifact implements Artifact {
@Override
public String getGroupId() {
return ProjectStub.this.getGroupId();
}

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

@Override
public Version getVersion() {
return new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme()))
.parseVersion(ProjectStub.this.getVersion());
}

@Override
public Version getBaseVersion() {
return null;
}

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

@Override
public String getExtension() {
return "pom";
}

@Override
public boolean isSnapshot() {
return false;
}

@Override
public ArtifactCoordinate toCoordinate() {
return null;
}
public ProjectStub addProperty(String key, String value) {
Map<String, String> props = new HashMap<>(model.getProperties());
props.put(key, value);
model = model.withProperties(props);
return this;
}
}
Loading

0 comments on commit 74af24a

Please sign in to comment.