Skip to content

Commit 7ed92bb

Browse files
committed
add an editor for p2.inf
1 parent d2bff11 commit 7ed92bb

File tree

8 files changed

+300
-0
lines changed

8 files changed

+300
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,18 @@ public interface ICoreConstants {
312312
String OSGI_INF_FOLDER_NAME = "OSGI-INF/"; //$NON-NLS-1$
313313
String FEATURE_FOLDER_NAME = "features"; //$NON-NLS-1$
314314

315+
String P2_INF_FILENAME = "p2.inf"; //$NON-NLS-1$
316+
String P2_INF_BUNDLE_DESCRIPTOR = "META-INF/p2.inf"; //$NON-NLS-1$
317+
315318
// Common paths
316319
IPath MANIFEST_PATH = IPath.fromOSString(BUNDLE_FILENAME_DESCRIPTOR);
317320
IPath PLUGIN_PATH = IPath.fromOSString(PLUGIN_FILENAME_DESCRIPTOR);
318321
IPath FRAGMENT_PATH = IPath.fromOSString(FRAGMENT_FILENAME_DESCRIPTOR);
319322
IPath FEATURE_PATH = IPath.fromOSString(FEATURE_FILENAME_DESCRIPTOR);
320323
IPath BUILD_PROPERTIES_PATH = IPath.fromOSString(BUILD_FILENAME_DESCRIPTOR);
321324
IPath OSGI_INF_PATH = IPath.fromOSString(OSGI_INF_FOLDER_NAME);
325+
IPath P2_INF_BUNDLE_PATH = IPath.fromOSString(P2_INF_BUNDLE_DESCRIPTOR);
326+
IPath P2_INF_FEATURE_PATH = IPath.fromOSString(P2_INF_FILENAME);
322327

323328
// Extension point identifiers
324329
String EXTENSION_POINT_SOURCE = PDECore.PLUGIN_ID + ".source"; //$NON-NLS-1$

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/project/PDEProject.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,31 @@ public static IFolder getMetaInf(IProject project) {
260260
return getBundleRelativeFolder(project, IPath.fromOSString(ICoreConstants.MANIFEST_FOLDER_NAME));
261261
}
262262

263+
/**
264+
* Returns the resource in the specified project corresponding to its
265+
* <code>META-INF/p2.inf</code> file (for bundle/plugin projects).
266+
*
267+
* @param project project
268+
* @param path bundle root relative path
269+
* @return <code>META-INF/p2.inf</code> file that may or may not exist
270+
*/
271+
public static IFile getBundleP2Inf(IProject project) {
272+
return getBundleRelativeFile(project, ICoreConstants.P2_INF_BUNDLE_PATH);
273+
}
274+
275+
/**
276+
* Returns the resource in the specified project corresponding to its
277+
* <code>p2.inf</code> file (for feature projects). Feature projects have
278+
* the p2.inf file in the project root, not in META-INF.
279+
*
280+
* @param project
281+
* project
282+
* @return <code>p2.inf</code> file that may or may not exist
283+
*/
284+
public static IFile getFeatureP2Inf(IProject project) {
285+
return getBundleRelativeFile(project, ICoreConstants.P2_INF_FEATURE_PATH);
286+
}
287+
263288
/**
264289
* Returns a file relative to the bundle root of the specified project.
265290
*

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureEditor.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
import org.eclipse.pde.internal.ui.editor.build.BuildSourcePage;
5353
import org.eclipse.pde.internal.ui.editor.context.InputContext;
5454
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
55+
import org.eclipse.pde.internal.ui.editor.p2inf.P2InfInputContext;
56+
import org.eclipse.pde.internal.ui.editor.p2inf.P2InfSourcePage;
5557
import org.eclipse.swt.SWTError;
5658
import org.eclipse.swt.dnd.RTFTransfer;
5759
import org.eclipse.swt.dnd.TextTransfer;
@@ -172,8 +174,14 @@ protected void createResourceContexts(InputContextManager manager, IFileEditorIn
172174
FileEditorInput in = new FileEditorInput(buildFile);
173175
manager.putContext(in, new BuildInputContext(this, in, file == buildFile));
174176
}
177+
IFile p2InfFile = PDEProject.getFeatureP2Inf(project);
178+
if (p2InfFile != null && p2InfFile.exists()) {
179+
FileEditorInput in = new FileEditorInput(p2InfFile);
180+
manager.putContext(in, new P2InfInputContext(this, in, false));
181+
}
175182
manager.monitorFile(featureFile);
176183
manager.monitorFile(buildFile);
184+
manager.monitorFile(p2InfFile);
177185
}
178186

179187
@Override
@@ -200,6 +208,11 @@ public void monitoredFileAdded(IFile file) {
200208
IEditorInput in = new FileEditorInput(file);
201209
fInputContextManager.putContext(in, new BuildInputContext(this, in, false));
202210
}
211+
} else if (name.equalsIgnoreCase(ICoreConstants.P2_INF_FILENAME)) {
212+
if (!fInputContextManager.hasContext(P2InfInputContext.CONTEXT_ID)) {
213+
IEditorInput in = new FileEditorInput(file);
214+
fInputContextManager.putContext(in, new P2InfInputContext(this, in, false));
215+
}
203216
}
204217
}
205218

@@ -254,6 +267,12 @@ protected void createSystemFileContexts(InputContextManager manager, FileStoreEd
254267
IEditorInput in = new FileStoreEditorInput(store);
255268
manager.putContext(in, new BuildInputContext(this, in, file == buildFile));
256269
}
270+
File p2InfFile = new File(file.getParentFile(), ICoreConstants.P2_INF_FILENAME);
271+
if (p2InfFile.exists()) {
272+
IFileStore store = EFS.getStore(p2InfFile.toURI());
273+
IEditorInput in = new FileStoreEditorInput(store);
274+
manager.putContext(in, new P2InfInputContext(this, in, false));
275+
}
257276
} catch (CoreException e) {
258277
PDEPlugin.logException(e);
259278
}
@@ -298,6 +317,7 @@ protected void addEditorPages() {
298317
}
299318
addSourcePage(FeatureInputContext.CONTEXT_ID);
300319
addSourcePage(BuildInputContext.CONTEXT_ID);
320+
addSourcePage(P2InfInputContext.CONTEXT_ID);
301321
}
302322

303323
@Override
@@ -323,6 +343,9 @@ protected IEditorPart createSourcePage(PDEFormEditor editor, String title, Strin
323343
if (contextId.equals(BuildInputContext.CONTEXT_ID)) {
324344
return new BuildSourcePage(editor, title, name);
325345
}
346+
if (contextId.equals(P2InfInputContext.CONTEXT_ID)) {
347+
return new P2InfSourcePage(editor, contextId, title);
348+
}
326349
return super.createSourcePage(editor, title, name, contextId);
327350
}
328351

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.eclipse.pde.internal.ui.editor.p2inf;
2+
3+
import java.nio.charset.Charset;
4+
import java.nio.charset.StandardCharsets;
5+
import java.util.ArrayList;
6+
7+
import org.eclipse.core.runtime.CoreException;
8+
import org.eclipse.jface.text.IDocument;
9+
import org.eclipse.pde.core.IBaseModel;
10+
import org.eclipse.pde.core.IModelChangedEvent;
11+
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
12+
import org.eclipse.pde.internal.ui.editor.context.InputContext;
13+
import org.eclipse.text.edits.TextEdit;
14+
import org.eclipse.ui.IEditorInput;
15+
16+
public class P2InfInputContext extends InputContext {
17+
public static final String P2_INF_PARTITION = "___p2_inf_partition"; //$NON-NLS-1$
18+
19+
public static final String CONTEXT_ID = "p2inf-context"; //$NON-NLS-1$
20+
21+
public P2InfInputContext(PDEFormEditor editor, IEditorInput input, boolean primary) {
22+
super(editor, input, primary);
23+
create();
24+
}
25+
26+
@Override
27+
protected Charset getDefaultCharset() {
28+
return StandardCharsets.UTF_8;
29+
}
30+
31+
@Override
32+
protected IBaseModel createModel(IEditorInput input) throws CoreException {
33+
IDocument document = getDocumentProvider().getDocument(input);
34+
P2InfModel model = new P2InfModel(document);
35+
model.load();
36+
return model;
37+
}
38+
39+
@Override
40+
public P2InfModel getModel() {
41+
return (P2InfModel) super.getModel();
42+
}
43+
44+
@Override
45+
public String getId() {
46+
return CONTEXT_ID;
47+
}
48+
49+
@Override
50+
protected void addTextEditOperation(ArrayList<TextEdit> ops, IModelChangedEvent event) {
51+
52+
}
53+
54+
@Override
55+
public void doRevert() {
56+
// Revert to the saved version by reloading the model from the document
57+
P2InfModel model = getModel();
58+
if (model != null) {
59+
model.load();
60+
}
61+
}
62+
63+
@Override
64+
protected String getPartitionName() {
65+
return P2_INF_PARTITION;
66+
}
67+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.eclipse.pde.internal.ui.editor.p2inf;
2+
3+
import org.eclipse.jface.text.IDocument;
4+
import org.eclipse.pde.core.IBaseModel;
5+
import org.eclipse.pde.core.IModelChangeProvider;
6+
import org.eclipse.pde.core.IModelChangedEvent;
7+
import org.eclipse.pde.core.IModelChangedListener;
8+
9+
public class P2InfModel implements IBaseModel, IModelChangeProvider {
10+
11+
private final IDocument document;
12+
private volatile boolean valid;
13+
private volatile boolean disposed;
14+
15+
public P2InfModel(IDocument document) {
16+
this.document = document;
17+
}
18+
19+
public void load() {
20+
valid = document != null;
21+
}
22+
23+
public IDocument getDocument() {
24+
return document;
25+
}
26+
27+
@Override
28+
public boolean isEditable() {
29+
return true;
30+
}
31+
32+
@Override
33+
public boolean isValid() {
34+
return valid;
35+
}
36+
37+
@Override
38+
public boolean isDisposed() {
39+
return disposed;
40+
}
41+
42+
@Override
43+
public void dispose() {
44+
disposed = true;
45+
}
46+
47+
@Override
48+
public <T> T getAdapter(Class<T> adapter) {
49+
if (adapter == IDocument.class) {
50+
return adapter.cast(document);
51+
}
52+
return null;
53+
}
54+
55+
@Override
56+
public void addModelChangedListener(IModelChangedListener listener) {
57+
}
58+
59+
@Override
60+
public void fireModelChanged(IModelChangedEvent event) {
61+
}
62+
63+
@Override
64+
public void fireModelObjectChanged(Object object, String property, Object oldValue, Object newValue) {
65+
}
66+
67+
@Override
68+
public void removeModelChangedListener(IModelChangedListener listener) {
69+
}
70+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.eclipse.pde.internal.ui.editor.p2inf;
2+
3+
import org.eclipse.jface.viewers.ILabelProvider;
4+
import org.eclipse.jface.viewers.ITreeContentProvider;
5+
import org.eclipse.pde.internal.ui.editor.KeyValueSourcePage;
6+
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
7+
8+
public class P2InfSourcePage extends KeyValueSourcePage {
9+
10+
public P2InfSourcePage(PDEFormEditor editor, String id, String title) {
11+
super(editor, id, title);
12+
}
13+
14+
@Override
15+
public ILabelProvider createOutlineLabelProvider() {
16+
return null;
17+
}
18+
19+
@Override
20+
public ITreeContentProvider createOutlineContentProvider() {
21+
return null;
22+
}
23+
24+
@Override
25+
public void updateSelection(Object object) {
26+
}
27+
28+
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
import org.eclipse.pde.internal.ui.editor.build.BuildSourcePage;
8383
import org.eclipse.pde.internal.ui.editor.context.InputContext;
8484
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
85+
import org.eclipse.pde.internal.ui.editor.p2inf.P2InfInputContext;
86+
import org.eclipse.pde.internal.ui.editor.p2inf.P2InfSourcePage;
8587
import org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction;
8688
import org.eclipse.swt.widgets.Display;
8789
import org.eclipse.ui.IEditorInput;
@@ -274,6 +276,12 @@ protected void createResourceContexts(InputContextManager manager, IFileEditorIn
274276
manager.putContext(in, new BuildInputContext(this, in, false));
275277
}
276278
manager.monitorFile(buildFile);
279+
IFile p2InfFile = container.getFile(ICoreConstants.P2_INF_BUNDLE_PATH);
280+
if (p2InfFile != null && p2InfFile.exists()) {
281+
FileEditorInput in = new FileEditorInput(p2InfFile);
282+
manager.putContext(in, new P2InfInputContext(this, in, false));
283+
}
284+
manager.monitorFile(p2InfFile);
277285

278286
fPrefs = new ProjectScope(container.getProject()).getNode(PDECore.PLUGIN_ID);
279287
if (fPrefs != null) {
@@ -325,6 +333,16 @@ public void monitoredFileAdded(IFile file) {
325333
IEditorInput in = new FileEditorInput(file);
326334
fInputContextManager.putContext(in, new BndInputContext(this, in, false));
327335
}
336+
} else if (name.equalsIgnoreCase(ICoreConstants.P2_INF_FILENAME)) {
337+
// check if p2.inf is in META-INF folder (for bundles)
338+
if (!fInputContextManager.hasContext(P2InfInputContext.CONTEXT_ID)) {
339+
IContainer parent = file.getParent();
340+
// compare with folder name "META-INF/"
341+
if (parent != null && "META-INF".equals(parent.getName())) { //$NON-NLS-1$
342+
IEditorInput in = new FileEditorInput(file);
343+
fInputContextManager.putContext(in, new P2InfInputContext(this, in, false));
344+
}
345+
}
328346
}
329347
}
330348

@@ -561,6 +579,7 @@ protected void addEditorPages() {
561579
addSourcePage(PluginInputContext.CONTEXT_ID);
562580
addSourcePage(BuildInputContext.CONTEXT_ID);
563581
addSourcePage(BndInputContext.CONTEXT_ID);
582+
addSourcePage(P2InfInputContext.CONTEXT_ID);
564583
}
565584

566585
private boolean isSourcePageID(String pageID) {
@@ -574,6 +593,7 @@ private boolean isSourcePageID(String pageID) {
574593
case PluginInputContext.CONTEXT_ID: // plugin.xml
575594
case BundleInputContext.CONTEXT_ID: // MANIFEST.MF
576595
case BndInputContext.CONTEXT_ID: // bnd instruction
596+
case P2InfInputContext.CONTEXT_ID: // p2.inf
577597
return true;
578598
default:
579599
break;
@@ -688,6 +708,9 @@ protected IEditorPart createSourcePage(PDEFormEditor editor, String title, Strin
688708
if (contextId.equals(BndInputContext.CONTEXT_ID)) {
689709
return new BndSourcePage(editor, contextId, title);
690710
}
711+
if (contextId.equals(P2InfInputContext.CONTEXT_ID)) {
712+
return new P2InfSourcePage(editor, contextId, title);
713+
}
691714
return super.createSourcePage(editor, title, name, contextId);
692715
}
693716

0 commit comments

Comments
 (0)