All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.pde.internal.ui.wizards.product.ProductFromExtensionOperation Maven / Gradle / Ivy

There is a newer version: 3.15.100
Show newest version
/*******************************************************************************
 *  Copyright (c) 2005, 2015 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.internal.ui.wizards.product;

import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.core.iproduct.IProduct;
import org.eclipse.pde.internal.core.iproduct.IProductModelFactory;
import org.eclipse.pde.internal.ui.search.dependencies.DependencyCalculator;

public class ProductFromExtensionOperation extends BaseProductCreationOperation {

	private String fId;

	public ProductFromExtensionOperation(IFile file, String productId) {
		super(file);
		fId = productId;
	}

	@Override
	protected void initializeProduct(IProduct product) {
		if (fId == null)
			return;
		IProductModelFactory factory = product.getModel().getFactory();
		initializeProductInfo(factory, product, fId);
		addPlugins(factory, product, getPlugins());
		super.initializeProduct(product);
	}

	private String[] getPlugins() {
		int lastDot = fId.lastIndexOf('.');
		if (lastDot == -1)
			return new String[0];

		DependencyCalculator calculator = new DependencyCalculator(false);
		// add plugin declaring product and its pre-reqs
		IPluginModelBase model = PluginRegistry.findModel(fId.substring(0, lastDot));
		if (model != null)
			calculator.findDependency(model);

		// add plugin declaring product application and its pre-reqs
		IPluginElement element = getProductExtension(fId);
		if (element != null) {
			IPluginAttribute attr = element.getAttribute("application"); //$NON-NLS-1$
			if (attr != null) {
				String appId = attr.getValue();
				lastDot = appId.lastIndexOf('.');
				if (lastDot != -1) {
					model = PluginRegistry.findModel(appId.substring(0, lastDot));
					if (model != null) {
						calculator.findDependency(model);
					}
				}
			}
		}
		Set ids = calculator.getBundleIDs();
		return ids.toArray(new String[ids.size()]);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy