Skip to content
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

Merged
merged 7 commits into from
Jun 8, 2023

Conversation

koppor
Copy link
Member

@koppor koppor commented May 16, 2023

Fixes #9909 (comment)

Compulsory checks

Copy link
Member

@calixtus calixtus left a 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() {
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Member

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.

Comment on lines 2024 to 2027
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;
}
Copy link
Member

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.

Copy link
Member Author

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).

@@ -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,
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@calixtus calixtus May 17, 2023

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? 😅

Copy link
Member Author

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).

Copy link
Member Author

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 ^^

@calixtus calixtus added the status: changes required Pull requests that are not yet complete label May 17, 2023
@JabRef JabRef deleted a comment from github-actions bot Jun 7, 2023
@Siedlerchr Siedlerchr added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes required Pull requests that are not yet complete labels Jun 7, 2023
@koppor
Copy link
Member Author

koppor commented Jun 8, 2023

After this is merged, work should continue at #9990.

@Siedlerchr Siedlerchr merged commit 85386e6 into main Jun 8, 2023
@Siedlerchr Siedlerchr deleted the fix-hostname-detection branch June 8, 2023 14:40
Siedlerchr added a commit that referenced this pull request Jan 1, 2024
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Logging status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants