Skip to content

Commit

Permalink
[FIXED JENKINS-4543] Identify the short name of the plugin from the m…
Browse files Browse the repository at this point in the history
…anifest.
  • Loading branch information
kohsuke committed Apr 24, 2013
1 parent 6ec5d51 commit f166960
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down

0 comments on commit f166960

Please sign in to comment.