/*******************************************************************************
 * Copyright (c) 2016 Rogue Wave Software, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Rogue Wave Software, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.plugin.zdb.server.utils;

import java.io.File;

import javax.inject.Inject;

import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.project.server.ProjectManager;
import org.eclipse.che.api.project.server.VirtualFileEntry;
import org.eclipse.che.api.vfs.Path;
import org.eclipse.che.plugin.zdb.server.ZendDebugger;

import com.google.inject.Singleton;

/**
 * Zend debug utils.
 *
 * @author Bartlomiej Laczkowski
 */
@Singleton
public class ZendDbgFileUtils {

    private static ProjectManager projectManager;

    @Inject
    public ZendDbgFileUtils(ProjectManager projectManager) {
        ZendDbgFileUtils.projectManager = projectManager;
    }

    /**
     * Finds local file entry that corresponds to remote file path.
     *
     * @param remotePath
     * @return corresponding local file entry
     */
    public static VirtualFileEntry findVirtualFileEntry(String remotePath) {
        Path remoteFilePath = Path.of(remotePath);
        try {
            for (int i = 0; i < remoteFilePath.length(); i++) {
                Path path = remoteFilePath.subPath(i);
                VirtualFileEntry child = getVirtualFileEntry(path.toString());
                if (child != null) {
                    return child;
                }
            }
        } catch (Exception e) {
            ZendDebugger.LOG.error(e.getMessage(), e);
            return null;
        }
        return null;
    }

    /**
     * Returns local file absolute path.
     *
     * @param vfsPath
     * @return local file absolute path
     */
    public static String findAbsolutePath(String vfsPath) {
        VirtualFileEntry virtualFileEntry = getVirtualFileEntry(vfsPath);
        if (virtualFileEntry != null) {
            File ioFile = virtualFileEntry.getVirtualFile().toIoFile();
            if (ioFile != null) {
                return ioFile.getAbsolutePath();
            }
            return virtualFileEntry.getVirtualFile().getPath().toString();
        }
        return vfsPath;
    }

    private static VirtualFileEntry getVirtualFileEntry(String path) {
        VirtualFileEntry virtualFileEntry = null;
        try {
            virtualFileEntry = projectManager.getProjectsRoot().getChild(path);
        } catch (ServerException e) {
            ZendDebugger.LOG.error(e.getMessage(), e);
        }
        return virtualFileEntry;
    }

}

@@ -607,51 +607,71 @@
 ort 
-java.io.File;%0D%0A%0D%0Aimport javax.inject.Inject
+com.google.inject.Provider;%0D%0Aimport com.google.inject.Singleton
 ;%0D%0A%0D
@@ -948,35 +948,49 @@
 ort 
-com.google.inject.Singleton
+javax.inject.Inject;%0D%0Aimport java.io.File
 ;%0D%0A%0D
@@ -1126,16 +1126,25 @@
  static 
+Provider%3C
 ProjectM
@@ -1141,32 +1141,33 @@
 r%3CProjectManager
+%3E
  projectManager;
@@ -1165,16 +1165,24 @@
 tManager
+Provider
 ;%0D%0A%0D%0A   
@@ -1219,16 +1219,25 @@
 leUtils(
+Provider%3C
 ProjectM
@@ -1242,16 +1242,17 @@
 tManager
+%3E
  project
@@ -1258,16 +1258,24 @@
 tManager
+Provider
 ) %7B%0D%0A   
@@ -1310,16 +1310,24 @@
 tManager
+Provider
  = proje
@@ -1335,16 +1335,24 @@
 tManager
+Provider
 ;%0D%0A    %7D
@@ -1347,32 +1347,34 @@
 ider;%0D%0A    %7D%0D%0A%0D%0A
+%0D%0A
     /**%0D%0A     * 
@@ -2921,16 +2921,30 @@
 tManager
+Provider.get()
 .getProj

Fix initialization ZendDbgFileUtils (#3398)