Skip to content

Commit de5de34

Browse files
committed
Do not implement IClasspathContainer
Currently RequiredPluginsClasspathContainer itself implements IClasspathContainer but we actually only need that instance to compute the entries. As the RequiredPluginsClasspathContainer retains some objects in its instance and to make handling more uniform (e.g. regarding equals and hashcode of container instances) this now removes the actual implementation of the interface and simply wraps the resulting entries in a SerializableClasspathContainer that only holds a reference to the entries produced itself.
1 parent 260640d commit de5de34

6 files changed

Lines changed: 24 additions & 44 deletions

File tree

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.eclipse.core.runtime.CoreException;
3333
import org.eclipse.core.runtime.IPath;
3434
import org.eclipse.jdt.core.IClasspathAttribute;
35-
import org.eclipse.jdt.core.IClasspathContainer;
3635
import org.eclipse.jdt.core.IClasspathEntry;
3736
import org.eclipse.jdt.core.IJavaModelStatus;
3837
import org.eclipse.jdt.core.IJavaProject;
@@ -474,9 +473,10 @@ public static IClasspathEntry createContainerEntry() {
474473
return JavaCore.newContainerEntry(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH);
475474
}
476475

477-
public static IClasspathEntry[] computeClasspathEntries(IPluginModelBase model, IProject project) {
478-
IClasspathContainer container = new RequiredPluginsClasspathContainer(model, project);
479-
return container.getClasspathEntries();
476+
public static IClasspathEntry[] computeClasspathEntries(IPluginModelBase model, IProject project)
477+
throws CoreException {
478+
RequiredPluginsClasspathContainer container = new RequiredPluginsClasspathContainer(model, project);
479+
return container.computeEntries();
480480
}
481481

482482
}

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathContainerState.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ protected IStatus run(IProgressMonitor jobMonitor) {
111111
IPluginModelBase model = modelManager.findModel(project);
112112
if (model != null && PluginProject.isJavaProject(project)) {
113113
IJavaProject javaProject = JavaCore.create(project);
114-
RequiredPluginsClasspathContainer classpathContainer = new RequiredPluginsClasspathContainer(
115-
model, project);
116114
try {
117-
if (!isUpToDate(project, classpathContainer.computeEntries(), request.container())) {
118-
updateProjects.put(javaProject, classpathContainer);
115+
IClasspathEntry[] entries = ClasspathComputer.computeClasspathEntries(model,
116+
javaProject.getProject());
117+
if (!isUpToDate(project, entries, request.container())) {
118+
updateProjects.put(javaProject, PDEClasspathContainerSaveHelper.containerOf(entries));
119119
errorsPerProject.remove(project);
120-
saveState(project, classpathContainer);
120+
saveState(project, entries);
121121
}
122122
} catch (CoreException e) {
123123
errorsPerProject.put(project, e.getStatus());
@@ -213,13 +213,13 @@ private static boolean isUpToDate(IProject project, IClasspathEntry[] currentEnt
213213
return true;
214214
}
215215

216-
private static void saveState(IProject project, RequiredPluginsClasspathContainer classpathContainer) {
216+
private static void saveState(IProject project, IClasspathEntry[] entries) {
217217
synchronized (project) {
218218
try {
219219
File stateFile = getStateFile(project);
220220
stateFile.getParentFile().mkdirs();
221221
try (BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(stateFile))) {
222-
PDEClasspathContainerSaveHelper.writeContainer(classpathContainer, stream);
222+
PDEClasspathContainerSaveHelper.writeContainerEntries(entries, stream);
223223
}
224224
} catch (Exception e) {
225225
// can't write then...

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.eclipse.core.runtime.IPath;
4343
import org.eclipse.core.runtime.Platform;
4444
import org.eclipse.jdt.core.IClasspathAttribute;
45-
import org.eclipse.jdt.core.IClasspathContainer;
4645
import org.eclipse.jdt.core.IClasspathEntry;
4746
import org.eclipse.jdt.core.JavaCore;
4847
import org.eclipse.osgi.service.resolver.BaseDescription;
@@ -72,7 +71,7 @@
7271
import aQute.bnd.build.Workspace;
7372
import aQute.bnd.osgi.Constants;
7473

75-
class RequiredPluginsClasspathContainer implements IClasspathContainer {
74+
class RequiredPluginsClasspathContainer {
7675

7776
@SuppressWarnings("nls")
7877
private static final Set<String> JUNIT5_RUNTIME_PLUGINS = Set.of("org.junit", //
@@ -114,30 +113,6 @@ class RequiredPluginsClasspathContainer implements IClasspathContainer {
114113
this.project = project;
115114
}
116115

117-
@Override
118-
public int getKind() {
119-
return K_APPLICATION;
120-
}
121-
122-
@Override
123-
public IPath getPath() {
124-
return PDECore.REQUIRED_PLUGINS_CONTAINER_PATH;
125-
}
126-
127-
@Override
128-
public String getDescription() {
129-
return PDECoreMessages.RequiredPluginsClasspathContainer_description;
130-
}
131-
132-
@Override
133-
public IClasspathEntry[] getClasspathEntries() {
134-
try {
135-
return computeEntries();
136-
} catch (CoreException e) {
137-
return new IClasspathEntry[0];
138-
}
139-
}
140-
141116
IClasspathEntry[] computeEntries() throws CoreException {
142117
if (fEntries == null) {
143118
if (fModel == null) {

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/PDEClasspathContainerSaveHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public static IClasspathContainer emptyContainer() {
6666
return new SerializableClasspathContainer();
6767
}
6868

69-
public static void writeContainer(IClasspathContainer container, OutputStream output) throws IOException {
69+
public static IClasspathContainer containerOf(IClasspathEntry[] entries) {
70+
return new SerializableClasspathContainer(entries);
71+
}
72+
73+
public static void writeContainerEntries(IClasspathEntry[] entries, OutputStream output) throws IOException {
7074
ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(output)) {
7175
{
7276
enableReplaceObject(true);
@@ -90,7 +94,7 @@ protected Object replaceObject(Object o) throws IOException {
9094
return super.replaceObject(o);
9195
}
9296
};
93-
os.writeObject(new SerializableClasspathContainer(container.getClasspathEntries()));
97+
os.writeObject(new SerializableClasspathContainer(entries));
9498
os.flush();
9599
}
96100

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/SerializableClasspathContainer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public String getDescription() {
5757

5858
@Override
5959
public int hashCode() {
60-
final int prime = 31;
61-
int result = 1;
62-
result = prime * result + Arrays.hashCode(entries);
63-
return result;
60+
return Arrays.hashCode(entries);
6461
}
6562

6663
@Override

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/RequiredPluginsContainerPage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*******************************************************************************/
1515
package org.eclipse.pde.internal.ui.wizards;
1616

17+
import org.eclipse.core.runtime.CoreException;
1718
import org.eclipse.core.runtime.IPath;
1819
import org.eclipse.jdt.core.IClasspathContainer;
1920
import org.eclipse.jdt.core.IClasspathEntry;
@@ -199,7 +200,10 @@ private void createRealEntries() {
199200
entry = ClasspathComputer.createContainerEntry();
200201
IPluginModelBase model = PluginRegistry.findModel(javaProject.getProject());
201202
if (model != null) {
202-
realEntries = ClasspathComputer.computeClasspathEntries(model, javaProject.getProject());
203+
try {
204+
realEntries = ClasspathComputer.computeClasspathEntries(model, javaProject.getProject());
205+
} catch (CoreException e) {
206+
}
203207
}
204208
} else {
205209
try {

0 commit comments

Comments
 (0)