New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIXED JENKINS-28843] Stored the unique value in the job configuration #1
Changes from 12 commits
2706618
18da636
19e7474
b5b5f08
7762111
1de8efd
1991180
76f95d1
944138b
07f5de0
cbee5b5
c38cbb0
4258879
9cb4df5
f4700e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/target/ | ||
/work/ | ||
/.classpath | ||
/.project | ||
/.settings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
package org.jenkinsci.plugins.uniqueid; | ||
|
||
import hudson.ExtensionPoint; | ||
|
||
import jenkins.model.Jenkins; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.UUID; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.apache.commons.codec.binary.Base64; | ||
|
||
/** | ||
* An abstraction to persistently store and retrieve unique id's | ||
* for various Jenkins model objects. | ||
* | ||
* These keys are guaranteed to be unique with a Jenkins | ||
* and immutable across the lifetime of the given object. | ||
* | ||
* Implementations should not store the ID inside any specific item configuration as it is | ||
* common for users top copy items either through the UI or manually and this will cause the | ||
* IDs to become non-unique. | ||
* | ||
* | ||
* @param <T> | ||
*/ | ||
|
@@ -26,14 +38,14 @@ public IdStore (Class<T> forType) { | |
* Creates an unique id for the given object. | ||
* Subsequent calls are idempotent. | ||
* | ||
* @param object | ||
* @param object the object to make the id for. | ||
*/ | ||
public abstract void make(T object); | ||
|
||
/** | ||
* Get the id for this given object. | ||
* @param object | ||
* @return the id or null if none assigned. | ||
* @return the id or {@code null} if none assigned. | ||
*/ | ||
@Nullable | ||
public abstract String get(T object); | ||
|
@@ -63,7 +75,7 @@ public static <C> IdStore<C> forClass(Class<C> clazz) { | |
* | ||
* @throws java.lang.IllegalArgumentException if the type is not supported. | ||
*/ | ||
public static void makeId(Object object) { | ||
public static void makeId(Object object) throws IllegalArgumentException { | ||
IdStore store = forClass(object.getClass()); | ||
if (store == null) { | ||
throw new IllegalArgumentException("Unsupported type: " + object.getClass().getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems more like an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the previous API was IllegalArgumeException - so I do not want to change all callers. |
||
|
@@ -77,7 +89,7 @@ public static void makeId(Object object) { | |
* | ||
* @throws java.lang.IllegalArgumentException if the type is not supported. | ||
*/ | ||
public static String getId(Object object) { | ||
public static String getId(Object object) throws IllegalArgumentException { | ||
IdStore store = forClass(object.getClass()); | ||
if (store == null) { | ||
throw new IllegalArgumentException("Unsupported type: " + object.getClass().getName()); | ||
|
@@ -86,4 +98,13 @@ public static String getId(Object object) { | |
} | ||
} | ||
|
||
/** | ||
* Generates a new unique ID. | ||
* Subclasses do not need to use this to create unique IDs and are free to create IDs by other methods. | ||
* @return a string that should be unique against all jenkins instances. | ||
*/ | ||
protected static String generateUniqueID() { | ||
return Base64.encodeBase64String(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)).substring(0, 30); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May also want to change the Animal Sniffer execution.
Apparently even the current plugin POM does not define
java.level
like Jenkins core itself does. Something to be fixed in a future version of the POM.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's currently working. I'll leave that to someone for a future excesize (along with using a recent core)