introduce scm version to be sure the plugin is for the correct scm-manager major version

This commit is contained in:
Sebastian Sdorra
2014-09-13 20:07:07 +02:00
parent 557bc29c31
commit b465e4b18b
8 changed files with 69 additions and 10 deletions

View File

@@ -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;
}

View File

@@ -33,6 +33,8 @@
-->
<plugin>
<scm-version>2</scm-version>
<information>
<!--

View File

@@ -41,6 +41,8 @@
-->
<plugin>
<scm-version>2</scm-version>
<information>
<author>Sebastian Sdorra</author>

View File

@@ -41,6 +41,8 @@
-->
<plugin>
<scm-version>2</scm-version>
<information>
<author>Sebastian Sdorra</author>

View File

@@ -41,6 +41,8 @@
-->
<plugin>
<scm-version>2</scm-version>
<information>
<author>Sebastian Sdorra</author>

View File

@@ -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 */

View File

@@ -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);
}

View File

@@ -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);