-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use environment variables for hostname detection #9910
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More than nitpicks. Sorry.
/** | ||
* The constructor is made package private to enforce this as a singleton class while allowing testing of the class | ||
*/ | ||
JabRefPreferences() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet it could now be instantiated by any other class in the same package but the internal singleton 'factory'. Please do not remove private, use the singleton factory getInstance
also for the tests instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need to rewrite "get instance". -- A new method "reset references"
The intention is that the preferences are created from scratch at each test. No reuse.
The main paint is about re initialization each time in the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading your next comment, the whole change is unnecessary. However, I wonder why there are no tests for preferences at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now the preferences work live on the real preferences data. there are no tests at all, because the whole class is still untestable. This is one driver for me to refactor the whole preferences mechanic. So we have a testable part that can be instantiated with a mock dao (?) and the real java preferences.
String hostName; | ||
// Following code inspired by https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/SystemUtils.html#getHostName-- | ||
// See also https://stackoverflow.com/a/20793241/873282 | ||
if (OS.WINDOWS) { | ||
hostName = System.getenv("COMPUTERNAME"); | ||
} else { | ||
hostName = System.getenv("HOSTNAME"); | ||
} | ||
if (StringUtil.isBlank(hostName)) { | ||
try { | ||
hostName = InetAddress.getLocalHost().getHostName(); | ||
} catch (UnknownHostException e) { | ||
LOGGER.info("Hostname not found. Using \"localhost\" as fallback.", e); | ||
hostName = "localhost"; | ||
} | ||
} | ||
|
||
userAndHost = get(DEFAULT_OWNER) + '-' + hostName; | ||
return userAndHost; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the open-closed design principle, i believe this should all go to the OS classes instead, so the JabRefPreferences does not have to distinguish between the different os, but just call to the proper overridden method. Also the call directly to System.getenv
would imho break the level of abstraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change was easy: 151ea22
(#9910). Huge preparation work required though: 84899aa
(#9910).
src/test/java/org/jabref/preferences/JabRefPreferencesTest.java
Outdated
Show resolved
Hide resolved
@@ -37,7 +37,7 @@ public class FilePreferences { | |||
private final BooleanProperty createBackup = new SimpleBooleanProperty(); | |||
private final ObjectProperty<Path> backupDiretory = new SimpleObjectProperty<>(); | |||
|
|||
public FilePreferences(String user, | |||
public FilePreferences(String userAndHost, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single responsibility? Please use separate variables instead and differentiate between the vars in FilePreferences and InternalPreferences if you want to use it for different purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the variables to match the existing (!!!) content. Separatiin can be done in a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, calixtus can do the separation in a follow up pr? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The renaming is now in 7025d45
(#9910). I think, the combination is OK, because it is "only" needed for the directory and the stitching together should be done as early as possible.
Nevertheless, some changes will be necessary to prevent restart of JabRef when the owner name is changed. I made a small beginning at cc40eaf
(#9910).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, you are right. Was nevertheless too much work for me now ^^
79ccba1
to
151ea22
Compare
After this is merged, work should continue at #9990. |
* upstream/main: (68 commits) Fix issue 9863 - Change Tab selection order (#9907) New Crowdin updates (#9994) Enable editing typo with double clicking on field name in custom entry type (#9977) Remove "Field name:" from localization - we already have "Field name" (#9991) Changed database to catalog in org.jabref.gui.slr and org.jabref.logic.crawler (#9989) Use environment variables for hostname detection (#9910) Add cleanup activity for URL field (#9970) Fix freezing when fetching IBSN and no results are found (#9987) Make Group(Node)TreeViewModel more OO (#9978) Fix container for group item count still visible if display count is off (#9980) Fix paste of BibTeX data (#9985) Bring back SimplifyBoolean* and UnnecessaryParantheses (and refine guide) (#9981) Add new menu entry to remove braces from selection, aka unprotect it. (#9968) User specific comment (#9727) Bump org.openrewrite.recipe:rewrite-recipe-bom from 1.19.3 to 2.0.0 (#9975) Fix typos Remove non-needed link Fix typos Enable RemoveJavaDocAuthorTag (#9973) Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 (#9974) ...
Fixes #9909 (comment)
Compulsory checks