Skip to content
Permalink
Browse files
Merge remote-tracking branch 'upstream/2.0' into JENKINS-31162
  • Loading branch information
recena committed Mar 23, 2016
2 parents 1fdc56b + 6a355ae commit 3fe0a1ed706137c792b7af8d3c7cc2ba2be017ff
Showing 40 changed files with 605 additions and 71 deletions.
@@ -130,7 +130,6 @@

import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.GlobalConfigurationCategory.Unclassified;
import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithChildren;
import jenkins.model.ModelObjectWithContextMenu;
@@ -965,12 +964,8 @@ public static Collection<Descriptor> getSortedDescriptorsForGlobalConfig(Predica
Descriptor d = c.getInstance();
if (d.getGlobalConfigPage()==null) continue;

if (d instanceof GlobalConfiguration) {
if (predicate.apply(((GlobalConfiguration)d).getCategory()))
r.add(new Tag(c.ordinal(), d));
} else {
if (predicate.apply(GlobalConfigurationCategory.get(Unclassified.class)))
r.add(new Tag(0, d));
if (predicate.apply(d.getCategory())) {
r.add(new Tag(c.ordinal(), d));
}
}
Collections.sort(r);
@@ -36,6 +36,8 @@
import hudson.util.ReflectionUtils;
import hudson.util.ReflectionUtils.Parameter;
import hudson.views.ListViewColumn;
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -807,7 +809,18 @@ public String getConfigPage() {
public String getGlobalConfigPage() {
return getViewPage(clazz, getPossibleViewNames("global"), null);
}


/**
* Define the global configuration category the global config of this Descriptor is in.
*
* @return never null, always the same value for a given instance of {@link Descriptor}.
*
* @since TODO, used to be in {@link GlobalConfiguration} before that.
*/
public GlobalConfigurationCategory getCategory() {
return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Unclassified.class);
}

private String getViewPage(Class<?> clazz, String pageName, String defaultValue) {
return getViewPage(clazz,Collections.singleton(pageName),defaultValue);
}
@@ -35,7 +35,7 @@
public class ManageJenkinsAction implements RootAction {
public String getIconFileName() {
if (Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER))
return "setting.png";
return "gear2.png";
else
return null;
}
@@ -34,7 +34,10 @@
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.Jenkins;
import jenkins.tools.ToolConfigurationCategory;
import net.sf.json.JSONObject;
import org.jvnet.tiger_types.Types;
import org.kohsuke.stapler.QueryParameter;
@@ -89,6 +92,12 @@ public List<ToolPropertyDescriptor> getPropertyDescriptors() {
return PropertyDescriptor.for_(ToolProperty.all(),clazz);
}


@Override
public GlobalConfigurationCategory getCategory() {
return GlobalConfigurationCategory.get(ToolConfigurationCategory.class);
}

/**
* Optional list of installers to be configured by default for new tools of this type.
* If there are popular versions of the tool available using generic installation techniques,
@@ -1,5 +1,26 @@
package jenkins.install;

import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import hudson.util.VersionNumber;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import hudson.BulkChange;
import hudson.FilePath;
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy;
@@ -85,24 +106,24 @@ public SetupWizard(Jenkins j) throws IOException, InterruptedException {
bc.abort();
}
}

String setupKey = iapf.readToString().trim();

LOGGER.info("\n\n*************************************************************\n"
+ "*************************************************************\n"
+ "*************************************************************\n"
+ "\n"
String ls = System.lineSeparator();
LOGGER.info(ls + ls + "*************************************************************" + ls
+ "*************************************************************" + ls
+ "*************************************************************" + ls
+ ls
+ "Jenkins initial setup is required. An admin user has been created and"
+ "a password generated. \n"
+ "Please use the following password to proceed to installation: \n"
+ "\n"
+ "" + setupKey + "\n"
+ "\n"
+ "This may also be found at: " + iapf.getRemote() + "\n"
+ "\n"
+ "*************************************************************\n"
+ "*************************************************************\n"
+ "*************************************************************\n");
+ "a password generated." + ls
+ "Please use the following password to proceed to installation:" + ls
+ ls
+ setupKey + ls
+ ls
+ "This may also be found at: " + iapf.getRemote() + ls
+ ls
+ "*************************************************************" + ls
+ "*************************************************************" + ls
+ "*************************************************************" + ls);

try {
PluginServletFilter.addFilter(FORCE_SETUP_WIZARD_FILTER);
@@ -128,6 +149,11 @@ public HttpResponse doCompleteInstall() throws IOException, ServletException {
PluginServletFilter.removeFilter(FORCE_SETUP_WIZARD_FILTER);
// Also, clean up the setup wizard if it's completed
jenkins.setSetupWizard(null);

UpgradeWizard uw = jenkins.getInjector().getInstance(UpgradeWizard.class);
if (uw!=null)
uw.setCurrentLevel(new VersionNumber("2.0"));

return HttpResponses.okJSON();
}

@@ -0,0 +1,147 @@
package jenkins.install;

import hudson.Extension;
import hudson.model.PageDecorator;
import hudson.model.UpdateSite.Plugin;
import hudson.util.HttpResponses;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
import org.apache.commons.io.FileUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.interceptor.RequirePOST;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import static java.util.logging.Level.*;
import static org.apache.commons.io.FileUtils.*;
import static org.apache.commons.lang.StringUtils.*;

/**
* This is a stop-gap measure until JENKINS-33663 comes in.
* This call may go away. Please don't use it from outside.
*
* @author Kohsuke Kawaguchi
*/
@Restricted(NoExternalUse.class)
@Extension
public class UpgradeWizard extends PageDecorator {
@Inject
private Jenkins jenkins;

/**
* Is this instance fully upgraded?
*/
private volatile boolean upToDate;

/**
* File that captures the state of upgrade.
*
* This file records the vesrion number that the installation has upgraded to.
*/
/*package*/ File getStateFile() {
return new File(Jenkins.getInstance().getRootDir(),"upgraded");
}

public UpgradeWizard() throws IOException {
updateUpToDate();
}

private void updateUpToDate() throws IOException {
upToDate = new VersionNumber("2.0").compareTo(getCurrentLevel()) <= 0;
}

/**
* What is the version the upgrade wizard has run the last time and upgraded to?
*/
private VersionNumber getCurrentLevel() throws IOException {
VersionNumber from = new VersionNumber("1.0");
File state = getStateFile();
if (state.exists()) {
from = new VersionNumber(defaultIfBlank(readFileToString(state), "1.0").trim());
}
return from;
}

/*package*/
public void setCurrentLevel(VersionNumber v) throws IOException {
FileUtils.writeStringToFile(getStateFile(), v.toString());
updateUpToDate();
}

/**
* Do we need to show the upgrade wizard prompt?
*/
public boolean isDue() {
if (upToDate)
return false;

// only admin users should see this
if (!jenkins.hasPermission(Jenkins.ADMINISTER))
return false;

return System.currentTimeMillis() > getStateFile().lastModified();
}

/**
* Snooze the upgrade wizard notice.
*/
@RequirePOST
public HttpResponse doSnooze() throws IOException {
jenkins.checkPermission(Jenkins.ADMINISTER);
File f = getStateFile();
FileUtils.touch(f);
f.setLastModified(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1));
LOGGER.log(FINE, "Snoozed the upgrade wizard notice");
return HttpResponses.redirectToContextRoot();
}

/**
* Performs the upgrade activity.
*/
@RequirePOST
public HttpResponse doUpgrade() throws IOException {
jenkins.checkPermission(Jenkins.ADMINISTER);
try {
if (new VersionNumber("2.0").compareTo(getCurrentLevel())>0) {
// 1.0 -> 2.0 upgrade
LOGGER.log(WARNING, "Performing 1.0 to 2.0 upgrade");

for (String shortName : Arrays.asList("workflow-aggregator", "pipeline-stage-view", "github-organization-folder")) {
Plugin p = jenkins.getUpdateCenter().getPlugin(shortName);
if (p==null) {
LOGGER.warning("Plugin not found in the update center: " + shortName);
} else {
p.deploy(true);
}
}

// upgrade to 2.0 complete (if plugin installations fail, that's too bad)
FileUtils.writeStringToFile(getStateFile(),"2.0");

// send the user to the update center so that people can see the installation & restart if need be.
return HttpResponses.redirectViaContextPath("updateCenter/");
}

// in the future...
// if (new VersionNumber("3.0").compareTo(getCurrentLevel())>0) {
//
// }

return NOOP;
} finally {
updateUpToDate();
}
}

/*package*/ static final HttpResponse NOOP = HttpResponses.redirectToContextRoot();


private static final Logger LOGGER = Logger.getLogger(UpgradeWizard.class.getName());
}
@@ -35,7 +35,7 @@ public class ConfigureLink extends ManagementLink {

@Override
public String getIconFileName() {
return "setting.png";
return "gear2.png";
}

public String getDisplayName() {
@@ -42,15 +42,6 @@ public final Descriptor<GlobalConfiguration> getDescriptor() {
return this;
}

/**
* Every {@link GlobalConfiguration} belongs to a specific category.
*
* @return never null, always the same value for a given instance of {@link GlobalConfiguration}.
*/
public GlobalConfigurationCategory getCategory() {
return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Unclassified.class);
}

@Override
public String getGlobalConfigPage() {
return getConfigPage();
@@ -4,8 +4,6 @@
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.model.ModelObject;
import hudson.security.*;
import hudson.security.Messages;

/**
* Grouping of related {@link GlobalConfiguration}s.
@@ -73,11 +71,12 @@ public String getDisplayName() {
public static class Security extends GlobalConfigurationCategory {
@Override
public String getShortDescription() {
return Messages.GlobalSecurityConfiguration_Description();
return hudson.security.Messages.GlobalSecurityConfiguration_Description();
}

public String getDisplayName() {
return hudson.security.Messages.GlobalSecurityConfiguration_DisplayName();
}
}

}
@@ -3354,8 +3354,6 @@ public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp

systemMessage = Util.nullify(req.getParameter("system_message"));

setJDKs(req.bindJSONToList(JDK.class, json.get("jdks")));

boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigUnclassified())
result &= configureDescriptor(req,json,d);
@@ -2,6 +2,8 @@

import hudson.Extension;
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.tools.ToolConfigurationCategory;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.StaplerRequest;
@@ -16,6 +18,11 @@ public GlobalMavenConfig() {
load();
}

@Override
public ToolConfigurationCategory getCategory() {
return GlobalConfigurationCategory.get(ToolConfigurationCategory.class);
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
req.bindJSON(this, json);

0 comments on commit 3fe0a1e

Please sign in to comment.