提交 a7b9f5fd 编写于 作者: K kohsuke

- moved to the newer version of winsw that supports file replacement.

- hudson.war overwrite requires a special handling in certain running mode, such as on Windows where the file is locked.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@12911 71c3de6d-444a-0410-be80-ed276b4c234a
上级 a6b6bb3a
......@@ -488,7 +488,7 @@
<dependency>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<version>1.2</version>
<version>1.3</version>
<classifier>bin</classifier>
<type>exe</type>
<scope>provided</scope><!-- this isn't really a dependency that Maven should care about, so putting 'provided' -->
......
......@@ -57,8 +57,7 @@ public abstract class Lifecycle implements ExtensionPoint {
/**
* If the location of <tt>hudson.war</tt> is known in this life cycle,
* and if this file is writable while Hudson is running, return it location.
* Otherwise return null to indicate that it is unknown.
* return it location. Otherwise return null to indicate that it is unknown.
*
* <p>
* When a non-null value is returned, Hudson will offer an upgrade UI
......@@ -71,6 +70,31 @@ public abstract class Lifecycle implements ExtensionPoint {
return null;
}
/**
* Replaces hudson.war by the given file.
*/
public void rewriteHudsonWar(File by) throws IOException {
throw new UnsupportedOperationException();
}
/**
* Can {@link #rewriteHudsonWar(File)} work?
*/
public boolean canRewriteHudsonWar() {
// if we don't know where hudson.war is, it's impossible to replace.
if(getHudsonWar()==null) return false;
// the rewriteHudsonWar method isn't overridden.
try {
return !getClass().getMethod("rewriteHudsonWar",File.class).equals(
Lifecycle.class.getMethod("rewriteHudsonWar",File.class));
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
/**
* If this life cycle supports a restart of Hudson, do so.
* Otherwise, throw {@link UnsupportedOperationException},
......
......@@ -56,6 +56,11 @@ public class WindowsServiceLifecycle extends Lifecycle {
}
}
public void rewriteHudsonWar(File by) throws IOException {
// TODO: implement this method later
throw new UnsupportedOperationException();
}
public void restart() throws IOException, InterruptedException {
File me = getHudsonWar();
File home = me.getParentFile();
......
......@@ -142,7 +142,7 @@ public class UpdateCenter extends AbstractModelObject {
public void doUpgrade(StaplerResponse rsp) throws IOException, ServletException {
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
HudsonUpgradeJob job = new HudsonUpgradeJob();
if(!job.isSupported()) {
if(!Lifecycle.get().canRewriteHudsonWar()) {
sendError("Hudson upgrade not supported in this running mode");
return;
}
......@@ -506,10 +506,7 @@ public class UpdateCenter extends AbstractModelObject {
in.close();
out.close();
dst.delete();
if(!tmp.renameTo(dst)) {
throw new IOException("Failed to rename "+tmp+" to "+dst);
}
replace(dst, tmp);
LOGGER.info("Installation successful: "+getName());
status = new Success();
......@@ -520,6 +517,17 @@ public class UpdateCenter extends AbstractModelObject {
}
}
/**
* Called when the download is completed to overwrite
* the old file with the new file.
*/
protected void replace(File dst, File src) throws IOException {
dst.delete();
if(!src.renameTo(dst)) {
throw new IOException("Failed to rename "+src+" to "+dst);
}
}
/**
* Indicates the status or the result of a plugin installation.
* <p>
......@@ -611,10 +619,6 @@ public class UpdateCenter extends AbstractModelObject {
public HudsonUpgradeJob() {
}
public boolean isSupported() {
return getDestination()!=null;
}
protected URL getURL() throws MalformedURLException {
return new URL(getData().core.url);
}
......@@ -631,6 +635,11 @@ public class UpdateCenter extends AbstractModelObject {
status = new RestartNeeded();
}
@Override
protected void replace(File dst, File src) throws IOException {
Lifecycle.get().rewriteHudsonWar(src);
}
/**
* Indicates that the upgrade needs a restart.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册