1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* 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());
}
}
|