Skip to content

Commit

Permalink
Merge branch 'master' into minor_refactoring_in_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSpieker authored Sep 24, 2023
2 parents 2cdf9d2 + 2fc718d commit c9ccf14
Show file tree
Hide file tree
Showing 82 changed files with 1,029 additions and 312 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a href="https://jenkins.io">
<img width="400" src="https://www.jenkins.io/images/jenkins-logo-title-dark.svg">
<img width="400" src="https://www.jenkins.io/images/jenkins-logo-title-dark.svg" alt="Jenkins logo">
</a>

# About
Expand Down
2 changes: 1 addition & 1 deletion ath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o xtrace
cd "$(dirname "$0")"

# https://github.com/jenkinsci/acceptance-test-harness/releases
export ATH_VERSION=5699.v27deb_ef5796c
export ATH_VERSION=5717.v51fb_b_1f0f6d1

if [[ $# -eq 0 ]]; then
export JDK=17
Expand Down
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.5</asm.version>
<slf4jVersion>2.0.9</slf4jVersion>
<stapler.version>1802.v9e2750160d01</stapler.version>
<stapler.version>1802.1804.va_8d30483a_7f7</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand All @@ -64,7 +64,7 @@ THE SOFTWARE.
<!-- https://docs.spring.io/spring-security/site/docs/5.5.4/reference/html5/#getting-maven-no-boot -->
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>5.8.6</version>
<version>5.8.7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
21 changes: 2 additions & 19 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import static hudson.init.InitMilestone.PLUGINS_LISTED;
import static hudson.init.InitMilestone.PLUGINS_PREPARED;
import static hudson.init.InitMilestone.PLUGINS_STARTED;
import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
Expand Down Expand Up @@ -83,18 +81,15 @@
import java.net.URLConnection;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.security.CodeSource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -1883,16 +1878,6 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
copier = new FileUploadPluginCopier(fileItem);
}

if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
Arrays.stream(Objects.requireNonNull(tmpDir.listFiles())).forEach((file -> {
try {
Files.setPosixFilePermissions(file.toPath(), EnumSet.of(OWNER_READ, OWNER_WRITE));
} catch (IOException e) {
throw new RuntimeException(e);
}
}));
}

if ("".equals(fileName)) {
return new HttpRedirect("advanced");
}
Expand All @@ -1902,7 +1887,8 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
}

// first copy into a temporary file name
File t = File.createTempFile("uploaded", ".jpi");
File t = File.createTempFile("uploaded", ".jpi", tmpDir);
tmpDir.deleteOnExit();
t.deleteOnExit();
// TODO Remove this workaround after FILEUPLOAD-293 is resolved.
Files.delete(Util.fileToPath(t));
Expand All @@ -1913,9 +1899,6 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
throw new ServletException(e);
}
copier.cleanup();
if (!tmpDir.delete()) {
System.err.println("Failed to delete temporary directory: " + tmpDir);
}

final String baseName = identifyPluginShortName(t);

Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/hudson/ProxyConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import hudson.model.Descriptor;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import hudson.util.DaemonThreadFactory;
import hudson.util.FormValidation;
import hudson.util.NamingThreadFactory;
import hudson.util.Scrambler;
import hudson.util.Secret;
import hudson.util.XStream2;
Expand All @@ -58,6 +60,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import jenkins.UserAgentURLConnectionDecorator;
Expand Down Expand Up @@ -370,6 +374,8 @@ public static HttpClient newHttpClient() {
return newHttpClientBuilder().followRedirects(HttpClient.Redirect.NORMAL).build();
}

private static final Executor httpClientExecutor = Executors.newCachedThreadPool(new NamingThreadFactory(new DaemonThreadFactory(), "Jenkins HttpClient"));

/**
* Create a new {@link HttpClient.Builder} preconfigured with Jenkins-specific default settings.
*
Expand Down Expand Up @@ -397,6 +403,7 @@ public static HttpClient.Builder newHttpClientBuilder() {
if (DEFAULT_CONNECT_TIMEOUT_MILLIS > 0) {
httpClientBuilder.connectTimeout(Duration.ofMillis(DEFAULT_CONNECT_TIMEOUT_MILLIS));
}
httpClientBuilder.executor(httpClientExecutor);
return httpClientBuilder;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/console/ExpandableDetailsNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.Functions;
import hudson.MarkupText;
import java.io.IOException;
import java.util.logging.Level;
Expand All @@ -52,7 +53,7 @@ public ExpandableDetailsNote(String caption, String html) {
@Override
public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
text.addMarkup(charPos,
"<input type=button value='" + caption + "' class='reveal-expandable-detail'><div class='expandable-detail'>" + html + "</div>");
"<input type=button value='" + Functions.htmlAttributeEscape(caption) + "' class='reveal-expandable-detail'><div class='expandable-detail'>" + html + "</div>");
return null;
}

Expand Down
12 changes: 11 additions & 1 deletion core/src/main/java/hudson/logging/LogRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ public int hashCode() {
*/
@RequirePOST
public synchronized void doDoDelete(StaplerResponse rsp) throws IOException, ServletException {
delete();
rsp.sendRedirect2("..");
}

/**
* Deletes this log recorder.
* @throws IOException In case anything went wrong while deleting the configuration file.
* @since TODO
*/
public void delete() throws IOException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

getConfigFile().delete();
Expand All @@ -544,7 +554,7 @@ public synchronized void doDoDelete(StaplerResponse rsp) throws IOException, Ser
loggers.forEach(Target::disable);

getParent().getRecorders().forEach(logRecorder -> logRecorder.getLoggers().forEach(Target::enable));
rsp.sendRedirect2("..");
SaveableListener.fireOnChange(this, getConfigFile());
}

/**
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,15 @@ public final String getUrl() {
View view = (View) last.getObject();
if (view.getOwner().getItemGroup() == getParent() && !view.isDefault()) {
// Showing something inside a view, so should use that as the base URL.
String base = last.getUrl().substring(req.getContextPath().length() + 1) + '/';
LOGGER.log(Level.FINER, "using {0}{1} for {2} from {3}", new Object[] {base, shortUrl, this, uri});
return base + shortUrl;
String prefix = req.getContextPath() + "/";
String url = last.getUrl();
if (url.startsWith(prefix)) {
String base = url.substring(prefix.length()) + '/';
LOGGER.log(Level.FINER, "using {0}{1} for {2} from {3} given {4}", new Object[] {base, shortUrl, this, uri, prefix});
return base + shortUrl;
} else {
LOGGER.finer(() -> url + " does not start with " + prefix + " as expected");
}
} else {
LOGGER.log(Level.FINER, "irrelevant {0} for {1} from {2}", new Object[] {view.getViewName(), this, uri});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import hudson.Util;
import hudson.model.Queue.WaitingItem;
import hudson.model.queue.ScheduleResult;
import hudson.util.AlternativeUiTextProvider;
import java.io.IOException;
import java.util.AbstractList;
import java.util.ArrayList;
Expand Down Expand Up @@ -72,6 +73,8 @@
public class ParametersDefinitionProperty extends OptionalJobProperty<Job<?, ?>>
implements Action {

public static final AlternativeUiTextProvider.Message<Job> BUILD_BUTTON_TEXT = new AlternativeUiTextProvider.Message<>();

private final List<ParameterDefinition> parameterDefinitions;

@DataBoundConstructor
Expand All @@ -87,6 +90,11 @@ private Object readResolve() {
return parameterDefinitions == null ? new ParametersDefinitionProperty() : this;
}


public final String getBuildButtonText() {
return AlternativeUiTextProvider.get(BUILD_BUTTON_TEXT, owner, Messages.ParametersDefinitionProperty_BuildButtonText());
}

@Deprecated
public AbstractProject<?, ?> getOwner() {
return (AbstractProject) owner;
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,6 @@ protected final void execute(@NonNull RunExecution job) {

LOGGER.log(FINE, "{0} main build action completed: {1}", new Object[] {this, result});
CheckPoint.MAIN_COMPLETED.report();
} catch (ThreadDeath t) {
throw t;
} catch (AbortException e) { // orderly abortion.
result = Result.FAILURE;
listener.error(e.getMessage());
Expand All @@ -1919,8 +1917,6 @@ protected final void execute(@NonNull RunExecution job) {
// even if the main build fails fatally, try to run post build processing
job.post(Objects.requireNonNull(listener));

} catch (ThreadDeath t) {
throw t;
} catch (Throwable e) {
handleFatalBuildProblem(listener, e);
result = Result.FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public static void fireOnChange(Saveable o, XmlFile file) {
for (SaveableListener l : all()) {
try {
l.onChange(o, file);
} catch (ThreadDeath t) {
throw t;
} catch (Throwable t) {
Logger.getLogger(SaveableListener.class.getName()).log(Level.WARNING, null, t);
}
Expand Down
52 changes: 37 additions & 15 deletions core/src/main/java/hudson/util/AtomicFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.lang.ref.Cleaner;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.AtomicMoveNotSupportedException;
Expand All @@ -55,6 +56,9 @@ public class AtomicFileWriter extends Writer {

private static final Logger LOGGER = Logger.getLogger(AtomicFileWriter.class.getName());

private static final Cleaner CLEANER = Cleaner.create(
new NamingThreadFactory(new DaemonThreadFactory(), AtomicFileWriter.class.getName() + ".cleaner"));

private static /* final */ boolean DISABLE_FORCED_FLUSH = SystemProperties.getBoolean(
AtomicFileWriter.class.getName() + ".DISABLE_FORCED_FLUSH");

Expand All @@ -64,7 +68,7 @@ public class AtomicFileWriter extends Writer {
}
}

private final Writer core;
private final FileChannelWriter core;
private final Path tmpPath;
private final Path destPath;

Expand Down Expand Up @@ -151,6 +155,8 @@ public AtomicFileWriter(@NonNull Path destinationPath, @NonNull Charset charset,
}

core = new FileChannelWriter(tmpPath, charset, integrityOnFlush, integrityOnClose, StandardOpenOption.WRITE, StandardOpenOption.CREATE);

CLEANER.register(this, new CleanupChecker(core, tmpPath, destPath));
}

@Override
Expand Down Expand Up @@ -185,7 +191,12 @@ public void close() throws IOException {
* the {@link #commit()} is called, to simplify coding.
*/
public void abort() throws IOException {
closeAndDeleteTempFile();
// One way or another, the temporary file should be deleted.
try {
close();
} finally {
Files.deleteIfExists(tmpPath);
}
}

public void commit() throws IOException {
Expand Down Expand Up @@ -225,21 +236,32 @@ public void commit() throws IOException {
}
}

@Override
protected void finalize() throws Throwable {
try {
closeAndDeleteTempFile();
} finally {
super.finalize();
private static final class CleanupChecker implements Runnable {
private final FileChannelWriter core;
private final Path tmpPath;
private final Path destPath;

CleanupChecker(final FileChannelWriter core, final Path tmpPath, final Path destPath) {
this.core = core;
this.tmpPath = tmpPath;
this.destPath = destPath;
}
}

private void closeAndDeleteTempFile() throws IOException {
// one way or the other, temporary file should be deleted.
try {
close();
} finally {
Files.deleteIfExists(tmpPath);
@Override
public void run() {
if (core.isOpen()) {
LOGGER.log(Level.WARNING, "AtomicFileWriter for " + destPath + " was not closed before being released");
try {
core.close();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to close " + tmpPath + " for destination file " + destPath, e);
}
}
try {
Files.deleteIfExists(tmpPath);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to delete temporary file " + tmpPath + " for destination file " + destPath, e);
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/hudson/util/FileChannelWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.Channel;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.OpenOption;
Expand All @@ -26,7 +27,7 @@
* @see <a href="https://github.com/jenkinsci/jenkins/pull/2548">PR-2548</a>
*/
@Restricted(NoExternalUse.class)
public class FileChannelWriter extends Writer {
public class FileChannelWriter extends Writer implements Channel {

private static final Logger LOGGER = Logger.getLogger(FileChannelWriter.class.getName());

Expand Down Expand Up @@ -82,6 +83,11 @@ public void flush() throws IOException {
}
}

@Override
public boolean isOpen() {
return channel.isOpen();
}

@Override
public void close() throws IOException {
if (channel.isOpen()) {
Expand Down
Loading

0 comments on commit c9ccf14

Please sign in to comment.