Skip to content

Commit

Permalink
Merge pull request #436 from olivergondza/avoid-docker-cp
Browse files Browse the repository at this point in the history
Fix tests for cifs publisher
  • Loading branch information
olivergondza committed Jun 11, 2018
2 parents 5e94024 + 2ec94e3 commit 04937e5
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 76 deletions.
8 changes: 4 additions & 4 deletions docs/SUT-VERSIONS.md
Expand Up @@ -11,17 +11,17 @@ the update center. There are several ways to override this:

### Use custom plugin version

Environment variables like `<ARTIFACT_ID>.version` can be used to specify what version will be installed:
Environment variable `VERSION_OVERRIDES` can be used to specify what plugin version should be used instead of those in update center:

$ env git.version=2.3 mvn test
$ export VERSION_OVERRIDES=foo=1.2,bar=1.0

### Use custom plugin file

When you are testing locally developed Jenkins plugin, you'd like the test harness to pick up your
local version as opposed to download the plugin from update center. This can be done by instructing the harness
accordingly.

$ env LOCAL_JARS=path/to/your/ldap.jpi:path/to/another.jpi
$ export LOCAL_JARS=path/to/your/ldap.jpi:path/to/another.jpi

You can also do this from [the groovy wiring script](WIRING.md).
This scheme also works for a plugin that's not yet released.
Expand Down Expand Up @@ -67,4 +67,4 @@ You can activate this `pre configured plugins` mode with the System property `pl
* `"skipOnInvalid"` Which means the test will be skipped if the installed plugins are not enough to cover the test requisites
* `"failOnInvalid"` Which means the test will fail if the installed plugins are not enough to cover the test requisites

Note this mode is disabled if the property is not specified
Note this mode is disabled if the property is not specified
Expand Up @@ -8,19 +8,35 @@
*/
@Extension
public class DownloadOverrideUpdateCenterMetadataDecorator implements UpdateCenterMetadataDecorator {
private static final String VARNAME = "VERSION_OVERRIDES";

@Override
public void decorate(UpdateCenterMetadata ucm) {
for (Map.Entry<String,String> e : System.getenv().entrySet()) {
String key = e.getKey();
if (key.endsWith(".version")) {
System.err.println("Using XXX.version env vars is deprecated. Use " + VARNAME + " instead.");
String name = key.substring(0, key.length() - 8);
String version = e.getValue();

PluginMetadata original = ucm.plugins.get(name);
if (original == null) throw new IllegalArgumentException("Plugin does not exists in update center: " + name);
ucm.plugins.put(name, original.withVersion(version));
override(ucm, name, version);
}
}

String overrides = System.getenv(VARNAME);
if (overrides != null) {
for (String override : overrides.split(",")) {
String[] chunks = override.split("=");
if (chunks.length != 2) throw new Error("Unable to parse " + override + " as a " + VARNAME);
override(ucm, chunks[0], chunks[1]);
}
}
}

private void override(UpdateCenterMetadata ucm, String name, String version) {
PluginMetadata original = ucm.plugins.get(name);
if (original == null) throw new IllegalArgumentException("Plugin does not exists in update center: " + name);
ucm.plugins.put(name, original.withVersion(version));
System.err.println("Overriding the version of " + name + " with " + version);
}
}
Expand Up @@ -67,6 +67,7 @@ public void decorate(UpdateCenterMetadata ucm) {

try {
override(ucm, e.getValue());
System.err.println("Using XXX.jpi/XXX_JPI env vars is deprecated. Use LOCAL_JARS instead.");
} catch (Exception x) {
throw new IllegalArgumentException("Unable to honor environment variable "+key, x);
}
Expand Down
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -94,8 +95,8 @@ public VersionNumber requiredCore() {

public PluginMetadata withVersion(@Nonnull String v) {
if (v == null) throw new IllegalArgumentException();

return new PluginMetadata(name, gav, v, requiredCore, dependencies);
String newGav = gav.replaceAll("\\b" + Pattern.quote(version) + "\\b", v);
return new PluginMetadata(name, newGav, v, requiredCore, dependencies);
}

@Override
Expand Down

0 comments on commit 04937e5

Please sign in to comment.