Skip to content

Commit

Permalink
Provide descriptors and config jelly
Browse files Browse the repository at this point in the history
Begin work on deprecated password
  • Loading branch information
jetersen committed Jan 25, 2018
1 parent 82c791d commit ac7ee1d
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 416 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
package org.jenkinsci.plugins.jvctb;

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKETSERVERURL;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_COMMENTONLYCHANGEDCONTENT;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_COMMENTONLYCHANGEDCONTENTCONTEXT;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_CREATECOMMENTWITHALLSINGLEFILECOMMENTS;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_CREATESINGLEFILECOMMENTS;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_KEEP_OLD_COMMENTS;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_MINSEVERITY;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PASSWORD;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PATTERN;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PROJECTKEY;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PULLREQUESTID;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_REPORTER;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_REPOSLUG;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_USERNAME;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_USERNAMEPASSWORDCREDENTIALSID;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_USEUSERNAMEPASSWORD;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_USEUSERNAMEPASSWORDCREDENTIALS;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.createNewConfig;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;
import hudson.util.ListBoxModel;

import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.jvctb.config.CredentialsHelper;
import org.jenkinsci.plugins.jvctb.config.ViolationConfig;
import org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfig;
import org.kohsuke.stapler.StaplerRequest;

import se.bjurr.violations.lib.model.SEVERITY;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_MINSEVERITY;
import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.createNewConfig;

@Extension
@Symbol("ViolationsToBitbucketServer")
Expand All @@ -52,10 +27,6 @@ public ViolationsToBitbucketServerDescriptor() {
}
}

public ListBoxModel doFillUsernamePasswordCredentialsIdItems() {
return CredentialsHelper.doFillUsernamePasswordCredentialsIdItems();
}

@Override
public String getDisplayName() {
return "Report Violations to Bitbucket Server";
Expand All @@ -81,51 +52,14 @@ public boolean isApplicable(
@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData)
throws hudson.model.Descriptor.FormException {
final ViolationsToBitbucketServerConfig config = createNewConfig();
config.setBitbucketServerUrl(formData.getString(FIELD_BITBUCKETSERVERURL));
config.setRepoSlug(formData.getString(FIELD_REPOSLUG));
config.setProjectKey(formData.getString(FIELD_PROJECTKEY));
config.setPullRequestId(formData.getString(FIELD_PULLREQUESTID));

config.setUseUsernamePassword(formData.getBoolean(FIELD_USEUSERNAMEPASSWORD));
config.setUsername(formData.getString(FIELD_USERNAME));
config.setPassword(formData.getString(FIELD_PASSWORD));

config.setUseUsernamePasswordCredentials(
formData.getBoolean(FIELD_USEUSERNAMEPASSWORDCREDENTIALS));
config.setUsernamePasswordCredentialsId(
formData.getString(FIELD_USERNAMEPASSWORDCREDENTIALSID));

config.setCreateCommentWithAllSingleFileComments(
formData.getString(FIELD_CREATECOMMENTWITHALLSINGLEFILECOMMENTS).equalsIgnoreCase("true"));

config.setCreateSingleFileComments(
formData.getString(FIELD_CREATESINGLEFILECOMMENTS).equalsIgnoreCase("true"));
config.setCommentOnlyChangedContent(
formData.getString(FIELD_COMMENTONLYCHANGEDCONTENT).equalsIgnoreCase("true"));
config.setCommentOnlyChangedContentContext(
formData.getInt(FIELD_COMMENTONLYCHANGEDCONTENTCONTEXT));

final String minSeverityString = formData.getString(FIELD_MINSEVERITY);
config.setKeepOldComments(formData.getString(FIELD_KEEP_OLD_COMMENTS).equalsIgnoreCase("true"));
if (!isNullOrEmpty(minSeverityString)) {
config.setMinSeverity(SEVERITY.valueOf(minSeverityString));
} else {
config.setMinSeverity(null);
if (formData != null) {
JSONObject config = formData.getJSONObject("config");
String minSeverity = config.getString(FIELD_MINSEVERITY);
if (StringUtils.isBlank(minSeverity)) {
config.remove(FIELD_MINSEVERITY);
}
}

int i = 0;
final List<String> patterns = (List<String>) formData.get(FIELD_PATTERN);
final List<String> reporters = (List<String>) formData.get(FIELD_REPORTER);
for (final String pattern : patterns) {
final ViolationConfig violationConfig = config.getViolationConfigs().get(i);
violationConfig.setPattern(pattern);
final String reporter = reporters.get(i);
violationConfig.setReporter(reporter);
i++;
}
final ViolationsToBitbucketServerRecorder publisher = new ViolationsToBitbucketServerRecorder();
publisher.setConfig(config);
return publisher;
return req.bindJSON(ViolationsToBitbucketServerRecorder.class, formData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import java.io.Serializable;

import org.jenkinsci.plugins.jvctb.config.CredentialsHelper;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

import com.google.common.base.Optional;

import hudson.Extension;
import hudson.util.ListBoxModel;
import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.jvctb.config.CredentialsHelper;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;
import se.bjurr.violations.lib.model.SEVERITY;

/** Created by magnayn on 07/04/2016. */
Expand All @@ -37,7 +37,7 @@ public static Optional<ViolationsToBitbucketServerGlobalConfiguration> get() {
public String repoSlug;
public String username;
private String usernamePasswordCredentialsId;
private SEVERITY minSeverity;
private SEVERITY minSeverity = SEVERITY.INFO;

public ViolationsToBitbucketServerGlobalConfiguration() {
load();
Expand All @@ -50,6 +50,17 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
return true;
}

public static final ListBoxModel TYPES = new ListBoxModel(
new ListBoxModel.Option("Info", SEVERITY.INFO.toString()),
new ListBoxModel.Option("Warning", SEVERITY.WARN.toString()),
new ListBoxModel.Option("Error", SEVERITY.ERROR.toString())
);

@Restricted(NoExternalUse.class)
public ListBoxModel doFillMinSeverityItems() {
return TYPES;
}

public ListBoxModel doFillUsernamePasswordCredentialsIdItems() {
return CredentialsHelper.doFillUsernamePasswordCredentialsIdItems();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package org.jenkinsci.plugins.jvctb;

import static hudson.tasks.BuildStepMonitor.NONE;
import static org.jenkinsci.plugins.jvctb.perform.JvctbPerformer.jvctsPerform;
import javax.annotation.Nonnull;
import java.io.IOException;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.TaskListener;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;

import java.io.IOException;

import javax.annotation.Nonnull;

import jenkins.tasks.SimpleBuildStep;

import org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfig;
import org.kohsuke.stapler.DataBoundConstructor;

import static hudson.tasks.BuildStepMonitor.NONE;
import static org.jenkinsci.plugins.jvctb.perform.JvctbPerformer.jvctsPerform;

public class ViolationsToBitbucketServerRecorder extends Recorder implements SimpleBuildStep {
@Extension
public static final BuildStepDescriptor<Publisher> DESCRIPTOR =
Expand All @@ -36,7 +34,7 @@ public ViolationsToBitbucketServerRecorder(ViolationsToBitbucketServerConfig con
}

public ViolationsToBitbucketServerConfig getConfig() {
return this.config;
return config;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.jenkinsci.plugins.jvctb.config;

import javax.annotation.Nonnull;
import java.io.Serializable;

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.util.ListBoxModel;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;

import se.bjurr.violations.lib.reports.Parser;

public class ViolationConfig implements Serializable {
public class ViolationConfig extends AbstractDescribableImpl<ViolationConfig> implements Serializable {
private static final long serialVersionUID = 6664329842273455651L;
private String pattern;
private String reporter;
Expand Down Expand Up @@ -100,4 +106,22 @@ public String toString() {
+ parser
+ "]";
}

@Extension
public static class DescriptorImpl extends Descriptor<ViolationConfig> {
@Nonnull
@Override
public String getDisplayName() {
return "Violations Parser Config";
}

@Restricted(NoExternalUse.class)
public ListBoxModel doFillParserItems() {
ListBoxModel items = new ListBoxModel();
for (Parser parser: Parser.values()) {
items.add(parser.name());
}
return items;
}
}
}
Loading

0 comments on commit ac7ee1d

Please sign in to comment.