Skip to content

Commit

Permalink
Merge branch 'master' into update-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jan 9, 2022
2 parents 4b8e0ff + 64d0f15 commit 2915caa
Show file tree
Hide file tree
Showing 72 changed files with 307 additions and 209 deletions.
4 changes: 2 additions & 2 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<properties>
<asm.version>9.2</asm.version>
<slf4jVersion>1.7.32</slf4jVersion>
<stapler.version>1635.vb_0ddedb_739f2</stapler.version>
<stapler.version>1638.v229a_24fa_b_17c</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand Down Expand Up @@ -221,7 +221,7 @@ THE SOFTWARE.
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.1.14</version>
<version>3.1.15</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
Expand Down
8 changes: 8 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
<pattern>net</pattern>
<shadedPattern>io.jenkins.cli.shaded.net</shadedPattern>
</relocation>
<relocation>
<pattern>com</pattern>
<shadedPattern>io.jenkins.cli.shaded.com</shadedPattern>
</relocation>
<relocation>
<pattern>jakarta</pattern>
<shadedPattern>io.jenkins.cli.shaded.jakarta</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
Expand Down
9 changes: 5 additions & 4 deletions cli/src/test/java/hudson/cli/PlainCLIProtocolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.Charset;
import org.junit.jupiter.api.Test;

public class PlainCLIProtocolTest {
Expand Down Expand Up @@ -67,7 +68,7 @@ protected void handleClose() {}
void send() throws IOException {
sendArg("command");
sendStart();
streamStdin().write("hello".getBytes());
streamStdin().write("hello".getBytes(Charset.defaultCharset()));
}

void newop() throws IOException {
Expand Down Expand Up @@ -123,7 +124,7 @@ protected void onEndStdin() throws IOException {}
protected void handleClose() {}

void send() throws IOException {
streamStdout().write("goodbye".getBytes());
streamStdout().write("goodbye".getBytes(Charset.defaultCharset()));
sendExit(2);
}

Expand Down Expand Up @@ -156,9 +157,9 @@ void newop() throws IOException {
while (server.stdin.size() == 0) {
Thread.sleep(100);
}
assertEquals("hello", server.stdin.toString());
assertEquals("hello", server.stdin.toString(Charset.defaultCharset().name()));
assertEquals("command", server.arg);
assertEquals("goodbye", client.stdout.toString());
assertEquals("goodbye", client.stdout.toString(Charset.defaultCharset().name()));
assertEquals(2, client.code);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/ExtensionFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import hudson.init.InitMilestone;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import jakarta.annotation.PostConstruct;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
Expand All @@ -56,7 +57,6 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.PostConstruct;
import jenkins.ExtensionComponentSet;
import jenkins.ExtensionFilter;
import jenkins.ExtensionRefreshException;
Expand Down Expand Up @@ -580,7 +580,7 @@ public <T> void onProvision(ProvisionInvocation<T> provision) {
Arrays.stream(c.getDeclaredMethods())
.map(m -> getMethodAndInterfaceDeclarations(m, interfaces))
.flatMap(Collection::stream)
.filter(m -> m.getAnnotation(PostConstruct.class) != null)
.filter(m -> m.getAnnotation(PostConstruct.class) != null || m.getAnnotation(javax.annotation.PostConstruct.class) != null)
.findFirst()
.ifPresent(method -> methods.add(0, method));
c = c.getSuperclass();
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
Expand Down Expand Up @@ -1656,7 +1655,7 @@ public String invoke(File dir, VirtualChannel channel) throws IOException {
throw new IOException("Failed to create a temporary directory in " + dir, e);
}

try (Writer w = new FileWriter(f)) {
try (Writer w = Files.newBufferedWriter(Util.fileToPath(f), Charset.defaultCharset())) {
w.write(contents);
}

Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/hudson/cli/CLICommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ public final String getUsage() {
@Restricted(NoExternalUse.class)
public final String getLongDescription() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(out);
PrintStream ps;
try {
ps = new PrintStream(out, false, getClientCharset().name());
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}

printUsageSummary(ps);
ps.close();
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/cli/GroovyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import groovy.lang.GroovyShell;
import hudson.Extension;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -63,7 +64,7 @@ protected int run() throws Exception {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

Binding binding = new Binding();
binding.setProperty("out", new PrintWriter(stdout, true));
binding.setProperty("out", new PrintWriter(new OutputStreamWriter(stdout, getClientCharset()), true));
binding.setProperty("stdin", stdin);
binding.setProperty("stdout", stdout);
binding.setProperty("stderr", stderr);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/cli/GroovyshCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import hudson.Extension;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
Expand Down Expand Up @@ -84,7 +85,7 @@ protected Groovysh createShell(InputStream stdin, PrintStream stdout,

Binding binding = new Binding();
// redirect "println" to the CLI
binding.setProperty("out", new PrintWriter(stdout, true));
binding.setProperty("out", new PrintWriter(new OutputStreamWriter(stdout, getClientCharset()), true));
binding.setProperty("hudson", Jenkins.get()); // backward compatibility
binding.setProperty("jenkins", Jenkins.get());

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/cli/ListChangesCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hudson.scm.ChangeLogSet;
import hudson.util.QuotedStringTokenizer;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.List;
import jenkins.scm.RunWithSCM;
Expand Down Expand Up @@ -46,7 +47,7 @@ protected int act(List<Run<?, ?>> builds) throws IOException {
// No other permission check needed.
switch (format) {
case XML:
PrintWriter w = new PrintWriter(stdout);
PrintWriter w = new PrintWriter(new OutputStreamWriter(stdout, getClientCharset()));
w.println("<changes>");
for (Run<?, ?> build : builds) {
if (build instanceof RunWithSCM) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
import hudson.util.StreamTaskListener;
import hudson.util.jna.Kernel32;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -110,7 +113,7 @@ public void rewriteHudsonWar(File by) throws IOException {
File baseDir = getBaseDir();
File copyFiles = new File(baseDir, baseName + ".copies");

try (FileWriter w = new FileWriter(copyFiles, true)) {
try (Writer w = Files.newBufferedWriter(Util.fileToPath(copyFiles), Charset.defaultCharset(), StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n');
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/PersistentDescriptor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hudson.model;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;

/**
* Marker interface for Descriptors which use xml persistent data, and as such need to load from disk when instantiated.
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/StreamBuildListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public StreamBuildListener(File out, Charset charset) throws IOException {
super(out, charset);
}

/**
* @deprecated as of TODO
* The caller should use {@link #StreamBuildListener(OutputStream, Charset)} to pass in
* the charset and output stream separately, so that this class can handle encoding correctly.
*/
@Deprecated
public StreamBuildListener(OutputStream w) {
super(w);
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/os/SU.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.util.Collections;

/**
Expand Down Expand Up @@ -83,7 +84,7 @@ protected String sudoExe() {
return "sudo";
}

@SuppressFBWarnings(value = {"COMMAND_INJECTION", "DM_DEFAULT_ENCODING"}, justification = "TODO needs triage")
@SuppressFBWarnings(value = "COMMAND_INJECTION", justification = "TODO needs triage")
@Override
protected Process sudoWithPass(ArgumentListBuilder args) throws IOException {
args.prepend(sudoExe(), "-S");
Expand All @@ -92,7 +93,7 @@ protected Process sudoWithPass(ArgumentListBuilder args) throws IOException {
Process p = pb.start();
// TODO: use -p to detect prompt
// TODO: detect if the password didn't work
try (PrintStream ps = new PrintStream(p.getOutputStream())) {
try (PrintStream ps = new PrintStream(p.getOutputStream(), false, Charset.defaultCharset().name())) {
ps.println(rootPassword);
ps.println(rootPassword);
ps.println(rootPassword);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/triggers/SCMTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import hudson.util.NamingThreadFactory;
import hudson.util.SequentialExecutionQueue;
import hudson.util.StreamTaskListener;
import jakarta.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -71,7 +72,6 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import jenkins.model.Jenkins;
import jenkins.model.RunAction2;
import jenkins.scm.SCMDecisionHandler;
Expand Down
18 changes: 16 additions & 2 deletions core/src/main/java/hudson/util/StreamTaskListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ public StreamTaskListener(@NonNull PrintStream out) {
this(out, null);
}

/**
* @deprecated as of TODO
* The caller should use {@link #StreamTaskListener(OutputStream, Charset)} to pass in
* the charset and output stream separately, so that this class can handle encoding correctly,
* or use {@link #fromStdout()} or {@link #fromStderr()}.
*/
@Deprecated
public StreamTaskListener(@NonNull OutputStream out) {
this(out, null);
}

public StreamTaskListener(@NonNull OutputStream out, @CheckForNull Charset charset) {
try {
if (charset == null)
this.out = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out, false);
this.out = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out, false, Charset.defaultCharset().name());
else
this.out = new PrintStream(out, false, charset.name());
this.charset = charset;
Expand All @@ -93,6 +100,12 @@ public StreamTaskListener(@NonNull OutputStream out, @CheckForNull Charset chars
}
}

/**
* @deprecated as of TODO
* The caller should use {@link #StreamTaskListener(File, Charset)} to pass in
* the charset and file separately, so that this class can handle encoding correctly.
*/
@Deprecated
public StreamTaskListener(@NonNull File out) throws IOException {
this(out, null);
}
Expand Down Expand Up @@ -187,8 +200,9 @@ private void writeObject(ObjectOutputStream out) throws IOException {
private static /* not final */ boolean AUTO_FLUSH = SystemProperties.getBoolean(KEY_AUTO_FLUSH);

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
out = new PrintStream((OutputStream) in.readObject(), AUTO_FLUSH);
OutputStream os = (OutputStream) in.readObject();
String name = (String) in.readObject();
out = new PrintStream(os, AUTO_FLUSH, name != null ? name : Charset.defaultCharset().name());
charset = name == null ? null : Charset.forName(name);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, null, new Throwable("deserializing here with AUTO_FLUSH=" + AUTO_FLUSH));
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/jenkins/diagnosis/HsErrPidList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import hudson.util.jna.Kernel32Utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
Expand Down Expand Up @@ -123,7 +124,7 @@ private void scan(String pattern) {
private void scanFile(File log) {
LOGGER.fine("Scanning " + log);

try (Reader rawReader = new FileReader(log);
try (Reader rawReader = Files.newBufferedReader(log.toPath(), Charset.defaultCharset());
BufferedReader r = new BufferedReader(rawReader)) {

if (!findHeader(r))
Expand All @@ -140,7 +141,7 @@ private void scanFile(File log) {
return;
}
}
} catch (IOException e) {
} catch (IOException | InvalidPathException e) {
// not a big enough deal.
LOGGER.log(Level.FINE, "Failed to parse hs_err_pid file: " + log, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.servlet.ServletContext;
import jenkins.util.SystemProperties;
import jenkins.util.UrlHelper;
Expand Down Expand Up @@ -210,11 +208,11 @@ public FormValidation doCheckUrl(@QueryParameter String value) {
}

public FormValidation doCheckAdminAddress(@QueryParameter String value) {
try {
new InternetAddress(value);
// TODO if equal to Messages.Mailer_Address_Not_Configured(), suggest configuring it with FormValidation.warning?
if (Util.fixNull(value).contains("@")) {
return FormValidation.ok();
} catch (AddressException e) {
return FormValidation.error(e.getMessage());
} else {
return FormValidation.error(Messages.JenkinsLocationConfiguration_does_not_look_like_an_email_address());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public AdminWhitelistRule() {
}

public boolean getMasterKillSwitch() {
LOGGER.log(WARNING, "AdminWhitelistRule no longer has any effect but an attempt was made to read its current configuration value. See https://www.jenkins.io/redirect/AdminWhitelistRule to learn more.", new Exception());
return false;
}

Expand Down
Loading

0 comments on commit 2915caa

Please sign in to comment.