/** * Print out an array as a String */ public static String arrayToString(Object[] array) { return arrayToString(array, ','); }
/** * Test if #toCheck matches one of the allowedValues and throw a BadArgumentException * if not. In this case the attribute name is passed in the exception * * * @param attributeName Name of the Attribute in error * @param toCheck Value to check for * @param allowedValues Allowed values * @throws BadArgumentException if the values to check does not match any of the allowed values */ private void checkForAllowedValues(String attributeName, String toCheck, String... allowedValues) { if (toCheck==null) { throw new BadArgumentException("Field " + attributeName + " must be set. Allowed values are: " + StringUtil.arrayToString(allowedValues)); } if (allowedValues==null) { throw new IllegalArgumentException("No allowed values are provided - please contact support"); } boolean match = false; for (String value : allowedValues) { if (toCheck.equals(value)) match=true; } if (!match) { throw new BadArgumentException("Field " + attributeName + " has an invalid value [" + toCheck + "]. Allowed values are: " + StringUtil.arrayToString(allowedValues)); } }
private String getVersion(File homeDir, JBossProductType productType) { // Products should have a version.txt file at root dir File versionFile = new File(homeDir, "version.txt"); String version = getProductVersionInFile(versionFile, " - Version ", productType); if (version == null && productType != JBossProductType.AS && productType != JBossProductType.WILDFLY8) { // No version.txt file. Try modules/system/layers/base/org/jboss/as/product/slot/dir/META-INF/MANIFEST.MF String layeredProductManifestFilePath = arrayToString( new String[] { "modules", "system", "layers", "base", "org", "jboss", "as", "product", productType.SHORT_NAME.toLowerCase(), "dir", "META-INF", "MANIFEST.MF" }, File.separatorChar); File productManifest = new File(homeDir, layeredProductManifestFilePath); version = getProductVersionInFile(productManifest, "JBoss-Product-Release-Version: ", productType); if (version == null) { // Try modules/org/jboss/as/product/slot/dir/META-INF/MANIFEST.MF String productManifestFilePath = arrayToString(new String[] { "modules", "org", "jboss", "as", "product", productType.SHORT_NAME.toLowerCase(), "dir", "META-INF", "MANIFEST.MF" }, File.separatorChar); productManifest = new File(homeDir, productManifestFilePath); version = getProductVersionInFile(productManifest, "JBoss-Product-Release-Version: ", productType); } } if (version == null) { // Fallback version = determineServerVersionFromHomeDir(homeDir); } return version; }