Browse Source

rename PluginVersion to Version

pull/22/head
Decebal Suiu 11 years ago
parent
commit
eb24fa2b32
  1. 10
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  2. 4
      pf4j/src/main/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinder.java
  3. 18
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginDependency.java
  4. 14
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java
  5. 4
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java
  6. 34
      pf4j/src/main/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinder.java
  7. 25
      pf4j/src/main/java/ro/fortsoft/pf4j/Version.java

10
pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java

@ -92,7 +92,7 @@ public class DefaultPluginManager implements PluginManager {
/** /**
* The system version used for comparisons to the plugin requires attribute. * The system version used for comparisons to the plugin requires attribute.
*/ */
private PluginVersion systemVersion = PluginVersion.ZERO; private Version systemVersion = Version.ZERO;
/** /**
* The plugins directory is supplied by System.getProperty("pf4j.pluginsDir", "plugins"). * The plugins directory is supplied by System.getProperty("pf4j.pluginsDir", "plugins").
@ -116,12 +116,12 @@ public class DefaultPluginManager implements PluginManager {
} }
@Override @Override
public void setSystemVersion(PluginVersion version) { public void setSystemVersion(Version version) {
systemVersion = version; systemVersion = version;
} }
@Override @Override
public PluginVersion getSystemVersion() { public Version getSystemVersion() {
return systemVersion; return systemVersion;
} }
@ -657,8 +657,8 @@ public class DefaultPluginManager implements PluginManager {
} }
protected boolean isPluginValid(PluginWrapper pluginWrapper) { protected boolean isPluginValid(PluginWrapper pluginWrapper) {
PluginVersion requires = pluginWrapper.getDescriptor().getRequires(); Version requires = pluginWrapper.getDescriptor().getRequires();
PluginVersion system = getSystemVersion(); Version system = getSystemVersion();
if (system.isZero() || system.atLeast(requires)) { if (system.isZero() || system.atLeast(requires)) {
return true; return true;
} }

4
pf4j/src/main/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinder.java

@ -96,7 +96,7 @@ public class ManifestPluginDescriptorFinder implements PluginDescriptorFinder {
if (StringUtils.isEmpty(version)) { if (StringUtils.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(Version.createVersion(version));
String provider = attrs.getValue("Plugin-Provider"); String provider = attrs.getValue("Plugin-Provider");
pluginDescriptor.setProvider(provider); pluginDescriptor.setProvider(provider);
@ -105,7 +105,7 @@ public class ManifestPluginDescriptorFinder implements PluginDescriptorFinder {
String requires = attrs.getValue("Plugin-Requires"); String requires = attrs.getValue("Plugin-Requires");
if (StringUtils.isNotEmpty(requires)) { if (StringUtils.isNotEmpty(requires)) {
pluginDescriptor.setRequires(PluginVersion.createVersion(requires)); pluginDescriptor.setRequires(Version.createVersion(requires));
} }
return pluginDescriptor; return pluginDescriptor;

18
pf4j/src/main/java/ro/fortsoft/pf4j/PluginDependency.java

@ -1,11 +1,11 @@
/* /*
* Copyright 2012 Decebal Suiu * Copyright 2012 Decebal Suiu
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * 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: * the License. You may obtain a copy of the License in the LICENSE file, or at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * specific language governing permissions and limitations under the License.
@ -18,17 +18,17 @@ package ro.fortsoft.pf4j;
public class PluginDependency { public class PluginDependency {
private String pluginId; private String pluginId;
private PluginVersion pluginVersion; private Version pluginVersion;
public PluginDependency(String dependency) { public PluginDependency(String dependency) {
/* /*
int index = dependency.indexOf(':'); int index = dependency.indexOf(':');
if (index == -1) { if (index == -1) {
throw new IllegalArgumentException("Illegal dependency specifier "+ dependency); throw new IllegalArgumentException("Illegal dependency specifier "+ dependency);
} }
this.pluginId = dependency.substring(0, index); this.pluginId = dependency.substring(0, index);
this.pluginVersion = PluginVersion.createVersion(dependency.substring(index + 1)); this.pluginVersion = Version.createVersion(dependency.substring(index + 1));
*/ */
this.pluginId = dependency; this.pluginId = dependency;
} }
@ -37,7 +37,7 @@ public class PluginDependency {
return pluginId; return pluginId;
} }
public PluginVersion getPluginVersion() { public Version getPluginVersion() {
return pluginVersion; return pluginVersion;
} }
@ -45,5 +45,5 @@ public class PluginDependency {
public String toString() { public String toString() {
return "PluginDependency [pluginId=" + pluginId + ", pluginVersion=" + pluginVersion + "]"; return "PluginDependency [pluginId=" + pluginId + ", pluginVersion=" + pluginVersion + "]";
} }
} }

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

@ -27,13 +27,13 @@ public class PluginDescriptor {
private String pluginId; private String pluginId;
private String pluginDescription; private String pluginDescription;
private String pluginClass; private String pluginClass;
private PluginVersion version; private Version version;
private PluginVersion requires; private Version requires;
private String provider; private String provider;
private List<PluginDependency> dependencies; private List<PluginDependency> dependencies;
public PluginDescriptor() { public PluginDescriptor() {
requires = PluginVersion.ZERO; requires = Version.ZERO;
dependencies = new ArrayList<PluginDependency>(); dependencies = new ArrayList<PluginDependency>();
} }
@ -61,14 +61,14 @@ public class PluginDescriptor {
/** /**
* Returns the version of this plugin. * Returns the version of this plugin.
*/ */
public PluginVersion getVersion() { public Version getVersion() {
return version; return version;
} }
/** /**
* Returns the requires of this plugin. * Returns the requires of this plugin.
*/ */
public PluginVersion getRequires() { public Version getRequires() {
return requires; return requires;
} }
@ -107,7 +107,7 @@ public class PluginDescriptor {
this.pluginClass = pluginClassName; this.pluginClass = pluginClassName;
} }
void setPluginVersion(PluginVersion version) { void setPluginVersion(Version version) {
this.version = version; this.version = version;
} }
@ -115,7 +115,7 @@ public class PluginDescriptor {
this.provider = provider; this.provider = provider;
} }
void setRequires(PluginVersion requires) { void setRequires(Version requires) {
this.requires = requires; this.requires = requires;
} }

4
pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java

@ -149,12 +149,12 @@ public interface PluginManager {
* @default 0.0.0 * @default 0.0.0
* @param version * @param version
*/ */
public void setSystemVersion(PluginVersion version); public void setSystemVersion(Version version);
/** /**
* Returns the system version. * Returns the system version.
* *
* * @return the system version * * @return the system version
*/ */
public PluginVersion getSystemVersion(); public Version getSystemVersion();
} }

34
pf4j/src/main/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinder.java

@ -1,11 +1,11 @@
/* /*
* Copyright 2012 Decebal Suiu * Copyright 2012 Decebal Suiu
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * 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: * the License. You may obtain a copy of the License in the LICENSE file, or at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * specific language governing permissions and limitations under the License.
@ -26,15 +26,15 @@ import ro.fortsoft.pf4j.util.StringUtils;
/** /**
* Find a plugin descriptor in a properties file (in plugin repository). * Find a plugin descriptor in a properties file (in plugin repository).
* *
* @author Decebal Suiu * @author Decebal Suiu
*/ */
public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder { public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder {
private static final Logger log = LoggerFactory.getLogger(PropertiesPluginDescriptorFinder.class); private static final Logger log = LoggerFactory.getLogger(PropertiesPluginDescriptorFinder.class);
private static final String DEFAULT_PROPERTIES_FILE_NAME = "plugin.properties"; private static final String DEFAULT_PROPERTIES_FILE_NAME = "plugin.properties";
private String propertiesFileName; private String propertiesFileName;
public PropertiesPluginDescriptorFinder() { public PropertiesPluginDescriptorFinder() {
@ -44,7 +44,7 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder
public PropertiesPluginDescriptorFinder(String propertiesFileName) { public PropertiesPluginDescriptorFinder(String propertiesFileName) {
this.propertiesFileName = propertiesFileName; this.propertiesFileName = propertiesFileName;
} }
@Override @Override
public PluginDescriptor find(File pluginRepository) throws PluginException { public PluginDescriptor find(File pluginRepository) throws PluginException {
File propertiesFile = new File(pluginRepository, propertiesFileName); File propertiesFile = new File(pluginRepository, propertiesFileName);
@ -57,9 +57,9 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder
try { try {
input = new FileInputStream(propertiesFile); input = new FileInputStream(propertiesFile);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// not happening // not happening
} }
Properties properties = new Properties(); Properties properties = new Properties();
try { try {
properties.load(input); properties.load(input);
@ -71,31 +71,31 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder
} catch (IOException e) { } catch (IOException e) {
throw new PluginException(e.getMessage(), e); throw new PluginException(e.getMessage(), e);
} }
} }
PluginDescriptor pluginDescriptor = new PluginDescriptor(); PluginDescriptor pluginDescriptor = new PluginDescriptor();
// TODO validate !!! // TODO validate !!!
String id = properties.getProperty("plugin.id"); String id = properties.getProperty("plugin.id");
if (StringUtils.isEmpty(id)) { if (StringUtils.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 = properties.getProperty("plugin.class"); String clazz = properties.getProperty("plugin.class");
if (StringUtils.isEmpty(clazz)) { if (StringUtils.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 = properties.getProperty("plugin.version"); String version = properties.getProperty("plugin.version");
if (StringUtils.isEmpty(version)) { if (StringUtils.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(Version.createVersion(version));
String provider = properties.getProperty("plugin.provider"); String provider = properties.getProperty("plugin.provider");
pluginDescriptor.setProvider(provider); pluginDescriptor.setProvider(provider);
String dependencies = properties.getProperty("plugin.dependencies"); String dependencies = properties.getProperty("plugin.dependencies");
pluginDescriptor.setDependencies(dependencies); pluginDescriptor.setDependencies(dependencies);

25
pf4j/src/main/java/ro/fortsoft/pf4j/PluginVersion.java → pf4j/src/main/java/ro/fortsoft/pf4j/Version.java

@ -18,7 +18,6 @@ import java.util.regex.Pattern;
import ro.fortsoft.pf4j.util.StringUtils; import ro.fortsoft.pf4j.util.StringUtils;
/** /**
* Represents the version of a Plugin and allows versions to be compared.
* Version following semantic defined by <a href="http://semver.org/">Semantic Versioning</a> document. * Version following semantic defined by <a href="http://semver.org/">Semantic Versioning</a> document.
* Version identifiers have four components. * Version identifiers have four components.
* *
@ -31,9 +30,9 @@ import ro.fortsoft.pf4j.util.StringUtils;
* *
* @author Decebal Suiu * @author Decebal Suiu
*/ */
public class PluginVersion implements Comparable<PluginVersion> { public class Version implements Comparable<Version> {
public static final PluginVersion ZERO = new PluginVersion(0, 0, 0); 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 String FORMAT = "(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?";
private static final Pattern PATTERN = Pattern.compile(FORMAT); private static final Pattern PATTERN = Pattern.compile(FORMAT);
@ -44,13 +43,13 @@ public class PluginVersion implements Comparable<PluginVersion> {
private String separator; private String separator;
private String qualifier; private String qualifier;
public PluginVersion(int major, int minor, int patch) { public Version(int major, int minor, int patch) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
} }
public PluginVersion(int major, int minor, int patch, String separator, String qualifier) { public Version(int major, int minor, int patch, String separator, String qualifier) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -58,7 +57,7 @@ public class PluginVersion implements Comparable<PluginVersion> {
this.qualifier = qualifier; this.qualifier = qualifier;
} }
public static PluginVersion createVersion(String version) { public static Version createVersion(String version) {
Matcher matcher = PATTERN.matcher(version); Matcher matcher = PATTERN.matcher(version);
if (!matcher.matches()) { if (!matcher.matches()) {
throw new IllegalArgumentException("'" + version + "' does not match format '" + FORMAT + "'"); throw new IllegalArgumentException("'" + version + "' does not match format '" + FORMAT + "'");
@ -78,7 +77,7 @@ public class PluginVersion implements Comparable<PluginVersion> {
String separator = matcher.group(4); String separator = matcher.group(4);
String qualifier = matcher.group(5); String qualifier = matcher.group(5);
return new PluginVersion(major, minor, patch, separator, "".equals(qualifier) ? null : qualifier); return new Version(major, minor, patch, separator, "".equals(qualifier) ? null : qualifier);
} }
public int getMajor() { public int getMajor() {
@ -116,7 +115,7 @@ public class PluginVersion implements Comparable<PluginVersion> {
} }
@Override @Override
public int compareTo(PluginVersion version) { public int compareTo(Version version) {
if (version.major > major) { if (version.major > major) {
return 1; return 1;
} else if (version.major < major) { } else if (version.major < major) {
@ -142,21 +141,21 @@ public class PluginVersion implements Comparable<PluginVersion> {
return compareTo(ZERO) == 0; return compareTo(ZERO) == 0;
} }
public boolean atLeast(PluginVersion v) { public boolean atLeast(Version v) {
return compareTo(v) <= 0; return compareTo(v) <= 0;
} }
public boolean exceeds(PluginVersion v) { public boolean exceeds(Version v) {
return compareTo(v) > 0; return compareTo(v) > 0;
} }
// for test only // for test only
public static void main(String[] args) { public static void main(String[] args) {
PluginVersion v = PluginVersion.createVersion("1.2.3-SNAPSHOT"); Version v = Version.createVersion("1.2.3-SNAPSHOT");
System.out.println(v.toString()); System.out.println(v.toString());
PluginVersion v1 = PluginVersion.createVersion("4.1.0"); Version v1 = Version.createVersion("4.1.0");
System.out.println(v1.toString()); System.out.println(v1.toString());
PluginVersion v2 = PluginVersion.createVersion("4.0.32"); Version v2 = Version.createVersion("4.0.32");
System.out.println(v2.toString()); System.out.println(v2.toString());
System.out.println(v1.compareTo(v2)); System.out.println(v1.compareTo(v2));
} }
Loading…
Cancel
Save