/** * Finds the name of the matrix project that this action probably belongs to. * @return the name of the project or null if runs are bad. */ public synchronized String findUpStreamName() { if (runs != null) { for (MatrixRun run : runs) { Cause.UpstreamCause cause = run.getCause(Cause.UpstreamCause.class); if (cause != null) { return cause.getUpstreamProject(); } } } return null; }
/** * Helper method for {@link #readResolve()}, will try to find the upstream {@link MatrixBuild}. Since the run is * de-serialized badly (not referenced in the correct hierarchy) this could be a bit tricky. * * @param run the MatrixRun to search. * @return the correct instance if possible. */ private MatrixBuild findUpStream(MatrixRun run) { Cause.UpstreamCause cause = run.getCause(Cause.UpstreamCause.class); if (cause != null) { String project = cause.getUpstreamProject(); //Yes the folders plugin could cause problems here, // but stapler can't help me if I use the URL which would be preferred. //TODO what to do when the job is renamed? TopLevelItem item; item = Jenkins.getInstance().getItem(project); logger.log(Level.FINE, "Project item for {0} is {1}", new Object[]{project, item}); if (item != null && item instanceof MatrixProject) { logger.log(Level.FINEST, "It is a matrix project; searching for build {0}", cause.getUpstreamBuild()); //Find the build return ((MatrixProject)item).getBuildByNumber(cause.getUpstreamBuild()); } } return null; } }
doReturn(Collections.emptyList().iterator()).when(listMock).iterator(); doReturn(listMock).when(ExtensionList.class, "lookup", same(TransientActionFactory.class)); Cause.UpstreamCause upCause = run.getCause(Cause.UpstreamCause.class); List upstreamCauses = Whitebox.getInternalState(upCause, "upstreamCauses"); GerritCause cause = (GerritCause)upstreamCauses.get(0);