diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng')
8 files changed, 1037 insertions, 1037 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Activator.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Activator.java index 3edead4465..512790ddfa 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Activator.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Activator.java @@ -1,207 +1,207 @@ -/*
- * 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.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.core.runtime.Status;
-
-import org.osgi.framework.BundleContext;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * @author Eike Stepper
- */
-public class Activator extends Plugin
-{
- public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.version";
-
- private static Activator plugin;
-
- private Map<String, BuildState> buildStates;
-
- private File stateFile;
-
- public Activator()
- {
- }
-
- @Override
- public void start(BundleContext context) throws Exception
- {
- super.start(context);
- plugin = this;
-
- try
- {
- File stateFolder = Platform.getStateLocation(getBundle()).toFile();
- stateFile = new File(stateFolder, "buildStates.bin");
- if (stateFile.exists())
- {
- loadBuildStates();
- stateFile.delete(); // Future indication for possible workspace crash
- }
- }
- finally
- {
- if (buildStates == null)
- {
- buildStates = new HashMap<String, BuildState>();
- }
-
- }
- }
-
- @Override
- public void stop(BundleContext context) throws Exception
- {
- if (!buildStates.isEmpty())
- {
- saveBuildStates();
- }
-
- stateFile = null;
- plugin = null;
- super.stop(context);
- }
-
- private void loadBuildStates()
- {
- ObjectInputStream stream = null;
-
- try
- {
- stream = new ObjectInputStream(new FileInputStream(stateFile));
- @SuppressWarnings("unchecked")
- Map<String, BuildState> object = (Map<String, BuildState>)stream.readObject();
- buildStates = object;
- }
- catch (Exception ex)
- {
- log(ex);
- }
- finally
- {
- if (stream != null)
- {
- try
- {
- stream.close();
- }
- catch (Exception ex)
- {
- log(ex);
- }
- }
- }
- }
-
- private void saveBuildStates()
- {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- for (Iterator<Entry<String, BuildState>> it = buildStates.entrySet().iterator(); it.hasNext();)
- {
- Entry<String, BuildState> entry = it.next();
- IProject project = root.getProject(entry.getKey());
- if (!project.exists())
- {
- it.remove();
- }
- }
-
- ObjectOutputStream stream = null;
-
- try
- {
- stream = new ObjectOutputStream(new FileOutputStream(stateFile));
- stream.writeObject(buildStates);
- }
- catch (Exception ex)
- {
- log(ex);
- }
- finally
- {
- if (stream != null)
- {
- try
- {
- stream.close();
- }
- catch (Exception ex)
- {
- log(ex);
- }
- }
- }
- }
-
- public static BuildState getBuildState(IProject project)
- {
- String name = project.getName();
- BuildState buildState = plugin.buildStates.get(name);
- if (buildState == null)
- {
- buildState = new BuildState();
- plugin.buildStates.put(name, buildState);
- }
-
- return buildState;
- }
-
- public static void log(String message)
- {
- plugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
- }
-
- public static void log(IStatus status)
- {
- plugin.getLog().log(status);
- }
-
- public static String log(Throwable t)
- {
- IStatus status = getStatus(t);
- log(status);
- return status.getMessage();
- }
-
- public static IStatus getStatus(Throwable t)
- {
- if (t instanceof CoreException)
- {
- CoreException coreException = (CoreException)t;
- return coreException.getStatus();
- }
-
- String msg = t.getLocalizedMessage();
- if (msg == null || msg.length() == 0)
- {
- msg = t.getClass().getName();
- }
-
- return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
- }
-}
+/* + * 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.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; + +import org.osgi.framework.BundleContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +/** + * @author Eike Stepper + */ +public class Activator extends Plugin +{ + public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.version"; + + private static Activator plugin; + + private Map<String, BuildState> buildStates; + + private File stateFile; + + public Activator() + { + } + + @Override + public void start(BundleContext context) throws Exception + { + super.start(context); + plugin = this; + + try + { + File stateFolder = Platform.getStateLocation(getBundle()).toFile(); + stateFile = new File(stateFolder, "buildStates.bin"); + if (stateFile.exists()) + { + loadBuildStates(); + stateFile.delete(); // Future indication for possible workspace crash + } + } + finally + { + if (buildStates == null) + { + buildStates = new HashMap<String, BuildState>(); + } + + } + } + + @Override + public void stop(BundleContext context) throws Exception + { + if (!buildStates.isEmpty()) + { + saveBuildStates(); + } + + stateFile = null; + plugin = null; + super.stop(context); + } + + private void loadBuildStates() + { + ObjectInputStream stream = null; + + try + { + stream = new ObjectInputStream(new FileInputStream(stateFile)); + @SuppressWarnings("unchecked") + Map<String, BuildState> object = (Map<String, BuildState>)stream.readObject(); + buildStates = object; + } + catch (Exception ex) + { + log(ex); + } + finally + { + if (stream != null) + { + try + { + stream.close(); + } + catch (Exception ex) + { + log(ex); + } + } + } + } + + private void saveBuildStates() + { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + for (Iterator<Entry<String, BuildState>> it = buildStates.entrySet().iterator(); it.hasNext();) + { + Entry<String, BuildState> entry = it.next(); + IProject project = root.getProject(entry.getKey()); + if (!project.exists()) + { + it.remove(); + } + } + + ObjectOutputStream stream = null; + + try + { + stream = new ObjectOutputStream(new FileOutputStream(stateFile)); + stream.writeObject(buildStates); + } + catch (Exception ex) + { + log(ex); + } + finally + { + if (stream != null) + { + try + { + stream.close(); + } + catch (Exception ex) + { + log(ex); + } + } + } + } + + public static BuildState getBuildState(IProject project) + { + String name = project.getName(); + BuildState buildState = plugin.buildStates.get(name); + if (buildState == null) + { + buildState = new BuildState(); + plugin.buildStates.put(name, buildState); + } + + return buildState; + } + + public static void log(String message) + { + plugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); + } + + public static void log(IStatus status) + { + plugin.getLog().log(status); + } + + public static String log(Throwable t) + { + IStatus status = getStatus(t); + log(status); + return status.getMessage(); + } + + public static IStatus getStatus(Throwable t) + { + if (t instanceof CoreException) + { + CoreException coreException = (CoreException)t; + return coreException.getStatus(); + } + + String msg = t.getLocalizedMessage(); + if (msg == null || msg.length() == 0) + { + msg = t.getClass().getName(); + } + + return new Status(IStatus.ERROR, PLUGIN_ID, msg, t); + } +} diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/BuildState.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/BuildState.java index e54953e42c..64a27b5f5d 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/BuildState.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/BuildState.java @@ -1,61 +1,61 @@ -/*
- * 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 java.io.Serializable;
-
-/**
- * @author Eike Stepper
- */
-public class BuildState implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- private String releaseTag;
-
- private boolean changedSinceRelease;
-
- private Serializable validatorState;
-
- BuildState()
- {
- }
-
- void setReleaseTag(String releaseTag)
- {
- this.releaseTag = releaseTag;
- }
-
- public String getReleaseTag()
- {
- return releaseTag;
- }
-
- public boolean isChangedSinceRelease()
- {
- return changedSinceRelease;
- }
-
- public void setChangedSinceRelease(boolean changedSinceRelease)
- {
- this.changedSinceRelease = changedSinceRelease;
- }
-
- public Serializable getValidatorState()
- {
- return validatorState;
- }
-
- public void setValidatorState(Serializable validatorState)
- {
- this.validatorState = validatorState;
- }
-}
+/* + * 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 java.io.Serializable; + +/** + * @author Eike Stepper + */ +public class BuildState implements Serializable +{ + private static final long serialVersionUID = 1L; + + private String releaseTag; + + private boolean changedSinceRelease; + + private Serializable validatorState; + + BuildState() + { + } + + void setReleaseTag(String releaseTag) + { + this.releaseTag = releaseTag; + } + + public String getReleaseTag() + { + return releaseTag; + } + + public boolean isChangedSinceRelease() + { + return changedSinceRelease; + } + + public void setChangedSinceRelease(boolean changedSinceRelease) + { + this.changedSinceRelease = changedSinceRelease; + } + + public Serializable getValidatorState() + { + return validatorState; + } + + public void setValidatorState(Serializable validatorState) + { + this.validatorState = validatorState; + } +} diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java index bd6d63e492..3ffbe0c1dc 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java @@ -1,135 +1,135 @@ -/*
- * 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.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * @author Eike Stepper
- */
-public final class Markers
-{
- public static final String MARKER_TYPE = "org.eclipse.emf.cdo.releng.version.VersionProblem"; //$NON-NLS-1$
-
- private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
-
- private Markers()
- {
- }
-
- public static void addMarker(IResource resource, String message) throws CoreException
- {
- addMarker(resource, message, IMarker.SEVERITY_ERROR);
- }
-
- public static void addMarker(IResource resource, String message, int severity) throws CoreException
- {
- IMarker marker = resource.createMarker(MARKER_TYPE);
- marker.setAttribute(IMarker.MESSAGE, message);
- marker.setAttribute(IMarker.SEVERITY, severity);
- }
-
- public static void addMarker(IResource resource, String message, int severity, int lineNumber) throws CoreException
- {
- IMarker marker = resource.createMarker(MARKER_TYPE);
- marker.setAttribute(IMarker.MESSAGE, message);
- marker.setAttribute(IMarker.SEVERITY, severity);
- if (lineNumber == -1)
- {
- lineNumber = 1;
- }
-
- marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
- }
-
- public static void addMarker(IFile file, String message, int severity, int lineNumber, int charStart, int charEnd)
- throws CoreException
- {
- if (lineNumber < 1)
- {
- lineNumber = 1;
- }
-
- IMarker marker = file.createMarker(MARKER_TYPE);
- marker.setAttribute(IMarker.MESSAGE, message);
- marker.setAttribute(IMarker.SEVERITY, severity);
- marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
- marker.setAttribute(IMarker.CHAR_START, charStart);
- marker.setAttribute(IMarker.CHAR_END, charEnd);
- }
-
- public static void addMarker(IFile file, String message, int severity, String regex) throws CoreException,
- IOException
- {
- Pattern pattern = Pattern.compile(regex);
- InputStream contents = null;
-
- try
- {
- contents = file.getContents();
- BufferedReader reader = new BufferedReader(new InputStreamReader(contents));
-
- String line;
- int lineNumber = 1;
- int charNumber = 0;
- while ((line = reader.readLine()) != null)
- {
- Matcher matcher = pattern.matcher(line);
- if (matcher.matches())
- {
- int startChar = charNumber + matcher.start(1);
- int endChar = charNumber + matcher.end(1);
- addMarker(file, message, severity, lineNumber, startChar, endChar);
- return;
- }
-
- lineNumber += 1;
- charNumber += line.length() + NL.length();
- }
- }
- finally
- {
- if (contents != null)
- {
- try
- {
- contents.close();
- }
- catch (Exception ex)
- {
- Activator.log(ex);
- }
- }
- }
-
- addMarker(file, message, severity);
- }
-
- public static void deleteMarkers(IResource resource) throws CoreException
- {
- resource.deleteMarkers(Markers.MARKER_TYPE, false, IResource.DEPTH_ZERO);
- }
-
- public static void deleteAllMarkers(IResource resource) throws CoreException
- {
- resource.deleteMarkers(Markers.MARKER_TYPE, false, IResource.DEPTH_INFINITE);
- }
-}
+/* + * 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.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Eike Stepper + */ +public final class Markers +{ + public static final String MARKER_TYPE = "org.eclipse.emf.cdo.releng.version.VersionProblem"; //$NON-NLS-1$ + + private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$ + + private Markers() + { + } + + public static void addMarker(IResource resource, String message) throws CoreException + { + addMarker(resource, message, IMarker.SEVERITY_ERROR); + } + + public static void addMarker(IResource resource, String message, int severity) throws CoreException + { + IMarker marker = resource.createMarker(MARKER_TYPE); + marker.setAttribute(IMarker.MESSAGE, message); + marker.setAttribute(IMarker.SEVERITY, severity); + } + + public static void addMarker(IResource resource, String message, int severity, int lineNumber) throws CoreException + { + IMarker marker = resource.createMarker(MARKER_TYPE); + marker.setAttribute(IMarker.MESSAGE, message); + marker.setAttribute(IMarker.SEVERITY, severity); + if (lineNumber == -1) + { + lineNumber = 1; + } + + marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); + } + + public static void addMarker(IFile file, String message, int severity, int lineNumber, int charStart, int charEnd) + throws CoreException + { + if (lineNumber < 1) + { + lineNumber = 1; + } + + IMarker marker = file.createMarker(MARKER_TYPE); + marker.setAttribute(IMarker.MESSAGE, message); + marker.setAttribute(IMarker.SEVERITY, severity); + marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); + marker.setAttribute(IMarker.CHAR_START, charStart); + marker.setAttribute(IMarker.CHAR_END, charEnd); + } + + public static void addMarker(IFile file, String message, int severity, String regex) throws CoreException, + IOException + { + Pattern pattern = Pattern.compile(regex); + InputStream contents = null; + + try + { + contents = file.getContents(); + BufferedReader reader = new BufferedReader(new InputStreamReader(contents)); + + String line; + int lineNumber = 1; + int charNumber = 0; + while ((line = reader.readLine()) != null) + { + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) + { + int startChar = charNumber + matcher.start(1); + int endChar = charNumber + matcher.end(1); + addMarker(file, message, severity, lineNumber, startChar, endChar); + return; + } + + lineNumber += 1; + charNumber += line.length() + NL.length(); + } + } + finally + { + if (contents != null) + { + try + { + contents.close(); + } + catch (Exception ex) + { + Activator.log(ex); + } + } + } + + addMarker(file, message, severity); + } + + public static void deleteMarkers(IResource resource) throws CoreException + { + resource.deleteMarkers(Markers.MARKER_TYPE, false, IResource.DEPTH_ZERO); + } + + public static void deleteAllMarkers(IResource resource) throws CoreException + { + resource.deleteMarkers(Markers.MARKER_TYPE, false, IResource.DEPTH_INFINITE); + } +} 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 55a87a4ad0..c8d874f937 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 @@ -1,255 +1,255 @@ -/*
- * 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.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.osgi.framework.Version;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.SAXParser;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class Release
-{
- private IFile file;
-
- private String tag;
-
- private boolean integration;
-
- private String repository;
-
- private Map<String, Element> elements = new HashMap<String, Element>();
-
- Release(SAXParser parser, IFile file) throws CoreException, IOException, SAXException
- {
- this.file = file;
-
- XMLHandler handler = new XMLHandler();
- InputStream contents = null;
-
- try
- {
- contents = file.getContents();
- parser.parse(contents, handler);
- }
- finally
- {
- if (contents != null)
- {
- try
- {
- contents.close();
- }
- catch (Exception ex)
- {
- Activator.log(ex);
- }
- }
- }
- }
-
- public IFile getFile()
- {
- return file;
- }
-
- public String getTag()
- {
- return tag;
- }
-
- public boolean isIntegration()
- {
- return integration;
- }
-
- public String getRepository()
- {
- return repository;
- }
-
- public Map<String, Element> getElements()
- {
- return Collections.unmodifiableMap(elements);
- }
-
- public int getSize()
- {
- return elements.size();
- }
-
- public static Version normalizeVersion(Version version)
- {
- return new Version(version.getMajor(), version.getMinor(), version.getMicro());
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Element
- {
- private String name;
-
- private Version version;
-
- private Type type;
-
- public Element(String name, Version version, Type type)
- {
- this.name = name;
- this.version = normalizeVersion(version);
- this.type = type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Version getVersion()
- {
- return version;
- }
-
- public Type getType()
- {
- return type;
- }
-
- /**
- * @author Eike Stepper
- */
- public static enum Type
- {
- FEATURE, PLUGIN
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class XMLHandler extends DefaultHandler
- {
- public XMLHandler()
- {
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
- {
- if ("release".equalsIgnoreCase(qName))
- {
- tag = getString(attributes, "tag");
- integration = getBoolean(attributes, "integration");
- repository = getString(attributes, "repository");
- }
- else if ("element".equalsIgnoreCase(qName))
- {
- String name = getString(attributes, "name");
- Version version = new Version(getString(attributes, "version"));
- Type type = getType(attributes, "type");
-
- Element element = new Element(name, version, type);
- elements.put(name, element);
- }
- }
-
- private String getString(Attributes attributes, String name) throws SAXException
- {
- String value = attributes.getValue(name);
- if (value != null)
- {
- return value;
- }
-
- throw new SAXException("Illegal value for " + name);
- }
-
- private boolean getBoolean(Attributes attributes, String name) throws SAXException
- {
- String value = attributes.getValue(name);
- if ("false".equalsIgnoreCase(value))
- {
- return false;
- }
-
- if ("true".equalsIgnoreCase(value))
- {
- return true;
- }
-
- throw new SAXException("Illegal value for " + name);
- }
-
- 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);
- }
-
- @Override
- public void error(SAXParseException exception) throws SAXException
- {
- addMarker(exception, IMarker.SEVERITY_ERROR);
- }
-
- @Override
- public void fatalError(SAXParseException exception) throws SAXException
- {
- addMarker(exception, IMarker.SEVERITY_ERROR);
- }
-
- @Override
- public void warning(SAXParseException exception) throws SAXException
- {
- addMarker(exception, IMarker.SEVERITY_WARNING);
- }
-
- private void addMarker(SAXParseException e, int severity)
- {
- try
- {
- Markers.addMarker(file, e.getMessage(), severity, e.getLineNumber());
- }
- catch (Exception ex)
- {
- Activator.log(ex);
- }
- }
- }
-}
+/* + * 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.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.osgi.framework.Version; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +import javax.xml.parsers.SAXParser; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Eike Stepper + */ +public class Release +{ + private IFile file; + + private String tag; + + private boolean integration; + + private String repository; + + private Map<String, Element> elements = new HashMap<String, Element>(); + + Release(SAXParser parser, IFile file) throws CoreException, IOException, SAXException + { + this.file = file; + + XMLHandler handler = new XMLHandler(); + InputStream contents = null; + + try + { + contents = file.getContents(); + parser.parse(contents, handler); + } + finally + { + if (contents != null) + { + try + { + contents.close(); + } + catch (Exception ex) + { + Activator.log(ex); + } + } + } + } + + public IFile getFile() + { + return file; + } + + public String getTag() + { + return tag; + } + + public boolean isIntegration() + { + return integration; + } + + public String getRepository() + { + return repository; + } + + public Map<String, Element> getElements() + { + return Collections.unmodifiableMap(elements); + } + + public int getSize() + { + return elements.size(); + } + + public static Version normalizeVersion(Version version) + { + return new Version(version.getMajor(), version.getMinor(), version.getMicro()); + } + + /** + * @author Eike Stepper + */ + public static class Element + { + private String name; + + private Version version; + + private Type type; + + public Element(String name, Version version, Type type) + { + this.name = name; + this.version = normalizeVersion(version); + this.type = type; + } + + public String getName() + { + return name; + } + + public Version getVersion() + { + return version; + } + + public Type getType() + { + return type; + } + + /** + * @author Eike Stepper + */ + public static enum Type + { + FEATURE, PLUGIN + } + } + + /** + * @author Eike Stepper + */ + private final class XMLHandler extends DefaultHandler + { + public XMLHandler() + { + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException + { + if ("release".equalsIgnoreCase(qName)) + { + tag = getString(attributes, "tag"); + integration = getBoolean(attributes, "integration"); + repository = getString(attributes, "repository"); + } + else if ("element".equalsIgnoreCase(qName)) + { + String name = getString(attributes, "name"); + Version version = new Version(getString(attributes, "version")); + Type type = getType(attributes, "type"); + + Element element = new Element(name, version, type); + elements.put(name, element); + } + } + + private String getString(Attributes attributes, String name) throws SAXException + { + String value = attributes.getValue(name); + if (value != null) + { + return value; + } + + throw new SAXException("Illegal value for " + name); + } + + private boolean getBoolean(Attributes attributes, String name) throws SAXException + { + String value = attributes.getValue(name); + if ("false".equalsIgnoreCase(value)) + { + return false; + } + + if ("true".equalsIgnoreCase(value)) + { + return true; + } + + throw new SAXException("Illegal value for " + name); + } + + 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); + } + + @Override + public void error(SAXParseException exception) throws SAXException + { + addMarker(exception, IMarker.SEVERITY_ERROR); + } + + @Override + public void fatalError(SAXParseException exception) throws SAXException + { + addMarker(exception, IMarker.SEVERITY_ERROR); + } + + @Override + public void warning(SAXParseException exception) throws SAXException + { + addMarker(exception, IMarker.SEVERITY_WARNING); + } + + private void addMarker(SAXParseException e, int severity) + { + try + { + Markers.addMarker(file, e.getMessage(), severity, e.getLineNumber()); + } + catch (Exception ex) + { + Activator.log(ex); + } + } + } +} 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 bf9f8c09be..c086e3ab79 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 @@ -1,92 +1,92 @@ -/*
- * 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.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import java.io.FileNotFoundException;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.WeakHashMap;
-
-/**
- * @author Eike Stepper
- */
-public class ReleaseManager
-{
- public static final ReleaseManager INSTANCE = new ReleaseManager();
-
- private Map<Release, Long> releases = new WeakHashMap<Release, Long>();
-
- private SAXParserFactory parserFactory;
-
- private ReleaseManager()
- {
- }
-
- private SAXParser getParser() throws ParserConfigurationException, SAXException
- {
- if (parserFactory == null)
- {
- parserFactory = SAXParserFactory.newInstance();
- }
-
- return parserFactory.newSAXParser();
- }
-
- public synchronized Release getRelease(IFile file) throws CoreException
- {
- try
- {
- for (Entry<Release, Long> entry : releases.entrySet())
- {
- Release release = entry.getKey();
- if (release.getFile().equals(file))
- {
- long timeStamp = entry.getValue();
- if (file.getLocalTimeStamp() == timeStamp)
- {
- return release;
- }
-
- releases.remove(release);
- break;
- }
- }
-
- if (!file.exists())
- {
- throw new FileNotFoundException(file.getFullPath().toString());
- }
-
- Release release = new Release(getParser(), file);
- releases.put(release, file.getLocalTimeStamp());
- return release;
- }
- catch (CoreException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getLocalizedMessage(), ex));
- }
- }
-}
+/* + * 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.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import java.io.FileNotFoundException; +import java.util.Map; +import java.util.Map.Entry; +import java.util.WeakHashMap; + +/** + * @author Eike Stepper + */ +public class ReleaseManager +{ + public static final ReleaseManager INSTANCE = new ReleaseManager(); + + private Map<Release, Long> releases = new WeakHashMap<Release, Long>(); + + private SAXParserFactory parserFactory; + + private ReleaseManager() + { + } + + private SAXParser getParser() throws ParserConfigurationException, SAXException + { + if (parserFactory == null) + { + parserFactory = SAXParserFactory.newInstance(); + } + + return parserFactory.newSAXParser(); + } + + public synchronized Release getRelease(IFile file) throws CoreException + { + try + { + for (Entry<Release, Long> entry : releases.entrySet()) + { + Release release = entry.getKey(); + if (release.getFile().equals(file)) + { + long timeStamp = entry.getValue(); + if (file.getLocalTimeStamp() == timeStamp) + { + return release; + } + + releases.remove(release); + break; + } + } + + if (!file.exists()) + { + throw new FileNotFoundException(file.getFullPath().toString()); + } + + Release release = new Release(getParser(), file); + releases.put(release, file.getLocalTimeStamp()); + return release; + } + catch (CoreException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getLocalizedMessage(), ex)); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionNature.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionNature.java index c48c3e317b..e961aea5a2 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionNature.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionNature.java @@ -1,81 +1,81 @@ -/*
- * 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.core.resources.ICommand;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IProjectNature;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * @author Eike Stepper
- */
-public class VersionNature implements IProjectNature
-{
- public static final String NATURE_ID = "org.eclipse.emf.cdo.releng.version.VersionNature";
-
- private IProject project;
-
- public VersionNature()
- {
- }
-
- public IProject getProject()
- {
- return project;
- }
-
- public void setProject(IProject project)
- {
- this.project = project;
- }
-
- public void configure() throws CoreException
- {
- IProjectDescription desc = project.getDescription();
- ICommand[] commands = desc.getBuildSpec();
-
- for (int i = 0; i < commands.length; ++i)
- {
- if (commands[i].getBuilderName().equals(VersionBuilder.BUILDER_ID))
- {
- return;
- }
- }
-
- ICommand[] newCommands = new ICommand[commands.length + 1];
- System.arraycopy(commands, 0, newCommands, 0, commands.length);
- ICommand command = desc.newCommand();
- command.setBuilderName(VersionBuilder.BUILDER_ID);
- newCommands[newCommands.length - 1] = command;
- desc.setBuildSpec(newCommands);
- project.setDescription(desc, null);
- }
-
- public void deconfigure() throws CoreException
- {
- IProjectDescription description = getProject().getDescription();
- ICommand[] commands = description.getBuildSpec();
- for (int i = 0; i < commands.length; ++i)
- {
- if (commands[i].getBuilderName().equals(VersionBuilder.BUILDER_ID))
- {
- ICommand[] newCommands = new ICommand[commands.length - 1];
- System.arraycopy(commands, 0, newCommands, 0, i);
- System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
- description.setBuildSpec(newCommands);
- project.setDescription(description, null);
- return;
- }
- }
- }
-}
+/* + * 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.core.resources.ICommand; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +/** + * @author Eike Stepper + */ +public class VersionNature implements IProjectNature +{ + public static final String NATURE_ID = "org.eclipse.emf.cdo.releng.version.VersionNature"; + + private IProject project; + + public VersionNature() + { + } + + public IProject getProject() + { + return project; + } + + public void setProject(IProject project) + { + this.project = project; + } + + public void configure() throws CoreException + { + IProjectDescription desc = project.getDescription(); + ICommand[] commands = desc.getBuildSpec(); + + for (int i = 0; i < commands.length; ++i) + { + if (commands[i].getBuilderName().equals(VersionBuilder.BUILDER_ID)) + { + return; + } + } + + ICommand[] newCommands = new ICommand[commands.length + 1]; + System.arraycopy(commands, 0, newCommands, 0, commands.length); + ICommand command = desc.newCommand(); + command.setBuilderName(VersionBuilder.BUILDER_ID); + newCommands[newCommands.length - 1] = command; + desc.setBuildSpec(newCommands); + project.setDescription(desc, null); + } + + public void deconfigure() throws CoreException + { + IProjectDescription description = getProject().getDescription(); + ICommand[] commands = description.getBuildSpec(); + for (int i = 0; i < commands.length; ++i) + { + if (commands[i].getBuilderName().equals(VersionBuilder.BUILDER_ID)) + { + ICommand[] newCommands = new ICommand[commands.length - 1]; + System.arraycopy(commands, 0, newCommands, 0, i); + System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); + description.setBuildSpec(newCommands); + project.setDescription(description, null); + return; + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionValidator.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionValidator.java index d3e952c916..c0c98bd232 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionValidator.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionValidator.java @@ -1,35 +1,35 @@ -/*
- * 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.core.resources.IProject;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.pde.core.plugin.IPluginModelBase;
-
-/**
- * @author Eike Stepper
- */
-public abstract class VersionValidator
-{
- public VersionValidator()
- {
- }
-
- public void abort(BuildState buildState, IProject project, Exception exception, IProgressMonitor monitor)
- throws Exception
- {
- buildState.setValidatorState(null);
- }
-
- public abstract void updateBuildState(BuildState buildState, String releasePath, Release release, IProject project,
- IResourceDelta delta, IPluginModelBase pluginModel, IProgressMonitor monitor) throws Exception;
-}
+/* + * 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.core.resources.IProject; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.pde.core.plugin.IPluginModelBase; + +/** + * @author Eike Stepper + */ +public abstract class VersionValidator +{ + public VersionValidator() + { + } + + public void abort(BuildState buildState, IProject project, Exception exception, IProgressMonitor monitor) + throws Exception + { + buildState.setValidatorState(null); + } + + public abstract void updateBuildState(BuildState buildState, String releasePath, Release release, IProject project, + IResourceDelta delta, IPluginModelBase pluginModel, IProgressMonitor monitor) throws Exception; +} diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/test/TestResourceChangeListener.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/test/TestResourceChangeListener.java index 31f2ff3ff4..63e895ff7d 100644 --- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/test/TestResourceChangeListener.java +++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/test/TestResourceChangeListener.java @@ -1,171 +1,171 @@ -/*
- * 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.test;
-
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.runtime.CoreException;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public final class TestResourceChangeListener implements IResourceChangeListener
-{
- public void resourceChanged(IResourceChangeEvent event)
- {
- try
- {
- System.out.println(getType(event));
- IResourceDelta delta = event.getDelta();
- if (delta != null)
- {
- delta.accept(new IResourceDeltaVisitor()
- {
- public boolean visit(IResourceDelta delta) throws CoreException
- {
- System.out.println(" " + delta.getFullPath() + " --> " + getKind(delta) + " " + getFlags(delta));
- return true;
- }
- });
- }
- }
- catch (CoreException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public static String getType(IResourceChangeEvent event)
- {
- switch (event.getType())
- {
- case IResourceChangeEvent.POST_BUILD:
- return "POST_BUILD";
- case IResourceChangeEvent.POST_CHANGE:
- return "POST_CHANGE";
- case IResourceChangeEvent.PRE_BUILD:
- return "PRE_BUILD";
- case IResourceChangeEvent.PRE_CLOSE:
- return "PRE_CLOSE";
- case IResourceChangeEvent.PRE_DELETE:
- return "PRE_DELETE";
- case IResourceChangeEvent.PRE_REFRESH:
- return "PRE_REFRESH";
- default:
- return "Unknown event type: " + event.getType();
- }
- }
-
- public static String getKind(IResourceDelta delta)
- {
- switch (delta.getKind())
- {
- case IResourceDelta.ADDED:
- return "ADDED";
- case IResourceDelta.REMOVED:
- return "REMOVED";
- case IResourceDelta.CHANGED:
- return "CHANGED";
- case IResourceDelta.ADDED_PHANTOM:
- return "ADDED_PHANTOM";
- case IResourceDelta.REMOVED_PHANTOM:
- return "REMOVED_PHANTOM";
- default:
- return "Unknown delta kind: " + delta.getKind();
- }
- }
-
- public static String getFlags(IResourceDelta delta)
- {
- List<String> list = new ArrayList<String>();
- if (hasFlag(delta, IResourceDelta.CONTENT))
- {
- list.add("CONTENT");
- }
-
- if (hasFlag(delta, IResourceDelta.DERIVED_CHANGED))
- {
- list.add("DERIVED_CHANGED");
- }
-
- if (hasFlag(delta, IResourceDelta.DESCRIPTION))
- {
- list.add("DESCRIPTION");
- }
-
- if (hasFlag(delta, IResourceDelta.ENCODING))
- {
- list.add("ENCODING");
- }
-
- if (hasFlag(delta, IResourceDelta.LOCAL_CHANGED))
- {
- list.add("LOCAL_CHANGED");
- }
-
- if (hasFlag(delta, IResourceDelta.OPEN))
- {
- list.add("OPEN");
- }
-
- if (hasFlag(delta, IResourceDelta.MOVED_TO))
- {
- list.add("MOVED_TO");
- }
-
- if (hasFlag(delta, IResourceDelta.MOVED_FROM))
- {
- list.add("MOVED_FROM");
- }
-
- if (hasFlag(delta, IResourceDelta.COPIED_FROM))
- {
- list.add("COPIED_FROM");
- }
-
- if (hasFlag(delta, IResourceDelta.TYPE))
- {
- list.add("TYPE");
- }
-
- if (hasFlag(delta, IResourceDelta.SYNC))
- {
- list.add("SYNC");
- }
-
- if (hasFlag(delta, IResourceDelta.MARKERS))
- {
- list.add("MARKERS");
- }
-
- if (hasFlag(delta, IResourceDelta.REPLACED))
- {
- list.add("REPLACED");
- }
-
- if (list.isEmpty())
- {
- return "";
- }
-
- return list.toString();
- }
-
- public static boolean hasFlag(IResourceDelta delta, int flag)
- {
- return (delta.getFlags() & flag) != 0;
- }
-}
+/* + * 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.test; + +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.runtime.CoreException; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Eike Stepper + */ +public final class TestResourceChangeListener implements IResourceChangeListener +{ + public void resourceChanged(IResourceChangeEvent event) + { + try + { + System.out.println(getType(event)); + IResourceDelta delta = event.getDelta(); + if (delta != null) + { + delta.accept(new IResourceDeltaVisitor() + { + public boolean visit(IResourceDelta delta) throws CoreException + { + System.out.println(" " + delta.getFullPath() + " --> " + getKind(delta) + " " + getFlags(delta)); + return true; + } + }); + } + } + catch (CoreException ex) + { + ex.printStackTrace(); + } + } + + public static String getType(IResourceChangeEvent event) + { + switch (event.getType()) + { + case IResourceChangeEvent.POST_BUILD: + return "POST_BUILD"; + case IResourceChangeEvent.POST_CHANGE: + return "POST_CHANGE"; + case IResourceChangeEvent.PRE_BUILD: + return "PRE_BUILD"; + case IResourceChangeEvent.PRE_CLOSE: + return "PRE_CLOSE"; + case IResourceChangeEvent.PRE_DELETE: + return "PRE_DELETE"; + case IResourceChangeEvent.PRE_REFRESH: + return "PRE_REFRESH"; + default: + return "Unknown event type: " + event.getType(); + } + } + + public static String getKind(IResourceDelta delta) + { + switch (delta.getKind()) + { + case IResourceDelta.ADDED: + return "ADDED"; + case IResourceDelta.REMOVED: + return "REMOVED"; + case IResourceDelta.CHANGED: + return "CHANGED"; + case IResourceDelta.ADDED_PHANTOM: + return "ADDED_PHANTOM"; + case IResourceDelta.REMOVED_PHANTOM: + return "REMOVED_PHANTOM"; + default: + return "Unknown delta kind: " + delta.getKind(); + } + } + + public static String getFlags(IResourceDelta delta) + { + List<String> list = new ArrayList<String>(); + if (hasFlag(delta, IResourceDelta.CONTENT)) + { + list.add("CONTENT"); + } + + if (hasFlag(delta, IResourceDelta.DERIVED_CHANGED)) + { + list.add("DERIVED_CHANGED"); + } + + if (hasFlag(delta, IResourceDelta.DESCRIPTION)) + { + list.add("DESCRIPTION"); + } + + if (hasFlag(delta, IResourceDelta.ENCODING)) + { + list.add("ENCODING"); + } + + if (hasFlag(delta, IResourceDelta.LOCAL_CHANGED)) + { + list.add("LOCAL_CHANGED"); + } + + if (hasFlag(delta, IResourceDelta.OPEN)) + { + list.add("OPEN"); + } + + if (hasFlag(delta, IResourceDelta.MOVED_TO)) + { + list.add("MOVED_TO"); + } + + if (hasFlag(delta, IResourceDelta.MOVED_FROM)) + { + list.add("MOVED_FROM"); + } + + if (hasFlag(delta, IResourceDelta.COPIED_FROM)) + { + list.add("COPIED_FROM"); + } + + if (hasFlag(delta, IResourceDelta.TYPE)) + { + list.add("TYPE"); + } + + if (hasFlag(delta, IResourceDelta.SYNC)) + { + list.add("SYNC"); + } + + if (hasFlag(delta, IResourceDelta.MARKERS)) + { + list.add("MARKERS"); + } + + if (hasFlag(delta, IResourceDelta.REPLACED)) + { + list.add("REPLACED"); + } + + if (list.isEmpty()) + { + return ""; + } + + return list.toString(); + } + + public static boolean hasFlag(IResourceDelta delta, int flag) + { + return (delta.getFlags() & flag) != 0; + } +} |