Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-24 07:02:13 +0000
committerEike Stepper2012-07-24 07:02:13 +0000
commitf22139d1f9e2f8bc6b324c02f24300607308d409 (patch)
treecb54a737672c927f476f4c4e7145f05b17217bd4 /plugins
parent2a2e594a22e15fd799c4be59c35459a14209ff0a (diff)
downloadcdo-f22139d1f9e2f8bc6b324c02f24300607308d409.tar.gz
cdo-f22139d1f9e2f8bc6b324c02f24300607308d409.tar.xz
cdo-f22139d1f9e2f8bc6b324c02f24300607308d409.zip
Refactoring
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.digest.ui/src/org/eclipse/emf/cdo/releng/version/digest/ui/CreateDigestAction.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Element.java236
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ElementResolver.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Release.java233
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ReleaseManager.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionBuilder.java42
6 files changed, 317 insertions, 220 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.digest.ui/src/org/eclipse/emf/cdo/releng/version/digest/ui/CreateDigestAction.java b/plugins/org.eclipse.emf.cdo.releng.version.digest.ui/src/org/eclipse/emf/cdo/releng/version/digest/ui/CreateDigestAction.java
index 5cd888e887..13e05a476a 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.digest.ui/src/org/eclipse/emf/cdo/releng/version/digest/ui/CreateDigestAction.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version.digest.ui/src/org/eclipse/emf/cdo/releng/version/digest/ui/CreateDigestAction.java
@@ -10,8 +10,8 @@
*/
package org.eclipse.emf.cdo.releng.version.digest.ui;
+import org.eclipse.emf.cdo.releng.version.Element;
import org.eclipse.emf.cdo.releng.version.Release;
-import org.eclipse.emf.cdo.releng.version.Release.Element;
import org.eclipse.emf.cdo.releng.version.ReleaseManager;
import org.eclipse.emf.cdo.releng.version.VersionBuilder;
import org.eclipse.emf.cdo.releng.version.digest.DigestValidator;
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Element.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Element.java
new file mode 100644
index 0000000000..ee17277a16
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Element.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.version;
+
+import org.eclipse.pde.core.IModel;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.core.plugin.PluginRegistry;
+
+import org.osgi.framework.Version;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class Element
+{
+ private Element.Type type;
+
+ private String name;
+
+ private Version version;
+
+ private List<Element> children = new ArrayList<Element>();
+
+ private Set<Element> allChildren;
+
+ public Element(Element.Type type, String name, Version version)
+ {
+ this.type = type;
+ this.name = name;
+ this.version = VersionUtil.normalize(version);
+ resolveVersion();
+ }
+
+ public Element(Element.Type type, String name, String version)
+ {
+ this(type, name, new Version(version));
+ }
+
+ public Element.Type getType()
+ {
+ return type;
+ }
+
+ public String getTag()
+ {
+ return type == Type.PLUGIN ? Release.PLUGIN_TAG : Release.FEATURE_TAG;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Version getVersion()
+ {
+ return version;
+ }
+
+ public List<Element> getChildren()
+ {
+ return children;
+ }
+
+ public Set<Element> getAllChildren(ElementResolver resolver)
+ {
+ if (allChildren == null)
+ {
+ allChildren = new HashSet<Element>();
+ for (Element child : children)
+ {
+ recurseChildren(resolver, child);
+ }
+ }
+
+ return allChildren;
+ }
+
+ private void recurseChildren(ElementResolver resolver, Element element)
+ {
+ if (!allChildren.contains(element))
+ {
+ Element topElement = resolver.resolveElement(element);
+ if (topElement == null)
+ {
+ allChildren.add(element);
+ return;
+ }
+
+ allChildren.add(topElement);
+
+ for (Element child : topElement.getChildren())
+ {
+ recurseChildren(resolver, child);
+ }
+ }
+ }
+
+ public Element getChild(ElementResolver resolver, Element key)
+ {
+ Set<Element> allChildren = getAllChildren(resolver);
+ for (Element child : allChildren)
+ {
+ if (child.equals(key))
+ {
+ return child;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Element [type=" + type + ", name=" + name + ", version=" + version + "]";
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (name == null ? 0 : name.hashCode());
+ result = prime * result + (getType() == null ? 0 : getType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj == null)
+ {
+ return false;
+ }
+
+ if (!(obj instanceof Element))
+ {
+ return false;
+ }
+
+ Element other = (Element)obj;
+ if (name == null)
+ {
+ if (other.name != null)
+ {
+ return false;
+ }
+ }
+ else if (!name.equals(other.name))
+ {
+ return false;
+ }
+
+ if (getType() != other.getType())
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean isUnresolved()
+ {
+ return version.equals(Version.emptyVersion);
+ }
+
+ private void resolveVersion()
+ {
+ if (isUnresolved())
+ {
+ Version resolvedVersion;
+ if (type == Element.Type.PLUGIN)
+ {
+ resolvedVersion = getPluginVersion(name);
+ }
+ else
+ {
+ resolvedVersion = getFeatureVersion(name);
+ }
+
+ if (resolvedVersion != null)
+ {
+ version = resolvedVersion;
+ }
+ }
+ }
+
+ private Version getPluginVersion(String name)
+ {
+ IPluginModelBase pluginModel = PluginRegistry.findModel(name);
+ if (pluginModel != null)
+ {
+ Version version = pluginModel.getBundleDescription().getVersion();
+ return VersionUtil.normalize(version);
+ }
+
+ return null;
+ }
+
+ private Version getFeatureVersion(String name)
+ {
+ IModel componentModel = ReleaseManager.INSTANCE.getComponentModel(this);
+ if (componentModel != null)
+ {
+ return VersionBuilder.getComponentVersion(componentModel);
+ }
+
+ return version;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static enum Type
+ {
+ FEATURE, PLUGIN
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ElementResolver.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ElementResolver.java
new file mode 100644
index 0000000000..39c150657c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ElementResolver.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.version;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ElementResolver
+{
+ public Element resolveElement(Element key);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Release.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Release.java
index 892e9c0eba..b76aa3c990 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Release.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Release.java
@@ -14,9 +14,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.pde.core.IModel;
-import org.eclipse.pde.core.plugin.IPluginModelBase;
-import org.eclipse.pde.core.plugin.PluginRegistry;
import org.osgi.framework.Version;
import org.xml.sax.Attributes;
@@ -39,7 +36,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public class Release
+public class Release implements ElementResolver
{
public static final String RELEASE_TAG = "release";
@@ -120,6 +117,11 @@ public class Release
return elements;
}
+ public Element resolveElement(Element key)
+ {
+ return elements.get(key);
+ }
+
public int getSize()
{
return elements.size();
@@ -217,205 +219,12 @@ public class Release
/**
* @author Eike Stepper
*/
- public static class Element
- {
- private Type type;
-
- private String name;
-
- private Version version;
-
- private List<Element> children = new ArrayList<Element>();
-
- private List<Element> allChildren;
-
- public Element(Type type, String name, Version version)
- {
- this.type = type;
- this.name = name;
- this.version = VersionUtil.normalize(version);
- resolveVersion();
- }
-
- public Element(Type type, String name, String version)
- {
- this(type, name, new Version(version));
- }
-
- public Type getType()
- {
- return type;
- }
-
- public String getTag()
- {
- return type == Type.PLUGIN ? PLUGIN_TAG : FEATURE_TAG;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Version getVersion()
- {
- return version;
- }
-
- public List<Element> getChildren()
- {
- return children;
- }
-
- public List<Element> getAllChildren()
- {
- if (allChildren == null)
- {
- allChildren = new ArrayList<Element>();
- for (Element child : children)
- {
- recurseChildren(child);
- }
- }
-
- return allChildren;
- }
-
- private void recurseChildren(Element element)
- {
- allChildren.add(element);
- for (Element child : element.getChildren())
- {
- recurseChildren(child);
- }
- }
-
- public Element getChild(Element childElement)
- {
- List<Element> allChildren = getAllChildren();
- int index = allChildren.indexOf(childElement);
- if (index != -1)
- {
- return allChildren.get(index);
- }
-
- return null;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + (name == null ? 0 : name.hashCode());
- result = prime * result + (getType() == null ? 0 : getType().hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
-
- if (obj == null)
- {
- return false;
- }
-
- if (!(obj instanceof Element))
- {
- return false;
- }
-
- Element other = (Element)obj;
- if (name == null)
- {
- if (other.name != null)
- {
- return false;
- }
- }
- else if (!name.equals(other.name))
- {
- return false;
- }
-
- if (getType() != other.getType())
- {
- return false;
- }
-
- return true;
- }
-
- public boolean isUnresolved()
- {
- return version.equals(Version.emptyVersion);
- }
-
- private void resolveVersion()
- {
- if (isUnresolved())
- {
- Version resolvedVersion;
- if (type == Element.Type.PLUGIN)
- {
- resolvedVersion = getPluginVersion(name);
- }
- else
- {
- resolvedVersion = getFeatureVersion(name);
- }
-
- if (resolvedVersion != null)
- {
- version = resolvedVersion;
- }
- }
- }
-
- private Version getPluginVersion(String name)
- {
- IPluginModelBase pluginModel = PluginRegistry.findModel(name);
- if (pluginModel != null)
- {
- Version version = pluginModel.getBundleDescription().getVersion();
- return VersionUtil.normalize(version);
- }
-
- return null;
- }
-
- private Version getFeatureVersion(String name)
- {
- IModel componentModel = ReleaseManager.INSTANCE.getComponentModel(this);
- if (componentModel != null)
- {
- return VersionBuilder.getComponentVersion(componentModel);
- }
-
- return version;
- }
-
- /**
- * @author Eike Stepper
- */
- public static enum Type
- {
- FEATURE, PLUGIN
- }
- }
-
- /**
- * @author Eike Stepper
- */
public class XMLHandler extends DefaultHandler
{
private Element parent;
+ private int level;
+
public XMLHandler()
{
}
@@ -430,13 +239,29 @@ public class Release
}
else if (FEATURE_TAG.equalsIgnoreCase(qName))
{
- parent = createElement(Element.Type.FEATURE, attributes);
- elements.put(parent, parent);
+ Element element = createElement(Element.Type.FEATURE, attributes);
+ if (++level == 1)
+ {
+ elements.put(element, element);
+ parent = element;
+ }
+ else
+ {
+ parent.getChildren().add(element);
+ }
}
else if (PLUGIN_TAG.equalsIgnoreCase(qName))
{
- parent = createElement(Element.Type.PLUGIN, attributes);
- elements.put(parent, parent);
+ Element element = createElement(Element.Type.PLUGIN, attributes);
+ if (++level == 1)
+ {
+ elements.put(element, element);
+ parent = element;
+ }
+ else
+ {
+ parent.getChildren().add(element);
+ }
}
}
@@ -453,7 +278,7 @@ public class Release
{
if (FEATURE_TAG.equalsIgnoreCase(qName) || PLUGIN_TAG.equalsIgnoreCase(qName))
{
- parent = null;
+ --level;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ReleaseManager.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ReleaseManager.java
index 98701495af..c307f5886e 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ReleaseManager.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/ReleaseManager.java
@@ -10,8 +10,7 @@
*/
package org.eclipse.emf.cdo.releng.version;
-import org.eclipse.emf.cdo.releng.version.Release.Element;
-import org.eclipse.emf.cdo.releng.version.Release.Element.Type;
+import org.eclipse.emf.cdo.releng.version.Element.Type;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
@@ -168,7 +167,7 @@ public class ReleaseManager
return createElement(componentModel, false);
}
- private Element createElement(IModel componentModel, boolean withFeatureContent) throws CoreException
+ public Element createElement(IModel componentModel, boolean withFeatureContent) throws CoreException
{
if (componentModel instanceof IPluginModelBase)
{
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionBuilder.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionBuilder.java
index 1f48cab5eb..547fc54732 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionBuilder.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionBuilder.java
@@ -10,8 +10,6 @@
*/
package org.eclipse.emf.cdo.releng.version;
-import org.eclipse.emf.cdo.releng.version.Release.Element;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@@ -38,11 +36,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
/**
* @author Eike Stepper
*/
-public class VersionBuilder extends IncrementalProjectBuilder
+public class VersionBuilder extends IncrementalProjectBuilder implements ElementResolver
{
public static final String BUILDER_ID = "org.eclipse.emf.cdo.releng.version.VersionBuilder";
@@ -80,6 +79,24 @@ public class VersionBuilder extends IncrementalProjectBuilder
{
}
+ public Element resolveElement(Element key)
+ {
+ try
+ {
+ IModel componentModel = ReleaseManager.INSTANCE.getComponentModel(key);
+ if (componentModel != null)
+ {
+ return ReleaseManager.INSTANCE.createElement(componentModel, true);
+ }
+ }
+ catch (Exception ex)
+ {
+ Activator.log(ex);
+ }
+
+ return null;
+ }
+
@Override
protected final IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
throws CoreException
@@ -213,13 +230,13 @@ public class VersionBuilder extends IncrementalProjectBuilder
}
else if (change == MICRO_CHANGE)
{
- nextFeatureVersion = new Version(releaseVersion.getMajor(), releaseVersion.getMinor(),
- releaseVersion.getMicro() + 1);
+ nextFeatureVersion = nextImplVersion;
}
if (elementVersion.compareTo(nextFeatureVersion) < 0)
{
- addVersionMarker("Version should be " + nextFeatureVersion);
+ addVersionMarker("Version must be increased to " + nextFeatureVersion
+ + " because the feature's references have changed");
for (Entry<Element, Version> entry : warnings)
{
@@ -277,7 +294,8 @@ public class VersionBuilder extends IncrementalProjectBuilder
{
if (buildState.isChangedSinceRelease())
{
- addVersionMarker("Version must be increased to " + nextImplVersion);
+ addVersionMarker("Version must be increased to " + nextImplVersion
+ + " because the project's contents have changed");
}
}
catch (Exception ignore)
@@ -330,7 +348,7 @@ public class VersionBuilder extends IncrementalProjectBuilder
}
int biggestChange = NO_CHANGE;
- List<Element> allChildren = element.getAllChildren();
+ Set<Element> allChildren = element.getAllChildren(this);
for (Element child : allChildren)
{
int change = checkFeatureAPI(element, releasedElement, child, warnings);
@@ -343,7 +361,7 @@ public class VersionBuilder extends IncrementalProjectBuilder
}
}
- for (Element releasedElementsChild : releasedElement.getAllChildren())
+ for (Element releasedElementsChild : releasedElement.getAllChildren(release))
{
if (!allChildren.contains(releasedElementsChild))
{
@@ -363,7 +381,7 @@ public class VersionBuilder extends IncrementalProjectBuilder
return NO_CHANGE;
}
- Element releasedElementsChild = releasedElement.getChild(childElement);
+ Element releasedElementsChild = releasedElement.getChild(release, childElement);
if (releasedElementsChild == null)
{
addWarning(childElement, ADDITION, warnings);
@@ -433,7 +451,7 @@ public class VersionBuilder extends IncrementalProjectBuilder
{
return getPluginProject(name);
}
-
+
return getFeatureProject(name);
}
@@ -461,7 +479,7 @@ public class VersionBuilder extends IncrementalProjectBuilder
for (org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel : featureModels)
{
IResource resource = featureModel.getUnderlyingResource();
- if (resource != null)
+ if (resource != null && featureModel.getFeature().getId().equals(name))
{
return resource.getProject();
}

Back to the top