Skip to content

Commit

Permalink
Merge pull request #45 from casz/prettifyStepGenerator
Browse files Browse the repository at this point in the history
Prettify step generator and deprecate password
  • Loading branch information
tomasbjerre authored Jan 27, 2018
2 parents 07ff991 + 32a0702 commit 120ee1b
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 591 deletions.
56 changes: 9 additions & 47 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.23</version>
<version>3.2</version>
</parent>

<properties>
<java.level>7</java.level>
<jenkins.version>2.7.4</jenkins.version>
<hpi-plugin.version>1.115</hpi-plugin.version>
<jenkins-test-harness.version>2.19</jenkins-test-harness.version>
<findbugs.failOnError>false</findbugs.failOnError>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>

<artifactId>violation-comments-to-stash</artifactId>
Expand Down Expand Up @@ -63,23 +63,8 @@
</pluginRepository>
</pluginRepositories>

<distributionManagement>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/releases</url>
</repository>
<snapshotRepository>
<id>maven.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/snapshots</url>
</snapshotRepository>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -92,19 +77,6 @@
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>se.bjurr.gitchangelog</groupId>
<artifactId>git-changelog-maven-plugin</artifactId>
Expand Down Expand Up @@ -176,25 +148,9 @@ Changelog of Violation Comments to Bitbucket Server Plugin.
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
Expand Down Expand Up @@ -229,5 +185,11 @@ Changelog of Violation Comments to Bitbucket Server Plugin.
<version>2.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
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;

@Extension
@Symbol("ViolationsToBitbucketServer")
Expand All @@ -46,16 +20,11 @@ public final class ViolationsToBitbucketServerDescriptor extends BuildStepDescri
public ViolationsToBitbucketServerDescriptor() {
super(ViolationsToBitbucketServerRecorder.class);
load();
if (config == null
|| config.getViolationConfigs().size() != createNewConfig().getViolationConfigs().size()) {
config = createNewConfig();
if (config == null) {
config = new ViolationsToBitbucketServerConfig();
}
}

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

@Override
public String getDisplayName() {
return "Report Violations to Bitbucket Server";
Expand All @@ -66,11 +35,6 @@ public String getHelpFile() {
return super.getHelpFile();
}

/** Create new blank configuration. Used when job is created. */
public ViolationsToBitbucketServerConfig getNewConfig() {
return createNewConfig();
}

@Override
public boolean isApplicable(
@SuppressWarnings("rawtypes") final Class<? extends AbstractProject> jobType) {
Expand All @@ -81,51 +45,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);
}
}
Loading

0 comments on commit 120ee1b

Please sign in to comment.