* @throws PluginException if validation fails
*/
protected void validatePluginDescriptor(PluginDescriptor descriptor) throws PluginException {
- if (StringUtils.isEmpty(descriptor.getPluginId())) {
+ if (StringUtils.isNullOrEmpty(descriptor.getPluginId())) {
throw new PluginException("Field 'id' cannot be empty");
}
- if (StringUtils.isEmpty(descriptor.getPluginClass())) {
+ if (StringUtils.isNullOrEmpty(descriptor.getPluginClass())) {
throw new PluginException("Field 'class' cannot be empty");
}
pluginDescriptor.setPluginId(id);
String description = attributes.getValue("Plugin-Description");
- if (StringUtils.isEmpty(description)) {
+ if (StringUtils.isNullOrEmpty(description)) {
pluginDescriptor.setPluginDescription("");
} else {
pluginDescriptor.setPluginDescription(description);
pluginDescriptor.setPluginClass(clazz);
String version = attributes.getValue("Plugin-Version");
- if (StringUtils.isNotEmpty(version)) {
+ if (StringUtils.isNotNullOrEmpty(version)) {
pluginDescriptor.setPluginVersion(version);
}
pluginDescriptor.setDependencies(dependencies);
String requires = attributes.getValue("Plugin-Requires");
- if (StringUtils.isNotEmpty(requires)) {
+ if (StringUtils.isNotNullOrEmpty(requires)) {
pluginDescriptor.setRequires(requires);
}
pluginDescriptor.setPluginId(id);
String description = properties.getProperty("plugin.description");
- if (StringUtils.isEmpty(description)) {
+ if (StringUtils.isNullOrEmpty(description)) {
pluginDescriptor.setPluginDescription("");
} else {
pluginDescriptor.setPluginDescription(description);
pluginDescriptor.setPluginClass(clazz);
String version = properties.getProperty("plugin.version");
- if (StringUtils.isNotEmpty(version)) {
+ if (StringUtils.isNotNullOrEmpty(version)) {
pluginDescriptor.setPluginVersion(version);
}
pluginDescriptor.setDependencies(dependencies);
String requires = properties.getProperty("plugin.requires");
- if (StringUtils.isNotEmpty(requires)) {
+ if (StringUtils.isNotNullOrEmpty(requires)) {
pluginDescriptor.setRequires(requires);
}
*/
public class FileUtils {
- private static final String SLASH = "/";
private static final Logger log = LoggerFactory.getLogger(FileUtils.class);
public static List<String> readLines(Path path, boolean ignoreComments) throws IOException {
public static Path getPath(Path path, String first, String... more) throws IOException {
URI uri = path.toUri();
if (isJarFile(path)) {
- String pathString = path.toString().replace("\\", SLASH);
- if(!pathString.startsWith(SLASH)){
- pathString = SLASH + pathString;
- }
+ String pathString = path.toString();
+ // transformation for Windows OS
+ pathString = StringUtils.addStart(pathString.replace("\\", "/"), "/");
uri = URI.create("jar:file:" + pathString);
}
*/
public class StringUtils {
- public static boolean isEmpty(String str) {
+ public static boolean isNullOrEmpty(String str) {
return (str == null) || str.isEmpty();
}
- public static boolean isNotEmpty(String str) {
- return !isEmpty(str);
+ public static boolean isNotNullOrEmpty(String str) {
+ return !isNullOrEmpty(str);
}
/**
return String.format(str, args);
}
+ /**
+ * <p>Adds a substring only if the source string does not already start with the substring,
+ * otherwise returns the source string.</p>
+ * <p/>
+ * <p>A {@code null} source string will return {@code null}.
+ * An empty ("") source string will return the empty string.
+ * A {@code null} search string will return the source string.</p>
+ * <p/>
+ * <pre>
+ * StringUtils.addStart(null, *) = *
+ * StringUtils.addStart("", *) = *
+ * StringUtils.addStart(*, null) = *
+ * StringUtils.addStart("domain.com", "www.") = "www.domain.com"
+ * StringUtils.addStart("abc123", "abc") = "abc123"
+ * </pre>
+ *
+ * @param str the source String to search, may be null
+ * @param add the String to search for and add, may be null
+ * @return the substring with the string added if required
+ */
+ public static String addStart(String str, String add) {
+ if (isNullOrEmpty(add)) {
+ return str;
+ }
+
+ if (isNullOrEmpty(str)) {
+ return add;
+ }
+
+ if (!str.startsWith(add)) {
+ return add + str;
+ }
+
+ return str;
+ }
+
}