Skip to content

Commit

Permalink
Merge pull request #3505 from oleg-nenashev/java11-support
Browse files Browse the repository at this point in the history
[Java 11 support] - Pick weekly and new Java 10 fixes
  • Loading branch information
oleg-nenashev authored Jun 18, 2018
2 parents 7b7415b + f520fb7 commit bf49945
Show file tree
Hide file tree
Showing 35 changed files with 1,228 additions and 210 deletions.
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ THE SOFTWARE.
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.41</version>
<version>3.0.45</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
Expand Down Expand Up @@ -212,7 +212,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>bytecode-compatibility-transformer</artifactId>
<version>2.0-alpha-3</version>
<version>2.0-alpha-4-20180618.093353-2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import hudson.model.ModelObject;
import hudson.model.Node;
import hudson.model.PageDecorator;
import jenkins.model.SimplePageDecorator;
import hudson.model.PaneStatusProperties;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterDefinition.ParameterDescriptor;
Expand Down Expand Up @@ -133,8 +134,6 @@
import jenkins.model.ModelObjectWithChildren;
import jenkins.model.ModelObjectWithContextMenu;

import org.acegisecurity.Authentication;
import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.Script;
Expand Down Expand Up @@ -1772,7 +1771,14 @@ public static List<PageDecorator> getPageDecorators() {
if(Jenkins.getInstanceOrNull()==null) return Collections.emptyList();
return PageDecorator.all();
}

/**
* Gets only one {@link SimplePageDecorator}.
* @since FIXME
*/
public static SimplePageDecorator getSimplePageDecorator() {
return SimplePageDecorator.first();
}

public static List<Descriptor<Cloud>> getCloudDescriptors() {
return Cloud.all();
}
Expand Down
12 changes: 1 addition & 11 deletions core/src/main/java/hudson/cli/CliProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CliProtocol extends AgentProtocol {
*/
@Override
public boolean isOptIn() {
return OPT_IN;
return true;
}

@Override
Expand Down Expand Up @@ -109,14 +109,4 @@ protected void runCli(Connection c) throws IOException, InterruptedException {
channel.join();
}
}

/**
* A/B test turning off this protocol by default.
*/
private static final boolean OPT_IN;

static {
byte hash = Util.fromHexString(Jenkins.getInstance().getLegacyInstanceId())[0];
OPT_IN = (hash % 10) == 0;
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/cli/CliProtocol2.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String getName() {
*/
@Override
public boolean isOptIn() {
return false;
return true;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/UpdateCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
@ExportedBean
public class UpdateCenter extends AbstractModelObject implements Saveable, OnMaster {

private static final String UPDATE_CENTER_URL = SystemProperties.getString(UpdateCenter.class.getName()+".updateCenterUrl","https://updates.jenkins.io/");
// TODO: Revert to the common update center before the release (JENKINS-52013)
private static final String UPDATE_CENTER_URL = SystemProperties.getString(UpdateCenter.class.getName()+".updateCenterUrl","https://updates.jenkins.io/experimental/");

/**
* Read timeout when downloading plugins, defaults to 1 minute
Expand Down
66 changes: 37 additions & 29 deletions core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.*;
import java.util.logging.Logger;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -312,13 +308,22 @@ public User createAccountByAdmin(StaplerRequest req, StaplerResponse rsp, String
public User createAccountFromSetupWizard(StaplerRequest req) throws IOException, AccountCreationFailedException {
checkPermission(Jenkins.ADMINISTER);
SignupInfo si = validateAccountCreationForm(req, false);
if (si.errorMessage != null) {
throw new AccountCreationFailedException(si.errorMessage);
if (!si.errors.isEmpty()) {
String messages = getErrorMessages(si);
throw new AccountCreationFailedException(messages);
} else {
return createAccount(si);
}
}

private String getErrorMessages(SignupInfo si) {
StringBuilder messages = new StringBuilder();
for (String message : si.errors.values()) {
messages.append(message).append(" | ");
}
return messages.toString();
}

/**
* Creates a first admin user account.
*
Expand Down Expand Up @@ -363,7 +368,7 @@ private void tryToMakeAdmin(User u) {
private User createAccount(StaplerRequest req, StaplerResponse rsp, boolean validateCaptcha, String formView) throws ServletException, IOException {
SignupInfo si = validateAccountCreationForm(req, validateCaptcha);

if (si.errorMessage != null) {
if (!si.errors.isEmpty()) {
// failed. ask the user to try again.
req.getView(this, formView).forward(req, rsp);
return null;
Expand All @@ -377,72 +382,73 @@ private User createAccount(StaplerRequest req, StaplerResponse rsp, boolean vali
* @param validateCaptcha whether to attempt to validate a captcha in the request
*
* @return a {@link SignupInfo#SignupInfo(StaplerRequest) SignupInfo from given request}, with {@link
* SignupInfo#errorMessage} set to a non-null value if any of the supported fields are invalid
* SignupInfo#errors} set to a non-null value if any of the supported fields are invalid
*/
private SignupInfo validateAccountCreationForm(StaplerRequest req, boolean validateCaptcha) {
// form field validation
// this pattern needs to be generalized and moved to stapler
SignupInfo si = new SignupInfo(req);

if (validateCaptcha && !validateCaptcha(si.captcha)) {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_TextNotMatchWordInImage();
}

if (si.password1 != null && !si.password1.equals(si.password2)) {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_PasswordNotMatch();
}

if (!(si.password1 != null && si.password1.length() != 0)) {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_PasswordRequired();
si.errors.put("captcha", Messages.HudsonPrivateSecurityRealm_CreateAccount_TextNotMatchWordInImage());
}

if (si.username == null || si.username.length() == 0) {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameRequired();
si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameRequired());
} else if(!containsOnlyAcceptableCharacters(si.username)) {
if (ID_REGEX == null) {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharacters();
si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharacters());
} else {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharactersCustom(ID_REGEX);
si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameInvalidCharactersCustom(ID_REGEX));
}
} else {
// do not create the user - we just want to check if the user already exists but is not a "login" user.
User user = User.getById(si.username, false);
if (null != user)
// Allow sign up. SCM people has no such property.
if (user.getProperty(Details.class) != null)
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameAlreadyTaken();
si.errors.put("username", Messages.HudsonPrivateSecurityRealm_CreateAccount_UserNameAlreadyTaken());
}

if (si.password1 != null && !si.password1.equals(si.password2)) {
si.errors.put("password1", Messages.HudsonPrivateSecurityRealm_CreateAccount_PasswordNotMatch());
}

if (!(si.password1 != null && si.password1.length() != 0)) {
si.errors.put("password1", Messages.HudsonPrivateSecurityRealm_CreateAccount_PasswordRequired());
}

if (si.fullname == null || si.fullname.length() == 0) {
si.fullname = si.username;
}

if (isMailerPluginPresent() && (si.email == null || !si.email.contains("@"))) {
si.errorMessage = Messages.HudsonPrivateSecurityRealm_CreateAccount_InvalidEmailAddress();
si.errors.put("email", Messages.HudsonPrivateSecurityRealm_CreateAccount_InvalidEmailAddress());
}

if (!User.isIdOrFullnameAllowed(si.username)) {
si.errorMessage = hudson.model.Messages.User_IllegalUsername(si.username);
si.errors.put("username", hudson.model.Messages.User_IllegalUsername(si.username));
}

if (!User.isIdOrFullnameAllowed(si.fullname)) {
si.errorMessage = hudson.model.Messages.User_IllegalFullname(si.fullname);
si.errors.put("fullname", hudson.model.Messages.User_IllegalFullname(si.fullname));
}
req.setAttribute("data", si); // for error messages in the view
return si;
}

/**
* Creates a new account from a valid signup info. A signup info is valid if its {@link SignupInfo#errorMessage}
* field is null.
* Creates a new account from a valid signup info. A signup info is valid if its {@link SignupInfo#errors}
* field is empty.
*
* @param si the valid signup info to create an account from
* @return a valid {@link User} object created from given signup info
* @throws IllegalArgumentException if an invalid signup info is passed
*/
private User createAccount(SignupInfo si) throws IOException {
if (si.errorMessage != null) {
throw new IllegalArgumentException("invalid signup info passed to createAccount(si): " + si.errorMessage);
if (!si.errors.isEmpty()) {
String messages = getErrorMessages(si);
throw new IllegalArgumentException("invalid signup info passed to createAccount(si): " + messages);
}
// register the user
User user = createAccount(si.username, si.password1);
Expand Down Expand Up @@ -541,6 +547,8 @@ public static final class SignupInfo {
*/
public String errorMessage;

public HashMap<String, String> errors = new HashMap<String, String>();

public SignupInfo() {
}

Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/jenkins/install/SetupWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ public SetupWizard() {

// Disable CLI over Remoting
CLI.get().setEnabled(false);

// Disable old Non-Encrypted protocols ()
HashSet<String> newProtocols = new HashSet<>(jenkins.getAgentProtocols());
newProtocols.removeAll(Arrays.asList(
"JNLP2-connect", "JNLP-connect", "CLI-connect"
));
jenkins.setAgentProtocols(newProtocols);

// require a crumb issuer
jenkins.setCrumbIssuer(new DefaultCrumbIssuer(SystemProperties.getBoolean(Jenkins.class.getName() + ".crumbIssuerProxyCompatibility",false)));
Expand Down
36 changes: 36 additions & 0 deletions core/src/main/java/jenkins/model/DefaultSimplePageDecorator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* The MIT License
*
* Copyright 2018, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins.model;

import hudson.Extension;

/**
* In case there are no other implementations we will fallback to this implementation.
*
* To make sure that we load this extension last (or at least very late) we use a negative ordinal.
* This allows custom implementation to be "first"
*/
@Extension(ordinal=-9999)
public class DefaultSimplePageDecorator extends SimplePageDecorator {
}
72 changes: 72 additions & 0 deletions core/src/main/java/jenkins/model/SimplePageDecorator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* The MIT License
*
* Copyright 2018, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins.model;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;
/**
* Participates in the rendering of the login page
*
* <p>
* This class provides a few hooks to augment the HTML of the login page.
*
* @since TODO
*/
public class SimplePageDecorator extends Descriptor<SimplePageDecorator> implements ExtensionPoint, Describable<SimplePageDecorator> {

protected SimplePageDecorator() {
super(self());
}

@Override
public final Descriptor<SimplePageDecorator> getDescriptor() {
return this;
}
/**
* Obtains the URL of this object, excluding the context path.
*
* <p>
* Every {@link SimplePageDecorator} is bound to URL via {@link Jenkins#getDescriptor()}.
* This method returns such an URL.
*/
public final String getUrl() {
return "descriptor/"+clazz.getName();
}

/**
* The first found LoginDecarator, there can only be one.
* @return the first found {@link SimplePageDecorator}
*/
public static SimplePageDecorator first(){
DescriptorExtensionList<SimplePageDecorator, SimplePageDecorator> descriptorList = Jenkins.getInstanceOrNull().<SimplePageDecorator, SimplePageDecorator>getDescriptorList(SimplePageDecorator.class);
if (descriptorList.size() >= 1) {
return descriptorList.get(0);
} else {
return null;
}
}

}
12 changes: 1 addition & 11 deletions core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setHub(NioChannelSelector hub) {
*/
@Override
public boolean isOptIn() {
return OPT_IN;
return true;
}

@Override
Expand Down Expand Up @@ -104,14 +104,4 @@ public void handle(Socket socket) throws IOException, InterruptedException {
ExtensionList.lookup(JnlpAgentReceiver.class));
}


/**
* A/B test turning off this protocol by default.
*/
private static final boolean OPT_IN;

static {
byte hash = Util.fromHexString(Jenkins.getInstance().getLegacyInstanceId())[0];
OPT_IN = (hash % 10) == 0;
}
}
Loading

0 comments on commit bf49945

Please sign in to comment.