Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop recommending -jnlpUrl #8639

Merged
merged 1 commit into from Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions core/src/main/java/hudson/slaves/JNLPLauncher.java
Expand Up @@ -24,6 +24,8 @@

package hudson.slaves;

import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -38,6 +40,7 @@
import jenkins.slaves.RemotingWorkDirSettings;
import jenkins.util.SystemProperties;
import jenkins.websocket.WebSockets;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -195,6 +198,59 @@
@Restricted(NoExternalUse.class)
public static /*almost final*/ Descriptor<ComputerLauncher> DESCRIPTOR;

@NonNull
@Restricted(NoExternalUse.class)
public String getRemotingOptionsUnix(@NonNull Computer computer) {
return getRemotingOptions(escapeUnix(computer.getName()));
}

@NonNull
@Restricted(NoExternalUse.class)
public String getRemotingOptionsWindows(@NonNull Computer computer) {
return getRemotingOptions(escapeWindows(computer.getName()));
}

private String getRemotingOptions(String computerName) {
StringBuilder sb = new StringBuilder();
sb.append("-name ");
sb.append(computerName);
sb.append(' ');
if (isWebSocket()) {

Check warning on line 218 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 218 is only partially covered, one branch is missing
Copy link
Member

@jglick jglick Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simply deprecate this option, since it will now have no effect other than changing the recommendation for the command if you take the advice to stop using -jnlpUrl. Compare discussion of vmargs in #6543.

sb.append("-webSocket ");

Check warning on line 219 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 219 is not covered by tests
}
if (tunnel != null) {

Check warning on line 221 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 221 is only partially covered, one branch is missing
Copy link
Member

@jglick jglick Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Also workDirSettings. IOW there is no longer a reason to have any nondeprecated configurable parameters on JNLPLauncher.

sb.append(" -tunnel ");
sb.append(tunnel);
sb.append(' ');

Check warning on line 224 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 222-224 are not covered by tests
}
return sb.toString();
}

/**
* {@link Jenkins#checkGoodName(String)} saves us from most troublesome characters, but we still have to deal with
* spaces and therefore with double quotes and backticks.
*/
private static String escapeUnix(String input) {
if (StringUtils.isAlphanumeric(input)) {

Check warning on line 234 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 234 is only partially covered, one branch is missing
return input;
}
Escaper escaper =
Escapers.builder().addEscape('"', "\\\"").addEscape('`', "\\`").build();
return "\"" + escaper.escape(input) + "\"";

Check warning on line 239 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 238-239 are not covered by tests
}

/**
* {@link Jenkins#checkGoodName(String)} saves us from most troublesome characters, but we still have to deal with
* spaces and therefore with double quotes.
*/
private static String escapeWindows(String input) {
if (StringUtils.isAlphanumeric(input)) {

Check warning on line 247 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 247 is only partially covered, one branch is missing
return input;
}
Escaper escaper = Escapers.builder().addEscape('"', "\\\"").build();
return "\"" + escaper.escape(input) + "\"";

Check warning on line 251 in core/src/main/java/hudson/slaves/JNLPLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 250-251 are not covered by tests
}

/**
* Gets work directory options as a String.
*
Expand Down
33 changes: 18 additions & 15 deletions core/src/main/resources/hudson/slaves/JNLPLauncher/main.jelly
Expand Up @@ -35,71 +35,74 @@ THE SOFTWARE.
<j:set var="jenkinsURL" value="${h.inferHudsonURL(request)}"/>
<j:set var="copy_agent_jar_unix" value="curl -sO ${jenkinsURL}jnlpJars/agent.jar" />
<j:set var="copy_agent_jar_windows" value="curl.exe -sO ${jenkinsURL}jnlpJars/agent.jar" />
<j:set var="copy_java_cmd" value="java -jar agent.jar -jnlpUrl ${jenkinsURL}${it.url}jenkins-agent.jnlp ${it.launcher.getWorkDirOptions(it)}" />
<j:set var="copy_java_cmd_unix" value="java -jar agent.jar -url ${jenkinsURL} ${it.launcher.getRemotingOptionsUnix(it)}${it.launcher.getWorkDirOptions(it)}" />
<j:set var="copy_java_cmd_windows" value="java -jar agent.jar -url ${jenkinsURL} ${it.launcher.getRemotingOptionsWindows(it)}${it.launcher.getWorkDirOptions(it)}" />
<j:if test="${h.hasPermission(it, it.CONNECT)}">
<j:choose>
<j:when test="${it.ACL.hasPermission(app.ANONYMOUS, it.CONNECT)}">
<h3>
${%slaveAgent.cli.run} (Unix)
<l:copyButton text="${copy_agent_jar_unix};${copy_java_cmd}"/>
<l:copyButton text="${copy_agent_jar_unix};${copy_java_cmd_unix}"/>
</h3>
<pre>
${copy_agent_jar_unix}
${copy_java_cmd}
${copy_java_cmd_unix}
</pre>

<h3>
${%slaveAgent.cli.run} (Windows)
<l:copyButton text="${copy_agent_jar_windows} &amp; ${copy_java_cmd}"/>
<l:copyButton text="${copy_agent_jar_windows} &amp; ${copy_java_cmd_windows}"/>
</h3>
<pre>
${copy_agent_jar_windows}
${copy_java_cmd}
${copy_java_cmd_windows}
</pre>

</j:when>
<j:otherwise>
<j:set var="copy_java_cmd_secret" value="java -jar agent.jar -jnlpUrl ${jenkinsURL}${it.url}jenkins-agent.jnlp -secret ${it.jnlpMac} ${it.launcher.getWorkDirOptions(it)}" />
<j:set var="copy_java_cmd_secret_unix" value="java -jar agent.jar -url ${jenkinsURL} -secret ${it.jnlpMac} ${it.launcher.getRemotingOptionsUnix(it)}${it.launcher.getWorkDirOptions(it)}" />
<j:set var="copy_java_cmd_secret_windows" value="java -jar agent.jar -url ${jenkinsURL} -secret ${it.jnlpMac} ${it.launcher.getRemotingOptionsWindows(it)}${it.launcher.getWorkDirOptions(it)}" />
<h3>
${%slaveAgent.cli.run} (Unix)
<l:copyButton text="${copy_agent_jar_unix};${copy_java_cmd_secret}"/>
<l:copyButton text="${copy_agent_jar_unix};${copy_java_cmd_secret_unix}"/>
</h3>
<!-- TODO conceal secret w/ JS if possible -->
<pre>
${copy_agent_jar_unix}
${copy_java_cmd_secret}
${copy_java_cmd_secret_unix}
</pre>

<h3>
${%slaveAgent.cli.run} (Windows)
<l:copyButton text="${copy_agent_jar_windows} &amp; ${copy_java_cmd_secret}"/>
<l:copyButton text="${copy_agent_jar_windows} &amp; ${copy_java_cmd_secret_windows}"/>
</h3>
<!-- TODO conceal secret w/ JS if possible -->
<pre>
${copy_agent_jar_windows}
${copy_java_cmd_secret}
${copy_java_cmd_secret_windows}
</pre>

<j:set var="copy_secret_to_file" value="echo ${it.jnlpMac} &gt; secret-file" />
<j:set var="copy_java_cmd_secret2" value="java -jar agent.jar -jnlpUrl ${jenkinsURL}${it.url}jenkins-agent.jnlp -secret @secret-file ${it.launcher.getWorkDirOptions(it)}" />
<j:set var="copy_java_cmd_secret2_unix" value="java -jar agent.jar -url ${jenkinsURL} -secret @secret-file ${it.launcher.getRemotingOptionsUnix(it)}${it.launcher.getWorkDirOptions(it)}" />
<j:set var="copy_java_cmd_secret2_windows" value="java -jar agent.jar -url ${jenkinsURL} -secret @secret-file ${it.launcher.getRemotingOptionsWindows(it)}${it.launcher.getWorkDirOptions(it)}" />
<h3>
${%slaveAgent.cli.run.secret} (Unix)
<l:copyButton text="${copy_secret_to_file};${copy_agent_jar_unix};${copy_java_cmd_secret2}"/>
<l:copyButton text="${copy_secret_to_file};${copy_agent_jar_unix};${copy_java_cmd_secret2_unix}"/>
</h3>
<pre>
${copy_secret_to_file}
${copy_agent_jar_unix}
${copy_java_cmd_secret2}
${copy_java_cmd_secret2_unix}
</pre>

<h3>
${%slaveAgent.cli.run.secret} (Windows)
<l:copyButton text="${copy_secret_to_file} &amp; ${copy_agent_jar_windows} &amp; ${copy_java_cmd_secret2}"/>
<l:copyButton text="${copy_secret_to_file} &amp; ${copy_agent_jar_windows} &amp; ${copy_java_cmd_secret2_windows}"/>
</h3>
<pre>
${copy_secret_to_file}
${copy_agent_jar_windows}
${copy_java_cmd_secret2}
${copy_java_cmd_secret2_windows}
</pre>
</j:otherwise>
</j:choose>
Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle/checkstyle-configuration.xml
Expand Up @@ -58,7 +58,7 @@
<!-- prevent the use of jsr-305 annotations and Spring utilities -->
<property name="illegalClasses" value="javax.annotation.MatchesPattern.Checker, javax.annotation.Nonnegative.Checker, javax.annotation.Nonnull.Checker, javax.annotation.RegEx.Checker, javax.annotation.CheckForNull, javax.annotation.CheckForSigned, javax.annotation.CheckReturnValue, javax.annotation.Detainted, javax.annotation.MatchesPattern, javax.annotation.Nonnegative, javax.annotation.Nonnull, javax.annotation.Nullable, javax.annotation.OverridingMethodsMustInvokeSuper, javax.annotation.ParametersAreNonnullByDefault, javax.annotation.ParametersAreNullableByDefault, javax.annotation.PropertyKey, javax.annotation.RegEx, javax.annotation.Signed, javax.annotation.Syntax, javax.annotation.Tainted, javax.annotation.Untainted, javax.annotation.WillClose, javax.annotation.WillCloseWhenClosed, javax.annotation.WillNotClose, javax.annotation.concurrent.GuardedBy, javax.annotation.concurrent.Immutable, javax.annotation.concurrent.NotThreadSafe, javax.annotation.concurrent.ThreadSafe, javax.annotation.meta.TypeQualifierValidator, javax.annotation.meta.When, javax.annotation.meta.Exclusive, javax.annotation.meta.Exhaustive, javax.annotation.meta.TypeQualifier, javax.annotation.meta.TypeQualifierDefault, javax.annotation.meta.TypeQualifierNickname, org.apache.log4j.Logger, org.springframework.util.Assert, org.springframework.util.StringUtils"/>
<!-- Prevent the expansion of Guava usages and ban internal library packages -->
<property name="illegalPkgs" value="com.google.common.base, com.google.common.escape, com.google.common.eventbus, com.google.common.graph, com.google.common.hash, com.google.common.html, com.google.common.io, com.google.common.math, com.google.common.net, com.google.common.reflect, com.google.common.xml, com.google.thirdparty, jline.internal"/>
<property name="illegalPkgs" value="com.google.common.base, com.google.common.eventbus, com.google.common.graph, com.google.common.hash, com.google.common.html, com.google.common.io, com.google.common.math, com.google.common.net, com.google.common.reflect, com.google.common.xml, com.google.thirdparty, jline.internal"/>
</module>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
Expand Down