diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/request-form.md b/.github/ISSUE_TEMPLATE/request-form.md new file mode 100644 index 0000000..391860e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/request-form.md @@ -0,0 +1,19 @@ +--- +name: Request Form +about: Request access for the services keeping this project alive. +title: "[REQUEST]: Server Access" +labels: Request +assignees: happysad- + +--- + +## Which service do you require access for? +- [ ] Jenkins CI / Pipelines +- [ ] DEV server access +- [ ] PREPROD server access +- [ ] PROD server access +- [ ] DEV database +- [ ] PROD database + +## Description +Describe why you need access to the selected service, please be as descriptive as possible. diff --git a/jenkins/scripts/deploy-dev.sh b/jenkins/scripts/deploy-dev.sh index d63e4c4..1f1f1ab 100644 --- a/jenkins/scripts/deploy-dev.sh +++ b/jenkins/scripts/deploy-dev.sh @@ -1,29 +1,45 @@ #!/usr/bin/env sh -# -# Will change this so it copies the latest build created by Jenkins -# so the DEV server won't have to rebuild an already built project. -# - -ORG_PATH="~/JavaPlebes" +get_xpath_value() { + xml=$1 + path=$2 + if [ -f "${xml}" ]; then + value=$( xpath "${xml} ${path}" 2>/dev/null | perl -pe 's/^.+?\>//; s/\<.+?$//;' ) + echo "${value}" + else + echo "Invalid xml file: ${xml}!" + exit 1 + fi +} + +ORG_PATH="${HOME}/JavaPlebes" PROJ_DIR="/TextAdventure" GIT_URL="git@github.com:javaplebes/TextAdventure.git" -if [ ! -d "$ORG_PATH" ]; then +if [ ! -d "${ORG_PATH}" ]; then echo "Organisation path does not exist. Creating..." - mkdir ORG_PATH + mkdir "${ORG_PATH}" fi -cd $ORG_PATH +cd "${ORG_PATH}" || echo "Unable to change directory to: ${ORG_PATH}. Exiting..."; exit 1 -if [ -! -d "$PROJ_DIR" ]; then +if [ ! -d "${PROJ_DIR}" ]; then echo "Project directory does not exist. Cloning latest from GitHub..." - git clone $GIT_URL $PROJ_DIR + git clone "${GIT_URL} ${PROJ_DIR}" fi -cd $PROJ_DIR +cd "${PROJ_DIR}" || echo "Unable to change directory to: ${PROJ_DIR}. Exiting..."; exit 1 echo "Pulling the latest master branch..." git pull origin master -echo "Deploy not yet implemented!" \ No newline at end of file +mvn compile +mvn test +mvn package + +# Running of JAR on server currently disabled as not sure how to present the 'frontend' of the game. +ARTIFACT_ID=$(get_xpath_value "/pom.xml" "project/artifactId") +VERSION=$(get_xpath_value "/pom.xml" "project/version") +#java -jar "/target/${ARTIFACT_ID}-${VERSION}.jar" + +echo "Deployed: ${ARTIFACT_ID}-${VERSION}" \ No newline at end of file diff --git a/jenkins/scripts/deploy-preprod.sh b/jenkins/scripts/deploy-preprod.sh new file mode 100644 index 0000000..1f1f1ab --- /dev/null +++ b/jenkins/scripts/deploy-preprod.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env sh + +get_xpath_value() { + xml=$1 + path=$2 + if [ -f "${xml}" ]; then + value=$( xpath "${xml} ${path}" 2>/dev/null | perl -pe 's/^.+?\>//; s/\<.+?$//;' ) + echo "${value}" + else + echo "Invalid xml file: ${xml}!" + exit 1 + fi +} + +ORG_PATH="${HOME}/JavaPlebes" +PROJ_DIR="/TextAdventure" +GIT_URL="git@github.com:javaplebes/TextAdventure.git" + +if [ ! -d "${ORG_PATH}" ]; then + echo "Organisation path does not exist. Creating..." + mkdir "${ORG_PATH}" +fi + +cd "${ORG_PATH}" || echo "Unable to change directory to: ${ORG_PATH}. Exiting..."; exit 1 + +if [ ! -d "${PROJ_DIR}" ]; then + echo "Project directory does not exist. Cloning latest from GitHub..." + git clone "${GIT_URL} ${PROJ_DIR}" +fi + +cd "${PROJ_DIR}" || echo "Unable to change directory to: ${PROJ_DIR}. Exiting..."; exit 1 + +echo "Pulling the latest master branch..." +git pull origin master + +mvn compile +mvn test +mvn package + +# Running of JAR on server currently disabled as not sure how to present the 'frontend' of the game. +ARTIFACT_ID=$(get_xpath_value "/pom.xml" "project/artifactId") +VERSION=$(get_xpath_value "/pom.xml" "project/version") +#java -jar "/target/${ARTIFACT_ID}-${VERSION}.jar" + +echo "Deployed: ${ARTIFACT_ID}-${VERSION}" \ No newline at end of file diff --git a/jenkins/scripts/deploy-prod.sh b/jenkins/scripts/deploy-prod.sh new file mode 100644 index 0000000..4ed1867 --- /dev/null +++ b/jenkins/scripts/deploy-prod.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env sh + +get_xpath_value() { + xml=$1 + path=$2 + if [ -f "${xml}" ]; then + value=$( xpath "${xml} ${path}" 2>/dev/null | perl -pe 's/^.+?\>//; s/\<.+?$//;' ) + echo "${value}" + else + echo "Invalid xml file: ${xml}!" + exit 1 + fi +} + +ORG_PATH="${HOME}/${PROD_ORG_PATH}" +PROJ_DIR="${PROD_PROJ_DIR}" +XML_PATH="${PROD_XML_PATH}" + +if [ ! -d "${ORG_PATH}" ]; then + echo "Organisation path does not exist. Exiting..." +fi + +cd "${ORG_PATH}" || echo "Unable to change directory to: ${ORG_PATH}. Exiting..."; exit 1 + +if [ ! -d "${PROJ_DIR}" ]; then + echo "Project directory does not exist. Exiting..."; exit 1 +fi + +cd "${PROJ_DIR}" || echo "Unable to change directory to: ${PROJ_DIR}. Exiting..."; exit 1 + +echo "Pulling the latest master branch..." +git pull origin master + +mvn compile +mvn test +mvn package + +# Running of JAR on server currently disabled as not sure how to present the 'frontend' of the game. +ARTIFACT_ID=$(get_xpath_value "${XML_PATH}" "project/artifactId") +VERSION=$(get_xpath_value "${XML_PATH}" "project/version") +#java -jar "${ARTIFACT_ID}-${VERSION}.jar" + +echo "Deployed: ${ARTIFACT_ID}-${VERSION}" \ No newline at end of file diff --git a/jenkins/scripts/deploy.sh b/jenkins/scripts/deploy.sh index 345ad58..f7136fe 100755 --- a/jenkins/scripts/deploy.sh +++ b/jenkins/scripts/deploy.sh @@ -1,8 +1,37 @@ #!/usr/bin/env sh -# Todo: Write a simple deploy script -echo "Deploy not implemented yet!" +deploy_to_env() { + if [ -z "$1" ] || [ "$1" = "DEV" ]; then + echo "Deploying to DEV environment." + ssh "${PROJ_USER}@${DEV_SERVER}" "bash -s" < deploy-dev.sh + elif [ "$1" = "PREPROD" ]; then + echo "Deploying to PREPROD environment." + ssh "${PROJ_USER}@${PREPROD_SERVER}" "bash -s" < deploy-preprod.sh + elif [ "$1" = "PROD" ]; then + echo "Deploying to PROD environment." + ssh "${PROJ_USER}@${PROD_SERVER}" "bash -s" < deploy-prod.sh + else + echo "Unknown environment." + return 1 + fi +} -echo "Running the deployment script on DEV environment..." -echo "Secrets have not yet been added." -#ssh jenkins-ci@shard-server-lon01 'bash -s' < deploy-dev.sh \ No newline at end of file +check_environment() { + if [ -z "${PROJ_USER}" ] \ + || [ -z "${DEV_SERVER}" ] \ + || [ -z "${PREPROD_SERVER}" ] \ + || [ -z "${PROD_SERVER}" ]; then + return 1 + fi +} + +if ! check_environment ; then + echo "Environment is not correctly set up. Exiting..." + exit 1 +else + if ! deploy_to_env "$@" ; then + echo "Something went wrong during deployment. Exiting..." + else + echo "Successfully deployed to server. [$1]" + fi +fi diff --git a/src/main/java/com/textadventure/Lexer.java b/src/main/java/com/textadventure/Lexer.java index 3484f7d..42cd804 100644 --- a/src/main/java/com/textadventure/Lexer.java +++ b/src/main/java/com/textadventure/Lexer.java @@ -7,44 +7,56 @@ public class Lexer { public enum TokenType { - MOVEMENT(" w | a | s | d "), WALK("walk"), RUN("run"), DIRECTION("North|South|East|West"), - WHITESPACE("[ \t\f\r\n]+"); + WALK("walk"), RUN("run"), DIRECTION("North|South|East|West"); public final String pattern; - private TokenType(String pattern) { + TokenType(String pattern) { this.pattern = pattern; } } public static ArrayList lex(String input) { // The tokens to return - ArrayList tokens = new ArrayList<>(); + ArrayList tokens = new ArrayList(); // Lexer logic begins here - StringBuffer tokenPatternsBuffer = new StringBuffer(); + StringBuilder tokenPatternsBuilder = new StringBuilder(); for (TokenType tokenType : TokenType.values()) + tokenPatternsBuilder.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); + Pattern tokenPatterns = Pattern.compile(tokenPatternsBuilder.substring(1)); + + for (String word : input.split(" ")) { + // Begin matching tokens + Matcher matcher = tokenPatterns.matcher(word); + while (matcher.find()) { + if (matcher.group(TokenType.WALK.name()) != null) { + tokens.add(new Token(TokenType.WALK, matcher.group(TokenType.WALK.name()))); + continue; + } else if (matcher.group(TokenType.RUN.name()) != null) { + tokens.add(new Token(TokenType.RUN, matcher.group(TokenType.RUN.name()))); + continue; + } else if (matcher.group(TokenType.DIRECTION.name()) != null) { + tokens.add(new Token(TokenType.DIRECTION, matcher.group(TokenType.DIRECTION.name()))); + } + } tokenPatternsBuffer.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); Pattern tokenPatterns = Pattern.compile(tokenPatternsBuffer.substring(1)); - - // Begin matching tokens - Matcher matcher = tokenPatterns.matcher(input); - while (matcher.find()) { - if (matcher.group(TokenType.MOVEMENT.name()) != null) { - tokens.add(new Token(TokenType.MOVEMENT, matcher.group(TokenType.MOVEMENT.name()))); - continue; - } else if (matcher.group(TokenType.WALK.name()) != null) { - tokens.add(new Token(TokenType.WALK, matcher.group(TokenType.WALK.name()))); - continue; - } else if (matcher.group(TokenType.RUN.name()) != null) { - tokens.add(new Token(TokenType.RUN, matcher.group(TokenType.RUN.name()))); - continue; - } else if (matcher.group(TokenType.DIRECTION.name()) != null) { - tokens.add(new Token(TokenType.DIRECTION, matcher.group(TokenType.DIRECTION.name()))); - continue; - } else if (matcher.group(TokenType.WHITESPACE.name()) != null) - continue; + + for(String word: input.split(" ")) { + // Begin matching tokens + Matcher matcher = tokenPatterns.matcher(word); + while (matcher.find()) { + if (matcher.group(TokenType.WALK.name()) != null) { + tokens.add(new Token(TokenType.WALK, matcher.group(TokenType.WALK.name()))); + continue; + } else if (matcher.group(TokenType.RUN.name()) != null) { + tokens.add(new Token(TokenType.RUN, matcher.group(TokenType.RUN.name()))); + continue; + } else if (matcher.group(TokenType.DIRECTION.name()) != null) { + tokens.add(new Token(TokenType.DIRECTION, matcher.group(TokenType.DIRECTION.name()))); + } + } } - return tokens; } -} \ No newline at end of file +} diff --git a/src/main/java/com/textadventure/Main.java b/src/main/java/com/textadventure/Main.java index 8c44a06..d4ba917 100644 --- a/src/main/java/com/textadventure/Main.java +++ b/src/main/java/com/textadventure/Main.java @@ -7,11 +7,15 @@ public class Main { public static void main(String[] args) { +<<<<<<< HEAD log.info("Hi there! Let's rock this"); String input = " w walk s North"; ArrayList tokens = Lexer.lex(input); for (Token token : tokens) log.info(token.toString()); +======= + System.out.println("Hi there! Let's rock this"); +>>>>>>> 2379c5d31875271667c3eed689ccf1d115ff8d03 } } \ No newline at end of file diff --git a/src/test/java/com/textadventure/LexerTest.java b/src/test/java/com/textadventure/LexerTest.java index b4afba7..90785c9 100644 --- a/src/test/java/com/textadventure/LexerTest.java +++ b/src/test/java/com/textadventure/LexerTest.java @@ -1,15 +1,36 @@ package com.textadventure; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; + +import org.junit.Test; public class LexerTest { - @DisplayName("Single dummy test") - @Test - void dummyTest() { - assertTrue(true); - } + @Test + public void testOutputToken() { + String inputTest = "North run walk"; + ArrayList tokens = Lexer.lex(inputTest); + StringBuilder output = new StringBuilder(); + for (Token token : tokens) + output.append(token); + assertTrue(output.toString().contains("DIRECTION")); + assertTrue(output.toString().contains("WALK")); + assertTrue(output.toString().contains("RUN")); + } + + @Test + public void testOutputNumberOfWords() { + String inputTest = "North run walk"; + ArrayList tokens = Lexer.lex(inputTest); + int numberOfWords = 0; + for (Token token : tokens) + numberOfWords++; + + assertEquals(3, tokens.size()); + } } \ No newline at end of file diff --git a/src/test/java/com/textadventure/MainTest.java b/src/test/java/com/textadventure/MainTest.java index e613d57..28d2f74 100644 --- a/src/test/java/com/textadventure/MainTest.java +++ b/src/test/java/com/textadventure/MainTest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +<<<<<<< HEAD import static org.junit.jupiter.api.Assertions.assertTrue; public class MainTest { @@ -13,3 +14,35 @@ void dummyTest() { assertTrue(true); } } +======= +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; + +public class LexerTest { + + @Test + void testOutputToken() { + String inputTest = "North run walk"; + ArrayList tokens = Lexer.lex(inputTest); + String output = ""; + for (Token token : tokens) + output += token.type + " "; + assertTrue(output.contains("DIRECTION")); + assertTrue(output.contains("WALK")); + assertTrue(output.contains("RUN")); + } + + @Test + public void testOutputNumberOfWords() { + String inputTest = "North run walk"; + ArrayList tokens = Lexer.lex(inputTest); + int numberOfWords = 1; + for (Token token : tokens) + numberOfWords++; + + assertEquals(3, tokens.size()); + } +} +>>>>>>> 2379c5d31875271667c3eed689ccf1d115ff8d03