Skip to content

Commit 97acf6c

Browse files
Neha Burnwalgireeshpunathil
authored andcommitted
Quick fix to provide an option to update user directive to mandatory
singleton true directive(if not present)
1 parent 85df6d3 commit 97acf6c

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ private void validateSingleton(IHeader header, ManifestElement element) {
431431
// must check the existence of plugin.xml file instead of using IPluginBase because if the bundle is not a singleton,
432432
// it won't be registered with the extension registry and will always return 0 when querying extensions/extension points
433433
boolean hasExtensions = base != null && PDEProject.getPluginXml(fProject).exists();
434-
435434
if (hasExtensions) {
436435
if (TargetPlatformHelper.getTargetVersion() >= 3.1) {
437436
if (!"true".equals(singletonDir)) { //$NON-NLS-1$
@@ -444,6 +443,21 @@ private void validateSingleton(IHeader header, ManifestElement element) {
444443
return;
445444
}
446445
} else {
446+
Enumeration<String> attrKeys = element.getDirectiveKeys();
447+
int length = 0;
448+
String key = null;
449+
while (attrKeys.hasMoreElements()) {
450+
key = attrKeys.nextElement();
451+
length++;
452+
}
453+
if (length == 1) {
454+
String message = NLS.bind(PDECoreMessages.BundleErrorReporter_singletonRequired,
455+
Constants.SINGLETON_DIRECTIVE);
456+
VirtualMarker marker = report(message, header.getLineNumber(), CompilerFlags.ERROR,
457+
PDEMarkerFactory.M_SINGLETON_DIR_CHANGE, PDEMarkerFactory.CAT_FATAL);
458+
addMarkerAttribute(marker, "userDirective", key); //$NON-NLS-1$
459+
return;
460+
}
447461
String message = NLS.bind(PDECoreMessages.BundleErrorReporter_singletonRequired, Constants.SINGLETON_DIRECTIVE);
448462
report(message, header.getLineNumber(), CompilerFlags.ERROR, PDEMarkerFactory.M_SINGLETON_DIR_NOT_SET, PDEMarkerFactory.CAT_FATAL);
449463
return;

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/PDEMarkerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class PDEMarkerFactory {
7676
public static final int M_EXEC_ENV_TOO_LOW = 0x1029; // other problem
7777
public static final int M_CONFLICTING_AUTOMATIC_MODULE = 0x1030; // other
7878
// problem
79+
public static final int M_SINGLETON_DIR_CHANGE = 0x1033; // other problem
7980

8081
// build properties fixes
8182
public static final int B_APPEND_SLASH_FOLDER_ENTRY = 0x2001;

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ public class PDEUIMessages extends NLS {
716716
public static String Errors_CreationError;
717717
public static String Errors_CreationError_NoWizard;
718718

719+
public static String UpdateSingleton_dir_label;
720+
719721
public static String UpdateSplashHandlerInModelAction_msgAddingExtension;
720722

721723
public static String UpdateSplashHandlerInModelAction_msgAddingExtensionPoint;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
6565
return new IMarkerResolution[] {new CreateJREBundleHeaderResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker)};
6666
case PDEMarkerFactory.M_SINGLETON_DIR_NOT_SET :
6767
return new IMarkerResolution[] {new AddSingletonToSymbolicName(AbstractPDEMarkerResolution.RENAME_TYPE, true, marker)};
68+
case PDEMarkerFactory.M_SINGLETON_DIR_CHANGE:
69+
return updateSingletonProposal(marker);
6870
case PDEMarkerFactory.M_SINGLETON_ATT_NOT_SET :
6971
return new IMarkerResolution[] {new AddSingletonToSymbolicName(AbstractPDEMarkerResolution.RENAME_TYPE, false,marker)};
7072
case PDEMarkerFactory.M_SINGLETON_DIR_NOT_SUPPORTED :
@@ -151,6 +153,13 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
151153
return NO_RESOLUTIONS;
152154
}
153155

156+
private IMarkerResolution[] updateSingletonProposal(IMarker marker) {
157+
return new IMarkerResolution[] {
158+
new UpdateSingletonToSymbolicName(AbstractPDEMarkerResolution.RENAME_TYPE, true, marker),
159+
new AddSingletonToSymbolicName(AbstractPDEMarkerResolution.RENAME_TYPE, true, marker) };
160+
161+
}
162+
154163
/**
155164
* Checks for the <<code>problemID</code> attribute first, failing
156165
* that returns the <code>id</code> attribute.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.eclipse.pde.internal.ui.correction;
2+
3+
import org.eclipse.core.resources.IMarker;
4+
import org.eclipse.osgi.util.NLS;
5+
import org.eclipse.pde.internal.core.TargetPlatformHelper;
6+
import org.eclipse.pde.internal.core.ibundle.IBundle;
7+
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
8+
import org.eclipse.pde.internal.core.text.bundle.Bundle;
9+
import org.eclipse.pde.internal.core.text.bundle.BundleModel;
10+
import org.eclipse.pde.internal.core.text.bundle.BundleSymbolicNameHeader;
11+
import org.eclipse.pde.internal.ui.PDEUIMessages;
12+
import org.osgi.framework.Constants;
13+
14+
public class UpdateSingletonToSymbolicName extends AbstractManifestMarkerResolution {
15+
16+
private final boolean fisDirective;
17+
18+
public UpdateSingletonToSymbolicName(int type, boolean directive, IMarker marker) {
19+
super(type, marker);
20+
fisDirective = directive;
21+
}
22+
23+
@Override
24+
public String getLabel() {
25+
String userDirective = marker.getAttribute("userDirective", null); //$NON-NLS-1$
26+
return NLS.bind(PDEUIMessages.UpdateSingleton_dir_label, userDirective);
27+
}
28+
29+
@Override
30+
protected void createChange(BundleModel model) {
31+
IBundle bundle = model.getBundle();
32+
if (bundle instanceof Bundle bun) {
33+
IManifestHeader header = bun.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
34+
if (header instanceof BundleSymbolicNameHeader) {
35+
if (fisDirective && TargetPlatformHelper.getTargetVersion() >= 3.1)
36+
bundle.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
37+
else if (!fisDirective && TargetPlatformHelper.getTargetVersion() < 3.1)
38+
bundle.setHeader(Constants.BUNDLE_MANIFESTVERSION, null);
39+
String entry = ((BundleSymbolicNameHeader) header).getValue();
40+
int ind1 = entry.indexOf(';');
41+
int ind2 = entry.indexOf(':');
42+
String invalidDir = entry.substring(ind1 + 1, ind2);
43+
((BundleSymbolicNameHeader) header).setDirective(invalidDir, null);
44+
((BundleSymbolicNameHeader) header).setDirective(Constants.SINGLETON_DIRECTIVE, String.valueOf(true));
45+
}
46+
}
47+
}
48+
49+
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,7 @@ ControlValidationUtility_errorMsgKeyNotFound=The specified key is not present in
25202520
ControlValidationUtility_errorMsgFilterInvalidSyntax=The specified platform filter contains invalid syntax
25212521
PackageFinder_taskName=Searching class files for package references
25222522

2523+
UpdateSingleton_dir_label=Update ''{0}'' to 'singleton' directive true
25232524
UpdateSplashHandlerInModelAction_nameEmbedded=Embedded
25242525
UpdateSplashHandlerInModelAction_nameRCP=RCP
25252526
UpdateSplashHandlerInModelAction_templateTypeBrowser=Browser - An embedded HTML browser

0 commit comments

Comments
 (0)