Skip to content

Commit

Permalink
Action to convert MANIFEST-first PDE projects to PDE automatic manifest
Browse files Browse the repository at this point in the history
If one has a traditional MANIFEST-first PDE project and want to make use
of the new automatic manifest generation these can include some tedious
steps to perform that are prone to errors.

This adds a new refactoring wizard that helps the user in perform the
necessary steps in a convenient and configurable way.

Fix #703
  • Loading branch information
laeubi committed Nov 30, 2023
1 parent fc8ce0b commit d48880a
Show file tree
Hide file tree
Showing 17 changed files with 1,355 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,15 @@ private static IPluginModelBase[] findModels(String id) {
* @since 3.7
*/
public static IBuildModel createBuildModel(IPluginModelBase model) throws CoreException {
IProject project = model.getUnderlyingResource().getProject();
if (project != null) {
IFile buildFile = PDEProject.getBuildProperties(project);
if (buildFile.exists()) {
IBuildModel buildModel = new WorkspaceBuildModel(buildFile);
buildModel.load();
return buildModel;
if (model != null) {
IProject project = model.getUnderlyingResource().getProject();
if (project != null) {
IFile buildFile = PDEProject.getBuildProperties(project);
if (buildFile.exists()) {
IBuildModel buildModel = new WorkspaceBuildModel(buildFile);
buildModel.load();
return buildModel;
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class BndProject extends BaseProject {

public static final String INSTRUCTIONS_FILE = "pde" + INSTRUCTIONS_FILE_EXTENSION; //$NON-NLS-1$

public static final String BUILDER_ID = "org.eclipse.pde.BndBuilder"; //$NON-NLS-1$

@Override
public void configure() throws CoreException {
addToBuildSpec(BndBuilder.BUILDER_ID);
Expand Down
4 changes: 3 additions & 1 deletion ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ Require-Bundle:
org.eclipse.help;bundle-version="[3.10.200,4.0.0)",
org.eclipse.equinox.bidi;bundle-version="[1.4.300,2.0.0)",
org.eclipse.equinox.security;bundle-version="[1.4.100,2.0.0)",
org.eclipse.pde.bnd.ui;bundle-version="1.0.0"
org.eclipse.pde.bnd.ui;bundle-version="1.0.0",
org.eclipse.pde.ds.core;bundle-version="1.3.300"
Import-Package: aQute.bnd.build;version="4.5.0",
aQute.bnd.build.model;version="[4.2.0,5.0.0)",
aQute.bnd.build.model.clauses;version="2.5.0",
aQute.bnd.header;version="[2.5.0,3.0.0)",
aQute.bnd.help;version="2.0.0",
aQute.bnd.osgi;version="[5.6.0,8.0.0)",
Expand Down
2 changes: 2 additions & 0 deletions ui/org.eclipse.pde.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ command.organizeManifests.name = Organize Manifests
command.organizeManifests.label= &Organize Manifests...
command.organizeManifests.description = Cleans up plug-in manifest files

command.convertAutomaticManifest.label=Convert to &Automatic Manifest Generation...

command.externalizeStrings.description = Extract translatable strings from plug-in files
command.externalizeStrings.name = Externalize Strings in Plug-ins
command.externalizeStrings.label = E&xternalize Strings...
Expand Down
22 changes: 21 additions & 1 deletion ui/org.eclipse.pde.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,10 @@
class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction"
commandId="org.eclipse.pde.ui.organizeManifest">
</handler>
<handler
class="org.eclipse.pde.internal.ui.wizards.tools.ConvertAutomaticManifestAction"
commandId="org.eclipse.pde.ui.convertAutomaticManifest">
</handler>
<handler
class="org.eclipse.pde.internal.ui.nls.GetNonExternalizedStringsAction"
commandId="org.eclipse.pde.ui.externalizeStrings">
Expand Down Expand Up @@ -1952,9 +1956,25 @@
</reference>
</visibleWhen>
</command>
<separator
name="group3"
visible="true">
</separator>
<command
commandId="org.eclipse.pde.ui.convertAutomaticManifest"
icon="icons/obj16/toc_leaftopic_obj.png"
label="%command.convertAutomaticManifest.label"
style="push">
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.pde.ui.pluginFile">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
<extension
point="org.eclipse.ui.ide.markerSupport">
<markerGroupingEntry id="org.eclipse.pde.ui.jdt_category.pde"
markerGrouping="org.eclipse.jdt.ui.java_marker_category"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ public class PDEUIMessages extends NLS {
public static String OrganizeManifestsProcessor_invalidParam;

public static String OrganizeManifestsProcessor_rootMessage;
public static String ConvertAutomaticManifestsProcessor_rootMessage;
public static String ConvertAutomaticManifestsProcessor_changeProject;

public static String ConvertAutomaticManifestsWizardSettingsPage_convert_to_annotations;

public static String ConvertAutomaticManifestsWizardSettingsPage_description;

public static String ConvertAutomaticManifestsWizardSettingsPage_manifest;

public static String ConvertAutomaticManifestsWizardSettingsPage_manifest_at_output;

public static String ConvertAutomaticManifestsWizardSettingsPage_manifest_at_root;

public static String ConvertAutomaticManifestsWizardSettingsPage_discard;

public static String ConvertAutomaticManifestsWizardSettingsPage_keep;

public static String ConvertAutomaticManifestsWizardSettingsPage_to_instructions;

public static String PDECompilersConfigurationBlock_0;
public static String PDECompilersConfigurationBlock_1;
Expand Down Expand Up @@ -2548,10 +2566,14 @@ public class PDEUIMessages extends NLS {

public static String ClassSearchParticipant_taskMessage;

public static String CreateJarChange_instruction_jar;

public static String CreateJREBundleHeaderResolution_desc;

public static String CreateJREBundleHeaderResolution_label;

public static String CreatePackageInfoChange_name;

public static String UpdateActivationResolution_lazyStart_desc;

public static String UpdateActivationResolution_lazyStart_label;
Expand Down Expand Up @@ -2604,6 +2626,7 @@ public class PDEUIMessages extends NLS {
public static String ConfigureTargetPlatformResolution_description;

public static String OrganizeManifestJob_taskName;
public static String ConvertAutomaticManifestJob_taskName;

public static String RemoveImportPkgResolution_description;

Expand Down Expand Up @@ -2939,6 +2962,8 @@ public class PDEUIMessages extends NLS {

public static String OrganizeManifestsWizardPage_title;

public static String ConvertAutomaticManifestWizardPage_title;

public static String OrganizeManifestsWizardPage_description;

public static String OrganizeManifestsWizardPage_errorMsg;
Expand Down Expand Up @@ -3362,4 +3387,11 @@ public class PDEUIMessages extends NLS {
public static String ExtensionAttributeRow_AttrLabelDepr;
public static String ExtensionAttributeRow_AttrLabelReq;
public static String ExtensionAttributeRow_AttrLabelReqDepr;

public static String ProjectUpdateChange_configure_nature_and_builder;
public static String ProjectUpdateChange_convert_manifest_to_bnd;
public static String ProjectUpdateChange_convert_build_to_bnd;
public static String ProjectUpdateChange_set_pde_preference;

}

Original file line number Diff line number Diff line change
Expand Up @@ -2277,11 +2277,13 @@ RequiredExecutionEnvironmentSection_pluginDesc=Specify the minimum execution env
RequiredExecutionEnvironmentSection_dialog_title=Execution Environments
RequiredExecutionEnvironmentSection_dialogMessage=Select an execution environment:
ClassSearchParticipant_taskMessage=Searching for types and packages in manifest files
CreateJarChange_instruction_jar=create instruction file for jar {0}
CreateJREBundleHeaderResolution_desc=Add the Eclipse-JREBundle header. This will enable the code to compile but it will still fail to run.
CreateManifestClassResolution_label=Create a new class for the {0} header...
CreateModuleInfoPDEAction_mod_info_not_in_sync=Module-info file created in a plugin project may not be synchronized with the manifest file.
CreateModuleInfoPDEAction_sync_issue=Synchronization Issue
CreateJREBundleHeaderResolution_label=add the Eclipse-JREBundle header
CreatePackageInfoChange_name=Create {0} for package {1}
RemoveBuildOrderEntries_label=remove all <project> entries
RemoveNodeXMLResolution_label=Remove the {0} element.
RemoveNodeXMLResolution_attrLabel=Remove the {0} attribute.
Expand Down Expand Up @@ -2315,8 +2317,10 @@ ConfigureProblemSeverityForPDECompiler_6=Open the Plug-in Development > Compiler
ConfigureTargetPlatformResolution_label=Configure Target-Platform...
ConfigureTargetPlatformResolution_description=Open preference page to configure the Target-Platforms. Target-Platforms describe which external artifacts are visible while developing plugins.
OrganizeManifestJob_taskName=Organizing Manifest Headers...
ConvertAutomaticManifestJob_taskName=Converting to Automatic Manifest generation...
OrganizeManifestsWizard_title=Organize Manifests Wizard
OrganizeManifestsWizardPage_title=Organize Manifests
ConvertAutomaticManifestWizardPage_title=Convert to Automatic Manifest Generation
OrganizeManifestsWizardPage_remove=&removing them
OrganizeManifestsOperation_export=organizing export packages... {0}
OrganizeManifestsOperation_unusedDeps=removing unused dependencies... {0}
Expand All @@ -2328,6 +2332,16 @@ OrganizeManifestsOperation_nlIconPath=checking icon paths for missing $nl$ segme
OrganizeManifestsOperation_unusedKeys=checking for unused keys... {0}
OrganizeManifestsWizardPage_addMissing=&Ensure that all packages appear in the MANIFEST.MF
OrganizeManifestsProcessor_rootMessage=Organize Manifest for {0}
ConvertAutomaticManifestsProcessor_rootMessage=Converting {0}...
ConvertAutomaticManifestsProcessor_changeProject=Convert project {0}
ConvertAutomaticManifestsWizardSettingsPage_convert_to_annotations=convert to annotations
ConvertAutomaticManifestsWizardSettingsPage_description=Please choose options below to converts your existing plugin-project into one using automatic manifest generation.
ConvertAutomaticManifestsWizardSettingsPage_manifest=Generate manifest at
ConvertAutomaticManifestsWizardSettingsPage_manifest_at_output=output folder
ConvertAutomaticManifestsWizardSettingsPage_manifest_at_root=project root
ConvertAutomaticManifestsWizardSettingsPage_discard=discard
ConvertAutomaticManifestsWizardSettingsPage_keep=keep
ConvertAutomaticManifestsWizardSettingsPage_to_instructions=to instructions
OrganizeManifestsWizardPage_lazyStart=Remove unnecessary lazy activation headers
OrganizeManifestsWizardPage_uselessPluginFile=Delete unnecessary plugin manifest files
OrganizeManifestsOperation_filterInternal=marking export packages matching filter as internal... {0}
Expand Down Expand Up @@ -2672,3 +2686,7 @@ ExtensionAttributeRow_AttrLabelDepr={0}(!):
ExtensionAttributeRow_AttrLabelReq={0}*:
ExtensionAttributeRow_AttrLabelReqDepr={0}(!)*:
AnnotationHover_version_change={0} \n Reason for this version change: \n {1}
ProjectUpdateChange_configure_nature_and_builder=Update natures and builder
ProjectUpdateChange_convert_manifest_to_bnd=Convert MANIFEST.MF to bnd instructions
ProjectUpdateChange_convert_build_to_bnd=Convert build.properties to bnd instructions
ProjectUpdateChange_set_pde_preference=Set {0} in preferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.ui.wizards.tools;

import java.util.List;
import java.util.Objects;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.pde.internal.core.natures.BndProject;
import org.eclipse.pde.internal.core.natures.PDE;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* Command handler to run the convert to automatic manifests operation.
*
*/
public class ConvertAutomaticManifestAction extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (PlatformUI.getWorkbench().saveAllEditors(true)) {
// only do our work when all work is committed to files...
if (HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection selection) {
List<IProject> projects = selection.stream().map(ConvertAutomaticManifestAction::toProject)
.filter(Objects::nonNull)
.filter(proj -> PDE.hasPluginNature(proj))
.filter(proj -> !BndProject.isBndProject(proj)).toList();
if (projects.isEmpty()) {
MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(),
PDEUIMessages.ConvertAutomaticManifestWizardPage_title,
PDEUIMessages.OrganizeManifestsWizardPage_errorMsg);
return null;
}
RefactoringWizardOpenOperation refactoringOperation = new RefactoringWizardOpenOperation(new ConvertAutomaticManifestsWizard(projects));
try {
refactoringOperation.run(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.ConvertAutomaticManifestWizardPage_title);
} catch (final InterruptedException e) {
// ignore...
}
}
}
return null;
}

private static IProject toProject(Object object) {
if (object instanceof IJavaProject java) {
return java.getProject();
}
if (object instanceof IResource resource) {
return resource.getProject();
}
return null;
}

}
Loading

0 comments on commit d48880a

Please sign in to comment.