1
0
Fork 0

Tidy up and add error option to logging

Formatted the files so far getting rid of theose pesky tabs. Also added the error logging options to the logging wrapper classes.
This commit is contained in:
Steven Cooney 2019-05-31 12:22:55 +01:00
parent 82ed9cc10b
commit 5f25b065aa
8 changed files with 144 additions and 146 deletions

View file

@ -1,8 +1,8 @@
package uk.xlab.teamcity.phabricator;
public class Constants {
public static final String BUILD_FEATURE_TYPE = "phabricator-build-feature";
public static final String PLUGIN_NAME = "phabricator";
public static final String PLUGIN_DISPLAY_NAME = "Phabricator Plugin";
public static final String PHABRICATOR_URL_SETTING = "phabricator_url_setting";
public static final String BUILD_FEATURE_TYPE = "phabricator-build-feature";
public static final String PLUGIN_NAME = "phabricator";
public static final String PLUGIN_DISPLAY_NAME = "Phabricator Plugin";
public static final String PHABRICATOR_URL_SETTING = "phabricator_url_setting";
}

View file

@ -1,6 +1,10 @@
package uk.xlab.teamcity.phabricator;
public interface IPhabricatorPluginLogger {
public void info(String message);
public void warn(String message, Exception e);
public void info(String message);
public void warn(String message, Exception e);
public void error(String message, Exception e);
}

View file

@ -4,13 +4,18 @@ import jetbrains.buildServer.log.Loggers;
public final class PhabricatorAgentLogger implements IPhabricatorPluginLogger {
@Override
public void info(String message) {
Loggers.AGENT.info(String.format("Phabricator Plugin: %s", message));
}
@Override
public void info(String message) {
Loggers.AGENT.info(String.format("Phabricator Plugin: %s", message));
}
@Override
@Override
public void warn(String message, Exception e) {
Loggers.AGENT.warn(String.format("Phabricator Plugin: %s", message), e);
}
@Override
public void error(String message, Exception e) {
Loggers.AGENT.error(String.format("Phabricator Plugin: %s", message), e);
}
}

View file

@ -3,43 +3,41 @@ package uk.xlab.teamcity.phabricator;
import java.util.Map;
/**
* Holds all the parameters set on the build applied by the
* harbormaster trigger from phabricator. It also has the
* methods used to communicate the build result back to
* harbormaster
* Holds all the parameters set on the build applied by the harbormaster trigger
* from phabricator. It also has the methods used to communicate the build
* result back to harbormaster
*
* @author steven.cooney
*
*/
public class PhabricatorPluginConfig {
private IPhabricatorPluginLogger logger;
private Map<String, String> params;
/**
* Set the appropriate logger depending if the class is
* called from the SERVER or AGENT
*
* @param logger
*/
public void setLogger(PhabricatorServerLogger logger) {
this.logger = logger;
}
/**
* Take a copy of all build parameters which will then
* be parsed
*
* @param parameters
*/
public void setParameters(Map<String, String> parameters) {
params = parameters;
private IPhabricatorPluginLogger logger;
private Map<String, String> params;
/**
* Set the appropriate logger depending if the class is called from the SERVER
* or AGENT
*
* @param logger
*/
public void setLogger(PhabricatorServerLogger logger) {
this.logger = logger;
}
/**
* Take a copy of all build parameters which will then be parsed
*
* @param parameters
*/
public void setParameters(Map<String, String> parameters) {
params = parameters;
logger.info(String.format("Looking for parameters"));
for (String param : params.keySet()) {
if (param != null) {
logger.info(String.format("Found %s", param));
}
if (param != null) {
logger.info(String.format("Found %s", param));
}
}
}
}
}

View file

@ -4,22 +4,18 @@ import jetbrains.buildServer.log.Loggers;
public final class PhabricatorServerLogger implements IPhabricatorPluginLogger {
@Override
public void info(String message) {
Loggers.SERVER.info(String.format("Phabricator Plugin: %s", message));
}
@Override
public void info(String message) {
Loggers.SERVER.info(String.format("Phabricator Plugin: %s", message));
}
@Override
@Override
public void warn(String message, Exception e) {
Loggers.SERVER.warn(String.format("Phabricator Plugin: %s", message), e);
}
// public void agentInfo(String message) {
// Loggers.AGENT.info(String.format("Phabricator Plugin: %s", message));
// }
//
// public void agentWarn(String message, Exception e) {
// Loggers.AGENT.warn(String.format("Phabricator Plugin: %s", message), e);
// }
@Override
public void error(String message, Exception e) {
Loggers.SERVER.error(String.format("Phabricator Plugin: %s", message), e);
}
}

View file

@ -17,48 +17,48 @@ import jetbrains.buildServer.serverSide.SRunningBuild;
*/
public class BuildTracker implements Runnable {
private SRunningBuild build;
private PhabricatorServerLogger logger;
private PhabricatorPluginConfig phabricatorConfig;
private SRunningBuild build;
private PhabricatorServerLogger logger;
private PhabricatorPluginConfig phabricatorConfig;
public BuildTracker(SRunningBuild runningBuild, PhabricatorServerLogger phabLogger) {
build = runningBuild;
logger = phabLogger;
public BuildTracker(SRunningBuild runningBuild, PhabricatorServerLogger phabLogger) {
build = runningBuild;
logger = phabLogger;
phabricatorConfig = new PhabricatorPluginConfig();
phabricatorConfig.setLogger(logger);
}
phabricatorConfig = new PhabricatorPluginConfig();
phabricatorConfig.setLogger(logger);
}
@Override
public void run() {
// Attempt to get the parameters set by the phabricator build feature. If non
// are set then the feature is not turned on.
Collection<SBuildFeatureDescriptor> phabricatorBuildFeatureParameters = build
.getBuildFeaturesOfType(Constants.BUILD_FEATURE_TYPE);
@Override
public void run() {
// Attempt to get the parameters set by the phabricator build feature. If non
// are set then the feature is not turned on.
Collection<SBuildFeatureDescriptor> phabricatorBuildFeatureParameters = build
.getBuildFeaturesOfType(Constants.BUILD_FEATURE_TYPE);
// Check if the build is part of a configuration which
// uses the phabricator build feature.
if (!phabricatorBuildFeatureParameters.isEmpty()) {
logger.info("Tracking build " + build.getBuildNumber());
// Check if the build is part of a configuration which
// uses the phabricator build feature.
if (!phabricatorBuildFeatureParameters.isEmpty()) {
logger.info("Tracking build " + build.getBuildNumber());
// Gather together all the build and phabricator parameters
Map<String, String> params = new HashMap<>();
params.putAll(build.getBuildOwnParameters());
params.putAll(phabricatorBuildFeatureParameters.iterator().next().getParameters());
// Gather together all the build and phabricator parameters
Map<String, String> params = new HashMap<>();
params.putAll(build.getBuildOwnParameters());
params.putAll(phabricatorBuildFeatureParameters.iterator().next().getParameters());
// Setup plugin specific configuration
// TODO: implement AppConfig as PluginConfig
phabricatorConfig.setParameters(params);
// Setup plugin specific configuration
// TODO: implement AppConfig as PluginConfig
phabricatorConfig.setParameters(params);
while (!build.isFinished()) {
// Wait until the build finishes
}
while (!build.isFinished()) {
// Wait until the build finishes
}
logger.info(String.format("Build %s finished: %s", build.getBuildNumber(), build.getBuildStatus()));
logger.info(String.format("Build %s finished: %s", build.getBuildNumber(), build.getBuildStatus()));
if (build.getStatusDescriptor().isSuccessful()) {
logger.info("Successful Build");
}
}
}
if (build.getStatusDescriptor().isSuccessful()) {
logger.info("Successful Build");
}
}
}
}

View file

@ -8,33 +8,30 @@ import jetbrains.buildServer.serverSide.SRunningBuild;
import jetbrains.buildServer.util.EventDispatcher;
/**
* Listen for builds been started and track their progress
* with BuildTracker
* Listen for builds been started and track their progress with BuildTracker
*
* @author steven.cooney
*
*/
public class PhabricatorBuildServerAdapter extends BuildServerAdapter {
private PhabricatorServerLogger logger;
public PhabricatorBuildServerAdapter(
@NotNull final EventDispatcher<BuildServerListener> buildServerListener,
@NotNull final PhabricatorServerLogger phabLogger
) {
buildServerListener.addListener(this);
logger = phabLogger;
logger.info("Build server adapter registered");
}
@Override
public void buildStarted(@NotNull SRunningBuild runningBuild) {
super.buildStarted(runningBuild);
// Do the work in a separate thread to avoid blocking
// other builds monitored by this adapter (this might be
// a tad overkill)
new Thread(new BuildTracker(runningBuild, logger)).start();
}
private PhabricatorServerLogger logger;
public PhabricatorBuildServerAdapter(@NotNull final EventDispatcher<BuildServerListener> buildServerListener,
@NotNull final PhabricatorServerLogger phabLogger) {
buildServerListener.addListener(this);
logger = phabLogger;
logger.info("Build server adapter registered");
}
@Override
public void buildStarted(@NotNull SRunningBuild runningBuild) {
super.buildStarted(runningBuild);
// Do the work in a separate thread to avoid blocking
// other builds monitored by this adapter (this might be
// a tad overkill)
new Thread(new BuildTracker(runningBuild, logger)).start();
}
}

View file

@ -8,50 +8,48 @@ import jetbrains.buildServer.serverSide.BuildFeature;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
public class PhabricatorPluginBuildFeature extends BuildFeature {
private final String myEditUrl;
private PhabricatorServerLogger logger;
public PhabricatorPluginBuildFeature(
@NotNull final PluginDescriptor pluginDescriptor,
@NotNull final PhabricatorServerLogger phabLogger
) {
myEditUrl = pluginDescriptor.getPluginResourcesPath("phabricatorBuildFeature.jsp");
logger = phabLogger;
logger.info("Build feature registered");
}
@Override
public String getType() {
return Constants.BUILD_FEATURE_TYPE;
}
@Override
public String getDisplayName() {
return Constants.PLUGIN_DISPLAY_NAME;
}
private final String myEditUrl;
private PhabricatorServerLogger logger;
@Override
public String getEditParametersUrl() {
return myEditUrl;
}
@Override
public PhabricatorPluginBuildFeature(@NotNull final PluginDescriptor pluginDescriptor,
@NotNull final PhabricatorServerLogger phabLogger) {
myEditUrl = pluginDescriptor.getPluginResourcesPath("phabricatorBuildFeature.jsp");
logger = phabLogger;
logger.info("Build feature registered");
}
@Override
public String getType() {
return Constants.BUILD_FEATURE_TYPE;
}
@Override
public String getDisplayName() {
return Constants.PLUGIN_DISPLAY_NAME;
}
@Override
public String getEditParametersUrl() {
return myEditUrl;
}
@Override
public boolean isMultipleFeaturesPerBuildTypeAllowed() {
return false;
}
/**
* Populates the Parameters Description on the build features page
*/
/**
* Populates the Parameters Description on the build features page
*/
@NotNull
@Override
public String describeParameters(@NotNull final Map<String, String> params) {
String url = "";
for(String key : params.keySet()){
if(key.equals(Constants.PHABRICATOR_URL_SETTING)){
for (String key : params.keySet()) {
if (key.equals(Constants.PHABRICATOR_URL_SETTING)) {
url = params.get(key);
}
}