Skip to content
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

Adding some interface default method implementations #2879

Merged
merged 8 commits into from
May 20, 2017
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: 1 addition & 1 deletion core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ public static String getRelativeLinkTo(Item p) {
ItemGroup ig = i.getParent();
url = i.getShortUrl()+url;

if(ig== Jenkins.getInstance() || (view != null && ig == view.getOwnerItemGroup())) {
if(ig== Jenkins.getInstance() || (view != null && ig == view.getOwner().getItemGroup())) {
assert i instanceof TopLevelItem;
if (view != null) {
// assume p and the current page belong to the same view, so return a relative path
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,11 +900,7 @@ protected boolean filter(Method e) {
if (d.shortName.equals(p.getShortName())) {
// this plugin depends on the newly loaded one!
// recalculate dependencies!
try {
getPluginStrategy().updateDependency(depender, p);
} catch (AbstractMethodError x) {
LOGGER.log(WARNING, "{0} does not yet implement updateDependency", getPluginStrategy().getClass());
}
getPluginStrategy().updateDependency(depender, p);
break;
}
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/hudson/PluginStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;

/**
Expand Down Expand Up @@ -92,5 +94,8 @@ PluginWrapper createPluginWrapper(File archive)
* @param dependee newly loaded plugin.
* @since 1.557
*/
void updateDependency(PluginWrapper depender, PluginWrapper dependee);
// TODO an @Abstract annotation with a matching processor could make it a compile-time error to neglect to override this, without breaking binary compatibility
default void updateDependency(PluginWrapper depender, PluginWrapper dependee) {
Logger.getLogger(PluginStrategy.class.getName()).log(Level.WARNING, "{0} does not yet implement updateDependency", getClass());
}
}
7 changes: 1 addition & 6 deletions core/src/main/java/hudson/model/AbstractBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,7 @@ private void reportError(BuildStep bs, Throwable e, BuildListener listener, bool
* Calls a build step.
*/
protected final boolean perform(BuildStep bs, BuildListener listener) throws InterruptedException, IOException {
BuildStepMonitor mon;
try {
mon = bs.getRequiredMonitorService();
} catch (AbstractMethodError e) {
mon = BuildStepMonitor.BUILD;
}
BuildStepMonitor mon = bs.getRequiredMonitorService();
Result oldResult = AbstractBuild.this.getResult();
for (BuildStepListener bsl : BuildStepListener.all()) {
bsl.started(AbstractBuild.this, bs, listener);
Expand Down
13 changes: 2 additions & 11 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@

import static hudson.model.queue.Executables.getParentOf;
import hudson.model.queue.SubTask;
import java.lang.reflect.InvocationTargetException;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import org.apache.commons.io.FileUtils;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -127,10 +126,6 @@ protected AbstractItem(ItemGroup parent, String name) {
doSetName(name);
}

public void onCreatedFromScratch() {
// noop
}

@Exported(visibility=999)
public String getName() {
return name;
Expand Down Expand Up @@ -326,11 +321,7 @@ protected void renameTo(final String newName) throws IOException {
doSetName(oldName);
}

try {
parent.onRenamed(this, oldName, newName);
} catch (AbstractMethodError _) {
// ignore
}
parent.onRenamed(this, oldName, newName);
}
}
ItemListener.fireLocationChange(this, oldFullName);
Expand Down Expand Up @@ -446,7 +437,7 @@ public final String getUrl() {
Ancestor last = ancestors.get(ancestors.size() - 1);
if (last.getObject() instanceof View) {
View view = (View) last.getObject();
if (view.getOwnerItemGroup() == getParent() && !view.isDefault()) {
if (view.getOwner().getItemGroup() == getParent() && !view.isDefault()) {
// Showing something inside a view, so should use that as the base URL.
String base = last.getUrl().substring(req.getContextPath().length() + 1) + '/';
LOGGER.log(Level.FINER, "using {0}{1} for {2} from {3}", new Object[] {base, shortUrl, this, uri});
Expand Down
18 changes: 0 additions & 18 deletions core/src/main/java/hudson/model/AbstractProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import hudson.scm.SCMRevisionState;
import hudson.scm.SCMS;
import hudson.search.SearchIndexBuilder;
import hudson.security.ACL;
import hudson.security.Permission;
import hudson.slaves.Cloud;
import hudson.slaves.WorkspaceList;
Expand Down Expand Up @@ -111,7 +110,6 @@
import jenkins.triggers.SCMTriggerItem;
import jenkins.util.TimeDuration;
import net.sf.json.JSONObject;
import org.acegisecurity.Authentication;
import org.jenkinsci.bytecode.AdaptField;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
Expand Down Expand Up @@ -1017,22 +1015,6 @@ public Object getSameNodeConstraint() {
return this; // in this way, any member that wants to run with the main guy can nominate the project itself
}

public final Task getOwnerTask() {
return this;
}

@Nonnull
public Authentication getDefaultAuthentication() {
// backward compatible behaviour.
return ACL.SYSTEM;
}

@Nonnull
@Override
public Authentication getDefaultAuthentication(Queue.Item item) {
return getDefaultAuthentication();
}

/**
* {@inheritDoc}
*
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/model/AllView.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public String getDisplayName() {
@Override
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp)
throws IOException, ServletException {
ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup();
ItemGroup<? extends TopLevelItem> ig = getOwner().getItemGroup();
if (ig instanceof ModifiableItemGroup)
return ((ModifiableItemGroup<? extends TopLevelItem>)ig).doCreateItem(req, rsp);
return null;
}

@Override
public Collection<TopLevelItem> getItems() {
return (Collection)getOwnerItemGroup().getItems();
return (Collection)getOwner().getItemGroup().getItems();
}

@Override
Expand Down
25 changes: 9 additions & 16 deletions core/src/main/java/hudson/model/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import hudson.Functions;
import hudson.Util;
import hudson.model.Queue.Executable;
import hudson.model.queue.Executables;
import hudson.model.queue.SubTask;
import hudson.model.queue.Tasks;
import hudson.model.queue.WorkUnit;
import hudson.security.ACL;
import hudson.util.InterceptingProxy;
Expand Down Expand Up @@ -680,7 +678,7 @@ public int getProgress() {
if (executable == null) {
return -1;
}
d = Executables.getEstimatedDurationFor(executable);
d = executable.getEstimatedDuration();
} finally {
lock.readLock().unlock();
}
Expand Down Expand Up @@ -713,7 +711,7 @@ public boolean isLikelyStuck() {
}

elapsed = getElapsedTime();
d = Executables.getEstimatedDurationFor(executable);
d = executable.getEstimatedDuration();
} finally {
lock.readLock().unlock();
}
Expand Down Expand Up @@ -771,7 +769,7 @@ public String getEstimatedRemainingTime() {
return Messages.Executor_NotAvailable();
}

d = Executables.getEstimatedDurationFor(executable);
d = executable.getEstimatedDuration();
} finally {
lock.readLock().unlock();
}
Expand Down Expand Up @@ -799,7 +797,7 @@ public long getEstimatedRemainingTimeMillis() {
return -1;
}

d = Executables.getEstimatedDurationFor(executable);
d = executable.getEstimatedDuration();
} finally {
lock.readLock().unlock();
}
Expand Down Expand Up @@ -857,7 +855,7 @@ public HttpResponse doStop() {
lock.writeLock().lock(); // need write lock as interrupt will change the field
try {
if (executable != null) {
Tasks.getOwnerTaskOf(getParentOf(executable)).checkAbortPermission();
getParentOf(executable).getOwnerTask().checkAbortPermission();
interrupt();
}
} finally {
Expand All @@ -880,7 +878,7 @@ public HttpResponse doYank() {
public boolean hasStopPermission() {
lock.readLock().lock();
try {
return executable != null && Tasks.getOwnerTaskOf(getParentOf(executable)).hasAbortPermission();
return executable != null && getParentOf(executable).getOwnerTask().hasAbortPermission();
} finally {
lock.readLock().unlock();
}
Expand All @@ -899,7 +897,7 @@ public long getIdleStartMilliseconds() {
if (isIdle())
return Math.max(creationTime, owner.getConnectTime());
else {
return Math.max(startTime + Math.max(0, Executables.getEstimatedDurationFor(executable)),
return Math.max(startTime + Math.max(0, executable == null ? -1 : executable.getEstimatedDuration()),
System.currentTimeMillis() + 15000);
}
} finally {
Expand Down Expand Up @@ -965,16 +963,11 @@ public static Executor of(Executable executable) {
}

/**
* Returns the estimated duration for the executable.
* Protects against {@link AbstractMethodError}s if the {@link Executable} implementation
* was compiled against Hudson prior to 1.383
*
* @deprecated as of 1.388
* Use {@link Executables#getEstimatedDurationFor(Queue.Executable)}
* @deprecated call {@link Executable#getEstimatedDuration} directly
*/
@Deprecated
public static long getEstimatedDurationFor(Executable e) {
return Executables.getEstimatedDurationFor(e);
return e == null ? -1 : e.getEstimatedDuration();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont
*
* @since 1.374
*/
void onCreatedFromScratch();
default void onCreatedFromScratch() {}

/**
* Save the settings to a file.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/ItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public interface ItemGroup<T extends Item> extends PersistenceRoot, ModelObject
* Internal method. Called by {@link Item}s when they are renamed by users.
* This is <em>not</em> expected to call {@link ItemListener#onRenamed}, inconsistent with {@link #onDeleted}.
*/
void onRenamed(T item, String oldName, String newName) throws IOException;
default void onRenamed(T item, String oldName, String newName) throws IOException {}

/**
* Internal method. Called by {@link Item}s when they are deleted by users.
Expand Down
12 changes: 1 addition & 11 deletions core/src/main/java/hudson/model/ItemGroupMixIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,7 @@ public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, Str
Items.verifyItemDoesNotAlreadyExist(parent, name, null);

TopLevelItem item = type.newInstance(parent, name);
try {
callOnCreatedFromScratch(item);
} catch (AbstractMethodError e) {
// ignore this error. Must be older plugin that doesn't have this method
}
item.onCreatedFromScratch();
item.save();
add(item);
Jenkins.getInstance().rebuildDependencyGraphAsync();
Expand All @@ -332,10 +328,4 @@ public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, Str
return item;
}

/**
* Pointless wrapper to avoid HotSpot problem. See JENKINS-5756
*/
private void callOnCreatedFromScratch(TopLevelItem item) {
item.onCreatedFromScratch();
}
}
24 changes: 12 additions & 12 deletions core/src/main/java/hudson/model/ListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public List<TopLevelItem> getItems() {
names = new TreeSet<String>(jobNames);
}

ItemGroup<? extends TopLevelItem> parent = getOwnerItemGroup();
ItemGroup<? extends TopLevelItem> parent = getOwner().getItemGroup();
List<TopLevelItem> parentItems = new ArrayList<TopLevelItem>(parent.getItems());
includeItems(parent, parentItems, names);

Expand All @@ -196,7 +196,7 @@ public List<TopLevelItem> getItems() {
candidates = parent.getItems();
}
for (TopLevelItem item : candidates) {
if (!names.contains(item.getRelativeNameFrom(getOwnerItemGroup()))) continue;
if (!names.contains(item.getRelativeNameFrom(getOwner().getItemGroup()))) continue;
// Add if no status filter or filter matches enabled/disabled status:
if(statusFilter == null || !(item instanceof ParameterizedJobMixIn.ParameterizedJob) // TODO or better to call the more generic Job.isBuildable?
|| ((ParameterizedJobMixIn.ParameterizedJob)item).isDisabled() ^ statusFilter)
Expand Down Expand Up @@ -251,7 +251,7 @@ private void includeItems(ItemGroup<? extends TopLevelItem> root, Collection<? e

public synchronized boolean jobNamesContains(TopLevelItem item) {
if (item == null) return false;
return jobNames.contains(item.getRelativeNameFrom(getOwnerItemGroup()));
return jobNames.contains(item.getRelativeNameFrom(getOwner().getItemGroup()));
}

/**
Expand All @@ -262,7 +262,7 @@ public synchronized boolean jobNamesContains(TopLevelItem item) {
@Override
public void add(TopLevelItem item) throws IOException {
synchronized (this) {
jobNames.add(item.getRelativeNameFrom(getOwnerItemGroup()));
jobNames.add(item.getRelativeNameFrom(getOwner().getItemGroup()));
}
save();
}
Expand All @@ -275,7 +275,7 @@ public void add(TopLevelItem item) throws IOException {
@Override
public boolean remove(TopLevelItem item) throws IOException {
synchronized (this) {
String name = item.getRelativeNameFrom(getOwnerItemGroup());
String name = item.getRelativeNameFrom(getOwner().getItemGroup());
if (!jobNames.remove(name)) return false;
}
save();
Expand Down Expand Up @@ -335,13 +335,13 @@ private boolean needToAddToCurrentView(StaplerRequest req) throws ServletExcepti
@Override
@RequirePOST
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup();
ItemGroup<? extends TopLevelItem> ig = getOwner().getItemGroup();
if (ig instanceof ModifiableItemGroup) {
TopLevelItem item = ((ModifiableItemGroup<? extends TopLevelItem>)ig).doCreateItem(req, rsp);
if (item!=null) {
if (needToAddToCurrentView(req)) {
synchronized (this) {
jobNames.add(item.getRelativeNameFrom(getOwnerItemGroup()));
jobNames.add(item.getRelativeNameFrom(getOwner().getItemGroup()));
}
owner.save();
}
Expand Down Expand Up @@ -385,9 +385,9 @@ public HttpResponse doRemoveJobFromView(@QueryParameter String name) throws IOEx
}

private TopLevelItem resolveName(String name) {
TopLevelItem item = getOwnerItemGroup().getItem(name);
TopLevelItem item = getOwner().getItemGroup().getItem(name);
if (item == null) {
name = Items.getCanonicalName(getOwnerItemGroup(), name);
name = Items.getCanonicalName(getOwner().getItemGroup(), name);
item = Jenkins.getInstance().getItemByFullName(name, TopLevelItem.class);
}
return item;
Expand All @@ -406,12 +406,12 @@ protected void submit(StaplerRequest req) throws ServletException, FormException
jobNames.clear();
Iterable<? extends TopLevelItem> items;
if (recurse) {
items = Items.getAllItems(getOwnerItemGroup(), TopLevelItem.class);
items = Items.getAllItems(getOwner().getItemGroup(), TopLevelItem.class);
} else {
items = getOwnerItemGroup().getItems();
items = getOwner().getItemGroup().getItems();
}
for (TopLevelItem item : items) {
String relativeNameFrom = item.getRelativeNameFrom(getOwnerItemGroup());
String relativeNameFrom = item.getRelativeNameFrom(getOwner().getItemGroup());
if(req.getParameter(relativeNameFrom)!=null) {
jobNames.add(relativeNameFrom);
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/hudson/model/LoadStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import hudson.model.MultiStageTimeSeries.TimeScale;
import hudson.model.MultiStageTimeSeries.TrendChart;
import hudson.model.queue.SubTask;
import hudson.model.queue.Tasks;
import hudson.util.ColorPalette;
import hudson.util.NoOverlapCategoryAxis;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -406,9 +405,11 @@ protected void doRun() {
private int count(List<Queue.BuildableItem> bis, Label l) {
int q=0;
for (Queue.BuildableItem bi : bis) {
for (SubTask st : Tasks.getSubTasksOf(bi.task))
if (bi.getAssignedLabelFor(st)==l)
for (SubTask st : bi.task.getSubTasks()) {
if (bi.getAssignedLabelFor(st) == l) {
q++;
}
}
}
return q;
}
Expand Down
Loading