Skip to content
Permalink
Browse files

[FIXED JENKINS-4543] Identify the short name of the plugin from the m…

…anifest.
  • Loading branch information...
kohsuke committed Apr 24, 2013
1 parent 6ec5d51 commit f1669601e4bd607ffa8a809e109f1ad0c79244b1
Showing with 27 additions and 3 deletions.
  1. +27 −3 core/src/main/java/hudson/PluginManager.java
@@ -101,6 +101,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xml.sax.Attributes;
@@ -729,11 +730,19 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
if(!fileName.endsWith(".jpi") && !fileName.endsWith(".hpi")){
throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
}
final String baseName = FilenameUtils.getBaseName(fileName);
new File(rootDir, baseName + ".hpi").delete(); // don't keep confusing legacy *.hpi
fileItem.write(new File(rootDir, baseName + ".jpi")); // rename all new plugins to *.jpi

// first copy into a temporary file name
File t = File.createTempFile("uploaded", "jp_",rootDir);
fileItem.write(t); // rename all new plugins to *.jpi
fileItem.delete();

final String baseName = identifyPluginShortName(t);

// and move the temp file into a proper name
new File(rootDir, baseName + ".hpi").delete(); // don't keep confusing legacy *.hpi
new File(rootDir, baseName + ".jpi").delete(); // rename can fail if the file already exists
t.renameTo(new File(rootDir, baseName + ".jpi"));

PluginWrapper existing = getPlugin(baseName);
if (existing!=null && existing.isBundled){
existing.doPin();
@@ -749,6 +758,21 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
}
}

protected String identifyPluginShortName(File t) {
try {
JarFile j = new JarFile(t);
try {
String name = j.getManifest().getMainAttributes().getValue("Short-Name");
if (name!=null) return name;
} finally {
j.close();
}
} catch (IOException e) {
LOGGER.log(WARNING, "Failed to identify the short name from "+t,e);
}
return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded
}

public Descriptor<ProxyConfiguration> getProxyDescriptor() {
return Jenkins.getInstance().getDescriptor(ProxyConfiguration.class);
}

0 comments on commit f166960

Please sign in to comment.
You can’t perform that action at this time.