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

Transfer the source file encoding from Gradle to Eclipse #344

Open
donat opened this issue Feb 8, 2017 · 15 comments
Open

Transfer the source file encoding from Gradle to Eclipse #344

donat opened this issue Feb 8, 2017 · 15 comments

Comments

@donat
Copy link
Contributor

donat commented Feb 8, 2017

Original post: https://bugs.eclipse.org/bugs/show_bug.cgi?id=488947

@spoenemann
Copy link
Member

Related: gradle/gradle#898

What workaround could be applied until this is solved?

@donat
Copy link
Contributor Author

donat commented Aug 22, 2018

Not really at the moment, however, we'll soon implement new APIs that might be useful for you. We're going enable clients to hook into the project synchronization and to access the Tooling APIs to query arbitrary configuration from the Gradle build.

@mkq
Copy link

mkq commented Aug 27, 2018

@spoenemann Our workaround is this:

eclipse {
    project {
        file { beforeMerged { gp ->
            setEclipsePreference(file('.settings/org.eclipse.core.resources.prefs'), 'encoding/<project>', FILE_ENCODING)
        }}
    }
}

project.ext.setProperty = { File file, String key, String value ->
    def s = file.text.replaceAll("(?ms)(^\\Q${key}\\E\\s*=).*?\$", '')
    s = s.replaceAll('\n{2,}', '\n')
    file.text = s + key + '=' + value + '\n'
}

project.ext.setEclipsePreference = { File prefsFile, String key, String value ->
    println("edit ${prefsFile}:\t${key} := ${value}")
    if (!prefsFile.exists()) {
        prefsFile.parentFile.mkdirs()
        prefsFile.write("eclipse.preferences.version=1\n")
    }
    setProperty(prefsFile, key, value)
}

FILE_ENCODING is a property that we set in gradle.properties in order to set compileJava.options.encoding = project.FILE_ENCODING etc.

Unfortunately, the setting is not in effect by only a Buildship project import. It seems you need to also run the gradle eclipse task and then refresh the project in Eclipse.

@FrankS77
Copy link

FrankS77 commented Apr 3, 2019

Any news on this?

@laflaneuse
Copy link

+1

1 similar comment
@UdoW
Copy link

UdoW commented Jul 31, 2019

+1

@donat
Copy link
Contributor Author

donat commented Dec 19, 2019

I have (sort of a) workaround. I've implemented a sample Buildship extension that reads the encoding from the Java compile options and sets it the corresponding Eclipse workspace project. It's not production-ready (no test coverage, etc.), but it should do the job. Please try it out and give me feedback. If it works fine, I might be able to merge it into the Buildship core.

@UdoW
Copy link

UdoW commented Apr 6, 2020

Is this fix part of the next release?

@mjameson-se
Copy link

The sample extension did not work for me

@mauromol
Copy link

I'm the original reporter of this feature request in Eclipse Bugzilla back in March 2016. I still think this is a really important feature as soon as you work in a mixed-OS environment and/or you don't use a default text file encoding. This feature was present in the old Gradle-Eclipse plugin from SpringSource and it's surprising that it's not yet in Buildship, where a recurring motto is that the build script should be "the truth".

@cypher256
Copy link

Since Eclipse 2022-06, Eclipse warns if the encoding of the project is not set.
Is there a plan for support by Buildship?

Warn when a project does not have the encoding set
https://bugs.eclipse.org/bugs/show_bug.cgi?id=479451

@donat
Copy link
Contributor Author

donat commented Jun 16, 2022

From @onmishkin

The just-released Eclipse 2022-06 (4.24) has some changes WRT project-level info about what character encoding is used for files in the project. See [this 4.24 New & Noteworthy section](https://www.eclipse.org/eclipse/news/4.24/platform.php#no-explicit-encoding-project-warning) about the change.

The projects created by Buildship apparently do not set the project's encoding info. The result is that Eclipse reports a warning like this:

    Project 'xxx' has no explicit encoding set

for every imported project. There doesn't seem to be a way in Eclipse to suppress this warning. Buildship should do something to make Eclipse not warn.

@donat
Copy link
Contributor Author

donat commented Jun 16, 2022

Since this is a requirement now, the feature should be prioritized.

@mauromol
Copy link

Good news :-)

donat added a commit that referenced this issue Mar 23, 2023
We observed failing tests on CI verifying that the Gradle tasks view
refreshes when workspace projects open and close. The test started to
fail for Eclipse versions 4.24 and above.

The root cause was that the event listener checked for project open
events with an equals operation:

    delta.getFlags() == IResourceDelta.OPEN

It can happen, though, that the delta contains other flags. The proper
check uses byte manipulation:

    0 != (delta.getFlags() & IResourceDelta.OPEN)

The tests started to fail only for Eclipse 4.24 because that’s the first
version that requires an encoding configured for all workspace projects.
Buildship does not do that yet (see issue #344). The missing
configuration is visualized with a warning marker that’s also observed
in the resource delta:

    delta.getFlags() == IResourceDelta.OPEN && IResourceDelta.MARKERS
@donat donat modified the milestones: 3.1.7, 3.1.8 Apr 28, 2023
@donat donat modified the milestones: 3.1.8, 3.1.9 Nov 17, 2023
@donat donat modified the milestones: 3.1.9, 3.1.10 Jan 12, 2024
@reinhapa
Copy link
Contributor

@donat any update on this?

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

No branches or pull requests

10 participants