Skip to content

Commit

Permalink
Merge pull request #32 from Canoobi/add-pipeline
Browse files Browse the repository at this point in the history
add pipeline with formatter and pitest builder
  • Loading branch information
TOH01 authored Jun 10, 2024
2 parents f75b504 + 5dcfff5 commit a011716
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 103 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Google-Code-Format

on:
[push]

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'oracle'
cache: maven
- uses: axel-op/googlejavaformat-action@v3
with:
args: "--skip-sorting-imports --replace"

build-pitest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'oracle'
cache: maven
- name: Generate Pitest Report
run: mvn test-compile org.pitest:pitest-maven:mutationCoverage --file pom.xml
- name: Upload Pitest Report
uses: actions/upload-artifact@v2
with:
name: pitest-report
path: target/pit-reports/
- name: Deploy to GitHub Pages
if: success()
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git fetch origin +refs/heads/gh-pages:refs/remotes/origin/gh-pages || git checkout --orphan gh-pages
git checkout gh-pages
mkdir -p main
cp -r target/pit-reports/* main/
git add main
git commit -m "Update mutation coverage report: ${{ github.event.head_commit.message }}"
git push origin gh-pages
166 changes: 84 additions & 82 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,98 +20,100 @@

public class MavenWrapperDownloader {

private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
private static final String WRAPPER_VERSION = "0.5.6";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/** Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION
+ "/maven-wrapper-"
+ WRAPPER_VERSION
+ ".jar";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use
* instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
/** Path where the maven-wrapper.jar will be saved to. */
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '"
+ outputFile.getParentFile().getAbsolutePath()
+ "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(
new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OOP-Projekt Gruppe 7 (Schach)
# :chess_pawn: Schach-Gruppe-7 [![Static Badge](https://img.shields.io/badge/Mutation%20Coverage-8A2BE2)](https://canoobi.github.io/Schach-Gruppe-7/main/index.html)

This repository contains a student chess project created for an ongoing lecture on object-oriented programming with Java
at HWR Berlin (summer term 2024).
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hwr/oop/chess/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
public final class Cli {

private final PrintStream out;
private final ArgumentParser argumentParser;
private final ArgumentParser argumentParser;

public Cli(OutputStream outputStream, PersistanceHandler persistance) {
this.out = new PrintStream(outputStream);
this.argumentParser = new ArgumentParser(persistance);
this.argumentParser = new ArgumentParser(persistance);
}

public void handle(String... arguments) {
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/hwr/oop/chessTests/GameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void loadGameTest() {
void getWinnerTest() {
Game game = new Game(5);
game.setWinner("White");
assertSoftly(
softly -> softly.assertThat(game.getWinner()).isEqualTo("White"));
assertSoftly(softly -> softly.assertThat(game.getWinner()).isEqualTo("White"));
}

@Test
Expand Down Expand Up @@ -74,17 +73,15 @@ void movePossible() {
Game game = new Game(6);
game.getBoard().setBoardToFen(new FENString("7b/8/8/8/3P4/8/8/B7"));

assertSoftly(
softly -> softly.assertThat(game.movePossible(0, 0, 7, 7)).isFalse());
assertSoftly(softly -> softly.assertThat(game.movePossible(0, 0, 7, 7)).isFalse());
}

@Test
void movePossibleMoveIntoCheck() {
Game game = new Game(7);
game.getBoard().setBoardToFen(new FENString("r7/8/8/8/8/8/B7/K7"));

assertSoftly(
softly -> softly.assertThat(game.movePossible(0, 1, 1, 2)).isFalse());
assertSoftly(softly -> softly.assertThat(game.movePossible(0, 1, 1, 2)).isFalse());
}

@Test
Expand Down Expand Up @@ -131,7 +128,6 @@ void movePieceBlackTest() {
void movePieceFalseTest() {
Game game = new Game(6);
game.setActivePlayer(Piece.Color.BLACK);
assertSoftly(
softly -> softly.assertThat(game.movePiece(1, 1, 6, 6)).isFalse());
assertSoftly(softly -> softly.assertThat(game.movePiece(1, 1, 6, 6)).isFalse());
}
}
12 changes: 5 additions & 7 deletions src/test/java/hwr/oop/cliTests/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ void playOnGameCommandTest() {
void playOnGameCommandFail1Test() {
cli.handle("on", "game", "-3", "player", "white", "moves", "b2", "to", "b3");
final var output = outputStream.toString();
assertSoftly(
softly -> softly.assertThat(output).contains("Game with ID -3 not found!"));
assertSoftly(softly -> softly.assertThat(output).contains("Game with ID -3 not found!"));
}

@Test
Expand All @@ -134,8 +133,7 @@ void playOnGameCommandFail2Test() {
persistance.saveGame(game);
cli.handle("on", "game", "0", "player", "white", "moves", "a1", "to", "c7");
final var output = outputStream.toString();
assertSoftly(
softly -> softly.assertThat(output).contains("Move failed! Please try again."));
assertSoftly(softly -> softly.assertThat(output).contains("Move failed! Please try again."));
}

@Test
Expand All @@ -145,7 +143,8 @@ void playOnGameCommandFail3Test() {
cli.handle("on", "game", "0", "player", "white", "moves", "d4", "to", "d5");
final var output = outputStream.toString();
assertSoftly(
softly -> softly.assertThat(output).contains("No piece at position d4 found. Please try again."));
softly ->
softly.assertThat(output).contains("No piece at position d4 found. Please try again."));
}

@Test
Expand All @@ -154,8 +153,7 @@ void playOnGameCommandWrongPlayerTest() {
persistance.saveGame(game);
cli.handle("on", "game", "0", "player", "black", "moves", "b2", "to", "b3");
final var output = outputStream.toString();
assertSoftly(
softly -> softly.assertThat(output).contains("Player WHITE is playing!"));
assertSoftly(softly -> softly.assertThat(output).contains("Player WHITE is playing!"));
}

@Test
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/hwr/oop/cliTests/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ void main_CanBeCalledWithHelpCommand() {
System.out.println(mainTest);
Main.main(new String[] {"help"});
assertSoftly(
softly -> softly
.assertThat(outContent.toString())
.contains("You can use one of the following commands:"));
softly ->
softly
.assertThat(outContent.toString())
.contains("You can use one of the following commands:"));
}
}

0 comments on commit a011716

Please sign in to comment.