added plugin conditions

This commit is contained in:
Sebastian Sdorra
2011-03-12 16:14:17 +01:00
parent d16cd2da64
commit 331a49af31
4 changed files with 330 additions and 4 deletions

View File

@@ -53,6 +53,17 @@ import javax.xml.bind.annotation.XmlTransient;
public class Plugin
{
/**
* Method description
*
*
* @return
*/
public PluginCondition getCondition()
{
return condition;
}
/**
* Method description
*
@@ -99,6 +110,18 @@ public class Plugin
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
*
* @param condition
*/
public void setCondition(PluginCondition condition)
{
this.condition = condition;
}
/**
* Method description
*
@@ -145,6 +168,10 @@ public class Plugin
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElement(name="conditions")
private PluginCondition condition;
/** Field description */
private PluginInformation information;

View File

@@ -0,0 +1,218 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.SCMContext;
import sonia.scm.util.SystemUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Sebastian Sdorra
*/
@XmlRootElement(name = "conditions")
@XmlAccessorType(XmlAccessType.FIELD)
public class PluginCondition
{
/**
* Method description
*
*
* @return
*/
public String getArch()
{
return arch;
}
/**
* Method description
*
*
* @return
*/
public String getMinVersion()
{
return minVersion;
}
/**
* Method description
*
*
* @return
*/
public List<String> getOs()
{
return os;
}
/**
* Method description
*
*
* @return
*/
public boolean isSupported()
{
return isSupported(SCMContext.getContext().getVersion(),
SystemUtil.getOS(), SystemUtil.getArch());
}
/**
* Method description
*
*
* @param version
* @param os
* @param arch
*
* @return
*/
public boolean isSupported(String version, String os, String arch)
{
boolean supported = true;
if (Util.isNotEmpty(minVersion) && Util.isNotEmpty(version))
{
supported = new PluginVersion(version).isNewer(minVersion);
}
if (supported && Util.isNotEmpty(this.os) && Util.isNotEmpty(os))
{
supported = false;
os = os.toLowerCase();
for (String osType : this.os)
{
supported = isOs(osType, os);
if (supported)
{
break;
}
}
}
if (supported && Util.isNotEmpty(this.arch) && Util.isNotEmpty(arch))
{
supported = arch.equals(this.arch);
}
return supported;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param arch
*/
public void setArch(String arch)
{
this.arch = arch;
}
/**
* Method description
*
*
* @param minVersion
*/
public void setMinVersion(String minVersion)
{
this.minVersion = minVersion;
}
/**
* Method description
*
*
* @param os
*/
public void setOs(List<String> os)
{
this.os = os;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param osType
* @param os
*
* @return
*/
private boolean isOs(String osType, String os)
{
osType = osType.toLowerCase();
return (osType.startsWith("mac") && (os.indexOf("mac") >= 0))
|| (osType.startsWith("win") && (os.indexOf("win") >= 0))
|| ((osType.startsWith("unix") && (os.indexOf("nix") >= 0))
|| (os.indexOf("nux") >= 0));
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String arch;
/** Field description */
@XmlElement(name = "min-version")
private String minVersion;
/** Field description */
@XmlElement(name = "name")
@XmlElementWrapper(name = "os")
private List<String> os;
}

View File

@@ -73,6 +73,12 @@ public class PluginInformation implements Validateable
final PluginInformation other = (PluginInformation) obj;
if ((this.condition != other.condition)
&& ((this.condition == null) ||!this.condition.equals(other.condition)))
{
return false;
}
if ((this.artifactId == null)
? (other.artifactId != null)
: !this.artifactId.equals(other.artifactId))
@@ -87,6 +93,13 @@ public class PluginInformation implements Validateable
return false;
}
if ((this.description == null)
? (other.description != null)
: !this.description.equals(other.description))
{
return false;
}
if ((this.groupId == null)
? (other.groupId != null)
: !this.groupId.equals(other.groupId))
@@ -94,6 +107,25 @@ public class PluginInformation implements Validateable
return false;
}
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if (this.state != other.state)
{
return false;
}
if ((this.url == null)
? (other.url != null)
: !this.url.equals(other.url))
{
return false;
}
if ((this.version == null)
? (other.version != null)
: !this.version.equals(other.version))
@@ -113,15 +145,33 @@ public class PluginInformation implements Validateable
@Override
public int hashCode()
{
int hash = 7;
int hash = 5;
hash = 53 * hash + ((this.artifactId != null)
hash = 83 * hash + ((this.condition != null)
? this.condition.hashCode()
: 0);
hash = 83 * hash + ((this.artifactId != null)
? this.artifactId.hashCode()
: 0);
hash = 53 * hash + ((this.groupId != null)
hash = 83 * hash + ((this.author != null)
? this.author.hashCode()
: 0);
hash = 83 * hash + ((this.description != null)
? this.description.hashCode()
: 0);
hash = 83 * hash + ((this.groupId != null)
? this.groupId.hashCode()
: 0);
hash = 53 * hash + ((this.version != null)
hash = 83 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 83 * hash + ((this.state != null)
? this.state.hashCode()
: 0);
hash = 83 * hash + ((this.url != null)
? this.url.hashCode()
: 0);
hash = 83 * hash + ((this.version != null)
? this.version.hashCode()
: 0);
@@ -152,6 +202,17 @@ public class PluginInformation implements Validateable
return author;
}
/**
* Method description
*
*
* @return
*/
public PluginCondition getCondition()
{
return condition;
}
/**
* Method description
*
@@ -270,6 +331,17 @@ public class PluginInformation implements Validateable
this.author = author;
}
/**
* Method description
*
*
* @param condition
*/
public void setCondition(PluginCondition condition)
{
this.condition = condition;
}
/**
* Method description
*
@@ -344,6 +416,9 @@ public class PluginInformation implements Validateable
/** Field description */
private String author;
/** Field description */
private PluginCondition condition;
/** Field description */
private String description;

View File

@@ -244,6 +244,12 @@ public class DefaultPluginLoader implements PluginLoader
Plugin plugin = JAXB.unmarshal(url, Plugin.class);
PluginInformation info = plugin.getInformation();
PluginCondition condition = plugin.getCondition();
if (condition != null)
{
info.setCondition(condition);
}
if (info != null)
{