/*
 * Copyright (c) 2012-2018 Red Hat, 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
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.ide.ext.java.client.command;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.js.Promises;
import org.eclipse.che.ide.ext.java.client.project.classpath.ClasspathChangedEvent;
import org.eclipse.che.ide.ext.java.client.service.JavaLanguageExtensionServiceClient;
import org.eclipse.che.jdt.ls.extension.api.dto.ClasspathEntry;

/**
 * Storage of the classpath entries.
 *
 * @author Valeriy Svydenko
 */
@Singleton
public class ClasspathContainer implements ClasspathChangedEvent.ClasspathChangedHandler {
  public static String JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER";

  private final JavaLanguageExtensionServiceClient extensionService;
  private Map<String, Promise<List<ClasspathEntry>>> classpath;

  @Inject
  public ClasspathContainer(
      JavaLanguageExtensionServiceClient extensionService, EventBus eventBus) {
    this.extensionService = extensionService;
    classpath = new HashMap<>();

    eventBus.addHandler(ClasspathChangedEvent.TYPE, this);
  }

  /**
   * Returns list of the classpath entries. If the classpath already exist for this project -
   * returns its otherwise gets classpath from the server.
   *
   * @param projectPath path to the project
   * @return list of the classpath entries
   */
  public Promise<List<ClasspathEntry>> getClasspathEntries(String projectPath) {
    if (classpath.containsKey(projectPath)) {
      return classpath.get(projectPath);
    } else {
      Promise<List<ClasspathEntry>> result = extensionService.classpathTree(projectPath);
      classpath.put(projectPath, result);
      return result;
    }
  }

  @Override
  public void onClasspathChanged(ClasspathChangedEvent event) {
    classpath.put(event.getPath(), Promises.resolve(event.getEntries()));
  }
}

@@ -681,19 +681,23 @@
 ent.
-js.
 Promise
-s
+Provider
 ;%0Aim
@@ -1260,16 +1260,65 @@
 ervice;%0A
+  private final PromiseProvider promiseProvider;%0A
   privat
@@ -1471,16 +1471,22 @@
 Service,
+%0A     
  EventBu
@@ -1495,16 +1495,55 @@
 eventBus
+,%0A      PromiseProvider promiseProvider
 ) %7B%0A    
@@ -1584,16 +1584,60 @@
 ervice;%0A
+    this.promiseProvider = promiseProvider;%0A
     clas
@@ -2208,16 +2208,26 @@
 result =
+%0A         
  extensi
@@ -2235,16 +2235,31 @@
 nService
+%0A              
 .classpa
@@ -2273,24 +2273,217 @@
 projectPath)
+%0A              .catchErrorPromise(%0A                  error -%3E %7B%0A                    classpath.remove(projectPath);%0A                    return promiseProvider.reject(error);%0A                  %7D)
 ;%0A      clas
@@ -2661,16 +2661,23 @@
 (), 
-P
+p
 romise
-s
+Provider
 .res

Clean cached classpath on error (#10362)