Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ protected AbstractItem(ItemGroup parent, String name) {
doSetName(name);
}

@NonNull
@Override
@Exported(visibility = 999)
public String getName() {
Expand Down Expand Up @@ -470,6 +471,7 @@ public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractIte
@Override
public abstract Collection<? extends Job> getAllJobs();

@NonNull
@Override
@Exported
public final String getFullName() {
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/hudson/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
import hudson.util.Secret;
import java.io.IOException;
import java.util.Collection;
import jenkins.model.FullyNamed;
import jenkins.model.FullyNamedModelObject;
import jenkins.model.Jenkins;
import jenkins.model.Named;
import jenkins.search.SearchGroup;
import jenkins.util.SystemProperties;
import jenkins.util.io.OnMaster;
Expand Down Expand Up @@ -73,7 +76,7 @@
* @see Items
* @see ItemVisitor
*/
public interface Item extends PersistenceRoot, SearchableModelObject, AccessControlled, OnMaster {
public interface Item extends PersistenceRoot, FullyNamedModelObject, SearchableModelObject, FullyNamed, Named, AccessControlled, OnMaster {
/**
* Gets the parent that contains this item.
*/
Expand All @@ -97,6 +100,8 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont
*
* @see #getFullName()
*/
@NonNull
@Override
String getName();

/**
Expand All @@ -110,6 +115,8 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont
*
* @see jenkins.model.Jenkins#getItemByFullName(String,Class)
*/
@NonNull
@Override
String getFullName();

/**
Expand All @@ -127,13 +134,6 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont
@Override
String getDisplayName();

/**
* Works like {@link #getDisplayName()} but return
* the full path that includes all the display names
* of the ancestors.
*/
String getFullDisplayName();

/**
* Gets the relative name to this item from the specified group.
*
Expand Down
16 changes: 3 additions & 13 deletions core/src/main/java/hudson/model/ItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jenkins.model.FullyNamed;
import jenkins.model.FullyNamedModelObject;
import org.springframework.security.access.AccessDeniedException;

/**
Expand All @@ -41,19 +43,7 @@
* @author Kohsuke Kawaguchi
* @see ItemGroupMixIn
*/
public interface ItemGroup<T extends Item> extends PersistenceRoot, ModelObject {
/**
* Gets the full name of this {@link ItemGroup}.
*
* @see Item#getFullName()
*/
String getFullName();

/**
* @see Item#getFullDisplayName()
*/
String getFullDisplayName();

public interface ItemGroup<T extends Item> extends FullyNamed, FullyNamedModelObject, PersistenceRoot {
/**
* Gets all the items in this collection in a read-only view.
*/
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/java/hudson/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import jenkins.console.WithConsoleUrl;
import jenkins.model.FullyNamed;
import jenkins.model.FullyNamedModelObject;
import jenkins.model.Jenkins;
import jenkins.model.queue.AsynchronousExecution;
import jenkins.model.queue.CompositeCauseOfBlockage;
Expand Down Expand Up @@ -1882,7 +1884,7 @@ public interface NonBlockingTask extends Task {}
* design, a {@link Task} must have at least one sub-task.)
* Most of the time, the primary subtask is the only sub task.
*/
public interface Task extends ModelObject, SubTask {
public interface Task extends FullyNamedModelObject, SubTask {
/**
* Returns true if the execution should be blocked
* for temporary reasons.
Expand Down Expand Up @@ -1928,21 +1930,22 @@ default CauseOfBlockage getCauseOfBlockage() {
*/
String getName();

/**
* @see hudson.model.Item#getFullDisplayName()
*/
String getFullDisplayName();

/**
* Returns task-specific key which is used by the {@link LoadBalancer} to choose one particular executor
* amongst all the free executors on all possibly suitable nodes.
* NOTE: To be able to re-use the same node during the next run this key should not change from one run to
* another. You probably want to compute that key based on the job's name.
*
* @return by default: {@link #getFullDisplayName()}
* @return by default: {@link FullyNamed#getFullName()} if implements {@link FullyNamed} or {@link #getFullDisplayName()} otherwise.
* @see hudson.model.LoadBalancer
*/
default String getAffinityKey() { return getFullDisplayName(); }
default String getAffinityKey() {
if (this instanceof FullyNamed fullyNamed) {
return fullyNamed.getFullName();
} else {
return getFullDisplayName();
}
}

/**
* Checks the permission to see if the current user can abort this executable.
Expand Down
7 changes: 1 addition & 6 deletions core/src/main/java/hudson/model/ResourceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author Kohsuke Kawaguchi
*/
public interface ResourceActivity {
public interface ResourceActivity extends ModelObject {
/**
* Gets the list of {@link Resource}s that this task requires.
* Used to make sure no two conflicting tasks run concurrently.
Expand All @@ -47,9 +47,4 @@ public interface ResourceActivity {
default ResourceList getResourceList() {
return ResourceList.EMPTY;
}

/**
* Used for rendering HTML.
*/
String getDisplayName();
}
6 changes: 5 additions & 1 deletion core/src/main/java/hudson/model/queue/MappingWorksheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static java.lang.Math.max;

import com.google.common.collect.Iterables;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Label;
Expand All @@ -48,6 +49,7 @@
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import jenkins.model.Named;

/**
* Defines a mapping problem for answering "where do we execute this task?"
Expand Down Expand Up @@ -114,7 +116,7 @@ public int size() {
}
}

public final class ExecutorChunk extends ReadOnlyList<ExecutorSlot> {
public final class ExecutorChunk extends ReadOnlyList<ExecutorSlot> implements Named {
public final int index;
public final Computer computer;
public final Node node;
Expand Down Expand Up @@ -150,6 +152,8 @@ public boolean canAccept(WorkChunk c) {
/**
* Node name.
*/
@NonNull
@Override
public String getName() {
return node.getNodeName();
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/jenkins/model/FullyNamed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package jenkins.model;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* An interface for objects that have a name and a parent, so exposing a full name.
*/
public interface FullyNamed {
/**
* Returns the full name of this object, which is a qualified name
* that includes the names of all its ancestors, separated by '/'.
*
* @return the full name of this object.
*/
@NonNull
String getFullName();
}
23 changes: 23 additions & 0 deletions core/src/main/java/jenkins/model/FullyNamedModelObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package jenkins.model;

import hudson.model.ModelObject;
import jenkins.security.stapler.StaplerAccessibleType;

/**
* A model object that has a human-readable full name. This is usually valid when nested as part of an object hierarchy.
*
* <p>
* This interface is used to mark objects that can be qualified in the context of a Jenkins instance.
* It is typically used for objects that are part of the Jenkins model and can be referenced by their names.
*
* @see ModelObject
*/
@StaplerAccessibleType
public interface FullyNamedModelObject extends ModelObject {
/**
* Works like {@link #getDisplayName()} but return
* the full path that includes all the display names
* of the ancestors in an unspecified format.
*/
String getFullDisplayName();
}
9 changes: 1 addition & 8 deletions core/src/main/java/jenkins/model/HistoricalBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import hudson.markup.MarkupFormatter;
import hudson.model.BallColor;
import hudson.model.BuildBadgeAction;
import hudson.model.ModelObject;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Queue;
Expand All @@ -48,7 +47,7 @@
* @since 2.477
*/
@Restricted(Beta.class)
public interface HistoricalBuild extends ModelObject {
public interface HistoricalBuild extends FullyNamedModelObject {

/**
* @return A build number
Expand All @@ -74,12 +73,6 @@ public interface HistoricalBuild extends ModelObject {
@CheckForNull
String getDescription();

/**
* @return a human-readable full display name of this build.
*/
@NonNull
String getFullDisplayName();

/**
* Get the {@link Queue.Item#getId()} of the original queue item from where this {@link HistoricalBuild} instance
* originated.
Expand Down
16 changes: 2 additions & 14 deletions core/src/main/java/jenkins/model/IComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.ModelObject;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import java.util.List;
Expand All @@ -45,13 +45,7 @@
* @since 2.480
*/
@Restricted(Beta.class)
public interface IComputer extends AccessControlled, IconSpec {
/**
* Returns {@link Node#getNodeName() the name of the node}.
*/
@NonNull
String getName();

public interface IComputer extends AccessControlled, IconSpec, ModelObject, Named {
/**
* Used to render the list of executors.
* @return a snapshot of the executor display information
Expand All @@ -64,12 +58,6 @@ public interface IComputer extends AccessControlled, IconSpec {
*/
boolean isOffline();

/**
* @return the node name for UI purposes.
*/
@NonNull
String getDisplayName();

/**
* Returns {@code true} if the computer is accepting tasks. Needed to allow agents programmatic suspension of task
* scheduling that does not overlap with being offline.
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/jenkins/model/IDisplayExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package jenkins.model;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.ModelObject;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;

Expand All @@ -34,13 +35,7 @@
* @since 2.480
*/
@Restricted(Beta.class)
public interface IDisplayExecutor {
/**
* @return The UI label for this executor.
*/
@NonNull
String getDisplayName();

public interface IDisplayExecutor extends ModelObject {
/**
* @return the URL where to reach specifically this executor, relative to Jenkins URL.
*/
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,7 @@ public Launcher createLauncher(TaskListener listener) {
}


@NonNull
@Override
public String getFullName() {
return "";
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/jenkins/model/Named.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package jenkins.model;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* An object that has a name.
* <p>
* This interface is used to provide a consistent way to retrieve the name of an object in Jenkins.
* It is typically implemented by objects that need to be identified by a name, such as tasks, nodes, or other model objects.
*/
public interface Named {
/**
* Returns the name of this object.
*
* @return the name of this object, never null.
*/
@NonNull
String getName();
}
4 changes: 2 additions & 2 deletions core/src/main/java/jenkins/model/queue/ITask.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.model.Item;
import hudson.model.ModelObject;
import hudson.security.AccessControlled;
import jenkins.model.FullyNamedModelObject;

/**
* A task that can be displayed in the executors widget.
*
* @since 2.480
*/
public interface ITask extends ModelObject {
public interface ITask extends FullyNamedModelObject {
/**
* @return {@code true} if the current user can cancel the current task.
*
Expand Down
Loading
Loading