-
-
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 all commits
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 |
---|---|---|
|
@@ -25,9 +25,12 @@ | |
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; | ||
import jline.internal.Nullable; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import java.io.IOException; | ||
|
@@ -39,6 +42,9 @@ | |
import hudson.security.AccessControlled; | ||
import hudson.util.Secret; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Basic configuration unit in Hudson. | ||
* | ||
|
@@ -131,18 +137,32 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont | |
/** | ||
* Gets the relative name to this item from the specified group. | ||
* | ||
* @param g | ||
* The {@link ItemGroup} instance used as context to evaluate the relative name of this item | ||
* @return | ||
* The name of the current item, relative to p. Nested {@link ItemGroup}s are separated by {@code /} character. | ||
* @since 1.419 | ||
* @return | ||
* String like "../foo/bar" | ||
* String like "../foo/bar". | ||
* {@code null} if one of item parents is not an {@link Item}. | ||
*/ | ||
String getRelativeNameFrom(ItemGroup g); | ||
@Nullable | ||
default String getRelativeNameFrom(@CheckForNull ItemGroup g) { | ||
return Functions.getRelativeNameFrom(this, g); | ||
} | ||
|
||
/** | ||
* Short for {@code getRelativeNameFrom(item.getParent())} | ||
* | ||
* @return String like "../foo/bar". | ||
* {@code null} if one of item parents is not an {@link Item}. | ||
* @since 1.419 | ||
*/ | ||
String getRelativeNameFrom(Item item); | ||
@Nullable | ||
default String getRelativeNameFrom(@Nonnull Item item) { | ||
return getRelativeNameFrom(item.getParent()); | ||
|
||
} | ||
|
||
/** | ||
* Returns the URL of this item relative to the context root of the application. | ||
|
@@ -180,7 +200,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 +232,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.
tabs vs spaces :( Should I use tabs or refactor the methods?