@@ -58,6 +58,7 @@ public class PbCompiler implements SourceGeneratingCompiler {
5858 private static final String PROTOC_LINUX = "protoc" ;
5959 private static final String PROTOC_MAC = "protoc" ;
6060
61+ private static final String DEFAULT_PROTO_SOURCE_ROOT = "src/main/proto" ;
6162
6263 private static final Matcher ERROR_IN_LINE_MATCHER = Pattern .compile ("[^:]*:[0-9]*:[0-9]*:.*" ).matcher ("" );
6364 private static final Matcher ERROR_IN_FILE_MATCHER = Pattern .compile ("[^:]*:[^:]*" ).matcher ("" );
@@ -150,13 +151,22 @@ public void run(final Result<PsiDirectory> result) {
150151 for (String addtionalProtoPath : getModuleAdditionalProtoPaths (item )) {
151152 compilerCommand .append (" --proto_path=" ).append (addtionalProtoPath );
152153 }
154+ // Add the default proto source root for the module if the directory exists.
155+ VirtualFile moduleFile = item .getModule ().getModuleFile ();
156+ if (moduleFile != null ) {
157+ VirtualFile protoSourceRoot = moduleFile .getParent ().findFileByRelativePath (DEFAULT_PROTO_SOURCE_ROOT );
158+ if ((protoSourceRoot != null ) && protoSourceRoot .isDirectory ()) {
159+ compilerCommand .append (" --proto_path=" ).append (protoSourceRoot .getPath ());
160+ }
161+ }
162+
153163 if (item .getFacet ().getConfiguration ().isGenerateNanoProto ()) {
154164 compilerCommand .append (" --javanano_out=" );
155165 } else {
156166 compilerCommand .append (" --java_out=" );
157167 }
158168 compilerCommand .append (outputPath );
159- compilerCommand .append (" " ).append (item .getPath ());
169+ compilerCommand .append (" " ).append (item .getPath ());
160170 LOG .info ("Invoking protoc: " + compilerCommand .toString ());
161171 proc = Runtime .getRuntime ().exec (compilerCommand .toString ());
162172 processStreams (compileContext , proc .getInputStream (), proc .getErrorStream (), item );
0 commit comments