mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
added plugin conditions
This commit is contained in:
@@ -53,6 +53,17 @@ import javax.xml.bind.annotation.XmlTransient;
|
|||||||
public class Plugin
|
public class Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PluginCondition getCondition()
|
||||||
|
{
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -99,6 +110,18 @@ public class Plugin
|
|||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
*/
|
||||||
|
public void setCondition(PluginCondition condition)
|
||||||
|
{
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -145,6 +168,10 @@ public class Plugin
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name="conditions")
|
||||||
|
private PluginCondition condition;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private PluginInformation information;
|
private PluginInformation information;
|
||||||
|
|
||||||
|
|||||||
218
scm-core/src/main/java/sonia/scm/plugin/PluginCondition.java
Normal file
218
scm-core/src/main/java/sonia/scm/plugin/PluginCondition.java
Normal 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;
|
||||||
|
}
|
||||||
@@ -73,6 +73,12 @@ public class PluginInformation implements Validateable
|
|||||||
|
|
||||||
final PluginInformation other = (PluginInformation) obj;
|
final PluginInformation other = (PluginInformation) obj;
|
||||||
|
|
||||||
|
if ((this.condition != other.condition)
|
||||||
|
&& ((this.condition == null) ||!this.condition.equals(other.condition)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((this.artifactId == null)
|
if ((this.artifactId == null)
|
||||||
? (other.artifactId != null)
|
? (other.artifactId != null)
|
||||||
: !this.artifactId.equals(other.artifactId))
|
: !this.artifactId.equals(other.artifactId))
|
||||||
@@ -87,6 +93,13 @@ public class PluginInformation implements Validateable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((this.description == null)
|
||||||
|
? (other.description != null)
|
||||||
|
: !this.description.equals(other.description))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((this.groupId == null)
|
if ((this.groupId == null)
|
||||||
? (other.groupId != null)
|
? (other.groupId != null)
|
||||||
: !this.groupId.equals(other.groupId))
|
: !this.groupId.equals(other.groupId))
|
||||||
@@ -94,6 +107,25 @@ public class PluginInformation implements Validateable
|
|||||||
return false;
|
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)
|
if ((this.version == null)
|
||||||
? (other.version != null)
|
? (other.version != null)
|
||||||
: !this.version.equals(other.version))
|
: !this.version.equals(other.version))
|
||||||
@@ -113,15 +145,33 @@ public class PluginInformation implements Validateable
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
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()
|
? this.artifactId.hashCode()
|
||||||
: 0);
|
: 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()
|
? this.groupId.hashCode()
|
||||||
: 0);
|
: 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()
|
? this.version.hashCode()
|
||||||
: 0);
|
: 0);
|
||||||
|
|
||||||
@@ -152,6 +202,17 @@ public class PluginInformation implements Validateable
|
|||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PluginCondition getCondition()
|
||||||
|
{
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -270,6 +331,17 @@ public class PluginInformation implements Validateable
|
|||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
*/
|
||||||
|
public void setCondition(PluginCondition condition)
|
||||||
|
{
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -344,6 +416,9 @@ public class PluginInformation implements Validateable
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private PluginCondition condition;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
|||||||
@@ -244,6 +244,12 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
|
|
||||||
Plugin plugin = JAXB.unmarshal(url, Plugin.class);
|
Plugin plugin = JAXB.unmarshal(url, Plugin.class);
|
||||||
PluginInformation info = plugin.getInformation();
|
PluginInformation info = plugin.getInformation();
|
||||||
|
PluginCondition condition = plugin.getCondition();
|
||||||
|
|
||||||
|
if (condition != null)
|
||||||
|
{
|
||||||
|
info.setCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
if (info != null)
|
if (info != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user