Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Link to DT Project page on the sidebar
fixes #JENKINS-55627
- Loading branch information
1 parent
56ad0de
commit 61b0ff7
Showing
7 changed files
with
195 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/org/jenkinsci/plugins/DependencyTrack/ResultLinkAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2020 OWASP. | ||
* | ||
* 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 | ||
* | ||
* https://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.DependencyTrack; | ||
|
||
import hudson.model.Run; | ||
import java.io.Serializable; | ||
import jenkins.model.RunAction2; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
/** | ||
* Action to Provide a Link to the Project on the Dependency-Track Server | ||
* | ||
* @author Ronny "Sephiroth" Perinke <sephiroth@sephiroth-j.de> | ||
*/ | ||
@Getter | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor | ||
public class ResultLinkAction implements RunAction2, Serializable { | ||
|
||
private static final long serialVersionUID = 9144463546984654654L; | ||
|
||
/** | ||
* the URL of the Dependency-Track Server to which these results are | ||
* belonging to | ||
*/ | ||
private final String dependencyTrackUrl; | ||
|
||
/** | ||
* the ID of the project to which these results are belonging to | ||
*/ | ||
private final String projectId; | ||
|
||
/** | ||
* the name of the project to which these results are belonging to | ||
*/ | ||
@Setter | ||
private String projectName; | ||
|
||
/** | ||
* the version of the project to which these results are belonging to | ||
*/ | ||
@Setter | ||
private String projectVersion; | ||
|
||
@Override | ||
public String getIconFileName() { | ||
return isEnabled() ? "/plugin/dependency-track/icons/dt-logo-symbol.svg" : null; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return isEnabled() ? Messages.Result_DT_Project(): null; | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return isEnabled() ? String.format("%s/projects/%s", dependencyTrackUrl, projectId) : null; | ||
} | ||
|
||
@Override | ||
public void onAttached(Run<?, ?> run) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void onLoad(Run<?, ?> run) { | ||
// nothing to do | ||
} | ||
|
||
private boolean isEnabled() { | ||
return StringUtils.isNotBlank(dependencyTrackUrl) && StringUtils.isNotBlank(projectId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/org/jenkinsci/plugins/DependencyTrack/ResultLinkActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2020 OWASP. | ||
* | ||
* 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 | ||
* | ||
* https://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.DependencyTrack; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* | ||
* @author Ronny "Sephiroth" Perinke <sephiroth@sephiroth-j.de> | ||
*/ | ||
public class ResultLinkActionTest { | ||
|
||
@Test | ||
public void testWithMissingUrlAndProjectId() { | ||
ResultLinkAction uut = new ResultLinkAction(null, null); | ||
assertThat(uut.getUrlName()).isNull(); | ||
assertThat(uut.getDisplayName()).isNull(); | ||
assertThat(uut.getIconFileName()).isNull(); | ||
} | ||
|
||
@Test | ||
public void testWithMissingUrl() { | ||
ResultLinkAction uut = new ResultLinkAction(null, "an-id"); | ||
assertThat(uut.getUrlName()).isNull(); | ||
assertThat(uut.getDisplayName()).isNull(); | ||
assertThat(uut.getIconFileName()).isNull(); | ||
} | ||
|
||
@Test | ||
public void testWithMissingProjectId() { | ||
ResultLinkAction uut = new ResultLinkAction("http://foo.bar", null); | ||
assertThat(uut.getUrlName()).isNull(); | ||
assertThat(uut.getDisplayName()).isNull(); | ||
assertThat(uut.getIconFileName()).isNull(); | ||
} | ||
|
||
@Test | ||
public void testWithUrlAndProjectId() { | ||
ResultLinkAction uut = new ResultLinkAction("http://foo.bar", "an-id"); | ||
assertThat(uut.getUrlName()).isEqualTo("http://foo.bar/projects/an-id"); | ||
assertThat(uut.getDisplayName()).isNotEmpty(); | ||
assertThat(uut.getIconFileName()).isNotEmpty(); | ||
} | ||
|
||
} |