View Javadoc
1   /*
2    *    Copyright 2011-2026 the original author or authors.
3    *
4    *    This program is free software; you can redistribute it and/or
5    *    modify it under the terms of the GNU General Public License
6    *    as published by the Free Software Foundation; either version 2
7    *    of the License, or (at your option) any later version.
8    *
9    *    You may obtain a copy of the License at
10   *
11   *       https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
12   *
13   *    This program is distributed in the hope that it will be useful,
14   *    but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   *    GNU General Public License for more details.
17   */
18  package com.hazendaz.maven.makeself;
19  
20  import java.nio.file.Files;
21  import java.nio.file.Path;
22  
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugin.MojoFailureException;
25  import org.apache.maven.plugins.annotations.LifecyclePhase;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  
29  /**
30   * The Class GitMojo.
31   * <p>
32   * Downloads and installs portable Git on Windows from the Maven repository. This goal can be used standalone in any
33   * Maven project (or without a project) to obtain a secure, vetted copy of portable Git without needing to use a browser
34   * or locate the artifact in the local Maven repository manually.
35   * </p>
36   * <p>
37   * On non-Windows systems this goal is a no-op since makeself and bash are natively available.
38   * </p>
39   */
40  @Mojo(name = "git", defaultPhase = LifecyclePhase.NONE, requiresProject = false)
41  public class GitMojo extends AbstractGitMojo {
42  
43      /** Skip run of plugin. */
44      @Parameter(defaultValue = "false", property = "makeself.skip")
45      private boolean skip;
46  
47      @Override
48      public void execute() throws MojoExecutionException, MojoFailureException {
49          // Ensure gitPath is never null
50          if (this.gitPath == null) {
51              this.gitPath = "";
52          }
53  
54          // Check if plugin run should be skipped
55          if (this.skip) {
56              this.getLog().info("Makeself git is skipped");
57              return;
58          }
59  
60          if (!this.isWindows()) {
61              this.getLog().info("Portable git is only applicable on Windows; skipping on this platform");
62              return;
63          }
64  
65          // Use existing git if a valid path was provided
66          if (!this.gitPath.isEmpty() && Files.exists(Path.of(this.gitPath))) {
67              this.getLog().info("Using existing 'Git' found at " + this.gitPath);
68              this.gitPath = this.gitPath + AbstractGitMojo.GIT_USER_BIN;
69          } else {
70              // Download and install portable git
71              this.checkGitSetup();
72          }
73  
74          this.getLog().info("Portable git is available at: " + this.gitPath);
75      }
76  
77  }