Skip to content

Commit

Permalink
Merge branch 'master' into JenkinsRule-additions
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Mar 23, 2015
2 parents 6a90b74 + c6d54a1 commit 94b427f
Show file tree
Hide file tree
Showing 29 changed files with 344 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -29,4 +29,4 @@ indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false~
trim_trailing_whitespace = false
10 changes: 9 additions & 1 deletion changelog.html
Expand Up @@ -55,7 +55,15 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
Jenkins CLI doesn't handle arguments with equal signs
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-21160">issue 21160</a>)
<li class=bug>
master/slave communication ping reacts badly if a clock jumps.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-21251">issue 21251</a>)
<li class=rfe>
JNLP slaves can now connect to master through HTTP proxy.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-6167">issue 21251</a>)
</ul>
</div><!--=TRUNK-END=-->
<h3><a name=v1.605>What's new in 1.605</a> (2015/03/16)</h3>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -190,7 +190,7 @@ THE SOFTWARE.
<dependency><!-- JENKINS-21160: remoting also depends on args4j, please update accordingly -->
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.23</version>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
Expand Down
46 changes: 35 additions & 11 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -131,7 +131,7 @@ public static <T> List<T> filter( @Nonnull List<?> base, @Nonnull Class<T> type
public static String replaceMacro( @CheckForNull String s, @Nonnull Map<String,String> properties) {
return replaceMacro(s,new VariableResolver.ByMap<String>(properties));
}

/**
* Replaces the occurrence of '$key' by <tt>resolver.get('key')</tt>.
*
Expand All @@ -143,7 +143,7 @@ public static String replaceMacro(@CheckForNull String s, @Nonnull VariableResol
if (s == null) {
return null;
}

int idx=0;
while(true) {
Matcher m = VARIABLE.matcher(s);
Expand Down Expand Up @@ -370,6 +370,30 @@ private static Boolean isSymlinkJava7(@Nonnull File file) throws IOException {
}
}

/**
* A mostly accurate check of whether a path is a relative path or not. This is designed to take a path against
* an unknown operating system so may give invalid results.
*
* @param path the path.
* @return {@code true} if the path looks relative.
* @since 1.606
*/
public static boolean isRelativePath(String path) {
if (path.startsWith("/"))
return false;
if (path.startsWith("\\\\") && path.length() > 3 && path.indexOf('\\', 3) != -1)
return false; // a UNC path which is the most absolute you can get on windows
if (path.length() >= 3 && ':' == path.charAt(1)) {
// never mind that the drive mappings can be changed between sessions, we just want to
// know if the 3rd character is a `\` (or a '/' is acceptable too)
char p = path.charAt(0);
if (('A' <= p && p <= 'Z') || ('a' <= p && p <= 'z')) {
return path.charAt(2) != '\\' && path.charAt(2) != '/';
}
}
return true;
}

/**
* Creates a new temporary directory.
*/
Expand Down Expand Up @@ -624,7 +648,7 @@ public static String getDigestOf(@Nonnull File file) throws IOException {
* Converts a string into 128-bit AES key.
* @since 1.308
*/
@Nonnull
@Nonnull
public static SecretKey toAes128Key(@Nonnull String s) {
try {
// turn secretKey into 256 bit hash
Expand Down Expand Up @@ -743,9 +767,9 @@ public static String getPastTimeString(long duration) {

/**
* Combines number and unit, with a plural suffix if needed.
*
* @deprecated
* Use individual localization methods instead.
*
* @deprecated
* Use individual localization methods instead.
* See {@link Messages#Util_year(Object)} for an example.
* Deprecated since 2009-06-24, remove method after 2009-12-24.
*/
Expand Down Expand Up @@ -780,7 +804,7 @@ public static <T> List<T> createSubList(@Nonnull Collection<?> source, @Nonnull
* {@link #rawEncode(String)} should generally be used instead, though be careful to pass only
* a single path component to that method (it will encode /, but this method does not).
*/
@Nonnull
@Nonnull
public static String encode(@Nonnull String s) {
try {
boolean escaped = false;
Expand Down Expand Up @@ -888,7 +912,7 @@ public static String singleQuote(String s) {
/**
* Escapes HTML unsafe characters like &lt;, &amp; to the respective character entities.
*/
@Nonnull
@Nonnull
public static String escape(@Nonnull String text) {
if (text==null) return null;
StringBuilder buf = new StringBuilder(text.length()+64);
Expand Down Expand Up @@ -1112,7 +1136,7 @@ public static FileSet createFileSet(@Nonnull File baseDir, @Nonnull String inclu
* @param symlinkPath
* Where to create a symlink in (relative to {@code baseDir})
*/
public static void createSymlink(@Nonnull File baseDir, @Nonnull String targetPath,
public static void createSymlink(@Nonnull File baseDir, @Nonnull String targetPath,
@Nonnull String symlinkPath, @Nonnull TaskListener listener) throws InterruptedException {
try {
if (createSymlinkJava7(baseDir, targetPath, symlinkPath)) {
Expand Down Expand Up @@ -1346,7 +1370,7 @@ public static String resolveSymlink(@Nonnull File link) throws InterruptedExcept
* @deprecated since 2008-05-13. This method is broken (see ISSUE#1666). It should probably
* be removed but I'm not sure if it is considered part of the public API
* that needs to be maintained for backwards compatibility.
* Use {@link #encode(String)} instead.
* Use {@link #encode(String)} instead.
*/
@Deprecated
public static String encodeRFC2396(String url) {
Expand All @@ -1367,7 +1391,7 @@ public static String wrapToErrorSpan(@Nonnull String s) {
s = "<span class=error style='display:inline-block'>"+s+"</span>";
return s;
}

/**
* Returns the parsed string if parsed successful; otherwise returns the default number.
* If the string is null, empty or a ParseException is thrown then the defaultNumber
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/hudson/cli/declarative/MethodBinder.java
Expand Up @@ -30,10 +30,12 @@
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.spi.FieldSetter;
import org.kohsuke.args4j.spi.Setter;
import org.kohsuke.args4j.spi.OptionHandler;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
Expand Down Expand Up @@ -79,6 +81,16 @@ public Class getType() {
public boolean isMultiValued() {
return false;
}

@Override
public FieldSetter asFieldSetter() {
return null;
}

@Override
public AnnotatedElement asAnnotatedElement() {
return p;
}
};
Option option = p.annotation(Option.class);
if (option!=null) {
Expand Down Expand Up @@ -148,5 +160,10 @@ public boolean multiValued() {
public Class<? extends Annotation> annotationType() {
return base.annotationType();
}

@Override
public boolean hidden() {
return base.hidden();
}
}
}
54 changes: 32 additions & 22 deletions core/src/main/java/hudson/model/Slave.java
@@ -1,19 +1,19 @@
/*
* The MIT License
*
*
* Copyright (c) 2004-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi,
* Erik Ramfelt, Martin Eigenbrodt, Stephen Connolly, Tom Huybrechts
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -63,6 +63,7 @@
import jenkins.slaves.WorkspaceLocator;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -92,8 +93,12 @@ public abstract class Slave extends Node implements Serializable {
private final String description;

/**
* Absolute path to the root of the workspace
* from the view point of this node, such as "/hudson"
* Path to the root of the workspace from the view point of this node, such as "/hudson", this need not
* be absolute provided that the launcher establishes a consistent working directory, such as "./.jenkins-slave"
* when used with an SSH launcher.
*
* NOTE: if the administrator is using a relative path they are responsible for ensuring that the launcher used
* provides a consistent working directory
*/
protected final String remoteFS;

Expand Down Expand Up @@ -121,14 +126,14 @@ public abstract class Slave extends Node implements Serializable {
* Whitespace-separated labels.
*/
private String label="";

private /*almost final*/ DescribableList<NodeProperty<?>,NodePropertyDescriptor> nodeProperties = new DescribableList<NodeProperty<?>,NodePropertyDescriptor>(Jenkins.getInstance());

/**
* Lazily computed set of labels from {@link #label}.
*/
private transient volatile Set<Label> labels;

/**
* Id of user which creates this slave {@link User}.
*/
Expand All @@ -147,7 +152,7 @@ public Slave(String name, String nodeDescription, String remoteFS, int numExecut
Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy) throws FormException, IOException {
this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList());
}

public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int numExecutors,
Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
this.name = name;
Expand All @@ -159,7 +164,7 @@ public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int
this.launcher = launcher;
this.retentionStrategy = retentionStrategy;
getAssignedLabels(); // compute labels now

this.nodeProperties.replaceBy(nodeProperties);
Slave node = (Slave) Jenkins.getInstance().getNode(name);

Expand All @@ -168,7 +173,7 @@ public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int
}
else{
User user = User.current();
userId = user!=null ? user.getId() : "anonymous";
userId = user!=null ? user.getId() : "anonymous";
}
if (name.equals(""))
throw new FormException(Messages.Slave_InvalidConfig_NoName(), null);
Expand All @@ -179,10 +184,10 @@ public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int
if (this.numExecutors<=0)
throw new FormException(Messages.Slave_InvalidConfig_Executors(name), null);
}

/**
* Return id of user which created this slave
*
*
* @return id of user
*/
public String getUserId() {
Expand All @@ -192,7 +197,7 @@ public String getUserId() {
public void setUserId(String userId){
this.userId = userId;
}

public ComputerLauncher getLauncher() {
return launcher == null ? new JNLPLauncher() : launcher;
}
Expand All @@ -214,7 +219,7 @@ public String getNodeName() {
}

public void setNodeName(String name) {
this.name = name;
this.name = name;
}

public String getNodeDescription() {
Expand All @@ -237,7 +242,7 @@ public DescribableList<NodeProperty<?>, NodePropertyDescriptor> getNodePropertie
assert nodeProperties != null;
return nodeProperties;
}

public RetentionStrategy getRetentionStrategy() {
return retentionStrategy == null ? RetentionStrategy.Always.INSTANCE : retentionStrategy;
}
Expand Down Expand Up @@ -273,14 +278,21 @@ public FilePath getWorkspaceFor(TopLevelItem item) {
return workspace;
}
}

FilePath r = getWorkspaceRoot();
if(r==null) return null; // offline
return r.child(item.getFullName());
}

@CheckForNull
public FilePath getRootPath() {
return createPath(remoteFS);
final SlaveComputer computer = getComputer();
if (computer == null) {
// if computer is null then channel is null and thus we were going to return null anyway
return null;
} else {
return createPath(StringUtils.defaultString(computer.getAbsoluteRemoteFs(), remoteFS));
}
}

/**
Expand Down Expand Up @@ -422,10 +434,8 @@ public FormValidation doCheckRemoteFS(@QueryParameter String value) throws IOExc
if(value.startsWith("\\\\") || value.startsWith("/net/"))
return FormValidation.warning(Messages.Slave_Network_Mounted_File_System_Warning());

if (!value.contains("\\") && !value.startsWith("/")) {
// Unix-looking path that doesn't start with '/'
// TODO: detect Windows-looking relative path
return FormValidation.error(Messages.Slave_the_remote_root_must_be_an_absolute_path());
if (Util.isRelativePath(value)) {
return FormValidation.warning(Messages.Slave_Remote_Relative_Path_Warning());
}

return FormValidation.ok();
Expand Down

0 comments on commit 94b427f

Please sign in to comment.