Skip to content

Commit

Permalink
Merge pull request #2674 from jglick/InstallPluginCommand
Browse files Browse the repository at this point in the history
[FIX JENKINS-32358] Correctly compute plugin name when multiple sources are passed to install-plugin CLI command
  • Loading branch information
oleg-nenashev committed Dec 25, 2016
2 parents 4f814c0 + 5d98185 commit 2612298
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions core/src/main/java/hudson/cli/InstallPluginCommand.java
Expand Up @@ -75,17 +75,20 @@ protected int run() throws Exception {
h.checkPermission(PluginManager.UPLOAD_PLUGINS);
PluginManager pm = h.getPluginManager();

if (sources.size() > 1 && name != null) {
throw new IllegalArgumentException("-name is incompatible with multiple sources");
}

for (String source : sources) {
// is this a file?
if (channel!=null) {
FilePath f = new FilePath(channel, source);
if (f.exists()) {
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromLocalFile(f));
if (name==null)
name = f.getBaseName();
f.copyTo(getTargetFilePath());
String n = name != null ? name : f.getBaseName();
f.copyTo(getTargetFilePath(n));
if (dynamicLoad)
pm.dynamicLoad(getTargetFile());
pm.dynamicLoad(getTargetFile(n));
continue;
}
}
Expand All @@ -94,16 +97,21 @@ protected int run() throws Exception {
try {
URL u = new URL(source);
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
if (name==null) {
name = u.getPath();
name = name.substring(name.lastIndexOf('/')+1);
name = name.substring(name.lastIndexOf('\\')+1);
int idx = name.lastIndexOf('.');
if (idx>0) name = name.substring(0,idx);
String n;
if (name != null) {
n = name;
} else {
n = u.getPath();
n = n.substring(n.lastIndexOf('/') + 1);
n = n.substring(n.lastIndexOf('\\') + 1);
int idx = n.lastIndexOf('.');
if (idx > 0) {
n = n.substring(0, idx);
}
}
getTargetFilePath().copyFrom(u);
getTargetFilePath(n).copyFrom(u);
if (dynamicLoad)
pm.dynamicLoad(getTargetFile());
pm.dynamicLoad(getTargetFile(n));
continue;
} catch (MalformedURLException e) {
// not an URL
Expand Down Expand Up @@ -149,11 +157,11 @@ protected int run() throws Exception {
return 0; // all success
}

private FilePath getTargetFilePath() {
return new FilePath(getTargetFile());
private static FilePath getTargetFilePath(String name) {
return new FilePath(getTargetFile(name));
}

private File getTargetFile() {
private static File getTargetFile(String name) {
return new File(Jenkins.getActiveInstance().getPluginManager().rootDir,name+".jpi");
}
}

0 comments on commit 2612298

Please sign in to comment.