4747import java .util .List ;
4848import java .util .Map ;
4949import java .util .Set ;
50- import java .util .UUID ;
5150import java .util .logging .Level ;
5251import java .util .logging .Logger ;
5352import jenkins .model .TransientActionFactory ;
@@ -136,7 +135,7 @@ public boolean equals(Object obj) {
136135 */
137136 @ Deprecated
138137 protected SCMSource (@ CheckForNull String id ) {
139- this .id = id == null ? UUID . randomUUID (). toString () : id ;
138+ this .id = id == null ? "" : id ;
140139 }
141140
142141 /**
@@ -148,18 +147,16 @@ protected SCMSource() {
148147 /**
149148 * Sets the ID that is used to ensure this {@link SCMSource} can be retrieved from its {@link SCMSourceOwner}
150149 * provided that this {@link SCMSource} does not already {@link #hasId()}.
151- * <p>
152- * Note this is a <strong>one-shot</strong> setter. If {@link #getId()} is called first, then its value will stick,
153- * otherwise the first call to {@link #setId(String)} will stick.
154- *
150+ * This should be called from the {@link SCMSourceOwner} when saving the list of {@link SCMSource}s,
151+ * though for compatibility reasons it may also be called directly.
155152 * @param id the ID, this is an opaque token expected to be unique within any one {@link SCMSourceOwner}.
156153 * @see #hasId()
157154 * @see #getId()
158155 * @since 2.2.0
159156 */
160157 @ DataBoundSetter
161158 public final synchronized void setId (@ CheckForNull String id ) {
162- if (this .id == null ) {
159+ if (this .id == null || this . id . isEmpty () ) {
163160 this .id = id ;
164161 } else if (!this .id .equals (id )) {
165162 throw new IllegalStateException ("The ID cannot be changed after it has been set." );
@@ -186,20 +183,19 @@ public final SCMSource withId(@CheckForNull String id) {
186183 * @since 2.2.0
187184 */
188185 public final synchronized boolean hasId () {
189- return this .id != null ;
186+ return this .id != null && ! this . id . isEmpty () ;
190187 }
191188 /**
192- * The ID of this source. The ID is not related to anything at all. If this {@link SCMSource} does not have an ID
193- * then one will be generated.
189+ * The ID of this source.
194190 *
195- * @return the ID of this source.
191+ * @return the ID of this source; the empty string until assigned
196192 * @see #setId(String)
197193 * @see #hasId()
198194 */
199195 @ NonNull
200196 public final synchronized String getId () {
201197 if (id == null ) {
202- id = UUID . randomUUID (). toString () ;
198+ id = "" ;
203199 }
204200 return id ;
205201 }
0 commit comments