@Override
  public void init(IWorkbench workbench, IStructuredSelection selection) {
    if (selection != null && !selection.isEmpty()) {
      final Object element = selection.getFirstElement();

      if (element instanceof IResource) {
        initialProject = ((IResource) element).getProject();
      } else if (element instanceof IJavaProject) {
        initialProject = ((IJavaProject) element).getProject();
      } else if (element instanceof IPackageFragment) {
        initialProject = ((IJavaElement) element).getResource().getProject();
      } else if (element instanceof IJavaElement) {
        initialProject = ((IJavaElement) element).getResource().getProject();
      }

      if (initialProject != null) {
        final IBundleProject bundleProject =
            LiferayCore.create(IBundleProject.class, initialProject);

        if (bundleProject != null && bundleProject.isFragmentBundle()) {
          element().setProjectName(initialProject.getName());
        }
      }
    }
  }
  @Override
  public void execute(IProgressMonitor monitor, IAdaptable info) throws CoreException {
    for (IModule module : modules) {
      IStatus retval = Status.OK_STATUS;

      if (module.getProject() == null) {
        continue;
      }

      final IBundleProject bundleProject =
          LiferayCore.create(IBundleProject.class, module.getProject());

      if (bundleProject != null) {
        // TODO catch error in getOUtputJar and show a popup notification instead
        final IPath outputJar = bundleProject.getOutputJar(true, monitor);

        if (outputJar != null && outputJar.toFile().exists()) {
          if (this.server.getServerState() == IServer.STATE_STARTED) {
            retval = remoteDeploy(bundleProject.getSymbolicName(), outputJar);
          } else {
            retval = autoDeploy(outputJar);
          }
        } else {
          retval = LiferayServerCore.error("Could not create output jar");
        }
      } else {
        retval =
            LiferayServerCore.error(
                "Unable to get bundle project for " + module.getProject().getName());
      }

      if (retval.isOK()) {
        this.portalServerBehavior.setModulePublishState2(
            new IModule[] {module}, IServer.PUBLISH_STATE_NONE);
      } else {
        this.portalServerBehavior.setModulePublishState2(
            new IModule[] {module}, IServer.PUBLISH_STATE_FULL);
      }
    }
  }