Skip to content

Commit

Permalink
[JENKINS-67870] Add project action Latest Dependency-Check
Browse files Browse the repository at this point in the history
To improve accessibility to the latest dependency check report add a new
action on the main job page as for the "Last Test Result" that leads to
the last dependency-check.
  • Loading branch information
nfalco79 committed Oct 11, 2022
1 parent 060902c commit cc0ad6f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
Expand Up @@ -73,7 +73,11 @@ public void onLoad(Run<?, ?> run) {

@Override
public Collection<? extends Action> getProjectActions() {
return Collections.singleton(new JobAction(run.getParent()));
if (!run.getActions(ResultProjectAction.class).isEmpty()) {
// someone already added one
return Collections.emptySet();
}
return Collections.singleton(new ResultProjectAction(run.getParent()));
}

public Run getRun() {
Expand Down
@@ -0,0 +1,53 @@
/*
* This file is part of Dependency-Check Jenkins plugin.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jenkinsci.plugins.DependencyCheck;

import hudson.model.Action;
import hudson.model.Job;

/**
* Action attached to project to link latest dependency-check report.
*
* @author Nikolas Falco
* @since 5.1.3
*/
public class ResultProjectAction implements Action {

/**
* Project that owns this action.
*/
public final Job<?,?> job;

public ResultProjectAction(Job<?,?> job) {
this.job = job;
}

@Override
public String getIconFileName() {
return null;
}

@Override
public String getDisplayName() {
return "Dependency-Check";
}

@Override
public String getUrlName() {
return null;
}

}
@@ -0,0 +1,28 @@
<!--
This file is part of Dependency-Check Jenkins plugin.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:t="/lib/hudson" xmlns:test="/lib/hudson/test">
<table style="margin-top: 1em; margin-left: 1em;">
<j:set var="tr" value="${it.job.lastCompletedBuild.getAction(it.class.classLoader.loadClass('org.jenkinsci.plugins.DependencyCheck.ResultAction'))}"/>
<j:if test="${tr != null}">
<t:summary icon="/plugin/dependency-check-jenkins-plugin/icons/dependency-check-icon.svg">
<a href="lastCompletedBuild/${tr.urlName}/">${%Latest Dependency-Check}</a>
<st:nbsp/>
<test:test-result it="${tr}"/>
</t:summary>
</j:if>
</table>
</j:jelly>

0 comments on commit cc0ad6f

Please sign in to comment.