From 4c5cd1188b76f3e671215241b735fe2879005a5d Mon Sep 17 00:00:00 2001 From: Christian Steiger Date: Thu, 15 Aug 2013 11:13:59 +0200 Subject: [PATCH] modified Description entry field and adjust methods --- .description | 1 - .../plugins/relution/Application.java | 74 ++++---- .../relution/ApplicationFileCallable.java | 8 +- .../relution/GlobalConfigurationImpl.java | 25 +-- .../relution/RelutionCommunicator.java | 161 +++++++++--------- .../plugins/relution/json/APIObject.java | 2 +- .../GlobalConfigurationImpl/config.jelly | 5 - .../relution/RelutionPublisher/config.jelly | 5 + ....html => help-applicationDescription.html} | 0 9 files changed, 143 insertions(+), 138 deletions(-) delete mode 100644 .description rename src/main/webapp/{help-gitDescription.html => help-applicationDescription.html} (100%) diff --git a/.description b/.description deleted file mode 100644 index 4d01690..0000000 --- a/.description +++ /dev/null @@ -1 +0,0 @@ -This is a Jenkins Plugin that could be used to upload different Jobs to (global) defined URLs. diff --git a/src/main/java/org/jenkinsci/plugins/relution/Application.java b/src/main/java/org/jenkinsci/plugins/relution/Application.java index 676b9cb..c6cda03 100644 --- a/src/main/java/org/jenkinsci/plugins/relution/Application.java +++ b/src/main/java/org/jenkinsci/plugins/relution/Application.java @@ -48,6 +48,7 @@ public class Application extends AbstractDescribableImpl { private String apiEndpointURL; private String applicationName; private String applicationReleaseNotes; + private String applicationDescription; /** * These constructor will be executed every time when the save/submit button will be triggered in the Jenkins. @@ -57,13 +58,15 @@ public class Application extends AbstractDescribableImpl { * @param apiReleaseStatus String Representation of the ReleaseState to the app will be published. */ @DataBoundConstructor - public Application(final String apiEndpointURL, final String applicationFile, final String applicationIcon, final String apiReleaseStatus, final String applicationName, final String applicationReleaseNotes) { + public Application(final String apiEndpointURL, final String applicationFile, final String applicationIcon, final String apiReleaseStatus, final String applicationName, final String applicationReleaseNotes, final String applicationDescription) { this.setApiEndpointURL(apiEndpointURL); this.setApplicationFile(applicationFile); this.setApplicationIcon(applicationIcon); this.setApiReleaseStatus(apiReleaseStatus); this.setApplicationName(applicationName); this.setApplicationReleaseNotes(applicationReleaseNotes); + System.out.println("Constructor: " + applicationDescription); + this.setApplicationDescription(applicationDescription); } /** @@ -152,6 +155,19 @@ public void setApplicationReleaseNotes(String applicationReleaseNotes) { this.applicationReleaseNotes = applicationReleaseNotes; } + /** + * @return Content of the Descriptopm-File which will be set in the TextField. + */ + public String getApplicationDescription() { + return this.applicationDescription; + } + + /** + * @param applicationDescription Content that should be set to the app. + */ + public void setApplicationDescription(String applicationDescription) { + this.applicationDescription = applicationDescription; + } /** * Descriptor for {@link DescriptorImpl}. Used as a singleton. @@ -193,35 +209,35 @@ public ListBoxModel doFillApiEndpointURLItems() { return items; } - /** - * Validates if the enntry in the Inputfield is empty/not empty. - * @param value value of the input field applicationName. - * @return true if an entry exists, false if no entry exists. - * @throws IOException - * @throws ServletException - */ - public FormValidation doCheckApplicationName(@QueryParameter final String value) - throws IOException, ServletException { - if (value.length() == 0) { - return FormValidation.error(Messages.Relution_appName()); - } - return FormValidation.ok(); - } +// /** +// * Validates if the enntry in the Inputfield is empty/not empty. +// * @param value value of the input field applicationName. +// * @return true if an entry exists, false if no entry exists. +// * @throws IOException +// * @throws ServletException +// */ +// public FormValidation doCheckApplicationName(@QueryParameter final String value) +// throws IOException, ServletException { +// if (value.length() == 0) { +// return FormValidation.error(Messages.Relution_appName()); +// } +// return FormValidation.ok(); +// } - /** - * Validates if the entry in the Inputfield is empty/no empty. - * @param value value of the input field applicationIcon. - * @return true if an entry exists, false if no entry exists. - * @throws IOException - * @throws ServletException - */ - public FormValidation doCheckApplicationIcon(@QueryParameter final String value) - throws IOException, ServletException { - if (value.length() == 0) { - return FormValidation.error(Messages.Relution_apiIconIsRequired()); - } - return FormValidation.ok(); - } +// /** +// * Validates if the entry in the Inputfield is empty/no empty. +// * @param value value of the input field applicationIcon. +// * @return true if an entry exists, false if no entry exists. +// * @throws IOException +// * @throws ServletException +// */ +// public FormValidation doCheckApplicationIcon(@QueryParameter final String value) +// throws IOException, ServletException { +// if (value.length() == 0) { +// return FormValidation.error(Messages.Relution_apiIconIsRequired()); +// } +// return FormValidation.ok(); +// } /** * @return List of ReleaseStatuses that the actual app could have. diff --git a/src/main/java/org/jenkinsci/plugins/relution/ApplicationFileCallable.java b/src/main/java/org/jenkinsci/plugins/relution/ApplicationFileCallable.java index c49683e..f2437a7 100644 --- a/src/main/java/org/jenkinsci/plugins/relution/ApplicationFileCallable.java +++ b/src/main/java/org/jenkinsci/plugins/relution/ApplicationFileCallable.java @@ -41,8 +41,6 @@ import org.apache.tools.ant.types.FileSet; import org.jenkinsci.plugins.relution.entities.ApplicationInformation; import org.jenkinsci.plugins.relution.entities.ShortApplicationInformation; -import org.jenkinsci.plugins.relution.json.APIObject; -import org.jenkinsci.plugins.relution.net.RequestFactory; @SuppressWarnings("serial") public class ApplicationFileCallable implements FileCallable { @@ -117,7 +115,7 @@ public Boolean invoke(final File f, final VirtualChannel channel) throws IOExcep final String uploadedAssetToken = communicator.uploadApplicationAsset("", applicationFile); // this.listener.getLogger().println("[Relution Publisher]: Uploaded application asset (token " + uploadedAssetToken + ")"); // ----------------------------------------------------------------- - final String appObject = communicator.analyzeUploadedApplication(uploadedAssetToken, app.getUUID(), this.application.getApplicationIcon(), this.application.getApiReleaseStatus(), this.application.getApplicationName(), this.application.getApplicationReleaseNotes(), fileSet, communicator); + final String appObject = communicator.analyzeUploadedApplication(uploadedAssetToken, app.getUUID(), this.application.getApplicationIcon(), this.application.getApiReleaseStatus(), this.application.getApplicationName(), this.application.getApplicationReleaseNotes(), this.application.getApplicationDescription(), fileSet, communicator); if(appObject.equals("Version already exists. Please delete the old one to upload the same version again.")) { this.listener.getLogger().println("[Relution Publisher]: Version already exists. Please delete the old one to upload the same version again."); return false; @@ -133,6 +131,10 @@ public Boolean invoke(final File f, final VirtualChannel channel) throws IOExcep e.printStackTrace(); } catch (final URISyntaxException e) { e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); } return false; diff --git a/src/main/java/org/jenkinsci/plugins/relution/GlobalConfigurationImpl.java b/src/main/java/org/jenkinsci/plugins/relution/GlobalConfigurationImpl.java index 05aae8d..01a642e 100644 --- a/src/main/java/org/jenkinsci/plugins/relution/GlobalConfigurationImpl.java +++ b/src/main/java/org/jenkinsci/plugins/relution/GlobalConfigurationImpl.java @@ -76,7 +76,6 @@ public class GlobalConfigurationImpl extends GlobalConfiguration { private String apiOrganization; private String response; private String apiReleaseStatus; - private String gitDescription; /** * executed during startup of the Plugin and instantiate different GlobalConfiguration-Objects. @@ -96,7 +95,7 @@ public GlobalConfigurationImpl() { * @param proxyPort */ @DataBoundConstructor - public GlobalConfigurationImpl(final String apiEndpoint, final String apiUsername, final String apiPassword, final String apiOrganization, final String apiReleaseStatus, final String gitDescription, final String proxyHost, final int proxyPort) { + public GlobalConfigurationImpl(final String apiEndpoint, final String apiUsername, final String apiPassword, final String apiOrganization, final String apiReleaseStatus, final String proxyHost, final int proxyPort) { super(); this.load(); @@ -105,7 +104,6 @@ public GlobalConfigurationImpl(final String apiEndpoint, final String apiUsernam this.setApiPassword(apiPassword); this.setApiOrganization(apiOrganization); this.setApiReleaseStatus(apiReleaseStatus); - this.setGitDescription(gitDescription); this.setProxyHost(proxyHost); this.setProxyPort(proxyPort); } @@ -216,10 +214,9 @@ public boolean configure(final StaplerRequest req, final JSONObject formData) th this.apiPassword = ((JSONObject)jsonArray.get(index)).get("apiPassword").toString(); this.apiOrganization = ((JSONObject)jsonArray.get(index)).get("apiOrganization").toString(); this.apiReleaseStatus = ((JSONObject)jsonArray.get(index)).get("apiReleaseStatus").toString(); - this.gitDescription = ((JSONObject)jsonArray.get(index)).get("gitDescription").toString(); this.proxyHost = formData.getString("proxyHost"); this.proxyPort = formData.getInt("proxyPort"); - instances.add(new GlobalConfigurationImpl(this.apiEndpoint, this.apiUsername, this.apiPassword, this.apiOrganization, this.apiReleaseStatus, this.gitDescription, this.proxyHost, this.proxyPort)); + instances.add(new GlobalConfigurationImpl(this.apiEndpoint, this.apiUsername, this.apiPassword, this.apiOrganization, this.apiReleaseStatus, this.proxyHost, this.proxyPort)); loginCredentials.put(((JSONObject)jsonArray.get(index)).get("apiEndpoint").toString(), this.apiUsername + ":" + this.apiOrganization + ":" + this.apiPassword); } } @@ -232,10 +229,9 @@ else if(apiEndpoint instanceof JSONObject) { this.apiPassword = innerObject.get("apiPassword").toString(); this.apiOrganization = innerObject.get("apiOrganization").toString(); this.apiReleaseStatus = innerObject.getString("apiReleaseStatus"); - this.gitDescription = innerObject.getString("gitDescription"); this.proxyHost = formData.getString("proxyHost"); this.proxyPort = formData.getInt("proxyPort"); - instances.add(new GlobalConfigurationImpl(this.apiEndpoint, this.apiUsername, this.apiPassword, this.apiOrganization, this.apiReleaseStatus, this.gitDescription, this.proxyHost, this.proxyPort)); + instances.add(new GlobalConfigurationImpl(this.apiEndpoint, this.apiUsername, this.apiPassword, this.apiOrganization, this.apiReleaseStatus, this.proxyHost, this.proxyPort)); loginCredentials.put(this.apiEndpoint, this.apiUsername + ":" + this.apiOrganization + ":" + this.apiPassword); } System.out.println(formData.toString()); @@ -387,19 +383,4 @@ public void setApiReleaseStatus(String apiReleaseStatus) { public String getApiReleaseStatus() { return this.apiReleaseStatus; } - - /** - * @param gitDescription Sets entry of the textfield gitDescription. - */ - public void setGitDescription(String gitDescription) { - this.gitDescription = gitDescription; - } - - /** - * @return actual entered ReleaseStatus. - */ - public String getGitDescription() { - return this.gitDescription; - } - } diff --git a/src/main/java/org/jenkinsci/plugins/relution/RelutionCommunicator.java b/src/main/java/org/jenkinsci/plugins/relution/RelutionCommunicator.java index 7986309..b50b6bd 100644 --- a/src/main/java/org/jenkinsci/plugins/relution/RelutionCommunicator.java +++ b/src/main/java/org/jenkinsci/plugins/relution/RelutionCommunicator.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; import java.lang.reflect.Type; import java.net.URISyntaxException; import java.net.URL; @@ -137,12 +138,22 @@ public String uploadApplicationAsset(final String uploadToken, * @param UUID unique ID of the App that should be uploaded. * @return Json Object that could be uploaded to the mcap. * @throws URISyntaxException - * @throws IOException - * @throws ClientProtocolException * @throws ParseException + * @throws ClientProtocolException + * @throws IOException + * @throws IllegalArgumentException + * @throws IllegalAccessException */ - public String analyzeUploadedApplication(final String uploadToken, final String UUID, final String appIcon, final String releaseStatus, final String appName, final String appReleaseNotes, final FileSet fileSet, final RelutionCommunicator communicator) throws URISyntaxException, ParseException, - ClientProtocolException, IOException { + public String analyzeUploadedApplication(final String uploadToken, + final String UUID, + final String appIcon, + final String releaseStatus, + final String appName, + final String appReleaseNotes, + final String appDescription, + final FileSet fileSet, + final RelutionCommunicator communicator) throws URISyntaxException, ParseException, + ClientProtocolException, IOException, IllegalArgumentException, IllegalAccessException { final Request request = this.getRequestFactory().createAnalyzeUploadedApplication(uploadToken, UUID); final String response = this.getRequestFactory().send(request); @@ -158,22 +169,28 @@ public String analyzeUploadedApplication(final String uploadToken, final String else { String changedApp = null; if(appName != null && !appName.equals("")) { - changedApp = changeApplicationName(response, appName); + APIObject.Name apiObjectName = new APIObject.Name(); + apiObjectName.setDe_DE(appName); + apiObjectName.setEn_US(appName); + changedApp = changeAPIObject(response, apiObjectName, null, null); } JsonParser jsonReleaseStatusParser = new JsonParser(); if(changedApp != null) { if(releaseStatus != null && !releaseStatus.equals("")) { - changedApp = changeReleaseStatus(changedApp, releaseStatus); + changedApp = changeAPIObject(changedApp, new APIObject.Versions(), "releaseStatus", releaseStatus); } } else { if(releaseStatus != null && !releaseStatus.equals("")) { - changedApp = changeReleaseStatus(response, releaseStatus); + changedApp = changeAPIObject(response, new APIObject.Versions(), "releaseStatus", releaseStatus); } } - if(appIcon != null && !appIcon.equals("") || appReleaseNotes != null && !appReleaseNotes.equals("")) { + if(appIcon != null && !appIcon.equals("") || + appReleaseNotes != null && !appReleaseNotes.equals("") || + appDescription != null && !appDescription.equals("")) { File applicationIconFile = null; File applicationReleaseNotes = null; + File applicationDescription = null; DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(fileSet.getDir()); scanner.setCaseSensitive(false); @@ -185,7 +202,12 @@ public String analyzeUploadedApplication(final String uploadToken, final String final String uploadedIconUUID = communicator.uploadApplicationAsset("", applicationIconFile); Request iconRequest = communicator.getRequestFactory().createUploadRequest(uploadedIconUUID, applicationIconFile); final String iconResponse = communicator.getRequestFactory().send(iconRequest); - changedApp = changeApplicationIcon(iconResponse, changedApp); + + //parse the icon out of the json returned by the communicator + Type collectionType = new TypeToken>(){}.getType(); + Collection uploadedIconCollection = new Gson().fromJson(((JsonObject)new JsonParser().parse(iconResponse)).get("results").toString(), collectionType); + APIObject.Icon changeIcon = (APIObject.Icon)uploadedIconCollection.toArray()[0]; + changedApp = changeAPIObject(changedApp, changeIcon, null, null); } if(includedFiles[i].equals(appReleaseNotes)) { applicationReleaseNotes = new File(scanner.getBasedir().getAbsolutePath() + File.separator + includedFiles[i]); @@ -193,7 +215,21 @@ public String analyzeUploadedApplication(final String uploadToken, final String if(log.length() > 256) { log = log.substring(0, 252) + "..."; } - changedApp = changeReleaseNotes(changedApp, log); + APIObject.Changelog changeLog = new APIObject.Changelog(); + changeLog.setDe_DE(log); + changeLog.setEn_US(log); + changedApp = changeAPIObject(changedApp, changeLog, null, null); + } + if(includedFiles[i].equals(appDescription)) { + applicationDescription = new File(scanner.getBasedir().getAbsolutePath() + File.separator + includedFiles[i]); + String description = download("file://" + applicationDescription.getAbsolutePath()); + if(description.length() > 256) { + description = description.substring(0, 252) + "..."; + } + APIObject.Description changeDescription = new APIObject.Description(); + changeDescription.setDe_DE(description); + changeDescription.setEn_US(description); + changedApp = changeAPIObject(changedApp, changeDescription, null, null); } } } @@ -203,6 +239,44 @@ public String analyzeUploadedApplication(final String uploadToken, final String } } + private static String changeAPIObject(String app, Object object, String fieldName, String newFieldValue) throws IllegalArgumentException, IllegalAccessException { + Gson gson = new Gson(); + APIObject apiObject = gson.fromJson(app, APIObject.class); + for (int index = 0; index < apiObject.getResults().size(); index++) { + APIObject.Results result = apiObject.getResults().get(index); + if (object instanceof APIObject.Versions) { + APIObject.Versions objectVersion = result.getVersions().get(index); + for (Field field : objectVersion.getClass().getDeclaredFields()) { + field.setAccessible(true); + String name = field.getName(); + if(name.equals(fieldName)) { + field.set(objectVersion, newFieldValue); + } + else { + Object value = field.get(objectVersion); + field.set(objectVersion, value); + } + } + } + for (int j = 0; j < result.getVersions().size(); j++) { + APIObject.Versions version = result.getVersions().get(j); + if (object instanceof APIObject.Description) { + version.setDescription((APIObject.Description) object); + } + if (object instanceof APIObject.Changelog) { + version.setChangelog((APIObject.Changelog) object); + } + if (object instanceof APIObject.Name) { + version.setName((APIObject.Name) object); + } + if (object instanceof APIObject.Icon) { + version.setIcon((APIObject.Icon) object); + } + } + } + return gson.toJson(apiObject); + } + private static String download(String url) throws java.io.IOException { java.io.InputStream s = null; String content = null; @@ -217,73 +291,6 @@ private static String download(String url) throws java.io.IOException { return content.toString(); } - private static String changeReleaseNotes(String app, String appReleaseStatus) { - Gson gson = new Gson(); - APIObject.Changelog changeLog = new APIObject.Changelog(); - changeLog.setDe_DE(appReleaseStatus); - changeLog.setEn_US(appReleaseStatus); - - APIObject apiObject = gson.fromJson(app, APIObject.class); - for(int index=0; index>(){}.getType(); - Collection uploadedIconCollection = gson.fromJson(jsonIcon, collectionType); - APIObject.Icon icon = (APIObject.Icon)uploadedIconCollection.toArray()[0]; - APIObject apiObject = gson.fromJson(apiObjectResponse, APIObject.class); - for(int i=0; i - - -
diff --git a/src/main/resources/org/jenkinsci/plugins/relution/RelutionPublisher/config.jelly b/src/main/resources/org/jenkinsci/plugins/relution/RelutionPublisher/config.jelly index 6184f30..dcc4895 100644 --- a/src/main/resources/org/jenkinsci/plugins/relution/RelutionPublisher/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/relution/RelutionPublisher/config.jelly @@ -40,6 +40,11 @@ title="Application change log file (optional)"> + + + diff --git a/src/main/webapp/help-gitDescription.html b/src/main/webapp/help-applicationDescription.html similarity index 100% rename from src/main/webapp/help-gitDescription.html rename to src/main/webapp/help-applicationDescription.html