提交 2676adca 编写于 作者: K kohsuke

class initialization of Hudson is much more work than that of Util, so pushing...

class initialization of Hudson is much more work than that of Util, so pushing these small utilities out to Util to reduce the overhead of remoting.

Plus it helps to keep Hudson.java smaller

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@27448 71c3de6d-444a-0410-be80-ed276b4c234a
上级 7089a818
......@@ -1628,7 +1628,7 @@ public final class FilePath implements Serializable {
IOUtils.copy(t,f);
f.setLastModified(te.getModTime().getTime());
int mode = te.getMode()&0777;
if(mode!=0 && !Hudson.isWindows()) // be defensive
if(mode!=0 && !Functions.isWindows()) // be defensive
try {
LIBC.chmod(f.getPath(),mode);
} catch (NoClassDefFoundError e) {
......
......@@ -963,7 +963,7 @@ public class Util {
* If there's a prior symlink at baseDir+symlinkPath, it will be overwritten.
*/
public static void createSymlink(File baseDir, String targetPath, String symlinkPath, TaskListener listener) throws InterruptedException {
if(isWindows() || NO_SYMLINK) return;
if(Functions.isWindows() || NO_SYMLINK) return;
try {
// if a file or a directory exists here, delete it first.
......@@ -1009,7 +1009,7 @@ public class Util {
* (TODO: try readlink(1) available on some platforms)
*/
public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException {
if(isWindows()) return null;
if(Functions.isWindows()) return null;
String filename = link.getAbsolutePath();
try {
......
......@@ -24,6 +24,7 @@
package hudson.lifecycle;
import hudson.ExtensionPoint;
import hudson.Functions;
import hudson.Util;
import hudson.model.Hudson;
......@@ -75,7 +76,7 @@ public abstract class Lifecycle implements ExtensionPoint {
throw x;
}
} else {
if(Hudson.isWindows()) {
if(Functions.isWindows()) {
instance = new Lifecycle() {
@Override
public void verifyRestartable() throws RestartNotSupportedException {
......
......@@ -23,10 +23,10 @@
*/
package hudson.lifecycle;
import hudson.Functions;
import hudson.model.ManagementLink;
import hudson.model.Hudson;
import hudson.AbortException;
import hudson.FilePath;
import hudson.Extension;
import hudson.util.StreamTaskListener;
import hudson.util.jna.DotNet;
......@@ -241,7 +241,7 @@ public class WindowsInstallerLink extends ManagementLink {
*/
@Extension
public static WindowsInstallerLink registerIfApplicable() {
if(!Hudson.isWindows())
if(!Functions.isWindows())
return null; // this is a Windows only feature
if(Lifecycle.get() instanceof WindowsServiceLifecycle)
......
......@@ -3288,10 +3288,14 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
return !"ISO-8859-1".equalsIgnoreCase(System.getProperty("file.encoding"));
}
/**
* @deprecated
* Use {@link Functions#isWindows()}.
*/
public static boolean isWindows() {
return File.pathSeparatorChar==';';
}
public static boolean isDarwin() {
// according to http://developer.apple.com/technotes/tn2002/tn2110.html
return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("mac");
......
......@@ -24,6 +24,7 @@
package hudson.security;
import groovy.lang.Binding;
import hudson.Functions;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.Util;
......@@ -170,7 +171,7 @@ public class PAMSecurityRealm extends SecurityRealm {
@Extension
public static DescriptorImpl install() {
if(!Hudson.isWindows()) return new DescriptorImpl();
if(!Functions.isWindows()) return new DescriptorImpl();
return null;
}
}
......@@ -27,6 +27,7 @@ import hudson.CopyOnWrite;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
......@@ -358,7 +359,7 @@ public class Ant extends Builder {
private File getExeFile() {
String execName;
if(Hudson.isWindows())
if(Functions.isWindows())
execName = "ant.bat";
else
execName = "ant";
......
......@@ -24,6 +24,7 @@
package hudson.tasks;
import hudson.FilePath;
import hudson.Functions;
import hudson.Util;
import hudson.Extension;
import hudson.model.AbstractProject;
......@@ -138,7 +139,7 @@ public class Shell extends CommandInterpreter {
public String getShellOrDefault() {
if(shell==null)
return isWindows()?"sh":"/bin/sh";
return Functions.isWindows() ?"sh":"/bin/sh";
return shell;
}
......
......@@ -33,7 +33,6 @@ import hudson.Functions;
import hudson.os.PosixAPI;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.model.Hudson;
import hudson.remoting.VirtualChannel;
import hudson.util.FormValidation;
import hudson.util.jna.GNUCLibrary;
......@@ -123,7 +122,7 @@ public class ZipExtractionInstaller extends ToolInstaller {
static class ChmodRecAPlusX implements FileCallable<Void> {
private static final long serialVersionUID = 1L;
public Void invoke(File d, VirtualChannel channel) throws IOException {
if(!Hudson.isWindows())
if(!Functions.isWindows())
process(d);
return null;
}
......
......@@ -30,7 +30,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.io.File;
import hudson.model.Hudson;
import hudson.util.StreamTaskListener;
/**
......@@ -144,7 +143,7 @@ public class UtilTest extends TestCase {
}
public void testSymlink() throws Exception {
if (Hudson.isWindows()) return;
if (Functions.isWindows()) return;
StreamTaskListener l = new StreamTaskListener(System.out);
File d = Util.createTempDir();
......
......@@ -57,7 +57,6 @@ import hudson.model.Result;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.TaskListener;
import hudson.model.UpdateCenter;
import hudson.model.UpdateSite;
import hudson.model.AbstractProject;
import hudson.model.View;
......@@ -147,9 +146,6 @@ import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.host.Stylesheet;
import hudson.model.Computer;
import hudson.slaves.ComputerListener;
import java.util.concurrent.CountDownLatch;
......@@ -435,7 +431,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
File mvnHome = createTmpDir();
mvn.unzip(new FilePath(mvnHome));
// TODO: switch to tar that preserves file permissions more easily
if(!Hudson.isWindows())
if(!Functions.isWindows())
GNUCLibrary.LIBC.chmod(new File(mvnHome,mavenVersion+"/bin/mvn").getPath(),0755);
MavenInstallation mavenInstallation = new MavenInstallation("default",
......@@ -459,7 +455,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
File antHome = createTmpDir();
ant.unzip(new FilePath(antHome));
// TODO: switch to tar that preserves file permissions more easily
if(!Hudson.isWindows())
if(!Functions.isWindows())
GNUCLibrary.LIBC.chmod(new File(antHome,"apache-ant-1.7.1/bin/ant").getPath(),0755);
antInstallation = new AntInstallation("default", new File(antHome,"apache-ant-1.7.1").getAbsolutePath(),NO_PROPERTIES);
......
......@@ -23,6 +23,7 @@
*/
package hudson.model;
import hudson.Functions;
import hudson.tasks.Shell;
import hudson.tasks.BatchFile;
import hudson.Launcher;
......@@ -43,7 +44,7 @@ public class DirectoryBrowserSupportTest extends HudsonTestCase {
public void testDoubleDots() throws Exception {
// create a problematic file name in the workspace
FreeStyleProject p = createFreeStyleProject();
if(Hudson.isWindows())
if(Functions.isWindows())
p.getBuildersList().add(new BatchFile("echo > abc..def"));
else
p.getBuildersList().add(new Shell("touch abc..def"));
......@@ -67,7 +68,7 @@ public class DirectoryBrowserSupportTest extends HudsonTestCase {
*/
@Email("http://www.nabble.com/Status-Code-400-viewing-or-downloading-artifact-whose-filename-contains-two-consecutive-periods-tt21407604.html")
public void testDoubleDots2() throws Exception {
if(Hudson.isWindows()) return; // can't test this on Windows
if(Functions.isWindows()) return; // can't test this on Windows
// create a problematic file name in the workspace
FreeStyleProject p = createFreeStyleProject();
......
......@@ -24,6 +24,7 @@
package hudson.tools;
import hudson.Functions;
import hudson.model.*;
import hudson.slaves.DumbSlave;
import hudson.tasks.Maven;
......@@ -117,7 +118,7 @@ public class ToolLocationNodePropertyTest extends HudsonTestCase {
}
private void configureDumpEnvBuilder() throws IOException {
if(Hudson.isWindows())
if(Functions.isWindows())
project.getBuildersList().add(new BatchFile("set"));
else
project.getBuildersList().add(new Shell("export"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册