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

Support for --module-path dependencies for compatibility with javafx 9+ #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions jgo/jgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def jgo_parser(log_levels = _default_log_levels):

parser = argparse.ArgumentParser(
description = 'Run Java main class from maven coordinates.',
usage = '%(prog)s [-v] [-u] [-U] [-m] [-q] [--log-level] [--ignore-jgorc] [--link-type type] [--additional-jars jar [jar ...]] [--additional-endpoints endpoint [endpoint ...]] [JVM_OPTIONS [JVM_OPTIONS ...]] <endpoint> [main-args]',
usage = '%(prog)s [-v] [-u] [-U] [-m] [-q] [--log-level] [--ignore-jgorc] [--link-type type] [--modules-dependencies dep [dep ..]] [--additional-jars jar [jar ...]] [--additional-endpoints endpoint [endpoint ...]] [JVM_OPTIONS [JVM_OPTIONS ...]] <endpoint> [main-args]',
epilog = epilog,
formatter_class = argparse.RawTextHelpFormatter
)
Expand All @@ -267,6 +267,7 @@ def jgo_parser(log_levels = _default_log_levels):
parser.add_argument('-r', '--repository', nargs='+', help='Add additional maven repository (key=url format)', default=[], required=False)
parser.add_argument('-a', '--additional-jars', nargs='+', help='Add additional jars to classpath', default=[], required=False)
parser.add_argument('-q', '--quiet', action='store_true', required=False, help='Suppress jgo output, including logging')
parser.add_argument('--module-dependencies', nargs='+', help='Specify which dependencies should be treated as modules (of the form "group:artifact:version[:classifier]', default=[], required=False)
parser.add_argument( '--additional-endpoints', nargs='+', help='Add additional endpoints', default=[], required=False)
parser.add_argument('--ignore-jgorc', action='store_true', help='Ignore ~/.jgorc')
parser.add_argument('--link-type', default=None, type=str, help='How to link from local maven repository into jgo cache. Defaults to the `links\' setting in ~/.jgorc or \'auto\' if not specified.', choices=('hard', 'soft', 'copy', 'auto'))
Expand Down Expand Up @@ -396,6 +397,7 @@ def resolve_dependencies(
manage_dependencies=False,
repositories={},
shortcuts={},
modules_deps=[],
verbose=0):


Expand All @@ -406,6 +408,7 @@ def resolve_dependencies(
repo_str = ''.join('<repository><id>{rid}</id><url>{url}</url></repository>'.format(rid=k, url=v) for (k, v) in repositories.items())
coordinates = coordinates_from_endpoints(endpoints)
workspace = workspace_dir_from_coordinates(coordinates, cache_dir=cache_dir)
module_dir = os.path.join(workspace, "modules")
build_success_file = os.path.join(workspace, 'buildSuccess')

update_cache = True if force_update else update_cache
Expand All @@ -424,6 +427,7 @@ def resolve_dependencies(
shutil.rmtree(workspace, True)

os.makedirs(workspace, exist_ok=True)
os.makedirs(module_dir, exist_ok=True)

# TODO should this be for all endpoints or only the primary endpoint?
if manage_dependencies:
Expand Down Expand Up @@ -480,7 +484,7 @@ def resolve_dependencies(


info_regex = re.compile('^.*\\[[A-Z]+\\] *')
relevant_jars = []
modules_discovered = set()
for l in str(mvn_out).split('\\n'):
# TODO: the compile|runtime|provided matches might fail if an artifactId starts with accordingly
# TODO: If that ever turns out to be an issue, it is going to be necessary to update these checks
Expand All @@ -507,13 +511,24 @@ def resolve_dependencies(
jar_file = '{}.{}'.format(artifact_name, extension)
jar_file_in_workspace = os.path.join(workspace, jar_file)

relevant_jars.append(jar_file_in_workspace)

try:
link(os.path.join(m2_repo, *g.split('.'), a, version, jar_file), jar_file_in_workspace, link_type=link_type)
dependency_identifier = ':'.join((g, a, version, c) if c else (g, a, version))
if dependency_identifier in modules_deps:
jar_file_in_module_dir = os.path.join(module_dir, jar_file)
link(os.path.join(m2_repo, *g.split('.'), a, version, jar_file), jar_file_in_module_dir, link_type=link_type)
modules_discovered.add(dependency_identifier)
else:
jar_file_in_workspace = os.path.join(workspace, jar_file)
link(os.path.join(m2_repo, *g.split('.'), a, version, jar_file), jar_file_in_workspace, link_type=link_type)
except FileExistsError as e:
# Do not throw exceptionif target file exists.
pass
module_set = set(modules_deps)
if len(module_set) != len(modules_discovered):
missing_mods = '\n'.join(x for x in module_set - modules_discovered)
_logger.info("Missing Modules:\n{}".format(missing_mods))
raise Exception("Could not discover all module dependencies")
pathlib.Path(build_success_file).touch(exist_ok=True)
return primary_endpoint, workspace

Expand Down Expand Up @@ -579,7 +594,13 @@ def run(parser, argv=sys.argv[1:], stdout=None, stderr=None):
repositories = repositories,
shortcuts = shortcuts,
verbose = args.verbose,
link_type = link_type)
link_type = link_type,
modules_deps=args.module_dependencies)

if len(args.module_dependencies) > 0:
jvm_args.append("--module-path")
jvm_args.append(os.path.join(workspace, "modules"))


main_class_file = os.path.join(workspace, primary_endpoint.main_class) if primary_endpoint.main_class else os.path.join(workspace, 'mainClass')
try:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_parsington.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ def test_resolve_auto(self):
finally:
shutil.rmtree(tmp_dir)

def test_resolve_as_module(self):
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir')
m2_repo = os.path.join(str(pathlib.Path.home()), '.m2', 'repository')
try:
_, workspace = jgo.resolve_dependencies(
PARSINGTON_ENDPOINT,
m2_repo=m2_repo,
cache_dir=tmp_dir,
link_type='auto',
modules_deps=[PARSINGTON_ENDPOINT]
)
jars = glob.glob(os.path.join(workspace, '*jar'))
self.assertEqual(len(jars), 0, 'Expected zero jars in workspace')
modules = glob.glob(os.path.join(workspace, "modules", '*jar'))
self.assertEqual(len(modules), 1, 'Expected one jar in the module directory')
self.assertEqual(modules[0], os.path.join(workspace, "modules", 'parsington-%s.jar' % PARSINGTON_VERSION), 'Expected parsington jar')
finally:
shutil.rmtree(tmp_dir)

def test_run_jgo(self):
tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir')

Expand Down