@Test public void successfullyDiscoverArtifact() throws IOException { tempFolder.newFile(SAMPLE_ARTIFACT_FILE_NAME); ArtifactSizeEnforcerRule enforcer = new ArtifactSizeEnforcerRule(); try { enforcer.execute(defaultMockhelper); } catch (EnforcerRuleException e) { fail("Failed to discover artifact."); } }
@Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (skip) { return; } String packaging = getPackaging(helper); if (!SUPPORTED_PACKAGE_TYPES.contains(packaging)) { helper .getLog() .info( String.format( "Unsupported package type %s. Skipping artifact size enforcement.", packaging)); return; } String artifactPath = getArtifactPath(helper); long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper); long artifactSize = getArtifact(artifactPath).length(); if (artifactSize >= maxArtifactSizeBytes) { throw new EnforcerRuleException( String.format( MAX_FILE_SIZE_EXCEEDED_MSG, artifactPath, artifactSize, maxArtifactSizeBytes)); } }
ArtifactSizeEnforcerRule implements EnforcerRule { @Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (skip) { return; } String packaging = getPackaging(helper); if (!SUPPORTED_PACKAGE_TYPES.contains(packaging)) { helper .getLog() .info( String.format( "Unsupported package type %s. Skipping artifact size enforcement.", packaging)); return; } String artifactPath = getArtifactPath(helper); long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper); long artifactSize = getArtifact(artifactPath).length(); if (artifactSize >= maxArtifactSizeBytes) { throw new EnforcerRuleException( String.format( MAX_FILE_SIZE_EXCEEDED_MSG, artifactPath, artifactSize, maxArtifactSizeBytes)); } } }
ArtifactSizeEnforcerRule implements EnforcerRule { @Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (skip) { return; } String packaging = getPackaging(helper); if (!SUPPORTED_PACKAGE_TYPES.contains(packaging)) { helper .getLog() .info( String.format( "Unsupported package type %s. Skipping artifact size enforcement.", packaging)); return; } String artifactPath = getArtifactPath(helper); long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper); long artifactSize = getArtifact(artifactPath).length(); if (artifactSize >= maxArtifactSizeBytes) { throw new EnforcerRuleException( String.format( MAX_FILE_SIZE_EXCEEDED_MSG, artifactPath, artifactSize, maxArtifactSizeBytes)); } }  }
ArtifactSizeEnforcerRule implements EnforcerRule { @Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (skip) { return; } String packaging = getPackaging(helper); if (!SUPPORTED_PACKAGE_TYPES.contains(packaging)) { helper .getLog() .info( String.format( "Unsupported package type %s. Skipping artifact size enforcement.", packaging)); return; } String artifactPath = getArtifactPath(helper); long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper); long artifactSize = getArtifact(artifactPath).length(); if (artifactSize >= maxArtifactSizeBytes) { throw new EnforcerRuleException( String.format( MAX_FILE_SIZE_EXCEEDED_MSG, artifactPath, artifactSize, maxArtifactSizeBytes)); } }  @Override void execute(EnforcerRuleHelper helper); @Override boolean isCacheable(); @Override boolean isResultValid(EnforcerRule enforcerRule); @Override String getCacheId(); ArtifactSizeEnforcerRule setMaxArtifactSize(String maxArtifactSize); ArtifactSizeEnforcerRule setArtifactLocation(String artifactLocation); }
ArtifactSizeEnforcerRule implements EnforcerRule { @Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (skip) { return; } String packaging = getPackaging(helper); if (!SUPPORTED_PACKAGE_TYPES.contains(packaging)) { helper .getLog() .info( String.format( "Unsupported package type %s. Skipping artifact size enforcement.", packaging)); return; } String artifactPath = getArtifactPath(helper); long maxArtifactSizeBytes = maxArtifactSizeToBytes(helper); long artifactSize = getArtifact(artifactPath).length(); if (artifactSize >= maxArtifactSizeBytes) { throw new EnforcerRuleException( String.format( MAX_FILE_SIZE_EXCEEDED_MSG, artifactPath, artifactSize, maxArtifactSizeBytes)); } }  @Override void execute(EnforcerRuleHelper helper); @Override boolean isCacheable(); @Override boolean isResultValid(EnforcerRule enforcerRule); @Override String getCacheId(); ArtifactSizeEnforcerRule setMaxArtifactSize(String maxArtifactSize); ArtifactSizeEnforcerRule setArtifactLocation(String artifactLocation); static final String PROJECT_PACKAGING_PROP; static final String PROJECT_ARTIFACT_ID_PROP; static final String PROJECT_VERSION_PROP; static final String PROJECT_BUILD_DIR_PROP; static final String DEFAULT_MAX_ARTIFACT_SIZE; static final String BYTES; static final String MEGA_BYTES; static final String KILO_BYTES; static final String JAR; static final String BUNDLE; static final List<String> SUPPORTED_PACKAGE_TYPES; static final String MAX_FILE_SIZE_EXCEEDED_MSG; static final String DEFAULT_ARTIFACT_INFO_MSG; static final String UNKNOWN_ARTIFACT_SIZE_UNIT_MSG; }