diff --git a/pom.xml b/pom.xml index cad1436..4db294d 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,9 @@ open-stf hpi - 1.4.0 + 1.0.4-SNAPSHOT Open STF Plugin + https://wiki.jenkins-ci.org/display/JENKINS/Open+STF+Plugin justice3120 @@ -88,12 +89,6 @@ - - maven-release-plugin - - deploy - - org.apache.maven.plugins maven-javadoc-plugin @@ -156,6 +151,13 @@ + + scm:git:git://github.com/jenkinsci/open-stf-plugin.git + scm:git:git@github.com:jenkinsci/open-stf-plugin.git + https://github.com/jenkinsci/open-stf-plugin + HEAD + + @@ -176,13 +178,6 @@ - - - maven.jenkins-ci.org - http://maven.jenkins-ci.org:8081/content/repositories/releases/ - - - github-maven diff --git a/src/main/java/hudson/plugins/openstf/STFBuildWrapper.java b/src/main/java/hudson/plugins/openstf/STFBuildWrapper.java index 34e86f7..f2f3d3f 100644 --- a/src/main/java/hudson/plugins/openstf/STFBuildWrapper.java +++ b/src/main/java/hudson/plugins/openstf/STFBuildWrapper.java @@ -2,7 +2,6 @@ import static hudson.plugins.android_emulator.AndroidEmulator.log; -import jenkins.model.Jenkins; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -31,6 +30,7 @@ import hudson.util.ListBoxModel; import hudson.util.NullStream; import io.swagger.client.model.DeviceListResponseDevices; +import jenkins.model.Jenkins; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; @@ -119,6 +119,14 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList androidHome = hudson.plugins.android_emulator.util.Utils .discoverAndroidHome(launcher, node, envVars, androidHome); + // Validate Setting values + String configError = isConfigValid(stfApiEndpoint, stfToken); + if (configError != null) { + log(logger, Messages.ERROR_MISCONFIGURED(configError)); + build.setResult(Result.NOT_BUILT); + return null; + } + // Confirm that the required SDK tools are available AndroidSdk androidSdk = hudson.plugins.android_emulator.util.Utils .getAndroidSdk(launcher, androidHome, null); @@ -165,6 +173,9 @@ private Environment doSetup(final AbstractBuild build, final Launcher laun String reservedDeviceId = stfConfig.reserve(); DeviceListResponseDevices device = Utils.getSTFDeviceById(reservedDeviceId); remote.setDevice(device); + log(logger, Messages.SHOW_RESERVED_DEVICE_INFO(device.name, device.serial, + device.sdk, device.version)); + build.addAction(new STFReservedDeviceAction(descriptor.stfApiEndpoint, device)); } catch (STFException ex) { log(logger, ex.getMessage()); build.setResult(Result.NOT_BUILT); @@ -322,6 +333,23 @@ private void cleanUp(STFConfig stfConfig, AndroidRemoteContext remote, Proc logc remote.cleanUp(); } + private String isConfigValid(String stfApiEndpoint, String stfToken) { + + if (stfApiEndpoint == null || stfApiEndpoint.equals("")) { + return Messages.API_ENDPOINT_URL_NOT_SET(); + } + FormValidation result = descriptor.doCheckSTFApiEndpoint(stfApiEndpoint); + if (FormValidation.Kind.ERROR == result.kind) { + return result.getMessage(); + } + result = descriptor.doCheckSTFToken(stfApiEndpoint, stfToken); + if (FormValidation.Kind.ERROR == result.kind) { + return result.getMessage(); + } + + return null; + } + private boolean waitForSTFDeviceConnectCompletion(final int timeout, AndroidRemoteContext remote) { @@ -434,29 +462,19 @@ public ListBoxModel doFillConditionNameItems() { return Utils.getSTFDeviceAttributeListBoxItems(); } - public ComboBoxModel doFillConditionValueItems(@QueryParameter String conditionName) { - Utils.setupSTFApiClient(stfApiEndpoint, stfToken); - return Utils.getSTFDeviceAttributeValueComboBoxItems(conditionName); - } - - /** - * Setting device model values on jelly. - * This method is called by Jenkins. - * @return List of Device Model values. - */ - public ComboBoxModel doFillModelItems() { - Utils.setupSTFApiClient(stfApiEndpoint, stfToken); - return Utils.getSTFDeviceAttributeValueComboBoxItems("model"); - } - /** - * Setting OS version values on jelly. + * Fill condition value items on Jenkins web view. * This method is called by Jenkins. - * @return List of OS version values. + * @param conditionName Condition name to get values. + * @return condition value items. */ - public ComboBoxModel doFillVersionItems() { - Utils.setupSTFApiClient(stfApiEndpoint, stfToken); - return Utils.getSTFDeviceAttributeValueComboBoxItems("version"); + public ComboBoxModel doFillConditionValueItems(@QueryParameter String conditionName) { + if (Util.fixEmpty(stfApiEndpoint) == null || Util.fixEmpty(stfToken) == null) { + return new ComboBoxModel(); + } else { + Utils.setupSTFApiClient(stfApiEndpoint, stfToken); + return Utils.getSTFDeviceAttributeValueComboBoxItems(conditionName); + } } /** @@ -504,6 +522,10 @@ public FormValidation doCheckUseSpecificKey(@QueryParameter Boolean value) { @JavaScriptMethod public JSONArray getDeviceListJSON(JSONObject filter) { + if (Util.fixEmpty(stfApiEndpoint) == null || Util.fixEmpty(stfToken) == null) { + return new JSONArray(); + } + if (!Utils.validateDeviceFilter(filter)) { return new JSONArray(); } diff --git a/src/main/java/hudson/plugins/openstf/STFReservedDeviceAction.java b/src/main/java/hudson/plugins/openstf/STFReservedDeviceAction.java new file mode 100644 index 0000000..08fcdb1 --- /dev/null +++ b/src/main/java/hudson/plugins/openstf/STFReservedDeviceAction.java @@ -0,0 +1,57 @@ +package hudson.plugins.openstf; + +import hudson.model.Action; +import hudson.plugins.openstf.Messages; +import io.swagger.client.model.DeviceListResponseDevices; +import org.kohsuke.stapler.export.Exported; + +import java.net.URL; + +public class STFReservedDeviceAction implements Action { + private final String stfApiEndpoint; + private final DeviceListResponseDevices reservedDevice; + + public STFReservedDeviceAction(String stfApiEndpoint, DeviceListResponseDevices reservedDevice) { + this.stfApiEndpoint = stfApiEndpoint; + this.reservedDevice = reservedDevice; + } + + /** + * Get the device image URL. + * This method is called by Jenkins. + * return image URL + */ + @Exported + public String getDeviceIcon() { + String path = "/static/app/devices/icon/x120/"; + if (reservedDevice.image != null) { + path += reservedDevice.image; + } else { + path += "_default.jpg"; + } + try { + URL iconUrl = new URL(new URL(stfApiEndpoint), path); + return iconUrl.toString(); + } catch (Exception ex) { + return ""; + } + } + + @Exported + public String getSummary() { + return Messages.PUBLISH_RESERVED_DEVICE_INFO(reservedDevice.name, reservedDevice.sdk, + reservedDevice.version); + } + + public String getDisplayName() { + return null; + } + + public String getIconFileName() { + return null; + } + + public String getUrlName() { + return null; + } +} diff --git a/src/main/java/hudson/plugins/openstf/axis/STFDeviceConditionAxis.java b/src/main/java/hudson/plugins/openstf/axis/STFDeviceConditionAxis.java index 345a5b1..449f58d 100644 --- a/src/main/java/hudson/plugins/openstf/axis/STFDeviceConditionAxis.java +++ b/src/main/java/hudson/plugins/openstf/axis/STFDeviceConditionAxis.java @@ -1,12 +1,12 @@ package hudson.plugins.openstf.axis; -import jenkins.model.Jenkins; import hudson.Extension; import hudson.matrix.Axis; import hudson.matrix.AxisDescriptor; import hudson.plugins.openstf.STFBuildWrapper; import hudson.plugins.openstf.util.Utils; import hudson.util.ListBoxModel; +import jenkins.model.Jenkins; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; diff --git a/src/main/java/hudson/plugins/openstf/util/Utils.java b/src/main/java/hudson/plugins/openstf/util/Utils.java index 49dd449..825f1f6 100644 --- a/src/main/java/hudson/plugins/openstf/util/Utils.java +++ b/src/main/java/hudson/plugins/openstf/util/Utils.java @@ -344,6 +344,7 @@ public static FormValidation validateSTFApiEndpoint(String stfApiEndpoint) { ApiClient stfApiClient = new ApiClient(); stfApiClient.setBasePath(stfApiEndpoint); + stfApiClient.setConnectTimeout(10 * 1000); UserApi stfUserApi = new UserApi(stfApiClient); try { stfUserApi.getUser(); @@ -356,6 +357,8 @@ public static FormValidation validateSTFApiEndpoint(String stfApiEndpoint) { String message = ex.getMessage(); if (message.startsWith("java.net.UnknownHostException:")) { return FormValidation.error(Messages.CANNOT_RESOLVE_HOST()); + } else if (message.startsWith("java.net.SocketTimeoutException:")) { + return FormValidation.error(Messages.CONNECTION_TIMEOUT()); } else if (message.startsWith("java.net.ConnectException:")) { return FormValidation.error(message.replaceAll("java.net.ConnectException: ", "")); } else { diff --git a/src/main/resources/hudson/plugins/openstf/Messages.properties b/src/main/resources/hudson/plugins/openstf/Messages.properties index 8269ae0..917c4ed 100644 --- a/src/main/resources/hudson/plugins/openstf/Messages.properties +++ b/src/main/resources/hudson/plugins/openstf/Messages.properties @@ -2,6 +2,7 @@ MALFORMED_STF_API_ENDPOINT_URL=STF API endpoint URL is malformed INVALID_STF_API_ENDPOINT_URL=URL seems not valid as the STF API endpoint CANNOT_RESOLVE_HOST=Cannot resolve this host name +CONNECTION_TIMEOUT=Connection time out. STF_API_ENDPOINT_NOT_SET=Please set STF API endpoint URL first STF_TOKEN_REQUIRED=STF token is required STF_TOKEN_NOT_VALID=STF token is not valid @@ -15,6 +16,9 @@ INVALID_REGEXP_VALUE=Invalid Regex value # Execution CANNOT_GET_HUDSON_INSTANCE=Could not get any hudson instances on this build INVALID_DEVICE_CONDITION_SET_IS_GIVEN=Invalid device condition set was given. Please check your job setting. +API_ENDPOINT_URL_NOT_SET=The STF API Endpoint URL has not been set. +ERROR_MISCONFIGURED=Cannot use the Open STF due to misconfiguration: {0} +SHOW_RESERVED_DEVICE_INFO=Reserved Device Info:\n Name: {0}\n Serial: {1}\n API Level:{2}\n OS Version: {3} OVERWRITE_ADBKEY_FILE=Overwriting ADB key file at ''{0}'' ADBKEY_IS_NOT_SET=ADB key file is not set. Skip overwriting START_WAITING_STF_DEVICE_RELEASED=Waiting for the STF device to be released... @@ -24,3 +28,7 @@ CONNECTING_STF_DEVICE_FAILED=Connecting to the STF divice is failed CANNOT_GET_WORKSPACE_ON_THIS_BUILD=Could not get workspace directory on this build INTERRUPTED_DURING_STF_DEVICE_CONNECT_COMPLETION=Interrupted while waiting for the connection to the STF device to complete COULD_NOT_CHECK_STF_DEVICE_CONNECT_COMPLETION=Could not check for the STF device connect completion + +# Publish + +PUBLISH_RESERVED_DEVICE_INFO=Built with "{0}" (API Level={1}, OS Version={2}) diff --git a/src/main/resources/hudson/plugins/openstf/STFBuildWrapper/config.jelly b/src/main/resources/hudson/plugins/openstf/STFBuildWrapper/config.jelly index 876b4c8..6f281e0 100644 --- a/src/main/resources/hudson/plugins/openstf/STFBuildWrapper/config.jelly +++ b/src/main/resources/hudson/plugins/openstf/STFBuildWrapper/config.jelly @@ -1,3 +1,4 @@ +