diff options
Diffstat (limited to 'plugins')
4 files changed, 345 insertions, 127 deletions
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 8933a80217..77fea92ee3 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 @@ -15,6 +15,9 @@ import org.eclipse.emf.cdo.releng.version.Release.Element.Type; 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.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.PluginRegistry; import org.osgi.framework.Version; import org.xml.sax.Attributes; @@ -24,10 +27,14 @@ import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParser; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -35,16 +42,39 @@ import java.util.Map; */ public class Release { + public static final String RELEASE_TAG = "release"; + + public static final String ELEMENT_TAG = "element"; + + public static final String INCLUDES_TAG = "includes"; + + public static final String TAG_ATTRIBUTE = "tag"; + + public static final String INTEGRATION_ATTRIBUTE = "integration"; + + public static final String TYPE_ATTRIBUTE = "type"; + + public static final String NAME_ATTRIBUTE = "name"; + + public static final String VERSION_ATTRIBUTE = "version"; + + private static final String INDENT = "\t"; + private IFile file; private String tag; private boolean integration; - private String repository; - private Map<Element, Element> elements = new HashMap<Element, Element>(); + public Release(IFile file) + { + this.file = file; + tag = ""; + integration = true; + } + Release(SAXParser parser, IFile file) throws CoreException, IOException, SAXException { this.file = file; @@ -88,14 +118,9 @@ public class Release return integration; } - public String getRepository() - { - return repository; - } - public Map<Element, Element> getElements() { - return Collections.unmodifiableMap(elements); + return elements; } public int getSize() @@ -103,9 +128,94 @@ public class Release return elements.size(); } - public static Version normalizeVersion(Version version) + public void write() throws IOException, CoreException + { + StringBuilder builder = new StringBuilder(); + writeRelease(builder); + + String xml = builder.toString(); + ByteArrayInputStream contents = new ByteArrayInputStream(xml.getBytes("UTF-8")); + if (file.exists()) + { + file.setContents(contents, true, true, new NullProgressMonitor()); + } + else + { + file.create(contents, true, new NullProgressMonitor()); + } + } + + private void writeRelease(StringBuilder builder) + { + builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + builder.append("<" + RELEASE_TAG + " " + TAG_ATTRIBUTE + "=\"\" " + INTEGRATION_ATTRIBUTE + "=\"" + integration + + "\">\n"); + + List<Element> list = new ArrayList<Element>(elements.keySet()); + Collections.sort(list, new Comparator<Element>() + { + public int compare(Element o1, Element o2) + { + int result = o1.getType().compareTo(o2.getType()); + if (result == 0) + { + result = o1.getName().compareTo(o2.getName()); + } + + if (result == 0) + { + result = o1.getVersion().compareTo(o2.getVersion()); + } + + return result; + } + }); + + for (Element element : list) + { + writeElement(builder, element, INDENT, ELEMENT_TAG); + } + + builder.append("</" + RELEASE_TAG + ">\n"); + } + + private void writeElement(StringBuilder builder, Element element, String indent, String tag) { - return new Version(version.getMajor(), version.getMinor(), version.getMicro()); + String type = element.getType().toString().toLowerCase(); + String name = element.getName(); + Version version = element.getVersion(); + + builder.append(indent + "<" + tag + " " + TYPE_ATTRIBUTE + "=\"" + type + "\" " + NAME_ATTRIBUTE + "=\"" + name + + "\" " + VERSION_ATTRIBUTE + "=\"" + version + "\""); + + List<Element> content = element.getContent(); + if (content.isEmpty()) + { + builder.append("/"); + writeElementEnd(builder, element); + } + else + { + writeElementEnd(builder, element); + + for (Element child : content) + { + writeElement(builder, child, indent + INDENT, INCLUDES_TAG); + } + + builder.append(indent + "</" + tag + ">\n"); + } + } + + private void writeElementEnd(StringBuilder builder, Element element) + { + builder.append(">"); + if (element.getVersion().equals(Version.emptyVersion)) + { + builder.append(" <!-- UNRESOLVED -->"); + } + + builder.append("\n"); } /** @@ -113,22 +223,30 @@ public class Release */ public static class Element { + private Type type; + private String name; private Version version; - private Type type; + private List<Element> content = new ArrayList<Element>(); - public Element(String name, Version version, Type type) + public Element(Type type, String name, Version version) { - this.name = name; - this.version = normalizeVersion(version); this.type = type; + this.name = name; + this.version = VersionUtil.normalize(version); + resolveVersion(); } - public Element(String name, String version, Type type) + public Element(Type type, String name, String version) { - this(name, new Version(version), type); + this(type, name, new Version(version)); + } + + public Type getType() + { + return type; } public String getName() @@ -141,6 +259,11 @@ public class Release return version; } + public List<Element> getContent() + { + return content; + } + @Override public int hashCode() { @@ -190,9 +313,57 @@ public class Release return true; } - public Type getType() + private void resolveVersion() { - return type; + if (version.equals(Version.emptyVersion)) + { + 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; + } + + @SuppressWarnings("restriction") + private Version getFeatureVersion(String name) + { + org.eclipse.pde.internal.core.ifeature.IFeatureModel[] featureModels = org.eclipse.pde.internal.core.PDECore + .getDefault().getFeatureModelManager().getModels(); + + for (org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel : featureModels) + { + org.eclipse.pde.internal.core.ifeature.IFeature feature = featureModel.getFeature(); + String id = feature.getId(); + if (id.equals(name)) + { + Version version = new Version(feature.getVersion()); + return VersionUtil.normalize(version); + } + } + + return null; } /** @@ -207,8 +378,10 @@ public class Release /** * @author Eike Stepper */ - private final class XMLHandler extends DefaultHandler + public class XMLHandler extends DefaultHandler { + private Element parent; + public XMLHandler() { } @@ -216,20 +389,38 @@ public class Release @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if ("release".equalsIgnoreCase(qName)) + if (RELEASE_TAG.equalsIgnoreCase(qName)) { - tag = getString(attributes, "tag"); - integration = getBoolean(attributes, "integration"); - repository = getString(attributes, "repository"); + tag = getString(attributes, TAG_ATTRIBUTE); + integration = getBoolean(attributes, INTEGRATION_ATTRIBUTE); } - else if ("element".equalsIgnoreCase(qName)) + else if (ELEMENT_TAG.equalsIgnoreCase(qName)) { - String name = getString(attributes, "name"); - Version version = new Version(getString(attributes, "version")); - Type type = getType(attributes, "type"); + parent = createElement(attributes); + elements.put(parent, parent); + } + else if (INCLUDES_TAG.equalsIgnoreCase(qName)) + { + Element child = createElement(attributes); + parent.getContent().add(child); + } + } - Element element = new Element(name, version, type); - elements.put(element, element); + private Element createElement(Attributes attributes) throws SAXException + { + Type type = getType(attributes, TYPE_ATTRIBUTE); + String name = getString(attributes, NAME_ATTRIBUTE); + Version version = new Version(getString(attributes, VERSION_ATTRIBUTE)); + + return new Element(type, name, version); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException + { + if (ELEMENT_TAG.equalsIgnoreCase(qName)) + { + parent = null; } } @@ -262,18 +453,8 @@ public class Release private Type getType(Attributes attributes, String name) throws SAXException { - String type = getString(attributes, name); - if ("org.eclipse.update.feature".equals(type)) - { - return Type.FEATURE; - } - - if ("osgi.bundle".equals(type)) - { - return Type.PLUGIN; - } - - throw new SAXException("Illegal value for " + name); + String type = getString(attributes, name).toUpperCase(); + return Type.valueOf(type); } @Override 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 c086e3ab79..8e6b7aee2a 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,11 +10,22 @@ */ 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.core.resources.ICommand; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.pde.core.IModel; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.osgi.framework.Version; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; @@ -22,6 +33,7 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Map; import java.util.Map.Entry; import java.util.WeakHashMap; @@ -89,4 +101,89 @@ public class ReleaseManager throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getLocalizedMessage(), ex)); } } + + public synchronized Release createRelease(IFile file) throws CoreException, IOException + { + Release release = new Release(file); + String path = file.getFullPath().toString(); + + for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) + { + if (project.isOpen()) + { + IProjectDescription desc = project.getDescription(); + ICommand[] commands = desc.getBuildSpec(); + + for (int i = 0; i < commands.length; ++i) + { + if (commands[i].getBuilderName().equals(VersionBuilder.BUILDER_ID)) + { + Map<String, String> arguments = commands[i].getArguments(); + if (arguments != null) + { + String releasePath = arguments.get(VersionBuilder.RELEASE_PATH_ARGUMENT); + if (path.equals(releasePath)) + { + IModel componentModel = VersionBuilder.getComponentModel(project); + Element element = createElement(componentModel, true); + release.getElements().put(element, element); + } + } + } + } + } + } + + release.write(); + releases.put(release, file.getLocalTimeStamp()); + return release; + } + + public Element createElement(IModel componentModel) throws CoreException + { + return createElement(componentModel, false); + } + + private Element createElement(IModel componentModel, boolean withFeatureContent) throws CoreException + { + if (componentModel instanceof IPluginModelBase) + { + IPluginModelBase pluginModel = (IPluginModelBase)componentModel; + BundleDescription description = pluginModel.getBundleDescription(); + + String name = description.getSymbolicName(); + Version version = description.getVersion(); + return new Element(Type.PLUGIN, name, version); + } + + return createFeatureElement(componentModel, withFeatureContent); + } + + @SuppressWarnings("restriction") + private Element createFeatureElement(IModel componentModel, boolean withContent) + { + org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel = (org.eclipse.pde.internal.core.ifeature.IFeatureModel)componentModel; + org.eclipse.pde.internal.core.ifeature.IFeature feature = featureModel.getFeature(); + + String name = feature.getId(); + Version version = new Version(feature.getVersion()); + Element element = new Element(Type.FEATURE, name, version); + + if (withContent) + { + for (org.eclipse.pde.internal.core.ifeature.IFeatureChild versionable : feature.getIncludedFeatures()) + { + Element child = new Element(Element.Type.FEATURE, versionable.getId(), versionable.getVersion()); + element.getContent().add(child); + } + + for (org.eclipse.pde.internal.core.ifeature.IFeaturePlugin versionable : feature.getPlugins()) + { + Element child = new Element(Element.Type.PLUGIN, versionable.getId(), versionable.getVersion()); + element.getContent().add(child); + } + } + + return element; + } } 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 372c3c01a4..7b527cf27d 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 @@ -11,7 +11,6 @@ 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.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -112,7 +111,16 @@ public class VersionBuilder extends IncrementalProjectBuilder IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(releasePath)); buildDpependencies.add(file.getProject()); - Release release = ReleaseManager.INSTANCE.getRelease(file); + Release release; + if (!file.exists()) + { + release = ReleaseManager.INSTANCE.createRelease(file); + } + else + { + release = ReleaseManager.INSTANCE.getRelease(file); + } + boolean releaseHasChanged = !release.getTag().equals(buildState.getReleaseTag()); if (releaseHasChanged) { @@ -124,8 +132,9 @@ public class VersionBuilder extends IncrementalProjectBuilder } catch (CoreException ex) { + ex.printStackTrace(); String msg = "Problem with release spec: " + releasePath; - Markers.addMarker(projectDescription, msg, IMarker.SEVERITY_ERROR, releasePath); + Markers.addMarker(projectDescription, msg, IMarker.SEVERITY_ERROR, "(" + releasePath.replace(".", "\\.") + ")"); return buildDpependencies.toArray(new IProject[buildDpependencies.size()]); } @@ -133,7 +142,7 @@ public class VersionBuilder extends IncrementalProjectBuilder * Determine if a validation is needed or if the version has already been increased properly */ - Element element = createElement(componentModel); + Element element = ReleaseManager.INSTANCE.createElement(componentModel); Element releaseElement = release.getElements().get(element); if (releaseElement == null) { @@ -306,7 +315,7 @@ public class VersionBuilder extends IncrementalProjectBuilder for (org.eclipse.pde.internal.core.ifeature.IFeatureChild versionable : feature.getIncludedFeatures()) { String id = versionable.getId(); - Element element = new Element(id, versionable.getVersion(), Element.Type.FEATURE); + Element element = new Element(Element.Type.FEATURE, id, versionable.getVersion()); int change = checkFeatureAPI(element, warnings); biggestChange = Math.max(biggestChange, change); @@ -319,7 +328,7 @@ public class VersionBuilder extends IncrementalProjectBuilder for (org.eclipse.pde.internal.core.ifeature.IFeaturePlugin versionable : feature.getPlugins()) { - Element element = new Element(versionable.getId(), versionable.getVersion(), Element.Type.PLUGIN); + Element element = new Element(Element.Type.PLUGIN, versionable.getId(), versionable.getVersion()); int change = checkFeatureAPI(element, warnings); biggestChange = Math.max(biggestChange, change); @@ -328,7 +337,6 @@ public class VersionBuilder extends IncrementalProjectBuilder { buildDpependencies.add(project); } - } return biggestChange; @@ -342,23 +350,11 @@ public class VersionBuilder extends IncrementalProjectBuilder if (releasedElement != null) { Version releasedVersion = releasedElement.getVersion(); - Version version = element.getVersion(); - if (version.equals(Version.emptyVersion)) - { - if (element.getType() == Element.Type.PLUGIN) - { - version = getPluginVersion(element.getName()); - } - else - { - version = getFeatureVersion(element.getName()); - } - if (version == null) - { - return NO_CHANGE; - } + if (version == null) + { + return NO_CHANGE; } if (version.getMajor() != releasedVersion.getMajor()) @@ -408,38 +404,6 @@ public class VersionBuilder extends IncrementalProjectBuilder }); } - private Version getPluginVersion(String name) - { - IPluginModelBase pluginModel = PluginRegistry.findModel(name); - if (pluginModel != null) - { - Version version = pluginModel.getBundleDescription().getVersion(); - return stripQualifier(version); - } - - return null; - } - - @SuppressWarnings("restriction") - private Version getFeatureVersion(String name) - { - org.eclipse.pde.internal.core.ifeature.IFeatureModel[] featureModels = org.eclipse.pde.internal.core.PDECore - .getDefault().getFeatureModelManager().getModels(); - - for (org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel : featureModels) - { - org.eclipse.pde.internal.core.ifeature.IFeature feature = featureModel.getFeature(); - String id = feature.getId(); - if (id.equals(name)) - { - Version version = new Version(feature.getVersion()); - return stripQualifier(version); - } - } - - return null; - } - private IProject getPluginProject(String name) { IPluginModelBase pluginModel = PluginRegistry.findModel(name); @@ -473,37 +437,6 @@ public class VersionBuilder extends IncrementalProjectBuilder return null; } - private Version stripQualifier(Version version) - { - return new Version(version.getMajor(), version.getMinor(), version.getMicro()); - } - - private Element createElement(IModel componentModel) throws CoreException - { - if (componentModel instanceof IPluginModelBase) - { - IPluginModelBase pluginModel = (IPluginModelBase)componentModel; - BundleDescription description = pluginModel.getBundleDescription(); - - String name = description.getSymbolicName(); - Version version = description.getVersion(); - return new Element(name, version, Type.PLUGIN); - } - - return createFeatureElement(componentModel); - } - - @SuppressWarnings("restriction") - private Element createFeatureElement(IModel componentModel) - { - org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel = (org.eclipse.pde.internal.core.ifeature.IFeatureModel)componentModel; - org.eclipse.pde.internal.core.ifeature.IFeature feature = featureModel.getFeature(); - - String name = feature.getId(); - Version version = new Version(feature.getVersion()); - return new Element(name, version, Type.FEATURE); - } - private void checkDependencyRanges(IPluginModelBase pluginModel) throws CoreException, IOException { BundleDescription description = pluginModel.getBundleDescription(); @@ -586,7 +519,7 @@ public class VersionBuilder extends IncrementalProjectBuilder { BundleDescription description = pluginModel.getBundleDescription(); String bundleName = description.getSymbolicName(); - Version bundleVersion = Release.normalizeVersion(description.getVersion()); + Version bundleVersion = VersionUtil.normalize(description.getVersion()); for (ExportPackageDescription packageExport : description.getExportPackages()) { diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java index d4f5e4f84e..236d9a3c84 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java @@ -10,11 +10,18 @@ */ package org.eclipse.emf.cdo.releng.version; +import org.osgi.framework.Version; + /** * @author Eike Stepper */ public class VersionUtil { + public static Version normalize(Version version) + { + return new Version(version.getMajor(), version.getMinor(), version.getMicro()); + } + /** * @deprecated This method exists so that others can produce a reliable compiler warning by calling it. A * <code>@SuppressWarnings("deprecation")</code> annotation will never become unnecessary then. |