From e18e59f502750a4943559f29a7728cc2626bfca2 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:02:13 +0100 Subject: [PATCH 1/9] [TASK] Updated internal API to 1.4.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c356eb2..a97cdad 100755 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ org.parabot internal-api - 1.4.46 + 1.4.5 From 801cd9f6d112aa8153176ccb68d3342871654978 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:02:31 +0100 Subject: [PATCH 2/9] [TASK] Removed invalid cache clearing --- src/main/java/org/parabot/core/Core.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/parabot/core/Core.java b/src/main/java/org/parabot/core/Core.java index ff70069..240b8be 100644 --- a/src/main/java/org/parabot/core/Core.java +++ b/src/main/java/org/parabot/core/Core.java @@ -210,17 +210,8 @@ public class Core { * Method that removes the cache contents after 3 days */ private static void validateCache() { - File[] cache = Directories.getCachePath().listFiles(); - - if (cache != null) { - for (File f : cache) { - long age = new Date().getTime() - f.lastModified(); - - if (age > 3 * 24 * 60 * 60 * 1000) { - f.delete(); - } - } - } + // Already handled by Directories initiating + // Method will be used once BDN V3 has a functionality for this } public static void downloadNewVersion() { From c451bb6d29226c49fc2cd33393c012462ed26ca3 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:02:45 +0100 Subject: [PATCH 3/9] [TASK] Moved StringUtils to Internal API StringUtil --- .../environment/api/utils/StringUtils.java | 48 ++----------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/parabot/environment/api/utils/StringUtils.java b/src/main/java/org/parabot/environment/api/utils/StringUtils.java index 892c75b..8911317 100644 --- a/src/main/java/org/parabot/environment/api/utils/StringUtils.java +++ b/src/main/java/org/parabot/environment/api/utils/StringUtils.java @@ -1,52 +1,10 @@ package org.parabot.environment.api.utils; +import org.parabot.api.misc.StringUtil; + /** * @author mkyong, JKetelaar */ -public class StringUtils { +public class StringUtils extends StringUtil { - private static java.util.Random random = new java.util.Random(); - private static char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray(); - - public static String convertHexToString(String hex) { - - StringBuilder sb = new StringBuilder(); - StringBuilder temp = new StringBuilder(); - - for (int i = 0; i < hex.length() - 1; i += 2) { - - // grab the hex in pairs - String output = hex.substring(i, (i + 2)); - // convert hex to decimal - int decimal = Integer.parseInt(output, 16); - // convert the decimal to character - sb.append((char) decimal); - - temp.append(decimal); - } - - return sb.toString(); - } - - public static String implode(String separator, String... data) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < data.length - 1; i++) { - //data.length - 1 => to not add separator at the end - if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on - sb.append(data[i]); - sb.append(separator); - } - } - sb.append(data[data.length - 1].trim()); - return sb.toString(); - } - - public static String randomString(final int length) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 20; i++) { - char c = chars[random.nextInt(chars.length)]; - sb.append(c); - } - return sb.toString(); - } } From f77aa730eed27e26e580a60f8bf0d069259ac478 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:03:01 +0100 Subject: [PATCH 4/9] [FEATURE] Added CacheValidation unit test --- .../java/org/parabot/CacheValidation.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/org/parabot/CacheValidation.java diff --git a/src/test/java/org/parabot/CacheValidation.java b/src/test/java/org/parabot/CacheValidation.java new file mode 100644 index 0000000..c9b8e8d --- /dev/null +++ b/src/test/java/org/parabot/CacheValidation.java @@ -0,0 +1,34 @@ +package org.parabot; + +import org.junit.Assert; +import org.junit.Test; +import org.parabot.core.Directories; + +import java.io.File; +import java.io.IOException; + +/** + * @author JKetelaar + */ +public class CacheValidation { + + @Test + public void test(){ + try { + File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); + File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); + + fileOne.createNewFile(); + fileTwo.createNewFile(); + + fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000); + + Directories.clearCache(259200, false); + + Assert.assertTrue(fileOne.exists()); + Assert.assertTrue(!fileTwo.exists()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} From 296025cbb2ce7b001672d6e8d7de63c29b75edfd Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:10:05 +0100 Subject: [PATCH 5/9] [BUGFIX] Renamed CacheValidation to CacheValidationTest Allowing JUnit to understand it has to run this test too --- .../parabot/{CacheValidation.java => CacheValidationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/org/parabot/{CacheValidation.java => CacheValidationTest.java} (95%) diff --git a/src/test/java/org/parabot/CacheValidation.java b/src/test/java/org/parabot/CacheValidationTest.java similarity index 95% rename from src/test/java/org/parabot/CacheValidation.java rename to src/test/java/org/parabot/CacheValidationTest.java index c9b8e8d..e966b78 100644 --- a/src/test/java/org/parabot/CacheValidation.java +++ b/src/test/java/org/parabot/CacheValidationTest.java @@ -10,7 +10,7 @@ import java.io.IOException; /** * @author JKetelaar */ -public class CacheValidation { +public class CacheValidationTest { @Test public void test(){ From 0badb2f0947cffb22d8aff895371cd78866d8f4e Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:19:39 +0100 Subject: [PATCH 6/9] [BUGFIX] Added maven test requirement --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 780a3d9..e3121ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,9 @@ before_install: install: - sudo apt-get update && sudo apt-get --assume-yes install zip unzip -script: "./.travis/maven-build.sh" +script: + - mvn test + - "./.travis/maven-build.sh" after_deploy: "./.travis/call-creation.sh" From 3198b3aff9dec835d8f0b6be69eded80c6e2eff7 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:22:19 +0100 Subject: [PATCH 7/9] [BUGFIX] Added throwable to method, instead of catching --- .../java/org/parabot/CacheValidationTest.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/parabot/CacheValidationTest.java b/src/test/java/org/parabot/CacheValidationTest.java index e966b78..cecaed6 100644 --- a/src/test/java/org/parabot/CacheValidationTest.java +++ b/src/test/java/org/parabot/CacheValidationTest.java @@ -13,22 +13,18 @@ import java.io.IOException; public class CacheValidationTest { @Test - public void test(){ - try { - File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); - File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); + public void test() throws IOException { + File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); + File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); - fileOne.createNewFile(); - fileTwo.createNewFile(); + fileOne.createNewFile(); + fileTwo.createNewFile(); - fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000); + fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000); - Directories.clearCache(259200, false); + Directories.clearCache(259200, false); - Assert.assertTrue(fileOne.exists()); - Assert.assertTrue(!fileTwo.exists()); - } catch (IOException e) { - e.printStackTrace(); - } + Assert.assertTrue(fileOne.exists()); + Assert.assertTrue(!fileTwo.exists()); } } From 1b2375145ca5cfc802dfa00fe20e49cc81d21ca4 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:22:46 +0100 Subject: [PATCH 8/9] [TASK] Removed mvn test --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3121ac..780a3d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,7 @@ before_install: install: - sudo apt-get update && sudo apt-get --assume-yes install zip unzip -script: - - mvn test - - "./.travis/maven-build.sh" +script: "./.travis/maven-build.sh" after_deploy: "./.travis/call-creation.sh" From f58eef3c62662913e0450f973e13e8cc498769fe Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:25:34 +0100 Subject: [PATCH 9/9] [BUGFIX] Added validate to create required directories --- src/test/java/org/parabot/CacheValidationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/parabot/CacheValidationTest.java b/src/test/java/org/parabot/CacheValidationTest.java index cecaed6..24aa1de 100644 --- a/src/test/java/org/parabot/CacheValidationTest.java +++ b/src/test/java/org/parabot/CacheValidationTest.java @@ -14,6 +14,8 @@ public class CacheValidationTest { @Test public void test() throws IOException { + Directories.validate(); + File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp");