-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Add default implementations of deprecated methods of BuilableItem and Item. #3142
Changes from 1 commit
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 |
---|---|---|
|
@@ -125,6 +125,7 @@ | |
import java.util.logging.SimpleFormatter; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
@@ -1143,11 +1144,14 @@ public static List<TopLevelItem> getAllTopLevelItems(ItemGroup root) { | |
* | ||
* @since 1.515 | ||
* @param p the Item we want the relative display name | ||
* @param g the ItemGroup used as point of reference for the item | ||
* @param g the ItemGroup used as point of reference for the item. | ||
* If the group is not specified, item's path will be used. | ||
* @param useDisplayName if true, returns a display name, otherwise returns a name | ||
* @return | ||
* String like "foo » bar" | ||
* String like "foo » bar". | ||
* {@code null} if item is null or if one of its parents is not an {@link ItemGroup}. | ||
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. Just documented it while I was around 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. Huh? A parent by definition is an |
||
*/ | ||
@Nullable | ||
public static String getRelativeNameFrom(Item p, ItemGroup g, boolean useDisplayName) { | ||
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. Really these methods should have been in |
||
if (p == null) return null; | ||
if (g == null) return useDisplayName ? p.getFullDisplayName() : p.getFullName(); | ||
|
@@ -1182,7 +1186,7 @@ public static String getRelativeNameFrom(Item p, ItemGroup g, boolean useDisplay | |
|
||
if (gr instanceof Item) | ||
i = (Item)gr; | ||
else | ||
else // Parent is a group, but not an item | ||
return null; | ||
} | ||
} | ||
|
@@ -1194,8 +1198,10 @@ public static String getRelativeNameFrom(Item p, ItemGroup g, boolean useDisplay | |
* @param p the Item we want the relative display name | ||
* @param g the ItemGroup used as point of reference for the item | ||
* @return | ||
* String like "foo/bar" | ||
* String like "foo/bar". | ||
* {@code null} if the item is {@code null} or if one of its parents is not an {@link ItemGroup}. | ||
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. ditto |
||
*/ | ||
@Nullable | ||
public static String getRelativeNameFrom(Item p, ItemGroup g) { | ||
return getRelativeNameFrom(p, g, false); | ||
} | ||
|
@@ -1208,8 +1214,10 @@ public static String getRelativeNameFrom(Item p, ItemGroup g) { | |
* @param p the Item we want the relative display name | ||
* @param g the ItemGroup used as point of reference for the item | ||
* @return | ||
* String like "Foo » Bar" | ||
* String like "Foo » Bar". | ||
* {@code null} if the item is {@code null} or if one of its parents is not an {@link ItemGroup}. | ||
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. ditto |
||
*/ | ||
@Nullable | ||
public static String getRelativeDisplayNameFrom(Item p, ItemGroup g) { | ||
return getRelativeNameFrom(p, g, true); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,19 @@ public interface BuildableItem extends Item, Task { | |
* Use {@link #scheduleBuild(Cause)}. Since 1.283 | ||
*/ | ||
@Deprecated | ||
boolean scheduleBuild(); | ||
default boolean scheduleBuild() { | ||
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. tabs vs spaces :( Should I use tabs or refactor the methods? |
||
return scheduleBuild(new Cause.LegacyCodeCause()); | ||
} | ||
|
||
boolean scheduleBuild(Cause c); | ||
/** | ||
* @deprecated | ||
* Use {@link #scheduleBuild(int, Cause)}. Since 1.283 | ||
*/ | ||
@Deprecated | ||
boolean scheduleBuild(int quietPeriod); | ||
default boolean scheduleBuild(int quietPeriod) { | ||
return scheduleBuild(quietPeriod, new Cause.LegacyCodeCause()); | ||
} | ||
|
||
boolean scheduleBuild(int quietPeriod, Cause c); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
package hudson.model; | ||
|
||
import hudson.Functions; | ||
import hudson.Util; | ||
import jenkins.model.Jenkins; | ||
import jenkins.util.SystemProperties; | ||
import hudson.security.PermissionScope; | ||
import jenkins.util.io.OnMaster; | ||
|
@@ -131,18 +133,28 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont | |
/** | ||
* Gets the relative name to this item from the specified group. | ||
* | ||
* @param g | ||
* The ItemGroup instance used as context to evaluate the relative name of this AbstractItem | ||
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. Not necessarily an |
||
* @return | ||
* The name of the current item, relative to p. Nested ItemGroups are separated by {@code /} character. | ||
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. use |
||
* @since 1.419 | ||
* @return | ||
* String like "../foo/bar" | ||
* String like "../foo/bar". | ||
* {@code null} if item parents is not an {@link ItemGroup}. | ||
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. probably s/ |
||
*/ | ||
String getRelativeNameFrom(ItemGroup g); | ||
default String getRelativeNameFrom(ItemGroup g) { | ||
return Functions.getRelativeNameFrom(this, g); | ||
} | ||
|
||
/** | ||
* Short for {@code getRelativeNameFrom(item.getParent())} | ||
* | ||
* @since 1.419 | ||
*/ | ||
String getRelativeNameFrom(Item item); | ||
default String getRelativeNameFrom(Item item) { | ||
return getRelativeNameFrom(item.getParent()); | ||
|
||
} | ||
|
||
/** | ||
* Returns the URL of this item relative to the context root of the application. | ||
|
@@ -180,7 +192,12 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont | |
* (even this won't work for the same reason, which should be fixed.) | ||
*/ | ||
@Deprecated | ||
String getAbsoluteUrl(); | ||
default String getAbsoluteUrl() { | ||
String r = Jenkins.getInstance().getRootUrl(); | ||
if(r==null) | ||
throw new IllegalStateException("Root URL isn't configured yet. Cannot compute absolute URL."); | ||
return Util.encode(r+getUrl()); | ||
} | ||
|
||
/** | ||
* Called right after when a {@link Item} is loaded from disk. | ||
|
@@ -207,7 +224,9 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont | |
* | ||
* @since 1.374 | ||
*/ | ||
default void onCreatedFromScratch() {} | ||
default void onCreatedFromScratch() { | ||
// do nothing by default | ||
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. Why would there not be default no-op impls of 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. I was thinking about that, but I decided not to touch it for now since I was unable to find noop implementations. |
||
} | ||
|
||
/** | ||
* Save the settings to a file. | ||
|
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.
mark it
@CheckForNull
please