Skip to content

Commit

Permalink
Automatic version detection. Log details.
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedpair committed Apr 13, 2018
1 parent 0c399ec commit a71d554
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
36 changes: 32 additions & 4 deletions src/main/java/com/mabl/integration/jenkins/MablStepConstants.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.mabl.integration.jenkins;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Manifest;

/**
* mabl custom build step
*
*/
class MablStepConstants {
static final String PLUGIN_SYMBOL = "mabl";
static final String MABL_PLUGIN_NAME = "mabl-integration-plugin";
private static final String PLUGIN_VERSION = "0.4.0"; // TODO automatically set this from Maven
static final String PLUGIN_USER_AGENT = "mabl-jenkins-plugin/"+PLUGIN_VERSION;
static final String PLUGIN_NAME = "mabl-integration-plugin";
private static final String PLUGIN_ARTIFACT_NAME = "mabl-integration";
static final String PLUGIN_VERSION = getPluginVersion();
static final String PLUGIN_VERSION_UNKNOWN = "unknown";
static final String PLUGIN_USER_AGENT = "mabl-jenkins-plugin/" + PLUGIN_VERSION;

// Label for build steps drop down list
static final String BUILD_STEP_DISPLAY_NAME = "Run mabl journeys";
Expand All @@ -17,4 +23,26 @@ class MablStepConstants {
static final int EXECUTION_TIMEOUT_SECONDS = 3600;
static final int REQUEST_TIMEOUT_MILLISECONDS = 60000;
static final long EXECUTION_STATUS_POLLING_INTERNAL_MILLISECONDS = 10000;


/**
* Dynamically grab the plugin version, so we can't forget to update it on release.
*
* @return plugin version, or {@link #PLUGIN_VERSION_UNKNOWN} on error/missing.
*/
static String getPluginVersion() {
try {
final Enumeration<URL> resources = MablStepConstants.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
final Manifest manifest = new Manifest(resources.nextElement().openStream());

String title = manifest.getMainAttributes().getValue("Implementation-title");
if (PLUGIN_ARTIFACT_NAME.equalsIgnoreCase(title)) {
final String version = manifest.getMainAttributes().getValue("Implementation-Version");
return version != null && !version.isEmpty() ? version : PLUGIN_VERSION_UNKNOWN;
}
}
} catch (IOException ignored) {}
return PLUGIN_VERSION_UNKNOWN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import java.util.Set;
import java.util.concurrent.Callable;

import static com.mabl.integration.jenkins.MablStepConstants.MABL_PLUGIN_NAME;
import static com.mabl.integration.jenkins.MablStepConstants.PLUGIN_NAME;
import static com.mabl.integration.jenkins.MablStepConstants.PLUGIN_VERSION;

/**
* mabl runner to launch all plans for a given
Expand Down Expand Up @@ -61,7 +62,7 @@ public MablStepDeploymentRunner(
@Override
public Boolean call() {
try {
outputStream.print("\nmabl Jenkins plugging running...\n");
outputStream.printf("\nmabl Jenkins plugin v%s running...\n", PLUGIN_VERSION);
execute();
return true;

Expand All @@ -74,7 +75,7 @@ public Boolean call() {
return continueOnPlanFailure;

} catch (Exception e) {
outputStream.printf("Unexpected %s exception\n", MABL_PLUGIN_NAME);
outputStream.printf("Unexpected %s exception\n", PLUGIN_NAME);
e.printStackTrace(outputStream);
return continueOnMablError;
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/mabl/integration/jenkins/MablConstantsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mabl.integration.jenkins;

import org.junit.Test;

import static com.mabl.integration.jenkins.MablStepConstants.PLUGIN_VERSION_UNKNOWN;
import static com.mabl.integration.jenkins.MablStepConstants.getPluginVersion;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* Unit test runner
*/
public class MablConstantsTest {

@Test
// Note: Doesn't run in junit because manifest injected at packaging")
public void ensurePluginVersionUnavailable() {
final String pluginVersion = getPluginVersion();
assertNotNull("plugin version unavailable", pluginVersion);
assertEquals("plugin version unavailable", pluginVersion, PLUGIN_VERSION_UNKNOWN);
}
}

0 comments on commit a71d554

Please sign in to comment.