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

Add pipeline support #7

Merged
merged 22 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<!-- Jenkins Plug-in Dependencies Versions -->
<plugin-util-api.version>1.2.2</plugin-util-api.version>
<workflow-step-api.version>2.22</workflow-step-api.version>
</properties>

<licenses>
Expand Down Expand Up @@ -54,6 +55,11 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow-step-api.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
42 changes: 38 additions & 4 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksAction.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
package io.jenkins.plugins.checks.api;

import java.io.Serializable;
import java.util.Optional;

import edu.umd.cs.findbugs.annotations.Nullable;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractDescribableImpl;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* An action of a check. It can be used to create actions like re-run or automatic formatting.
*/
@Restricted(Beta.class)
public class ChecksAction {
private final String label;
private final String description;
private final String identifier;
@SuppressWarnings("PMD.DataClass")
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "Empty constructor used by stapler")
public class ChecksAction extends AbstractDescribableImpl<ChecksAction> implements Serializable {
private static final long serialVersionUID = 1L;

private String label;
private String description;
private String identifier;

/**
* Empty constructor used by stapler to support pipeline.
*/
@DataBoundConstructor
public ChecksAction() {
super();
}

/**
* Creates a {@link ChecksAction} using the given parameters.
Expand All @@ -35,11 +52,28 @@ public class ChecksAction {
@SuppressFBWarnings("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE")
public ChecksAction(@Nullable final String label, @Nullable final String description,
@Nullable final String identifier) {
super();

this.label = label;
this.description = description;
this.identifier = identifier;
}

@DataBoundSetter
public void setLabel(final String label) {
this.label = label;
}

@DataBoundSetter
public void setDescription(final String description) {
this.description = description;
}

@DataBoundSetter
public void setIdentifier(final String identifier) {
this.identifier = identifier;
}

public Optional<String> getLabel() {
return Optional.ofNullable(label);
}
Expand Down
106 changes: 85 additions & 21 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksAnnotation.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.jenkins.plugins.checks.api;

import java.io.Serializable;
import java.util.Optional;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractDescribableImpl;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import static java.util.Objects.*;

Expand All @@ -12,16 +17,41 @@
*/
@Restricted(Beta.class)
@SuppressWarnings("PMD.DataClass")
public class ChecksAnnotation {
private final String path;
private final Integer startLine;
private final Integer endLine;
private final ChecksAnnotationLevel annotationLevel;
private final String message;
private final Integer startColumn;
private final Integer endColumn;
private final String title;
private final String rawDetails;
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "Empty constructor used by stapler")
public class ChecksAnnotation extends AbstractDescribableImpl<ChecksAnnotation> implements Serializable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth separating our pipeline models from our API models?

So that they don't get polluted with all the setters etc required by stapler?

private static final long serialVersionUID = 1L;

private String path;
private Integer startLine;
private Integer endLine;
private ChecksAnnotationLevel annotationLevel;
private String message;
private Integer startColumn;
private Integer endColumn;
private String title;
private String rawDetails;

/**
* Empty constructor used by stapler to support pipeline.
*/
@DataBoundConstructor
public ChecksAnnotation() {
super();
}

/**
* Copy constructor.
*
* @param that
* the source
*/
public ChecksAnnotation(final ChecksAnnotation that) {
this(that.getPath().orElse(null), that.getStartLine().orElse(null), that.getEndLine().orElse(null),
that.getAnnotationLevel(), that.getMessage().orElse(null), that.getStartColumn().orElse(null),
that.getEndColumn().orElse(null), that.getTitle().orElse(null),
that.getRawDetails().orElse(null));
}

@SuppressWarnings("ParameterNumber")
private ChecksAnnotation(final String path,
Expand All @@ -31,6 +61,8 @@ private ChecksAnnotation(final String path,
final Integer startColumn, final Integer endColumn,
final String title,
final String rawDetails) {
super();

this.path = path;
this.startLine = startLine;
this.endLine = endLine;
Expand All @@ -42,17 +74,49 @@ private ChecksAnnotation(final String path,
this.rawDetails = rawDetails;
}

/**
* Copy constructor.
*
* @param that
* the source
*/
public ChecksAnnotation(final ChecksAnnotation that) {
this(that.getPath().orElse(null), that.getStartLine().orElse(null), that.getEndLine().orElse(null),
that.getAnnotationLevel(), that.getMessage().orElse(null), that.getStartColumn().orElse(null),
that.getEndColumn().orElse(null), that.getTitle().orElse(null),
that.getRawDetails().orElse(null));
@DataBoundSetter
public void setPath(final String path) {
this.path = path;
}

@DataBoundSetter
public void setStartLine(final int startLine) {
this.startLine = startLine;
}

@DataBoundSetter
public void setEndLine(final int endLine) {
this.endLine = endLine;
}

@DataBoundSetter
public void setAnnotationLevel(final String annotationLevel) {
this.annotationLevel = ChecksAnnotationLevel.valueOf(annotationLevel);
}

@DataBoundSetter
public void setMessage(final String message) {
this.message = message;
}

@DataBoundSetter
public void setStartColumn(final int startColumn) {
this.startColumn = startColumn;
}

@DataBoundSetter
public void setEndColumn(final int endColumn) {
this.endColumn = endColumn;
}

@DataBoundSetter
public void setTitle(final String title) {
this.title = title;
}

@DataBoundSetter
public void setRawDetails(final String rawDetails) {
this.rawDetails = rawDetails;
}

public Optional<String> getPath() {
Expand Down
42 changes: 38 additions & 4 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksImage.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
package io.jenkins.plugins.checks.api;

import java.io.Serializable;
import java.util.Optional;

import edu.umd.cs.findbugs.annotations.Nullable;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractDescribableImpl;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* An image of a check. Users may use a image to show the code coverage, issues trend, etc.
*/
@Restricted(Beta.class)
public class ChecksImage {
private final String alt;
private final String imageUrl;
private final String caption;
@SuppressWarnings("PMD.DataClass")
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "Empty constructor used by stapler")
public class ChecksImage extends AbstractDescribableImpl<ChecksImage> implements Serializable {
private static final long serialVersionUID = 1L;

private String alt;
private String imageUrl;
private String caption;

/**
* Empty constructor used by stapler to support pipeline.
*/
@DataBoundConstructor
public ChecksImage() {
super();
}

/**
* Constructs an image with all parameters.
Expand All @@ -29,11 +46,28 @@ public class ChecksImage {
*/
@SuppressFBWarnings("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE")
public ChecksImage(@Nullable final String alt, @Nullable final String imageUrl, @Nullable final String caption) {
super();

this.alt = alt;
this.imageUrl = imageUrl;
this.caption = caption;
}

@DataBoundSetter
public void setAlt(final String alt) {
this.alt = alt;
}

@DataBoundSetter
public void setImageUrl(final String imageUrl) {
this.imageUrl = imageUrl;
}

@DataBoundSetter
public void setCaption(final String caption) {
this.caption = caption;
}

/**
* Returns the alternative text for the image.
*
Expand Down
71 changes: 58 additions & 13 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package io.jenkins.plugins.checks.api;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractDescribableImpl;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import static java.util.Objects.*;

Expand All @@ -15,20 +20,24 @@
* annotations, etc.
*/
@Restricted(Beta.class)
public class ChecksOutput {
private final String title;
private final String summary;
private final String text;
private final List<ChecksAnnotation> annotations;
private final List<ChecksImage> images;
@SuppressWarnings("PMD.DataClass")
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "Empty constructor used by stapler")
public class ChecksOutput extends AbstractDescribableImpl<ChecksOutput> implements Serializable {
private static final long serialVersionUID = 1L;

private String title;
private String summary;
private String text;
private List<ChecksAnnotation> annotations;
private List<ChecksImage> images;

private ChecksOutput(final String title, final String summary, final String text,
final List<ChecksAnnotation> annotations, final List<ChecksImage> images) {
this.title = title;
this.summary = summary;
this.text = text;
this.annotations = annotations;
this.images = images;
/**
* Empty constructor used by stapler to support pipeline.
*/
@DataBoundConstructor
public ChecksOutput() {
super();
}

/**
Expand All @@ -42,6 +51,42 @@ public ChecksOutput(final ChecksOutput that) {
that.getChecksAnnotations(), that.getChecksImages());
}

private ChecksOutput(final String title, final String summary, final String text,
final List<ChecksAnnotation> annotations, final List<ChecksImage> images) {
super();

this.title = title;
this.summary = summary;
this.text = text;
this.annotations = annotations;
this.images = images;
}

@DataBoundSetter
public void setTitle(final String title) {
this.title = title;
}

@DataBoundSetter
public void setSummary(final String summary) {
this.summary = summary;
}

@DataBoundSetter
public void setText(final String text) {
this.text = text;
}

@DataBoundSetter
public void setAnnotations(final List<ChecksAnnotation> annotations) {
this.annotations = annotations;
}

@DataBoundSetter
public void setImages(final List<ChecksImage> images) {
this.images = images;
}

public Optional<String> getTitle() {
return Optional.ofNullable(title);
}
Expand Down
Loading