本文整理了Java中hudson.Functions.isWindows()
方法的一些代码示例,展示了Functions.isWindows()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Functions.isWindows()
方法的具体详情如下:
包路径:hudson.Functions
类名称:Functions
方法名:isWindows
暂无
代码示例来源:origin: jenkinsci/jenkins
@Override
public Boolean isUnix() {
return !Functions.isWindows();
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public String invoke(File f, VirtualChannel channel) throws IOException {
if(!writing(f).setLastModified(timestamp)) {
if (Functions.isWindows()) {
// On Windows this seems to fail often. See JENKINS-11073
// Therefore don't fail, but just log a warning
return "Failed to set the timestamp of "+f+" to "+timestamp;
} else {
throw new IOException("Failed to set the timestamp of "+f+" to "+timestamp);
}
}
return null;
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public String resolveCanonicalId(String idOrFullName, Map<String, ?> context) {
String id = idOrFullName.replace('\\', '_').replace('/', '_').replace('<','_')
.replace('>', '_'); // 4 replace() still faster than regex
if (Functions.isWindows()) id = id.replace(':','_');
return id;
}
代码示例来源:origin: jenkinsci/jenkins
public Void invoke(File d, VirtualChannel channel) throws IOException {
if(!Functions.isWindows())
process(d);
return null;
}
private void process(File f) {
代码示例来源:origin: jenkinsci/jenkins
/**
* Transform path for Windows.
*/
private InputStream transformForWindows(InputStream src) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(src));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (PrintStream p = new PrintStream(out)) {
String line;
while ((line = r.readLine()) != null) {
if (!line.startsWith("#") && Functions.isWindows())
line = line.replace("/", "\\\\");
p.println(line);
}
}
return new ByteArrayInputStream(out.toByteArray());
}
代码示例来源:origin: jenkinsci/jenkins
private File getExeFile(String execName) {
String m2Home = Util.replaceMacro(getHome(),EnvVars.masterEnvVars);
if(Functions.isWindows()) {
File exeFile = new File(m2Home, "bin/" + execName + ".bat");
// since Maven 3.3 .bat files are replaced with .cmd
if (!exeFile.exists()) {
return new File(m2Home, "bin/" + execName + ".cmd");
}
return exeFile;
} else {
return new File(m2Home, "bin/" + execName);
}
}
代码示例来源:origin: jenkinsci/jenkins
private static void makeWritable(@Nonnull Path path) throws IOException {
if (!Functions.isWindows()) {
try {
PosixFileAttributes attrs = Files.readAttributes(path, PosixFileAttributes.class);
Set<PosixFilePermission> newPermissions = attrs.permissions();
newPermissions.add(PosixFilePermission.OWNER_WRITE);
Files.setPosixFilePermissions(path, newPermissions);
} catch (NoSuchFileException ignored) {
return;
} catch (UnsupportedOperationException ignored) {
// PosixFileAttributes not supported, fall back to old IO.
}
}
/*
* We intentionally do not check the return code of setWritable, because if it
* is false we prefer to rethrow the exception thrown by Files.deleteIfExists,
* which will have a more useful message than something we make up here.
*/
path.toFile().setWritable(true);
}
代码示例来源:origin: jenkinsci/jenkins
public boolean checkFileAccess(String op, File path) throws SecurityException {
String pathStr = null;
for (FilePathRule rule : get()) {
if (rule.op.matches(op)) {
if (pathStr==null) {
// do not canonicalize, so that JENKINS_HOME that spans across
// multiple volumes via symlinks can look logically like one unit.
pathStr = path.getPath();
if (isWindows()) // Windows accepts '/' as separator, but for rule matching we want to normalize for consistent comparison
pathStr = pathStr.replace('/','\\');
}
if (rule.path.matcher(pathStr).matches()) {
// exclusion rule is only to bypass later path rules within #filePathRules,
// and we still want other FilePathFilters to whitelist/blacklist access.
// therefore I'm not throwing a SecurityException here
return rule.allow;
}
}
}
return false;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected FilePathRule parse(String line) {
line = line.trim();
if (line.isEmpty()) return null;
line = line.replace("<BUILDDIR>","<JOBDIR>/builds/<BUILDID>");
line = line.replace("<BUILDID>","(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]-[0-9][0-9]-[0-9][0-9]|[0-9]+)");
line = line.replace("<JOBDIR>","<JENKINS_HOME>/jobs/.+");
line = line.replace("<JENKINS_HOME>","\\Q"+Jenkins.getInstance().getRootDir().getPath()+"\\E");
// config file is always /-separated even on Windows, so bring it back to \-separation.
// This is done in the context of regex, so it has to be \\, which means in the source code it is \\\\
if (isWindows()) line = line.replace("/","\\\\");
Matcher m = PARSER.matcher(line);
if (!m.matches())
throw new Failure("Invalid filter rule line: "+line);
try {
return new FilePathRule(
Pattern.compile(m.group(3)),
createOpMatcher(m.group(2)),
m.group(1).equals("allow"));
} catch (Exception e) {
throw new Failure("Invalid filter rule line: "+line+"\n"+ Functions.printThrowable(e));
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Decide if {@link WindowsInstallerLink} should show up in UI, and if so, register it.
*/
@Extension
public static WindowsInstallerLink registerIfApplicable() {
if(!Functions.isWindows())
return null; // this is a Windows only feature
if(Lifecycle.get() instanceof WindowsServiceLifecycle)
return null; // already installed as Windows service
// this system property is set by the launcher when we run "java -jar jenkins.war"
// and this is how we know where is jenkins.war.
String war = SystemProperties.getString("executable-war");
if(war!=null && new File(war).exists()) {
WindowsInstallerLink link = new WindowsInstallerLink(new File(war));
// in certain situations where we know the user is just trying Jenkins (like when Jenkins is launched
// from JNLP), also put this link on the navigation bar to increase
// visibility
if(SystemProperties.getString(WindowsInstallerLink.class.getName()+".prominent")!=null)
Jenkins.getInstance().getActions().add(link);
return link;
}
return null;
}
代码示例来源:origin: jenkinsci/jenkins
Functions.printStackTrace(e, log);
} catch (IOException e) {
if (Functions.isWindows() && e instanceof FileSystemException) {
warnWindowsSymlink();
return;
代码示例来源:origin: jenkinsci/jenkins
if (Functions.isWindows()) {
File dir = Kernel32Utils.getTempDir();
if (dir!=null) {
代码示例来源:origin: jenkinsci/jenkins
public void visit(File file, String relativePath) throws IOException {
if(Functions.isWindows())
relativePath = relativePath.replace('\\','/');
代码示例来源:origin: jenkinsci/jenkins
if (mode != 0 && !Functions.isWindows()) // be defensive
_chmod(f, mode);
代码示例来源:origin: jenkinsci/jenkins
if(Functions.isWindows()) {
instance = new Lifecycle() {
@Override
代码示例来源:origin: jenkinsci/jenkins
/**
* Gets the mode of a file/directory, if appropriate. Only includes read, write, and
* execute permissions for the owner, group, and others, i.e. the max return value
* is 0777. Consider using {@link Files#getPosixFilePermissions} instead if you only
* care about access permissions.
* <p>If the file is symlink, the mode is that of the link target, not the link itself.
* @return a file mode, or -1 if not on Unix
* @throws PosixException if the file could not be statted, e.g. broken symlink
*/
public static int mode(File f) throws PosixException {
if(Functions.isWindows()) return -1;
try {
if (Util.NATIVE_CHMOD_MODE) {
return PosixAPI.jnr().stat(f.getPath()).mode();
} else {
return Util.permissionsToMode(Files.getPosixFilePermissions(fileToPath(f)));
}
} catch (IOException cause) {
PosixException e = new PosixException("Unable to get file permissions", null);
e.initCause(cause);
throw e;
}
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
public String getShellOrDefault() {
if(shell==null)
return Functions.isWindows() ?"sh":"/bin/sh";
return shell;
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
@Override
public String resolveCanonicalId(String idOrFullName, Map<String, ?> context) {
String id = idOrFullName.replace('\\', '_').replace('/', '_').replace('<','_')
.replace('>', '_'); // 4 replace() still faster than regex
if (Functions.isWindows()) id = id.replace(':','_');
return id;
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
public Void invoke(File d, VirtualChannel channel) throws IOException {
if(!Functions.isWindows())
process(d);
return null;
}
private void process(File f) {
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Gets the mode of a file/directory, if appropriate.
* @return a file mode, or -1 if not on Unix
* @throws PosixException if the file could not be statted, e.g. broken symlink
*/
public static int mode(File f) throws PosixException {
if(Functions.isWindows()) return -1;
return PosixAPI.jnr().stat(f.getPath()).mode();
}
内容来源于网络,如有侵权,请联系作者删除!