Skip to content

Commit

Permalink
Refactored code standard
Browse files Browse the repository at this point in the history
  • Loading branch information
t04glovern committed Feb 1, 2018
1 parent d276eb0 commit 3fa27a6
Show file tree
Hide file tree
Showing 19 changed files with 828 additions and 733 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -11,7 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<go.version>17.11.0</go.version>
<go.version>18.1.0</go.version>
</properties>

<dependencies>
Expand Down
129 changes: 65 additions & 64 deletions src/main/java/com/nathanglover/gocd/spark/GoNotificationMessage.java
@@ -1,21 +1,28 @@
package com.nathanglover.gocd.spark;

import com.google.gson.annotations.SerializedName;
import com.nathanglover.gocd.spark.jsonapi.*;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.nathanglover.gocd.spark.jsonapi.History;
import com.nathanglover.gocd.spark.jsonapi.MaterialRevision;
import com.nathanglover.gocd.spark.jsonapi.Pipeline;
import com.nathanglover.gocd.spark.jsonapi.Server;
import com.nathanglover.gocd.spark.jsonapi.ServerFactory;
import com.nathanglover.gocd.spark.jsonapi.Stage;
import com.nathanglover.gocd.spark.ruleset.Rules;
import com.thoughtworks.go.plugin.api.logging.Logger;
import in.ashwanthkumar.utils.lang.StringUtils;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

public class GoNotificationMessage {

private Logger LOG = Logger.getLoggerFor(GoNotificationMessage.class);

private final ServerFactory serverFactory;
private Logger LOG = Logger.getLoggerFor(GoNotificationMessage.class);
@SerializedName("pipeline")
private PipelineInfo pipeline;
// Internal cache of pipeline history data from GoCD's JSON API.
private History mRecentPipelineHistory;

public GoNotificationMessage() {
serverFactory = new ServerFactory();
Expand All @@ -26,65 +33,6 @@ public GoNotificationMessage() {
this.pipeline = pipeline;
}

/**
* Raised when we can't find information about our build in the array returned by the server.
*/
static public class BuildDetailsNotFoundException extends Exception {

public BuildDetailsNotFoundException(String pipelineName,
int pipelineCounter) {
super(String.format("could not find details for %s/%d",
pipelineName, pipelineCounter));
}
}

static class StageInfo {

@SerializedName("name")
String name;

@SerializedName("counter")
String counter;

@SerializedName("state")
String state;

@SerializedName("result")
String result;

@SerializedName("create-time")
String createTime;

@SerializedName("last-transition-time")
String lastTransitionTime;
}

static class PipelineInfo {

@SerializedName("name")
String name;

@SerializedName("counter")
String counter;

@SerializedName("group")
String group;

@SerializedName("stage")
StageInfo stage;

@Override
public String toString() {
return name + "/" + counter + "/" + stage.name + "/" + stage.result;
}
}

@SerializedName("pipeline")
private PipelineInfo pipeline;

// Internal cache of pipeline history data from GoCD's JSON API.
private History mRecentPipelineHistory;

public String goServerUrl(String host) throws URISyntaxException {
return new URI(String
.format("%s/go/pipelines/%s/%s/%s/%s", host, pipeline.name, pipeline.counter,
Expand Down Expand Up @@ -224,4 +172,57 @@ public List<MaterialRevision> fetchChanges(Rules rules)
server.getPipelineInstance(pipeline.name, Integer.parseInt(pipeline.counter));
return pipelineInstance.rootChanges(server);
}

/**
* Raised when we can't find information about our build in the array returned by the server.
*/
static public class BuildDetailsNotFoundException extends Exception {

public BuildDetailsNotFoundException(String pipelineName,
int pipelineCounter) {
super(String.format("could not find details for %s/%d",
pipelineName, pipelineCounter));
}
}

static class StageInfo {

@SerializedName("name")
String name;

@SerializedName("counter")
String counter;

@SerializedName("state")
String state;

@SerializedName("result")
String result;

@SerializedName("create-time")
String createTime;

@SerializedName("last-transition-time")
String lastTransitionTime;
}

static class PipelineInfo {

@SerializedName("name")
String name;

@SerializedName("counter")
String counter;

@SerializedName("group")
String group;

@SerializedName("stage")
StageInfo stage;

@Override
public String toString() {
return name + "/" + counter + "/" + stage.name + "/" + stage.result;
}
}
}
@@ -1,25 +1,30 @@
package com.nathanglover.gocd.spark;

import static java.util.Arrays.asList;

import com.google.gson.GsonBuilder;
import com.nathanglover.gocd.spark.base.AbstractNotificationPlugin;
import com.nathanglover.gocd.spark.ruleset.Rules;
import com.nathanglover.gocd.spark.ruleset.RulesReader;
import com.thoughtworks.go.plugin.api.GoApplicationAccessor;
import com.thoughtworks.go.plugin.api.GoPlugin;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.plugin.api.annotation.Extension;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import com.nathanglover.gocd.spark.ruleset.Rules;
import com.nathanglover.gocd.spark.ruleset.RulesReader;
import in.ashwanthkumar.utils.lang.StringUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import static java.util.Arrays.asList;
import org.apache.commons.io.IOUtils;

@Extension
public class GoNotificationPlugin extends AbstractNotificationPlugin implements GoPlugin {
Expand All @@ -44,7 +49,7 @@ public class GoNotificationPlugin extends AbstractNotificationPlugin implements
private final Timer timer = new Timer();
private GoEnvironment environment = new GoEnvironment();
private Rules rules;
private long configLastModified = 0l;
private long configLastModified = 0L;
private File pluginConfig;

public GoNotificationPlugin() {
Expand All @@ -53,7 +58,7 @@ public GoNotificationPlugin() {
@Override
public void run() {
if (pluginConfig.lastModified() != configLastModified) {
if (configLastModified == 0l) {
if (configLastModified == 0L) {
LOGGER.info("Loading configuration file");
} else {
LOGGER.info(
Expand Down
@@ -1,16 +1,15 @@
package com.nathanglover.gocd.spark;

import com.thoughtworks.go.plugin.api.logging.Logger;
import com.nathanglover.gocd.spark.ruleset.PipelineRule;
import com.nathanglover.gocd.spark.ruleset.PipelineStatus;
import com.nathanglover.gocd.spark.ruleset.Rules;

import com.thoughtworks.go.plugin.api.logging.Logger;
import java.util.List;

abstract public class PipelineListener {

private Logger LOG = Logger.getLoggerFor(PipelineListener.class);
protected Rules rules;
private Logger LOG = Logger.getLoggerFor(PipelineListener.class);

public PipelineListener(Rules rules) {
this.rules = rules;
Expand Down
@@ -1,29 +1,28 @@
package com.nathanglover.gocd.spark;

import com.ciscospark.*;
import static in.ashwanthkumar.utils.lang.StringUtils.startsWith;

import com.ciscospark.Message;
import com.ciscospark.NotAuthenticatedException;
import com.ciscospark.Spark;
import com.ciscospark.Webhook;
import com.nathanglover.gocd.spark.jsonapi.MaterialRevision;
import com.nathanglover.gocd.spark.jsonapi.Stage;
import com.nathanglover.gocd.spark.jsonapi.Modification;
import com.nathanglover.gocd.spark.jsonapi.Pipeline;
import com.nathanglover.gocd.spark.jsonapi.Stage;
import com.nathanglover.gocd.spark.ruleset.PipelineRule;
import com.nathanglover.gocd.spark.ruleset.PipelineStatus;
import com.nathanglover.gocd.spark.ruleset.Rules;

import com.thoughtworks.go.plugin.api.logging.Logger;

import in.ashwanthkumar.utils.collections.Lists;
import in.ashwanthkumar.utils.func.Function;
import in.ashwanthkumar.utils.lang.StringUtils;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import static in.ashwanthkumar.utils.lang.StringUtils.startsWith;

public class SparkPipelineListener extends PipelineListener {

public static final int DEFAULT_MAX_CHANGES_PER_MATERIAL_IN_SPARK = 5;
Expand Down
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.GsonBuilder;
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;

import java.util.HashMap;
import java.util.Map;

Expand Down

0 comments on commit 3fa27a6

Please sign in to comment.