Skip to content

Commit 08d1b93

Browse files
committed
Addtional list of proto_paths
Allow to provide an addtional list of directories used to resolve import directive. The list of directories is added after the proto file directory. This enables a scenario when dependencies in the proto file directory hide those somewhere else.
1 parent 129f153 commit 08d1b93

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

resources/messages/PbBundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ compiler.description=protoc
5959
compiler.configurable.enable.compilation.text=Enable compilation
6060
compiler.configurable.protobuf.output.panel.label=Protobuf compiler output
6161
compiler.configurable.path.to.compiler.text=Path to protoc:
62+
compiler.configurable.additionalProtoPaths.text=Additional proto paths:
6263
compiler.configurable.source.directory=Output source directory:
6364
compiler.validate.error.title=Protocol Buffers compiler
6465
compiler.validate.error.unsupported.os=Plugin compiler does not support this OS.
@@ -80,3 +81,4 @@ facet.protobuf.installation.chooser.title = Path to the Google Protocol Buffers
8081
facet.protobuf.output.dir.chooser.title = Path to the Google Protocol Buffers output directory
8182
facet.protobuf.configuration.missing_output_dir = Please specify the output directory in the Protocol Buffers facet configuration for module {0}. <a href="configure">Configure</a>
8283
file.chooser.description.select.output.directory.for.files.generated.by.protobuf.compiler = Select the output directory for files generated by the Google Protocol Buffers compiler
84+
compiler.configurable.postProtoPaths.text=[compiler.configurable.additionalProtoPaths.text / messages/PbBundle]

src/protobuf/compiler/PbCompiler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public void run(final Result<PsiDirectory> result) {
144144
StringBuilder compilerCommand = new StringBuilder();
145145
compilerCommand.append(protocPath);
146146
compilerCommand.append(" --proto_path=").append(item.getBaseDir());
147+
for (String addtionalProtoPath : getAdditionalProtoPaths()) {
148+
compilerCommand.append(" --proto_path=").append(addtionalProtoPath);
149+
}
147150
compilerCommand.append(" --java_out=").append(outputPath);
148151
compilerCommand.append(" ").append(item.getPath());
149152
LOG.info("Invoking protoc: " + compilerCommand.toString());
@@ -331,6 +334,10 @@ private String getPathToCompiler() {
331334
return compilerAppSettings.PATH_TO_COMPILER;
332335
}
333336

337+
private String[] getAdditionalProtoPaths() {
338+
return compilerAppSettings.ADDITIONAL_PROTO_PATHS.split(";");
339+
}
340+
334341
private void processStreams(CompileContext context, InputStream inp, InputStream err, PbGenerationItem item) {
335342
try {
336343
String[] errorLines = StreamUtil.readText(err).trim().split("\n");

src/protobuf/settings/application/PbCompilerApplicationSettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import com.intellij.util.xmlb.XmlSerializerUtil;
66
import org.jetbrains.annotations.NotNull;
77

8+
import java.util.Collections;
9+
import java.util.List;
10+
811
/**
912
* @author Nikolay Matveev
1013
* Date: Apr 5, 2010
@@ -19,7 +22,8 @@
1922
)
2023
public class PbCompilerApplicationSettings implements PersistentStateComponent<PbCompilerApplicationSettings>, ApplicationComponent {
2124

22-
public String PATH_TO_COMPILER = "";
25+
public String PATH_TO_COMPILER = "";
26+
public String ADDITIONAL_PROTO_PATHS = "";
2327

2428
public static PbCompilerApplicationSettings getInstance() {
2529
return ApplicationManager.getApplication().getComponent(PbCompilerApplicationSettings.class);

src/protobuf/settings/application/PbCompilerConfigurable.form

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="protobuf.settings.application.PbCompilerConfigurable">
3-
<grid id="27dc6" binding="settingsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="27dc6" binding="settingsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="500" height="400"/>
6+
<xy x="20" y="20" width="618" height="400"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -13,10 +13,10 @@
1313
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
1414
</constraints>
1515
</vspacer>
16-
<grid id="6aeae" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16+
<grid id="6aeae" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1717
<margin top="0" left="0" bottom="0" right="0"/>
1818
<constraints>
19-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
19+
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
2020
</constraints>
2121
<properties/>
2222
<border type="none"/>
@@ -31,13 +31,30 @@
3131
</component>
3232
<component id="98876" class="javax.swing.JLabel">
3333
<constraints>
34-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
34+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
3535
</constraints>
3636
<properties>
3737
<text resource-bundle="messages/PbBundle" key="compiler.configurable.path.to.compiler.text"/>
3838
<toolTipText value="Path to the directory containing the protoc binary"/>
3939
</properties>
4040
</component>
41+
<component id="27c76" class="javax.swing.JTextField" binding="addtionalProtoPathsField">
42+
<constraints>
43+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
44+
<preferred-size width="150" height="-1"/>
45+
</grid>
46+
</constraints>
47+
<properties/>
48+
</component>
49+
<component id="98877" class="javax.swing.JLabel">
50+
<constraints>
51+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
52+
</constraints>
53+
<properties>
54+
<text resource-bundle="messages/PbBundle" key="compiler.configurable.additionalProtoPaths.text"/>
55+
<toolTipText value="Semicolon separated list of paths that will be used when resolving import directives"/>
56+
</properties>
57+
</component>
4158
</children>
4259
</grid>
4360
</children>

src/protobuf/settings/application/PbCompilerConfigurable.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class PbCompilerConfigurable implements Configurable {
2626

2727
private TextFieldWithBrowseButton pathField;
28+
private JTextField addtionalProtoPathsField;
2829
private JPanel settingsPanel;
2930

3031
PbCompilerApplicationSettings myAppSettings;
@@ -60,17 +61,21 @@ public JComponent createComponent() {
6061

6162
@Override
6263
public boolean isModified() {
63-
return !myAppSettings.PATH_TO_COMPILER.equals(pathField.getText());
64+
return !myAppSettings.PATH_TO_COMPILER.equals(pathField.getText())
65+
|| !myAppSettings.ADDITIONAL_PROTO_PATHS.equals(addtionalProtoPathsField.getText());
6466
}
6567

6668
@Override
6769
public void apply() throws ConfigurationException {
6870
myAppSettings.PATH_TO_COMPILER = pathField.getText();
71+
myAppSettings.ADDITIONAL_PROTO_PATHS = addtionalProtoPathsField.getText();
72+
6973
}
7074

7175
@Override
7276
public void reset() {
7377
pathField.setText(myAppSettings.PATH_TO_COMPILER);
78+
addtionalProtoPathsField.setText(myAppSettings.ADDITIONAL_PROTO_PATHS);
7479
}
7580

7681
@Override

0 commit comments

Comments
 (0)