blob: c933cfb7ba826ef6c435224e21ae68902e654282 [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2009, 2012 SpringSource, a division of VMware, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.virgo.ide.export;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.virgo.ide.facet.core.FacetCorePlugin;
import org.eclipse.virgo.ide.manifest.core.BundleManifestCorePlugin;
import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
/**
* Export wizard page for exporting bundle project
*
* @author Christian Dupuis
* @author Terry Hon
* @author Leo Dos Santos
*/
public class BundleExportWizardPage extends AbstractProjectExportWizardPage {
public BundleExportWizardPage(IStructuredSelection selection) {
super("bundleExportWizardPage", selection);
setTitle("JAR File Specification");
setDescription("Define which bundle project should be exported into the JAR.");
}
@Override
protected ViewerFilter getTreeViewerFilter() {
return new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IPackageFragmentRoot) {
IPackageFragmentRoot root = (IPackageFragmentRoot) element;
return !root.isArchive() && !root.isExternal();
} else if (element instanceof IProject) {
IProject project = (IProject) element;
try {
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
if (facetedProject == null) {
return false;
}
return facetedProject.hasProjectFacet(
ProjectFacetsManager.getProjectFacet(FacetCorePlugin.BUNDLE_FACET_ID).getDefaultVersion());
} catch (CoreException e) {
return false;
}
}
return false;
}
};
}
@Override
protected String getExtension() {
return ".jar";
}
@Override
protected String getDestinationLabel() {
return "JAR file:";
}
@Override
protected String getSymbolicName(BundleManifest bundleManifest) {
if (bundleManifest.getBundleSymbolicName() != null) {
return bundleManifest.getBundleSymbolicName().getSymbolicName();
}
return null;
}
@Override
protected String getVersion(BundleManifest bundleManifest) {
return bundleManifest.getBundleVersion() != null ? bundleManifest.getBundleVersion().toString() : "";
}
@Override
protected BundleManifest getBundleManifest(IProject project) {
if (project != null) {
return BundleManifestCorePlugin.getBundleManifestManager().getBundleManifest(JavaCore.create(project));
}
return null;
}
}