generated from clean-code-workshop/sigrid-training-2024
-
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
0 parents
commit 344f431
Showing
17 changed files
with
504 additions
and
0 deletions.
There are no files selected for viewing
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,32 @@ | ||
name: sigrid-publish | ||
on: | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
sigridci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Dump github context | ||
run: echo "$GITHUB_CONTEXT" | ||
shell: bash | ||
env: | ||
GITHUB_CONTEXT: ${{ toJson(github) }} | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Download Sigrid CI | ||
run: "git clone https://github.com/Software-Improvement-Group/sigridci.git sigridci" | ||
- name: "Run Sigrid CI" | ||
env: | ||
SIGRID_CI_TOKEN: "${{ secrets.SIGRID_CI_TOKEN }}" | ||
run: "./sigridci/sigridci/sigridci.py --customer sigridworkshop --system ${{ github.event.repository.name }} --source . --targetquality 3.0 --publish" | ||
- name: "Save Sigrid CI results" | ||
if: ${{ success() || failure() }} | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
path: "sigrid-ci-output/**" | ||
retention-days: 7 | ||
if-no-files-found: ignore |
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,30 @@ | ||
name: sigrid-pullrequest | ||
on: [pull_request] | ||
|
||
jobs: | ||
sigridci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Download Sigrid CI | ||
run: "git clone https://github.com/Software-Improvement-Group/sigridci.git sigridci" | ||
- name: "Run Sigrid CI" | ||
env: | ||
SIGRID_CI_TOKEN: "${{ secrets.SIGRID_CI_TOKEN }}" | ||
run: "./sigridci/sigridci/sigridci.py --customer sigridworkshop --system ${{ github.event.repository.name }} --source ." | ||
- name: "Save Sigrid CI results" | ||
if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
path: "sigrid-ci-output/**" | ||
retention-days: 7 | ||
if-no-files-found: ignore | ||
- name: "Sigrid pull request feedback" | ||
uses: mshick/add-pr-comment@v2 | ||
if: always() | ||
with: | ||
message-id: sigrid | ||
message-path: sigrid-ci-output/feedback.md |
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,13 @@ | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.classpath | ||
.project | ||
.settings | ||
.idea/ | ||
out/ |
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,40 @@ | ||
Assignments for Sigrid training 2024 | ||
========== | ||
This repository is part of the Sigrid training.<br /> | ||
You will need access to Sigrid to complete this training.<br /> | ||
If you want to use this code in a training yourself please contact us at <support@sig.eu>. | ||
|
||
About The Assignment Code | ||
----------- | ||
The training examples are code snippets from the book Building Maintainable Software: Ten Guidelines for Future-Proof Code by Joost Visser. | ||
|
||
The edition used for these examples is:<br /> | ||
The Java edition (ISBN print: 978-1-4919-5352-5, ISBN eBook: 978-1-4919-5348-8), available at the O'Reilly webshop and at Amazon. | ||
|
||
The [GitHub](https://github.com/oreillymedia/building_maintainable_software) page contains all snippets. | ||
|
||
|
||
Training preparation | ||
----------- | ||
|
||
* Sign in to GitHub (create an account if neccesary) | ||
|
||
* Use this repository as a template by clicking on the green "**Use this template**" button. | ||
|
||
[<img width="160" alt="image" src="https://user-images.githubusercontent.com/6178160/196057620-5d0acafb-b2a9-47fe-bae8-a67f7146c15f.png">](https://github.com/clean-code-workshop/sigrid-training-2024/generate) | ||
|
||
|
||
* Change the **Owner** to '**clean-code-workshop**' | ||
|
||
* Choose a **repository name** (eg. TeamName) | ||
|
||
* Choose **Public** repository. | ||
|
||
Congratulations, your repository will be analysed by Sigrid and will appear soon in the dashboard.<br /> | ||
Visit https://sigrid-says.com/sigridworkshop and log in with your Sigrid account. | ||
|
||
If you don't have a Sigrid account yet, please ask your teacher to create one for you | ||
|
||
----------- | ||
|
||
|
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,86 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>eu.sig.training</groupId> | ||
<artifactId>maintainabilitybook</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<organization> | ||
<name>Software Improvement Group</name> | ||
<url>http://www.sig.eu</url> | ||
</organization> | ||
<scm> | ||
<url>git@git.atlas.oreilly.com:oreillymedia/sig-project.git</url> | ||
</scm> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>1.10.19</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>2.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5.1</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<sourceDirectory>${basedir}/src/java</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<version>2.10</version> | ||
<configuration> | ||
<workspace>${basedir}</workspace> | ||
<workspaceCodeStylesURL>file:///${basedir}/java_eclipseformat.xml</workspaceCodeStylesURL> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.18.1</version> | ||
<configuration> | ||
<excludes> | ||
<exclude>**/v1/AccountsTest.java</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<reporting> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-pmd-plugin</artifactId> | ||
<version>3.5</version> | ||
</plugin> | ||
</plugins> | ||
</reporting> | ||
</project> |
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,15 @@ | ||
component_depth: 3 | ||
languages: | ||
- Java | ||
- Javascript | ||
|
||
dependencychecker: | ||
enabled: true | ||
blacklist: [] | ||
transitive: true | ||
|
||
architecture: | ||
enabled: true | ||
|
||
thirdpartyfindings: | ||
enabled: true |
52 changes: 52 additions & 0 deletions
52
training-assignments/src/java/eu/sig/training/ch03-complexity/flags/FlagFactory.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,52 @@ | ||
package eu.sig.training.ch03; | ||
|
||
import java.awt.Color; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class FlagFactory { | ||
|
||
// tag::getFlag[] | ||
public List<Color> getFlagColors(Nationality nationality) { | ||
List<Color> result; | ||
switch (nationality) { | ||
case DUTCH: | ||
result = Arrays.asList(Color.RED, Color.WHITE, Color.BLUE); | ||
break; | ||
case GERMAN: | ||
result = Arrays.asList(Color.BLACK, Color.RED, Color.YELLOW); | ||
break; | ||
case BELGIAN: | ||
result = Arrays.asList(Color.BLACK, Color.YELLOW, Color.RED); | ||
break; | ||
case FRENCH: | ||
result = Arrays.asList(Color.BLUE, Color.WHITE, Color.RED); | ||
break; | ||
case ITALIAN: | ||
result = Arrays.asList(Color.GREEN, Color.WHITE, Color.RED); | ||
break; | ||
case ROMANIA: | ||
result = Arrays.asList(Color.BLUE, Color.YELLOW, Color.RED); | ||
break; | ||
case IRELAND: | ||
result = Arrays.asList(Color.GREEN, Color.WHITE, Color.ORANGE); | ||
break; | ||
case HUNGARIAN: | ||
result = Arrays.asList(Color.RED, Color.WHITE, Color.GREEN); | ||
break; | ||
case BULGARIAN: | ||
result = Arrays.asList(Color.WHITE, Color.GREEN, Color.RED); | ||
break; | ||
case RUSSIA: | ||
result = Arrays.asList(Color.WHITE, Color.BLUE, Color.RED); | ||
break; | ||
case UNCLASSIFIED: | ||
default: | ||
result = Arrays.asList(Color.GRAY); | ||
break; | ||
} | ||
return result; | ||
} | ||
// end::getFlag[] | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/Accounts.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,18 @@ | ||
package eu.sig.training.ch04; | ||
|
||
public class Accounts { | ||
@SuppressWarnings("unused") | ||
public static CheckingAccount findAcctByNumber(String number) { | ||
return new CheckingAccount(); | ||
} | ||
|
||
// tag::isValid[] | ||
public static boolean isValid(String number) { | ||
int sum = 0; | ||
for (int i = 0; i < number.length(); i++) { | ||
sum = sum + (9 - i) * Character.getNumericValue(number.charAt(i)); | ||
} | ||
return sum % 11 == 0; | ||
} | ||
// end::isValid[] | ||
} |
9 changes: 9 additions & 0 deletions
9
...assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/BusinessException.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,9 @@ | ||
package eu.sig.training.ch04; | ||
|
||
public class BusinessException extends Exception { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public BusinessException(String message) { | ||
super(message); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...g-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/CheckingAccount.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,41 @@ | ||
package eu.sig.training.ch04; | ||
|
||
// tag::CheckingAccount[] | ||
public class CheckingAccount { | ||
private static final float INTEREST_PERCENTAGE = 0.01f; | ||
private Money balance = new Money(); | ||
private int transferLimit = 100; | ||
|
||
public Transfer makeTransfer(String counterAccount, Money amount) | ||
throws BusinessException { | ||
// 1. Check withdrawal limit: | ||
if (amount.greaterThan(this.transferLimit)) { | ||
throw new BusinessException("Limit exceeded!"); | ||
} | ||
// 2. Assuming result is 9-digit bank account number, validate 11-test: | ||
int sum = 0; | ||
for (int i = 0; i < counterAccount.length(); i++) { | ||
char character = counterAccount.charAt(i); | ||
int characterValue = Character.getNumericValue(character); | ||
sum = sum + (9 - i) * characterValue; | ||
} | ||
if (sum % 11 == 0) { | ||
// 3. Look up counter account and make transfer object: | ||
CheckingAccount acct = Accounts.findAcctByNumber(counterAccount); | ||
Transfer result = new Transfer(this, acct, amount); | ||
return result; | ||
} else { | ||
throw new BusinessException("Invalid account number!"); | ||
} | ||
} | ||
|
||
public void addInterest() { | ||
Money interest = balance.multiply(INTEREST_PERCENTAGE); | ||
if (interest.greaterThan(0)) { | ||
balance.add(interest); | ||
} else { | ||
balance.substract(interest); | ||
} | ||
} | ||
} | ||
// end::CheckingAccount[] |
19 changes: 19 additions & 0 deletions
19
training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/Money.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,19 @@ | ||
package eu.sig.training.ch04; | ||
|
||
public class Money { | ||
@SuppressWarnings("unused") | ||
public boolean greaterThan(int limit) { | ||
return true; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public Money multiply(float factor) { | ||
return this; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public void add(Money money) {} | ||
|
||
@SuppressWarnings("unused") | ||
public void substract(Money interest) {} | ||
} |
15 changes: 15 additions & 0 deletions
15
training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/Transfer.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,15 @@ | ||
package eu.sig.training.ch04; | ||
|
||
public class Transfer { | ||
CheckingAccount counterAccount; | ||
|
||
@SuppressWarnings("unused") | ||
public Transfer(CheckingAccount acct1, CheckingAccount acct2, Money m) {} | ||
|
||
@SuppressWarnings("unused") | ||
public Transfer(SavingsAccount acct1, CheckingAccount acct2, Money m) {} | ||
|
||
public CheckingAccount getCounterAccount() { | ||
return this.counterAccount; | ||
} | ||
} |
Oops, something went wrong.