Skip to content

Commit

Permalink
[JENKINS-61700] Windows upload needs required build_version parameter (
Browse files Browse the repository at this point in the history
…#50)

* Add buildVersion to pipeline syntax, validation and errors

* Add buildVersion to config.jelly

* Forgot to add DataBoundSetter

* [JENKINS-61700] Clarify level of support for Windows applications

Co-authored-by: Mez Pahlan <[email protected]>
  • Loading branch information
mythsunwind and mezpahlan authored May 16, 2020
1 parent a716606 commit 65a909f
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/main/java/io/jenkins/plugins/appcenter/AppCenterRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.jenkins.plugins.appcenter.task.UploadTask;
import io.jenkins.plugins.appcenter.validator.ApiTokenValidator;
import io.jenkins.plugins.appcenter.validator.AppNameValidator;
import io.jenkins.plugins.appcenter.validator.BuildVersionValidator;
import io.jenkins.plugins.appcenter.validator.DistributionGroupsValidator;
import io.jenkins.plugins.appcenter.validator.PathPlaceholderValidator;
import io.jenkins.plugins.appcenter.validator.PathToAppValidator;
Expand Down Expand Up @@ -64,6 +65,9 @@ public final class AppCenterRecorder extends Recorder implements SimpleBuildStep

private boolean notifyTesters = true;

@Nullable
private String buildVersion;

@Nullable
private String pathToDebugSymbols;

Expand Down Expand Up @@ -116,6 +120,11 @@ public boolean getNotifyTesters() {
return notifyTesters;
}

@Nonnull
public String getBuildVersion() {
return Util.fixNull(buildVersion);
}

@Nonnull
public String getPathToDebugSymbols() {
return Util.fixNull(pathToDebugSymbols);
Expand All @@ -136,6 +145,11 @@ public void setNotifyTesters(boolean notifyTesters) {
this.notifyTesters = notifyTesters;
}

@DataBoundSetter
public void setBuildVersion(@Nullable String buildVersion) {
this.buildVersion = Util.fixEmpty(buildVersion);
}

@DataBoundSetter
public void setPathToDebugSymbols(@Nullable String pathToDebugSymbols) {
this.pathToDebugSymbols = Util.fixEmpty(pathToDebugSymbols);
Expand Down Expand Up @@ -273,6 +287,21 @@ public FormValidation doCheckDistributionGroups(@QueryParameter String value) {
return FormValidation.ok();
}

@SuppressWarnings("unused")
public FormValidation doCheckBuildVersion(@QueryParameter String value) {
if (value.trim().isEmpty()) {
return FormValidation.ok();
}

final Validator buildVersionValidator = new BuildVersionValidator();

if (!buildVersionValidator.isValid(value)) {
return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_invalidBuildVersion());
}

return FormValidation.ok();
}

@SuppressWarnings("unused")
public FormValidation doCheckPathToDebugSymbols(@QueryParameter String value) {
if (value.trim().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static UploadRequest provideUploadRequest(AppCenterRecorder appCenterRecorder, E
.setReleaseNotes(envVars.expand(appCenterRecorder.getReleaseNotes()))
.setPathToReleaseNotes(envVars.expand(appCenterRecorder.getPathToReleaseNotes()))
.setNotifyTesters(appCenterRecorder.getNotifyTesters())
.setBuildVersion(envVars.expand(appCenterRecorder.getBuildVersion()))
.setPathToDebugSymbols(envVars.expand(appCenterRecorder.getPathToDebugSymbols()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private CompletableFuture<UploadRequest> createUploadResourceForApp(@Nonnull Upl
final CompletableFuture<UploadRequest> future = new CompletableFuture<>();

// TODO: Pass in the release_id as an optional parameter from the UI. Don't use it if not available
final ReleaseUploadBeginRequest releaseUploadBeginRequest = new ReleaseUploadBeginRequest(null, null, null);
final ReleaseUploadBeginRequest releaseUploadBeginRequest = new ReleaseUploadBeginRequest(null, request.buildVersion, null);
factory.createAppCenterService()
.releaseUploadsCreate(request.ownerName, request.appName, releaseUploadBeginRequest)
.whenComplete((releaseUploadBeginResponse, throwable) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public final class UploadRequest implements Serializable {
public final String pathToReleaseNotes;
public final boolean notifyTesters;
@Nonnull
public final String buildVersion;
@Nonnull
public final String pathToDebugSymbols;

// Properties above this line are expected to be set by plugin configuration before a run they should be nonnull.
Expand Down Expand Up @@ -54,6 +56,7 @@ public String toString() {
", releaseNotes='" + releaseNotes + '\'' +
", pathToReleaseNotes='" + pathToReleaseNotes + '\'' +
", notifyTesters=" + notifyTesters +
", buildVersion='" + buildVersion + '\'' +
", pathToDebugSymbols='" + pathToDebugSymbols + '\'' +
", uploadUrl='" + uploadUrl + '\'' +
", uploadId='" + uploadId + '\'' +
Expand All @@ -76,6 +79,7 @@ public boolean equals(Object o) {
destinationGroups.equals(that.destinationGroups) &&
releaseNotes.equals(that.releaseNotes) &&
pathToReleaseNotes.equals(that.pathToReleaseNotes) &&
buildVersion.equals(that.buildVersion) &&
pathToDebugSymbols.equals(that.pathToDebugSymbols) &&
Objects.equals(uploadUrl, that.uploadUrl) &&
Objects.equals(uploadId, that.uploadId) &&
Expand All @@ -87,7 +91,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(ownerName, appName, pathToApp, destinationGroups, releaseNotes, pathToReleaseNotes, notifyTesters, pathToDebugSymbols, uploadUrl, uploadId, releaseId, symbolUploadRequest, symbolUploadUrl, symbolUploadId);
return Objects.hash(ownerName, appName, pathToApp, destinationGroups, releaseNotes, pathToReleaseNotes, notifyTesters, buildVersion, pathToDebugSymbols, uploadUrl, uploadId, releaseId, symbolUploadRequest, symbolUploadUrl, symbolUploadId);
}

private UploadRequest(Builder builder) {
Expand All @@ -98,6 +102,7 @@ private UploadRequest(Builder builder) {
this.releaseNotes = builder.releaseNotes;
this.pathToReleaseNotes = builder.pathToReleaseNotes;
this.notifyTesters = builder.notifyTesters;
this.buildVersion = builder.buildVersion;
this.pathToDebugSymbols = builder.pathToDebugSymbols;

// Expected to be nullable until they are added during UploadTask.
Expand Down Expand Up @@ -129,6 +134,8 @@ public static final class Builder {
private String pathToReleaseNotes;
private boolean notifyTesters;
@Nonnull
private String buildVersion;
@Nonnull
private String pathToDebugSymbols;

// Expected to be nullable until they are added during UploadTask.
Expand All @@ -153,6 +160,7 @@ public Builder() {
releaseNotes = "";
pathToReleaseNotes = "";
notifyTesters = true;
buildVersion = "";
pathToDebugSymbols = "";
}

Expand All @@ -164,6 +172,7 @@ public Builder() {
this.releaseNotes = uploadRequest.releaseNotes;
this.pathToReleaseNotes = uploadRequest.pathToReleaseNotes;
this.notifyTesters = uploadRequest.notifyTesters;
this.buildVersion = uploadRequest.buildVersion;
this.pathToDebugSymbols = uploadRequest.pathToDebugSymbols;

// Expected to be nullable until they are added during UploadTask.
Expand Down Expand Up @@ -210,6 +219,11 @@ public Builder setNotifyTesters(boolean notifyTesters) {
return this;
}

public Builder setBuildVersion(@Nonnull String buildVersion) {
this.buildVersion = buildVersion;
return this;
}

public Builder setPathToDebugSymbols(@Nonnull String pathToDebugSymbols) {
this.pathToDebugSymbols = pathToDebugSymbols;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.jenkins.plugins.appcenter.validator;

import java.util.function.Predicate;

import javax.annotation.Nonnull;

public final class BuildVersionValidator extends Validator {

@Nonnull
@Override
protected Predicate<String> predicate() {
return value -> !value.contains(" ");
}

}
2 changes: 1 addition & 1 deletion src/main/resources/index.jelly
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
Upload new versions of your Android, iOS, and MacOS applications to AppCenter.
Upload new versions of your Android, iOS, MacOS, and (limited) Windows applications to AppCenter.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<f:checkbox name="notifyTesters" default="true"/>
</f:entry>

<f:entry title="${%Build version}" field="buildVersion"
description="${%Optional, version string for the build.}">
<f:textbox/>
</f:entry>

<f:entry title="${%Path To Debug Symbols}" field="pathToDebugSymbols"
description="${%Optional, relative path to debug symbols.}">
<f:textbox/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<p>
<strong>NOTE:</strong> Build version might be mandatory on certain platform releases. Supports variable substitution.
</p>
<hr/>
<p>
For example: <code>1.2.0</code> or <code>${version}</code>
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ AppCenterRecorder.DescriptorImpl.errors.missingDistributionGroups=Please specify
AppCenterRecorder.DescriptorImpl.errors.invalidDistributionGroups=Distribution Groups cannot be empty
AppCenterRecorder.DescriptorImpl.errors.missingPathToApp=Please specify a path to the app you wish to upload
AppCenterRecorder.DescriptorImpl.errors.invalidPath=Invalid path
AppCenterRecorder.DescriptorImpl.errors.invalidBuildVersion=Build version cannot contain whitespace
AppCenterRecorder.DescriptorImpl.DisplayName=Upload app to AppCenter
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void setUp() throws IOException {
envVars.put("OWNER_NAME", "janes-addiction");
envVars.put("APP_NAME", "ritual-de-lo-habitual");
envVars.put("PATH_TO_APP", "three/days/xiola.ipa");
envVars.put("BUILD_VERSION", "1.2.3");
envVars.put("PATH_TO_DEBUG_SYMBOLS", "three/days/blue.zip");
envVars.put("DISTRIBUTION_GROUPS", "casey, niccoli");
envVars.put("RELEASE_NOTES", "I miss you my dear Xiola");
Expand All @@ -55,6 +56,7 @@ public void setUp() throws IOException {
"${PATH_TO_APP}",
"${DISTRIBUTION_GROUPS}"
);
appCenterRecorder.setBuildVersion("${BUILD_VERSION}");
appCenterRecorder.setPathToDebugSymbols("${PATH_TO_DEBUG_SYMBOLS}");
appCenterRecorder.setReleaseNotes("${RELEASE_NOTES}");
appCenterRecorder.setPathToReleaseNotes("${PATH_TO_RELEASE_NOTES}");
Expand Down

0 comments on commit 65a909f

Please sign in to comment.