Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 0461c2e

Browse files
XanderXAJAlexander Palmer
andauthored
Make plugin configurable via dotted .sourcegraph-jetbrains.properties (#28)
* Make plugin configurable via dotted `.sourcegraph-jetbrains.properties` Normally configuration files for tools (especially global configuration) tend to begin with a dot to avoid showing up in file listings and other tools (unless desired). This change adds `.sourcegraph-jetbrains.properties` as a candidate path to check for the global configuration file. Since dotted files are conventional, the path mentioned in the README has been changed to suggest the dotted file name. The original filename is still read as a backup for backwards compatibility. * Make use of path and file terminology consistent Co-authored-by: Alexander Palmer <[email protected]>
1 parent 939e2d1 commit 0461c2e

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The plugin works with all JetBrains IDEs including:
3030

3131
## Configuring for use with a private Sourcegraph instance
3232

33-
The plugin is configurable _globally_ by creating a `sourcegraph-jetbrains.properties` in your home directory. For example, modify the following URL to match your on-premises Sourcegraph instance URL:
33+
The plugin is configurable _globally_ by creating a `.sourcegraph-jetbrains.properties` in your home directory. For example, modify the following URL to match your on-premises Sourcegraph instance URL:
3434

3535
```
3636
url = https://sourcegraph.example.com

src/main/java/Util.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import com.intellij.openapi.project.Project;
33

44
import java.io.*;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
57
import java.util.Properties;
68

79
public class Util {
@@ -78,26 +80,33 @@ public static String setRemoteUrlReplacements(Project project) {
7880
return replacements;
7981
}
8082

81-
// readProps tries to read the $HOME/sourcegraph-jetbrains.properties file.
83+
// readProps returns the first properties file it's able to parse from the following paths:
84+
// $HOME/.sourcegraph-jetbrains.properties
85+
// $HOME/sourcegraph-jetbrains.properties
8286
private static Properties readProps() {
87+
Path[] candidatePaths = {
88+
Paths.get(System.getProperty("user.home"), ".sourcegraph-jetbrains.properties"),
89+
Paths.get(System.getProperty("user.home"), "sourcegraph-jetbrains.properties"),
90+
};
91+
92+
for (Path path : candidatePaths) {
93+
try {
94+
return readPropsFile(path.toFile());
95+
} catch (IOException e) {
96+
// no-op
97+
}
98+
}
99+
// No files found/readable
100+
return new Properties();
101+
}
102+
103+
private static Properties readPropsFile(File file) throws IOException {
83104
Properties props = new Properties();
84-
InputStream input = null;
85105

86-
String path = System.getProperty("user.home") + File.separator + "sourcegraph-jetbrains.properties";
87-
try{
88-
input = new FileInputStream(path);
106+
try (InputStream input = new FileInputStream(file)) {
89107
props.load(input);
90-
} catch (IOException e) {
91-
// no-op
92-
} finally {
93-
if (input != null) {
94-
try{
95-
input.close();
96-
} catch (IOException e) {
97-
// no-op
98-
}
99-
}
100108
}
109+
101110
return props;
102111
}
103112

0 commit comments

Comments
 (0)