dvdkruk / protobuf-dt

Automatically exported from code.google.com/p/protobuf-dt
0 stars 0 forks source link

ImportPaths #180

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
suggestion:

protobuf-dt "ImportPaths" is inconvenient.

When more than one folder,for example than ten folder config is inconvenient.

This http://code.google.com/p/protoclipse/ protobuf for eclipse isn't config 
protobuf file path.

Thanks!

Original issue reported on code.google.com by liuji...@gmail.com on 17 Jan 2012 at 4:40

GoogleCodeExporter commented 9 years ago
Please provide more specific instructions of what you would like to see 
implemented.

Original comment by alr...@google.com on 12 Feb 2012 at 10:20

GoogleCodeExporter commented 9 years ago
I have the following organization:

protos
- <application>
- common
|- some.proto

the .protos from the application folder import the .protos from the common 
folder.

1. If I import "../common/some.proto", protobufs_dt does not issue an error 
which had me thinking that I had it right. However, compilation fails. 
Initially I though that this is because the import path for 'some.proto' was 
not included automatically by protobufs_dt. But it looks like protoc does not 
compile imports of this sort even if you do provide all the right import paths.

2. However simply doing an 'import some.proto' works as long as all necessary 
import paths are included. So I created my own protobufs compiler, which 
includes all necessary paths automatically and compiles all my .protos as 
required within eclipse. I assumed I could continue to use all other features 
of protobufs_dt (syntax coloring etc.) but now the editor complains that 
'some.proto' cannot be found hence marks the entire project with little red 'x' 
icons.

Fix suggestion: Let the 'root folder' be configurable > let protobufs_dt look 
for all necessary imports from the 'root folder' > then let it include all 
these necessary import paths during compilations. And the editor can do a 
similar traversal from 'root folder' and not complain about 'not finding 
imports' (since it has found the .protos somewhere in the root folder sub-tree 
and since it knows that the integrated compiler will use similar logic)

Here is the code that I wrote (it is quite clunky and not tested but it works 
for basic cases - maybe you can improve on this? my code is written to compile 
all protos each time I run.)

    /**
     * Get map of subdirectories and their .proto files
     * 
     * @param currentDir                Current directory being processed
     * @param directoriesAndProtos      HashMap of all subdirectories (including passed in currentDir) and .proto files in those directories
     * @return                          directoriesAndProtos
     */
    protected static HashMap<String, ArrayList<String>> getSubDirectoriesAndProtoFiles(File currentDir, HashMap<String,ArrayList<String>> directoriesAndProtos) {
        if (currentDir.isDirectory()) {
            //check if directory has any .proto files
            File[] fileList = currentDir.listFiles();
            if(fileList!=null) {
                ArrayList<String>protoFiles = null;
                for (File file: fileList){
                    String fileName = file.getAbsolutePath();
                    int fileNameLen=fileName.length();
                    if (fileName.substring(fileNameLen-6, fileNameLen).equals(".proto")){
                        if (protoFiles==null)
                            protoFiles = new ArrayList<String>();
                        protoFiles.add(fileName);
                    }
                }
                //add directory name to list of possible import locations and add .proto files
                if (protoFiles!=null){
                    directoriesAndProtos.put(currentDir.getAbsolutePath(),protoFiles);
                }

                //retrieve list of files and directory under this directory

                for (File file: fileList)
                    getSubDirectoriesAndProtoFiles(file,directoriesAndProtos);
            }
        }
        return directoriesAndProtos;
    }

Original comment by kushel...@gmail.com on 15 Mar 2012 at 6:22

GoogleCodeExporter commented 9 years ago
I'm sorry I missed the last comment.

Original comment by alr...@google.com on 24 Oct 2012 at 5:45