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

Add ability to set parent project (#345) #346

Merged
merged 9 commits into from
May 6, 2023

Conversation

pmckeown
Copy link
Owner

  • Added ability to set project parent. Cannot merge until DT 2401 is fixed.

  • Clarified behaviour of setParent

  • Tested against a 4.8.0 Snapshot and added handling of null version


Co-authored-by: jason jason.irwin@idoxgroup.com

* Added ability to set project parent. Cannot merge until [DT 2401](DependencyTrack/dependency-track#2401) is fixed.

* Clarified behaviour of setParent

* Tested against a 4.8.0 Snapshot and added handling of `null` version

---------

Co-authored-by: jason <jason.irwin@idoxgroup.com>
@sonarcloud
Copy link

sonarcloud bot commented Jan 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

86.2% 86.2% Coverage
0.0% 0.0% Duplication

ProjectInfo info = null;
if (updateReq.hasBomLocation()) {
logger.info("Project info will be updated");
Optional<ProjectInfo> optInfo = bomParser.getProjectInfo(new File(updateReq.getBomLocation()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/io/File.(Ljava/lang/String;)V) reads a file whose location might be specified by user input


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Owner Author

@pmckeown pmckeown Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignoreall

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ignoreall command is active on this PR, all the existing Lift issues are ignored.

@@ -61,22 +73,55 @@ public UploadBomMojo(UploadBomAction uploadBomAction, MetricsAction metricsActio
@Override
public void performAction() throws MojoExecutionException, MojoFailureException {
try {
logger.info("Update Project Parent: %s", updateParent);

Project parent = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12% of developers fix this issue

💬 2 similar findings have been found in this PR


Var: Non-constant variable missing @var annotation


Suggested change
Project parent = null;
@Var Project parent = null;

🔎 Expand here to view all instances of this finding
File Path Line Number
src/main/java/io/github/pmckeown/dependencytrack/project/ProjectAction.java 62
src/main/java/io/github/pmckeown/dependencytrack/upload/UploadBomMojo.java 96

Visit the Lift Web Console to find more details in your report.


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@sonatype-lift
Copy link

sonatype-lift bot commented Jan 28, 2023

🛠 Lift Auto-fix

Some of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.1

# Download the patch
curl https://lift.sonatype.com/api/patch/github.com/pmckeown/dependency-track-maven-plugin/346.diff -o lift-autofixes.diff

# Apply the patch with git
git apply lift-autofixes.diff

# Review the changes
git diff

Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command:

curl https://lift.sonatype.com/api/patch/github.com/pmckeown/dependency-track-maven-plugin/346.diff | git apply

Once you're satisfied commit and push your changes in your project.

Footnotes

  1. You can preview the patch by opening the patch URL in the browser.

@pmckeown
Copy link
Owner Author

@roadSurfer - I'm a bit reluctant to release a new feature into the plugin that operates against a snapshot of the target system. In general the feature looks fine and allows alignment between the project model in Maven and Dependency Track. So keen to add the feature, just not against the main branch code.

Are you OK to wait until 4.8.0 is released before revisiting?

@roadSurfer
Copy link
Contributor

Yes of course! Wasn't sure how you wanted to handle it or what your release plans were.

@pmckeown
Copy link
Owner Author

Yes of course! Wasn't sure how you wanted to handle it or what your release plans were.

OK cool - will wait until 4.8.0 is released then test this out properly.

Comment on lines +195 to +212
From Dependency-Track server 4.8.0 onwards, you can set the project parent by setting `updateParent` to `true`. The
parent name will be defaulted to that POM's project parent name. If you wish to override that value, or there is
no parent set within the `pom.xml`, then explicitly set `parentName` and `parentVersion`.

Dependency Track doesn't require a project version to be set which means this will fail if there is no version set on
the project in Dependency Track that matches the name of the parent of the maven project or the overridden parentName
value.

**Note:** If the parent cannot be found on the Dependency-Track server, the BOM upload will not be attempted in order to
prevent a project being incorrectly created or updated the server.

| Property | Required | Default Value | Example Values |
|-------------------|----------|---------------------------|-----------------------|
| bomLocation | false | target/bom.xml | target/custom-bom.xml |
| updateProjectInfo | false | false | false |
| updateParent | false | false | true |
| parentName | false | ${project.parent.name} | my-name-override |
| parentVersion | false | ${project.parent.version} | my-version-override |
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roadSurfer I've made some behaviour tweaks from your original PR best documented here.

In my view not defaulting the parent version to that of the maven parent pom seemed counter-intuitive. I see where you are coming from in that DT doesn't mandate a version on a project. However if that project was created by the plugin, then the version will be set. If the project wasn't created by this plugin and is missing a version, it can be added in the DT UI and then set as the parentVersion property in the use of this plugin to link it up.

Does that sound reasonable to you and not too far from your original intent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems totally fine to me.

metricsAction.refreshMetrics(project);
} catch (DependencyTrackException ex) {
handleFailure("Error occurred during upload", ex);
}
}

private Project getProjectParent(String parentName, String parentVersion)
throws DependencyTrackException {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made some tweaks the implementation of setting the parent too.

During testing, the error messages were not being displayed and due to my original implementation of error handling that you followed, the mvn -e was only showing a generic error so nothing useful for the user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry. I didn't spot this in my testing.

@pmckeown
Copy link
Owner Author

pmckeown commented May 3, 2023

Tests are failing at the minute on this branch and I'd like to tidy up a bit. So will be delayed a few days on getting this all tidied up.

@sonarcloud
Copy link

sonarcloud bot commented May 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

81.9% 81.9% Coverage
0.0% 0.0% Duplication

@pmckeown pmckeown merged commit 99ab598 into main May 6, 2023
6 checks passed
@pmckeown pmckeown deleted the feature/338-set-parent-project branch May 6, 2023 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants