Skip to content

Commit 39ff900

Browse files
committed
add an editor for p2.inf
1 parent 6640099 commit 39ff900

File tree

9 files changed

+316
-12
lines changed

9 files changed

+316
-12
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2021, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2024 IBM Corporation and others.
2+
* Copyright (c) 2010, 2024, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -260,6 +260,30 @@ 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+
* @return <code>META-INF/p2.inf</code> file that may or may not exist
269+
*/
270+
public static IFile getBundleP2Inf(IProject project) {
271+
return getBundleRelativeFile(project, ICoreConstants.P2_INF_BUNDLE_PATH);
272+
}
273+
274+
/**
275+
* Returns the resource in the specified project corresponding to its
276+
* <code>p2.inf</code> file (for feature projects). Feature projects have
277+
* the p2.inf file in the project root, not in META-INF.
278+
*
279+
* @param project
280+
* project
281+
* @return <code>p2.inf</code> file that may or may not exist
282+
*/
283+
public static IFile getFeatureP2Inf(IProject project) {
284+
return getBundleRelativeFile(project, ICoreConstants.P2_INF_FEATURE_PATH);
285+
}
286+
263287
/**
264288
* Returns a file relative to the bundle root of the specified project.
265289
*

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2021, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -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

@@ -426,9 +449,18 @@ protected boolean isPatchEditor() {
426449
public void showEditorInput(IEditorInput editorInput) {
427450
String name = editorInput.getName();
428451
if (name.equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR)) {
429-
setActivePage(0);
430-
} else {
431-
setActivePage(getPageCount() - 3);
452+
setActivePage(FeatureFormPage.PAGE_ID);
453+
} else if (name.equalsIgnoreCase(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)) {
454+
IFormPage uiPage = findPage(BuildPage.PAGE_ID);
455+
if (uiPage != null) {
456+
setActivePage(uiPage.getId());
457+
}
458+
459+
} else if (name.equalsIgnoreCase(ICoreConstants.P2_INF_FILENAME)) {
460+
IFormPage page = findPage(P2InfInputContext.CONTEXT_ID);
461+
if (page != null) {
462+
setActivePage(page.getId());
463+
}
432464
}
433465
}
434466

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2015 IBM Corporation and others.
2+
* Copyright (c) 2005, 2015, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -45,11 +45,18 @@ public boolean matches(IEditorReference editorRef, IEditorInput input) {
4545
// build.properties matches with editors that have a feature.xml file
4646
// as their input and that feature.xml is at the root
4747
if (inputFile.getName().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR)) {
48-
if (currInputFile.getName().equals(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)) {
48+
if (currInputFile.getName().equals(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)
49+
|| currInputFile.getName().equals(ICoreConstants.P2_INF_FILENAME)) {
4950
return inputFile.getProjectRelativePath().toString().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR);
5051
}
5152
return inputFile.equals(currInputFile);
5253
} else if (inputFile.getName().equals(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)) {
54+
if (currInputFile.getName().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR))
55+
return currInputFile.getProjectRelativePath().toString().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR);
56+
return inputFile.equals(currInputFile);
57+
} else if (inputFile.getName().equals(ICoreConstants.P2_INF_FILENAME)) {
58+
// p2.inf should match the feature editor when the current editor
59+
// input is the feature.xml at the project root
5360
if (currInputFile.getName().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR)) {
5461
return currInputFile.getProjectRelativePath().toString().equals(ICoreConstants.FEATURE_FILENAME_DESCRIPTOR);
5562
}
@@ -60,5 +67,4 @@ public boolean matches(IEditorReference editorRef, IEditorInput input) {
6067
return false;
6168
}
6269
}
63-
64-
}
70+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.pde.internal.ui.editor.p2inf;
15+
16+
import java.nio.charset.Charset;
17+
import java.nio.charset.StandardCharsets;
18+
import java.util.ArrayList;
19+
20+
import org.eclipse.core.runtime.CoreException;
21+
import org.eclipse.jface.text.IDocument;
22+
import org.eclipse.pde.core.IBaseModel;
23+
import org.eclipse.pde.core.IModelChangedEvent;
24+
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
25+
import org.eclipse.pde.internal.ui.editor.context.InputContext;
26+
import org.eclipse.text.edits.TextEdit;
27+
import org.eclipse.ui.IEditorInput;
28+
29+
public class P2InfInputContext extends InputContext {
30+
public static final String P2_INF_PARTITION = "___p2_inf_partition"; //$NON-NLS-1$
31+
32+
public static final String CONTEXT_ID = "p2inf-context"; //$NON-NLS-1$
33+
34+
public P2InfInputContext(PDEFormEditor editor, IEditorInput input, boolean primary) {
35+
super(editor, input, primary);
36+
create();
37+
}
38+
39+
@Override
40+
protected Charset getDefaultCharset() {
41+
return StandardCharsets.UTF_8;
42+
}
43+
44+
@Override
45+
protected IBaseModel createModel(IEditorInput input) throws CoreException {
46+
IDocument document = getDocumentProvider().getDocument(input);
47+
P2InfModel model = new P2InfModel(document);
48+
model.load();
49+
return model;
50+
}
51+
52+
@Override
53+
public P2InfModel getModel() {
54+
return (P2InfModel) super.getModel();
55+
}
56+
57+
@Override
58+
public String getId() {
59+
return CONTEXT_ID;
60+
}
61+
62+
@Override
63+
protected void addTextEditOperation(ArrayList<TextEdit> ops, IModelChangedEvent event) {
64+
65+
}
66+
67+
@Override
68+
public void doRevert() {
69+
// Revert to the saved version by reloading the model from the document
70+
P2InfModel model = getModel();
71+
if (model != null) {
72+
model.load();
73+
}
74+
}
75+
76+
@Override
77+
protected String getPartitionName() {
78+
return P2_INF_PARTITION;
79+
}
80+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.pde.internal.ui.editor.p2inf;
15+
16+
import org.eclipse.jface.text.IDocument;
17+
import org.eclipse.pde.core.IBaseModel;
18+
import org.eclipse.pde.core.IModelChangeProvider;
19+
import org.eclipse.pde.core.IModelChangedEvent;
20+
import org.eclipse.pde.core.IModelChangedListener;
21+
22+
public class P2InfModel implements IBaseModel, IModelChangeProvider {
23+
24+
private final IDocument document;
25+
private volatile boolean valid;
26+
private volatile boolean disposed;
27+
28+
public P2InfModel(IDocument document) {
29+
this.document = document;
30+
}
31+
32+
public void load() {
33+
valid = document != null;
34+
}
35+
36+
public IDocument getDocument() {
37+
return document;
38+
}
39+
40+
@Override
41+
public boolean isEditable() {
42+
return true;
43+
}
44+
45+
@Override
46+
public boolean isValid() {
47+
return valid;
48+
}
49+
50+
@Override
51+
public boolean isDisposed() {
52+
return disposed;
53+
}
54+
55+
@Override
56+
public void dispose() {
57+
disposed = true;
58+
}
59+
60+
@Override
61+
public <T> T getAdapter(Class<T> adapter) {
62+
if (adapter == IDocument.class) {
63+
return adapter.cast(document);
64+
}
65+
return null;
66+
}
67+
68+
@Override
69+
public void addModelChangedListener(IModelChangedListener listener) {
70+
}
71+
72+
@Override
73+
public void fireModelChanged(IModelChangedEvent event) {
74+
}
75+
76+
@Override
77+
public void fireModelObjectChanged(Object object, String property, Object oldValue, Object newValue) {
78+
}
79+
80+
@Override
81+
public void removeModelChangedListener(IModelChangedListener listener) {
82+
}
83+
}

0 commit comments

Comments
 (0)