2929BASE_URL = ALT_BASE_URL or 'https://www.languagetool.org/download/'
3030FILENAME = 'LanguageTool-{version}.zip'
3131PACKAGE_PATH = os .path .dirname (os .path .realpath (__file__ ))
32- JAVA_6_COMPATIBLE_VERSION = '2.2'
33- JAVA_7_COMPATIBLE_VERSION = '3.1'
3432LATEST_VERSION = '4.9'
3533
3634JAVA_VERSION_REGEX = re .compile (
@@ -64,45 +62,26 @@ def parse_java_version(version_text):
6462 if not match :
6563 raise SystemExit (
6664 'Could not parse Java version from """{}""".' .format (version_text ))
67-
6865 return (int (match .group ('major1' )), int (match .group ('major2' )))
6966
70-
71- def get_newest_possible_languagetool_version ():
72- """Return newest compatible version.
73-
74- >>> version = get_newest_possible_languagetool_version()
75- >>> version in [JAVA_6_COMPATIBLE_VERSION,
76- ... JAVA_7_COMPATIBLE_VERSION,
77- ... LATEST_VERSION]
78- True
79-
80- """
67+ def confirm_java_compatibility ():
68+ """ Confirms Java major version >= 8. """
8169 java_path = find_executable ('java' )
8270 if not java_path :
8371 # Just ignore this and assume an old version of Java. It might not be
8472 # found because of a PATHEXT-related issue
8573 # (https://bugs.python.org/issue2200).
86- return JAVA_6_COMPATIBLE_VERSION
74+ raise ModuleNotFoundError ( 'No java install detected. Please install java to use language-tool-python.' )
8775
8876 output = subprocess .check_output ([java_path , '-version' ],
8977 stderr = subprocess .STDOUT ,
9078 universal_newlines = True )
9179
92- java_version = parse_java_version (output )
93-
94- if java_version >= (1 , 8 ):
95- return LATEST_VERSION
96- elif java_version >= (1 , 7 ):
97- return JAVA_7_COMPATIBLE_VERSION
98- elif java_version >= (1 , 6 ):
99- warn ('language_tool_python would be able to use a newer version of '
100- 'LanguageTool if you had Java 7 or newer installed' )
101- return JAVA_6_COMPATIBLE_VERSION
102- else :
103- raise SystemExit (
104- 'You need at least Java 6 to use language_tool_python' )
105-
80+ major_version , minor_version = parse_java_version (output )
81+ if major_version < 8 :
82+ raise SystemError (f'Detected java { major_version } .{ minor_version } . LanguageTool requires Java >= 8.' )
83+
84+ return True
10685
10786def get_common_prefix (z ):
10887 """Get common directory in a zip file if any."""
@@ -123,7 +102,8 @@ def download_lt(update=False):
123102 if old_path_list and not update :
124103 return
125104
126- version = get_newest_possible_languagetool_version ()
105+ confirm_java_compatibility ()
106+ version = LATEST_VERSION
127107 filename = FILENAME .format (version = version )
128108 url = urljoin (BASE_URL , filename )
129109 dirname = os .path .splitext (filename )[0 ]
0 commit comments