Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-24 12:42:58 +0000
committerEike Stepper2012-07-24 12:42:58 +0000
commit501881c071a8dec3c997f8a62b326830b1bbf276 (patch)
treea93f807f5686694ce8871f9bda7aef6343abd7a6 /plugins
parent14c88ee12e9bf4c9ddd32bb6668601911ca0ffa8 (diff)
downloadcdo-501881c071a8dec3c997f8a62b326830b1bbf276.tar.gz
cdo-501881c071a8dec3c997f8a62b326830b1bbf276.tar.xz
cdo-501881c071a8dec3c997f8a62b326830b1bbf276.zip
Automate digest creation
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.java126
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.digest/src/org/eclipse/emf/cdo/releng/version/digest/DigestValidator.java134
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/prototypes/BuckyValidator.java (renamed from plugins/org.eclipse.emf.cdo.releng.version/BuckyValidator.java)0
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/prototypes/TestResourceChangeListener.java (renamed from plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/test/TestResourceChangeListener.java)0
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionBuilder.java1
6 files changed, 137 insertions, 127 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 13e05a476a..095217264a 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,40 +10,26 @@
*/
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.ReleaseManager;
-import org.eclipse.emf.cdo.releng.version.VersionBuilder;
import org.eclipse.emf.cdo.releng.version.digest.DigestValidator;
-import org.eclipse.emf.cdo.releng.version.digest.DigestValidatorState;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.pde.core.IModel;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
-import org.osgi.framework.Version;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
/**
* @author Eike Stepper
@@ -83,7 +69,12 @@ public class CreateDigestAction implements IObjectActionDelegate
{
try
{
- List<String> warnings = createDigest(release, target, monitor);
+ // TODO Determine validator class from .project
+ DigestValidator validator = new DigestValidator.BuildModel();
+
+ List<String> warnings = new ArrayList<String>();
+ DigestValidator.createDigest(validator, release, target, warnings, monitor);
+
if (!warnings.isEmpty())
{
final StringBuilder builder = new StringBuilder("The following problems occured:\n");
@@ -119,109 +110,4 @@ public class CreateDigestAction implements IObjectActionDelegate
}
}
- private List<String> createDigest(Release release, IFile target, IProgressMonitor monitor) throws CoreException
- {
- monitor.beginTask(null, release.getSize() + 1);
- List<String> warnings = new ArrayList<String>();
-
- try
- {
- Map<String, byte[]> result = new HashMap<String, byte[]>();
- for (Entry<Element, Element> entry : release.getElements().entrySet())
- {
- String name = entry.getKey().getName();
- monitor.subTask(name);
-
- try
- {
- try
- {
- Element element = entry.getValue();
- if (element.getName().endsWith(".source"))
- {
- continue;
- }
-
- IModel componentModel = ReleaseManager.INSTANCE.getComponentModel(element);
- if (componentModel == null)
- {
- warnings.add(name + ": Component not found");
- continue;
- }
-
- IResource resource = componentModel.getUnderlyingResource();
- if (resource == null)
- {
- warnings.add(name + ": Component is not in workspace");
- continue;
- }
-
- Version version = VersionBuilder.getComponentVersion(componentModel);
-
- if (!element.getVersion().equals(version))
- {
- warnings.add(name + ": Plugin version is not " + element.getVersion());
- }
-
- // TODO Determine validator class from .project
- DigestValidator validator = new DigestValidator.BuildModel();
- validator.beforeValidation(null, componentModel);
- DigestValidatorState state = validator.validateFull(resource.getProject(), null, componentModel,
- new NullProgressMonitor());
- validator.afterValidation(state);
- result.put(state.getName(), state.getDigest());
- }
- finally
- {
- monitor.worked(1);
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- warnings.add(name + ": " + Activator.getStatus(ex).getMessage());
- }
- }
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(result);
- oos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- if (target.exists())
- {
- int i = 1;
- for (;;)
- {
- try
- {
- target.move(target.getFullPath().addFileExtension("bak" + i), true, monitor);
- break;
- }
- catch (Exception ex)
- {
- ++i;
- }
- }
- }
-
- target.create(bais, true, monitor);
- monitor.worked(1);
- }
- catch (CoreException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new CoreException(Activator.getStatus(ex));
- }
- finally
- {
- monitor.done();
- }
-
- return warnings;
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.digest/src/org/eclipse/emf/cdo/releng/version/digest/DigestValidator.java b/plugins/org.eclipse.emf.cdo.releng.version.digest/src/org/eclipse/emf/cdo/releng/version/digest/DigestValidator.java
index 055d11cbe0..9479fedf6a 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.digest/src/org/eclipse/emf/cdo/releng/version/digest/DigestValidator.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version.digest/src/org/eclipse/emf/cdo/releng/version/digest/DigestValidator.java
@@ -11,7 +11,9 @@
package org.eclipse.emf.cdo.releng.version.digest;
import org.eclipse.emf.cdo.releng.version.BuildState;
+import org.eclipse.emf.cdo.releng.version.Element;
import org.eclipse.emf.cdo.releng.version.Release;
+import org.eclipse.emf.cdo.releng.version.ReleaseManager;
import org.eclipse.emf.cdo.releng.version.VersionBuilder;
import org.eclipse.emf.cdo.releng.version.VersionValidator;
@@ -24,24 +26,34 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.build.IBuild;
import org.eclipse.pde.core.build.IBuildEntry;
import org.eclipse.pde.core.build.IBuildModel;
import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.osgi.framework.Version;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
/**
@@ -82,7 +94,7 @@ public class DigestValidator extends VersionValidator
byte[] validatorDigest = validatorState.getDigest();
VersionBuilder.trace("DIGEST = " + formatDigest(validatorDigest));
- byte[] releaseDigest = getReleaseDigest(releasePath, project.getName());
+ byte[] releaseDigest = getReleaseDigest(releasePath, release, project.getName(), monitor);
VersionBuilder.trace("RELEASE = " + formatDigest(releaseDigest));
buildState.setChangedSinceRelease(!MessageDigest.isEqual(validatorDigest, releaseDigest));
@@ -217,13 +229,13 @@ public class DigestValidator extends VersionValidator
return !resource.isDerived();
}
- private byte[] getReleaseDigest(String releasePath, String name) throws IOException, CoreException,
- ClassNotFoundException
+ private byte[] getReleaseDigest(String releasePath, Release release, String name, IProgressMonitor monitor)
+ throws IOException, CoreException, ClassNotFoundException
{
IFile file = getDigestFile(new Path(releasePath));
if (!file.exists())
{
- throw new IllegalStateException("Digest file not found: " + file.getFullPath());
+ return createDigest(this, release, file, null, monitor);
}
ObjectInputStream stream = null;
@@ -371,6 +383,120 @@ public class DigestValidator extends VersionValidator
return builder.toString();
}
+ public static byte[] createDigest(DigestValidator validator, Release release, IFile target, List<String> warnings,
+ IProgressMonitor monitor) throws CoreException
+ {
+ monitor.beginTask(null, release.getSize() + 1);
+
+ try
+ {
+ Map<String, byte[]> result = new HashMap<String, byte[]>();
+ for (Entry<Element, Element> entry : release.getElements().entrySet())
+ {
+ String name = entry.getKey().getName();
+ monitor.subTask(name);
+
+ try
+ {
+ try
+ {
+ Element element = entry.getValue();
+ if (element.getName().endsWith(".source"))
+ {
+ continue;
+ }
+
+ IModel componentModel = ReleaseManager.INSTANCE.getComponentModel(element);
+ if (componentModel == null)
+ {
+ addWarning(warnings, name + ": Component not found");
+ continue;
+ }
+
+ IResource resource = componentModel.getUnderlyingResource();
+ if (resource == null)
+ {
+ addWarning(warnings, name + ": Component is not in workspace");
+ continue;
+ }
+
+ Version version = VersionBuilder.getComponentVersion(componentModel);
+
+ if (!element.getVersion().equals(version))
+ {
+ addWarning(warnings, name + ": Plugin version is not " + element.getVersion());
+ }
+
+ validator.beforeValidation(null, componentModel);
+ DigestValidatorState state = validator.validateFull(resource.getProject(), null, componentModel,
+ new NullProgressMonitor());
+ validator.afterValidation(state);
+ result.put(state.getName(), state.getDigest());
+ }
+ finally
+ {
+ monitor.worked(1);
+ }
+ }
+ catch (Exception ex)
+ {
+ addWarning(warnings, name + ": " + Activator.getStatus(ex).getMessage());
+ }
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(result);
+ oos.close();
+
+ byte[] digest = baos.toByteArray();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(digest);
+ if (target.exists())
+ {
+ int i = 1;
+ for (;;)
+ {
+ try
+ {
+ target.move(target.getFullPath().addFileExtension("bak" + i), true, monitor);
+ break;
+ }
+ catch (Exception ex)
+ {
+ ++i;
+ }
+ }
+ }
+
+ target.create(bais, true, monitor);
+ monitor.worked(1);
+
+ return digest;
+ }
+ catch (CoreException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new CoreException(Activator.getStatus(ex));
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ private static void addWarning(List<String> warnings, String msg)
+ {
+ Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, msg));
+ if (warnings != null)
+ {
+ warnings.add(msg);
+ }
+ }
+
public static IFile getDigestFile(IPath releasePath)
{
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(releasePath);
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.releng.version/META-INF/MANIFEST.MF
index 5868a0f6f1..3578139466 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.releng.version/META-INF/MANIFEST.MF
@@ -12,6 +12,5 @@ Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";visibility:=reexport,
org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)";visibility:=reexport,
org.eclipse.pde.core;bundle-version="[3.4.0,4.0.0)";visibility:=reexport
-Export-Package: org.eclipse.emf.cdo.releng.version;version="1.0.0",
- org.eclipse.emf.cdo.releng.version.test;version="1.0.0"
+Export-Package: org.eclipse.emf.cdo.releng.version;version="1.0.0"
Eclipse-BuddyPolicy: dependent
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/BuckyValidator.java b/plugins/org.eclipse.emf.cdo.releng.version/prototypes/BuckyValidator.java
index b663026c72..b663026c72 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/BuckyValidator.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/prototypes/BuckyValidator.java
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/prototypes/TestResourceChangeListener.java
index 63e895ff7d..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/prototypes/TestResourceChangeListener.java
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 d691ad1ecd..c907846234 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
@@ -182,7 +182,6 @@ public class VersionBuilder extends IncrementalProjectBuilder implements Element
}
catch (CoreException ex)
{
- ex.printStackTrace();
String msg = "Problem with release spec: " + releasePath;
Markers.addMarker(projectDescription, msg, IMarker.SEVERITY_ERROR, "(" + releasePath.replace(".", "\\.") + ")");
return buildDpependencies.toArray(new IProject[buildDpependencies.size()]);

Back to the top