Skip to content

Commit

Permalink
rework push goal
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwarz-eitco-de committed Jun 7, 2024
1 parent 9d6e814 commit 013a957
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/main/java/de/eitco/cicd/dotnet/AbstractDotnetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ public abstract class AbstractDotnetMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.directory}")
protected File targetDirectory;

@Parameter(defaultValue = "${project.version}")
protected String projectVersion;

@Parameter
protected String assemblyVersion;

@Parameter(defaultValue = "${project.organization.name}")
protected String vendor;

@Parameter
protected Map<String, String> nugetSources = Map.of();

@Parameter(defaultValue = "${settings}", readonly = true)
protected Settings settings;

@Component(hint = "dotnet-security")
private SecDispatcher securityDispatcher;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/eitco/cicd/dotnet/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class BuildMojo extends AbstractDotnetMojo {
@Override
public void execute() throws MojoExecutionException {

newExecutor().build();
newExecutor().build(projectVersion, assemblyVersion, vendor);
}
}
35 changes: 30 additions & 5 deletions src/main/java/de/eitco/cicd/dotnet/DotnetExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,47 @@ private List<String> buildCommand(List<String> parameters) {
return command;
}

public void build() throws MojoExecutionException {
private void retry(int times, String... parameters) throws MojoExecutionException {

int returnCode = execute(defaultOptions().ignoreResult(), List.of("build"), Set.of());
retry(times, List.of(parameters));
}

private void retry(int times, List<String> parameters) throws MojoExecutionException {

for (int index = 0; index < times; index++) {

if (returnCode != 0) {
int returnCode = execute(defaultOptions().ignoreResult(), parameters, Set.of());

execute("build");
if (returnCode == 0) {

return;
}
}

execute(defaultOptions(), parameters, Set.of());
}

public void build(String version, String assemblyVersion, String vendor) throws MojoExecutionException {

List<String> parameters = new ArrayList<>(List.of("build", "-p:Version=" + version));

if (assemblyVersion != null) {
parameters.add("-p:AssemblyVersion=" + assemblyVersion);
}

if (vendor != null) {
parameters.add("-p:Company=" + vendor);
}

retry(1, parameters);
}

public void pack(String version, String vendor, String description, String repositoryUrl) throws MojoExecutionException {

List<String> parameters = new ArrayList<>(List.of(
"pack",
"--no-build",
"-p:PackageVersion=" + version
"-p:Version=" + version
));

if (vendor != null) {
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/de/eitco/cicd/dotnet/PackMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
@Mojo(name = "pack", defaultPhase = LifecyclePhase.PACKAGE)
public class PackMojo extends AbstractDotnetMojo {

@Parameter(defaultValue = "${project.version}")
private String projectVersion;

@Parameter(defaultValue = "${project.organization.name}")
private String vendor;

@Parameter(defaultValue = "${project.description}")
private String description;

Expand Down

0 comments on commit 013a957

Please sign in to comment.