hudson.model.Cause Java Examples
The following examples show how to use
hudson.model.Cause.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BuildListener.java From audit-log-plugin with MIT License | 6 votes |
/** * Fired when a build is started, event logged via Log4j-audit. * * @param run of type Run having the build information * @param listener of type TaskListener that the onStarted method expects */ @Override public void onStarted(Run run, TaskListener listener) { BuildStart buildStart = LogEventFactory.getEvent(BuildStart.class); List causeObjects = run.getCauses(); List<String> causes = new ArrayList<>(causeObjects.size()); for (Object cause: causeObjects) { Cause c = (Cause)cause; causes.add(c.getShortDescription()); } buildStart.setBuildNumber(run.getNumber()); buildStart.setCause(causes); buildStart.setProjectName(run.getParent().getFullName()); buildStart.setTimestamp(formatDateISO(run.getStartTimeInMillis())); User user = User.current(); if(user != null) buildStart.setUserId(user.getId()); else buildStart.setUserId(null); buildStart.logEvent(); }
Example #2
Source File: CauseActionConverterTest.java From DotCi with MIT License | 6 votes |
@Test public void should_get_cause_from_dbObject() throws Exception { BasicDBObject cause1DbObject = new BasicDBObject("cause1", "cause1"); DBObject causes = new BasicDBObjectBuilder().add("causes", Arrays.asList(cause1DbObject)).get(); Mapper mapper = Mockito.mock(Mapper.class); Cause cause1 = new NullBuildCause(); when(mapper.fromDBObject(null, cause1DbObject, null)).thenReturn(cause1); CauseActionConverter converter = new CauseActionConverter(); converter.setMapper(mapper); CauseAction action = converter.decode(CauseAction.class, causes, Mockito.mock(MappedField.class)); Assert.assertEquals(1, action.getCauses().size()); Assert.assertEquals(cause1, action.getCauses().get(0)); }
Example #3
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private void notifyTestResults(String jobName, @Nullable TestResults testResults, Run<?, ?> run) { if (testResults != null) { String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatTests(jobName, repoOwner, repoName, branchName, testResults.getPassedTestCaseCount(), testResults.getSkippedTestCaseCount(), testResults.getFailedTestCaseCount(), buildUrl, buildNumber, buildCause); postData(data); for (TestSuite testSuite : testResults.getTestSuites()) { notifyTestSuite(jobName, testSuite, run); } } }
Example #4
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private String notifyTestCase(String jobName, String suiteName, TestCase testCase, Run<?, ?> run) { String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatTestCase(jobName, repoOwner, repoName, branchName, suiteName, testCase.getName(), testCase.getPassedCount(), testCase.getSkippedCount(), testCase.getFailedCount(), buildUrl, buildNumber, buildCause); return data; }
Example #5
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private void notifyCoverage(String jobName, @Nullable CodeCoverage coverageInfo, Run<?, ?> run) { if (coverageInfo != null) { String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatCoverage(jobName, repoOwner, repoName, branchName, coverageInfo.getClasses(), coverageInfo.getConditionals(), coverageInfo.getFiles(), coverageInfo.getLines(), coverageInfo.getMethods(), coverageInfo.getPackages(), coverageInfo.getInstructions(), buildUrl, buildNumber, buildCause); postData(data); } }
Example #6
Source File: InfluxDbNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
/** * Sends a state change to InfluxDB. * * @param jobName the name of the job * @param stageItem stage item describing the new state */ @Override public void notifyBuildStageStatus(String jobName, BuildStage stageItem) { if (stageItem.getBuildState() == BuildStage.State.Pending) { return; } String buildUrl = stageItem.getRun().getUrl(); int buildNumber = stageItem.getRun().getNumber(); Cause cause = stageItem.getRun().getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); String data = config.getSchema().formatStage(jobName, repoOwner, repoName, branchName, stageItem.getStageName(), stageItem.getBuildState().toString(), stageItem.getDuration(), stageItem.isPassed() ? 1 : 0, buildUrl, buildNumber, buildCause); postData(data); }
Example #7
Source File: HttpNotifier.java From github-autostatus-plugin with MIT License | 6 votes |
private BuildStatus constructBuildStatus(BuildStage.State buildState, Map<String, Object> parameters) { Run<?, ?> run = (Run<?, ?>) parameters.get(BuildNotifierConstants.BUILD_OBJECT); String jobName = (String) parameters.getOrDefault(BuildNotifierConstants.JOB_NAME, BuildNotifierConstants.DEFAULT_STRING); long blockedDuration = BuildNotifierConstants.getLong(parameters, BuildNotifierConstants.BLOCKED_DURATION); String buildUrl = run.getUrl(); int buildNumber = run.getNumber(); long buildDuration = BuildNotifierConstants.getLong(parameters, BuildNotifierConstants.JOB_DURATION) - blockedDuration; Cause cause = run.getCause(Cause.class); String buildCause = cause == null ? BuildNotifierConstants.DEFAULT_STRING : cause.getShortDescription(); BuildStatus result = new org.jenkinsci.plugins.githubautostatus.model.BuildStatus(); result.setRepoOwner(repoOwner); result.setRepoName(repoName); result.setJobName(jobName); result.setBranch(branchName); result.setBuildUrl(buildUrl); result.setBuildNumber(buildNumber); result.setTrigger(buildCause); result.setBlocked(blockedDuration > 0); result.setBlockedTime(blockedDuration); result.setDuration(buildDuration); result.setPassed(buildState == BuildStage.State.CompletedSuccess); result.setResult(buildState); result.setTimestamp(Clock.system(TimeZone.getTimeZone("UTC").toZoneId()).millis() / 1000); return result; }
Example #8
Source File: BuildFlowAction.java From yet-another-build-visualizer-plugin with MIT License | 6 votes |
private static Run getUpstreamBuild(@Nonnull Run build) { CauseAction causeAction = build.getAction(CauseAction.class); if (causeAction == null) { return null; } for (Cause cause : causeAction.getCauses()) { if (cause instanceof Cause.UpstreamCause) { Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause; Job upstreamJob = Jenkins.getInstance().getItemByFullName(upstreamCause.getUpstreamProject(), Job.class); // We want to ignore rebuilds, rebuilds have the same parent as // original build, see BuildCache#updateCache(). if (upstreamJob == null || build.getParent() == upstreamJob) { continue; } return upstreamJob.getBuildByNumber(upstreamCause.getUpstreamBuild()); } } return null; }
Example #9
Source File: CauseActionConverterTest.java From DotCi with MIT License | 6 votes |
@Test public void should_convert_cause_action_to_old_format() throws Exception { Cause cause1 = new NullBuildCause(); Mapper mapper = Mockito.mock(Mapper.class); when(mapper.toDBObject(cause1)).thenReturn(new BasicDBObject("cause1", "cause1")); CauseAction causeAction = new CauseAction(cause1); CauseActionConverter converter = new CauseActionConverter(); converter.setMapper(mapper); DBObject dbObject = (DBObject) converter.encode(causeAction, null); Assert.assertEquals(dbObject.get("className"), CauseAction.class.getName()); Assert.assertNotNull(dbObject.get("causes")); List dbCauses = ((List) dbObject.get("causes")); Assert.assertEquals(1, dbCauses.size()); Assert.assertEquals("cause1", ((BasicDBObject) dbCauses.get(0)).get("cause1")); }
Example #10
Source File: GitHubPRLabelUnblockQueueCondition.java From github-integration-plugin with MIT License | 6 votes |
@Override public boolean isUnblocked(Queue.Item item) { final List<Cause> causes = item.getCauses(); for (Cause cause : causes) { if (cause instanceof GitHubPRCause) { final GitHubPRCause gitHubPRCause = (GitHubPRCause) cause; final Set<String> causeLabels = gitHubPRCause.getLabels(); if (getLabel() != null) { if (causeLabels.containsAll(label.getLabelsSet())) { if (item.task instanceof Job<?, ?>) { final Job<?, ?> job = (Job<?, ?>) item.task; LOGGER.debug("Unblocking job item {} with matched labels {}", job.getFullName(), label.getLabelsSet()); } return true; } } } } return false; }
Example #11
Source File: JobRunnerForBranchCause.java From github-integration-plugin with MIT License | 6 votes |
/** * Cancel previous builds for specified PR id. */ private static boolean cancelQueuedBuildByBranchName(final String branch) { Queue queue = getJenkinsInstance().getQueue(); for (Queue.Item item : queue.getItems()) { Optional<Cause> cause = from(item.getAllActions()) .filter(instanceOf(CauseAction.class)) .transformAndConcat(new CausesFromAction()) .filter(instanceOf(GitHubBranchCause.class)) .firstMatch(new CauseHasBranch(branch)); if (cause.isPresent()) { queue.cancel(item); return true; } } return false; }
Example #12
Source File: Common.java From hubot-steps-plugin with Apache License 2.0 | 6 votes |
/** * Return the current build user. * * @param causes build causes. * @param envVars environment variables. * @return user name. */ public static String prepareBuildUserName(List<Cause> causes, EnvVars envVars) { String buildUser = "anonymous"; // For multi branch jobs, while PR building. if (Util.fixEmpty(envVars.get("CHANGE_AUTHOR")) != null) { return envVars.get("CHANGE_AUTHOR"); } if (causes != null && causes.size() > 0) { if (causes.get(0) instanceof UserIdCause) { buildUser = ((UserIdCause) causes.get(0)).getUserName(); } else if (causes.get(0) instanceof UpstreamCause) { List<Cause> upstreamCauses = ((UpstreamCause) causes.get(0)).getUpstreamCauses(); buildUser = prepareBuildUserName(upstreamCauses, envVars); } } return buildUser; }
Example #13
Source File: Common.java From hubot-steps-plugin with Apache License 2.0 | 6 votes |
/** * Retrun the build cause. * * @return build cause. */ public static String prepareBuildCause(List<Cause> causes) { String buildCause = null; if (causes != null && causes.size() > 0) { for (Cause cause : causes) { if (cause instanceof UserIdCause) { buildCause = ((UserIdCause) causes.get(0)).getUserName(); } else if (cause instanceof UpstreamCause) { List<Cause> upstreamCauses = ((UpstreamCause) cause).getUpstreamCauses(); buildCause = prepareBuildCause(upstreamCauses); } else { buildCause = cause.getClass().getSimpleName(); } } } return buildCause == null ? buildCause : buildCause.replace("Cause", ""); }
Example #14
Source File: UpstreamBuildUtil.java From jira-ext-plugin with Apache License 2.0 | 6 votes |
private static Cause.UpstreamCause getUpstreamCause(Run run) { if (run == null) { return null; } List<Cause> causes = run.getCauses(); for (Cause cause : causes) { if (cause instanceof Cause.UpstreamCause) { return (Cause.UpstreamCause)cause; } } return null; }
Example #15
Source File: PipelineApiTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void testPipelineQueue() throws Exception { FreeStyleProject p1 = j.createFreeStyleProject("pipeline1"); p1.setConcurrentBuild(true); p1.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("test","test"))); p1.getBuildersList().add(new Shell("echo hello!\nsleep 300")); p1.scheduleBuild2(0).waitForStart(); p1.scheduleBuild2(0).waitForStart(); Jenkins.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test","test1")), new CauseAction(new Cause.UserIdCause())); Jenkins.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test","test2")), new CauseAction(new Cause.UserIdCause())); List queue = request().get("/organizations/jenkins/pipelines/pipeline1/queue").build(List.class); Assert.assertEquals(2, queue.size()); Assert.assertEquals(4, ((Map) queue.get(0)).get("expectedBuildNumber")); Assert.assertEquals(3, ((Map) queue.get(1)).get("expectedBuildNumber")); Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(0)).get("causeOfBlockage")); Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(1)).get("causeOfBlockage")); Run r = QueueUtil.getRun(p1, Long.parseLong((String)((Map)queue.get(0)).get("id"))); assertNull(r); //its not moved out of queue yet }
Example #16
Source File: AbstractMultiBranchCreateRequest.java From blueocean-plugin with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public BluePipeline create(@Nonnull BlueOrganization organization, @Nonnull Reachable parent) throws IOException { validateInternal(getName(), scmConfig, organization); MultiBranchProject project = createMultiBranchProject(organization); assignCredentialToProject(scmConfig, project); SCMSource source = createSource(project, scmConfig).withId("blueocean"); project.setSourcesList(ImmutableList.of(new BranchSource(source))); source.afterSave(); project.save(); final boolean hasJenkinsfile = repoHasJenkinsFile(source); if(!hasJenkinsfile){ sendMultibranchIndexingCompleteEvent(project, 5); AbstractScmSourceEvent scmSourceEvent = getScmSourceEvent(project, source); if(scmSourceEvent != null) { SCMSourceEvent.fireNow(scmSourceEvent); } }else{ project.scheduleBuild(new Cause.UserIdCause()); } return BluePipelineFactory.getPipelineInstance(project, OrganizationFactory.getInstance().getContainingOrg(project.getItemGroup())); }
Example #17
Source File: PipelineTriggerService.java From pipeline-maven-plugin with MIT License | 6 votes |
/** * Check NO infinite loop of job triggers caused by {@link hudson.model.Cause.UpstreamCause}. * * @param initialBuild * @throws IllegalStateException if an infinite loop is detected */ public void checkNoInfiniteLoopOfUpstreamCause(@Nonnull Run initialBuild) throws IllegalStateException { java.util.Queue<Run> builds = new LinkedList<>(Collections.singleton(initialBuild)); Run currentBuild; while ((currentBuild = builds.poll()) != null) { for (Cause cause : ((List<Cause>) currentBuild.getCauses())) { if (cause instanceof Cause.UpstreamCause) { Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause; Run<?, ?> upstreamBuild = upstreamCause.getUpstreamRun(); if (upstreamBuild == null) { // Can be Authorization, build deleted on the file system... } else if (Objects.equals(upstreamBuild.getParent().getFullName(), initialBuild.getParent().getFullName())) { throw new IllegalStateException("Infinite loop of job triggers "); } else { builds.add(upstreamBuild); } } } } }
Example #18
Source File: WebhookJobPropertyIT.java From office-365-connector-plugin with Apache License 2.0 | 6 votes |
@Test public void testDataCompatibility() throws Exception { // given FreeStyleProject foo = (FreeStyleProject) rule.jenkins.createProjectFromXML( "bar", getClass().getResourceAsStream("WebhookJobProperty/freestyleold1.xml") ); // when WebhookJobProperty webhookJobProperty = foo.getProperty(WebhookJobProperty.class); assertThat(webhookJobProperty.getWebhooks()).isNotEmpty(); // then rule.assertBuildStatusSuccess(foo.scheduleBuild2(0, new Cause.UserIdCause()).get()); }
Example #19
Source File: FactsBuilderTest.java From office-365-connector-plugin with Apache License 2.0 | 6 votes |
@Test public void addRemarks_AddsFact() { // given FactsBuilder factBuilder = new FactsBuilder(run, taskListener); List<Cause> causes = CauseBuilder.sampleCauses(); when(run.getCauses()).thenReturn(causes); // when factBuilder.addRemarks(); // then FactAssertion.assertThat(factBuilder.collect()) .hasName(FactsBuilder.NAME_REMARKS) .hasValue(causes.get(0).getShortDescription() + ". " + causes.get(1).getShortDescription() + "."); }
Example #20
Source File: CauseDTO.java From kubernetes-pipeline-plugin with Apache License 2.0 | 6 votes |
public CauseDTO(Cause cause) { this.shortDescription = cause.getShortDescription(); if (cause instanceof Cause.UserIdCause) { Cause.UserIdCause userIdCause = (Cause.UserIdCause) cause; this.userId = userIdCause.getUserId(); this.userName = userIdCause.getUserName(); } else if (cause instanceof Cause.RemoteCause) { Cause.RemoteCause remoteCause = (Cause.RemoteCause) cause; this.remoteAddr = remoteCause.getAddr(); this.remoteNote = remoteCause.getNote(); } else if (cause instanceof Cause.UpstreamCause) { Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause; this.upstreamProject = upstreamCause.getUpstreamProject(); this.upstreamUrl = upstreamCause.getUpstreamUrl(); } }
Example #21
Source File: DeflakeListener.java From flaky-test-handler-plugin with Apache License 2.0 | 5 votes |
@Override public void onStarted(Run build, TaskListener listener) { List<Cause> causesList = build.getCauses(); try { for (Cause cause : causesList) { if (cause instanceof DeflakeCause) { build.setDisplayName(build.getDisplayName() + ": " + cause.getShortDescription()); return; } } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to set deflake build name: " + e.getMessage()); } }
Example #22
Source File: PendingBuildsHandler.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private GitLabWebHookCause getGitLabWebHookCauseData(Queue.Item item) { for (Cause cause : item.getCauses()) { if (cause instanceof GitLabWebHookCause) { return (GitLabWebHookCause) cause; } } return null; }
Example #23
Source File: GitLabBuildDescriptionRunListener.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
@Override public void onStarted(Run<?, ?> build, TaskListener listener) { GitLabPushTrigger trigger = GitLabPushTrigger.getFromJob(build.getParent()); if (trigger != null && trigger.getSetBuildDescription()) { Cause cause = build.getCause(GitLabWebHookCause.class); if (cause != null && !cause.getShortDescription().isEmpty()) { try { build.setDescription(cause.getShortDescription()); } catch (IOException e) { listener.getLogger().println("Failed to set build description"); } } } }
Example #24
Source File: CommitStatusUpdateQueueListener.java From DotCi with MIT License | 5 votes |
@Override public void onEnterWaiting(final Queue.WaitingItem wi) { final List<Cause> causes = wi.getCauses(); if (causes != null) { for (final Cause cause : causes) { if (cause instanceof BuildCause && wi.task instanceof DynamicProject) { setCommitStatus((BuildCause) cause, (DynamicProject) wi.task); return; } } } }
Example #25
Source File: UpstreamBuildUtil.java From jira-ext-plugin with Apache License 2.0 | 5 votes |
/** * Get the root upstream build which caused this build. Useful in build pipelines to * be able to extract the changes which started the pipeline in later stages of * the pipeline * * @return */ public static AbstractBuild getUpstreamBuild(AbstractBuild<?, ?> build) { logger.log(Level.FINE, "Find build upstream of " + build.getId()); Cause.UpstreamCause cause = getUpstreamCause(build); if (cause == null) { logger.log(Level.FINE, "No upstream cause, so must be upstream build: " + build.getId()); return build; } logger.log(Level.FINE, "Found upstream cause: " + cause.toString() + "(" + cause.getShortDescription() + ")"); AbstractProject project = (AbstractProject) Jenkins.getInstance().getItem(cause.getUpstreamProject(), build.getProject()); if (project == null) { logger.log(Level.WARNING, "Found an UpstreamCause (" + cause.toString() + "), but the upstream project (" + cause.getUpstreamProject() + ") does not appear to be valid!"); logger.log(Level.WARNING, "Using build [" + build.getId() + "] as the upstream build - this is likely incorrect."); return build; } AbstractBuild upstreamBuild = project.getBuildByNumber(cause.getUpstreamBuild()); if (upstreamBuild == null) { logger.log(Level.WARNING, "Found an UpstreamCause (" + cause.toString() + "), and an upstream project (" + project.getName() + "), but the build is invalid!" + cause.getUpstreamBuild()); logger.log(Level.WARNING, "Using build [" + build.getId() + "] as the upstream build - this is likely incorrect."); return build; } return getUpstreamBuild(upstreamBuild); }
Example #26
Source File: DatabaseSyncRunListener.java From pipeline-maven-plugin with MIT License | 5 votes |
@Override public void onInitialize(WorkflowRun run) { super.onInitialize(run); for (Cause cause: run.getCauses()) { if (cause instanceof Cause.UpstreamCause) { Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause; String upstreamJobName = upstreamCause.getUpstreamProject(); int upstreamBuildNumber = upstreamCause.getUpstreamBuild(); globalPipelineMavenConfig.getDao().recordBuildUpstreamCause(upstreamJobName, upstreamBuildNumber, run.getParent().getFullName(), run.getNumber()); } } }
Example #27
Source File: MavenDependencyUpstreamCause.java From pipeline-maven-plugin with MIT License | 5 votes |
/** * TODO create a PR on jenkins-core to make {@link hudson.model.Cause.UpstreamCause#print(TaskListener, int)} protected instead of private * <p> * Mimic {@link hudson.model.Cause.UpstreamCause#print(TaskListener, int)} waiting for this method to become protected instead of private * * @see UpstreamCause#print(TaskListener, int) */ private void print(TaskListener listener, int depth) { indent(listener, depth); Run<?, ?> upstreamRun = getUpstreamRun(); if (upstreamRun == null) { listener.getLogger().println("Started by upstream build " + ModelHyperlinkNote.encodeTo('/' + getUpstreamUrl(), getUpstreamProject()) + "\" #" + ModelHyperlinkNote.encodeTo('/' + getUpstreamUrl() + getUpstreamBuild(), Integer.toString(getUpstreamBuild())) + " generating Maven artifact: " + getMavenArtifactsDescription()); } else { listener.getLogger().println("Started by upstream build " + ModelHyperlinkNote.encodeTo('/' + upstreamRun.getUrl(), upstreamRun.getFullDisplayName()) + " generating Maven artifacts: " + getMavenArtifactsDescription()); } if (getUpstreamCauses() != null && !getUpstreamCauses().isEmpty()) { indent(listener, depth); listener.getLogger().println("originally caused by:"); for (Cause cause : getUpstreamCauses()) { if (cause instanceof MavenDependencyUpstreamCause) { ((MavenDependencyUpstreamCause) cause).print(listener, depth + 1); } else { indent(listener, depth + 1); cause.print(listener); } } } }
Example #28
Source File: MavenDependencyCauseHelper.java From pipeline-maven-plugin with MIT License | 5 votes |
public static List<MavenArtifact> isSameCause(MavenDependencyCause newMavenCause, List<Cause> oldMavenCauses) { List<MavenArtifact> matchingArtifacts = new ArrayList<>(); for (Cause oldMavenCause:oldMavenCauses) { matchingArtifacts.addAll(isSameCause(newMavenCause, oldMavenCause)); } return matchingArtifacts; }
Example #29
Source File: MavenDependencyCauseHelper.java From pipeline-maven-plugin with MIT License | 5 votes |
/** * Return matching artifact if the given causes refer to common Maven artifact. Empty list if there are no matching artifact */ @Nonnull public static List<MavenArtifact> isSameCause(MavenDependencyCause newMavenCause, Cause oldMavenCause) { if (!(oldMavenCause instanceof MavenDependencyCause)) { return Collections.emptyList(); } List<MavenArtifact> newCauseArtifacts = Preconditions.checkNotNull(newMavenCause.getMavenArtifacts(), "newMavenCause.mavenArtifacts should not be null"); List<MavenArtifact> oldCauseArtifacts = Preconditions.checkNotNull(((MavenDependencyCause) oldMavenCause).getMavenArtifacts(), "oldMavenCause.mavenArtifacts should not be null"); List<MavenArtifact> matchingArtifacts = new ArrayList<>(); for (MavenArtifact newCauseArtifact : newCauseArtifacts) { if (newCauseArtifact.isSnapshot() && newCauseArtifact.getVersion().contains("SNAPSHOT")) { // snapshot without exact version (aka base version), cannot search for same cause } else { for (MavenArtifact oldCauseArtifact : oldCauseArtifacts) { if (Objects.equals(newCauseArtifact.getGroupId(), oldCauseArtifact.getGroupId()) && Objects.equals(newCauseArtifact.getArtifactId(), oldCauseArtifact.getArtifactId()) && Objects.equals(newCauseArtifact.getVersion(), oldCauseArtifact.getVersion()) && Objects.equals(newCauseArtifact.getBaseVersion(), oldCauseArtifact.getBaseVersion()) && Objects.equals(newCauseArtifact.getClassifier(), oldCauseArtifact.getClassifier()) && Objects.equals(newCauseArtifact.getType(), oldCauseArtifact.getType())) { matchingArtifacts.add(newCauseArtifact); } } } } return matchingArtifacts; }
Example #30
Source File: PhabricatorBuildWrapper.java From phabricator-jenkins-plugin with MIT License | 5 votes |
@VisibleForTesting static Run<?, ?> getUpstreamRun(AbstractBuild build) { CauseAction action = build.getAction(hudson.model.CauseAction.class); if (action != null) { Cause.UpstreamCause upstreamCause = action.findCause(hudson.model.Cause.UpstreamCause.class); if (upstreamCause != null) { return upstreamCause.getUpstreamRun(); } } return null; }