/*
 * Copyright 2000-2014 Eugene Petrenko
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jonnyzzz.teamcity.virtual.run.vagrant;

import com.jonnyzzz.teamcity.virtual.VMConstants;
import com.jonnyzzz.teamcity.virtual.run.VMRunnerContext;
import jetbrains.buildServer.RunBuildException;
import jetbrains.buildServer.agent.BuildRunnerContext;
import org.jetbrains.annotations.NotNull;

import java.io.File;

/**
 * @author Eugene Petrenko (eugene.petrenko@gmail.com)
 */
public class VagrantContext extends VMRunnerContext {
  public VagrantContext(@NotNull final BuildRunnerContext context) {
    super(context);
  }

  @NotNull
  public File getVagrantFile() throws RunBuildException {
    String file = myContext.getRunnerParameters().get(VMConstants.PARAMETER_VAGRANT_FILE);

    File path;
    if (file == null) {
      path = new File(myContext.getWorkingDirectory(), VMConstants.VAGRANT_FILE);
    } else {
      path = resolvePath(file);
      if (path == null) throw new RunBuildException("Vagrant file '" + file + "' does not exist");

      if (path.isDirectory()) {
        path = new File(path, VMConstants.VAGRANT_FILE);
      }
    }

    if (!path.isFile()) throw new RunBuildException("Vagrant file '" + file + "' does not exist");
    return path;
  }


  /**
   * @return for Windows returns c:\\, for other returns /
   */
  @NotNull
  public String getRootPath() {
    //TODO: fix for windows
    return "/jonnyzzz/";
  }

}

@@ -853,24 +853,70 @@
 nerContext;%0A
+import jetbrains.buildServer.util.StringUtil;%0A
 import org.j
@@ -1367,20 +1367,40 @@
 if (
-file == null
+StringUtil.isEmptyOrSpaces(file)
 ) %7B%0A
@@ -1438,15 +1438,27 @@
 .get
-Working
+Build().getCheckout
 Dire

resolve path against checkout directory (as everywhere else)