Skip to content

Commit

Permalink
Merge branch 'master' into new-plugin-manager-1
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jul 12, 2022
2 parents 0f2ef2f + a990ebc commit e14b7d2
Show file tree
Hide file tree
Showing 104 changed files with 1,993 additions and 3,518 deletions.
5 changes: 4 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ updates:
reviewers:
- jenkinsci/sig-ux
ignore:
# Handlebars files (*.hbs) require a few tweaks in order to comply with 4.x' standards:
# Handlebars (*.hbs) require a few tweaks in order to comply with 4.x' standards:
# https://issues.jenkins.io/browse/JENKINS-68926
- dependency-name: "handlebars"

# A test case needs an update: https://issues.jenkins.io/browse/JENKINS-68975
- dependency-name: "jest"
3 changes: 2 additions & 1 deletion .github/workflows/label-conflicting-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ on:
push:
pull_request_target:
types: [synchronize]

permissions:
pull-requests: write

jobs:
main:
if: github.event.pull_request.user.login != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Label conflicting PRs
Expand Down
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for (i = 0; i < buildTypes.size(); i++) {
// Now run the actual build.
stage("${buildType} Build / Test") {
timeout(time: 6, unit: 'HOURS') {
realtimeJUnit(healthScaleFactor: 20.0, testResults: '*/target/surefire-reports/*.xml,war/junit.xml') {
realtimeJUnit(healthScaleFactor: 20.0, testResults: '*/target/surefire-reports/*.xml,war/target/jest-result.xml') {
def mavenOptions = [
'-Pdebug',
'-Penable-jacoco',
Expand Down Expand Up @@ -83,11 +83,11 @@ for (i = 0; i < buildTypes.size(); i++) {
error 'There were test failures; halting early'
}
if (buildType == 'Linux' && jdk == jdks[0]) {
publishCoverage calculateDiffForChangeRequests: true, adapters: [jacocoAdapter('coverage/target/site/jacoco-aggregate/jacoco.xml')]
def folders = env.JOB_NAME.split('/')
if (folders.length > 1) {
discoverGitReferenceBuild(scm: folders[1])
}
publishCoverage calculateDiffForChangeRequests: true, adapters: [jacocoAdapter('coverage/target/site/jacoco-aggregate/jacoco.xml')]

echo "Recording static analysis results for '${buildType}'"
recordIssues(
Expand All @@ -112,6 +112,13 @@ for (i = 0; i < buildTypes.size(); i++) {
qualityGates: [
[threshold: 1, type: 'TOTAL', unstable: true],
]])
recordIssues([tool: esLint(pattern: '**/target/eslint-warnings.xml'),
sourceCodeEncoding: 'UTF-8',
skipBlames: true,
trendChartType: 'TOOLS_ONLY',
qualityGates: [
[threshold: 1, type: 'TOTAL', unstable: true],
]])
if (failFast && currentBuild.result == 'UNSTABLE') {
error 'Static analysis quality gates not passed; halting early'
}
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ THE SOFTWARE.
<artifactId>j-interop</artifactId>
<version>2.0.8-kohsuke-1</version>
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>json-lib</artifactId>
Expand Down
21 changes: 10 additions & 11 deletions cli/src/main/java/hudson/cli/FullDuplexHttpStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ public class FullDuplexHttpStream {
private final InputStream input;

/**
* A way to get data from the server.
* There will be an initial zero byte used as a handshake which you should expect and ignore.
* Get data from the server.
* An initial zero byte is used as a handshake which you should expect and ignore.
*/
public InputStream getInputStream() {
return input;
}

/**
* A way to upload data to the server.
* You will need to write to this and {@link OutputStream#flush} it to finish establishing a connection.
* Upload data to the server.
* You will need to write to this and {@link OutputStream#flush} it to establish a connection.
*/
public OutputStream getOutputStream() {
return output;
}

/**
* @param base the base URL of Jenkins
* @param base the base URL of Jenkins.
* @param relativeTarget
* The endpoint that we are making requests to.
* @param authorization
* The value of the authorization header, if non-null.
* The value of the authorization header.
*/
public FullDuplexHttpStream(URL base, String relativeTarget, String authorization) throws IOException {
if (!base.toString().endsWith("/")) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public FullDuplexHttpStream(URL base, String relativeTarget, String authorizatio
if (con.getHeaderField("Hudson-Duplex") == null) {
throw new CLI.NotTalkingToJenkinsException("There's no Jenkins running at " + target + ", or is not serving the HTTP Duplex transport");
}
LOGGER.fine("established download side"); // calling getResponseCode or getHeaderFields breaks everything
LOGGER.fine("established download side"); // calling getResponseCode or getHeaderFields fails

// client->server uses chunked encoded POST for unlimited capacity.
LOGGER.fine("establishing upload side");
Expand All @@ -98,7 +98,7 @@ private HttpURLConnection openHttpConnection(URL target) throws IOException {
return (HttpURLConnection) target.openConnection();
}

// As this transport mode is using POST, it is necessary to resolve possible redirections using GET first. @SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "Client-side code doesn't involve SSRF.")
// As this transport mode is using POST, it is necessary to resolve possible redirections using GET first.
private URL tryToResolveRedirects(URL base, String authorization) {
try {
HttpURLConnection con = openHttpConnection(base);
Expand All @@ -108,9 +108,8 @@ private URL tryToResolveRedirects(URL base, String authorization) {
con.getInputStream().close();
base = con.getURL();
} catch (Exception ex) {
// Do not obscure the problem propagating the exception. If the problem is real it will manifest during the
// actual exchange so will be reported properly there. If it is not real (no permission in UI but sufficient
// for CLI connection using one of its mechanisms), there is no reason to bother user about it.
// If the exception is not real (permission for CLI connection but not for UI) do not inform user.
// Otherwise, the error will be reported during the exchange.
LOGGER.log(Level.FINE, "Failed to resolve potential redirects", ex);
}
return base;
Expand Down
13 changes: 11 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ THE SOFTWARE.
<groupId>org.jenkins-ci</groupId>
<artifactId>version-number</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>websocket-spi</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
Expand Down Expand Up @@ -375,10 +386,8 @@ THE SOFTWARE.
<artifactId>j-interop</artifactId>
</dependency>
<dependency>
<!-- not in BOM, optional -->
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.9</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
37 changes: 36 additions & 1 deletion core/src/main/java/hudson/model/ManageJenkinsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@
package hudson.model;

import hudson.Extension;
import hudson.Util;
import java.io.IOException;
import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithContextMenu;
import org.apache.commons.jelly.JellyException;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerFallback;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

/**
* Adds the "Manage Jenkins" link to the top page.
*
* @author Kohsuke Kawaguchi
*/
@Extension(ordinal = 100) @Symbol("manageJenkins")
public class ManageJenkinsAction implements RootAction {
public class ManageJenkinsAction implements RootAction, StaplerFallback, ModelObjectWithContextMenu {
@Override
public String getIconFileName() {
if (Jenkins.get().hasAnyPermission(Jenkins.MANAGE, Jenkins.SYSTEM_READ))
Expand All @@ -52,4 +62,29 @@ public String getDisplayName() {
public String getUrlName() {
return "/manage";
}

@Override
public Object getStaplerFallback() {
return Jenkins.get();
}

@Override
public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws JellyException, IOException {
return new ContextMenu().from(this, request, response, "index");
}

/**
* Workaround to ensuring that links in context menus resolve correctly in the submenu of the top-level 'Dashboard'
* menu.
*/
@Restricted(NoExternalUse.class)
public void addContextMenuItem(ContextMenu menu, String url, String icon, String iconXml, String text, boolean post, boolean requiresConfirmation) {
if (Stapler.getCurrentRequest().findAncestorObject(this.getClass()) != null || !Util.isSafeToRedirectTo(url)) {
// Default behavior if the URL is absolute or scheme-relative, or the current object is an ancestor (i.e. would resolve correctly)
menu.add(url, icon, iconXml, text, post, requiresConfirmation);
return;
}
// If neither is the case, rewrite the relative URL to point to inside the /manage/ URL space
menu.add("manage/" + url, icon, iconXml, text, post, requiresConfirmation);
}
}
8 changes: 7 additions & 1 deletion core/src/main/java/hudson/slaves/Channels.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
import hudson.util.StreamCopyThread;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -181,7 +183,9 @@ public synchronized void join() throws InterruptedException {
* @return
* never null
* @since 1.300
* @deprecated removed without replacement
*/
@Deprecated
public static Channel newJVM(String displayName, TaskListener listener, FilePath workDir, ClasspathBuilder classpath, Map<String, String> systemProperties) throws IOException {
JVMBuilder vmb = new JVMBuilder();
vmb.systemProperties(systemProperties);
Expand Down Expand Up @@ -212,7 +216,9 @@ public static Channel newJVM(String displayName, TaskListener listener, FilePath
* @return
* never null
* @since 1.361
* @deprecated removed without replacement
*/
@Deprecated
public static Channel newJVM(String displayName, TaskListener listener, JVMBuilder vmb, FilePath workDir, ClasspathBuilder classpath) throws IOException {
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress("localhost", 0));
Expand All @@ -223,7 +229,7 @@ public static Channel newJVM(String displayName, TaskListener listener, JVMBuild
vmb.mainClass(Launcher.class);

if (classpath != null)
vmb.args().add("-cp").add(classpath);
Arrays.stream(classpath.toString().split(File.pathSeparator)).forEach(arg -> vmb.classpath().add(arg));
vmb.args().add("-connectTo", "localhost:" + serverSocket.getLocalPort());

listener.getLogger().println("Starting " + displayName);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import hudson.model.ListView;
import hudson.model.LoadBalancer;
import hudson.model.LoadStatistics;
import hudson.model.ManageJenkinsAction;
import hudson.model.ManagementLink;
import hudson.model.Messages;
import hudson.model.ModifiableViewGroup;
Expand Down Expand Up @@ -4415,7 +4416,7 @@ public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse respons
for (MenuItem i : menu.items) {
if (i.url.equals(request.getContextPath() + "/manage")) {
// add "Manage Jenkins" subitems
i.subMenu = new ContextMenu().from(this, request, response, "manage");
i.subMenu = new ContextMenu().from(ExtensionList.lookupSingleton(ManageJenkinsAction.class), request, response, "index");
}
}
return menu;
Expand Down
Loading

0 comments on commit e14b7d2

Please sign in to comment.