Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#54 skip mojo execution if project packaging is not habushu #55

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
Expand All @@ -28,6 +30,13 @@ public abstract class AbstractHabushuMojo extends AbstractMojo {
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
protected Settings settings;

/**
* The packaging type of the current Maven project. If it is not "habushu", then habushu packaging-related mojos
* will skip execution.
*/
@Parameter(defaultValue = "${project.packaging}", readonly = true, required = true)
protected String packaging;

/**
* Folder in which Python source files are located - should align with Poetry's
* project structure conventions.
Expand Down Expand Up @@ -130,6 +139,17 @@ public abstract class AbstractHabushuMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "habushu.rewriteLocalPathDepsInArchives")
protected boolean rewriteLocalPathDepsInArchives;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if ("habushu".equals(packaging)) {
doExecute();
} else {
getLog().info("Skipping execution - packaging type is not 'habushu'");
}
}

protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;

/**
* Gets the canonical path for a file without having to deal w/ checked
* exceptions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class BehaveBddTestMojo extends AbstractHabushuMojo {
protected boolean skipTests;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {

if (skipTests) {
getLog().warn("Tests are skipped (-DskipTests=true)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class BuildDeploymentArtifactsMojo extends AbstractHabushuMojo {
protected File mavenArtifactFile;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {
PoetryCommandHelper poetryHelper = createPoetryCommandHelper();

String buildCommand, buildLogMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class CleanHabushuMojo extends CleanMojo {
@Parameter(defaultValue = "${project.basedir}/target", readonly = true, required = true)
protected File targetDirectory;

/**
* The packaging type of the current Maven project. If it is not "habushu", then this mojo will be skipped.
*/
@Parameter(defaultValue = "${project.packaging}", readonly = true, required = true)
protected String packaging;

/**
* Enables the explicit deletion of the virtual environment that is
* created/managed by Poetry.
Expand Down Expand Up @@ -93,7 +99,14 @@ public class CleanHabushuMojo extends CleanMojo {

@Override
public void execute() throws MojoExecutionException {
if ("habushu".equals(packaging)) {
clean();
} else {
getLog().info("Skipping execution - packaging type is not 'habushu'");
}
}

private void clean() throws MojoExecutionException {
if (deleteVirtualEnv) {
try {
PyenvAndPoetrySetup configureTools = new PyenvAndPoetrySetup(pythonVersion, usePyenv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class FormatPythonMojo extends AbstractHabushuMojo {
protected static final String BLACK_PACKAGE = "black";

@Override
public void execute() throws MojoExecutionException {
public void doExecute() throws MojoExecutionException {

List<String> directoriesToFormat = new ArrayList<>();
if (this.sourceDirectory.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class InitializeHabushuMojo extends AbstractHabushuMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {

getLog().info("Validating Poetry-based project structure...");
PoetryCommandHelper poetryHelper = createPoetryCommandHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class InstallDependenciesMojo extends AbstractHabushuMojo {
protected boolean failOnManagedDependenciesMismatches;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {
PoetryCommandHelper poetryHelper = createPoetryCommandHelper();

processManagedDependencyMismatches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class PublishToPyPiRepoMojo extends AbstractHabushuMojo {
protected boolean skipDeploy;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {
if (this.skipDeploy) {
getLog().info(String.format(
"Skipping deploy phase - package for %s will not be published to the configured PyPI repository",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RunCommandInVirtualEnvMojo extends AbstractHabushuMojo {
protected String runCommandArgs;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {
PoetryCommandHelper poetryHelper = createPoetryCommandHelper();
List<String> poetryRunCommandArgs = new ArrayList<>(Arrays.asList(StringUtils.split(runCommandArgs)));
poetryRunCommandArgs.add(0, "run");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ValidatePyenvAndPoetryMojo extends AbstractHabushuMojo {
private File patchInstallScript;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {
PyenvAndPoetrySetup configureTools = new PyenvAndPoetrySetup(pythonVersion, usePyenv,
patchInstallScript, getPoetryProjectBaseDir(), rewriteLocalPathDepsInArchives, getLog());
configureTools.execute();
Expand Down
Loading