Skip to content

feat(maven): Support BOM files in maven target - #270

Merged
iker-barriocanal merged 7 commits into
masterfrom
iker/feat/maven-bomfile
Jul 22, 2021
Merged

feat(maven): Support BOM files in maven target#270
iker-barriocanal merged 7 commits into
masterfrom
iker/feat/maven-bomfile

Conversation

@iker-barriocanal

Copy link
Copy Markdown
Contributor

Add support for BOM files in the maven target.

This is based on previous Kotlin code, but that's incomplete. A BOM file is a POM file with a <packaging>pom</packaging> key.

An artifact (the zip downloaded from GHA) may contain a POM and a BOM, both with the same name (pom-default.xml is the default name). In case both are present, unzipping the artifact may lead to having an unknown name for the BOM file (e.g. the POM is the pom-default.xml, and the BOM is ??). Thus, if the default file isn't a BOM, all xml files in the artifact are checked to not miss the BOM. If no BOM is found, the distribution is uploaded as it is now (without this PR); and if a BOM is found, a different command to upload files is run. Once artifacts have been uploaded, the registry is closed.

const revision = 'r3v1s10n';

await mvnTarget.publish(version, revision);
await mvnTarget.publish('1.0.0', revision);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why change to directly passing in the string vs. a variable like before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The version isn't being used anywhere else, so IMO removes a bit of noise (like in others upload calls). Do you think it's easier to read by leaving the variable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No I have no strong opinions, just wondering. I agree it helps reduce noise in the test file so I would keep it 👍

Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts
await retrySpawnProcess(this.mavenConfig.mavenCliPath, [
'gpg:sign-and-deploy-file',
`-Dfile=${bomFile}`,
`-DpomFile=${bomFile}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't need to set -Dtypes=jar,jar here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts
Comment thread src/targets/maven.ts Outdated

@AbhiPrasad AbhiPrasad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just wanted to get the comment about the zip behaviour address, and then I'll slam the ✅.

Comment thread src/targets/__tests__/maven.test.ts Outdated
Comment thread src/targets/maven.ts
* `undefined` if there isn't any.
*/
private async getBomFileInDist(distDir: string): Promise<string | undefined> {
const pomFilepath = join(distDir, POM_DEFAULT_FILENAME);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be something like possibleBomFilePath?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could, but not sure whether it should. We don't know whether it's a BOM, but we do know it's a POM (a BOM is a type of POM). So I think making a reference to BOM makes it less accurate; besides, some logic below treats any xml file as a potential BOM, so that would be confusing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it, that reasoning sounds good to me.

Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts
Comment on lines +284 to +288
// There may be several files in the ZIP-ed artifact with the same name,
// where the BOM may be one of them (there may not be a BOM). Files may be
// renamed when extracting the ZIP, so the default name (`pom-default.xml`)
// may not match. It's assumed that any renaming keeps the same extension,
// so all files with the same extension are checked to identify the BOM.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we simplify this logic by enforcing users of the target to pass in the bom file name as a craft option? I know we already wrote all of this out, but I'm scared of the regex test failing to account for all scenarios.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No. Although the end goal is to run the target in unattended mode, it currently is meant to run in attended mode. When files with same name exist in a ZIP, OSX (where this is going to run for now, at least until running in unattended mode is fully supported) asks for a name to rename the file. Force the user to set the same filename set in the config file is a clear no for me.

Regarding other scenarios, you're right this isn't solid enough. The Linux file system (where the Craft image will run), OSX, and running in attended mode is a lot of scenarios. The thing that should never change is the file extension (even Linux shouldn't modify it), and that's the reason behind it. The little prose in the PR description is ambiguous, but I left it like that on purpose. Once the maven target gets more work (to support unattended mode), these scenarios should be handled.

I'll add a TODO in the code for this, which clearly missing.

@AbhiPrasad AbhiPrasad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the additional context + TODO 🚀

@iker-barriocanal
iker-barriocanal merged commit cd4c61f into master Jul 22, 2021
@iker-barriocanal
iker-barriocanal deleted the iker/feat/maven-bomfile branch July 22, 2021 16:22
Comment thread src/targets/__tests__/maven.test.ts
Comment thread src/targets/maven.ts
Comment thread src/targets/maven.ts
Comment on lines +285 to +286
// where the BOM may be one of them (there may not be a BOM). Files may be
// renamed when extracting the ZIP, so the default name (`pom-default.xml`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Files may be renamed when extracting the ZIP

How so? We control how we unzip, right?

Comment thread src/targets/maven.ts
Comment thread src/targets/maven.ts
Comment on lines +299 to +303
for (const f of potentialPoms) {
if (await this.isBomFile(f)) {
return f;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strongly recommend using sync APIs for isBomFile and replacing this block with potentialPoms.find(f => this.isBomFile(f)) if the number of files is small and the file contents are small. Would be much faster and simpler code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure how big the size of the contents can be, but went with the declarative way.

Comment thread src/targets/maven.ts
@iker-barriocanal iker-barriocanal changed the title ref(maven): Support BOM files in maven target feat(maven): Support BOM files in maven target Aug 17, 2021
iker-barriocanal added a commit that referenced this pull request Aug 18, 2021
Removing the `gradle.properties` after running the maven target may prevent exposing it, which contains the OSSRH credentials (see #272). There also are minor changes to address some feedback in #270.
@BYK BYK added this to the Added Maven Target milestone Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants