Skip to content

Commit

Permalink
Fixed: Configuration not saved, configuration scratched (#19)
Browse files Browse the repository at this point in the history
* Fixed: Configuration not saved, configuration scratched

- Fixes a bug where configuration do not get saved when the user hits Save in the Global Tool Config page.
- Fixes a bug where tool configuration is scratched on restart of Jenkins, i.e. would be set to the default value on restart.

* .gitignore improvemements

- Added .iml extension to ignores.
  • Loading branch information
rasmusjelsgaard authored and jetersen committed Feb 7, 2019
1 parent d527286 commit 45c4732
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.class
*.iml

# Package Files #
*.jar
Expand Down
@@ -1,22 +1,24 @@
package org.jenkinsci.plugins.vstest_runner;

import java.io.File;
import java.io.IOException;

import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.EnvVars;
import hudson.Extension;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.model.EnvironmentSpecific;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.slaves.NodeSpecific;
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolInstallation;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import hudson.model.TaskListener;
import hudson.model.Node;
import hudson.slaves.NodeSpecific;
import hudson.model.EnvironmentSpecific;
import jenkins.model.Jenkins;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;

/**
* @author Yasuyuki Saito
Expand Down Expand Up @@ -90,31 +92,17 @@ public static VsTestInstallation getDefaultInstallation() {

@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED)
public static void onLoaded() {
DescriptorImpl descriptor = (DescriptorImpl) Jenkins.getInstance().getDescriptor(VsTestInstallation.class);
VsTestInstallation[] installations = getInstallations(descriptor);

DescriptorImpl descriptor = (VsTestInstallation.DescriptorImpl) Jenkins.getInstance().getDescriptor(VsTestInstallation.class);
VsTestInstallation[] installations = descriptor.getInstallations();
if (installations != null && installations.length > 0) {
// No need to initialize if there's already something
return;
}


String defaultVSTestExe = isWindows() ? "vstest.console.exe" : "vstest.console";
VsTestInstallation tool = new VsTestInstallation(DEFAULT, defaultVSTestExe);
descriptor.setInstallations(tool);
descriptor.save();
}

private static VsTestInstallation[] getInstallations(DescriptorImpl descriptor) {
VsTestInstallation[] installations = null;
try {
installations = descriptor.getInstallations();
} catch (NullPointerException e) {
installations = new VsTestInstallation[0];
}
return installations;
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) Jenkins.getInstance().getDescriptorOrDie(getClass());
Expand All @@ -130,10 +118,23 @@ private static boolean isWindows() {
@Extension
public static class DescriptorImpl extends ToolDescriptor<VsTestInstallation> {

public DescriptorImpl() {
super();
load();
}

public String getDisplayName() {
return Messages.VsTestInstallation_DisplayName();
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) {
setInstallations(req.bindJSONToList(VsTestInstallation.class, json.get("tool"))
.toArray((VsTestInstallation[]) Array.newInstance(VsTestInstallation.class, 0)));
save();
return true;
}

@Nullable
public VsTestInstallation getInstallation(String name) {
for (VsTestInstallation i : getInstallations()) {
Expand Down

0 comments on commit 45c4732

Please sign in to comment.