Skip to content

Commit

Permalink
Revert "[JENKINS-41196] demonstrate that core component override plug…
Browse files Browse the repository at this point in the history
…in can work in ATH"
  • Loading branch information
olivergondza committed Sep 19, 2017
1 parent 3a09d8b commit 71e56fa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 121 deletions.
9 changes: 7 additions & 2 deletions docs/SUT-VERSIONS.md
Expand Up @@ -21,10 +21,15 @@ When you are testing locally developed Jenkins plugin, you'd like the test harne
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
One way to do so is to set the environment variable:

$ env ldap.jpi=/path/to/your/ldap.jpi mvn test

You can also do this from [the groovy wiring script](WIRING.md).
This scheme also works for a plugin that's not yet released.

envs['ldap.jpi'] = '/path/to/your.ldap.jpi'

Since newer shells do not support environment variables with hyphens in the name, rather than `scm-api.jpi` you may use `SCM_API_JPI`.

### Install plugins from local maven repository

Expand Down
@@ -1,17 +1,18 @@
package org.jenkinsci.test.acceptance.update_center;

import com.cloudbees.sdk.extensibility.Extension;
import java.io.File;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionScheme;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.Iterator;
import java.util.Map;

/**
* Allow local plugins specified via environment variables to override plugin metadata from update center.
*
Expand Down Expand Up @@ -58,55 +59,34 @@ public void decorate(UpdateCenterMetadata ucm) {
}
}
}

// deprecated mechanism, as of 1.57
for (Map.Entry<String,String> e : System.getenv().entrySet()) {
String key = e.getKey();
if (!isPluginEnvironmentVariable(key))
String name;
if (key.endsWith(".jpi")) {
name = key.replace(".jpi", "");
} else if (key.endsWith("_JPI")) { // http://stackoverflow.com/a/36992531/12916
name = null;
for (String _name : ucm.plugins.keySet()) {
if ((_name.toUpperCase(Locale.ENGLISH).replaceAll("[^A-Z0-9_]", "_") + "_JPI").equals(key)) {
name = _name;
break;
}
}
if (name == null) {
throw new IllegalArgumentException("Could not identify plugin name from " + key + " given " + ucm.plugins.keySet());
}
} else {
continue;

try {
override(ucm, e.getValue());
} catch (Exception x) {
throw new IllegalArgumentException("Unable to honor environment variable "+key, x);
}
}

// past 1.57, preferred way
String localJars = System.getenv("LOCAL_JARS");
if (localJars!=null) {
for (String jar : localJars.split(File.pathSeparator)) {
try {
override(ucm, jar);
} catch (Exception x) {
throw new IllegalArgumentException("Unable to honor LOCAL_JARS environment variable", x);
}
PluginMetadata stock = ucm.plugins.get(name);
if (stock == null) {
throw new IllegalArgumentException("Plugin does not exists in update center: " + name);
}
File file = new File(e.getValue());
if (!file.exists()) throw new IllegalArgumentException("Plugin file for " + name + " does not exist: " + file.getAbsolutePath());
PluginMetadata m = PluginMetadata.LocalOverride.create(file);
System.err.println("Overriding " + name + " " + stock.getVersion() + " with local build of " + m.getVersion());
ucm.plugins.put(m.getName(), m);
}
}

private void override(UpdateCenterMetadata ucm, String jpi) {
File file = new File(jpi);
if (!file.exists()) throw new IllegalArgumentException("Plugin file does not exist: " + file.getAbsolutePath());

PluginMetadata m = PluginMetadata.LocalOverride.create(file);
PluginMetadata stock = ucm.plugins.get(m.getName());
if (stock == null) {
System.err.println("Creating new plugin " + m.getName() + " with local build of " + m.getVersion());
} else {
System.err.println("Overriding " + m.getName() + " " + stock.getVersion() + " with local build of " + m.getVersion());
}
ucm.plugins.put(m.getName(), m);
}

/**
* Returns true if the given environment variable name is an override to point to a local JPI file.
*/
private boolean isPluginEnvironmentVariable(String name) {
if (name.endsWith(".jpi"))
return true;
if (name.endsWith("_JPI")) // http://stackoverflow.com/a/36992531/12916
return true;
return false;
}
}
Expand Up @@ -3,9 +3,6 @@
import com.cloudbees.sdk.extensibility.ExtensionPoint;

/**
* A hook to tweak {@link UpdateCenterMetadata} to allow plugins and versions that are not in the update
* center to be installed and tested.
*
* @author Kohsuke Kawaguchi
*/
@ExtensionPoint
Expand Down
67 changes: 0 additions & 67 deletions src/test/java/plugins/RemotingPluginTest.java

This file was deleted.

0 comments on commit 71e56fa

Please sign in to comment.