From 90b977ea8e9e6efa6052fa7ee8fa9dedf26ce432 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 10 Jun 2016 18:46:05 -0400 Subject: [PATCH] [JENKINS-35098] Disable AutoBrowserHolder by default to improve the changelog rendering performance (#2371) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FIXED JENKINS-35098] Deleting AutoBrowserHolder. * Normalizing form binding scheme for AbstractProject.scm. * At @oleg-nenashev’s insistence, restoring AutoBrowserHolder, though not using it by default. * Using SystemProperties at @oleg-nenashev’s recommendation. (cherry picked from commit d33df0f2e4cbe5a6e35f34ece96059826aa7471d) --- .../java/hudson/scm/AutoBrowserHolder.java | 2 ++ core/src/main/java/hudson/scm/NullSCM.java | 11 +++++----- core/src/main/java/hudson/scm/SCM.java | 20 ++++++++++++++----- .../main/java/hudson/scm/SCMDescriptor.java | 4 ++++ core/src/main/java/hudson/scm/SCMS.java | 11 ++++------ .../lib/hudson/project/config-scm.jelly | 12 +++++------ 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/hudson/scm/AutoBrowserHolder.java b/core/src/main/java/hudson/scm/AutoBrowserHolder.java index 9f6dd18024..10e03cb0f6 100644 --- a/core/src/main/java/hudson/scm/AutoBrowserHolder.java +++ b/core/src/main/java/hudson/scm/AutoBrowserHolder.java @@ -37,7 +37,9 @@ import jenkins.model.Jenkins; * *

* This class makes such tracking easy by hiding this logic. + * @deprecated Disabled by default: JENKINS-35098 */ +@Deprecated final class AutoBrowserHolder { private int cacheGeneration; private RepositoryBrowser cache; diff --git a/core/src/main/java/hudson/scm/NullSCM.java b/core/src/main/java/hudson/scm/NullSCM.java index 911bac13a0..777db3759e 100644 --- a/core/src/main/java/hudson/scm/NullSCM.java +++ b/core/src/main/java/hudson/scm/NullSCM.java @@ -31,9 +31,8 @@ import hudson.model.Run; import hudson.model.TaskListener; import java.io.File; import java.io.IOException; -import net.sf.json.JSONObject; import org.jenkinsci.Symbol; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.DataBoundConstructor; /** * No {@link SCM}. @@ -41,6 +40,10 @@ import org.kohsuke.stapler.StaplerRequest; * @author Kohsuke Kawaguchi */ public class NullSCM extends SCM { + + @DataBoundConstructor + public NullSCM() {} + @Override public SCMRevisionState calcRevisionsFromBuild(Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { return null; } @@ -69,9 +72,5 @@ public class NullSCM extends SCM { return Messages.NullSCM_DisplayName(); } - @Override - public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException { - return new NullSCM(); - } } } diff --git a/core/src/main/java/hudson/scm/SCM.java b/core/src/main/java/hudson/scm/SCM.java index ce9d7a6762..2cf3341665 100644 --- a/core/src/main/java/hudson/scm/SCM.java +++ b/core/src/main/java/hudson/scm/SCM.java @@ -58,6 +58,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; import jenkins.model.Jenkins; +import jenkins.util.SystemProperties; import org.kohsuke.stapler.export.Exported; import org.kohsuke.stapler.export.ExportedBean; @@ -84,8 +85,13 @@ import org.kohsuke.stapler.export.ExportedBean; */ @ExportedBean public abstract class SCM implements Describable, ExtensionPoint { + + /** JENKINS-35098: discouraged */ + @SuppressWarnings("FieldMayBeFinal") + private static boolean useAutoBrowserHolder = SystemProperties.getBoolean(SCM.class.getName() + ".useAutoBrowserHolder"); /** * Stores {@link AutoBrowserHolder}. Lazily created. + * @deprecated Unused by default. */ private transient AutoBrowserHolder autoBrowserHolder; @@ -124,17 +130,21 @@ public abstract class SCM implements Describable, ExtensionPoint { * Returns the applicable {@link RepositoryBrowser} for files * controlled by this {@link SCM}. * @see #guessBrowser - * @see SCMDescriptor#isBrowserReusable */ + @SuppressWarnings("deprecation") @Exported(name="browser") public final @CheckForNull RepositoryBrowser getEffectiveBrowser() { RepositoryBrowser b = getBrowser(); if(b!=null) return b; - if(autoBrowserHolder==null) - autoBrowserHolder = new AutoBrowserHolder(this); - return autoBrowserHolder.get(); - + if (useAutoBrowserHolder) { + if (autoBrowserHolder == null) { + autoBrowserHolder = new AutoBrowserHolder(this); + } + return autoBrowserHolder.get(); + } else { + return guessBrowser(); + } } /** diff --git a/core/src/main/java/hudson/scm/SCMDescriptor.java b/core/src/main/java/hudson/scm/SCMDescriptor.java index 242ad88c6d..9929e95d3a 100644 --- a/core/src/main/java/hudson/scm/SCMDescriptor.java +++ b/core/src/main/java/hudson/scm/SCMDescriptor.java @@ -53,7 +53,9 @@ public abstract class SCMDescriptor extends Descriptor { * This is used to invalidate cache of {@link SCM#getEffectiveBrowser}. Due to the lack of synchronization and serialization, * this field doesn't really count the # of instances created to date, * but it's good enough for the cache invalidation. + * @deprecated No longer used by default. */ + @Deprecated public volatile int generation = 1; protected SCMDescriptor(Class clazz, Class repositoryBrowser) { @@ -102,7 +104,9 @@ public abstract class SCMDescriptor extends Descriptor { * @return * true if the two given SCM configurations are similar enough * that they can reuse {@link RepositoryBrowser} between them. + * @deprecated No longer used by default. {@link SCM#getKey} could be used to implement similar features if needed. */ + @Deprecated public boolean isBrowserReusable(T x, T y) { return false; } diff --git a/core/src/main/java/hudson/scm/SCMS.java b/core/src/main/java/hudson/scm/SCMS.java index e79af364de..4f7f71e4b1 100644 --- a/core/src/main/java/hudson/scm/SCMS.java +++ b/core/src/main/java/hudson/scm/SCMS.java @@ -54,14 +54,11 @@ public class SCMS { * @param target * The project for which this SCM is configured to. */ + @SuppressWarnings("deprecation") public static SCM parseSCM(StaplerRequest req, AbstractProject target) throws FormException, ServletException { - String scm = req.getParameter("scm"); - if(scm==null) return new NullSCM(); - - int scmidx = Integer.parseInt(scm); - SCMDescriptor d = SCM._for(target).get(scmidx); - d.generation++; - return d.newInstance(req, req.getSubmittedForm().getJSONObject("scm")); + SCM scm = req.bindJSON(SCM.class, req.getSubmittedForm().getJSONObject("scm")); + scm.getDescriptor().generation++; + return scm; } /** diff --git a/core/src/main/resources/lib/hudson/project/config-scm.jelly b/core/src/main/resources/lib/hudson/project/config-scm.jelly index 6874bb2dfb..0d3eb3bf1f 100644 --- a/core/src/main/resources/lib/hudson/project/config-scm.jelly +++ b/core/src/main/resources/lib/hudson/project/config-scm.jelly @@ -26,14 +26,14 @@ THE SOFTWARE. - - - + + - - + + - + + -- GitLab