From 1e2258c7080e9e34907543bfc1e8f2fd119f7515 Mon Sep 17 00:00:00 2001 From: Miruna Date: Thu, 22 Aug 2019 19:35:18 +0300 Subject: [PATCH 01/19] commit message --- src/main/java/com/textadventure/Lexer.java | 15 ++++++----- src/main/java/com/textadventure/Main.java | 2 +- src/test/java/com/textadventure/MainTest.java | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/textadventure/Lexer.java b/src/main/java/com/textadventure/Lexer.java index 6a102dd..6a103c1 100644 --- a/src/main/java/com/textadventure/Lexer.java +++ b/src/main/java/com/textadventure/Lexer.java @@ -7,8 +7,7 @@ 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]+"); + MOVEMENT("W|A|S|D"), WALK("walk"), RUN("run"), DIRECTION("North|South|East|West"); public final String pattern; private TokenType(String pattern) { @@ -26,8 +25,11 @@ public static ArrayList lex(String input) { tokenPatternsBuffer.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); Pattern tokenPatterns = Pattern.compile(new String(tokenPatternsBuffer.substring(1))); - // Begin matching tokens - Matcher matcher = tokenPatterns.matcher(input); + // The user's input is splited after " " + for (String word : input.split(" ")) { + + // Begin matching tokens + Matcher matcher = tokenPatterns.matcher(word); while (matcher.find()) { if (matcher.group(TokenType.MOVEMENT.name()) != null) { tokens.add(new Token(TokenType.MOVEMENT, matcher.group(TokenType.MOVEMENT.name()))); @@ -41,10 +43,11 @@ public static ArrayList lex(String input) { } 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; + } + } } 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 579f530..ea0409c 100644 --- a/src/main/java/com/textadventure/Main.java +++ b/src/main/java/com/textadventure/Main.java @@ -5,7 +5,7 @@ public class Main { public static void main(String[] args) { System.out.println("Hi there! Let's rock this"); - String input = " w walk s North"; + String input = "W walk W S S South "; Lexer lexer = new Lexer(); ArrayList tokens = lexer.lex(input); for (Token token : tokens) diff --git a/src/test/java/com/textadventure/MainTest.java b/src/test/java/com/textadventure/MainTest.java index 42818c3..b4ace83 100644 --- a/src/test/java/com/textadventure/MainTest.java +++ b/src/test/java/com/textadventure/MainTest.java @@ -1,5 +1,11 @@ package com.textadventure; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; + import org.junit.Assert; import org.junit.Test; @@ -8,4 +14,25 @@ public class MainTest { public void testMain() { Assert.assertEquals(true, true); } + @Test + public void testOutputToken() { + String inputTest = " W S North run walk D "; + Lexer lexer = new Lexer(); + ArrayList tokens = lexer.lex(inputTest); + String output = ""; + for (Token token : tokens) + output += token.type + " "; + assertTrue(output.contains("MOVEMENT")); + assertTrue(output.contains("DIRECTION")); + assertTrue(output.contains("WALK")); + assertTrue(output.contains("RUN")); + } + @Test + public void testOutputNumberOfWords() { + String inputTest = " W S North run walk D "; + Lexer lexer = new Lexer(); + ArrayList tokens = lexer.lex(inputTest); + assertEquals(6, tokens.size()); + } + } From ec0cfa2b473f55592d3a43ecc618cfd40fda2358 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 19:12:27 +0100 Subject: [PATCH 02/19] cicd-integration: Jenkinsfile created with simple steps of building, testing and deploying. --- jenkins/Jenkinsfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 jenkins/Jenkinsfile diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile new file mode 100644 index 0000000..b27628d --- /dev/null +++ b/jenkins/Jenkinsfile @@ -0,0 +1,31 @@ +pipeline { + agent { + docker { + image: 'maven:3-alpine' + args: '-v /root/.m2:/root/.m2' + } + } + options { + skipStagesAfterUnstable() + } + stages { + stage('Build') { + steps { + sh 'mvn -B -DskipTests clean package' + } + } + stage('Test') { + steps { + sh 'mvn test' + } + post { + always 'target/surefire-reports/*.xml' + } + } + stage('Deploy') { + steps { + sh './jenkins/scripts/deploy.sh' + } + } + } +} \ No newline at end of file From 6cacfb134d6f84167f4526d4775d5bba4de20b88 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 19:15:20 +0100 Subject: [PATCH 03/19] cicd-integration: deploy.sh script created, have to implement still. --- jenkins/scripts/deploy.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 jenkins/scripts/deploy.sh diff --git a/jenkins/scripts/deploy.sh b/jenkins/scripts/deploy.sh new file mode 100644 index 0000000..e69de29 From 82ce0f99186008454ca4aed0570ba386c27f5daa Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 19:38:52 +0100 Subject: [PATCH 04/19] cicd-integration: Simple deploy script for testing the Jenkins pipeline. --- jenkins/scripts/deploy-dev.sh | 29 +++++++++++++++++++++++++++++ jenkins/scripts/deploy.sh | 7 +++++++ 2 files changed, 36 insertions(+) create mode 100644 jenkins/scripts/deploy-dev.sh diff --git a/jenkins/scripts/deploy-dev.sh b/jenkins/scripts/deploy-dev.sh new file mode 100644 index 0000000..d63e4c4 --- /dev/null +++ b/jenkins/scripts/deploy-dev.sh @@ -0,0 +1,29 @@ +#!/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" +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 + +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 "Pulling the latest master branch..." +git pull origin master + +echo "Deploy not yet implemented!" \ No newline at end of file diff --git a/jenkins/scripts/deploy.sh b/jenkins/scripts/deploy.sh index e69de29..f40c705 100644 --- a/jenkins/scripts/deploy.sh +++ b/jenkins/scripts/deploy.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +# Todo: Write a simple deploy script +echo "Deploy not implemented yet!" + +echo "Running the deployment script on DEV environment..." +ssh jenkins-ci@shard-server-lon01 'bash -s' < deploy-dev.sh \ No newline at end of file From 291eca20caf0cfb037b977994706b359389ae636 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 19:45:31 +0100 Subject: [PATCH 05/19] cicd-integration: Moved Jenkinsfile to the root of project. --- jenkins/Jenkinsfile => Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename jenkins/Jenkinsfile => Jenkinsfile (100%) diff --git a/jenkins/Jenkinsfile b/Jenkinsfile similarity index 100% rename from jenkins/Jenkinsfile rename to Jenkinsfile From f1679de311a5989aec638e5f7117b01327004df9 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 19:55:15 +0100 Subject: [PATCH 06/19] cicd-integration: Removing colon after key to attempt fix declarative syntax error in Jenkins. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b27628d..2acbc9f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,8 +1,8 @@ pipeline { agent { docker { - image: 'maven:3-alpine' - args: '-v /root/.m2:/root/.m2' + image 'maven:3-alpine' + args '-v /root/.m2:/root/.m2' } } options { From de45c83cde24a77a3af0ba4e449976d81b239885 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 20:03:55 +0100 Subject: [PATCH 07/19] cicd-integration: Added missing junit call and fixed the 'always' declarative pipeline syntax. --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2acbc9f..14b530c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,7 +19,9 @@ pipeline { sh 'mvn test' } post { - always 'target/surefire-reports/*.xml' + always { + junit 'target/surefire-reports/*.xml' + } } } stage('Deploy') { From 2bc31d0b09bffe1ddd0596ff1cbf0b3dd25f595e Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 20:51:37 +0100 Subject: [PATCH 08/19] cicd-integration: Using the latest image of maven. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 14b530c..30e3b6d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent { docker { - image 'maven:3-alpine' + image 'maven:latest' args '-v /root/.m2:/root/.m2' } } From 2d3bc336f302bb7969d30942181ac21eeb772983 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 20:53:32 +0100 Subject: [PATCH 09/19] cicd-integration: Debug maven flag. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 30e3b6d..83cc75b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { stages { stage('Build') { steps { - sh 'mvn -B -DskipTests clean package' + sh 'mvn -X -B -DskipTests clean package' } } stage('Test') { From eebb0d4c3870dc818cfadb093eaf0d41c9a440cd Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 20:56:26 +0100 Subject: [PATCH 10/19] cicd-integration: bumping up Maven Compiler plugin version. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e6fd7ac..8986786 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 UTF-8 - 3.8.0 + 3.8.1 12 2.22.0 2.22.0 From e99de8cf575f30869cf5e0e046565a3dbebf44df Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 21:06:09 +0100 Subject: [PATCH 11/19] cicd-integration: using different JDK version for maven. --- Jenkinsfile | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 83cc75b..6e03ed0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent { docker { - image 'maven:latest' + image 'maven:3.6.1-jdk-14' args '-v /root/.m2:/root/.m2' } } diff --git a/pom.xml b/pom.xml index 8986786..e6fd7ac 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 UTF-8 - 3.8.1 + 3.8.0 12 2.22.0 2.22.0 From a671654337573324a937051c72c0565e47630e92 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 21:15:27 +0100 Subject: [PATCH 12/19] cicd-integration: More general version of Maven with correct JDK version, removed -X from mvn build, not ssh ing into server for deployment yet. --- Jenkinsfile | 4 ++-- jenkins/scripts/deploy.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6e03ed0..3b0f727 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent { docker { - image 'maven:3.6.1-jdk-14' + image 'maven:3-jdk-14' args '-v /root/.m2:/root/.m2' } } @@ -11,7 +11,7 @@ pipeline { stages { stage('Build') { steps { - sh 'mvn -X -B -DskipTests clean package' + sh 'mvn -B -DskipTests clean package' } } stage('Test') { diff --git a/jenkins/scripts/deploy.sh b/jenkins/scripts/deploy.sh index f40c705..345ad58 100644 --- a/jenkins/scripts/deploy.sh +++ b/jenkins/scripts/deploy.sh @@ -4,4 +4,5 @@ echo "Deploy not implemented yet!" echo "Running the deployment script on DEV environment..." -ssh jenkins-ci@shard-server-lon01 'bash -s' < deploy-dev.sh \ No newline at end of file +echo "Secrets have not yet been added." +#ssh jenkins-ci@shard-server-lon01 'bash -s' < deploy-dev.sh \ No newline at end of file From 2cb2fb39b9ec636d16fe2e5c5b871c6b4504e932 Mon Sep 17 00:00:00 2001 From: happysad- Date: Thu, 22 Aug 2019 21:18:31 +0100 Subject: [PATCH 13/19] cicd-integration: changed deploy permissions. --- jenkins/scripts/deploy.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 jenkins/scripts/deploy.sh diff --git a/jenkins/scripts/deploy.sh b/jenkins/scripts/deploy.sh old mode 100644 new mode 100755 From 9566226d6828b8318c8f645642747656ef096a98 Mon Sep 17 00:00:00 2001 From: happysad- Date: Fri, 23 Aug 2019 12:43:42 +0100 Subject: [PATCH 14/19] cicd-integration: deploy script updated. --- jenkins/scripts/deploy-dev.sh | 6 ++--- jenkins/scripts/deploy-preprod.sh | 0 jenkins/scripts/deploy-prod.sh | 0 jenkins/scripts/deploy.sh | 39 +++++++++++++++++++++++++++---- 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 jenkins/scripts/deploy-preprod.sh create mode 100644 jenkins/scripts/deploy-prod.sh diff --git a/jenkins/scripts/deploy-dev.sh b/jenkins/scripts/deploy-dev.sh index d63e4c4..64d1289 100644 --- a/jenkins/scripts/deploy-dev.sh +++ b/jenkins/scripts/deploy-dev.sh @@ -5,7 +5,7 @@ # so the DEV server won't have to rebuild an already built project. # -ORG_PATH="~/JavaPlebes" +ORG_PATH="$HOME/JavaPlebes" PROJ_DIR="/TextAdventure" GIT_URL="git@github.com:javaplebes/TextAdventure.git" @@ -14,14 +14,14 @@ if [ ! -d "$ORG_PATH" ]; then mkdir ORG_PATH fi -cd $ORG_PATH +cd "${ORG_PATH}" || exit 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 +cd $PROJ_DIR || exit echo "Pulling the latest master branch..." git pull origin master diff --git a/jenkins/scripts/deploy-preprod.sh b/jenkins/scripts/deploy-preprod.sh new file mode 100644 index 0000000..e69de29 diff --git a/jenkins/scripts/deploy-prod.sh b/jenkins/scripts/deploy-prod.sh new file mode 100644 index 0000000..e69de29 diff --git a/jenkins/scripts/deploy.sh b/jenkins/scripts/deploy.sh index 345ad58..398d733 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 \ No newline at end of file From 18d4f6bf35385bbb63c8011dc86a009699a3d550 Mon Sep 17 00:00:00 2001 From: happysad- Date: Fri, 23 Aug 2019 13:16:11 +0100 Subject: [PATCH 15/19] cicd-integration: Deploy scripts for different environmnets. DEV and PREPROD are the same until we use live db, which then will become an environmental secret. --- jenkins/scripts/deploy-dev.sh | 42 ++++++++++++++++++++--------- jenkins/scripts/deploy-preprod.sh | 45 +++++++++++++++++++++++++++++++ jenkins/scripts/deploy-prod.sh | 43 +++++++++++++++++++++++++++++ jenkins/scripts/deploy.sh | 6 ++--- 4 files changed, 120 insertions(+), 16 deletions(-) diff --git a/jenkins/scripts/deploy-dev.sh b/jenkins/scripts/deploy-dev.sh index 64d1289..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="$HOME/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}" || exit +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 || exit +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 index e69de29..1f1f1ab 100644 --- a/jenkins/scripts/deploy-preprod.sh +++ 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 index e69de29..4ed1867 100644 --- a/jenkins/scripts/deploy-prod.sh +++ 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 398d733..ff33e6c 100755 --- a/jenkins/scripts/deploy.sh +++ b/jenkins/scripts/deploy.sh @@ -3,13 +3,13 @@ deploy_to_env() { if [ -z "$1" ] || [ "$1" = "DEV" ]; then echo "Deploying to DEV environment." - ssh "${PROJ_USER}"@"${DEV_SERVER}" "bash -s" < deploy-dev.sh + 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 + 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 + ssh "${PROJ_USER}@${PROD_SERVER}" "bash -s" < deploy-prod.sh else echo "Unknown environment." return 1 From fde8e970c4114da9c4689227cc1bad9847a97274 Mon Sep 17 00:00:00 2001 From: Martin Bucinskas Date: Fri, 23 Aug 2019 15:17:46 +0100 Subject: [PATCH 16/19] Update issue templates Updated issue templates for issue creation, added request form for requesting access to live servers. --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ .github/ISSUE_TEMPLATE/request-form.md | 19 ++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/request-form.md 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. From 2379c5d31875271667c3eed689ccf1d115ff8d03 Mon Sep 17 00:00:00 2001 From: Miruna Date: Fri, 23 Aug 2019 19:48:39 +0300 Subject: [PATCH 17/19] lexer --- src/main/java/com/textadventure/Lexer.java | 19 ++---- src/main/java/com/textadventure/Main.java | 5 -- src/test/java/com/textadventure/MainTest.java | 61 +++++++++---------- 3 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/textadventure/Lexer.java b/src/main/java/com/textadventure/Lexer.java index 6a103c1..eb6ee9b 100644 --- a/src/main/java/com/textadventure/Lexer.java +++ b/src/main/java/com/textadventure/Lexer.java @@ -7,7 +7,7 @@ public class Lexer { public enum TokenType { - MOVEMENT("W|A|S|D"), WALK("walk"), RUN("run"), DIRECTION("North|South|East|West"); + WALK("walk"), RUN("run"), DIRECTION("North|South|East|West"); public final String pattern; private TokenType(String pattern) { @@ -23,18 +23,13 @@ public static ArrayList lex(String input) { StringBuffer tokenPatternsBuffer = new StringBuffer(); for (TokenType tokenType : TokenType.values()) tokenPatternsBuffer.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); - Pattern tokenPatterns = Pattern.compile(new String(tokenPatternsBuffer.substring(1))); - - // The user's input is splited after " " - for (String word : input.split(" ")) { + Pattern tokenPatterns = Pattern.compile(tokenPatternsBuffer.substring(1)); - // Begin matching tokens + for(String word: input.split(" ")) { + // Begin matching tokens Matcher matcher = tokenPatterns.matcher(word); 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) { + 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) { @@ -43,11 +38,9 @@ public static ArrayList lex(String input) { } else if (matcher.group(TokenType.DIRECTION.name()) != null) { tokens.add(new Token(TokenType.DIRECTION, matcher.group(TokenType.DIRECTION.name()))); continue; - } } } - + } 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 ea0409c..d42e9df 100644 --- a/src/main/java/com/textadventure/Main.java +++ b/src/main/java/com/textadventure/Main.java @@ -5,10 +5,5 @@ public class Main { public static void main(String[] args) { System.out.println("Hi there! Let's rock this"); - String input = "W walk W S S South "; - Lexer lexer = new Lexer(); - ArrayList tokens = lexer.lex(input); - for (Token token : tokens) - System.out.println(token); } } \ 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 b4ace83..2df1401 100644 --- a/src/test/java/com/textadventure/MainTest.java +++ b/src/test/java/com/textadventure/MainTest.java @@ -1,38 +1,35 @@ package com.textadventure; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; -import java.util.Collection; -import org.junit.Assert; -import org.junit.Test; +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++; -public class MainTest { - @Test - public void testMain() { - Assert.assertEquals(true, true); - } - @Test - public void testOutputToken() { - String inputTest = " W S North run walk D "; - Lexer lexer = new Lexer(); - ArrayList tokens = lexer.lex(inputTest); - String output = ""; - for (Token token : tokens) - output += token.type + " "; - assertTrue(output.contains("MOVEMENT")); - assertTrue(output.contains("DIRECTION")); - assertTrue(output.contains("WALK")); - assertTrue(output.contains("RUN")); - } - @Test - public void testOutputNumberOfWords() { - String inputTest = " W S North run walk D "; - Lexer lexer = new Lexer(); - ArrayList tokens = lexer.lex(inputTest); - assertEquals(6, tokens.size()); - } - -} + assertEquals(3, tokens.size()); + } +} \ No newline at end of file From 679e6b46655a0acd32e547bc080ce2c413a2d86e Mon Sep 17 00:00:00 2001 From: Miruna Date: Fri, 23 Aug 2019 23:11:29 +0300 Subject: [PATCH 18/19] Lexer --- src/main/java/com/textadventure/Lexer.java | 47 +++++++++---------- .../java/com/textadventure/LexerTest.java | 37 +++++++++++---- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/textadventure/Lexer.java b/src/main/java/com/textadventure/Lexer.java index 3484f7d..40f99b0 100644 --- a/src/main/java/com/textadventure/Lexer.java +++ b/src/main/java/com/textadventure/Lexer.java @@ -7,44 +7,39 @@ 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()) - 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; + 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()))); + } + } } - return tokens; } } \ 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 From d19afc5f0d29da9401a50e1ccbbe2513071e2516 Mon Sep 17 00:00:00 2001 From: MirunaLM <46753626+MirunaLM@users.noreply.github.com> Date: Fri, 23 Aug 2019 23:43:49 +0300 Subject: [PATCH 19/19] Update Lexer.java --- src/main/java/com/textadventure/Lexer.java | 30 ++++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/textadventure/Lexer.java b/src/main/java/com/textadventure/Lexer.java index 7bfd93a..42cd804 100644 --- a/src/main/java/com/textadventure/Lexer.java +++ b/src/main/java/com/textadventure/Lexer.java @@ -22,7 +22,6 @@ public static ArrayList lex(String input) { // Lexer logic begins here StringBuilder tokenPatternsBuilder = new StringBuilder(); for (TokenType tokenType : TokenType.values()) -<<<<<<< HEAD tokenPatternsBuilder.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); Pattern tokenPatterns = Pattern.compile(tokenPatternsBuilder.substring(1)); @@ -40,27 +39,24 @@ public static ArrayList lex(String input) { 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)); 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()))); - continue; + // 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()))); + } } } ->>>>>>> 2379c5d31875271667c3eed689ccf1d115ff8d03 - } return tokens; } -} \ No newline at end of file +}