public void rewriteHudsonWar(File by) throws IOException {
        File dest = getHudsonWar();
        // this should be impossible given the canRewriteHudsonWar method,
        // but let's be defensive
        if(dest==null)  throw new IOException("jenkins.war location is not known.");

        // backing up the old jenkins.war before it gets lost due to upgrading
        // (newly downloaded jenkins.war and 'backup' (jenkins.war.tmp) are the same files
        // unless we are trying to rewrite jenkins.war by a backup itself
        File bak = new File(dest.getPath() + ".bak");
        if (!by.equals(bak))
            FileUtils.copyFile(dest, bak);
       
        FileUtils.copyFile(by, dest);
        // we don't want to keep backup if we are downgrading
        if (by.equals(bak)&&bak.exists())
            bak.delete();
    }
public void rewriteHudsonWar ( File by ) throws IOException { File dest = getHudsonWar ( ) ; if ( dest == null ) throw new IOException ( "jenkins.war location is not known." ) ; File bak = new File ( dest . getPath ( ) + ".bak" ) ; if ( ! by . equals ( bak ) ) FileUtils . copyFile ( dest , bak ) ; FileUtils . copyFile ( by , dest ) ; if ( by . equals ( bak ) && bak . exists ( ) ) bak . delete ( ) ; }
Replaces jenkins.war by the given file.

<p>
On some system, most notably Windows, a file being in use cannot be changed,
so rewriting {@code jenkins.war} requires some special trick. Override this method
to do so.