From fb018544c0d4bc547b87431f00c598f430e0aaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Sat, 21 Nov 2026 16:24:35 +0100 Subject: [PATCH] fix: remove the unused Check project support from the Check UI The Check project and file wizards were removed in #1298, but their registrations stayed in plugin.xml, so File > New offered wizards that fail to start. Nothing in DDK adds the Check nature any more, so the Deploy and Undeploy menu, its jobs and the nature have no users either. Remove the wizard registrations, the Deploy and Undeploy menu with its actions, jobs, ProjectUtil and messages, the Check nature and its extension, and the checkcfg.core dependency that only the deploy job used. This also removes the last 3 deprecated popupMenus warnings in check.ui. Co-Authored-By: Claude Opus 5.5 --- .../META-INF/MANIFEST.MF | 5 +- com.avaloq.tools.ddk.check.ui/plugin.xml | 75 --- com.avaloq.tools.ddk.check.ui/pom.xml | 2 +- .../avaloq/tools/ddk/check/ui/Messages.java | 46 -- .../ddk/check/ui/internal/CheckNature.java | 47 -- .../tools/ddk/check/ui/messages.properties | 17 - .../check/ui/popup/actions/DeployAction.java | 40 -- .../ddk/check/ui/popup/actions/DeployJob.java | 433 ------------------ .../ui/popup/actions/UndeployAction.java | 40 -- .../check/ui/popup/actions/UndeployJob.java | 109 ----- .../tools/ddk/check/ui/util/ProjectUtil.java | 45 -- 11 files changed, 3 insertions(+), 856 deletions(-) delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/Messages.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/internal/CheckNature.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/messages.properties delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployAction.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployAction.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployJob.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/util/ProjectUtil.java diff --git a/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF index 1ecbefc599..0ce98a74f9 100644 --- a/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: com.avaloq.tools.ddk.check.ui Bundle-SymbolicName: com.avaloq.tools.ddk.check.ui;singleton:=true -Bundle-Version: 17.3.4.qualifier +Bundle-Version: 17.3.5.qualifier Bundle-Vendor: Avaloq Group AG Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-Activator: com.avaloq.tools.ddk.check.ui.internal.Activator @@ -30,8 +30,7 @@ Require-Bundle: com.avaloq.tools.ddk.xtext.builder, org.eclipse.ui.editors, org.eclipse.ui, org.eclipse.core.resources, - org.eclipse.jdt.debug.ui, - com.avaloq.tools.ddk.checkcfg.core + org.eclipse.jdt.debug.ui Export-Package: com.avaloq.tools.ddk.check.ui;x-friends:="com.avaloq.tools.ddk.check.ui.test", com.avaloq.tools.ddk.check.ui.builder.util, com.avaloq.tools.ddk.check.ui.contentassist, diff --git a/com.avaloq.tools.ddk.check.ui/plugin.xml b/com.avaloq.tools.ddk.check.ui/plugin.xml index 7a5ee347c2..fc235338b4 100644 --- a/com.avaloq.tools.ddk.check.ui/plugin.xml +++ b/com.avaloq.tools.ddk.check.ui/plugin.xml @@ -504,38 +504,6 @@ id="com.avaloq.tools.ddk.check.Check.rulerContextMenu.openBreapointPropertiesAction"> - - - - - - - - - - - - - - - - @@ -640,47 +608,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/com.avaloq.tools.ddk.check.ui/pom.xml b/com.avaloq.tools.ddk.check.ui/pom.xml index 06ef562dc9..c4972cc048 100644 --- a/com.avaloq.tools.ddk.check.ui/pom.xml +++ b/com.avaloq.tools.ddk.check.ui/pom.xml @@ -6,7 +6,7 @@ 18.0.1-SNAPSHOT ../ddk-parent - 17.3.4-SNAPSHOT + 17.3.5-SNAPSHOT com.avaloq.tools.ddk com.avaloq.tools.ddk.check.ui eclipse-plugin diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/Messages.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/Messages.java deleted file mode 100644 index d91dcc8d7c..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/Messages.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui; - -import org.eclipse.osgi.util.NLS; - - -/** - * TODO: Document type Messages. - */ -public class Messages extends NLS { - private static final String BUNDLE_NAME = "com.avaloq.tools.ddk.check.ui.messages"; //$NON-NLS-1$ - public static String DeployAction_DeployBundleLocally; - public static String DeployJob_DialogOk; - public static String DeployJob_CouldNotDeployCheckBundle; - public static String DeployJob_BundleAlreadyDeployed; - public static String DeployJob_TooManyCheckConfigurations; - public static String DeployJob_CannotDeployMoreThanOneCheckConfiguration; - public static String DeployJob_CouldNotCreateTemporaryDirectoryForJar; - public static String DeployJob_CouldNotSetPathVariable; - public static String DeployJob_CouldntGetBundleLocation; - public static String DeployJob_ExceptionWhileReadingTheCheckConfigurationFile; - public static String DeployJob_FailedToInstallAndStartBundle; - public static String DeployJob_FailedToReadBundle; - public static String UndeployAction_UndeployLocalBundle; - public static String UndeployJob_DundleUndeployed; - public static String UndeployJob_FailedToStopAndUninstallBundleWithSymbolicName; - public static String UndeployJob_FailedToUndeployCheckCofiguration; - public static String UndeployJob_NoBundleWithSymbolicNameInstalled; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/internal/CheckNature.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/internal/CheckNature.java deleted file mode 100644 index 02c03a3c13..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/internal/CheckNature.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.internal; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectNature; -import org.eclipse.core.runtime.CoreException; - - -/** - * Defines the nature of a check project within the workspace. - */ -public class CheckNature implements IProjectNature { - - public static final String CHECK_NATURE_ID = "com.avaloq.tools.ddk.check.ui.CheckNature"; //$NON-NLS-1$ - - /** The project. */ - private IProject project; - - @Override - public void configure() throws CoreException { - // nothing to do here. - } - - @Override - public void deconfigure() throws CoreException { - // nothing to do here. - } - - @Override - public IProject getProject() { - return project; - } - - @Override - public void setProject(final IProject project) { - this.project = project; - } -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/messages.properties b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/messages.properties deleted file mode 100644 index d10a1945fc..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/messages.properties +++ /dev/null @@ -1,17 +0,0 @@ -DeployAction_DeployBundleLocally=Deploy bundle locally -UndeployAction_UndeployLocalBundle=Undeploy local bundle -UndeployJob_DundleUndeployed=Bundle {0} undeployed. -UndeployJob_FailedToStopAndUninstallBundleWithSymbolicName=Failed to stop and uninstall bundle with symbolic name {0}. -UndeployJob_FailedToUndeployCheckCofiguration=Failed to undeploy check cofiguration. -UndeployJob_NoBundleWithSymbolicNameInstalled=No bundle with symbolic name {0} installed. -DeployJob_DialogOk=OK -DeployJob_CouldNotDeployCheckBundle=Could not deploy check bundle. -DeployJob_BundleAlreadyDeployed=Bundle {0} already deployed. Stoping and uninstalling it. -DeployJob_TooManyCheckConfigurations=Too many check configurations -DeployJob_CannotDeployMoreThanOneCheckConfiguration=Cannot deploy more than one check configuration. Please makes sure that there is only one configuration file in the project. -DeployJob_CouldNotCreateTemporaryDirectoryForJar=Could not create temporary directory {0} -DeployJob_CouldNotSetPathVariable=Could not set path variable {0}. -DeployJob_CouldntGetBundleLocation=Couldn't get bundle location -DeployJob_ExceptionWhileReadingTheCheckConfigurationFile=Exception while reading the check configuration file {0} -DeployJob_FailedToInstallAndStartBundle=Failed to install and start bundle -DeployJob_FailedToReadBundle=Failed to read bundle diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployAction.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployAction.java deleted file mode 100644 index d6b0c7e80a..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.popup.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -import com.avaloq.tools.ddk.check.ui.Messages; -import com.avaloq.tools.ddk.check.ui.util.ProjectUtil; - - -/** - * Action to deploy a check bundle. - */ -public class DeployAction implements IObjectActionDelegate { - - @Override - public void setActivePart(final IAction action, final IWorkbenchPart targetPart) { - } - - @Override - public void run(final IAction action) { - new DeployJob(Messages.DeployAction_DeployBundleLocally, ProjectUtil.getProject()).schedule(); - } - - @Override - public void selectionChanged(final IAction action, final ISelection selection) { - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java deleted file mode 100644 index 2477108fe8..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java +++ /dev/null @@ -1,433 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.popup.actions; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IPathVariableManager; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable; -import org.eclipse.jdt.ui.jarpackager.JarPackageData; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.xtext.resource.XtextResourceSet; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; - -import com.avaloq.tools.ddk.check.ui.Messages; -import com.avaloq.tools.ddk.check.ui.internal.Activator; -import com.avaloq.tools.ddk.checkcfg.CheckCfgConstants; -import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration; -import com.google.common.collect.ImmutableSet; -import com.google.common.io.Files; - - -/** - * Job deploying the plugin bundle generated by the artifacts of the given project. - * If a check configuration file is present, deploys it too. - */ -// CHECKSTYLE:OFF (data coupling 13 instead of maximum 10). -public class DeployJob extends Job { - // CHECKSTYLE:ON - - private static final Logger LOGGER = LogManager.getLogger(DeployJob.class); - - private static final String MANIFEST_MF = "MANIFEST.MF"; //$NON-NLS-1$ - private static final String META_INF = "META-INF"; //$NON-NLS-1$ - private static final Set IGNORED_RESOURCES = ImmutableSet.of(".classpath", ".project", ".settings"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private final BundleContext bundleContext = ResourcesPlugin.getPlugin().getBundle().getBundleContext(); - private final IProject project; - - /** - * Creates a new instance of {@link DeployJob}. - * - * @param name - * the name of the job - * @param project - * the plugin project whose bundle should be deployed. - */ - public DeployJob(final String name, final IProject project) { - super(name); - this.project = project; - } - - @Override - protected IStatus run(final IProgressMonitor monitor) { - try { - deployCheckBundle(); - } catch (DeployException e) { - return new Status(Status.ERROR, Activator.getPluginId(), Messages.DeployJob_CouldNotDeployCheckBundle, e); - } - - LOGGER.info("Generated bundle from project {} deployed.", project.getName()); //$NON-NLS-1$ - - try { - deployCheckConfiguration(); - } catch (DeployException e) { - return new Status(Status.ERROR, Activator.getPluginId(), Messages.DeployJob_CannotDeployMoreThanOneCheckConfiguration, e); - } - - LOGGER.info("Check configuration for project {} deployed.", project.getName()); //$NON-NLS-1$ - - return Status.OK_STATUS; - } - - /** - * Generated a bundle from this project and deploys it (install and run). - * - * @throws DeployException - * a deployment exception. - */ - private void deployCheckBundle() throws DeployException { - - File tempDir = createTempDirectory("check_catalog"); //$NON-NLS-1$ - tempDir.mkdirs(); - - final File jar = generateJar(tempDir, new NullProgressMonitor()); - - String bundleLocation; - try { - bundleLocation = jar.getCanonicalPath(); - } catch (IOException e) { - LOGGER.error(Messages.DeployJob_CouldntGetBundleLocation, e); - throw new DeployException(e); - } - - Bundle managedBundle = Platform.getBundle(project.getName()); - if (managedBundle != null) { - LOGGER.info(NLS.bind(Messages.DeployJob_BundleAlreadyDeployed, project.getName())); - try { - UndeployJob.undeployBundle(managedBundle); - } catch (BundleException e) { - LOGGER.error(NLS.bind(Messages.UndeployJob_FailedToStopAndUninstallBundleWithSymbolicName, managedBundle.getSymbolicName()), e); - throw new DeployException(e); - } - } - - LOGGER.info("Starting the bundle {} generated from the project {}", bundleLocation, project.getName()); //$NON-NLS-1$ - try { - managedBundle = bundleContext.installBundle(bundleLocation, Files.asByteSource(jar).openStream()); - managedBundle.start(); - } catch (BundleException e) { - LOGGER.error(Messages.DeployJob_FailedToInstallAndStartBundle, e); - throw new DeployException(e); - } catch (IOException e) { - LOGGER.error(Messages.DeployJob_FailedToReadBundle, e); - throw new DeployException(e); - } - - if (!jar.delete()) { - LOGGER.warn("Could not delete temp file."); //$NON-NLS-1$ - } - } - - /** - * Creates a new instance of {@link DeployJob}. - * - * @throws DeployException - * a general deployment exception. - */ - private void deployCheckConfiguration() throws DeployException { - - List checkCfgFiles = getCheckConfigurationFiles(); - if (checkCfgFiles.isEmpty()) { - return; - } - if (checkCfgFiles.size() != 1) { - showTooManyCheckConfigurationDialog(); - return; - } - IFile file = checkCfgFiles.get(0); - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IPathVariableManager pathMan = workspace.getPathVariableManager(); - if (pathMan.validateName(CheckCfgConstants.CHECK_CFG_VAR_NAME).isOK() && pathMan.validateValue(file.getFullPath()).isOK()) { - try { - pathMan.setURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME, file.getLocationURI()); - } catch (CoreException e) { - LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME)); - throw new DeployException(e); - } - } else { - LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME)); - throw new DeployException(); - } - - XtextResourceSet rs = new XtextResourceSet(); - String uriString = pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME).toString(); - URI uri = URI.createURI(uriString, true); - Resource resource = rs.createResource(uri); - try (FileInputStream input = new FileInputStream(new File(pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME)))) { - resource.load(input, rs.getLoadOptions()); - rs.getURIResourceMap().put(uri, resource); - EcoreUtil.resolveAll(resource); - CheckConfiguration checkConfig = (CheckConfiguration) resource.getContents().get(0); - assert checkConfig != null; - } catch (IOException e) { - LOGGER.error(NLS.bind(Messages.DeployJob_ExceptionWhileReadingTheCheckConfigurationFile, uriString), e); - throw new DeployException(e); - } - } - - /** - * Fetches the check configuration files of this project. - * - * @return the list of configuration files, never {@code null} - * @throws DeployException - * deploy exception - */ - private List getCheckConfigurationFiles() throws DeployException { - final List checkCfgFiles = new ArrayList(); - try { - project.accept(new IResourceVisitor() { - @Override - public boolean visit(final IResource resource) throws CoreException { - if (resource instanceof IProject) { - return true; - } - if (resource instanceof IFile && CheckCfgConstants.FILE_EXTENSION.equalsIgnoreCase(resource.getFileExtension())) { - checkCfgFiles.add((IFile) resource); - return false; - } - if (isProjectJarIgnoreResource(resource)) { - return false; - } - if (resource instanceof IFolder && "bin".equals(resource.getName())) { // NOPMD SimplifyBooleanReturns //$NON-NLS-1$ - return false; - } - return true; - } - }); - } catch (CoreException e) { - throw new DeployException(e); - } - return checkCfgFiles; - } - - /** - * Generate jar in the target folder of the project. - * - * @param tempDir - * the temp directory to store jar, must not be {@code null} - * @param progressMonitor - * the progress monitor, must not be {@code null} - * @return the file, never {@code null} - * @throws DeployException - * a general deployment exception. - */ - private File generateJar(final File tempDir, final IProgressMonitor progressMonitor) throws DeployException { - - try { - buildProject(); - } catch (CoreException e) { - throw new DeployException(e); - } - - final List resources = new ArrayList(); - final List manifest = new ArrayList(); - try { - project.accept(new IResourceVisitor() { - @Override - public boolean visit(final IResource resource) throws CoreException { - if (resource instanceof IProject) { - return true; - } - if (META_INF.equals(resource.getName())) { - return true; - } - if (MANIFEST_MF.equals(resource.getName())) { - manifest.add(resource); - return false; - } - if (isProjectJarIgnoreResource(resource)) { - return false; - } else { - resources.add(resource); - return false; - } - } - }); - } catch (CoreException e) { - LOGGER.error(e.getMessage(), e); - throw new DeployException(e); - } - JarPackageData description = new JarPackageData(); - IPath location = new Path(tempDir.toString()).append(project.getName() + ".jar"); //$NON-NLS-1$ - description.setJarLocation(location); - final IPath manifestLocation = manifest.get(0).getFullPath(); - description.setManifestLocation(manifestLocation); - description.setGenerateManifest(false); - description.setSaveManifest(true); - description.setElements(resources.toArray()); - IJarExportRunnable runnable = description.createJarExportRunnable(null); - try { - runnable.run(progressMonitor); - } catch (InvocationTargetException e) { - LOGGER.error(e.getMessage(), e); - throw new DeployException(e); - } catch (InterruptedException e) { - LOGGER.error(e.getMessage(), e); - throw new DeployException(e); - } - return new File(location.toOSString()); - } - - /** - * Builds the project. - * - * @return the file - * @throws CoreException - * the core exception - */ - private File buildProject() throws CoreException { - /* - * Doing clean build takes too long with Xtend. With auto build even full build is not necessary, - * but keep full build in case auto build is disabled. Then bin folder may be outdated or even empty. - * project.build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - */ - project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); - return new File(project.getWorkspace().getRoot().getFolder(getJavaOutputDirectory()).getLocation().toOSString()); - } - - /** - * Checks whether the resource is ignored for this project (no need to pack into JAR). - * - * @param resource - * the resource - * @return true, if is project jar ignore resource - */ - private boolean isProjectJarIgnoreResource(final IResource resource) { - return IGNORED_RESOURCES.contains(resource.getName()) && getJavaOutputDirectory().toOSString().equals(resource.getLocation().toOSString()); - } - - /** - * Gets the java output directory of the given project. - * - * @return the java output directory - */ - private IPath getJavaOutputDirectory() { - IPath outputLocation = null; - try { - IJavaProject javaProject = JavaCore.create(project); - if (javaProject != null) { - outputLocation = javaProject.getOutputLocation(); - } - } catch (JavaModelException e) { - LOGGER.error("Failed to get java output of the project", e); //$NON-NLS-1$ // NOPMD InvalidLogMessageFormat - return null; - } - return outputLocation; - } - - /** - * Creates the temp directory. - * - * @param name - * the name of the directory, must not be {@code null} - * @return the file, never {@code null} - * @throws DeployException - * Signals that an I/O exception has occurred. - */ - private static File createTempDirectory(final String name) throws DeployException { - final File temp; - try { - temp = File.createTempFile(name, null); - } catch (IOException e) { - LOGGER.error(e.getMessage()); - throw new DeployException(e); - } - if (!(temp.delete())) { - LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotCreateTemporaryDirectoryForJar, temp.getAbsolutePath())); - throw new DeployException(); - } - if (!(temp.mkdir())) { - LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotCreateTemporaryDirectoryForJar, temp.getAbsolutePath())); - throw new DeployException(); - } - return temp; - } - - /** - * Shows an error dialog box informing the user that there are too many check configurations in the project. - */ - private static void showTooManyCheckConfigurationDialog() { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); - final String dialogIitle = Messages.DeployJob_TooManyCheckConfigurations; - final String dialogMessage = Messages.DeployJob_CannotDeployMoreThanOneCheckConfiguration; - MessageDialog d = new MessageDialog(shell, dialogIitle, null, dialogMessage, MessageDialog.ERROR, new String[] {Messages.DeployJob_DialogOk}, 0); - d.open(); - } - }); - - } - - /** - * A custom exception for internal error handling. - */ - private static class DeployException extends Exception { - - /** The serialVersionUID. */ - private static final long serialVersionUID = 5396061810970195802L; - - /** Constructor without cause exception. */ - DeployException() { - } - - /** - * Constructor with cause exception. - * - * @param e - * the cause exception - */ - DeployException(final Exception e) { - super(e); - } - - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployAction.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployAction.java deleted file mode 100644 index 46019635d2..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.popup.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -import com.avaloq.tools.ddk.check.ui.Messages; -import com.avaloq.tools.ddk.check.ui.util.ProjectUtil; - - -/** - * Action to deploy a check bundle. - */ -public class UndeployAction implements IObjectActionDelegate { - - @Override - public void setActivePart(final IAction action, final IWorkbenchPart targetPart) { - } - - @Override - public void run(final IAction action) { - new UndeployJob(Messages.UndeployAction_UndeployLocalBundle, ProjectUtil.getProject()).schedule(); - } - - @Override - public void selectionChanged(final IAction action, final ISelection selection) { - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployJob.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployJob.java deleted file mode 100644 index 56edffc35c..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/UndeployJob.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.popup.actions; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.eclipse.core.resources.IPathVariableManager; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.osgi.util.NLS; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; - -import com.avaloq.tools.ddk.check.ui.Messages; -import com.avaloq.tools.ddk.check.ui.internal.Activator; -import com.avaloq.tools.ddk.checkcfg.CheckCfgConstants; - - -/** - * Job undeploying the plugin bundle that my have been deployed from this project. - * If a check configuration file is present, unddeploys it too. - */ -public class UndeployJob extends Job { - - private static final Logger LOGGER = LogManager.getLogger(UndeployJob.class); - - private final IProject project; - - /** - * Creates a new instance of {@link UndeployJob}. - * - * @param name - * the name of the job - * @param project - * the project whose bundle should be deployed. - */ - public UndeployJob(final String name, final IProject project) { - super(name); - this.project = project; - } - - @Override - protected IStatus run(final IProgressMonitor monitor) { - Bundle managedBundle = Platform.getBundle(project.getName()); - if (managedBundle == null) { - LOGGER.info(NLS.bind(Messages.UndeployJob_NoBundleWithSymbolicNameInstalled, project.getName())); - return new Status(Status.INFO, Activator.getPluginId(), NLS.bind(Messages.UndeployJob_NoBundleWithSymbolicNameInstalled, project.getName())); - } - try { - undeployBundle(managedBundle); - } catch (BundleException e) { - LOGGER.error(NLS.bind(Messages.UndeployJob_FailedToStopAndUninstallBundleWithSymbolicName, managedBundle.getSymbolicName()), e); - return new Status(Status.ERROR, Activator.getPluginId(), NLS.bind(Messages.UndeployJob_FailedToStopAndUninstallBundleWithSymbolicName, managedBundle.getSymbolicName()), e); - } - LOGGER.info(NLS.bind(Messages.UndeployJob_DundleUndeployed, managedBundle.getSymbolicName())); - - try { - undeployCheckConfiguration(); - } catch (CoreException e) { - LOGGER.error(Messages.UndeployJob_FailedToUndeployCheckCofiguration, e); - return new Status(Status.ERROR, Activator.getPluginId(), Messages.UndeployJob_FailedToUndeployCheckCofiguration, e); - } - return Status.OK_STATUS; - - } - - /** - * Undeploys the check configuration. - * - * @throws CoreException - * core exception. - */ - public static void undeployCheckConfiguration() throws CoreException { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IPathVariableManager pathMan = workspace.getPathVariableManager(); - if (pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME) == null) { - return; - } - pathMan.setURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME, null); - } - - /** - * Undeploys a bundle. - * - * @param managedBundle - * the bundle to be undeployed. - * @throws BundleException - * bundle exception. - */ - public static void undeployBundle(final Bundle managedBundle) throws BundleException { - managedBundle.stop(Bundle.STOP_TRANSIENT); - managedBundle.uninstall(); - } -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/util/ProjectUtil.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/util/ProjectUtil.java deleted file mode 100644 index 0e46ed8e10..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/util/ProjectUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.util; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - - -/** - * Helper methods to export Java project as OSGi bundle into a JAR. - */ -public final class ProjectUtil { - - private ProjectUtil() { - // Prevents creating an instance - } - - /** - * Retrieved the project from the active workbench window. - * - * @return the current selected project. - */ - public static IProject getProject() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof IAdaptable) { - return ((IAdaptable) firstElement).getAdapter(IProject.class); - } - } - return null; - } -}