RequireRedhatCompatibleVersionRule implements EnforcerRule { public void ensureValidRedhatVersion(String version) throws EnforcerRuleException { if (version.endsWith("SNAPSHOT")) { return; } if (version.contains("-")) { throw new EnforcerRuleException("The version \"" + version + "\" does not conform to the Redhat (linux packaging) version requirements. " + "It can't have the '-' character as it has a special meaning reserved for the RPM process."); } String reserved[] = { "noarch", "nosrc", "src", "fat", "i386", "i486", "i586", "i686", "pentium", "athlon", "ia64", "x86_64", "amd64", "ia32e", "alpha", "sparc", "m68k", "ppc", "parisc", "hppa", "mips", "mipsel", "armv", "atari", "falcon", "milan", "hades", "s390", "aix", "amigaos", "bsd", "cygwin", "darwin", "freebsd", "freemint", "hp", "hpux", "irix", "linux", "machten", "macosx", "mint", "mp_ras", "nextstep", "os/390", "osf1", "osf3.2", "osf4.0", "sco_sv", "solaris", "sunos", "unix", "ux", "vm", "esa", "sun", "xtensa", "rs6000", "sgi" }; String lversion = version.toLowerCase(); for (String id : reserved) { if (lversion.contains(id)) { throw new EnforcerRuleException("The version \"" + version + "\" does not conform to the Redhat (linux packaging) version requirements. " + "It can't use the RPM reserved word \"" + id + "\"."); } } }  void execute(EnforcerRuleHelper helper); void ensureValidRedhatVersion(String version); String getCacheId(); boolean isCacheable(); boolean isResultValid(EnforcerRule rule);  }
@Test public void testValidRedhatVersions() throws EnforcerRuleException { RequireRedhatCompatibleVersionRule rule = new RequireRedhatCompatibleVersionRule(); rule.ensureValidRedhatVersion( "1.0.0" ); rule.ensureValidRedhatVersion( "7.0.2.RC0" ); }
@Test public void testSkipSnapshotRedhatVersions() throws EnforcerRuleException { RequireRedhatCompatibleVersionRule rule = new RequireRedhatCompatibleVersionRule(); rule.ensureValidRedhatVersion( "1.0.0-SNAPSHOT" ); rule.ensureValidRedhatVersion( "7.0.2.SNAPSHOT" ); }
@Test public void testBadRedhatVersionDash() throws EnforcerRuleException { Assertions.assertThrows( EnforcerRuleException.class, () -> { RequireRedhatCompatibleVersionRule rule = new RequireRedhatCompatibleVersionRule(); rule.ensureValidRedhatVersion( "7.0.2-RC0" ); } ); }
@Test public void testBadRedhatVersionReservedAlpha() throws EnforcerRuleException { Assertions.assertThrows( EnforcerRuleException.class, () -> { RequireRedhatCompatibleVersionRule rule = new RequireRedhatCompatibleVersionRule(); rule.ensureValidRedhatVersion( "7.1.0.alpha3" ); } ); }