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. 17
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java
  5. 39
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java

6
demo/app/pom.xml

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

6
pf4j/pom.xml

@ -30,12 +30,6 @@
</scm>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>net.java.sezpoz</groupId>
<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.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();
}
}

17
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.
@ -87,13 +83,10 @@ 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();
return "PluginDescriptor [pluginId=" + pluginId + ", pluginClass="
+ pluginClass + ", version=" + version + ", provider="
+ provider + ", dependencies=" + dependencies
+ ", pluginClassLoader=" + pluginClassLoader + "]";
}
void setPluginId(String pluginId) {
@ -115,7 +108,7 @@ public class PluginDescriptor {
void setDependencies(String dependencies) {
if (dependencies != null) {
this.dependencies = new ArrayList<PluginDependency>();
List<String> tokens = Arrays.asList(StringUtils.split(dependencies, ','));
List<String> tokens = Arrays.asList(dependencies.split(","));
for (String dependency : tokens) {
this.dependencies.add(new PluginDependency(dependency));
}

39
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
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();
return "PluginWrapper [descriptor=" + descriptor + ", pluginPath="
+ pluginPath + "]";
}
}

Loading…
Cancel
Save