public List<String> getLiferayPlugins() {
    List<String> retval = new ArrayList<String>();

    Object response = null;

    try {
      response = getJSONAPI(getPluginsAPI());
    } catch (APIException e1) {
      LiferayServerCore.logError(e1);
    }

    if (response instanceof JSONObject) {
      JSONObject json = (JSONObject) response;

      try {
        if (isSuccess(json)) {
          JSONArray jsonPlugins = getJSONOutput(json);

          for (int i = 0; i < jsonPlugins.length(); i++) {
            retval.add(jsonPlugins.get(i).toString());
          }
        }
      } catch (Exception e) {
        LiferayServerCore.logError(e);
      }
    }

    return retval;
  }
  private void saveConfigInfoIntoCache(String configType, String configInfo, IPath portalDir) {
    IPath versionsInfoPath = null;

    if (configType.equals(CONFIG_TYPE_VERSION)) {
      versionsInfoPath =
          LiferayServerCore.getDefault().getStateLocation().append("version.properties");
    } else if (configType.equals(CONFIG_TYPE_SERVER)) {
      versionsInfoPath =
          LiferayServerCore.getDefault().getStateLocation().append("serverInfos.properties");
    }

    if (versionsInfoPath != null) {
      File versionInfoFile = versionsInfoPath.toFile();

      if (configInfo != null) {
        String portalDirKey = CoreUtil.createStringDigest(portalDir.toPortableString());
        Properties properties = new Properties();

        try (FileInputStream fileInput = new FileInputStream(versionInfoFile)) {
          properties.load(fileInput);
        } catch (Exception e) {
        }

        try (FileOutputStream fileOutput = new FileOutputStream(versionInfoFile)) {
          properties.put(portalDirKey, configInfo);
          properties.store(fileOutput, StringPool.EMPTY);
        } catch (Exception e) {
          LiferayServerCore.logError(e);
        }
      }
    }
  }
  protected void updateStubs() {
    ILiferayRuntimeStub[] stubs = LiferayServerCore.getRuntimeStubs();

    if (CoreUtil.isNullOrEmpty(stubs)) {
      return;
    }

    String[] names = new String[stubs.length];

    LiferayRuntimeStubDelegate delegate = getStubDelegate();

    String stubId = delegate.getRuntimeStubTypeId();

    int stubIndex = -1;

    for (int i = 0; i < stubs.length; i++) {
      names[i] = stubs[i].getName();
      if (stubs[i].getRuntimeStubTypeId().equals(stubId)) {
        stubIndex = i;
      }
    }

    comboRuntimeStubType.setItems(names);

    if (stubIndex >= 0) {
      comboRuntimeStubType.select(stubIndex);
    }
  }
  private String getConfigInfoFromManifest(String configType, IPath portalDir) {
    File implJar = portalDir.append("/WEB-INF/lib/portal-impl.jar").toFile();

    String version = null;
    String serverInfo = null;

    if (implJar.exists()) {
      try (JarFile jar = new JarFile(implJar)) {
        Manifest manifest = jar.getManifest();

        Attributes attributes = manifest.getMainAttributes();

        version = attributes.getValue("Liferay-Portal-Version");
        serverInfo = attributes.getValue("Liferay-Portal-Server-Info");

        if (CoreUtil.compareVersions(Version.parseVersion(version), MANIFEST_VERSION_REQUIRED)
            < 0) {
          version = null;
          serverInfo = null;
        }
      } catch (IOException e) {
        LiferayServerCore.logError(e);
      }
    }

    if (configType.equals(CONFIG_TYPE_VERSION)) {
      return version;
    }

    if (configType.equals(CONFIG_TYPE_SERVER)) {
      return serverInfo;
    }

    return null;
  }
  private IPath getConfigInfoPath(String configType) {
    IPath configInfoPath = null;

    if (configType.equals(CONFIG_TYPE_VERSION)) {
      configInfoPath =
          LiferayServerCore.getDefault().getStateLocation().append("version.properties");
    } else if (configType.equals(CONFIG_TYPE_SERVER)) {
      configInfoPath =
          LiferayServerCore.getDefault().getStateLocation().append("serverInfos.properties");
    }

    if (!clearedConfigInfoCacheOnce) {
      configInfoPath.toFile().delete();
      clearedConfigInfoCacheOnce = true;
    }

    return configInfoPath;
  }
  @Override
  protected Object run(Presentation context) {
    final NewModuleFragmentOp op =
        context.part().getModelElement().nearest(NewModuleFragmentOp.class);

    final ElementList<OverrideFilePath> currentFiles = op.getOverrideFiles();

    final String projectName = op.getProjectName().content();

    final OSGiBundleFileSelectionDialog dialog =
        new OSGiBundleFileSelectionDialog(null, currentFiles, projectName);

    final String runtimeName = op.getLiferayRuntimeName().content();

    final IRuntime runtime = ServerUtil.getRuntime(runtimeName);

    final IPath temp = GradleCore.getDefault().getStateLocation();

    dialog.setTitle("Add files from OSGi bundle to override");

    final PortalBundle portalBundle = LiferayServerCore.newPortalBundle(runtime.getLocation());
    String currentOSGiBundle = op.getHostOsgiBundle().content();

    if (!currentOSGiBundle.endsWith("jar")) {
      currentOSGiBundle = currentOSGiBundle + ".jar";
    }

    ServerUtil.getModuleFileFrom70Server(runtime, currentOSGiBundle, temp);

    if (portalBundle != null) {
      try {
        File module =
            portalBundle.getOSGiBundlesDir().append("modules").append(currentOSGiBundle).toFile();

        if (!module.exists()) {
          module = GradleCore.getDefault().getStateLocation().append(currentOSGiBundle).toFile();
        }

        dialog.setInput(module);
      } catch (Exception e) {
      }
    }

    if (dialog.open() == Window.OK) {
      Object[] selected = dialog.getResult();

      for (int i = 0; i < selected.length; i++) {
        OverrideFilePath file = op.getOverrideFiles().insert();
        file.setValue(selected[i].toString());
      }
    }

    return Status.createOkStatus();
  }
  public void propertyChange(PropertyChangeEvent evt) {
    if (IRemoteServer.ATTR_HOSTNAME.equals(evt.getPropertyName())
        || IRemoteServer.ATTR_HTTP_PORT.equals(evt.getPropertyName())
        || IRemoteServer.ATTR_USERNAME.equals(evt.getPropertyName())
        || IRemoteServer.ATTR_PASSWORD.equals(evt.getPropertyName())
        || IRemoteServer.ATTR_LIFERAY_PORTAL_CONTEXT_PATH.equals(evt.getPropertyName())
        || IRemoteServer.ATTR_SERVER_MANAGER_CONTEXT_PATH.equals(evt.getPropertyName())) {

      LiferayServerCore.updateConnectionSettings(
          (IRemoteServer) serverWC.loadAdapter(IRemoteServer.class, null));
    }
  }
  @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);
      }
    }
  }
  private IStatus remoteDeploy(String bsn, IPath output) {
    IStatus retval = null;

    final BundleDeployer deployer = getBundleDeployer();

    if (output != null && output.toFile().exists()) {
      try {
        long bundleId = deployer.deployBundle(bsn, output.toFile());

        retval = new Status(IStatus.OK, LiferayServerCore.PLUGIN_ID, (int) bundleId, null, null);
      } catch (Exception e) {
        retval =
            LiferayServerCore.error(
                "Unable to deploy bundle remotely " + output.toPortableString(), e);
      }
    } else {
      retval =
          LiferayServerCore.error("Unable to deploy bundle remotely " + output.toPortableString());
    }

    return retval;
  }
  protected void initMap() {
    try {
      wsdlNameURLMap = new HashMap<String, String>();
      String webServicesString = CoreUtil.readStreamToString(webServicesListURL.openStream());
      List<String> wsdlUrls = pullLinks(webServicesString);

      for (String url : wsdlUrls) {
        String name = pullServiceName(url);

        if (!CoreUtil.isNullOrEmpty(name)) {
          wsdlNameURLMap.put(name, url);
        }
      }
    } catch (IOException e1) {
      LiferayServerCore.logError("Unable to initial web services list."); // $NON-NLS-1$
    }
  }
  private String getConfigInfoFromCache(String configType, IPath portalDir) {
    File configInfoFile = getConfigInfoPath(configType).toFile();

    String portalDirKey = CoreUtil.createStringDigest(portalDir.toPortableString());

    Properties properties = new Properties();

    if (configInfoFile.exists()) {
      try (FileInputStream fileInput = new FileInputStream(configInfoFile)) {
        properties.load(fileInput);
        String configInfo = (String) properties.get(portalDirKey);

        if (!CoreUtil.isNullOrEmpty(configInfo)) {
          return configInfo;
        }
      } catch (IOException e) {
        LiferayServerCore.logError(e);
      }
    }

    return null;
  }
  private IStatus autoDeploy(IPath output) throws CoreException {
    IStatus retval = null;

    final IPath autoDeployPath = portalRuntime.getPortalBundle().getAutoDeployPath();
    final IPath statePath = portalRuntime.getPortalBundle().getModulesPath().append("state");

    if (autoDeployPath.toFile().exists()) {
      try {
        FileUtil.writeFileFromStream(
            autoDeployPath.append(output.lastSegment()).toFile(),
            new FileInputStream(output.toFile()));

        retval = Status.OK_STATUS;
      } catch (IOException e) {
        retval = LiferayServerCore.error("Unable to copy file to auto deploy folder", e);
      }
    }

    if (statePath.toFile().exists()) {
      FileUtil.deleteDir(statePath.toFile(), true);
    }

    return retval;
  }
  public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException {
    final IPath deployPath =
        LiferayServerCore.getTempLocation("direct-deploy", StringPool.EMPTY); // $NON-NLS-1$
    File warFile = deployPath.append(getProject().getName() + ".war").toFile(); // $NON-NLS-1$
    warFile.getParentFile().mkdirs();

    final Map<String, String> properties = new HashMap<String, String>();
    properties.put(ISDKConstants.PROPERTY_AUTO_DEPLOY_UNPACK_WAR, "false"); // $NON-NLS-1$

    final ILiferayRuntime runtime = ServerUtil.getLiferayRuntime(getProject());

    final String appServerDeployDirProp =
        ServerUtil.getAppServerPropertyKey(ISDKConstants.PROPERTY_APP_SERVER_DEPLOY_DIR, runtime);

    properties.put(appServerDeployDirProp, deployPath.toOSString());

    // IDE-1073 LPS-37923
    properties.put(ISDKConstants.PROPERTY_PLUGIN_FILE_DEFAULT, warFile.getAbsolutePath());

    properties.put(ISDKConstants.PROPERTY_PLUGIN_FILE, warFile.getAbsolutePath());

    final String fileTimeStamp = System.currentTimeMillis() + "";

    // IDE-1491
    properties.put(ISDKConstants.PROPERTY_LP_VERSION, fileTimeStamp);

    properties.put(ISDKConstants.PROPERTY_LP_VERSION_SUFFIX, ".0");

    final Map<String, String> appServerProperties =
        ServerUtil.configureAppServerProperties(getProject());

    final IStatus directDeployStatus =
        sdk.war(
            getProject(),
            properties,
            true,
            appServerProperties,
            new String[] {"-Duser.timezone=GMT"},
            monitor);

    if (!directDeployStatus.isOK() || (!warFile.exists())) {
      String pluginVersion = "1";

      final IPath pluginPropertiesPath = new Path("WEB-INF/liferay-plugin-package.properties");
      final IFile propertiesFile =
          CoreUtil.getDocrootFile(getProject(), pluginPropertiesPath.toOSString());

      if (propertiesFile != null) {
        try {
          if (propertiesFile.exists()) {
            final PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
            final InputStream is = propertiesFile.getContents();
            pluginPackageProperties.load(is);
            pluginVersion = pluginPackageProperties.getString("module-incremental-version");
            is.close();
          }
        } catch (Exception e) {
          LiferayCore.logError("error reading module-incremtnal-version. ", e);
        }
      }

      warFile =
          sdk.getLocation()
              .append("dist")
              .append(
                  getProject().getName()
                      + "-"
                      + fileTimeStamp
                      + "."
                      + pluginVersion
                      + ".0"
                      + ".war")
              .toFile();

      if (!warFile.exists()) {
        throw new CoreException(directDeployStatus);
      }
    }

    return new Path(warFile.getAbsolutePath());
  }