<name>PF4J</name>
<description>Plugin Framework for Java</description>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <compilerArgument>-proc:none</compilerArgument>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerArgument>-proc:none</compilerArgument>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
+ <dependency>
+ <groupId>com.github.zafarkhaja</groupId>
+ <artifactId>java-semver</artifactId>
+ <version>0.9.0</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
*/
package ro.fortsoft.pf4j;
+import com.github.zafarkhaja.semver.Version;
+import com.github.zafarkhaja.semver.expr.Expression;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
/**
* The system version used for comparisons to the plugin requires attribute.
*/
- private Version systemVersion = Version.ZERO;
+ private Version systemVersion = Version.forIntegers(0, 0, 0);
private PluginFactory pluginFactory;
private ExtensionFactory extensionFactory;
}
}
- return (version != null) ? Version.createVersion(version) : Version.ZERO;
+ return (version != null) ? Version.valueOf(version) : Version.forIntegers(0, 0, 0);
}
/**
}
protected boolean isPluginValid(PluginWrapper pluginWrapper) {
- Version requires = pluginWrapper.getDescriptor().getRequires();
+ Expression requires = pluginWrapper.getDescriptor().getRequires();
Version system = getSystemVersion();
- if (system.isZero() || system.atLeast(requires)) {
+ if (requires.interpret(system)) {
return true;
}
*/
package ro.fortsoft.pf4j;
+import com.github.zafarkhaja.semver.Version;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
if (StringUtils.isEmpty(version)) {
throw new PluginException("Plugin-Version cannot be empty");
}
- pluginDescriptor.setPluginVersion(Version.createVersion(version));
+ pluginDescriptor.setPluginVersion(Version.valueOf(version));
String provider = attrs.getValue("Plugin-Provider");
pluginDescriptor.setProvider(provider);
String requires = attrs.getValue("Plugin-Requires");
if (StringUtils.isNotEmpty(requires)) {
- pluginDescriptor.setRequires(Version.createVersion(requires));
+ pluginDescriptor.setRequires(requires);
}
return pluginDescriptor;
*/
package ro.fortsoft.pf4j;
+import com.github.zafarkhaja.semver.Version;
+
/**
* @author Decebal Suiu
*/
public class PluginDependency {
- private String pluginId;
- private Version pluginVersion;
-
- public PluginDependency(String dependency) {
- /*
- int index = dependency.indexOf(':');
- if (index == -1) {
- throw new IllegalArgumentException("Illegal dependency specifier "+ dependency);
- }
-
- this.pluginId = dependency.substring(0, index);
- this.pluginVersion = Version.createVersion(dependency.substring(index + 1));
- */
- this.pluginId = dependency;
- }
-
- public String getPluginId() {
- return pluginId;
- }
-
- public Version getPluginVersion() {
- return pluginVersion;
- }
-
- @Override
- public String toString() {
- return "PluginDependency [pluginId=" + pluginId + ", pluginVersion=" + pluginVersion + "]";
- }
+ private String pluginId;
+ private String pluginVersionSupport;
+
+ public PluginDependency(String dependency) {
+ int index = dependency.indexOf('@');
+ if (index == -1) {
+ this.pluginId = dependency;
+ } else {
+
+ this.pluginId = dependency.substring(0, index);
+ this.pluginVersionSupport = dependency.substring(index + 1);
+ }
+ }
+
+ public String getPluginId() {
+ return pluginId;
+ }
+
+ public String getPluginVersionSupport() {
+ return pluginVersionSupport;
+ }
+
+ @Override
+ public String toString() {
+ return "PluginDependency [pluginId=" + pluginId + ", pluginVersionSupport=" + pluginVersionSupport + "]";
+ }
}
*/
package ro.fortsoft.pf4j;
+import com.github.zafarkhaja.semver.Parser;
+import com.github.zafarkhaja.semver.Version;
+import static com.github.zafarkhaja.semver.expr.CompositeExpression.Helper.gte;
+import com.github.zafarkhaja.semver.expr.Expression;
+import com.github.zafarkhaja.semver.expr.ExpressionParser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
private String pluginDescription;
private String pluginClass;
private Version version;
- private Version requires;
+ private Expression requires;
private String provider;
private List<PluginDependency> dependencies;
public PluginDescriptor() {
- requires = Version.ZERO;
+ requires = gte("0.0.0"); // Any
dependencies = new ArrayList<>();
}
/**
* Returns the requires of this plugin.
*/
- public Version getRequires() {
+ public Expression getRequires() {
return requires;
}
this.provider = provider;
}
- void setRequires(Version requires) {
+ void setRequires(String requires) {
+ Parser<Expression> parser = ExpressionParser.newInstance();
+ this.requires = parser.parse(requires);
+ }
+
+ void setRequires(Expression requires) {
this.requires = requires;
}
*/
package ro.fortsoft.pf4j;
+import com.github.zafarkhaja.semver.Version;
import java.io.File;
import java.util.List;
import java.util.Set;
*/
package ro.fortsoft.pf4j;
+import com.github.zafarkhaja.semver.Version;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
if (StringUtils.isEmpty(version)) {
throw new PluginException("plugin.version cannot be empty");
}
- pluginDescriptor.setPluginVersion(Version.createVersion(version));
+ pluginDescriptor.setPluginVersion(Version.valueOf(version));
String provider = properties.getProperty("plugin.provider");
pluginDescriptor.setProvider(provider);
+++ /dev/null
-/*
- * Copyright 2012 Decebal Suiu
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
- * the License. You may obtain a copy of the License in the LICENSE file, or at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- */
-package ro.fortsoft.pf4j;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import ro.fortsoft.pf4j.util.StringUtils;
-
-/**
- * Version following semantic defined by <a href="http://semver.org/">Semantic Versioning</a> document.
- * Version identifiers have four components.
- *
- * 1. Major version. A non-negative integer.
- * 2. Minor version. A non-negative integer.
- * 3. Patch version. A non-negative integer.
- * 4. Qualifier. A text string.
- *
- * This class is immutable.
- *
- * @author Decebal Suiu
- */
-public class Version implements Comparable<Version> {
-
- public static final Version ZERO = new Version(0, 0, 0);
-
- private static final String FORMAT = "(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?";
- private static final Pattern PATTERN = Pattern.compile(FORMAT);
-
- private int major;
- private int minor;
- private int patch;
- private String separator;
- private String qualifier;
-
- public Version(int major, int minor, int patch) {
- this.major = major;
- this.minor = minor;
- this.patch = patch;
- }
-
- public Version(int major, int minor, int patch, String separator, String qualifier) {
- this.major = major;
- this.minor = minor;
- this.patch = patch;
- this.separator = separator;
- this.qualifier = qualifier;
- }
-
- public static Version createVersion(String version) {
- Matcher matcher = PATTERN.matcher(version);
- if (!matcher.matches()) {
- throw new IllegalArgumentException("'" + version + "' does not match format '" + FORMAT + "'");
- }
-
-
-
- int major = Integer.valueOf(matcher.group(1));
- int minor = Integer.valueOf(matcher.group(2));
- int patch;
- String patchMatch = matcher.group(3);
- if (StringUtils.isNotEmpty(patchMatch)) {
- patch = Integer.valueOf(patchMatch);
- } else {
- patch = 0;
- }
- String separator = matcher.group(4);
- String qualifier = matcher.group(5);
-
- return new Version(major, minor, patch, separator, "".equals(qualifier) ? null : qualifier);
- }
-
- public int getMajor() {
- return this.major;
- }
-
- public int getMinor() {
- return this.minor;
- }
-
- public int getPatch() {
- return this.patch;
- }
-
- public String getQualifier() {
- return qualifier;
- }
-
- @Override
- public String toString() {
- StringBuffer sb = new StringBuffer(50);
- sb.append(major);
- sb.append('.');
- sb.append(minor);
- sb.append('.');
- sb.append(patch);
- if (separator != null) {
- sb.append(separator);
- }
- if (qualifier != null) {
- sb.append(qualifier);
- }
-
- return sb.toString();
- }
-
- @Override
- public int compareTo(Version version) {
- if (version.major > major) {
- return 1;
- } else if (version.major < major) {
- return -1;
- }
-
- if (version.minor > minor) {
- return 1;
- } else if (version.minor < minor) {
- return -1;
- }
-
- if (version.patch > patch) {
- return 1;
- } else if (version.patch < patch) {
- return -1;
- }
-
- return 0;
- }
-
- public boolean isZero() {
- return compareTo(ZERO) == 0;
- }
-
- public boolean atLeast(Version v) {
- return compareTo(v) <= 0;
- }
-
- public boolean exceeds(Version v) {
- return compareTo(v) > 0;
- }
-
- // for test only
- public static void main(String[] args) {
- Version v = Version.createVersion("1.2.3-SNAPSHOT");
- System.out.println(v.toString());
- Version v1 = Version.createVersion("4.1.0");
- System.out.println(v1.toString());
- Version v2 = Version.createVersion("4.0.32");
- System.out.println(v2.toString());
- System.out.println(v1.compareTo(v2));
- }
-
-}