Status: New
Owner: ken...@google.com
Labels: Type-Defect Priority-Medium

New issue 250 by adrian.wilkins: [PATCH] Maven-plugin does not work with M2Eclipse
http://code.google.com/p/protobuf/issues/detail?id=250

maven-plugin always expects to add jar files to the classpath for .proto files, but when used in Eclipse with M2Eclipse, the classpath can include folders.

Patch below clarifies an error message and adds naked directories to classpath as well as JAR files, thus working with both M2Eclipse and command line.


=== modified file 'tools/maven-plugin/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java' --- tools/maven-plugin/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java 2009-02-10 18:34:50 +0000 +++ tools/maven-plugin/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java 2010-12-30 22:08:25 +0000
@@ -191,29 +191,32 @@
     }
     Set<File> protoDirectories = newHashSet();
     for (File classpathElementFile : classpathElementFiles) {
-      checkArgument(classpathElementFile.isFile(), "%s is not a file",
-          classpathElementFile);
-      // create the jar file. the constructor validates.
-      JarFile classpathJar = null;
-      try {
-        classpathJar = new JarFile(classpathElementFile);
-      } catch (IOException e) {
-        throw new IllegalArgumentException(format(
-            "%s was not a readable artifact", classpathElementFile));
-      }
-      for (JarEntry jarEntry : list(classpathJar.entries())) {
-        final String jarEntryName = jarEntry.getName();
-        if (jarEntry.getName().endsWith(PROTO_FILE_SUFFIX)) {
-          final File uncompressedCopy =
-              new File(new File(temporaryProtoFileDirectory, classpathJar
-                  .getName()), jarEntryName);
-          uncompressedCopy.getParentFile().mkdirs();
-          copyStreamToFile(new RawInputStreamFacade(classpathJar
-              .getInputStream(jarEntry)), uncompressedCopy);
-          protoDirectories.add(uncompressedCopy);
-        }
-      }
-
+
+       if(classpathElementFile.isDirectory()) {
+         protoDirectories.add(classpathElementFile);
+      } else {
+               
+             // create the jar file. the constructor validates.
+             JarFile classpathJar = null;
+             try {
+               classpathJar = new JarFile(classpathElementFile);
+             } catch (IOException e) {
+               throw new IllegalArgumentException(format(
+                   "%s was not a readable artifact", classpathElementFile));
+             }
+             for (JarEntry jarEntry : list(classpathJar.entries())) {
+               final String jarEntryName = jarEntry.getName();
+               if (jarEntry.getName().endsWith(PROTO_FILE_SUFFIX)) {
+                 final File uncompressedCopy =
+                     new File(new File(temporaryProtoFileDirectory, 
classpathJar
+                         .getName()), jarEntryName);
+                 uncompressedCopy.getParentFile().mkdirs();
+                 copyStreamToFile(new RawInputStreamFacade(classpathJar
+                     .getInputStream(jarEntry)), uncompressedCopy);
+                 protoDirectories.add(uncompressedCopy.getParentFile());
+               }
+             }
+      }
     }
     forceDeleteOnExit(temporaryProtoFileDirectory);
     return ImmutableSet.copyOf(protoDirectories);

=== modified file 'tools/maven-plugin/src/main/java/com/google/protobuf/maven/Protoc.java' --- tools/maven-plugin/src/main/java/com/google/protobuf/maven/Protoc.java 2009-02-10 18:34:50 +0000 +++ tools/maven-plugin/src/main/java/com/google/protobuf/maven/Protoc.java 2010-12-30 22:08:25 +0000
@@ -174,8 +174,9 @@
      *         directory.
      */
     public Builder addProtopathElement(File protopathElement) {
-      checkNotNull(protopathElement);
-      checkArgument(protopathElement.isDirectory());
+      checkNotNull(protopathElement, "path element is null");
+      checkArgument(protopathElement.isDirectory(),
+                 String.format("%1$s is not a directory", protopathElement));
       protopathElements.add(protopathElement);
       return this;
     }




--
You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to