Skip to content

Commit 8de0b27

Browse files
committed
Remove compilation error resolution proposal for adding Junit 5 bundles
For junit-5 it's sufficient and recommended to just import the packages needed for compilation. Alternatively it's also possible to require the junit-jupiter-api bundle. Both is already proposed by default and in both cases it's not necessary to require the junit-4 bundle (org.junit) too. Furthermore the current code seems to be partially incorrect, because actually package names have to be checked while it seems that the code assumed bundle names (which only coincidentally match). As this extra proposal also complicates the code significantly, it is removed with the recommendation to use the other standard proposals in case of missing JUnit-5 dependencies too. Removing it also avoids the need to handle the JUnit-6 case too.
1 parent 8d8b12d commit 8de0b27

File tree

2 files changed

+27
-113
lines changed

2 files changed

+27
-113
lines changed

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java

Lines changed: 27 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ private RequireBundleManifestChange(IProject project, ExportPackageDescription d
185185
super(project, desc, cu, qualifiedTypeToImport);
186186
}
187187

188-
private RequireBundleManifestChange(IProject project, String desc, CompilationUnit cu,
189-
String qualifiedTypeToImport) {
190-
super(project, desc, cu, qualifiedTypeToImport);
191-
}
192-
193188
@Override
194189
public Change perform(IProgressMonitor pm) throws CoreException {
195190
PDEModelUtility.modifyModel(new ModelModification(getProject()) {
@@ -198,69 +193,43 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co
198193
if (!(model instanceof IPluginModelBase base)) {
199194
return;
200195
}
201-
String[] pluginIdStrings = null;
202-
if ("JUnit 5 bundles".equals(getChangeObject())) { //$NON-NLS-1$
203-
pluginIdStrings = getJUnit5Bundles();
204-
}
205-
if (getChangeObject() instanceof ExportPackageDescription) {
206-
pluginIdStrings = new String[1];
207-
pluginIdStrings[0] = ((ExportPackageDescription) getChangeObject()).getSupplier()
208-
.getSymbolicName();
209-
}
210-
for (int i = 0; i < pluginIdStrings.length; i++) {
211-
String pluginId = pluginIdStrings[i];
212-
if (!isUndo()) {
213-
IPluginImport[] imports = base.getPluginBase().getImports();
214-
boolean duplicate = false;
215-
for (IPluginImport iPluginImport : imports) {
216-
if (iPluginImport.getId().equals(pluginId)) {
217-
duplicate = true;
218-
break;
219-
}
220-
}
221-
if (duplicate) {
222-
continue;
196+
String pluginId = ((ExportPackageDescription) getChangeObject()).getSupplier().getSymbolicName();
197+
if (!isUndo()) {
198+
IPluginImport[] imports = base.getPluginBase().getImports();
199+
boolean duplicate = false;
200+
for (IPluginImport iPluginImport : imports) {
201+
if (iPluginImport.getId().equals(pluginId)) {
202+
duplicate = true;
203+
break;
223204
}
224-
IPluginImport impt = base.getPluginFactory().createImport();
225-
impt.setId(pluginId);
226-
base.getPluginBase().add(impt);
227-
} else {
228-
IPluginImport[] imports = base.getPluginBase().getImports();
229-
for (IPluginImport pluginImport : imports) {
230-
if (pluginImport.getId().equals(pluginId)) {
231-
base.getPluginBase().remove(pluginImport);
232-
}
205+
}
206+
if (duplicate) {
207+
return;
208+
}
209+
IPluginImport impt = base.getPluginFactory().createImport();
210+
impt.setId(pluginId);
211+
base.getPluginBase().add(impt);
212+
} else {
213+
IPluginImport[] imports = base.getPluginBase().getImports();
214+
for (IPluginImport pluginImport : imports) {
215+
if (pluginImport.getId().equals(pluginId)) {
216+
base.getPluginBase().remove(pluginImport);
233217
}
234218
}
235219
}
236220
}
237-
238-
private String[] getJUnit5Bundles() {
239-
return new String[] { "org.junit", "junit-jupiter-api" }; //$NON-NLS-1$ //$NON-NLS-2$
240-
}
241221
}, new NullProgressMonitor());
242222

243223
insertImport(getCompilationUnit(), getQualifiedTypeToImport(), pm);
244224

245225
if (!isUndo()) {
246-
if (getChangeObject() instanceof ExportPackageDescription) {
247-
return new RequireBundleManifestChange(getProject(), (ExportPackageDescription) getChangeObject(),
248-
getCompilationUnit(), getQualifiedTypeToImport()) {
249-
@Override
250-
public boolean isUndo() {
251-
return true;
252-
}
253-
};
254-
}
255-
if (getChangeObject() instanceof String) {
256-
return new RequireBundleManifestChange(getProject(),(String) getChangeObject(),
257-
getCompilationUnit(), getQualifiedTypeToImport()) {
258-
@Override
259-
public boolean isUndo() {
260-
return true;
261-
}
262-
};
263-
}
226+
return new RequireBundleManifestChange(getProject(), (ExportPackageDescription) getChangeObject(),
227+
getCompilationUnit(), getQualifiedTypeToImport()) {
228+
@Override
229+
public boolean isUndo() {
230+
return true;
231+
}
232+
};
264233
}
265234
return null;
266235
}
@@ -474,39 +443,6 @@ public static final Object createRequireBundleProposal(IProject project, ExportP
474443
return createWrapper(change, type, relevance);
475444
}
476445

477-
/**
478-
* Creates and returns a proposal which create multiple Require-Bundle entry in the
479-
* MANIFEST.MF (or corresponding plugin.xml) for desc name.
480-
*
481-
* @param project
482-
* the project to be updated
483-
* @param desc
484-
* multiple bundles that is to be added as a Require-Bundle dependency
485-
* based on description name
486-
* @param type
487-
* the type of the proposal to be returned
488-
* @param relevance
489-
* the relevance of the new proposal
490-
* @param qualifiedTypeToImport
491-
* the qualified type name of the type that requires this
492-
* proposal. If this argument and cu are supplied the proposal
493-
* will add an import statement for this type to the source file
494-
* in which the proposal was invoked.
495-
* @param cu
496-
* the AST root of the java source file in which this fix was
497-
* invoked
498-
* @see JavaResolutionFactory#TYPE_JAVA_COMPLETION
499-
* @see JavaResolutionFactory#TYPE_CLASSPATH_FIX
500-
*/
501-
public static final Object createRequireBundleProposal(IProject project, String desc, int type, int relevance,
502-
CompilationUnit cu, String qualifiedTypeToImport) {
503-
if (desc == null) {
504-
return null;
505-
}
506-
AbstractManifestChange change = new RequireBundleManifestChange(project, desc, cu, qualifiedTypeToImport);
507-
return createWrapper(change, type, relevance);
508-
}
509-
510446
/**
511447
* Creates and returns a proposal which create an Import-Package entry in
512448
* the MANIFEST.MF for the package represented by desc. The object will be

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/UnresolvedImportFixProcessor.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ public void addResolutionModification(IProject project, ExportPackageDescription
5959
}
6060
}
6161

62-
/*
63-
* Creates proposal for adding require bundles in manifest file based on the
64-
* description name given
65-
*/
66-
public void addResolutionModification(IProject project, String desc, CompilationUnit cu,
67-
String qualifiedTypeToImport) {
68-
if (desc == null) {
69-
return;
70-
}
71-
Object proposal = JavaResolutionFactory.createRequireBundleProposal(project, desc,
72-
JavaResolutionFactory.TYPE_CLASSPATH_FIX, 16, cu, qualifiedTypeToImport);
73-
if (proposal != null) {
74-
fList.add(proposal);
75-
}
76-
}
77-
7862
/*
7963
* Returns all the ClasspathFixProposals which were found
8064
*/
@@ -96,12 +80,6 @@ public ClasspathFixProposal[] getFixImportProposals(IJavaProject project, String
9680
return new ClasspathFixProposal[0];
9781
}
9882
ClasspathFixCollector collector = new ClasspathFixCollector();
99-
// Add require bundles for junit5
100-
if (name.startsWith("junit-jupiter") || name.startsWith("junit-platform") || name.startsWith("org.junit.jupiter") || name.startsWith("org.junit.platform")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
101-
collector.addResolutionModification(project.getProject(), "JUnit 5 bundles", null, null);////$NON-NLS-1$
102-
return collector.getProposals();
103-
}
104-
10583
IRunnableWithProgress findOperation = new FindClassResolutionsOperation(project.getProject(), name, collector);
10684
try {
10785
findOperation.run(new NullProgressMonitor());

0 commit comments

Comments
 (0)