-
-
Notifications
You must be signed in to change notification settings - Fork 107
findbugs: fix issues in BuildData #44
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,17 +26,15 @@ | |
|
|
||
| import hudson.model.Action; | ||
| import hudson.model.Environment; | ||
| import hudson.model.Executor; | ||
| import hudson.model.Result; | ||
| import hudson.model.AbstractBuild; | ||
| import hudson.model.TaskListener; | ||
| import hudson.model.Run; | ||
| import hudson.model.Node; | ||
| import hudson.model.Executor; | ||
| import hudson.tasks.test.AbstractTestResultAction; | ||
| import hudson.tasks.test.TestResult; | ||
|
|
||
| import java.text.DateFormat; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.ArrayList; | ||
| import java.util.Calendar; | ||
| import java.util.Collections; | ||
|
|
@@ -53,6 +51,7 @@ | |
| import net.sf.json.JSONObject; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
| import org.apache.commons.lang.time.FastDateFormat; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
|
|
@@ -65,7 +64,7 @@ | |
| */ | ||
| public class BuildData { | ||
| // ISO 8601 date format | ||
| public transient static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); | ||
| public transient static final FastDateFormat DATE_FORMATTER = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); | ||
|
||
| private final static Logger LOGGER = Logger.getLogger(MethodHandles.lookup().lookupClass().getCanonicalName()); | ||
| public static class TestData { | ||
| int totalCount, skipCount, failCount, passCount; | ||
|
|
@@ -138,15 +137,6 @@ public TestData(Action action) { | |
| public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener listener) { | ||
| initData(build, currentTime); | ||
|
|
||
| Node node = build.getExecutor().getOwner().getNode(); | ||
| if (node == null) { | ||
| buildHost = "master"; | ||
| buildLabel = "master"; | ||
| } else { | ||
| buildHost = StringUtils.isBlank(node.getDisplayName()) ? "master" : node.getDisplayName(); | ||
| buildLabel = StringUtils.isBlank(node.getLabelString()) ? "master" : node.getLabelString(); | ||
| } | ||
|
|
||
| // build.getDuration() is always 0 in Notifiers | ||
| rootProjectName = build.getRootBuild().getProject().getName(); | ||
| rootFullProjectName = build.getRootBuild().getProject().getFullName(); | ||
|
|
@@ -186,15 +176,6 @@ public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener liste | |
| public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener) { | ||
| initData(build, currentTime); | ||
|
|
||
| Node node = build.getExecutor().getOwner().getNode(); | ||
| if (node == null) { | ||
| buildHost = "master"; | ||
| buildLabel = "master"; | ||
| } else { | ||
| buildHost = StringUtils.isBlank(node.getDisplayName()) ? "master" : node.getDisplayName(); | ||
| buildLabel = StringUtils.isBlank(node.getLabelString()) ? "master" : node.getLabelString(); | ||
| } | ||
|
|
||
| rootProjectName = projectName; | ||
| rootFullProjectName = fullProjectName; | ||
| rootProjectDisplayName = displayName; | ||
|
|
@@ -210,7 +191,24 @@ public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener) { | |
| } | ||
|
|
||
| private void initData(Run<?, ?> build, Date currentTime) { | ||
| result = build.getResult() == null ? null : build.getResult().toString(); | ||
|
|
||
| Executor executor = build.getExecutor(); | ||
| if (executor == null) { | ||
| buildHost = "master"; | ||
| buildLabel = "master"; | ||
| } else { | ||
| Node node = executor.getOwner().getNode(); | ||
| if (node == null) { | ||
| buildHost = "master"; | ||
| buildLabel = "master"; | ||
| } else { | ||
| buildHost = StringUtils.isBlank(node.getDisplayName()) ? "master" : node.getDisplayName(); | ||
| buildLabel = StringUtils.isBlank(node.getLabelString()) ? "master" : node.getLabelString(); | ||
| } | ||
| } | ||
|
|
||
| Result result = build.getResult(); | ||
| this.result = result == null ? null : result.toString(); | ||
| id = build.getId(); | ||
| projectName = build.getParent().getName(); | ||
| fullProjectName = build.getParent().getFullName(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure.. the addition of milliseconds can be a breaking change if somebody is parsing the date with a strict parser. I'd suggest extracting the format to configuration if you need the milis part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will leave the format as is for now. Making this configurable could be done with the refactoring of configuration