Fixed: [102] Setting path to descriptor.proto file in preferences breaks
the build process on Win 7
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder_findRootOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder_findRootOf_Test.java
index be531f2..ff28551 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder_findRootOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder_findRootOf_Test.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.builder;
+import static java.io.File.separator;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
@@ -41,11 +42,21 @@
@Test public void should_throw_error_if_path_does_not_contain_descriptor_FQN() {
thrown.expect(IllegalArgumentException.class);
+ if (separator.equals("\\")) {
+ thrown.expectMessage("Path '\\usr\\local\\include' does not contain '\\google\\protobuf\\descriptor.proto'");
+ finder.findRootOf("\\usr\\local\\include");
+ return;
+ }
thrown.expectMessage("Path '/usr/local/include' does not contain '/google/protobuf/descriptor.proto'");
finder.findRootOf("/usr/local/include");
}
@Test public void should_find_import_root_of_descriptor() {
+ if (separator.equals("\\")) {
+ String filePath = "\\usr\\local\\include\\google\\protobuf\\descriptor.proto";
+ assertThat(finder.findRootOf(filePath), equalTo("\\usr\\local\\include"));
+ return;
+ }
String filePath = "/usr/local/include/google/protobuf/descriptor.proto";
assertThat(finder.findRootOf(filePath), equalTo("/usr/local/include"));
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder.java
index 1e1dd46..f2d984a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtoDescriptorPathFinder.java
@@ -8,15 +8,16 @@
*/
package com.google.eclipse.protobuf.ui.builder;
-import static com.google.eclipse.protobuf.scoping.ProtoDescriptor.DESCRIPTOR_IMPORT_URI;
-import static org.eclipse.xtext.util.Strings.isEmpty;
+import static java.io.File.separator;
+import static java.util.Arrays.asList;
+import static org.eclipse.xtext.util.Strings.*;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
class ProtoDescriptorPathFinder {
- private static final String DESCRIPTOR_FQN = "/" + DESCRIPTOR_IMPORT_URI;
+ private static final String DESCRIPTOR_FQN = concat(separator, asList("", "google", "protobuf", "descriptor.proto"));
public String findRootOf(String descriptorFilePath) {
if (isEmpty(descriptorFilePath)) return null;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader.java
index 107ca0a..e2d5c1c 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader.java
@@ -8,7 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.editor.model;
-import static com.google.eclipse.protobuf.util.Closeables.close;
+import static com.google.eclipse.protobuf.util.Closeables.closeQuietly;
import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
import java.io.*;
@@ -36,7 +36,7 @@
}
return contents.toString();
} finally {
- close(reader);
+ closeQuietly(reader);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
index d61e573..aa924f5 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
@@ -9,7 +9,7 @@
package com.google.eclipse.protobuf.ui.editor.model;
import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
-import static com.google.eclipse.protobuf.util.Closeables.close;
+import static com.google.eclipse.protobuf.util.Closeables.closeQuietly;
import java.io.*;
@@ -50,7 +50,7 @@
inputStream = new FileInputStream(file);
return contentReader.contentsOf(inputStream);
} finally {
- close(inputStream);
+ closeQuietly(inputStream);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
index a4123e5..089a50f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
@@ -9,7 +9,7 @@
package com.google.eclipse.protobuf.ui.editor.model;
import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
-import static com.google.eclipse.protobuf.util.Closeables.close;
+import static com.google.eclipse.protobuf.util.Closeables.closeQuietly;
import java.io.IOException;
import java.io.InputStream;
@@ -53,7 +53,7 @@
inputStream = url.openConnection().getInputStream();
return contentReader.contentsOf(inputStream);
} finally {
- close(inputStream);
+ closeQuietly(inputStream);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
index edcada6..31a545f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
@@ -8,7 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.util;
-import java.io.File;
+import static java.io.File.separator;
/**
* Utility methods related to paths.
@@ -25,7 +25,7 @@
*/
public static String[] segmentsOf(String path) {
if (path == null) throw new NullPointerException("The given path should not be null");
- return path.split(File.separator);
+ return path.split(separator);
}
private Paths() {}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
index b27a2cf..a09197c 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
@@ -10,7 +10,7 @@
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PROPERTY__TYPE;
import static com.google.eclipse.protobuf.scoping.OptionType.*;
-import static com.google.eclipse.protobuf.util.Closeables.close;
+import static com.google.eclipse.protobuf.util.Closeables.closeQuietly;
import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
import static java.util.Collections.*;
import static org.eclipse.xtext.EcoreUtil2.*;
@@ -77,7 +77,7 @@
} catch (Throwable t) {
throw new IllegalStateException("Unable to parse descriptor.proto", t);
} finally {
- close(reader);
+ closeQuietly(reader);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
index 1065f29..0e4d490 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
@@ -18,11 +18,11 @@
public class Closeables {
/**
- * Invokes {@code close()} on the given <code>{@link Cloneable}</code>, ignoring any thrown exceptions.
+ * Invokes {@code close()} on the given <code>{@link Closeable}</code>, ignoring any thrown exceptions.
* @param c the given {@code Closeable}.
* @return {@code false} if the given {@code Closeable} was {@code null}; {@code true} otherwise.
*/
- public static boolean close(Closeable c) {
+ public static boolean closeQuietly(Closeable c) {
if (c == null) return false;
try {
c.close();