From 1a14c975a69d348b0c6deacbc9bbf73f9cb605fe Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Tue, 13 Nov 2012 11:38:31 +0200 Subject: [PATCH] remove commons-lang dependency --- demo/app/pom.xml | 6 +++ pf4j/pom.xml | 6 --- .../pf4j/DefaultPluginDescriptorFinder.java | 11 ++--- .../ro/fortsoft/pf4j/PluginDescriptor.java | 23 ++++------ .../java/ro/fortsoft/pf4j/PluginWrapper.java | 45 ++++++++++--------- 5 files changed, 45 insertions(+), 46 deletions(-) diff --git a/demo/app/pom.xml b/demo/app/pom.xml index be35260..18383a2 100644 --- a/demo/app/pom.xml +++ b/demo/app/pom.xml @@ -105,6 +105,12 @@ slf4j-log4j12 ${slf4j.version} + + + commons-lang + commons-lang + 2.4 + diff --git a/pf4j/pom.xml b/pf4j/pom.xml index 301ea44..7bace35 100644 --- a/pf4j/pom.xml +++ b/pf4j/pom.xml @@ -30,12 +30,6 @@ - - commons-lang - commons-lang - 2.4 - - net.java.sezpoz sezpoz diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java index fa86e2e..3cb6712 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java @@ -19,8 +19,6 @@ import java.io.IOException; import java.util.jar.Attributes; import java.util.jar.Manifest; -import org.apache.commons.lang.StringUtils; - /** * Read the plugin descriptor from the manifest file. * @@ -62,19 +60,19 @@ public class DefaultPluginDescriptorFinder implements PluginDescriptorFinder { // TODO validate !!! Attributes attrs = manifest.getMainAttributes(); String id = attrs.getValue("Plugin-Id"); - if (StringUtils.isEmpty(id)) { + if (isEmpty(id)) { throw new PluginException("Plugin-Id cannot be empty"); } pluginDescriptor.setPluginId(id); String clazz = attrs.getValue("Plugin-Class"); - if (StringUtils.isEmpty(clazz)) { + if (isEmpty(clazz)) { throw new PluginException("Plugin-Class cannot be empty"); } pluginDescriptor.setPluginClass(clazz); String version = attrs.getValue("Plugin-Version"); - if (StringUtils.isEmpty(version)) { + if (isEmpty(version)) { throw new PluginException("Plugin-Version cannot be empty"); } pluginDescriptor.setPluginVersion(PluginVersion.createVersion(version)); @@ -87,4 +85,7 @@ public class DefaultPluginDescriptorFinder implements PluginDescriptorFinder { return pluginDescriptor; } + private boolean isEmpty(String value) { + return (value != null) && !value.isEmpty(); + } } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java index a666b7a..aba2fac 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java @@ -17,10 +17,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * A plugin descriptor contains information about a plug-in obtained * from the manifest (META-INF) file. @@ -86,17 +82,14 @@ public class PluginDescriptor { } @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("pluginId", pluginId) - .append("pluginClass", pluginClass) - .append("version", version) - .append("provider", provider) - .append("dependencies", dependencies) - .toString(); - } + public String toString() { + return "PluginDescriptor [pluginId=" + pluginId + ", pluginClass=" + + pluginClass + ", version=" + version + ", provider=" + + provider + ", dependencies=" + dependencies + + ", pluginClassLoader=" + pluginClassLoader + "]"; + } - void setPluginId(String pluginId) { + void setPluginId(String pluginId) { this.pluginId = pluginId; } @@ -115,7 +108,7 @@ public class PluginDescriptor { void setDependencies(String dependencies) { if (dependencies != null) { this.dependencies = new ArrayList(); - List tokens = Arrays.asList(StringUtils.split(dependencies, ',')); + List tokens = Arrays.asList(dependencies.split(",")); for (String dependency : tokens) { this.dependencies.add(new PluginDependency(dependency)); } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java index b3a5a01..c960ec1 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java @@ -15,11 +15,6 @@ package ro.fortsoft.pf4j; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * A wrapper over plugin instance. * @@ -41,7 +36,6 @@ public class PluginWrapper { try { plugin = createPluginInstance(); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -92,31 +86,42 @@ public class PluginWrapper { return plugin; } - @Override + + @Override public int hashCode() { - return new HashCodeBuilder().append(descriptor.getPluginId()) - .toHashCode(); + final int prime = 31; + int result = 1; + result = prime * result + descriptor.getPluginId().hashCode(); + + return result; } @Override public boolean equals(Object obj) { - if (!(obj instanceof PluginWrapper)) { + if (this == obj) { + return true; + } + + if (obj == null) { return false; } - PluginWrapper wrapper = (PluginWrapper) obj; + if (getClass() != obj.getClass()) { + return false; + } + + PluginWrapper other = (PluginWrapper) obj; + if (!descriptor.getPluginId().equals(other.descriptor.getPluginId())) { + return false; + } - return new EqualsBuilder().append(descriptor.getPluginId(), wrapper.getDescriptor().getPluginId()) - .isEquals(); + return true; } @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("descriptor", descriptor) - .append("pluginPath", pluginPath) - .append("plugin", plugin) - .toString(); - } + public String toString() { + return "PluginWrapper [descriptor=" + descriptor + ", pluginPath=" + + pluginPath + "]"; + } } -- 2.39.5