Fixed: [Issue 205] Auto-Compiler problem in Windows
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption_segmentsOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption_segmentsOf_Test.java
similarity index 95%
rename from com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption_segmentsOf_Test.java
rename to com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption_segmentsOf_Test.java
index c2a3b2b..b52c0c4 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/AbstractOutputDirectoryProtocOption_segmentsOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption_segmentsOf_Test.java
@@ -21,7 +21,7 @@
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-public class AbstractOutputDirectoryProtocOption_segmentsOf_Test {
+public class CodeGenerationProtocOption_segmentsOf_Test {
   @Test(expected = NullPointerException.class)
   public void should_throw_error_if_path_is_null() {
     CodeGenerationProtocOption.segmentsOf(null);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption_singleImportRoot_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption_singleImportRoot_Test.java
new file mode 100644
index 0000000..59298fa
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption_singleImportRoot_Test.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012 Google 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
+ */
+package com.google.eclipse.protobuf.ui.protoc.command;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import org.junit.*;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Tests for <code>{@link ImportRootsProtocOption#singleImportRoot(File, File)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ImportRootsProtocOption_singleImportRoot_Test {
+  @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  private File project;
+
+  @Before public void setUp() {
+    project = temporaryFolder.newFolder("project");
+  }
+
+  @Test public void should_return_project_directory_if_file_is_underneath_it() {
+    File protoFile = new File(project, "test.proto");
+    String singleImportRoot = ImportRootsProtocOption.singleImportRoot(project, protoFile);
+    assertThat(singleImportRoot, equalTo(project.toString()));
+  }
+
+  @Test public void should_return_parent_directory_directly_below_project() {
+    File srcDirectory = createDirectory(project, "src");
+    File protoFile = new File(createDirectory(srcDirectory, "proto"), "test.proto");
+    String singleImportRoot = ImportRootsProtocOption.singleImportRoot(project, protoFile);
+    assertThat(singleImportRoot, equalTo(srcDirectory.toString()));
+  }
+
+  private File createDirectory(File parent, String name) {
+    File directory = new File(parent, name);
+    assertTrue(directory.mkdir());
+    return directory;
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
index 5f29cea..312b6eb 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
@@ -52,7 +52,7 @@
       return;
     }
     PathsPreferences pathsPreferences = new PathsPreferences(storeAccess, project);
-    ProtocCommandBuilder commandBuilder = new ProtocCommandBuilder(compilerPreferences, pathsPreferences, project);
+    ProtocCommandBuilder commandBuilder = new ProtocCommandBuilder(compilerPreferences, pathsPreferences);
     for (Delta d : deltas) {
       IFile protoFile = protoFile(d.getNew(), project);
       if (protoFile == null) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
index 143b2d6..cef9882 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
@@ -37,9 +37,9 @@
 import com.google.inject.Inject;
 
 /**
- * Inserts a semicolon at the end of a line, regardless of the current position of the caret in the editor. If the
- * line of code being edited is a field or enum literal and if it does not have an index yet, this handler will
- * insert an index with a proper value as well.
+ * Inserts a semicolon at the end of a line, regardless of the current position of the caret in the editor. If the line
+ * of code being edited is a field or enum literal and if it does not have an index yet, this handler will insert an
+ * index with a proper value as well.
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreference.java
index cf1cb60..3c82f0d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreference.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreference.java
@@ -8,6 +8,8 @@
  */
 package com.google.eclipse.protobuf.ui.preferences.compiler;
 
+import org.eclipse.core.resources.IProject;
+
 /**
  * @author alruiz@google.com (Alex Ruiz)
  */
@@ -15,4 +17,6 @@
   boolean isEnabled();
 
   String outputDirectory();
+
+  IProject project();
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java
index d87f142..72a3b97 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java
@@ -24,19 +24,21 @@
     if (!enableProjectSettings) {
       store = storeAccess.getWritablePreferenceStore();
     }
-    return new CompilerPreferences(store);
+    return new CompilerPreferences(store, project);
   }
 
   private final IPreferenceStore store;
+  private final IProject project;
   private final CodeGenerationPreference javaCodeGenerationPreference;
   private final CodeGenerationPreference cppCodeGenerationPreference;
   private final CodeGenerationPreference pythonCodeGenerationPreference;
 
-  private CompilerPreferences(IPreferenceStore store) {
+  private CompilerPreferences(IPreferenceStore store, IProject project) {
     this.store = store;
-    javaCodeGenerationPreference = new JavaCodeGenerationPreference(store);
-    cppCodeGenerationPreference = new CppCodeGenerationPreference(store);
-    pythonCodeGenerationPreference = new PythonCodeGenerationPreference(store);
+    this.project = project;
+    javaCodeGenerationPreference = new JavaCodeGenerationPreference(store, project);
+    cppCodeGenerationPreference = new CppCodeGenerationPreference(store, project);
+    pythonCodeGenerationPreference = new PythonCodeGenerationPreference(store, project);
   }
 
   public boolean shouldCompileProtoFiles() {
@@ -75,6 +77,10 @@
     return store.getBoolean(REFRESH_PROJECT);
   }
 
+  public IProject project() {
+    return project;
+  }
+
   public static class Initializer implements IPreferenceStoreInitializer {
     private static final String DEFAULT_OUTPUT_DIRECTORY = "src-gen";
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CppCodeGenerationPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CppCodeGenerationPreference.java
index 0a08d26..7adf8ea 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CppCodeGenerationPreference.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CppCodeGenerationPreference.java
@@ -10,6 +10,7 @@
 
 import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.*;
 
+import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 /**
@@ -17,9 +18,11 @@
  */
 class CppCodeGenerationPreference implements CodeGenerationPreference {
   private final IPreferenceStore store;
+  private final IProject project;
 
-  CppCodeGenerationPreference(IPreferenceStore store) {
+  CppCodeGenerationPreference(IPreferenceStore store, IProject project) {
     this.store = store;
+    this.project = project;
   }
 
   @Override public boolean isEnabled() {
@@ -29,4 +32,8 @@
   @Override public String outputDirectory() {
     return store.getString(JAVA_OUTPUT_DIRECTORY);
   }
+
+  @Override public IProject project() {
+    return project;
+  }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/JavaCodeGenerationPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/JavaCodeGenerationPreference.java
index 93fe698..7802867 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/JavaCodeGenerationPreference.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/JavaCodeGenerationPreference.java
@@ -10,6 +10,7 @@
 
 import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.*;
 
+import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 /**
@@ -17,9 +18,11 @@
  */
 class JavaCodeGenerationPreference implements CodeGenerationPreference {
   private final IPreferenceStore store;
+  private final IProject project;
 
-  JavaCodeGenerationPreference(IPreferenceStore store) {
+  JavaCodeGenerationPreference(IPreferenceStore store, IProject project) {
     this.store = store;
+    this.project = project;
   }
 
   @Override public boolean isEnabled() {
@@ -29,4 +32,8 @@
   @Override public String outputDirectory() {
     return store.getString(CPP_OUTPUT_DIRECTORY);
   }
+
+  @Override public IProject project() {
+    return project;
+  }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PythonCodeGenerationPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PythonCodeGenerationPreference.java
index c256ad8..145db98 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PythonCodeGenerationPreference.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PythonCodeGenerationPreference.java
@@ -10,6 +10,7 @@
 
 import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.*;
 
+import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 /**
@@ -17,9 +18,11 @@
  */
 class PythonCodeGenerationPreference implements CodeGenerationPreference {
   private final IPreferenceStore store;
+  private final IProject project;
 
-  PythonCodeGenerationPreference(IPreferenceStore store) {
+  PythonCodeGenerationPreference(IPreferenceStore store, IProject project) {
     this.store = store;
+    this.project = project;
   }
 
   @Override public boolean isEnabled() {
@@ -29,4 +32,8 @@
   @Override public String outputDirectory() {
     return store.getString(PYTHON_OUTPUT_DIRECTORY);
   }
+
+  @Override public IProject project() {
+    return project;
+  }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption.java
index 575055c..7cc7f4f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/CodeGenerationProtocOption.java
@@ -25,17 +25,15 @@
 
   private final String optionName;
   private final CodeGenerationPreference preferences;
-  private final IProject project;
 
   private boolean initialized;
   private boolean enabled;
   private IFolder outputDirectory;
   private String outputDirectoryLocation;
 
-  CodeGenerationProtocOption(String optionName, CodeGenerationPreference preferences, IProject project) {
+  CodeGenerationProtocOption(String optionName, CodeGenerationPreference preferences) {
     this.optionName = optionName;
     this.preferences = preferences;
-    this.project = project;
   }
 
   @Override public final void addOptionTo(ProtocCommand command) throws CoreException {
@@ -68,6 +66,7 @@
   private IFolder findOrCreateDirectory(String directoryName) throws CoreException {
     IFolder directory = null;
     StringBuilder path = new StringBuilder();
+    IProject project = preferences.project();
     for (String segment : segmentsOf(directoryName)) {
       path.append(segment);
       directory = project.getFolder(path.toString());
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java
index 6f72854..38bb19a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ImportRootsProtocOption.java
@@ -9,7 +9,7 @@
 package com.google.eclipse.protobuf.ui.protoc.command;
 
 import static com.google.common.collect.Lists.newArrayList;
-import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
 import static org.eclipse.xtext.util.Strings.isEmpty;
 
 import java.io.File;
@@ -17,6 +17,7 @@
 
 import org.eclipse.core.resources.*;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.eclipse.protobuf.ui.preferences.paths.*;
 
@@ -25,33 +26,27 @@
  */
 class ImportRootsProtocOption {
   private final PathsPreferences preferences;
-  private final IProject project;
 
   private boolean initialized;
   private List<String> importRoots;
 
-  ImportRootsProtocOption(PathsPreferences preferences, IProject project) {
+  ImportRootsProtocOption(PathsPreferences preferences) {
     this.preferences = preferences;
-    this.project = project;
   }
 
   public void addOptionToCommand(ProtocCommand command, IFile protoFile) {
     if (!initialized) {
-      initialize();
+      initialize(protoFile);
     }
-    if (!importRoots.isEmpty()) {
-      for (String importRoot : importRoots) {
-        appendToCommand(command, importRoot);
-      }
-      return;
+    for (String importRoot : importRoots) {
+      appendToCommand(command, importRoot);
     }
-    appendToCommand(command, singleImportRoot(protoFile));
   }
 
-  private void initialize() {
+  private void initialize(IFile protoFile) {
     initialized = true;
     if (!preferences.areFilesInMultipleDirectories()) {
-      importRoots =  emptyList();
+      importRoots = singletonList(singleImportRoot(protoFile));
       return;
     }
     importRoots = newArrayList();
@@ -67,15 +62,21 @@
   }
 
   private String singleImportRoot(IFile protoFile) {
-    File projectFile = locationAsFileOf(project);
-    File currentFile = locationAsFileOf(protoFile);
-    while (!currentFile.getParentFile().equals(projectFile)) {
-      currentFile = currentFile.getParentFile();
-    }
-    return currentFile.toString();
+    return singleImportRoot(locationOf(preferences.project()), locationOf(protoFile));
   }
 
-  private File locationAsFileOf(IResource resource) {
+  @VisibleForTesting static String singleImportRoot(File projectLocation, File protoFileLocation) {
+    if (protoFileLocation.getParentFile().equals(projectLocation)) {
+      return projectLocation.toString();
+    }
+    File current = protoFileLocation;
+    while (!current.getParentFile().equals(projectLocation)) {
+      current = current.getParentFile();
+    }
+    return current.toString();
+  }
+
+  private File locationOf(IResource resource) {
     return resource.getLocation().toFile();
   }
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java
index 8e40507..8737fb3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/protoc/command/ProtocCommandBuilder.java
@@ -30,14 +30,13 @@
   private final String protocPath;
   private final ImportRootsProtocOption importRootsProtocOption;
 
-  public ProtocCommandBuilder(CompilerPreferences compilerPreferences, PathsPreferences pathsPreferences,
-      IProject project) {
+  public ProtocCommandBuilder(CompilerPreferences compilerPreferences, PathsPreferences pathsPreferences) {
     protocPath = compilerPreferences.protocPath();
     options.add(new DescriptorPathProtocOption(compilerPreferences));
-    options.add(new CodeGenerationProtocOption("java_out", compilerPreferences.javaCodeGeneration(), project));
-    options.add(new CodeGenerationProtocOption("cpp_out", compilerPreferences.cppCodeGeneration(), project));
-    options.add(new CodeGenerationProtocOption("python_out", compilerPreferences.pythonCodeGeneration(), project));
-    importRootsProtocOption = new ImportRootsProtocOption(pathsPreferences, project);
+    options.add(new CodeGenerationProtocOption("java_out", compilerPreferences.javaCodeGeneration()));
+    options.add(new CodeGenerationProtocOption("cpp_out", compilerPreferences.cppCodeGeneration()));
+    options.add(new CodeGenerationProtocOption("python_out", compilerPreferences.pythonCodeGeneration()));
+    importRootsProtocOption = new ImportRootsProtocOption(pathsPreferences);
   }
 
   /**
@@ -57,8 +56,8 @@
   }
 
   /**
-   * Returns the output directories where generated code is stored.
-   * @return the output directories where generated code is stored.
+   * Returns the directories where to store generated code.
+   * @return the directories where to store generated code.
    * @throws CoreException if something goes wrong.
    */
   public List<IFolder> outputDirectories() throws CoreException {