diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 6b2529eabe..67499703e9 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -555,7 +555,7 @@ public final class FilePath implements Serializable { * @see #unzip(FilePath) */ public void unzipFrom(InputStream _in) throws IOException, InterruptedException { - final InputStream in = new RemoteInputStream(_in); + final InputStream in = new RemoteInputStream(_in, Flag.GREEDY); act(new SecureFileCallable() { public Void invoke(File dir, VirtualChannel channel) throws IOException { unzip(dir, in); @@ -724,7 +724,7 @@ public final class FilePath implements Serializable { */ public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException { try { - final InputStream in = new RemoteInputStream(_in); + final InputStream in = new RemoteInputStream(_in, Flag.GREEDY); act(new SecureFileCallable() { public Void invoke(File dir, VirtualChannel channel) throws IOException { readFromTar("input stream",dir, compression.extract(in)); diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 00f52e197c..9085656728 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -862,7 +862,19 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces protected void onRemoved(){ } - private synchronized void setNumExecutors(int n) { + /** + * Calling path, *means protected by Queue.withLock + * + * Computer.doConfigSubmit -> Computer.replaceBy ->Jenkins.setNodes* ->Computer.setNode + * AbstractCIBase.updateComputerList->Computer.inflictMortalWound* + * AbstractCIBase.updateComputerList->AbstractCIBase.updateComputer* ->Computer.setNode + * AbstractCIBase.updateComputerList->AbstractCIBase.killComputer->Computer.kill + * Computer.constructor->Computer.setNode + * Computer.kill is called after numExecutors set to zero(Computer.inflictMortalWound) so not need the Queue.lock + * + * @param number of executors + */ + private void setNumExecutors(int n) { this.numExecutors = n; final int diff = executors.size()-n; diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index ed1915e53d..16100a7727 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -30,6 +30,7 @@ import hudson.Functions; import hudson.PluginManager; import hudson.PluginWrapper; import hudson.ProxyConfiguration; +import hudson.security.ACLContext; import jenkins.util.SystemProperties; import hudson.Util; import hudson.XmlFile; @@ -1365,6 +1366,11 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas @Exported(inline=true) public volatile RestartJenkinsJobStatus status = new Pending(); + /** + * The name of the user that started this job + */ + private String authentication; + /** * Cancel job */ @@ -1378,6 +1384,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas public RestartJenkinsJob(UpdateSite site) { super(site); + this.authentication = Jenkins.getAuthentication().getName(); } public synchronized void run() { @@ -1386,7 +1393,10 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas } status = new Running(); try { - Jenkins.getInstance().safeRestart(); + // safeRestart records the current authentication for the log, so set it to the managing user + try (ACLContext _ = ACL.as(User.get(authentication, false, Collections.emptyMap()))) { + Jenkins.getInstance().safeRestart(); + } } catch (RestartNotSupportedException exception) { // ignore if restart is not allowed status = new Failure(); diff --git a/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java b/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java index 5fa446fef7..a27e575ee5 100644 --- a/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java +++ b/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java @@ -49,6 +49,9 @@ import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.jenkinsci.Symbol; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.DoNotUse; +import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -72,6 +75,15 @@ public class GlobalSecurityConfiguration extends ManagementLink implements Descr return Jenkins.getInstance().getSlaveAgentPort(); } + /** + * @since TODO + * @return true if the slave agent port is enforced on this instance. + */ + @Restricted(DoNotUse.class) // only for index.groovy + public boolean isSlaveAgentPortEnforced() { + return Jenkins.getInstance().isSlaveAgentPortEnforced(); + } + public Set getAgentProtocols() { return Jenkins.getInstance().getAgentProtocols(); } diff --git a/core/src/main/java/hudson/slaves/ComputerListener.java b/core/src/main/java/hudson/slaves/ComputerListener.java index c2e4dc1f70..b166a6c40d 100644 --- a/core/src/main/java/hudson/slaves/ComputerListener.java +++ b/core/src/main/java/hudson/slaves/ComputerListener.java @@ -143,7 +143,7 @@ public abstract class ComputerListener implements ExtensionPoint { * Starting Hudson 1.312, this method is also invoked for the master, not just for agents. * * @param listener - * This is connected to the launch log of the computer. + * This is connected to the launch log of the computer or Jenkins master. * Since this method is called synchronously from the thread * that launches a computer, if this method performs a time-consuming * operation, this listener should be notified of the progress. diff --git a/core/src/main/java/hudson/tools/InstallerTranslator.java b/core/src/main/java/hudson/tools/InstallerTranslator.java index 87d1dcd1e3..fd45212bd7 100644 --- a/core/src/main/java/hudson/tools/InstallerTranslator.java +++ b/core/src/main/java/hudson/tools/InstallerTranslator.java @@ -28,6 +28,7 @@ import hudson.Extension; import hudson.model.Node; import hudson.model.TaskListener; import java.io.IOException; +import java.util.ArrayList; import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.Semaphore; @@ -50,6 +51,9 @@ public class InstallerTranslator extends ToolLocationTranslator { if (isp == null) { return null; } + + ArrayList inapplicableInstallersMessages = new ArrayList(); + for (ToolInstaller installer : isp.installers) { if (installer.appliesTo(node)) { Semaphore semaphore; @@ -69,8 +73,16 @@ public class InstallerTranslator extends ToolLocationTranslator { } finally { semaphore.release(); } + } else { + inapplicableInstallersMessages.add(Messages.CannotBeInstalled( + installer.getDescriptor().getDisplayName(), + tool.getName(), + node.getDisplayName())); } } + for (String message : inapplicableInstallersMessages) { + log.getLogger().println(message); + } return null; } diff --git a/core/src/main/java/hudson/util/FormValidation.java b/core/src/main/java/hudson/util/FormValidation.java index 4c52f19b6d..c6dddca183 100644 --- a/core/src/main/java/hudson/util/FormValidation.java +++ b/core/src/main/java/hudson/util/FormValidation.java @@ -638,7 +638,7 @@ public abstract class FormValidation extends IOException implements HttpResponse */ public String toStemUrl() { if (names==null) return null; - return jsStringEscape(Descriptor.getCurrentDescriptorByNameUrl()) + '/' + relativePath(); + return Descriptor.getCurrentDescriptorByNameUrl() + '/' + relativePath(); } public String getDependsOn() { diff --git a/core/src/main/java/hudson/util/HttpResponses.java b/core/src/main/java/hudson/util/HttpResponses.java index 511a3f20e0..ccef89059e 100644 --- a/core/src/main/java/hudson/util/HttpResponses.java +++ b/core/src/main/java/hudson/util/HttpResponses.java @@ -29,6 +29,7 @@ import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.servlet.ServletException; import java.io.File; diff --git a/core/src/main/java/jenkins/install/SetupWizard.java b/core/src/main/java/jenkins/install/SetupWizard.java index 4196a061a6..6368fb4b8f 100644 --- a/core/src/main/java/jenkins/install/SetupWizard.java +++ b/core/src/main/java/jenkins/install/SetupWizard.java @@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; +import jenkins.util.SystemProperties; import org.acegisecurity.Authentication; import org.acegisecurity.context.SecurityContextHolder; import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; @@ -117,9 +118,9 @@ public class SetupWizard extends PageDecorator { authStrategy.setAllowAnonymousRead(false); jenkins.setAuthorizationStrategy(authStrategy); - // Shut down all the ports we can by default: - jenkins.setSlaveAgentPort(-1); // -1 to disable - + // Disable jnlp by default, but honor system properties + jenkins.setSlaveAgentPort(SystemProperties.getInteger(Jenkins.class.getName()+".slaveAgentPort",-1)); + // require a crumb issuer jenkins.setCrumbIssuer(new DefaultCrumbIssuer(false)); diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 66090849f9..5e034b3ffb 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -30,6 +30,7 @@ import antlr.ANTLRException; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.inject.Inject; import com.google.inject.Injector; import com.thoughtworks.xstream.XStream; import hudson.BulkChange; @@ -596,7 +597,16 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve * TCP agent port. * 0 for random, -1 to disable. */ - private int slaveAgentPort = SystemProperties.getInteger(Jenkins.class.getName()+".slaveAgentPort",0); + private int slaveAgentPort = getSlaveAgentPortInitialValue(0); + + private static int getSlaveAgentPortInitialValue(int def) { + return SystemProperties.getInteger(Jenkins.class.getName()+".slaveAgentPort", def); + } + + /** + * If -Djenkins.model.Jenkins.slaveAgentPort is defined, enforce it on every start instead of only the first one. + */ + private static final boolean SLAVE_AGENT_PORT_ENFORCE = SystemProperties.getBoolean(Jenkins.class.getName()+".slaveAgentPortEnforce", false); /** * The TCP agent protocols that are explicitly disabled (we store the disabled ones so that newer protocols @@ -606,6 +616,11 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve */ @CheckForNull private List disabledAgentProtocols; + /** + * @deprecated Just a temporary buffer for XSTream migration code from JENKINS-39465, do not use + */ + @Deprecated + private transient String[] _disabledAgentProtocols; /** * The TCP agent protocols that are {@link AgentProtocol#isOptIn()} and explicitly enabled. @@ -615,6 +630,11 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve */ @CheckForNull private List enabledAgentProtocols; + /** + * @deprecated Just a temporary buffer for XSTream migration code from JENKINS-39465, do not use + */ + @Deprecated + private transient String[] _enabledAgentProtocols; /** * The TCP agent protocols that are enabled. Built from {@link #disabledAgentProtocols} and @@ -947,11 +967,25 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve updateComputerList(); - {// master is online now - Computer c = toComputer(); - if(c!=null) - for (ComputerListener cl : ComputerListener.all()) - cl.onOnline(c, new LogTaskListener(LOGGER, INFO)); + {// master is online now, it's instance must always exist + final Computer c = toComputer(); + if(c != null) { + for (ComputerListener cl : ComputerListener.all()) { + try { + cl.onOnline(c, new LogTaskListener(LOGGER, INFO)); + } catch (Throwable t) { + if (t instanceof Error) { + // We propagate Runtime errors, because they are fatal. + throw t; + } + + // Other exceptions should be logged instead of failing the Jenkins startup (See listener's Javadoc) + // We also throw it for InterruptedException since it's what is expected according to the javadoc + LOGGER.log(SEVERE, String.format("Invocation of the computer listener %s failed for the Jenkins master node", + cl.getClass()), t); + } + } + } } for (ItemListener l : ItemListener.all()) { @@ -982,6 +1016,19 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve if (jdks == null) { jdks = new ArrayList<>(); } + if (SLAVE_AGENT_PORT_ENFORCE) { + slaveAgentPort = getSlaveAgentPortInitialValue(slaveAgentPort); + } + if (disabledAgentProtocols == null && _disabledAgentProtocols != null) { + disabledAgentProtocols = Arrays.asList(_disabledAgentProtocols); + _disabledAgentProtocols = null; + } + if (enabledAgentProtocols == null && _enabledAgentProtocols != null) { + enabledAgentProtocols = Arrays.asList(_enabledAgentProtocols); + _enabledAgentProtocols = null; + } + // Invalidate the protocols cache after the reload + agentProtocols = null; return this; } @@ -1091,11 +1138,26 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve return slaveAgentPort; } + /** + * @since TODO + */ + public boolean isSlaveAgentPortEnforced() { + return Jenkins.SLAVE_AGENT_PORT_ENFORCE; + } + /** * @param port * 0 to indicate random available TCP port. -1 to disable this service. */ public void setSlaveAgentPort(int port) throws IOException { + if (SLAVE_AGENT_PORT_ENFORCE) { + LOGGER.log(Level.WARNING, "setSlaveAgentPort({0}) call ignored because system property {1} is true", new String[] { Integer.toString(port), Jenkins.class.getName()+".slaveAgentPortEnforce" }); + } else { + forceSetSlaveAgentPort(port); + } + } + + private void forceSetSlaveAgentPort(int port) throws IOException { this.slaveAgentPort = port; launchTcpSlaveAgentListener(); } @@ -1206,6 +1268,38 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve } } + @Extension + @Restricted(NoExternalUse.class) + public static class EnforceSlaveAgentPortAdministrativeMonitor extends AdministrativeMonitor { + @Inject + Jenkins j; + + @Override + public String getDisplayName() { + return jenkins.model.Messages.EnforceSlaveAgentPortAdministrativeMonitor_displayName(); + } + + public String getSystemPropertyName() { + return Jenkins.class.getName() + ".slaveAgentPort"; + } + + public int getExpectedPort() { + int slaveAgentPort = j.slaveAgentPort; + return Jenkins.getSlaveAgentPortInitialValue(slaveAgentPort); + } + + public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException { + j.forceSetSlaveAgentPort(getExpectedPort()); + rsp.sendRedirect2(req.getContextPath() + "/manage"); + } + + @Override + public boolean isActivated() { + int slaveAgentPort = Jenkins.getInstance().slaveAgentPort; + return SLAVE_AGENT_PORT_ENFORCE && slaveAgentPort != Jenkins.getSlaveAgentPortInitialValue(slaveAgentPort); + } + } + public void setNodeName(String name) { throw new UnsupportedOperationException(); // not allowed } @@ -4949,8 +5043,8 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve // for backward compatibility with <1.75, recognize the tag name "view" as well. XSTREAM.alias("view", ListView.class); XSTREAM.alias("listView", ListView.class); - XSTREAM.addImplicitCollection(Jenkins.class, "disabledAgentProtocols", "disabledAgentProtocol", String.class); - XSTREAM.addImplicitCollection(Jenkins.class, "enabledAgentProtocols", "enabledAgentProtocol", String.class); + XSTREAM.addImplicitArray(Jenkins.class, "_disabledAgentProtocols", "disabledAgentProtocol"); + XSTREAM.addImplicitArray(Jenkins.class, "_enabledAgentProtocols", "enabledAgentProtocol"); XSTREAM2.addCriticalField(Jenkins.class, "securityRealm"); XSTREAM2.addCriticalField(Jenkins.class, "authorizationStrategy"); // this seems to be necessary to force registration of converter early enough diff --git a/core/src/main/java/jenkins/util/ResourceBundleUtil.java b/core/src/main/java/jenkins/util/ResourceBundleUtil.java index a62c3fa772..b2eee336ab 100644 --- a/core/src/main/java/jenkins/util/ResourceBundleUtil.java +++ b/core/src/main/java/jenkins/util/ResourceBundleUtil.java @@ -27,12 +27,16 @@ import net.sf.json.JSONObject; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import hudson.PluginWrapper; +import java.util.logging.Logger; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.concurrent.ConcurrentHashMap; +import jenkins.model.Jenkins; /** * Simple {@link java.util.ResourceBundle} utility class. @@ -42,6 +46,7 @@ import java.util.concurrent.ConcurrentHashMap; @Restricted(NoExternalUse.class) public class ResourceBundleUtil { + private static final Logger logger = Logger.getLogger("jenkins.util.ResourceBundle"); private static final Map bundles = new ConcurrentHashMap<>(); private ResourceBundleUtil() { @@ -72,7 +77,23 @@ public class ResourceBundleUtil { return bundleJSON; } - ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale); + ResourceBundle bundle = getBundle(baseName, locale, Jenkins.class.getClassLoader()); + if (bundle == null) { + // Not in Jenkins core. Check the plugins. + Jenkins jenkins = Jenkins.getInstance(); // will never return null + if (jenkins != null) { + for (PluginWrapper plugin : jenkins.getPluginManager().getPlugins()) { + bundle = getBundle(baseName, locale, plugin.classLoader); + if (bundle != null) { + break; + } + } + } + } + if (bundle == null) { + throw new MissingResourceException("Can't find bundle for base name " + + baseName + ", locale " + locale, baseName + "_" + locale, ""); + } bundleJSON = toJSONObject(bundle); bundles.put(bundleKey, bundleJSON); @@ -80,6 +101,30 @@ public class ResourceBundleUtil { return bundleJSON; } + /** + * Get a plugin bundle using the supplied Locale and classLoader + * + * @param baseName The bundle base name. + * @param locale The Locale. + * @param classLoader The classLoader + * @return The bundle JSON. + */ + private static @CheckForNull ResourceBundle getBundle(@Nonnull String baseName, @Nonnull Locale locale, @Nonnull ClassLoader classLoader) { + try { + return ResourceBundle.getBundle(baseName, locale, classLoader); + } catch (MissingResourceException e) { + // fall through and return null. + logger.finer(e.getMessage()); + } + return null; + } + + /** + * Create a JSON representation of a resource bundle + * + * @param bundle The resource bundle. + * @return The bundle JSON. + */ private static JSONObject toJSONObject(@Nonnull ResourceBundle bundle) { JSONObject json = new JSONObject(); for (String key : bundle.keySet()) { diff --git a/core/src/main/resources/hudson/model/BuildTimelineWidget/control.jelly b/core/src/main/resources/hudson/model/BuildTimelineWidget/control.jelly index f695275f06..a9efb2525b 100644 --- a/core/src/main/resources/hudson/model/BuildTimelineWidget/control.jelly +++ b/core/src/main/resources/hudson/model/BuildTimelineWidget/control.jelly @@ -41,35 +41,42 @@ THE SOFTWARE. var tz = ${(tz.rawOffset + tz.DSTSavings) / 3600000}; var tl = null; + var interval = 24*60*60*1000; - + diff --git a/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.groovy b/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.groovy index e56f86720c..f082a3fce5 100644 --- a/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.groovy +++ b/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.groovy @@ -26,8 +26,18 @@ l.layout(norefresh:true, permission:app.ADMINISTER, title:my.displayName, csscla set("descriptor", my.descriptor); f.optionalBlock( field:"useSecurity", title:_("Enable security"), checked:app.useSecurity) { - f.entry (title:_("TCP port for JNLP agents"), field:"slaveAgentPort") { - f.serverTcpPort() + f.entry(title: _("TCP port for JNLP agents"), field: "slaveAgentPort") { + if (my.slaveAgentPortEnforced) { + if (my.slaveAgentPort == -1) { + text(_("slaveAgentPortEnforcedDisabled")) + } else if (my.slaveAgentPort == 0) { + text(_("slaveAgentPortEnforcedRandom")) + } else { + text(_("slaveAgentPortEnforced", my.slaveAgentPort)) + } + } else { + f.serverTcpPort() + } } f.advanced(title: _("Agent protocols"), align:"left") { f.entry(title: _("Agent protocols")) { diff --git a/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.properties b/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.properties new file mode 100644 index 0000000000..4c959311a8 --- /dev/null +++ b/core/src/main/resources/hudson/security/GlobalSecurityConfiguration/index.properties @@ -0,0 +1,3 @@ +slaveAgentPortEnforced=enforced to {0,number,#} on startup through system property. +slaveAgentPortEnforcedRandom=enforced to random port on startup through system property. +slaveAgentPortEnforcedDisabled=disabled on startup through system property. diff --git a/core/src/main/resources/hudson/tools/Messages.properties b/core/src/main/resources/hudson/tools/Messages.properties index dabfa4c840..a59e064de7 100644 --- a/core/src/main/resources/hudson/tools/Messages.properties +++ b/core/src/main/resources/hudson/tools/Messages.properties @@ -37,3 +37,4 @@ JDKInstaller.DescriptorImpl.displayName=Install from java.sun.com JDKInstaller.DescriptorImpl.doCheckId=Define JDK ID JDKInstaller.DescriptorImpl.doCheckAcceptLicense=You must agree to the license to download the JDK. ToolDescriptor.NotADirectory={0} is not a directory on the Jenkins master (but perhaps it exists on some agents) +CannotBeInstalled=Installer "{0}" cannot be used to install "{1}" on the node "{2}" diff --git a/core/src/main/resources/jenkins/model/Jenkins/EnforceSlaveAgentPortAdministrativeMonitor/message.jelly b/core/src/main/resources/jenkins/model/Jenkins/EnforceSlaveAgentPortAdministrativeMonitor/message.jelly new file mode 100644 index 0000000000..bc2149f752 --- /dev/null +++ b/core/src/main/resources/jenkins/model/Jenkins/EnforceSlaveAgentPortAdministrativeMonitor/message.jelly @@ -0,0 +1,34 @@ + + + +
+ ${%description(it.systemPropertyName, it.expectedPort)} +
+
+ +
+
+
+
diff --git a/core/src/main/resources/jenkins/model/Jenkins/EnforceSlaveAgentPortAdministrativeMonitor/message.properties b/core/src/main/resources/jenkins/model/Jenkins/EnforceSlaveAgentPortAdministrativeMonitor/message.properties new file mode 100644 index 0000000000..e4f6f0fd8c --- /dev/null +++ b/core/src/main/resources/jenkins/model/Jenkins/EnforceSlaveAgentPortAdministrativeMonitor/message.properties @@ -0,0 +1,2 @@ +description=JNLP Agent Port has been changed but was specified through system property {0} on startup. Its value will be reset to {1,number,#} on restart. +reset=Reset to {0,number,#} diff --git a/core/src/main/resources/jenkins/model/Messages.properties b/core/src/main/resources/jenkins/model/Messages.properties index a1bb72ffe1..99fc5c3960 100644 --- a/core/src/main/resources/jenkins/model/Messages.properties +++ b/core/src/main/resources/jenkins/model/Messages.properties @@ -68,3 +68,5 @@ ParameterizedJobMixIn.build_now=Build Now BlockedBecauseOfBuildInProgress.shortDescription=Build #{0} is already in progress{1} BlockedBecauseOfBuildInProgress.ETA=\ (ETA:{0}) BuildDiscarderProperty.displayName=Discard old builds + +EnforceSlaveAgentPortAdministrativeMonitor.displayName=Enforce JNLP Slave Agent Port diff --git a/core/src/main/resources/lib/form/textarea/textarea.css b/core/src/main/resources/lib/form/textarea/textarea.css new file mode 100644 index 0000000000..71300ae0e3 --- /dev/null +++ b/core/src/main/resources/lib/form/textarea/textarea.css @@ -0,0 +1,5 @@ +td.setting-main .CodeMirror { + display: table; + table-layout: fixed; + width: 100%; +} \ No newline at end of file diff --git a/test/src/test/java/hudson/tools/InstallerTranslatorTest.java b/test/src/test/java/hudson/tools/InstallerTranslatorTest.java index 3d9e2a58fe..d38f780972 100644 --- a/test/src/test/java/hudson/tools/InstallerTranslatorTest.java +++ b/test/src/test/java/hudson/tools/InstallerTranslatorTest.java @@ -35,6 +35,8 @@ import hudson.slaves.RetentionStrategy; import hudson.tasks.Shell; import hudson.util.StreamTaskListener; import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import org.junit.Test; import static org.junit.Assert.*; @@ -98,4 +100,41 @@ public class InstallerTranslatorTest { r.assertLogContains("/opt/jdk1", b6); } + @Issue("JENKINS-26940") + @Test + public void testMessageLoggedWhenNoInstallerFound() throws Exception { + final CommandInstaller ci = new CommandInstaller("wrong1", "echo hello", "/opt/jdk"); + final BatchCommandInstaller bci = new BatchCommandInstaller("wrong2", "echo hello", "/opt/jdk2"); + InstallSourceProperty isp = new InstallSourceProperty(Arrays.asList(ci, bci)); + + JDK jdk = new JDK("jdk", null, Collections.singletonList(isp)); + r.jenkins.getJDKs().add(jdk); + + + FreeStyleProject p = r.createFreeStyleProject(); + p.setJDK(jdk); + p.getBuildersList().add(new Shell("echo $JAVA_HOME")); + FreeStyleBuild b1 = r.buildAndAssertSuccess(p); + r.assertLogContains(hudson.tools.Messages.CannotBeInstalled(ci.getDescriptor().getDisplayName(), jdk.getName(), r.jenkins.getDisplayName()), b1); + r.assertLogContains(hudson.tools.Messages.CannotBeInstalled(bci.getDescriptor().getDisplayName(), jdk.getName(), r.jenkins.getDisplayName()), b1); + } + + @Issue("JENKINS-26940") + @Test + public void testNoMessageLoggedWhenAnyInstallerFound() throws Exception { + final CommandInstaller ci = new CommandInstaller("wrong1", "echo hello", "/opt/jdk"); + final CommandInstaller ci2 = new CommandInstaller("master", "echo hello", "/opt/jdk2"); + InstallSourceProperty isp = new InstallSourceProperty(Arrays.asList(ci, ci2)); + + JDK jdk = new JDK("jdk", null, Collections.singletonList(isp)); + r.jenkins.getJDKs().add(jdk); + + + FreeStyleProject p = r.createFreeStyleProject(); + p.setJDK(jdk); + p.getBuildersList().add(new Shell("echo $JAVA_HOME")); + FreeStyleBuild b1 = r.buildAndAssertSuccess(p); + r.assertLogNotContains(ci.getDescriptor().getDisplayName(), b1); + } + } diff --git a/test/src/test/java/jenkins/I18nTest.java b/test/src/test/java/jenkins/I18nTest.java index a934422532..5f2da8e793 100644 --- a/test/src/test/java/jenkins/I18nTest.java +++ b/test/src/test/java/jenkins/I18nTest.java @@ -23,6 +23,7 @@ */ package jenkins; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import net.sf.json.JSONObject; import org.junit.Assert; import org.junit.Rule; @@ -31,6 +32,7 @@ import org.jvnet.hudson.test.JenkinsRule; import org.xml.sax.SAXException; import java.io.IOException; +import org.jvnet.hudson.test.Issue; /** * @author tom.fennelly@gmail.com @@ -49,9 +51,22 @@ public class I18nTest { @Test public void test_baseName_unknown() throws IOException, SAXException { - JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=com.acme.XyzWhatever").getJSONObject(); - Assert.assertEquals("error", response.getString("status")); - Assert.assertTrue(response.getString("message").contains("com.acme.XyzWhatever")); + try { + JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=com.acme.XyzWhatever").getJSONObject(); + } catch (FailingHttpStatusCodeException e) { + Assert.assertNotNull(e); + Assert.assertTrue(e.getMessage().contains("com.acme.XyzWhatever")); + } + } + + @Issue("JENKINS-35270") + @Test + public void test_baseName_plugin() throws IOException, SAXException { + // ssh-slaves plugin is installed by default + JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=hudson.plugins.sshslaves.Messages").getJSONObject(); + Assert.assertEquals("ok", response.getString("status")); + JSONObject data = response.getJSONObject("data"); + Assert.assertEquals("The launch timeout must be a number.", data.getString("SSHConnector.LaunchTimeoutMustBeANumber")); } @Test diff --git a/test/src/test/java/jenkins/model/JenkinsTest.java b/test/src/test/java/jenkins/model/JenkinsTest.java index 936e1ae977..e20d7f9a48 100644 --- a/test/src/test/java/jenkins/model/JenkinsTest.java +++ b/test/src/test/java/jenkins/model/JenkinsTest.java @@ -25,7 +25,10 @@ package jenkins.model; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertEquals; @@ -42,6 +45,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.maven.MavenModuleSet; import hudson.maven.MavenModuleSetBuild; +import hudson.model.Computer; import hudson.model.Failure; import hudson.model.RestartListener; import hudson.model.RootAction; @@ -51,6 +55,7 @@ import hudson.security.FullControlOnceLoggedInAuthorizationStrategy; import hudson.security.HudsonPrivateSecurityRealm; import hudson.util.HttpResponses; import hudson.model.FreeStyleProject; +import hudson.model.TaskListener; import hudson.security.GlobalMatrixAuthorizationStrategy; import hudson.security.LegacySecurityRealm; import hudson.security.Permission; @@ -59,6 +64,7 @@ import hudson.slaves.DumbSlave; import hudson.slaves.OfflineCause; import hudson.util.FormValidation; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Issue; @@ -70,8 +76,15 @@ import org.kohsuke.stapler.HttpResponse; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import org.junit.Assume; /** * @author kingfai @@ -452,4 +465,133 @@ public class JenkinsTest { assertThat(rsp.getContentAsString(), containsString("Node is offline")); assertThat(rsp.getStatusCode(), equalTo(404)); } + + @Test + @Issue("JENKINS-38487") + public void startupShouldNotFailOnFailingOnlineListener() { + // We do nothing, FailingOnOnlineListener & JenkinsRule should cause the + // boot failure if the issue is not fixed. + } + + @TestExtension(value = "startupShouldNotFailOnFailingOnlineListener") + public static final class FailingOnOnlineListener extends ComputerListener { + + @Override + public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException { + throw new IOException("Something happened (the listener always throws this exception)"); + } + } + + @Test + @Issue("JENKINS-39465") + public void agentProtocols_singleEnable_roundtrip() throws Exception { + final Set defaultProtocols = Collections.unmodifiableSet(j.jenkins.getAgentProtocols()); + Assume.assumeThat("We assume that JNLP3-connect is disabled", + defaultProtocols, not(hasItem("JNLP3-connect"))); + + final Set newProtocols = new HashSet<>(defaultProtocols); + newProtocols.add("JNLP3-connect"); + j.jenkins.setAgentProtocols(newProtocols); + j.jenkins.save(); + final Set agentProtocolsBeforeReload = j.jenkins.getAgentProtocols(); + assertThat("JNLP3-connect must be enabled before the roundtrip", + j.jenkins.getAgentProtocols(), hasItem("JNLP3-connect")); + + j.jenkins.reload(); + + final Set reloadedProtocols = j.jenkins.getAgentProtocols(); + assertFalse("The protocol list must have been really reloaded", agentProtocolsBeforeReload == reloadedProtocols); + assertThat("We should have additional enabled protocol", + reloadedProtocols.size(), equalTo(defaultProtocols.size() + 1)); + assertThat("JNLP3-connect must be enabled after the roundtrip", + reloadedProtocols, hasItem("JNLP3-connect")); + } + + @Test + @Issue("JENKINS-39465") + public void agentProtocols_multipleDisable_roundtrip() throws Exception { + final Set defaultProtocols = Collections.unmodifiableSet(j.jenkins.getAgentProtocols()); + Assume.assumeThat("At least one protocol is enabled", defaultProtocols.size(), greaterThan(0)); + + final String protocolToDisable = defaultProtocols.iterator().next(); + + final Set newProtocols = new HashSet<>(defaultProtocols); + newProtocols.remove(protocolToDisable); + j.jenkins.setAgentProtocols(newProtocols); + j.jenkins.save(); + assertThat(protocolToDisable + " must be disabled before the roundtrip", + j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable))); + final Set agentProtocolsBeforeReload = j.jenkins.getAgentProtocols(); + j.jenkins.reload(); + + assertFalse("The protocol list must have been really refreshed", agentProtocolsBeforeReload == j.jenkins.getAgentProtocols()); + assertThat("We should have disabled one protocol", + j.jenkins.getAgentProtocols().size(), equalTo(defaultProtocols.size() - 1)); + assertThat(protocolToDisable + " must be disabled after the roundtrip", + j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable))); + } + + @Test + @Issue("JENKINS-39465") + @Ignore("No JNLP4 for 2.19.3") + public void agentProtocols_multipleEnable_roundtrip() throws Exception { + final Set defaultProtocols = Collections.unmodifiableSet(j.jenkins.getAgentProtocols()); + Assume.assumeThat("We assume that JNLP3-connect is disabled", + defaultProtocols, not(hasItem("JNLP3-connect"))); + Assume.assumeThat("We assume that JNLP4-connect is disabled", + defaultProtocols, not(hasItem("JNLP4-connect"))); + + final Set newProtocols = new HashSet<>(defaultProtocols); + newProtocols.add("JNLP3-connect"); + newProtocols.add("JNLP4-connect"); + j.jenkins.setAgentProtocols(newProtocols); + j.jenkins.save(); + final Set agentProtocolsBeforeReload = j.jenkins.getAgentProtocols(); + assertThat("JNLP3-connect must be enabled before the roundtrip", + j.jenkins.getAgentProtocols(), hasItem("JNLP3-connect")); + assertThat("JNLP4-connect must be enabled before the roundtrip", + j.jenkins.getAgentProtocols(), hasItem("JNLP4-connect")); + + j.jenkins.reload(); + + final Set reloadedProtocols = j.jenkins.getAgentProtocols(); + assertFalse("The protocol list must have been really reloaded", agentProtocolsBeforeReload == reloadedProtocols); + assertThat("We should have two additional enabled protocols", + reloadedProtocols.size(), equalTo(defaultProtocols.size() + 2)); + assertThat("JNLP3-connect must be enabled after the roundtrip", + reloadedProtocols, hasItem("JNLP3-connect")); + assertThat("JNLP3-connect must be enabled after the roundtrip", + reloadedProtocols, hasItem("JNLP4-connect")); + } + + @Test + @Issue("JENKINS-39465") + public void agentProtocols_singleDisable_roundtrip() throws Exception { + final Set defaultProtocols = Collections.unmodifiableSet(j.jenkins.getAgentProtocols()); + Assume.assumeThat("At least two protocol should be enabled", defaultProtocols.size(), greaterThan(1)); + + Iterator iterator = defaultProtocols.iterator(); + final String protocolToDisable1 = iterator.next(); + final String protocolToDisable2 = iterator.next(); + + final Set newProtocols = new HashSet<>(defaultProtocols); + newProtocols.remove(protocolToDisable1); + newProtocols.remove(protocolToDisable2); + j.jenkins.setAgentProtocols(newProtocols); + j.jenkins.save(); + assertThat(protocolToDisable1 + " must be disabled before the roundtrip", + j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable1))); + assertThat(protocolToDisable2 + " must be disabled before the roundtrip", + j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable2))); + final Set agentProtocolsBeforeReload = j.jenkins.getAgentProtocols(); + j.jenkins.reload(); + + assertFalse("The protocol list must have been really reloaded", agentProtocolsBeforeReload == j.jenkins.getAgentProtocols()); + assertThat("We should have disabled two protocols", + j.jenkins.getAgentProtocols().size(), equalTo(defaultProtocols.size() - 2)); + assertThat(protocolToDisable1 + " must be disaabled after the roundtrip", + j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable1))); + assertThat(protocolToDisable2 + " must be disaabled after the roundtrip", + j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable2))); + } } diff --git a/war/src/main/js/add-item.js b/war/src/main/js/add-item.js index 22338ece65..7156144471 100644 --- a/war/src/main/js/add-item.js +++ b/war/src/main/js/add-item.js @@ -107,7 +107,6 @@ $.when(getItems()).done(function(data) { btn.removeClass('disabled'); btn.prop('disabled', false); } - btn.focus(); } else { if (!btn.hasClass('disabled')) { btn.addClass('disabled'); @@ -233,7 +232,7 @@ $.when(getItems()).done(function(data) { $("#add-item-panel").find("#name").focus(); // Init NameField - $('input[name="name"]', '#createItem').blur(function() { + $('input[name="name"]', '#createItem').on("blur input", function() { if (!isItemNameEmpty()) { var itemName = $('input[name="name"]', '#createItem').val(); $.get("checkJobName", { value: itemName }).done(function(data) { diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 1b89841a45..2966527713 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -1486,6 +1486,7 @@ function expandTextArea(button,id) { // refresh a part of the HTML specified by the given ID, // by using the contents fetched from the given URL. function refreshPart(id,url) { + var intervalID = null; var f = function() { if(isPageVisible()) { new Ajax.Request(url, { @@ -1493,6 +1494,8 @@ function refreshPart(id,url) { var hist = $(id); if (hist == null) { console.log("There's no element that has ID of " + id); + if (intervalID !== null) + window.clearInterval(intervalID); return; } var p = hist.up(); @@ -1505,22 +1508,14 @@ function refreshPart(id,url) { Behaviour.applySubtree(node); layoutUpdateCallback.call(); - - if(isRunAsTest) return; - refreshPart(id,url); } - }); - } else { - // Reschedule - if(isRunAsTest) return; - refreshPart(id,url); + }); } - }; // if run as test, just do it once and do it now to make sure it's working, // but don't repeat. if(isRunAsTest) f(); - else window.setTimeout(f, 5000); + else intervalID = window.setInterval(f, 5000); }