RequireDebianCompatibleVersionRule implements EnforcerRule { public void ensureValidDebianVersion(String version) throws EnforcerRuleException { if (version.endsWith("SNAPSHOT")) { return; } if (version.contains("-")) { throw new EnforcerRuleException("The version \"" + version + "\" does not conform to the Debian (linux packaging) version requirements. " + "It can't have the '-' character as it has a special meaning reserved for the DEB process (package build #)."); } if (version.contains("_")) { throw new EnforcerRuleException("The version \"" + version + "\" does not conform to the Debian (linux packaging) version requirements. " + "It can't have the '_' character as it has a special meaning reserved for the DEB process " + "(indicates split between package name, version, and architecture on filename)."); } String reserved[] = { "all", "i386", "i486", "i586", "i686", "pentium", "athlon", "ia64", "x86_64", "amd64", "ia32", "alpha", "sparc", "m68k", "ppc", "hppa", "arm" }; String lversion = version.toLowerCase(); for (String id : reserved) { if (lversion.contains(id)) { throw new EnforcerRuleException("The version \"" + version + "\" does not conform to the Debian (linux packaging) version requirements. " + "It can't use the DEB reserved word \"" + id + "\"."); } } }  void execute(EnforcerRuleHelper helper); void ensureValidDebianVersion(String version); String getCacheId(); boolean isCacheable(); boolean isResultValid(EnforcerRule rule);  }
@Test public void testGoodDebianVersions() throws EnforcerRuleException { RequireDebianCompatibleVersionRule rule = new RequireDebianCompatibleVersionRule(); rule.ensureValidDebianVersion( "1.0.0" ); rule.ensureValidDebianVersion( "7.0.2.RC0" ); }
@Test public void testSkippedSnapshotDebianVersions() throws EnforcerRuleException { RequireDebianCompatibleVersionRule rule = new RequireDebianCompatibleVersionRule(); rule.ensureValidDebianVersion( "1.0.0-SNAPSHOT" ); rule.ensureValidDebianVersion( "7.0.2.SNAPSHOT" ); }
@Test public void testBadDebianVersionDash() throws EnforcerRuleException { Assertions.assertThrows( EnforcerRuleException.class, () -> { RequireDebianCompatibleVersionRule rule = new RequireDebianCompatibleVersionRule(); rule.ensureValidDebianVersion( "7.0.2-RC0" ); } ); }
@Test public void testBadDebianVersionUnderscore() throws EnforcerRuleException { Assertions.assertThrows( EnforcerRuleException.class, () -> { RequireDebianCompatibleVersionRule rule = new RequireDebianCompatibleVersionRule(); rule.ensureValidDebianVersion( "7.0.2_RC0" ); } ); }
@Test public void testBadDebianVersionReservedAlpha() throws EnforcerRuleException { Assertions.assertThrows( EnforcerRuleException.class, () -> { RequireDebianCompatibleVersionRule rule = new RequireDebianCompatibleVersionRule(); rule.ensureValidDebianVersion( "7.0.2.alpha3" ); } ); }