-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
123 additions
and
97 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
ljprojectbuilder/generator/src/main/java/de/starwit/generator/services/Git.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package de.starwit.generator.services; | ||
|
||
import org.apache.log4j.Logger; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
/** Class for running git commands. */ | ||
public class Git { | ||
|
||
private final static Logger LOG = Logger.getLogger("Git"); | ||
|
||
public static void gitInit(Path directory) throws IOException, InterruptedException { | ||
runCommand(directory, "git", "init"); | ||
} | ||
|
||
public static void gitStage(Path directory) throws IOException, InterruptedException { | ||
runCommand(directory, "git", "add", "-A"); | ||
} | ||
|
||
public static void gitCommit(Path directory, String message) throws IOException, InterruptedException { | ||
runCommand(directory, "git", "commit", "-m", message); | ||
} | ||
|
||
public static void gitPush(Path directory) throws IOException, InterruptedException { | ||
runCommand(directory, "git", "push"); | ||
} | ||
|
||
public static void gitClone(Path directory, String originUrl) throws IOException, InterruptedException { | ||
runCommand(directory, "git", "clone", originUrl); | ||
} | ||
|
||
public static void gitClone(Path directory, String originUrl, String branch) throws IOException, InterruptedException { | ||
runCommand(directory, "git", "clone", "-b", branch, originUrl); | ||
} | ||
|
||
public static void runCommand(Path directory, String... command) throws IOException, InterruptedException { | ||
Objects.requireNonNull(directory, "directory"); | ||
if (!Files.exists(directory)) { | ||
throw new RuntimeException("can't run command in non-existing directory '" + directory + "'"); | ||
} | ||
ProcessBuilder pb = new ProcessBuilder() | ||
.command(command) | ||
.directory(directory.toFile()); | ||
Process p = pb.start(); | ||
int exitVal = p.waitFor(); | ||
|
||
if (exitVal == 0) { | ||
LOG.info("git commad SUCCESS in directory " + directory.toFile().toString()); | ||
} else { | ||
p.destroy(); | ||
throw new RuntimeException("Process ends with errors."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters