diff options
author | Michael Valenta | 2006-09-12 15:33:42 +0000 |
---|---|---|
committer | Michael Valenta | 2006-09-12 15:33:42 +0000 |
commit | 5ace59ba38a1230fa6a0c5753a4ed6de0001317b (patch) | |
tree | 45a161d5ed39a3f7883c7dad2776d85bffa12a63 /examples | |
parent | 5c278050efcc0684d1d6535d06c95b19b3d0da0c (diff) | |
download | eclipse.platform.team-5ace59ba38a1230fa6a0c5753a4ed6de0001317b.tar.gz eclipse.platform.team-5ace59ba38a1230fa6a0c5753a4ed6de0001317b.tar.xz eclipse.platform.team-5ace59ba38a1230fa6a0c5753a4ed6de0001317b.zip |
Bug 156726 [Mapping] Need API to allow models to ensure that related changes are grouped together during a commit
Diffstat (limited to 'examples')
2 files changed, 96 insertions, 4 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java index 7e0e3cca7..3922f5f1e 100644 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java @@ -12,12 +12,10 @@ package org.eclipse.team.examples.filesystem; import java.io.IOException; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.*; import org.eclipse.swt.widgets.Display; import org.eclipse.team.core.TeamException; +import org.eclipse.team.examples.model.PluginManifestChangeTracker; import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -48,6 +46,9 @@ public class FileSystemPlugin extends AbstractUIPlugin { private static FileSystemPlugin plugin; private PessimisticFilesystemProviderPlugin pessPlugin; + + private PluginManifestChangeTracker tracker; + /** * Override the standard plugin constructor. * @@ -120,6 +121,8 @@ public class FileSystemPlugin extends AbstractUIPlugin { super.start(context); //Call startup on the Pessimistic Plugin pessPlugin.startup(); + tracker = new PluginManifestChangeTracker(); + tracker.start(); } public void stop(BundleContext context) throws Exception { @@ -129,6 +132,8 @@ public class FileSystemPlugin extends AbstractUIPlugin { } finally { super.stop(context); } + tracker.dispose(); + tracker = null; } } diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/PluginManifestChangeTracker.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/PluginManifestChangeTracker.java new file mode 100644 index 000000000..ddccae0cd --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/PluginManifestChangeTracker.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.examples.model; + +import java.util.*; + +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.*; +import org.eclipse.osgi.util.NLS; +import org.eclipse.team.core.mapping.ChangeTracker; +import org.eclipse.team.examples.filesystem.FileSystemPlugin; + +public class PluginManifestChangeTracker extends ChangeTracker { + + Set manifestFilePaths; + + public PluginManifestChangeTracker() { + manifestFilePaths = new HashSet(); + manifestFilePaths.add(new Path(null, "plugin.xml")); + manifestFilePaths.add(new Path(null, "plugin.properties")); + manifestFilePaths.add(new Path(null, "build.properties")); + manifestFilePaths.add(new Path(null, "META-INF/MANIFEST.MF")); + } + + protected boolean isProjectOfInterest(IProject project) { + return super.isProjectOfInterest(project) && hasPDENature(project); + } + + private boolean hasPDENature(IProject project) { + try { + return project.getDescription().hasNature("org.eclipse.pde.PluginNature"); + } catch (CoreException e) { + FileSystemPlugin.log(new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, + NLS.bind("Could not obtain project description for {0}", project.getName()), e)); + } + return false; + } + + protected void handleChanges(IProject project, IResource[] resources) { + handleProjectChange(project); + } + + protected void handleProjectChange(IProject project) { + List changes = new ArrayList(); + for (Iterator iter = manifestFilePaths.iterator(); iter.hasNext();) { + IPath path = (IPath) iter.next(); + IFile file = project.getFile(path); + try { + if (isModified(file)) { + changes.add(file); + } + } catch (CoreException e) { + FileSystemPlugin.log(new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, + NLS.bind("Could not obtain diff for {0}", file.getFullPath().toString()), e)); + } + } + if (changes.size() > 1) { + groupInSet(project, (IFile[]) changes.toArray(new IFile[changes.size()])); + } + } + + private void groupInSet(IProject project, IFile[] files) { + String name = getSetName(project); + try { + ensureGrouped(project, name, files); + } catch (CoreException e) { + FileSystemPlugin.log(new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, + NLS.bind("Could not create change set {0}", name), e)); + } + } + + private String getSetName(IProject project) { + return "Plugin manifest files for " + project.getName(); + } + + protected boolean isResourceOfInterest(IResource resource) { + return manifestFilePaths.contains(resource.getProjectRelativePath()); + } +} |