1 /******************************************************************************* 2 * Copyright (c) 2005, 2015 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 * EclipseSource Corporation - ongoing enhancements 14 *******************************************************************************/ 15 package org.eclipse.pde.internal.ui.wizards.product; 16 17 import java.lang.reflect.InvocationTargetException; 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.core.plugin.PluginRegistry; 23 import org.eclipse.pde.internal.core.iproduct.IProduct; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 import org.eclipse.swt.widgets.Shell; 26 27 public class SynchronizationOperation extends ProductDefinitionOperation { 28 SynchronizationOperation(IProduct product, Shell shell, IProject project)29 public SynchronizationOperation(IProduct product, Shell shell, IProject project) { 30 super(product, getPluginId(product), getProductId(product), product.getApplication(), shell, project); 31 } 32 getProductId(IProduct product)33 private static String getProductId(IProduct product) { 34 String full = product.getProductId(); 35 int index = full.lastIndexOf('.'); 36 return index != -1 ? full.substring(index + 1) : full; 37 } 38 getPluginId(IProduct product)39 private static String getPluginId(IProduct product) { 40 String full = product.getProductId(); 41 int index = full.lastIndexOf('.'); 42 return index != -1 ? full.substring(0, index) : full; 43 } 44 45 @Override run(IProgressMonitor monitor)46 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { 47 IPluginModelBase model = PluginRegistry.findModel(fPluginId); 48 if (model == null) { 49 String message = PDEUIMessages.SynchronizationOperation_noDefiningPlugin; 50 throw new InvocationTargetException(createCoreException(message)); 51 } 52 53 if (model.getUnderlyingResource() == null) { 54 String id = model.getPluginBase().getId(); 55 String message = PDEUIMessages.SynchronizationOperation_externalPlugin; 56 throw new InvocationTargetException(createCoreException(NLS.bind(message, id))); 57 } 58 59 super.run(monitor); 60 } 61 createCoreException(String message)62 private CoreException createCoreException(String message) { 63 IStatus status = new Status(IStatus.ERROR, "org.eclipse.pde.ui", IStatus.ERROR, message, null); //$NON-NLS-1$ 64 return new CoreException(status); 65 } 66 67 } 68