Browse Source

remove commons-lang dependency

pull/3/head
Decebal Suiu 12 years ago
parent
commit
1a14c975a6
  1. 6
      demo/app/pom.xml
  2. 6
      pf4j/pom.xml
  3. 11
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java
  4. 23
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java
  5. 45
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java

6
demo/app/pom.xml

@ -105,6 +105,12 @@
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version> <version>${slf4j.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

6
pf4j/pom.xml

@ -30,12 +30,6 @@
</scm> </scm>
<dependencies> <dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency> <dependency>
<groupId>net.java.sezpoz</groupId> <groupId>net.java.sezpoz</groupId>
<artifactId>sezpoz</artifactId> <artifactId>sezpoz</artifactId>

11
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.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.apache.commons.lang.StringUtils;
/** /**
* Read the plugin descriptor from the manifest file. * Read the plugin descriptor from the manifest file.
* *
@ -62,19 +60,19 @@ public class DefaultPluginDescriptorFinder implements PluginDescriptorFinder {
// TODO validate !!! // TODO validate !!!
Attributes attrs = manifest.getMainAttributes(); Attributes attrs = manifest.getMainAttributes();
String id = attrs.getValue("Plugin-Id"); String id = attrs.getValue("Plugin-Id");
if (StringUtils.isEmpty(id)) { if (isEmpty(id)) {
throw new PluginException("Plugin-Id cannot be empty"); throw new PluginException("Plugin-Id cannot be empty");
} }
pluginDescriptor.setPluginId(id); pluginDescriptor.setPluginId(id);
String clazz = attrs.getValue("Plugin-Class"); String clazz = attrs.getValue("Plugin-Class");
if (StringUtils.isEmpty(clazz)) { if (isEmpty(clazz)) {
throw new PluginException("Plugin-Class cannot be empty"); throw new PluginException("Plugin-Class cannot be empty");
} }
pluginDescriptor.setPluginClass(clazz); pluginDescriptor.setPluginClass(clazz);
String version = attrs.getValue("Plugin-Version"); String version = attrs.getValue("Plugin-Version");
if (StringUtils.isEmpty(version)) { if (isEmpty(version)) {
throw new PluginException("Plugin-Version cannot be empty"); throw new PluginException("Plugin-Version cannot be empty");
} }
pluginDescriptor.setPluginVersion(PluginVersion.createVersion(version)); pluginDescriptor.setPluginVersion(PluginVersion.createVersion(version));
@ -87,4 +85,7 @@ public class DefaultPluginDescriptorFinder implements PluginDescriptorFinder {
return pluginDescriptor; return pluginDescriptor;
} }
private boolean isEmpty(String value) {
return (value != null) && !value.isEmpty();
}
} }

23
pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java

@ -17,10 +17,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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 * A plugin descriptor contains information about a plug-in obtained
* from the manifest (META-INF) file. * from the manifest (META-INF) file.
@ -86,17 +82,14 @@ public class PluginDescriptor {
} }
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return "PluginDescriptor [pluginId=" + pluginId + ", pluginClass="
.append("pluginId", pluginId) + pluginClass + ", version=" + version + ", provider="
.append("pluginClass", pluginClass) + provider + ", dependencies=" + dependencies
.append("version", version) + ", pluginClassLoader=" + pluginClassLoader + "]";
.append("provider", provider) }
.append("dependencies", dependencies)
.toString();
}
void setPluginId(String pluginId) { void setPluginId(String pluginId) {
this.pluginId = pluginId; this.pluginId = pluginId;
} }
@ -115,7 +108,7 @@ public class PluginDescriptor {
void setDependencies(String dependencies) { void setDependencies(String dependencies) {
if (dependencies != null) { if (dependencies != null) {
this.dependencies = new ArrayList<PluginDependency>(); this.dependencies = new ArrayList<PluginDependency>();
List<String> tokens = Arrays.asList(StringUtils.split(dependencies, ',')); List<String> tokens = Arrays.asList(dependencies.split(","));
for (String dependency : tokens) { for (String dependency : tokens) {
this.dependencies.add(new PluginDependency(dependency)); this.dependencies.add(new PluginDependency(dependency));
} }

45
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.Constructor;
import java.lang.reflect.Modifier; 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. * A wrapper over plugin instance.
* *
@ -41,7 +36,6 @@ public class PluginWrapper {
try { try {
plugin = createPluginInstance(); plugin = createPluginInstance();
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -92,31 +86,42 @@ public class PluginWrapper {
return plugin; return plugin;
} }
@Override
@Override
public int hashCode() { public int hashCode() {
return new HashCodeBuilder().append(descriptor.getPluginId()) final int prime = 31;
.toHashCode(); int result = 1;
result = prime * result + descriptor.getPluginId().hashCode();
return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof PluginWrapper)) { if (this == obj) {
return true;
}
if (obj == null) {
return false; 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()) return true;
.isEquals();
} }
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return "PluginWrapper [descriptor=" + descriptor + ", pluginPath="
.append("descriptor", descriptor) + pluginPath + "]";
.append("pluginPath", pluginPath) }
.append("plugin", plugin)
.toString();
}
} }

Loading…
Cancel
Save