mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
added ScmModule to read module.xml which is produced by the scm-annotation-processor
This commit is contained in:
141
scm-core/src/main/java/sonia/scm/plugin/ClassElement.java
Normal file
141
scm-core/src/main/java/sonia/scm/plugin/ClassElement.java
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/**
|
||||||
|
* 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 com.google.common.base.Objects;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public final class ClassElement
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ClassElement() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
*/
|
||||||
|
public ClassElement(Class<?> clazz)
|
||||||
|
{
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ClassElement other = (ClassElement) obj;
|
||||||
|
|
||||||
|
return Objects.equal(clazz, other.clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return Objects.hashCode(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
//J-
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("clazz", clazz)
|
||||||
|
.toString();
|
||||||
|
//J+
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Class<?> getClazz()
|
||||||
|
{
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "class")
|
||||||
|
private Class<?> clazz;
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
/**
|
||||||
|
* 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 com.google.common.base.Objects;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlRootElement(name = "extension-point")
|
||||||
|
public final class ExtensionPointElement
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ExtensionPointElement() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
* @param multiple
|
||||||
|
*/
|
||||||
|
public ExtensionPointElement(Class<?> clazz, boolean multiple)
|
||||||
|
{
|
||||||
|
this.clazz = clazz;
|
||||||
|
this.multiple = multiple;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ExtensionPointElement other = (ExtensionPointElement) obj;
|
||||||
|
|
||||||
|
return Objects.equal(clazz, other.clazz)
|
||||||
|
&& Objects.equal(multiple, other.multiple);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return Objects.hashCode(clazz, multiple);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
//J-
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("class", clazz)
|
||||||
|
.add("multiple", multiple)
|
||||||
|
.toString();
|
||||||
|
//J+
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Class<?> getClazz()
|
||||||
|
{
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isMultiple()
|
||||||
|
{
|
||||||
|
return multiple;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "class")
|
||||||
|
private Class<?> clazz;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "multi")
|
||||||
|
private boolean multiple = true;
|
||||||
|
}
|
||||||
@@ -39,14 +39,10 @@ import com.google.common.base.Objects;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import javax.xml.bind.annotation.XmlTransient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -54,9 +50,33 @@ import javax.xml.bind.annotation.XmlTransient;
|
|||||||
*/
|
*/
|
||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class Plugin
|
public final class Plugin extends ScmModule
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Plugin() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param information
|
||||||
|
* @param resources
|
||||||
|
* @param condition
|
||||||
|
*/
|
||||||
|
public Plugin(PluginInformation information, PluginResources resources,
|
||||||
|
PluginCondition condition)
|
||||||
|
{
|
||||||
|
this.information = information;
|
||||||
|
this.resources = resources;
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -82,8 +102,6 @@ public class Plugin
|
|||||||
|
|
||||||
return Objects.equal(condition, other.condition)
|
return Objects.equal(condition, other.condition)
|
||||||
&& Objects.equal(information, other.information)
|
&& Objects.equal(information, other.information)
|
||||||
&& Objects.equal(packageSet, other.packageSet)
|
|
||||||
&& Objects.equal(path, other.path)
|
|
||||||
&& Objects.equal(resources, other.resources);
|
&& Objects.equal(resources, other.resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +114,7 @@ public class Plugin
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return Objects.hashCode(condition, information, packageSet, packageSet,
|
return Objects.hashCode(condition, information, resources);
|
||||||
resources);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,8 +130,6 @@ public class Plugin
|
|||||||
return Objects.toStringHelper(this)
|
return Objects.toStringHelper(this)
|
||||||
.add("condition", condition)
|
.add("condition", condition)
|
||||||
.add("information", information)
|
.add("information", information)
|
||||||
.add("packageSet", packageSet)
|
|
||||||
.add("path", path)
|
|
||||||
.add("resources", resources)
|
.add("resources", resources)
|
||||||
.toString();
|
.toString();
|
||||||
//J+
|
//J+
|
||||||
@@ -144,28 +159,6 @@ public class Plugin
|
|||||||
return information;
|
return information;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Set<String> getPackageSet()
|
|
||||||
{
|
|
||||||
return packageSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getPath()
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -177,64 +170,6 @@ public class Plugin
|
|||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param condition
|
|
||||||
*/
|
|
||||||
public void setCondition(PluginCondition condition)
|
|
||||||
{
|
|
||||||
this.condition = condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param information
|
|
||||||
*/
|
|
||||||
public void setInformation(PluginInformation information)
|
|
||||||
{
|
|
||||||
this.information = information;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param packageSet
|
|
||||||
*/
|
|
||||||
public void setPackageSet(Set<String> packageSet)
|
|
||||||
{
|
|
||||||
this.packageSet = packageSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param path
|
|
||||||
*/
|
|
||||||
public void setPath(String path)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param resources
|
|
||||||
*/
|
|
||||||
public void setResources(PluginResources resources)
|
|
||||||
{
|
|
||||||
this.resources = resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@@ -244,15 +179,6 @@ public class Plugin
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private PluginInformation information;
|
private PluginInformation information;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
@XmlElement(name = "package")
|
|
||||||
@XmlElementWrapper(name = "packages")
|
|
||||||
private Set<String> packageSet;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
@XmlTransient
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private PluginResources resources;
|
private PluginResources resources;
|
||||||
}
|
}
|
||||||
|
|||||||
230
scm-core/src/main/java/sonia/scm/plugin/ScmModule.java
Normal file
230
scm-core/src/main/java/sonia/scm/plugin/ScmModule.java
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
/**
|
||||||
|
* 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 com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "module")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class ScmModule
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final Unwrapper unwrapper = new Unwrapper();
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<Class<?>> getEvents()
|
||||||
|
{
|
||||||
|
return unwrap(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<ExtensionPointElement> getExtensionPoints()
|
||||||
|
{
|
||||||
|
return nonNull(extensionPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<Class<?>> getExtensions()
|
||||||
|
{
|
||||||
|
return unwrap(extensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<Class<?>> getJaxrsProviders()
|
||||||
|
{
|
||||||
|
return unwrap(jaxrsProviders);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<Class<?>> getJaxrsResources()
|
||||||
|
{
|
||||||
|
return unwrap(jaxrsResources);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<SubscriberElement> getSubscribers()
|
||||||
|
{
|
||||||
|
return nonNull(subscribers);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param iterable
|
||||||
|
* @param <T>
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private <T> Iterable<T> nonNull(Iterable<T> iterable)
|
||||||
|
{
|
||||||
|
if (iterable == null)
|
||||||
|
{
|
||||||
|
iterable = ImmutableSet.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
return iterable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param iterable
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Iterable<Class<?>> unwrap(Iterable<ClassElement> iterable)
|
||||||
|
{
|
||||||
|
Iterable<Class<?>> unwrapped;
|
||||||
|
|
||||||
|
if (iterable != null)
|
||||||
|
{
|
||||||
|
unwrapped = Iterables.transform(iterable, unwrapper);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unwrapped = ImmutableSet.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
return unwrapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- inner classes --------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @version Enter version here..., 14/03/28
|
||||||
|
* @author Enter your name here...
|
||||||
|
*/
|
||||||
|
private static class Unwrapper implements Function<ClassElement, Class<?>>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classElement
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Class<?> apply(ClassElement classElement)
|
||||||
|
{
|
||||||
|
return classElement.getClazz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "event")
|
||||||
|
private Set<ClassElement> events;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "extension-point")
|
||||||
|
private Set<ExtensionPointElement> extensionPoints;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "extension")
|
||||||
|
private Set<ClassElement> extensions;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "jaxrs-provider")
|
||||||
|
private Set<ClassElement> jaxrsProviders;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "jaxrs-resource")
|
||||||
|
private Set<ClassElement> jaxrsResources;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "subscriber")
|
||||||
|
private Set<SubscriberElement> subscribers;
|
||||||
|
}
|
||||||
165
scm-core/src/main/java/sonia/scm/plugin/SubscriberElement.java
Normal file
165
scm-core/src/main/java/sonia/scm/plugin/SubscriberElement.java
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
/**
|
||||||
|
* 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 com.google.common.base.Objects;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "subscriber")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public final class SubscriberElement
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
SubscriberElement() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param subscriberClass
|
||||||
|
* @param eventClass
|
||||||
|
*/
|
||||||
|
public SubscriberElement(Class<?> subscriberClass, Class<?> eventClass)
|
||||||
|
{
|
||||||
|
this.subscriberClass = subscriberClass;
|
||||||
|
this.eventClass = eventClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final SubscriberElement other = (SubscriberElement) obj;
|
||||||
|
|
||||||
|
return Objects.equal(eventClass, other.eventClass)
|
||||||
|
&& Objects.equal(subscriberClass, other.subscriberClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return Objects.hashCode(eventClass, subscriberClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
//J-
|
||||||
|
return Objects.toStringHelper(this)
|
||||||
|
.add("eventClass", eventClass)
|
||||||
|
.add("subscriberClass", subscriberClass)
|
||||||
|
.toString();
|
||||||
|
//J+
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Class<?> getEventClass()
|
||||||
|
{
|
||||||
|
return eventClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Class<?> getSubscriberClass()
|
||||||
|
{
|
||||||
|
return subscriberClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "event")
|
||||||
|
private Class<?> eventClass;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "class")
|
||||||
|
private Class<?> subscriberClass;
|
||||||
|
}
|
||||||
115
scm-core/src/test/java/sonia/scm/plugin/ScmModuleTest.java
Normal file
115
scm-core/src/test/java/sonia/scm/plugin/ScmModuleTest.java
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
* 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 com.google.common.io.Resources;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class ScmModuleTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testUnmarshall()
|
||||||
|
{
|
||||||
|
URL resource = Resources.getResource("sonia/scm/plugin/module.xml");
|
||||||
|
ScmModule module = JAXB.unmarshal(resource, ScmModule.class);
|
||||||
|
|
||||||
|
// stupid cast to Class<?> to make hamecrest generics happy
|
||||||
|
|
||||||
|
//J-
|
||||||
|
assertThat(
|
||||||
|
module.getExtensions(),
|
||||||
|
containsInAnyOrder(
|
||||||
|
(Class<?>) String.class,
|
||||||
|
(Class<?>) Integer.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertThat(
|
||||||
|
module.getExtensionPoints(),
|
||||||
|
containsInAnyOrder(
|
||||||
|
new ExtensionPointElement(String.class, true),
|
||||||
|
new ExtensionPointElement(Long.class, true),
|
||||||
|
new ExtensionPointElement(Integer.class, false)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertThat(
|
||||||
|
module.getEvents(),
|
||||||
|
containsInAnyOrder(
|
||||||
|
(Class<?>) String.class,
|
||||||
|
(Class<?>) Boolean.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertThat(
|
||||||
|
module.getSubscribers(),
|
||||||
|
containsInAnyOrder(
|
||||||
|
new SubscriberElement(Long.class, Integer.class),
|
||||||
|
new SubscriberElement(Double.class, Float.class)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertThat(
|
||||||
|
module.getJaxrsProviders(),
|
||||||
|
containsInAnyOrder(
|
||||||
|
(Class<?>) Integer.class,
|
||||||
|
(Class<?>) Long.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assertThat(
|
||||||
|
module.getJaxrsResources(),
|
||||||
|
containsInAnyOrder(
|
||||||
|
(Class<?>) Float.class,
|
||||||
|
(Class<?>) Double.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
//J+
|
||||||
|
}
|
||||||
|
}
|
||||||
71
scm-core/src/test/resources/sonia/scm/plugin/module.xml
Normal file
71
scm-core/src/test/resources/sonia/scm/plugin/module.xml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<module>
|
||||||
|
|
||||||
|
<!-- subscribers -->
|
||||||
|
<subscriber>
|
||||||
|
<class>java.lang.Long</class>
|
||||||
|
<event>java.lang.Integer</event>
|
||||||
|
</subscriber>
|
||||||
|
|
||||||
|
<subscriber>
|
||||||
|
<class>java.lang.Double</class>
|
||||||
|
<event>java.lang.Float</event>
|
||||||
|
</subscriber>
|
||||||
|
|
||||||
|
<!-- events -->
|
||||||
|
|
||||||
|
<event>
|
||||||
|
<class>java.lang.String</class>
|
||||||
|
</event>
|
||||||
|
|
||||||
|
<event>
|
||||||
|
<class>java.lang.Boolean</class>
|
||||||
|
</event>
|
||||||
|
|
||||||
|
<!-- extension points -->
|
||||||
|
|
||||||
|
<extension-point>
|
||||||
|
<class>java.lang.String</class>
|
||||||
|
</extension-point>
|
||||||
|
|
||||||
|
<extension-point>
|
||||||
|
<class>java.lang.Integer</class>
|
||||||
|
<multi>false</multi>
|
||||||
|
</extension-point>
|
||||||
|
|
||||||
|
<extension-point>
|
||||||
|
<class>java.lang.Long</class>
|
||||||
|
<multi>true</multi>
|
||||||
|
</extension-point>
|
||||||
|
|
||||||
|
<!-- extensions -->
|
||||||
|
|
||||||
|
<extension>
|
||||||
|
<class>java.lang.String</class>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
<extension>
|
||||||
|
<class>java.lang.Integer</class>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
<!-- jax-rs providers -->
|
||||||
|
|
||||||
|
<jaxrs-provider>
|
||||||
|
<class>java.lang.Integer</class>
|
||||||
|
</jaxrs-provider>
|
||||||
|
|
||||||
|
<jaxrs-provider>
|
||||||
|
<class>java.lang.Long</class>
|
||||||
|
</jaxrs-provider>
|
||||||
|
|
||||||
|
<!-- jax-rs resources -->
|
||||||
|
|
||||||
|
<jaxrs-resource>
|
||||||
|
<class>java.lang.Float</class>
|
||||||
|
</jaxrs-resource>
|
||||||
|
|
||||||
|
<jaxrs-resource>
|
||||||
|
<class>java.lang.Double</class>
|
||||||
|
</jaxrs-resource>
|
||||||
|
|
||||||
|
</module>
|
||||||
Reference in New Issue
Block a user