Skip to content

Commit

Permalink
[FIXED JENKINS-16652] Use UpdateSite.Plugin.deploy from PluginManager…
Browse files Browse the repository at this point in the history
….doUploadPlugin.
  • Loading branch information
jglick committed May 15, 2013
1 parent 8c53e2f commit 5ecbbef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -58,6 +58,9 @@
<li class=bug>
NPE from <code>Run.getDynamic</code>.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17935">issue 17935</a>)
<li class=bug>
Reworked Upload Plugin gesture to work more like installation from an update center, and in particular to support dynamic load.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16652">issue 16652</a>)
<li class=bug>
Errors in <code>init.groovy</code> halted startup; changed to just log a warning.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17933">issue 17933</a>)
Expand Down
24 changes: 11 additions & 13 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -732,25 +732,23 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
}

// first copy into a temporary file name
File t = File.createTempFile("uploaded", "jp_",rootDir);
fileItem.write(t); // rename all new plugins to *.jpi
File t = File.createTempFile("uploaded", ".jpi");
t.deleteOnExit();
fileItem.write(t);
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();
}

pluginUploaded = true;

return new HttpRedirect(".");
// Now create a dummy plugin that we can dynamically load (the InstallationJob will force a restart if one is needed):
JSONObject cfg = new JSONObject().
element("name", baseName).
element("version", "0"). // unused but mandatory
element("url", t.toURI().toString()).
element("dependencies", new JSONArray());
new UpdateSite(UpdateCenter.ID_UPLOAD, null).new Plugin(UpdateCenter.ID_UPLOAD, cfg).deploy(true);
return new HttpRedirect("../updateCenter");
} catch (IOException e) {
throw e;
} catch (Exception e) {// grrr. fileItem.write throws this
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -89,6 +89,8 @@
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import org.acegisecurity.context.SecurityContextHolder;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.interceptor.RequirePOST;
Expand Down Expand Up @@ -119,6 +121,9 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
* @since 1.483
*/
public static final String ID_DEFAULT = "default";

@Restricted(NoExternalUse.class)
public static final String ID_UPLOAD = "_upload";

/**
* {@link ExecutorService} that performs installation.
Expand Down Expand Up @@ -1012,6 +1017,9 @@ public ConnectionCheckJob(UpdateSite site) {
}

public void run() {
if (ID_UPLOAD.equals(site.getId())) {
return;
}
LOGGER.fine("Doing a connectivity check");
try {
String connectionCheckUrl = site.getConnectionCheckUrl();
Expand Down

0 comments on commit 5ecbbef

Please sign in to comment.