2323 */
2424package hudson .scm ;
2525
26+ import hudson .RestrictedSince ;
2627import hudson .Util ;
2728import hudson .model .AbstractProject ;
2829import hudson .model .Descriptor ;
2930import hudson .model .Job ;
31+ import org .kohsuke .accmod .Restricted ;
32+ import org .kohsuke .accmod .restrictions .NoExternalUse ;
33+
3034import java .lang .reflect .Field ;
3135import java .util .Collections ;
3236import java .util .List ;
3337import static java .util .logging .Level .WARNING ;
38+
39+ import java .util .concurrent .atomic .AtomicInteger ;
3440import java .util .logging .Logger ;
3541
3642/**
@@ -48,15 +54,7 @@ public abstract class SCMDescriptor<T extends SCM> extends Descriptor<SCM> {
4854 */
4955 public transient final Class <? extends RepositoryBrowser > repositoryBrowser ;
5056
51- /**
52- * Incremented every time a new {@link SCM} instance is created from this descriptor.
53- * This is used to invalidate cache of {@link SCM#getEffectiveBrowser}. Due to the lack of synchronization and serialization,
54- * this field doesn't really count the # of instances created to date,
55- * but it's good enough for the cache invalidation.
56- * @deprecated No longer used by default.
57- */
58- @ Deprecated
59- public volatile int generation = 1 ;
57+ private final AtomicInteger generation = new AtomicInteger (1 );
6058
6159 protected SCMDescriptor (Class <T > clazz , Class <? extends RepositoryBrowser > repositoryBrowser ) {
6260 super (clazz );
@@ -74,6 +72,29 @@ protected SCMDescriptor(Class<? extends RepositoryBrowser> repositoryBrowser) {
7472 this .repositoryBrowser = repositoryBrowser ;
7573 }
7674
75+ /**
76+ * Incremented every time a new {@link SCM} instance is created from this descriptor.
77+ * This is used to invalidate cache of {@link SCM#getEffectiveBrowser}. Due to the lack of synchronization and serialization,
78+ * this field doesn't really count the # of instances created to date,
79+ * but it's good enough for the cache invalidation.
80+ * @deprecated No longer used by default.
81+ */
82+ @ Deprecated
83+ @ Restricted (NoExternalUse .class ) @ RestrictedSince ("TODO" )
84+ public int getGeneration () {
85+ return generation .get ();
86+ }
87+
88+ /**
89+ * Increments the generation value {@link SCMDescriptor#getGeneration} by one atomically.
90+ * @deprecated No longer used by default.
91+ */
92+ @ Deprecated
93+ @ Restricted (NoExternalUse .class ) @ RestrictedSince ("TODO" )
94+ public void incrementGeneration () {
95+ generation .incrementAndGet ();
96+ }
97+
7798 // work around HUDSON-4514. The repositoryBrowser field was marked as non-transient until 1.325,
7899 // causing the field to be persisted and overwritten on the load method.
79100 @ SuppressWarnings ({"ConstantConditions" })
0 commit comments