You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ja...@apache.org on 2014/10/14 14:57:32 UTC
git commit: SQOOP-1586: Sqoop2: Rename leftovers from the SQOOP2
merge of 1367
Repository: sqoop
Updated Branches:
refs/heads/sqoop2 6ae93e6ad -> 68577fbf7
SQOOP-1586: Sqoop2: Rename leftovers from the SQOOP2 merge of 1367
(Veena Basavaraj via Jarek Jarcec Cecho)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/68577fbf
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/68577fbf
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/68577fbf
Branch: refs/heads/sqoop2
Commit: 68577fbf71274dafe9ee60feb0d49f2d3abbd687
Parents: 6ae93e6
Author: Jarek Jarcec Cecho <ja...@apache.org>
Authored: Tue Oct 14 05:57:05 2014 -0700
Committer: Jarek Jarcec Cecho <ja...@apache.org>
Committed: Tue Oct 14 05:57:05 2014 -0700
----------------------------------------------------------------------
.../org/apache/sqoop/model/ConfigUtils.java | 116 +++++++++----------
.../org/apache/sqoop/model/TestConfigUtils.java | 54 ++++-----
.../org/apache/sqoop/shell/core/Constants.java | 2 +-
3 files changed, 84 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/68577fbf/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java b/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
index 9e762dc..372e7d3 100644
--- a/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
+++ b/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
@@ -58,13 +58,12 @@ public class ConfigUtils {
return toConfigs(configuration.getClass(), configuration);
}
- public static List<MConfig> toConfigs(Class klass) {
+ public static List<MConfig> toConfigs(Class<?> klass) {
return toConfigs(klass, null);
}
- @SuppressWarnings("unchecked")
- public static List<MConfig> toConfigs(Class klass, Object configuration) {
- Set<String> formNames = new HashSet<String>();
+ public static List<MConfig> toConfigs(Class<?> klass, Object configuration) {
+ Set<String> configNames = new HashSet<String>();
ConfigurationClass configurationClass =
(ConfigurationClass)klass.getAnnotation(ConfigurationClass.class);
@@ -83,12 +82,12 @@ public class ConfigUtils {
// Each field that should be part of user input should have Input
// annotation.
- Config formAnnotation = field.getAnnotation(Config.class);
+ Config configAnnotation = field.getAnnotation(Config.class);
- if (formAnnotation != null) {
- String formName = getFormName(field, formAnnotation, formNames);
+ if (configAnnotation != null) {
+ String configName = getConfigName(field, configAnnotation, configNames);
- Class type = field.getType();
+ Class<?> type = field.getType();
Object value = null;
if(configuration != null) {
@@ -100,7 +99,7 @@ public class ConfigUtils {
}
}
- configs.add(toConfig(formName, type, value));
+ configs.add(toConfig(configName, type, value));
}
}
@@ -108,7 +107,7 @@ public class ConfigUtils {
}
@SuppressWarnings("unchecked")
- private static MConfig toConfig(String formName, Class klass, Object object) {
+ private static MConfig toConfig(String configName, Class klass, Object object) {
ConfigClass global =
(ConfigClass)klass.getAnnotation(ConfigClass.class);
@@ -126,7 +125,7 @@ public class ConfigUtils {
field.setAccessible(true);
String fieldName = field.getName();
- String inputName = formName + "." + fieldName;
+ String inputName = configName + "." + fieldName;
// Each field that should be part of user input should have Input
// annotation.
@@ -182,30 +181,30 @@ public class ConfigUtils {
}
}
- return new MConfig(formName, inputs);
+ return new MConfig(configName, inputs);
}
private static Field getFieldFromName(Class<?> klass, String name) {
- Field formField;
+ Field configField;
try {
- formField = klass.getDeclaredField(name);
+ configField = klass.getDeclaredField(name);
} catch (NoSuchFieldException e) {
- // reverse lookup form field from custom form name
+ // reverse lookup config field from custom config name
if (name != null) {
for (Field field : klass.getDeclaredFields()) {
- Config formAnnotation = field.getAnnotation(Config.class);
- if (formAnnotation == null) {
+ Config configAnnotation = field.getAnnotation(Config.class);
+ if (configAnnotation == null) {
continue;
}
- if (!StringUtils.isEmpty(formAnnotation.name()) && name.equals(formAnnotation.name())) {
+ if (!StringUtils.isEmpty(configAnnotation.name()) && name.equals(configAnnotation.name())) {
return field;
}
}
}
- throw new SqoopException(ModelError.MODEL_006, "Missing field " + name + " on form class "
+ throw new SqoopException(ModelError.MODEL_006, "Missing field " + name + " on config class "
+ klass.getCanonicalName(), e);
}
- return formField;
+ return configField;
}
/**
@@ -214,6 +213,7 @@ public class ConfigUtils {
* @param configs Input config list
* @param configuration Output configuration object
*/
+ @SuppressWarnings("unchecked")
public static void fromConfigs(List<MConfig> configs, Object configuration) {
Class klass = configuration.getClass();
@@ -226,10 +226,10 @@ public class ConfigUtils {
"Missing field " + config.getName() + " on config class " + klass.getCanonicalName(), e);
}
- Field formField = getFieldFromName(klass, config.getName());
+ configField = getFieldFromName(klass, config.getName());
// We need to access this field even if it would be declared as private
configField.setAccessible(true);
- Class configClass = configField.getType();
+ Class<?> configClass = configField.getType();
Object newValue = ClassUtils.instantiate(configClass);
if (newValue == null) {
@@ -366,7 +366,7 @@ public class ConfigUtils {
@SuppressWarnings("unchecked")
public static String toJson(Object configuration) {
Class klass = configuration.getClass();
- Set<String> formNames = new HashSet<String>();
+ Set<String> configNames = new HashSet<String>();
ConfigurationClass configurationClass =
(ConfigurationClass)klass.getAnnotation(ConfigurationClass.class);
@@ -379,37 +379,37 @@ public class ConfigUtils {
JSONObject jsonOutput = new JSONObject();
// Iterate over all declared fields
- for (Field formField : klass.getDeclaredFields()) {
- formField.setAccessible(true);
+ for (Field configField : klass.getDeclaredFields()) {
+ configField.setAccessible(true);
// We're processing only config validations
- Config formAnnotation = formField.getAnnotation(Config.class);
- if(formAnnotation == null) {
+ Config configAnnotation = configField.getAnnotation(Config.class);
+ if(configAnnotation == null) {
continue;
}
- String formName = getFormName(formField, formAnnotation, formNames);
+ String configName = getConfigName(configField, configAnnotation, configNames);
- Object formValue;
+ Object configValue;
try {
- formValue = formField.get(configuration);
+ configValue = configField.get(configuration);
} catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, "Issue with field "
- + formName, e);
+ + configName, e);
}
JSONObject jsonConfig = new JSONObject();
// Now process each input on the config
- for(Field inputField : formField.getType().getDeclaredFields()) {
+ for(Field inputField : configField.getType().getDeclaredFields()) {
inputField.setAccessible(true);
String inputName = inputField.getName();
Object value;
try {
- value = inputField.get(formValue);
+ value = inputField.get(configValue);
} catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, "Issue with field "
- + formName + "." + inputName, e);
+ + configName + "." + inputName, e);
}
Input inputAnnotation = inputField.getAnnotation(Input.class);
@@ -421,7 +421,7 @@ public class ConfigUtils {
// We need to support NULL, so we do not support primitive types
if (type.isPrimitive()) {
throw new SqoopException(ModelError.MODEL_007,
- "Detected primitive type " + type + " for field " + formName
+ "Detected primitive type " + type + " for field " + configName
+ "." + inputName);
}
@@ -441,12 +441,12 @@ public class ConfigUtils {
jsonConfig.put(inputName, value);
}else {
throw new SqoopException(ModelError.MODEL_004,
- "Unsupported type " + type.getName() + " for input " + formName + "." + inputName);
+ "Unsupported type " + type.getName() + " for input " + configName + "." + inputName);
}
}
}
- jsonOutput.put(formName, jsonConfig);
+ jsonOutput.put(configName, jsonConfig);
}
return jsonOutput.toJSONString();
}
@@ -458,10 +458,11 @@ public class ConfigUtils {
* @param json JSON representation of the configuration object
* @param configuration ConfigurationGroup object to be filled
*/
+ @SuppressWarnings("unchecked")
public static void fillValues(String json, Object configuration) {
- Class klass = configuration.getClass();
+ Class<?> klass = configuration.getClass();
- Set<String> formNames = new HashSet<String>();
+ Set<String> configNames = new HashSet<String>();
JSONObject jsonConfigs = (JSONObject) JSONValue.parse(json);
for(Field configField : klass.getDeclaredFields()) {
@@ -469,11 +470,11 @@ public class ConfigUtils {
String configName = configField.getName();
// We're processing only config validations
- Config formAnnotation = configField.getAnnotation(Config.class);
- if(formAnnotation == null) {
+ Config configAnnotation = configField.getAnnotation(Config.class);
+ if(configAnnotation == null) {
continue;
}
- String formName = getFormName(configField, formAnnotation, formNames);
+ configName = getConfigName(configField, configAnnotation, configNames);
try {
configField.set(configuration, configField.getType().newInstance());
@@ -511,7 +512,7 @@ public class ConfigUtils {
continue;
}
- Class type = inputField.getType();
+ Class<?> type = inputField.getType();
try {
if(type == String.class) {
@@ -541,38 +542,38 @@ public class ConfigUtils {
}
}
- private static String getFormName(Field member, Config annotation, Set<String> existingFormNames) {
+ private static String getConfigName(Field member, Config annotation, Set<String> existingConfigNames) {
if (StringUtils.isEmpty(annotation.name())) {
return member.getName();
} else {
- checkForValidFormName(existingFormNames, annotation.name());
- existingFormNames.add(annotation.name());
+ checkForValidConfigName(existingConfigNames, annotation.name());
+ existingConfigNames.add(annotation.name());
return annotation.name();
}
}
- private static void checkForValidFormName(Set<String> existingFormNames,
- String customFormName) {
+ private static void checkForValidConfigName(Set<String> existingConfigNames,
+ String customConfigName) {
// uniqueness across fields check
- if (existingFormNames.contains(customFormName)) {
+ if (existingConfigNames.contains(customConfigName)) {
throw new SqoopException(ModelError.MODEL_012,
- "Issue with field form name " + customFormName);
+ "Issue with field config name " + customConfigName);
}
- if (!Character.isJavaIdentifierStart(customFormName.toCharArray()[0])) {
+ if (!Character.isJavaIdentifierStart(customConfigName.toCharArray()[0])) {
throw new SqoopException(ModelError.MODEL_013,
- "Issue with field form name " + customFormName);
+ "Issue with field config name " + customConfigName);
}
- for (Character c : customFormName.toCharArray()) {
+ for (Character c : customConfigName.toCharArray()) {
if (Character.isJavaIdentifierPart(c))
continue;
throw new SqoopException(ModelError.MODEL_013,
- "Issue with field form name " + customFormName);
+ "Issue with field config name " + customConfigName);
}
- if (customFormName.length() > 30) {
+ if (customConfigName.length() > 30) {
throw new SqoopException(ModelError.MODEL_014,
- "Issue with field form name " + customFormName);
+ "Issue with field config name " + customConfigName);
}
}
@@ -633,5 +634,4 @@ public class ConfigUtils {
throw new SqoopException(ModelError.MODEL_015, e);
}
}
-
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/68577fbf/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java b/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
index d5377f8..2a7281a 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
@@ -26,9 +26,6 @@ import junit.framework.TestCase;
import org.apache.sqoop.common.SqoopException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
/**
* Test config utils
*/
@@ -52,7 +49,7 @@ public class TestConfigUtils extends TestCase {
public void testConfigsMissingAnnotation() {
try {
- ConfigUtils.toConfigs(ConfigWithout.class);
+ ConfigUtils.toConfigs(ConfigWithoutAnnotation.class);
} catch(SqoopException ex) {
assertEquals(ModelError.MODEL_003, ex.getErrorCode());
return;
@@ -61,9 +58,9 @@ public class TestConfigUtils extends TestCase {
fail("Correct exception wasn't thrown");
}
- public void testNonUniqueFormNameAttributes() {
+ public void testNonUniqueConfigNameAttributes() {
try {
- ConfigUtils.toConfigs(ConfigurationWithNonUniqueFormNameAttribute.class);
+ ConfigUtils.toConfigs(ConfigurationWithNonUniqueConfigNameAttribute.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_012, ex.getErrorCode());
return;
@@ -72,20 +69,19 @@ public class TestConfigUtils extends TestCase {
fail("Correct exception wasn't thrown");
}
- public void testInvalidFormNameAttribute() {
+ public void testInvalidConfigNameAttribute() {
try {
- ConfigUtils.toConfigs(ConfigurationWithInvalidFormNameAttribute.class);
+ ConfigUtils.toConfigs(ConfigurationWithInvalidConfigNameAttribute.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_013, ex.getErrorCode());
return;
}
-
fail("Correct exception wasn't thrown");
}
- public void testInvalidFormNameAttributeLength() {
+ public void testInvalidConfigNameAttributeLength() {
try {
- ConfigUtils.toConfigs(ConfigurationWithInvalidFormNameAttributeLength.class);
+ ConfigUtils.toConfigs(ConfigurationWithInvalidConfigNameAttributeLength.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_014, ex.getErrorCode());
return;
@@ -196,36 +192,36 @@ public class TestConfigUtils extends TestCase {
}
@ConfigurationClass
- public static class ConfigurationWithNonUniqueFormNameAttribute {
- public ConfigurationWithNonUniqueFormNameAttribute() {
- aForm = new InvalidConfig();
- bForm = new InvalidConfig();
+ public static class ConfigurationWithNonUniqueConfigNameAttribute {
+ public ConfigurationWithNonUniqueConfigNameAttribute() {
+ aConfig = new InvalidConfig();
+ bConfig = new InvalidConfig();
}
@Config(name = "sameName")
- InvalidConfig aForm;
+ InvalidConfig aConfig;
@Config(name = "sameName")
- InvalidConfig bForm;
+ InvalidConfig bConfig;
}
@ConfigurationClass
- public static class ConfigurationWithInvalidFormNameAttribute {
- public ConfigurationWithInvalidFormNameAttribute() {
- invalidForm = new InvalidConfig();
+ public static class ConfigurationWithInvalidConfigNameAttribute {
+ public ConfigurationWithInvalidConfigNameAttribute() {
+ invalidConfig = new InvalidConfig();
}
- @Config(name = "#_form")
- InvalidConfig invalidForm;
+ @Config(name = "#_config")
+ InvalidConfig invalidConfig;
}
@ConfigurationClass
- public static class ConfigurationWithInvalidFormNameAttributeLength {
- public ConfigurationWithInvalidFormNameAttributeLength() {
- invalidLengthForm = new InvalidConfig();
+ public static class ConfigurationWithInvalidConfigNameAttributeLength {
+ public ConfigurationWithInvalidConfigNameAttributeLength() {
+ invalidLengthConfig = new InvalidConfig();
}
- @Config(name = "longest_form_more_than_30_characers")
- InvalidConfig invalidLengthForm;
+ @Config(name = "longest_config_more_than_30_characers")
+ InvalidConfig invalidLengthConfig;
}
@ConfigurationClass
@@ -280,11 +276,11 @@ public class TestConfigUtils extends TestCase {
@Input int value;
}
- public static class ConfigWithout {
+ public static class ConfigWithoutAnnotation {
}
enum Enumeration {
X,
Y,
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/68577fbf/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
index a1bc5d5..f2bbe7f 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
@@ -1,7 +1,7 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional inconfigation
+ * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance