1
0
Fork 0

Parse Phabricator Config Variables and Check all is Correct

We are now parsing the phabractor variables and checking the ones we need are present. If there is no phabricator url then the process end likewise if there is a missing configuration variable the process ends too.
This commit is contained in:
Steven Cooney 2019-05-31 14:44:51 +01:00
parent 265318a9ce
commit b2d8bff4f9
6 changed files with 102 additions and 6 deletions

View file

@ -39,8 +39,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

View file

@ -24,8 +24,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

View file

@ -0,0 +1,12 @@
package uk.xlab.teamcity.phabricator;
public final class CommonUtils {
public static Boolean isNullOrEmpty(String str) {
return str == null || str.equals("");
}
public static Boolean isNull(Object obj) {
return obj == null;
}
}

View file

@ -1,8 +1,18 @@
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";
// Build Feature
public static final String BUILD_FEATURE_TYPE = "phabricator-build-feature";
public static final String PHABRICATOR_URL_SETTING = "phabricator_url_setting";
// Build Config
public static final String BRANCH_NAME = "env.PHAB_BRANCH_NAME";
public static final String BUILD_ID = "env.PHAB_BUILD_ID";
public static final String DIFF_ID = "env.PHAB_DIFF_ID";
public static final String HARBORMASTER_PHID = "env.PHAB_HARBORMASTER_TARGET_PHID";
public static final String REVISION_ID = "env.PHAB_REVISION_ID";
}

View file

@ -1,6 +1,9 @@
package uk.xlab.teamcity.phabricator;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import static uk.xlab.teamcity.phabricator.CommonUtils.*;
/**
* Holds all the parameters set on the build applied by the harbormaster trigger
@ -15,6 +18,16 @@ public class PhabricatorPluginConfig {
private IPhabricatorPluginLogger logger;
private Map<String, String> params;
// Build Feature Variables
private URL phabricatorUrl;
// Harbormaster Variables
private String branchName;
private String buildId;
private String diffId;
private String harbormasterPHID;
private String revisionId;
/**
* Set the appropriate logger depending if the class is called from the SERVER
* or AGENT
@ -35,9 +48,62 @@ public class PhabricatorPluginConfig {
logger.info(String.format("Looking for parameters"));
for (String param : params.keySet()) {
if (param != null) {
if (!isNullOrEmpty(param)) {
logger.info(String.format("Found %s", param));
switch (param) {
case Constants.PHABRICATOR_URL_SETTING:
logger.info(
String.format("Found Phabrictor URL: %s", params.get(Constants.PHABRICATOR_URL_SETTING)));
try {
phabricatorUrl = parsePhabricatorURL(params.get(Constants.PHABRICATOR_URL_SETTING));
} catch (MalformedURLException e) {
logger.warn(String.format("Failed to parse phabricator URL: %s",
params.get(Constants.PHABRICATOR_URL_SETTING)), e);
}
case Constants.BRANCH_NAME:
logger.info(String.format("Found branch name: %s", params.get(Constants.BRANCH_NAME)));
branchName = params.get(Constants.BRANCH_NAME);
case Constants.BUILD_ID:
logger.info(String.format("Found build id: %s", params.get(Constants.BUILD_ID)));
buildId = params.get(Constants.BUILD_ID);
case Constants.DIFF_ID:
logger.info(String.format("Found diff ID: %s", params.get(Constants.DIFF_ID)));
diffId = params.get(Constants.DIFF_ID);
case Constants.HARBORMASTER_PHID:
logger.info(String.format("Found harbormaster target PHID: %s",
params.get(Constants.HARBORMASTER_PHID)));
harbormasterPHID = params.get(Constants.HARBORMASTER_PHID);
case Constants.REVISION_ID:
logger.info(String.format("Found revision ID: %s", params.get(Constants.REVISION_ID)));
revisionId = params.get(Constants.REVISION_ID);
}
}
}
}
public boolean isPluginSetup() {
if (!isNull(phabricatorUrl) && !isNullOrEmpty(branchName) && !isNullOrEmpty(buildId) && !isNullOrEmpty(diffId)
&& !isNullOrEmpty(harbormasterPHID) && !isNullOrEmpty(revisionId)) {
return true;
}
return false;
}
private URL parsePhabricatorURL(String input) throws MalformedURLException {
URL inputURL = new URL(input);
String scheme = inputURL.getProtocol();
if (scheme == null)
scheme = "http";
int port = inputURL.getPort();
if (port == -1) {
if (scheme == "https")
port = 443;
else
port = 80;
}
return inputURL;
}
}

View file

@ -49,6 +49,14 @@ public class BuildTracker implements Runnable {
// Setup plugin specific configuration
// TODO: implement AppConfig as PluginConfig
phabricatorConfig.setParameters(params);
// Now we have set all the parameters we need to check if
// everything is present and correct for us to continue
if (!phabricatorConfig.isPluginSetup())
{
logger.info("Plugin incorrectly configured");
return;
}
while (!build.isFinished()) {
// Wait until the build finishes