-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from uber/taskify
Create NonDifferentialBuildTask to handle non-differential build invocations.
- Loading branch information
Showing
7 changed files
with
438 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/com/uber/jenkins/phabricator/tasks/NonDifferentialBuildTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) 2015 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package com.uber.jenkins.phabricator.tasks; | ||
|
||
import com.uber.jenkins.phabricator.CodeCoverageMetrics; | ||
import com.uber.jenkins.phabricator.uberalls.UberallsClient; | ||
import com.uber.jenkins.phabricator.utils.CommonUtils; | ||
import com.uber.jenkins.phabricator.utils.Logger; | ||
import hudson.plugins.cobertura.targets.CoverageResult; | ||
|
||
/** | ||
* Generic build task. | ||
*/ | ||
public class NonDifferentialBuildTask extends Task { | ||
|
||
protected UberallsClient uberallsClient; | ||
protected CodeCoverageMetrics codeCoverageMetrics; | ||
protected boolean uberallsEnabled; | ||
protected String commitSha; | ||
|
||
/** | ||
* GenericBuildTask constructor. | ||
* @param logger The logger. | ||
* @param uberallsClient The uberalls client. | ||
* @param codeCoverageMetrics The coverage metrics. | ||
* @param uberallsEnabled Whether uberalls is enabled. | ||
* @param commitSha The commit sha. | ||
*/ | ||
public NonDifferentialBuildTask(Logger logger, UberallsClient uberallsClient, | ||
CodeCoverageMetrics codeCoverageMetrics, boolean uberallsEnabled, | ||
String commitSha) { | ||
super(logger); | ||
this.uberallsClient = uberallsClient; | ||
this.codeCoverageMetrics = codeCoverageMetrics; | ||
this.uberallsEnabled = uberallsEnabled; | ||
this.commitSha = commitSha; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected String getTag() { | ||
return "non-differential"; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected void setup() { | ||
// Handle bad input. | ||
if (codeCoverageMetrics == null || !codeCoverageMetrics.isValid()) { | ||
info("Coverage result not found. Ignoring build."); | ||
result = Result.IGNORED; | ||
} else if (!uberallsEnabled || CommonUtils.isBlank(uberallsClient.getBaseURL())) { | ||
info("Uberalls not configured. Skipping build."); | ||
result = Result.SKIPPED; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected void execute() { | ||
if (result == Result.UNKNWON) { | ||
if (!CommonUtils.isBlank(commitSha)) { | ||
info(String.format("Sending coverage result for %s as %s", commitSha, | ||
codeCoverageMetrics.toString())); | ||
result = uberallsClient.recordCoverage(commitSha, codeCoverageMetrics) ? | ||
Result.SUCCESS : Result.FAILURE; | ||
} else { | ||
info("No line coverage found. Ignoring build."); | ||
result = Result.IGNORED; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected void tearDown() { | ||
// Do nothing. | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/com/uber/jenkins/phabricator/tasks/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2015 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package com.uber.jenkins.phabricator.tasks; | ||
|
||
import com.uber.jenkins.phabricator.utils.Logger; | ||
|
||
/** | ||
* Base task for all operations in the phabricator-jenkins plugin. | ||
*/ | ||
public abstract class Task { | ||
|
||
/** | ||
* Task results. | ||
*/ | ||
public enum Result { | ||
SUCCESS, | ||
FAILURE, | ||
IGNORED, // For incorrect input. | ||
SKIPPED, // For incorrect configuration. | ||
UNKNWON | ||
}; | ||
|
||
protected Result result = Result.UNKNWON; | ||
private Logger logger; | ||
|
||
/** | ||
* Task constructor. | ||
* @param logger The logger where logs go to. | ||
*/ | ||
public Task(Logger logger) { | ||
this.logger = logger; | ||
} | ||
|
||
/** | ||
* Runs the task workflow. | ||
*/ | ||
public Result run() { | ||
setup(); | ||
execute(); | ||
tearDown(); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Logs the message. | ||
* @param message The message to log. | ||
*/ | ||
protected void info(String message) { | ||
logger.info(getTag(), message); | ||
} | ||
|
||
/** | ||
* Gets the task's tag. | ||
* @return A string representation of this task's tag. | ||
*/ | ||
protected abstract String getTag(); | ||
|
||
/** | ||
* Sets up the environment before task execution. | ||
*/ | ||
protected abstract void setup(); | ||
|
||
/** | ||
* Executes the task workflow. | ||
*/ | ||
protected abstract void execute(); | ||
|
||
/** | ||
* Tears down after task execution. | ||
*/ | ||
protected abstract void tearDown(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.