Skip to content

Commit

Permalink
Merge pull request JabRef#5370 from JabRef/improveEclipse
Browse files Browse the repository at this point in the history
Improve Eclipse config
  • Loading branch information
Siedlerchr committed Oct 1, 2019
2 parents 5d539ed + ba1fb95 commit 631cec5
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions eclipse.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.gradle.plugins.ide.eclipse.model.AccessRule
apply plugin: "eclipse"

// ensure that source code is generated, otherwise class `BstLexer` cannot be found
Expand All @@ -11,22 +10,25 @@ eclipseJdt.doLast {
f.append('encoding/<project>=UTF-8')
}
eclipse {
project {
natures 'org.eclipse.buildship.core.gradleprojectnature'
}

classpath {
file {
whenMerged {
entries.findAll { isModule(it) }.each { //(1)
entries.findAll { isModule(it) }.each { //this was already necessary to build modular projects
it.entryAttributes['module'] = 'true'
}
def controlsfx = entries.find { isControlsfx(it) };
controlsfx.entryAttributes['add-exports'] = 'org.controlsfx.controls/impl.org.controlsfx.skin=org.jabref:org.controlsfx.controls/org.controlsfx.control.textfield=org.jabref:org.controlsfx.controls/impl.org.controlsfx.autocompletion=org.jabref';
controlsfx.entryAttributes['add-opens'] = 'org.controlsfx.controls/impl.org.controlsfx.skin=org.jabref:org.controlsfx.controls/org.controlsfx.control.textfield=org.jabref:org.controlsfx.controls/impl.org.controlsfx.autocompletion=org.jabref';

entries.findAll { isSource(it) && isTestScope(it) }.each {
entries.findAll { isSource(it) && isTestScope(it) }.each { //mark test source folders
it.entryAttributes['test'] = 'true'
}

entries.findAll { isLibrary(it) && isTestScope(it) }.each {
def jreContainer = entries.find { isJREContainer(it) };
jreContainer.entryAttributes['add-exports'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref';
jreContainer.entryAttributes['add-opens'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref';

entries.findAll { isLibrary(it) && isTestScope(it) }.each { //mark test source files
it.entryAttributes['test'] = 'true'
}
}
Expand All @@ -39,10 +41,19 @@ eclipse {
}

boolean isLibrary(entry) { return entry.properties.kind.equals('lib') }
boolean isTestScope(entry) { return entry.entryAttributes.get('gradle_used_by_scope').equals('test'); }
boolean isModule(entry) { isLibrary(entry) && !isTestScope(entry); }

boolean isTestScope(entry) { return !entry.entryAttributes.get('gradle_used_by_scope').contains('main') }

boolean isModule(entry) {
isLibrary(entry) && !isTestScope(entry);
} //a test-scope library should be put on the classpath instead of the modulepath
boolean isSource(entry) { return entry.properties.kind.equals('src'); }

boolean isControlsfx(entry) { return entry.properties.path.contains('controlsfx'); }

boolean isJREContainer(entry) {
return entry.properties.kind == 'con' && entry.properties.path.startsWith('org.eclipse.jdt.launching.JRE_CONTAINER')
};

// add formatter and cleanup settings to Eclipse settings
// see http://stackoverflow.com/a/27461890/873282
Expand Down Expand Up @@ -465,7 +476,7 @@ tasks.eclipse.doFirst {
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
'''. stripIndent())
'''.stripIndent())

File jdt_ui_prefs = file("${project.projectDir}/.settings/org.eclipse.jdt.ui.prefs")
if (jdt_ui_prefs.exists()) {
Expand Down Expand Up @@ -597,6 +608,6 @@ tasks.eclipse.doFirst {
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=false
sp_cleanup.use_type_arguments=false
'''. stripIndent())
'''.stripIndent())
}
}
}

0 comments on commit 631cec5

Please sign in to comment.