| | |
| | |
|
| | | import org.parboiled.common.StringUtils;
|
| | |
|
| | | import ro.fortsoft.pf4j.PluginVersion;
|
| | | import ro.fortsoft.pf4j.Version;
|
| | |
|
| | | /**
|
| | | * Represents a list of plugin registrations.
|
| | |
| | |
|
| | | public String projectUrl;
|
| | |
|
| | | public String currentRelease;
|
| | |
|
| | | public transient String installedRelease;
|
| | |
|
| | | public transient String registry;
|
| | |
| | | this.releases = new ArrayList<PluginRelease>();
|
| | | }
|
| | |
|
| | | public PluginRelease getCurrentRelease() {
|
| | | public PluginRelease getCurrentRelease(Version system) {
|
| | | PluginRelease current = null;
|
| | | if (!StringUtils.isEmpty(currentRelease)) {
|
| | | // find specified
|
| | | current = getRelease(currentRelease);
|
| | | }
|
| | | Date date = new Date(0);
|
| | | for (PluginRelease pv : releases) {
|
| | | Version requires = Version.ZERO;
|
| | | if (!StringUtils.isEmpty(pv.requires)) {
|
| | | requires = Version.createVersion(pv.requires);
|
| | | }
|
| | |
|
| | | if (current == null) {
|
| | | // find by date
|
| | | Date date = new Date(0);
|
| | | for (PluginRelease pv : releases) {
|
| | | if (system.isZero() || system.atLeast(requires)) {
|
| | | if (pv.date.after(date)) {
|
| | | current = pv;
|
| | | date = pv.date;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public InstallState getInstallState() {
|
| | | public InstallState getInstallState(Version system) {
|
| | | if (StringUtils.isEmpty(installedRelease)) {
|
| | | return InstallState.NOT_INSTALLED;
|
| | | }
|
| | | PluginVersion ir = PluginVersion.createVersion(installedRelease);
|
| | | PluginVersion cr = PluginVersion.createVersion(currentRelease);
|
| | | Version ir = Version.createVersion(installedRelease);
|
| | | Version cr = Version.ZERO;
|
| | | PluginRelease curr = getCurrentRelease(system);
|
| | | if (curr != null) {
|
| | | cr = Version.createVersion(curr.version);
|
| | | }
|
| | | switch (ir.compareTo(cr)) {
|
| | | case -1:
|
| | | return InstallState.UNKNOWN;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public static class PluginRelease implements Comparable<PluginRelease> {
|
| | | public static class PluginRelease implements Serializable, Comparable<PluginRelease> {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public String version;
|
| | | public Date date;
|
| | | public String requires;
|
| | |
| | |
|
| | | @Override
|
| | | public int compareTo(PluginRelease o) {
|
| | | return PluginVersion.createVersion(version).compareTo(PluginVersion.createVersion(o.version));
|
| | | return Version.createVersion(version).compareTo(Version.createVersion(o.version));
|
| | | }
|
| | | }
|
| | | }
|