Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-29 07:36:16 +0000
committerEike Stepper2012-07-29 07:36:16 +0000
commitaf5be53433764aba1caca5f3a022c84d4090ebb4 (patch)
tree4955553bf22ecd69966e7c26cbcde85eae76d6a2 /plugins
parentc568b3cc1d4264cd9beb472d722d90593cea0492 (diff)
downloadcdo-af5be53433764aba1caca5f3a022c84d4090ebb4.tar.gz
cdo-af5be53433764aba1caca5f3a022c84d4090ebb4.tar.xz
cdo-af5be53433764aba1caca5f3a022c84d4090ebb4.zip
Add debug options validation
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/dialogs/ConfigurationDialog.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/IVersionBuilderArguments.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilderArguments.java140
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/Markers.java39
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/version/VersionUtil.java163
6 files changed, 221 insertions, 189 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/dialogs/ConfigurationDialog.java b/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/dialogs/ConfigurationDialog.java
index 5e66d1b7f4..ba0cdc86c1 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/dialogs/ConfigurationDialog.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/dialogs/ConfigurationDialog.java
@@ -49,6 +49,8 @@ public class ConfigurationDialog extends TitleAreaDialog implements IVersionBuil
private Button ignoreSchemaBuilderButton;
+ private Button ignoreDebugOptionsButton;
+
private Button ignoreMissingDependencyRangesButton;
private Button ignoreMissingExportVersionsButton;
@@ -99,7 +101,11 @@ public class ConfigurationDialog extends TitleAreaDialog implements IVersionBuil
ignoreSchemaBuilderButton = new Button(composite, SWT.CHECK);
ignoreSchemaBuilderButton.setText("Ignore schema builder");
- ignoreSchemaBuilderButton.setSelection(values.isIgnoreMalformedVersions());
+ ignoreSchemaBuilderButton.setSelection(values.isIgnoreSchemaBuilder());
+
+ ignoreDebugOptionsButton = new Button(composite, SWT.CHECK);
+ ignoreDebugOptionsButton.setText("Ignore debug options");
+ ignoreDebugOptionsButton.setSelection(values.isIgnoreDebugOptions());
ignoreMissingDependencyRangesButton = new Button(composite, SWT.CHECK);
ignoreMissingDependencyRangesButton.setText("Ignore missing dependency version ranges");
@@ -146,6 +152,7 @@ public class ConfigurationDialog extends TitleAreaDialog implements IVersionBuil
values.setReleasePath(releasePathText.getText());
values.setIgnoreMalformedVersions(ignoreMalformedVersionsButton.getSelection());
values.setIgnoreSchemaBuilder(ignoreSchemaBuilderButton.getSelection());
+ values.setIgnoreDebugOptions(ignoreDebugOptionsButton.getSelection());
values.setIgnoreMissingDependencyRanges(ignoreMissingDependencyRangesButton.getSelection());
values.setIgnoreMissingExportVersions(ignoreMissingExportVersionsButton.getSelection());
values.setIgnoreFeatureContentRedundancy(ignoreFeatureContentRedundancyButton.getSelection());
@@ -158,6 +165,11 @@ public class ConfigurationDialog extends TitleAreaDialog implements IVersionBuil
throw new UnsupportedOperationException();
}
+ public String getValidatorClassName()
+ {
+ throw new UnsupportedOperationException();
+ }
+
public boolean isIgnoreMalformedVersions()
{
throw new UnsupportedOperationException();
@@ -168,6 +180,11 @@ public class ConfigurationDialog extends TitleAreaDialog implements IVersionBuil
throw new UnsupportedOperationException();
}
+ public boolean isIgnoreDebugOptions()
+ {
+ throw new UnsupportedOperationException();
+ }
+
public boolean isIgnoreMissingDependencyRanges()
{
throw new UnsupportedOperationException();
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/IVersionBuilderArguments.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/IVersionBuilderArguments.java
index 060fbb9487..c3da7c49e5 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/IVersionBuilderArguments.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/IVersionBuilderArguments.java
@@ -30,6 +30,8 @@ public interface IVersionBuilderArguments extends Map<String, String>
public static final String IGNORE_SCHEMA_BUILDER_ARGUMENT = "ignore.schema.builder";
+ public static final String IGNORE_DEBUG_OPTIONS_ARGUMENT = "ignore.debug.options";
+
public static final String IGNORE_DEPENDENCY_RANGES_ARGUMENT = "ignore.missing.dependency.ranges";
public static final String IGNORE_EXPORT_VERSIONS_ARGUMENT = "ignore.missing.export.versions";
@@ -40,10 +42,14 @@ public interface IVersionBuilderArguments extends Map<String, String>
public String getReleasePath();
+ public String getValidatorClassName();
+
public boolean isIgnoreMalformedVersions();
public boolean isIgnoreSchemaBuilder();
+ public boolean isIgnoreDebugOptions();
+
public boolean isIgnoreMissingDependencyRanges();
public boolean isIgnoreMissingExportVersions();
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java
index 0cb1cdcc56..97735f6d79 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilder.java
@@ -66,6 +66,8 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
{
private static final Path DESCRIPTION_PATH = new Path(".project");
+ private static final Path OPTIONS_PATH = new Path(".options");
+
private static final Path MANIFEST_PATH = new Path("META-INF/MANIFEST.MF");
private static final Path FEATURE_PATH = new Path("feature.xml");
@@ -182,6 +184,11 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
checkSchemaBuilder((IPluginModelBase)componentModel, projectDescription);
}
+ if (!arguments.isIgnoreDebugOptions())
+ {
+ checkDebugOptions((IPluginModelBase)componentModel);
+ }
+
if (!arguments.isIgnoreMissingDependencyRanges())
{
checkDependencyRanges((IPluginModelBase)componentModel);
@@ -732,7 +739,7 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
{
try
{
- String content = Markers.getContent(file);
+ String content = VersionUtil.getContent(file);
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(content);
if (matcher.find())
@@ -908,6 +915,40 @@ public class VersionBuilder extends IncrementalProjectBuilder implements IElemen
}
}
+ private static final Pattern DEBUG_OPTION_PATTERN = Pattern.compile("^( *)([^/ \\n\\r]+)/([^ =]+)( *=.*)$",
+ Pattern.MULTILINE);
+
+ private void checkDebugOptions(IPluginModelBase pluginModel) throws CoreException, IOException
+ {
+ IFile file = getProject().getFile(OPTIONS_PATH);
+ if (file.isAccessible())
+ {
+ String symbolicName = pluginModel.getBundleDescription().getSymbolicName();
+ String content = VersionUtil.getContent(file);
+
+ Matcher matcher = DEBUG_OPTION_PATTERN.matcher(content);
+ while (matcher.find())
+ {
+ String pluginID = matcher.group(2);
+ if (!symbolicName.equals(pluginID))
+ {
+ String prefix = matcher.group(1);
+ String suffix = "/" + (matcher.group(3) + matcher.group(4)).replace(".", "\\.");
+ pluginID = pluginID.replace(".", "\\.");
+
+ String regex = prefix + "(" + pluginID + ")" + suffix;
+ String msg = "Debug option should be '" + symbolicName + "/" + matcher.group(3) + "'";
+
+ IMarker marker = Markers.addMarker(file, msg, IMarker.SEVERITY_ERROR, regex);
+ marker.setAttribute(Markers.QUICK_FIX_PATTERN, regex);
+ marker.setAttribute(Markers.QUICK_FIX_REPLACEMENT, symbolicName);
+ marker.setAttribute(Markers.QUICK_FIX_CONFIGURE_OPTION,
+ IVersionBuilderArguments.IGNORE_SCHEMA_BUILDER_ARGUMENT);
+ }
+ }
+ }
+ }
+
private boolean isBundlePackage(String packageName, String bundleName)
{
if (packageName.startsWith(bundleName))
diff --git a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilderArguments.java b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilderArguments.java
index 7bbd77330d..e17a36a80e 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilderArguments.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version/src/org/eclipse/emf/cdo/releng/internal/version/VersionBuilderArguments.java
@@ -61,135 +61,89 @@ public class VersionBuilderArguments extends HashMap<String, String> implements
return get(IVersionBuilderArguments.RELEASE_PATH_ARGUMENT);
}
+ public void setReleasePath(String value)
+ {
+ setString(IVersionBuilderArguments.RELEASE_PATH_ARGUMENT, value);
+ }
+
public String getValidatorClassName()
{
return get(IVersionBuilderArguments.VALIDATOR_CLASS_ARGUMENT);
}
+ public void setValidatorClassName(String value)
+ {
+ setString(IVersionBuilderArguments.VALIDATOR_CLASS_ARGUMENT, value);
+ }
+
public boolean isIgnoreMalformedVersions()
{
return "true".equals(get(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT));
}
- public boolean isIgnoreSchemaBuilder()
+ public void setIgnoreMalformedVersions(boolean value)
{
- return "true".equals(get(IVersionBuilderArguments.IGNORE_SCHEMA_BUILDER_ARGUMENT));
+ setBoolean(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT, value);
}
- public boolean isIgnoreMissingDependencyRanges()
+ public boolean isIgnoreSchemaBuilder()
{
- return "true".equals(get(IVersionBuilderArguments.IGNORE_DEPENDENCY_RANGES_ARGUMENT));
+ return "true".equals(get(IVersionBuilderArguments.IGNORE_SCHEMA_BUILDER_ARGUMENT));
}
- public boolean isIgnoreMissingExportVersions()
+ public void setIgnoreSchemaBuilder(boolean value)
{
- return "true".equals(get(IVersionBuilderArguments.IGNORE_EXPORT_VERSIONS_ARGUMENT));
+ setBoolean(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT, value);
}
- public boolean isIgnoreFeatureContentRedundancy()
+ public boolean isIgnoreDebugOptions()
{
- return "true".equals(get(IVersionBuilderArguments.IGNORE_CONTENT_REDUNDANCY_ARGUMENT));
+ return "true".equals(get(IVersionBuilderArguments.IGNORE_SCHEMA_BUILDER_ARGUMENT));
}
- public boolean isIgnoreFeatureContentChanges()
+ public void setIgnoreDebugOptions(boolean value)
{
- return "true".equals(get(IVersionBuilderArguments.IGNORE_CONTENT_CHANGES_ARGUMENT));
+ setBoolean(IVersionBuilderArguments.IGNORE_DEBUG_OPTIONS_ARGUMENT, value);
}
- public void setReleasePath(String value)
+ public boolean isIgnoreMissingDependencyRanges()
{
- if (value != null)
- {
- put(IVersionBuilderArguments.RELEASE_PATH_ARGUMENT, value);
- }
- else
- {
- remove(IVersionBuilderArguments.RELEASE_PATH_ARGUMENT);
- }
+ return "true".equals(get(IVersionBuilderArguments.IGNORE_DEPENDENCY_RANGES_ARGUMENT));
}
- public void setValidatorClassName(String value)
+ public void setIgnoreMissingDependencyRanges(boolean value)
{
- if (value != null)
- {
- put(IVersionBuilderArguments.VALIDATOR_CLASS_ARGUMENT, value);
- }
- else
- {
- remove(IVersionBuilderArguments.VALIDATOR_CLASS_ARGUMENT);
- }
+ setBoolean(IVersionBuilderArguments.IGNORE_DEPENDENCY_RANGES_ARGUMENT, value);
}
- public void setIgnoreMalformedVersions(boolean value)
+ public boolean isIgnoreMissingExportVersions()
{
- if (value)
- {
- put(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT, Boolean.toString(true));
- }
- else
- {
- remove(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT);
- }
+ return "true".equals(get(IVersionBuilderArguments.IGNORE_EXPORT_VERSIONS_ARGUMENT));
}
- public void setIgnoreSchemaBuilder(boolean value)
+ public void setIgnoreMissingExportVersions(boolean value)
{
- if (value)
- {
- put(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT, Boolean.toString(true));
- }
- else
- {
- remove(IVersionBuilderArguments.IGNORE_MALFORMED_VERSIONS_ARGUMENT);
- }
+ setBoolean(IVersionBuilderArguments.IGNORE_EXPORT_VERSIONS_ARGUMENT, value);
}
- public void setIgnoreMissingDependencyRanges(boolean value)
+ public boolean isIgnoreFeatureContentRedundancy()
{
- if (value)
- {
- put(IVersionBuilderArguments.IGNORE_DEPENDENCY_RANGES_ARGUMENT, Boolean.toString(true));
- }
- else
- {
- remove(IVersionBuilderArguments.IGNORE_DEPENDENCY_RANGES_ARGUMENT);
- }
+ return "true".equals(get(IVersionBuilderArguments.IGNORE_CONTENT_REDUNDANCY_ARGUMENT));
}
- public void setIgnoreMissingExportVersions(boolean value)
+ public void setIgnoreFeatureContentRedundancy(boolean value)
{
- if (value)
- {
- put(IVersionBuilderArguments.IGNORE_EXPORT_VERSIONS_ARGUMENT, Boolean.toString(true));
- }
- else
- {
- remove(IVersionBuilderArguments.IGNORE_EXPORT_VERSIONS_ARGUMENT);
- }
+ setBoolean(IVersionBuilderArguments.IGNORE_CONTENT_REDUNDANCY_ARGUMENT, value);
}
- public void setIgnoreFeatureContentRedundancy(boolean value)
+ public boolean isIgnoreFeatureContentChanges()
{
- if (value)
- {
- put(IVersionBuilderArguments.IGNORE_CONTENT_REDUNDANCY_ARGUMENT, Boolean.toString(true));
- }
- else
- {
- remove(IVersionBuilderArguments.IGNORE_CONTENT_REDUNDANCY_ARGUMENT);
- }
+ return "true".equals(get(IVersionBuilderArguments.IGNORE_CONTENT_CHANGES_ARGUMENT));
}
public void setIgnoreFeatureContentChanges(boolean value)
{
- if (value)
- {
- put(IVersionBuilderArguments.IGNORE_CONTENT_CHANGES_ARGUMENT, Boolean.toString(true));
- }
- else
- {
- remove(IVersionBuilderArguments.IGNORE_CONTENT_CHANGES_ARGUMENT);
- }
+ setBoolean(IVersionBuilderArguments.IGNORE_CONTENT_CHANGES_ARGUMENT, value);
}
public void applyTo(IProject project) throws CoreException
@@ -215,6 +169,30 @@ public class VersionBuilderArguments extends HashMap<String, String> implements
return command;
}
+ private void setString(String key, String value)
+ {
+ if (value != null)
+ {
+ put(key, value);
+ }
+ else
+ {
+ remove(key);
+ }
+ }
+
+ private void setBoolean(String key, boolean value)
+ {
+ if (value)
+ {
+ put(key, Boolean.toString(true));
+ }
+ else
+ {
+ remove(key);
+ }
+ }
+
public static List<String> getOtherNatures(IProjectDescription description)
{
String[] natureIds = description.getNatureIds();
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 65306a4327..010a11004e 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
@@ -17,11 +17,7 @@ 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.CharArrayWriter;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -117,43 +113,10 @@ public final class Markers
return marker;
}
- public static String getContent(IFile file) throws CoreException, IOException
- {
- InputStream contents = null;
- try
- {
- contents = file.getContents();
- BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset()));
- CharArrayWriter caw = new CharArrayWriter();
-
- int c;
- while ((c = reader.read()) != -1)
- {
- caw.write(c);
- }
-
- return caw.toString();
- }
- finally
- {
- if (contents != null)
- {
- try
- {
- contents.close();
- }
- catch (Exception ex)
- {
- Activator.log(ex);
- }
- }
- }
- }
-
public static IMarker addMarker(IFile file, String message, int severity, String regex) throws CoreException,
IOException
{
- String string = getContent(file);
+ String string = VersionUtil.getContent(file);
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(string);
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 794497a989..5d494f4fbb 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
@@ -24,10 +24,13 @@ import org.eclipse.pde.core.plugin.PluginRegistry;
import org.osgi.framework.Version;
+import java.io.BufferedReader;
+import java.io.CharArrayWriter;
import java.io.Closeable;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -47,84 +50,47 @@ public final class VersionUtil
{
}
- public static IModel getComponentModel(IProject project)
+ public static Version normalize(Version version)
{
- IModel componentModel = PluginRegistry.findModel(project);
- if (componentModel == null)
- {
- componentModel = getFeatureModel(project);
- if (componentModel == null)
- {
- throw new IllegalStateException("The project " + project.getName() + " is neither a plugin nor a feature");
- }
- }
+ return new Version(version.getMajor(), version.getMinor(), version.getMicro());
+ }
- return componentModel;
+ public static IFile getFile(IPath path, String extension)
+ {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IFile file = root.getFile(path);
+ IPath newPath = file.getFullPath().removeFileExtension().addFileExtension(extension);
+ return root.getFile(newPath);
}
- @SuppressWarnings("restriction")
- public static org.eclipse.pde.internal.core.ifeature.IFeatureModel getFeatureModel(IProject project)
+ public static String getContent(IFile file) throws CoreException, IOException
{
- org.eclipse.pde.internal.core.ifeature.IFeatureModel[] featureModels = org.eclipse.pde.internal.core.PDECore
- .getDefault().getFeatureModelManager().getWorkspaceModels();
+ InputStream contents = null;
- for (org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel : featureModels)
+ try
{
- if (featureModel.getUnderlyingResource().getProject() == project)
+ contents = file.getContents();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset()));
+ CharArrayWriter caw = new CharArrayWriter();
+
+ int c;
+ while ((c = reader.read()) != -1)
{
- return featureModel;
+ caw.write(c);
}
- }
- return null;
- }
-
- @SuppressWarnings("restriction")
- public static Version getComponentVersion(IModel componentModel)
- {
- if (componentModel instanceof IPluginModelBase)
- {
- IPluginModelBase pluginModel = (IPluginModelBase)componentModel;
- return normalize(pluginModel.getBundleDescription().getVersion());
+ return caw.toString();
}
-
- Version version = new Version(((org.eclipse.pde.internal.core.ifeature.IFeatureModel)componentModel).getFeature()
- .getVersion());
- return normalize(version);
- }
-
- public static void close(Closeable closeable)
- {
- if (closeable != null)
+ finally
{
- try
- {
- closeable.close();
- }
- catch (Exception ex)
- {
- Activator.log(ex);
- }
+ close(contents);
}
}
- public static IFile getFile(IPath releasePath, String extension)
- {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IFile file = root.getFile(releasePath);
- IPath path = file.getFullPath().removeFileExtension().addFileExtension(extension);
- return root.getFile(path);
- }
-
- public static Version normalize(Version version)
- {
- return new Version(version.getMajor(), version.getMinor(), version.getMicro());
- }
-
public static synchronized byte[] getSHA1(IFile file) throws NoSuchAlgorithmException, CoreException, IOException
{
InputStream stream = null;
-
+
try
{
final MessageDigest digest = MessageDigest.getInstance("SHA-1");
@@ -140,17 +106,17 @@ public final class VersionUtil
{
case -1:
return -1;
-
+
case 10:
case 13:
continue;
}
-
+
digest.update((byte)ch);
return ch;
}
}
-
+
@Override
public int read(byte[] b, int off, int len) throws IOException
{
@@ -159,7 +125,7 @@ public final class VersionUtil
{
return -1;
}
-
+
for (int i = off; i < off + read; i++)
{
byte c = b[i];
@@ -170,21 +136,21 @@ public final class VersionUtil
System.arraycopy(b, i + 1, b, i, read - i - 1);
--i;
}
-
+
--read;
}
}
-
+
digest.update(b, off, read);
return read;
}
};
-
+
while (stream.read(BUFFER) != -1)
{
// Do nothing
}
-
+
return digest.digest();
}
finally
@@ -202,4 +168,65 @@ public final class VersionUtil
}
}
}
+
+ public static void close(Closeable closeable)
+ {
+ if (closeable != null)
+ {
+ try
+ {
+ closeable.close();
+ }
+ catch (Exception ex)
+ {
+ Activator.log(ex);
+ }
+ }
+ }
+
+ public static IModel getComponentModel(IProject project)
+ {
+ IModel componentModel = PluginRegistry.findModel(project);
+ if (componentModel == null)
+ {
+ componentModel = getFeatureModel(project);
+ if (componentModel == null)
+ {
+ throw new IllegalStateException("The project " + project.getName() + " is neither a plugin nor a feature");
+ }
+ }
+
+ return componentModel;
+ }
+
+ @SuppressWarnings("restriction")
+ public static org.eclipse.pde.internal.core.ifeature.IFeatureModel getFeatureModel(IProject project)
+ {
+ org.eclipse.pde.internal.core.ifeature.IFeatureModel[] featureModels = org.eclipse.pde.internal.core.PDECore
+ .getDefault().getFeatureModelManager().getWorkspaceModels();
+
+ for (org.eclipse.pde.internal.core.ifeature.IFeatureModel featureModel : featureModels)
+ {
+ if (featureModel.getUnderlyingResource().getProject() == project)
+ {
+ return featureModel;
+ }
+ }
+
+ return null;
+ }
+
+ @SuppressWarnings("restriction")
+ public static Version getComponentVersion(IModel componentModel)
+ {
+ if (componentModel instanceof IPluginModelBase)
+ {
+ IPluginModelBase pluginModel = (IPluginModelBase)componentModel;
+ return normalize(pluginModel.getBundleDescription().getVersion());
+ }
+
+ Version version = new Version(((org.eclipse.pde.internal.core.ifeature.IFeatureModel)componentModel).getFeature()
+ .getVersion());
+ return normalize(version);
+ }
}

Back to the top