From 8bd960dfb7bf0834d0f467c494e71472eaaad4a3 Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Tue, 12 Nov 2019 15:44:53 +0700 Subject: [PATCH 1/6] Update embulk version to 0.9.20 --- README.md | 2 +- build.gradle | 8 +++--- .../input/jira/JiraPluginTestRuntime.java | 25 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7700980..ddadf8a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ embulk-input-jira is the Embulk input plugin for [JIRA](https://www.atlassian.co ## Overview -Required Embulk version >= 0.8.7 +Required Embulk version >= 0.9.20 * **Plugin type**: input * **Resume supported**: no diff --git a/build.gradle b/build.gradle index de68007..deb4880 100644 --- a/build.gradle +++ b/build.gradle @@ -20,15 +20,15 @@ sourceCompatibility = 1.8 targetCompatibility = 1.8 dependencies { - compile "org.embulk:embulk-core:0.9.11" - provided "org.embulk:embulk-core:0.9.11" + compile "org.embulk:embulk-core:0.9.20" + provided "org.embulk:embulk-core:0.9.20" compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6' compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.27' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' testCompile "junit:junit:4.+" testCompile "org.mockito:mockito-core:2.+" - testCompile "org.embulk:embulk-test:0.9.11" - testCompile "org.embulk:embulk-core:0.9.11:tests" + testCompile "org.embulk:embulk-test:0.9.20" + testCompile "org.embulk:embulk-core:0.9.20:tests" } task classpath(type: Copy, dependsOn: ["jar"]) { diff --git a/src/test/java/org/embulk/input/jira/JiraPluginTestRuntime.java b/src/test/java/org/embulk/input/jira/JiraPluginTestRuntime.java index cbd527b..38b8a8c 100644 --- a/src/test/java/org/embulk/input/jira/JiraPluginTestRuntime.java +++ b/src/test/java/org/embulk/input/jira/JiraPluginTestRuntime.java @@ -19,7 +19,6 @@ import org.embulk.jruby.JRubyScriptingModule; import org.embulk.plugin.BuiltinPluginSourceModule; import org.embulk.plugin.PluginClassLoaderFactory; -import org.embulk.plugin.PluginClassLoaderModule; import org.embulk.spi.BufferAllocator; import org.embulk.spi.Exec; import org.embulk.spi.ExecAction; @@ -37,7 +36,7 @@ public class JiraPluginTestRuntime extends GuiceBinder { private static ConfigSource getSystemConfig() { - ObjectNode configNode = JsonNodeFactory.instance.objectNode(); + final ObjectNode configNode = JsonNodeFactory.instance.objectNode(); configNode.set("jruby_load_path", JsonNodeFactory.instance.arrayNode().add("lib")); return new DataSourceImpl(new ModelManager(null, new ObjectMapper()), configNode); @@ -46,27 +45,26 @@ private static ConfigSource getSystemConfig() public static class TestRuntimeModule implements Module { @Override - public void configure(Binder binder) + public void configure(final Binder binder) { - ConfigSource systemConfig = getSystemConfig(); + final ConfigSource systemConfig = getSystemConfig(); new SystemConfigModule(systemConfig).configure(binder); - new ExecModule().configure(binder); + new ExecModule(systemConfig).configure(binder); new ExtensionServiceLoaderModule(systemConfig).configure(binder); new BuiltinPluginSourceModule().configure(binder); new JRubyScriptingModule(systemConfig).configure(binder); - new PluginClassLoaderModule(systemConfig).configure(binder); new TestUtilityModule().configure(binder); new TestPluginSourceModule().configure(binder); } } - private ExecSession exec; + private final ExecSession exec; public JiraPluginTestRuntime() { super(new TestRuntimeModule()); - Injector injector = getInjector(); - ConfigSource execConfig = new DataSourceImpl(injector.getInstance(ModelManager.class)); + final Injector injector = getInjector(); + final ConfigSource execConfig = new DataSourceImpl(injector.getInstance(ModelManager.class)); this.exec = ExecSession.builder(injector).fromExecConfig(execConfig).build(); } @@ -96,10 +94,11 @@ public PluginClassLoaderFactory getPluginClassLoaderFactory() } @Override - public Statement apply(Statement base, Description description) + public Statement apply(final Statement base, final Description description) { final Statement superStatement = JiraPluginTestRuntime.super.apply(base, description); return new Statement() { + @Override public void evaluate() throws Throwable { try { @@ -107,13 +106,13 @@ public void evaluate() throws Throwable try { superStatement.evaluate(); } - catch (Throwable ex) { + catch (final Throwable ex) { throw new RuntimeExecutionException(ex); } return null; }); } - catch (RuntimeException ex) { + catch (final RuntimeException ex) { throw ex.getCause(); } finally { @@ -125,7 +124,7 @@ public void evaluate() throws Throwable private static class RuntimeExecutionException extends RuntimeException { - public RuntimeExecutionException(Throwable cause) + public RuntimeExecutionException(final Throwable cause) { super(cause); } From e2240929d29b0b08804db03caac0c6e9ffaec415 Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Tue, 12 Nov 2019 16:09:41 +0700 Subject: [PATCH 2/6] Update dist in travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2dd9393..83d575c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: java jdk: oraclejdk8 +dist: trusty + env: global: secure: "NCkU3f60cn5Gmzq+NwDmKdQSq+ApF/rPqSHPirk1+ZPW9n+H9912meUuJr9qyn03MPdc6wAQinsl3skdPNh1Qz02TI/WZGMiCQTLh3nKIMzaaxx6I+OZ1TV7A4MoJMQ7oYQdXdbvRYXpOVRnfVDxpUC+BDk2T8xmjfm9cht+PGTzM6RxpmSL842hiudkcyxHxgEf66EGpi6h2G2PqYNfQrksqiVMWlLiTO5a2ee+iw9qTMhgKrhEKLCb+dFB56gtKIOpd3MxieLwf3PDcsjM+TSaWo6Bp+mjdA3zGJNz5wbWRVSdrIvKvxmf3eRqAGssBhBDO/LUN3LnI+/T/7J9XZZd7WXNudo/t6HQXhJkUIvOucCxSg8/uRsxrMAmF2zkJOnYGSvN3HNqdzyz86TK4/Xckl+gX51b0uYncHfZYSojn4py1RWPYpX/L2RHbzMn1MJ7B3/VZ21vY97aHhDgNyyAMxPnTAuR1IZicEgA8y8AmZkkK9tWq5wvAOKI91V+W8iBEaO2dZIib+KdJSUUj/Q3TM3i4wX9O/AU7tknsnCApvxQeveELJ4SxfFd/Z2imqmQWM0wIgp1u7Vjguf8kSaxcuQHonZNdwvvYOkbYxHvUqltzlmE1qFC/kQe6o9fS3NuiugHCYVeFs+LXVVW+nl0pWztFYMicUmQq7T781w=" From 72a7363f5fcf08dd61ad9ba3226473c7f997d66a Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Tue, 12 Nov 2019 16:34:25 +0700 Subject: [PATCH 3/6] Remove usage of getObjectNode --- .../embulk/input/jira/JiraInputPlugin.java | 2 +- .../org/embulk/input/jira/util/JiraUtil.java | 78 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/embulk/input/jira/JiraInputPlugin.java b/src/main/java/org/embulk/input/jira/JiraInputPlugin.java index 7dd307c..9960e43 100644 --- a/src/main/java/org/embulk/input/jira/JiraInputPlugin.java +++ b/src/main/java/org/embulk/input/jira/JiraInputPlugin.java @@ -162,7 +162,7 @@ public ConfigDiff guess(ConfigSource config) Buffer sample = Buffer.copyOf(createSamples(issues, getUniqueAttributes(issues)).toString().getBytes()); JsonNode columns = Exec.getInjector().getInstance(GuessExecutor.class) .guessParserConfig(sample, Exec.newConfigSource(), createGuessConfig()) - .getObjectNode().get("columns"); + .get(JsonNode.class, "columns"); return Exec.newConfigDiff().set("columns", columns); } diff --git a/src/main/java/org/embulk/input/jira/util/JiraUtil.java b/src/main/java/org/embulk/input/jira/util/JiraUtil.java index 6f57a61..8c9db7c 100644 --- a/src/main/java/org/embulk/input/jira/util/JiraUtil.java +++ b/src/main/java/org/embulk/input/jira/util/JiraUtil.java @@ -9,6 +9,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.embulk.config.ConfigException; +import org.embulk.config.ConfigSource; import org.embulk.input.jira.Issue; import org.embulk.input.jira.JiraInputPlugin.PluginTask; import org.embulk.spi.Column; @@ -37,32 +38,32 @@ public final class JiraUtil { private JiraUtil() {} - public static int calculateTotalPage(int totalCount, int resultPerPage) + public static int calculateTotalPage(final int totalCount, final int resultPerPage) { return (int) Math.ceil((double) totalCount / resultPerPage); } - public static String buildPermissionUrl(String url) + public static String buildPermissionUrl(final String url) { return UriBuilder.fromUri(url).path(CREDENTIAL_URI_PATH).build().toString(); } - public static String buildSearchUrl(String url) + public static String buildSearchUrl(final String url) { return UriBuilder.fromUri(url).path(SEARCH_URI_PATH).build().toString(); } public static void validateTaskConfig(final PluginTask task) { - String username = task.getUsername(); + final String username = task.getUsername(); if (isNullOrEmpty(username)) { throw new ConfigException("Username or email could not be empty"); } - String password = task.getPassword(); + final String password = task.getPassword(); if (isNullOrEmpty(password)) { throw new ConfigException("Password could not be empty"); } - String uri = task.getUri(); + final String uri = task.getUri(); if (isNullOrEmpty(uri)) { throw new ConfigException("JIRA API endpoint could not be empty"); } @@ -74,7 +75,7 @@ public static void validateTaskConfig(final PluginTask task) .setCookieSpec(CookieSpecs.STANDARD) .build()) .build()) { - HttpGet request = new HttpGet(uri); + final HttpGet request = new HttpGet(uri); try (CloseableHttpResponse response = client.execute(request)) { response.getStatusLine().getStatusCode(); } @@ -82,11 +83,11 @@ public static void validateTaskConfig(final PluginTask task) catch (IOException | IllegalArgumentException e) { throw new ConfigException("JIRA API endpoint is incorrect or not available"); } - int retryInitialWaitSec = task.getInitialRetryIntervalMillis(); + final int retryInitialWaitSec = task.getInitialRetryIntervalMillis(); if (retryInitialWaitSec < 1) { throw new ConfigException("Initial retry delay should be equal or greater than 1"); } - int retryLimit = task.getRetryLimit(); + final int retryLimit = task.getRetryLimit(); if (retryLimit < 0 || retryLimit > 10) { throw new ConfigException("Retry limit should between 0 and 10"); } @@ -96,26 +97,25 @@ public static void validateTaskConfig(final PluginTask task) * For getting the timestamp value of the node * Sometime if the parser could not parse the value then return null * */ - private static Timestamp getTimestampValue(PluginTask task, Column column, String value) + private static Timestamp getTimestampValue(final PluginTask task, final Column column, final String value) { - List columnConfigs = task.getColumns().getColumns(); + final List columnConfigs = task.getColumns().getColumns(); String pattern = DEFAULT_TIMESTAMP_PATTERN; - for (ColumnConfig config : columnConfigs) { + for (final ColumnConfig config : columnConfigs) { + final ConfigSource columnConfig = config.getConfigSource(); if (config.getName().equals(column.getName()) - && config.getConfigSource() != null - && config.getConfigSource().getObjectNode() != null - && config.getConfigSource().getObjectNode().get("format") != null - && config.getConfigSource().getObjectNode().get("format").isTextual()) { - pattern = config.getConfigSource().getObjectNode().get("format").asText(); + && columnConfig != null + && columnConfig.has("format")) { + pattern = columnConfig.get(String.class, "format"); break; } } - TimestampParser parser = TimestampParser.of(pattern, "UTC"); + final TimestampParser parser = TimestampParser.of(pattern, "UTC"); Timestamp result = null; try { result = parser.parse(value); } - catch (Exception e) { + catch (final Exception e) { } return result; } @@ -124,13 +124,13 @@ private static Timestamp getTimestampValue(PluginTask task, Column column, Strin * For getting the Long value of the node * Sometime if error occurs (i.e a JSON value but user modified it as long) then return null * */ - private static Long getLongValue(JsonElement value) + private static Long getLongValue(final JsonElement value) { Long result = null; try { result = value.getAsLong(); } - catch (Exception e) { + catch (final Exception e) { } return result; } @@ -139,13 +139,13 @@ private static Long getLongValue(JsonElement value) * For getting the Double value of the node * Sometime if error occurs (i.e a JSON value but user modified it as double) then return null * */ - private static Double getDoubleValue(JsonElement value) + private static Double getDoubleValue(final JsonElement value) { Double result = null; try { result = value.getAsDouble(); } - catch (Exception e) { + catch (final Exception e) { } return result; } @@ -154,24 +154,24 @@ private static Double getDoubleValue(JsonElement value) * For getting the Boolean value of the node * Sometime if error occurs (i.e a JSON value but user modified it as boolean) then return null * */ - private static Boolean getBooleanValue(JsonElement value) + private static Boolean getBooleanValue(final JsonElement value) { Boolean result = null; try { result = value.getAsBoolean(); } - catch (Exception e) { + catch (final Exception e) { } return result; } - public static void addRecord(Issue issue, Schema schema, PluginTask task, PageBuilder pageBuilder) + public static void addRecord(final Issue issue, final Schema schema, final PluginTask task, final PageBuilder pageBuilder) { schema.visitColumns(new ColumnVisitor() { @Override - public void jsonColumn(Column column) + public void jsonColumn(final Column column) { - JsonElement data = issue.getValue(column.getName()); + final JsonElement data = issue.getValue(column.getName()); if (data.isJsonNull() || data.isJsonPrimitive()) { pageBuilder.setNull(column); } @@ -181,9 +181,9 @@ public void jsonColumn(Column column) } @Override - public void stringColumn(Column column) + public void stringColumn(final Column column) { - JsonElement data = issue.getValue(column.getName()); + final JsonElement data = issue.getValue(column.getName()); if (data.isJsonNull()) { pageBuilder.setNull(column); } @@ -208,14 +208,14 @@ else if (data.isJsonArray()) { } @Override - public void timestampColumn(Column column) + public void timestampColumn(final Column column) { - JsonElement data = issue.getValue(column.getName()); + final JsonElement data = issue.getValue(column.getName()); if (data.isJsonNull() || data.isJsonObject() || data.isJsonArray()) { pageBuilder.setNull(column); } else { - Timestamp value = getTimestampValue(task, column, data.getAsString()); + final Timestamp value = getTimestampValue(task, column, data.getAsString()); if (value == null) { pageBuilder.setNull(column); } @@ -226,9 +226,9 @@ public void timestampColumn(Column column) } @Override - public void booleanColumn(Column column) + public void booleanColumn(final Column column) { - Boolean value = getBooleanValue(issue.getValue(column.getName())); + final Boolean value = getBooleanValue(issue.getValue(column.getName())); if (value == null) { pageBuilder.setNull(column); } @@ -238,9 +238,9 @@ public void booleanColumn(Column column) } @Override - public void longColumn(Column column) + public void longColumn(final Column column) { - Long value = getLongValue(issue.getValue(column.getName())); + final Long value = getLongValue(issue.getValue(column.getName())); if (value == null) { pageBuilder.setNull(column); } @@ -250,9 +250,9 @@ public void longColumn(Column column) } @Override - public void doubleColumn(Column column) + public void doubleColumn(final Column column) { - Double value = getDoubleValue(issue.getValue(column.getName())); + final Double value = getDoubleValue(issue.getValue(column.getName())); if (value == null) { pageBuilder.setNull(column); } From ea2df58932978f891e56a02e6322946fb9e8dbd0 Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Tue, 12 Nov 2019 16:36:53 +0700 Subject: [PATCH 4/6] Update changelog and gem version --- CHANGELOG.md | 4 ++++ build.gradle | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2b04e8..3e3bfb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.9 - 2019-11-17 + +* [enhancement] Remove usage of `ConfigSource#getObjectNode` [#57](https://github.com/treasure-data/embulk-input-jira/pull/57) + ## 0.2.8 - 2019-04-08 * [fixed] Process is hang forever when validate task [#56](https://github.com/treasure-data/embulk-input-jira/pull/56) diff --git a/build.gradle b/build.gradle index deb4880..b29c164 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ configurations { provided } -version = "0.2.8" +version = "0.2.9" sourceCompatibility = 1.8 targetCompatibility = 1.8 From a117336925a709d00a260b9edb940d5bd39b613a Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Wed, 13 Nov 2019 09:35:56 +0700 Subject: [PATCH 5/6] Code review --- build.gradle | 2 +- .../java/org/embulk/input/jira/util/JiraUtil.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index b29c164..6b01074 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ configurations { provided } -version = "0.2.9" +version = "0.2.9.alpha.01" sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/java/org/embulk/input/jira/util/JiraUtil.java b/src/main/java/org/embulk/input/jira/util/JiraUtil.java index 8c9db7c..d560599 100644 --- a/src/main/java/org/embulk/input/jira/util/JiraUtil.java +++ b/src/main/java/org/embulk/input/jira/util/JiraUtil.java @@ -101,12 +101,12 @@ private static Timestamp getTimestampValue(final PluginTask task, final Column c { final List columnConfigs = task.getColumns().getColumns(); String pattern = DEFAULT_TIMESTAMP_PATTERN; - for (final ColumnConfig config : columnConfigs) { - final ConfigSource columnConfig = config.getConfigSource(); - if (config.getName().equals(column.getName()) - && columnConfig != null - && columnConfig.has("format")) { - pattern = columnConfig.get(String.class, "format"); + for (final ColumnConfig columnConfig : columnConfigs) { + final ConfigSource columnConfigSource = columnConfig.getConfigSource(); + if (columnConfig.getName().equals(column.getName()) + && columnConfigSource != null + && columnConfigSource.has("format")) { + pattern = columnConfigSource.get(String.class, "format"); break; } } From e8494f1f8d8ee0786e31ba88d7b9d88313751c62 Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Wed, 13 Nov 2019 09:43:17 +0700 Subject: [PATCH 6/6] Revert gem version (previous commit mis-added it) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6b01074..b29c164 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ configurations { provided } -version = "0.2.9.alpha.01" +version = "0.2.9" sourceCompatibility = 1.8 targetCompatibility = 1.8