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

Contributes Maven ArtifactSizeEnforcerRule to DDF-Support #54

Merged
merged 1 commit into from
Sep 24, 2018
Merged

Contributes Maven ArtifactSizeEnforcerRule to DDF-Support #54

merged 1 commit into from
Sep 24, 2018

Conversation

coyotesqrl
Copy link
Member

Also restructures support-maven module to more easily enable future additions and resolves static analysis findings.

Git does not recognize the move of MavenVersionValidationPlugin because it detects too many internal changes; these were just fixes to static findings.

Copy link
Contributor

@paouelle paouelle left a comment

Choose a reason for hiding this comment

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

GTM with minor requested changes

<rules>
<rule>
<element>BUNDLE</element>
<limits>
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Should we not use lenient limits?

long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper);
long artifactSize = getArtifact(artifactPath).length();

if (artifactSize >= maxArtifactSizeBytes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Should we be lenient a bit? Since different compilers on different OS (or the same OS) might be generating different byte code. Hardcoding a hard limit might suffer the same fate as did jacoco.

Copy link
Member Author

Choose a reason for hiding this comment

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

My feeling is that we should be less worried about this particular failure hitting us only because of OS differences than Jacoco. Even if we're bumping up near the size boundary, the developer should be paying attention and should fix the size of the output artifact or manually bump the allowed max size. In reality, we shouldn't be close to the limits unless we're embedding jars willy-nilly.

@tbatie what's your opinion on this?

case JAR:
return JAR;
case BUNDLE:
return JAR;
Copy link
Contributor

Choose a reason for hiding this comment

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

❗️ BUNDLE instead of JAR

}

if (convertArtifactSize.endsWith(BYTES)) {
return Long.parseLong(convertArtifactSize.split(BYTES)[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Should we catch the NumberFormatException that can occur?

enforcer.setMaxArtifactSize("INVALID_UNIT");
enforcer.execute(defaultMockhelper);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests for invalid parsing for _B, _KB, and _MB values

@coyotesqrl
Copy link
Member Author

Updates for code review comments pushed in separate commit.

.debug(
String.format(DEFAULT_ARTIFACT_INFO_MSG, artifactId, version, packaging, buildDir));

convertedArtifactLocation =
Copy link
Member

Choose a reason for hiding this comment

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

❓ Is there a reason you didn't use String.format() here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No reason at all; I'll change it.

<version>2.3.15-SNAPSHOT</version>
</parent>

<artifactId>artifact-size-enforcer</artifactId>

Choose a reason for hiding this comment

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

✏️ <name> ? <description> may be handy too if we are looking for more third parties to use this.

import org.codehaus.plexus.util.StringUtils;

/**
* When the ArtifactSizeEnforceRule is active, it will look up the packaging type and enforce a

Choose a reason for hiding this comment

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

✏️ ArtifactSizeEnforce*r*Rule

long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper);
long artifactSize = getArtifact(artifactPath).length();

if (artifactSize >= maxArtifactSizeBytes) {

Choose a reason for hiding this comment

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

❓ Did we want this comparison to be greater than or equal to, or just greater than? The exception message indicates the size should not be exceeded.

*/
public class ArtifactSizeEnforcerRule implements EnforcerRule {

static final String PROJECT_PACKAGING_PROP = "${project.packaging}";

Choose a reason for hiding this comment

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

❓ Worth adding @VisibleForTesting on all these?

packaging);
helper
.getLog()
.debug(

Choose a reason for hiding this comment

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

Nit, any reason we don't log the generated path at the info level as you are when a path is provided? If this plugin fails, this could be really useful information to the user.

"Using the following parameters to find artifact: %n\tArtifactId: %s%n\tVersion: %s%n\tPackaging: %s%n\tArtifact Directory: %s";

private static final String UNKNOWN_ARTIFACT_SIZE_UNIT_MSG =
"Unknown artifact size unit. The artifactSize property must end with either: %n\t%s: Bytes%n\t%s: KiloBytes%n\t%s: MegaBytes";

Choose a reason for hiding this comment

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

✏️ I think we should tell the user they must end in the constants we're actually checking for here https://github.com/codice/ddf-support/pull/54/files#diff-d4e3d19b536f36abc3f7081665cc04d6R236

Copy link
Member Author

Choose a reason for hiding this comment

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

We do. It was just being oddly constructed before; I've simplified it.

- also restructures support-maven module to more easily enable future additions
@coyotesqrl
Copy link
Member Author

build now

@cxbot
Copy link
Collaborator

cxbot commented Sep 24, 2018

Internal build has been scheduled, your results will be available at build completion.

@cxbot
Copy link
Collaborator

cxbot commented Sep 24, 2018

Refer to this link for build results (access rights to CI server needed):
https://jenkins.codice.org/job/DDF-Support-Jobs/job/pr/job/Linux/10/
✅ JOB SUCCESS

@coyotesqrl coyotesqrl merged commit 0e22fd6 into codice:master Sep 24, 2018
@coyotesqrl coyotesqrl deleted the artifact_size branch September 24, 2018 17:02
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.

None yet

6 participants