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

Buildship is not using Eclipse APIs to persist the .prefs files #1111

Closed
jdneo opened this issue Sep 30, 2021 · 2 comments · Fixed by #1114
Closed

Buildship is not using Eclipse APIs to persist the .prefs files #1111

jdneo opened this issue Sep 30, 2021 · 2 comments · Fixed by #1114

Comments

@jdneo
Copy link
Member

jdneo commented Sep 30, 2021

Currently the Buildship uses an own implementation to read/write preferences. But not using Eclipse API to do such jobs. Is it intended for some reasons? (See the Context section for more explanation about this request)

Expected Behavior

Use APIs provided by Eclipse to read and write preferences to the .settings/ folder

Current Behavior

The current implementation hard-code the .prefs file's location and read/write it directly via Java IO APIs

Context

In VS Code Java, there is an issue complained mostly about stop generating .project, .classpath, .settings files at the project root: redhat-developer/vscode-java#618. After some investigation, we found that we can use the Eclipse File System Provider extension point to customize the file location for some specific files. But that requires other plugins use Eclipse standard APIs to read and write files.

We found that In Buildship, there is a customized implementation to deal with the preferences, and the file is persisted directly via Java IO APIs.

This makes the extension point not working, so we'd like to know if this is done by some reasons? Or this is can be fixed to use the standard Eclipse API.

Steps to Reproduce

Your Environment

@donat
Copy link
Contributor

donat commented Oct 11, 2021

The preference modification was implemented this way to avoid problems when the preference file cannot be written: the FS is not in sync, the project is closed, etc. The default implementation uses the Eclipse API, and falls back to the native file operation upon failure. IIRC JDT uses the same technique when importing Java projects.

@jdneo
Copy link
Member Author

jdneo commented Oct 12, 2021

Thanks for sharing the background.

I did some search to JDT and m2e projects but did not find use case for that? I might be wrong because I'm not familiar with those repos.

Seems that in buildship there are some cases that the passing parameter is a folder path not IProject. Do you think it's acceptable to do following changes when we read/write the prefs file, just like the implementation buildship already have in DefaultConfigurationManager#loadBuildConfiguration()

public String readPreferences(File projectDir) {
    Preconditions.checkNotNull(projectDir);
    Optional<IProject> projectCandidate = CorePlugin.workspaceOperations().findProjectByLocation(rootDir);
    if (projectCandidate.isPresent() && projectCandidate.get().isAccessible()) {
        IProject project = projectCandidate.get();
        try {
    	    return readPreferences(project);
        } catch (Exception e) {
             /** Fallback to the file IO based function here */
        }
    }
    /** Fallback to the file IO based function here */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants