Skip to content

Commit

Permalink
[GR-61332] Support TOOLS_JAVA_HOME for eclipseformat
Browse files Browse the repository at this point in the history
PullRequest: mx/1868
  • Loading branch information
zapster committed Jan 15, 2025
2 parents 4453beb + 6f36720 commit 8d7e5c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18367,7 +18367,7 @@ def alarm_handler(signum, frame):
_CACHE_DIR = get_env('MX_CACHE_DIR', join(dot_mx_dir(), 'cache'))

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("7.37.2") # GR-60644 - Ensure BenchmarkSuite.on_fail is called consistently
version = VersionSpec("7.38.0") # eclipseformat TOOLS_JAVA_HOME

_mx_start_datetime = datetime.utcnow()

Expand Down
16 changes: 15 additions & 1 deletion src/mx/_impl/mx_ide_eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ def _format_files(eclipse_exe, wsroot, eclipse_ini, config, files):
:param eclipse_ini the eclipse ini configuration file to use
:param config the JavaCodeFormatter config to use
:param files a list of file paths to format
:param jdk the JDK used to run the formatter
"""

capture = mx.OutputCapture()
jdk = mx.get_jdk()
jdk = mx.get_tools_jdk(purpose='eclipseformat')
rc = mx.run([eclipse_exe,
'--launcher.ini', eclipse_ini,
'-nosplash',
Expand Down Expand Up @@ -126,6 +127,16 @@ def __exit__(self, *args):
self.tmp_eclipseini.__exit__(*args)


_eclipseformat_attribute_name = 'eclipseformat'


def _is_enabled_for_project(p):
eclipseformat_attribute_value = getattr(p, _eclipseformat_attribute_name, True)
if not isinstance(eclipseformat_attribute_value, bool):
mx.abort(f'The {_eclipseformat_attribute_name} attribute must be a boolean value (True or False)', context=p)
return eclipseformat_attribute_value


@mx.command('mx', 'eclipseformat')
def eclipseformat(args):
"""run the Eclipse Code Formatter on the Java sources
Expand Down Expand Up @@ -201,6 +212,9 @@ def read_core_prefs_file(self):
for p in projectsToProcess:
if not p.isJavaProject():
continue
if not _is_enabled_for_project(p):
mx.logv(f'[not formatting {p.name} because "{_eclipseformat_attribute_name}" is False in suite.py]')
continue
sourceDirs = p.source_dirs()

batch = Batch(join(p.dir, '.settings'))
Expand Down

0 comments on commit 8d7e5c3

Please sign in to comment.