mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-01 00:19:44 +02:00
introduce scm version to be sure the plugin is for the correct scm-manager major version
This commit is contained in:
@@ -67,16 +67,18 @@ public final class Plugin extends ScmModule
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param scmVersion
|
||||
* @param information
|
||||
* @param resources
|
||||
* @param condition
|
||||
* @param childFirstClassLoader
|
||||
* @param dependencies
|
||||
*/
|
||||
public Plugin(PluginInformation information, PluginResources resources,
|
||||
PluginCondition condition, boolean childFirstClassLoader,
|
||||
Set<String> dependencies)
|
||||
public Plugin(int scmVersion, PluginInformation information,
|
||||
PluginResources resources, PluginCondition condition,
|
||||
boolean childFirstClassLoader, Set<String> dependencies)
|
||||
{
|
||||
this.scmVersion = scmVersion;
|
||||
this.information = information;
|
||||
this.resources = resources;
|
||||
this.condition = condition;
|
||||
@@ -109,7 +111,8 @@ public final class Plugin extends ScmModule
|
||||
|
||||
final Plugin other = (Plugin) obj;
|
||||
|
||||
return Objects.equal(condition, other.condition)
|
||||
return Objects.equal(scmVersion, other.scmVersion)
|
||||
&& Objects.equal(condition, other.condition)
|
||||
&& Objects.equal(information, other.information)
|
||||
&& Objects.equal(resources, other.resources)
|
||||
&& Objects.equal(childFirstClassLoader, other.childFirstClassLoader)
|
||||
@@ -125,7 +128,7 @@ public final class Plugin extends ScmModule
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(condition, information, resources,
|
||||
return Objects.hashCode(scmVersion, condition, information, resources,
|
||||
childFirstClassLoader, dependencies);
|
||||
}
|
||||
|
||||
@@ -140,6 +143,7 @@ public final class Plugin extends ScmModule
|
||||
{
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("scmVersion", scmVersion)
|
||||
.add("condition", condition)
|
||||
.add("information", information)
|
||||
.add("resources", resources)
|
||||
@@ -202,6 +206,17 @@ public final class Plugin extends ScmModule
|
||||
return resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getScmVersion()
|
||||
{
|
||||
return scmVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -233,4 +248,8 @@ public final class Plugin extends ScmModule
|
||||
|
||||
/** Field description */
|
||||
private PluginResources resources;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "scm-version")
|
||||
private int scmVersion = 1;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
-->
|
||||
<plugin>
|
||||
|
||||
<scm-version>2</scm-version>
|
||||
|
||||
<information>
|
||||
<!--
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
|
||||
<scm-version>2</scm-version>
|
||||
|
||||
<information>
|
||||
<author>Sebastian Sdorra</author>
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
|
||||
<scm-version>2</scm-version>
|
||||
|
||||
<information>
|
||||
<author>Sebastian Sdorra</author>
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
|
||||
<scm-version>2</scm-version>
|
||||
|
||||
<information>
|
||||
<author>Sebastian Sdorra</author>
|
||||
|
||||
@@ -52,6 +52,9 @@ import java.util.Set;
|
||||
public final class PluginTree
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final int SCM_VERSION = 2;
|
||||
|
||||
/**
|
||||
* the logger for PluginTree
|
||||
*/
|
||||
@@ -84,6 +87,19 @@ public final class PluginTree
|
||||
for (ExplodedSmp smp : smpOrdered)
|
||||
{
|
||||
Plugin plugin = smp.getPlugin();
|
||||
|
||||
if (plugin.getScmVersion() != SCM_VERSION)
|
||||
{
|
||||
//J-
|
||||
throw new PluginException(
|
||||
String.format(
|
||||
"scm version %s of plugin %s does not match, required is version %s",
|
||||
plugin.getScmVersion(), plugin.getInformation().getId(), SCM_VERSION
|
||||
)
|
||||
);
|
||||
//J+
|
||||
}
|
||||
|
||||
PluginCondition condition = plugin.getCondition();
|
||||
|
||||
if ((condition == null) || condition.isSupported())
|
||||
@@ -202,7 +218,6 @@ public final class PluginTree
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -135,7 +135,8 @@ public class ExplodedSmpTest
|
||||
info.setArtifactId(artifactId);
|
||||
info.setVersion(version);
|
||||
|
||||
Plugin plugin = new Plugin(info, null, null, false, Sets.newSet(dependencies));
|
||||
Plugin plugin = new Plugin(2, info, null, null, false,
|
||||
Sets.newSet(dependencies));
|
||||
|
||||
return new ExplodedSmp(null, plugin);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class PluginTreeTest
|
||||
{
|
||||
PluginCondition condition = new PluginCondition("999",
|
||||
new ArrayList<String>(), "hit");
|
||||
Plugin plugin = new Plugin(createInfo("a", "b", "1"), null, condition,
|
||||
Plugin plugin = new Plugin(2, createInfo("a", "b", "1"), null, condition,
|
||||
false, null);
|
||||
ExplodedSmp smp = createSmp(plugin);
|
||||
|
||||
@@ -105,6 +105,22 @@ public class PluginTreeTest
|
||||
assertThat(nodes, containsInAnyOrder("a:a", "b:b", "c:c"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test(expected = PluginException.class)
|
||||
public void testScmVersion() throws IOException
|
||||
{
|
||||
Plugin plugin = new Plugin(1, createInfo("a", "b", "1"), null, null, false,
|
||||
null);
|
||||
ExplodedSmp smp = createSmp(plugin);
|
||||
|
||||
new PluginTree(smp).getRootNodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -185,7 +201,7 @@ public class PluginTreeTest
|
||||
*/
|
||||
private ExplodedSmp createSmp(String name) throws IOException
|
||||
{
|
||||
return createSmp(new Plugin(createInfo(name, name, "1.0.0"), null, null,
|
||||
return createSmp(new Plugin(2, createInfo(name, name, "1.0.0"), null, null,
|
||||
false, null));
|
||||
}
|
||||
|
||||
@@ -211,7 +227,7 @@ public class PluginTreeTest
|
||||
dependencySet.add(d.concat(":").concat(d));
|
||||
}
|
||||
|
||||
Plugin plugin = new Plugin(createInfo(name, name, "1"), null, null,
|
||||
Plugin plugin = new Plugin(2, createInfo(name, name, "1"), null, null,
|
||||
false, dependencySet);
|
||||
|
||||
return createSmp(plugin);
|
||||
|
||||
Reference in New Issue
Block a user