Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-67450 #86

Merged
merged 6 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/main/java/io/jenkins/plugins/dotnet/DotNetSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public DotNetSDK(@NonNull String name, @NonNull String home, @CheckForNull List<
private boolean telemetryOptOut = true;

/**
* Determines whether or not the telemetry opt-out is set.
* Determines whether the telemetry opt-out is set.
*
* @return {@code true} when the telemetry opt-out is set; {@code false} otherwise.
*/
Expand All @@ -85,7 +85,7 @@ public boolean isTelemetryOptOut() {
}

/**
* Determines whether or not the telemetry opt-out should be set.
* Determines whether the telemetry opt-out should be set.
*
* @param telemetryOptOut {@code true} to opt out of telemetry; {@code false} otherwise.
*/
Expand Down Expand Up @@ -180,6 +180,7 @@ public boolean createGlobalJson(@NonNull FilePath dir, @NonNull TaskListener lis
* @param launcher The launcher to use for the verification.
*
* @return The full path to the {@code dotnet} executable in this .NET SDK installation.
*
* @throws AbortException When the executable could not be found.
* @throws IOException When an I/O error occurs.
* @throws InterruptedException When processing is interrupted.
Expand Down Expand Up @@ -257,7 +258,7 @@ public FilePath getHomePath(@CheckForNull VirtualChannel channel) {
}

/**
* Determines whether or not any .NET SDKs have been configured.
* Determines whether any .NET SDKs have been configured.
*
* @return {@code true} when at least one .NET SDK has been configured; otherwise, {@code false}.
*/
Expand Down Expand Up @@ -355,6 +356,7 @@ public String getDisplayName() {
* @param listener The task listener to use.
*
* @return The requested .NET SDK installation.
*
* @throws AbortException When the SDK installation could not be set up.
* @throws IOException Then an I/O error occurs.
* @throws InterruptedException When processing is interrupted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public DotNetSDKInstaller(@CheckForNull String label) {
* @param log The task listener to use for output.
*
* @return The SDK's installation location.
*
* @throws IOException When an I/O error occurs during processing.
* @throws InterruptedException When processing is interrupted.
*/
Expand Down Expand Up @@ -72,7 +73,7 @@ public FilePath performInstallation(@NonNull ToolInstallation tool, @NonNull Nod
private boolean includePreview;

/**
* Determines whether or not .NET preview releases should be made available for installation.
* Determines whether .NET preview releases should be made available for installation.
*
* @return {@code true} if installation of .NET preview releases is allowed, {@code false} otherwise.
*/
Expand All @@ -81,7 +82,7 @@ public boolean isIncludePreview() {
}

/**
* Determines whether or not .NET preview releases should be made available for installation.
* Determines whether .NET preview releases should be made available for installation.
*
* @param includePreview {@code true} to allow installation of .NET preview releases, {@code false} otherwise.
*/
Expand Down Expand Up @@ -327,7 +328,7 @@ public ListBoxModel doFillUrlItems(@CheckForNull @QueryParameter String sdk) {
* Fills a listbox with the names of .NET releases.
*
* @param version The name of the .NET version containing the releases.
* @param includePreview Indicates whether or not preview releases should be included.
* @param includePreview Indicates whether preview releases should be included.
*
* @return A suitably filled listbox model.
*/
Expand Down Expand Up @@ -374,7 +375,7 @@ public String getDisplayName() {
}

/**
* Determines whether or not this installer is applicable for the specified type of tool.
* Determines whether this installer is applicable for the specified type of tool.
*
* @param toolType The type of tool to install.
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/jenkins/plugins/dotnet/DotNetWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public boolean isSpecificSdkVersion() {
* most recent SDK version available on the system; with this set, a {@code global.json} file will be created to ensure a specific
* SDK version gets used.
*
* @param specificSdkVersion {@code true} if {@code global.json} should be used to ensure a specific SDK version gets used;
* {@code false} otherwise.
* @param specificSdkVersion {@code true} if {@code global.json} should be used to ensure a specific SDK version gets used; {@code
* false} otherwise.
*/
@DataBoundSetter
public void setSpecificSdkVersion(boolean specificSdkVersion) {
Expand Down Expand Up @@ -199,7 +199,7 @@ public String getDisplayName() {
}

/**
* Determines whether or not the .NET wrapper is applicable.
* Determines whether the .NET wrapper is applicable.
*
* @param item The project context.
*
Expand Down
73 changes: 56 additions & 17 deletions src/main/java/io/jenkins/plugins/dotnet/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static DotNetSDK.DescriptorImpl getSdkDescriptor() throws AbortException
*/
@Override
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull EnvVars env, @NonNull Launcher launcher, @NonNull TaskListener listener) throws InterruptedException, IOException {
final Charset cs = run.getCharset();
final Charset cs = this.charset == null ? run.getCharset() : Charset.forName(this.charset);
final DotNetSDK sdkInstance;
if (this.sdk == null)
sdkInstance = null;
Expand Down Expand Up @@ -121,12 +121,17 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
launcher.launch().cmds(cmdLine).envs(env).stdout(scanner).pwd(workspace).join();
}
// TODO: Maybe also add configuration to set the build as either failed or unstable based on return code
if (rc != 0)
run.setResult(Result.FAILURE);
else if (scanner.getErrors() > 0)
run.setResult(Result.FAILURE);
else if (this.unstableIfWarnings && scanner.getWarnings() > 0)
run.setResult(Result.UNSTABLE);
if (scanner.getErrors() > 0) {
run.setResult(this.unstableIfErrors ? Result.UNSTABLE : Result.FAILURE);
}
else {
if (this.unstableIfWarnings && scanner.getWarnings() > 0) {
run.setResult(Result.UNSTABLE);
}
if (rc != 0) {
run.setResult(Result.FAILURE);
}
}
}
catch (Throwable t) {
Functions.printStackTrace(t, listener.fatalError(Messages.Command_ExecutionFailed()));
Expand All @@ -140,6 +145,32 @@ else if (this.unstableIfWarnings && scanner.getWarnings() > 0)

//region Properties

/** A specific charset to use for the command's output. If {@code null}, the build's default charset will be used. */
@CheckForNull
private String charset = null;

/**
* Gets the specific charset to use for the command's output.
*
* @return The specific charset to use for the command's output, or {@code null} to indicate that the build's default charset
* should be used.
*/
@CheckForNull
public String getCharset() {
return this.charset;
}

/**
* Sets the specific charset to use for the command's output.
*
* @param charset The specific charset to use for the command's output, or {@code null} to indicate that the build's default
* charset should be used.
*/
@DataBoundSetter
public void setCharset(@CheckForNull String charset) {
this.charset = Util.fixEmptyAndTrim(charset);
}

/** The name of the SDK to use. */
@CheckForNull
protected String sdk;
Expand All @@ -164,20 +195,21 @@ public void setSdk(@CheckForNull String sdk) {
this.sdk = Util.fixEmpty(sdk);
}

/** Flag indicating whether or not SDK information should be shown. */
/** Flag indicating whether SDK information should be shown. */
protected boolean showSdkInfo = false;

/**
* Determines whether or not SDK information should be shown.
* Determines whether SDK information should be shown.
*
* @return {@code true} if "{@code dotnet --info}" should be run before the main command; {@code false} otherwise.
*/
@SuppressWarnings("unused")
public boolean isShowSdkInfo() {
return this.showSdkInfo;
}

/**
* Determines whether or not SDK information should be shown.
* Determines whether SDK information should be shown.
*
* @param showSdkInfo {@code true} if "{@code dotnet --info}" should be run before the main command; {@code false} otherwise.
*/
Expand All @@ -186,35 +218,40 @@ public void setShowSdkInfo(boolean showSdkInfo) {
this.showSdkInfo = showSdkInfo;
}

/** Flag indicating whether or not any build servers started by the main command should be shut down. */
/** Flag indicating whether any build servers started by the main command should be shut down. */
protected boolean shutDownBuildServers = false;

/** Flag indicating whether or not a specific SDK version should be used. */
/** Flag indicating whether a specific SDK version should be used. */
private boolean specificSdkVersion = false;

/**
* Determines whether or not a specific SDK version should be used.
* Determines whether a specific SDK version should be used.
*
* @return {@code true} if a {@code global.json} should be created to force the use of the configured .NET SDK (as opposed to
* a more recent one that happens to be installed on the build agent); {@code false} otherwise.
* @return {@code true} if a {@code global.json} should be created to force the use of the configured .NET SDK (as opposed to a
* more recent one that happens to be installed on the build agent); {@code false} otherwise.
*/
@SuppressWarnings("unused")
public boolean isSpecificSdkVersion() {
return this.specificSdkVersion;
}

/**
* Determines whether or not a specific SDK version should be used.
* Determines whether a specific SDK version should be used.
*
* @param specificSdkVersion {@code true} if a {@code global.json} should be created to force the use of the configured .NET SDK
* (as opposed to a more recent one that happens to be installed on the build agent); {@code false}
* otherwise.
*/
@DataBoundSetter
@SuppressWarnings("unused")
public void setSpecificSdkVersion(boolean specificSdkVersion) {
this.specificSdkVersion = specificSdkVersion;
}

/** Flag indicating whether or not the presence of warnings makes the build unstable. */
/** Flag indicating whether the presence of errors makes the build unstable (instead of failed). */
protected boolean unstableIfErrors = false;

/** Flag indicating whether the presence of warnings makes the build unstable (instead of successful). */
protected boolean unstableIfWarnings = false;

/** The working directory to use for the command. This directory is <em>not</em> created by the command execution. */
Expand All @@ -227,6 +264,7 @@ public void setSpecificSdkVersion(boolean specificSdkVersion) {
* @return The working directory to use for the command.
*/
@CheckForNull
@SuppressWarnings("unused")
public String getWorkDirectory() {
return this.workDirectory;
}
Expand All @@ -237,6 +275,7 @@ public String getWorkDirectory() {
* @param workDirectory The working directory to use for the command.
*/
@DataBoundSetter
@SuppressWarnings("unused")
public void setWorkDirectory(@CheckForNull String workDirectory) {
this.workDirectory = Util.fixEmpty(workDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import hudson.model.AbstractProject;
import hudson.model.AutoCompletionCandidates;
import hudson.tasks.BuildStepDescriptor;
Expand All @@ -14,6 +15,9 @@
import org.jenkinsci.plugins.structs.describable.CustomDescribableModel;
import org.kohsuke.stapler.QueryParameter;

import java.nio.charset.Charset;
import java.util.Set;

/** A descriptor for a .NET command. */
public abstract class CommandDescriptor extends BuildStepDescriptor<Builder> implements CustomDescribableModel {

Expand Down Expand Up @@ -87,6 +91,28 @@ public final AutoCompletionCandidates doAutoCompleteRuntimesString(@CheckForNull
return Runtime.getInstance().autoCompleteIdentifier(value);
}

/**
* Performs validation on a Java charset name.
*
* @param value The value to validate.
*
* @return The result of the validation.
*/
@SuppressWarnings("unused")
@NonNull
public FormValidation doCheckCharset(@CheckForNull @QueryParameter String value) {
final String name = Util.fixEmptyAndTrim(value);
if (name != null) {
try {
Charset.forName(value);
}
catch (Throwable t) {
return FormValidation.error(Messages.Command_UnsupportedCharset());
}
}
return FormValidation.ok();
}

/**
* Performs validation on a .NET target framework moniker.
*
Expand Down Expand Up @@ -139,6 +165,29 @@ public FormValidation doCheckRuntimesString(@CheckForNull @QueryParameter String
return Runtime.getInstance().checkIdentifiers(value);
}

/**
* Fills a listbox with the names of charsets supported by the running version of Java.
*
* @return A suitably filled listbox model.
*/
@SuppressWarnings("unused")
@NonNull
public final ListBoxModel doFillCharsetItems() {
final ListBoxModel model = new ListBoxModel();
model.add(Messages.Command_SameCharsetAsBuild(), "");
for (final Charset cs : Charset.availableCharsets().values()) {
final Set<String> aliases = cs.aliases();
final String name = cs.displayName();
if (aliases == null || aliases.isEmpty()) {
model.add(name);
}
else {
model.add(String.format("%s (%s)", name, String.join(" / ", aliases)), name);
}
}
return model;
}

/**
* Fills a listbox with the names of .NET SDKs that have been defined as global tools.
*
Expand Down Expand Up @@ -183,7 +232,7 @@ public final String getMoreOptions() {
}

/**
* Determines whether or not this descriptor is applicable for the specified job type.
* Determines whether this descriptor is applicable for the specified job type.
*
* @param jobType The job type.
*
Expand Down
Loading