From faea3695abd79fda12a1c110f49c310e2c9a2c34 Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Tue, 27 Nov 2018 17:27:42 -0500 Subject: [PATCH 1/3] Respect link type in Python jgo Fixes #24 --- jgo/jgo.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jgo/jgo.py b/jgo/jgo.py index 2f7cdfa..7cd1ce5 100644 --- a/jgo/jgo.py +++ b/jgo/jgo.py @@ -344,6 +344,7 @@ def resolve_dependencies( endpoint_string, cache_dir, m2_repo, + link_type='hard', update_cache=False, force_update=False, manage_dependencies=False, @@ -457,7 +458,7 @@ def resolve_dependencies( 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(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 @@ -493,6 +494,7 @@ def run(parser, argv=sys.argv[1:]): cache_dir = settings.get('cacheDir') m2_repo = settings.get('m2Repo') + link_type = settings.get('links') for repository in args.repository: repositories[repository.split('=')[0]] = repository.split('=')[1] @@ -514,7 +516,8 @@ def run(parser, argv=sys.argv[1:]): manage_dependencies = args.manage_dependencies, repositories = repositories, shortcuts = shortcuts, - verbose = args.verbose) + verbose = args.verbose, + link_type = link_type) main_class_file = os.path.join(workspace, primary_endpoint.main_class, 'mainClass') if primary_endpoint.main_class else os.path.join(workspace, 'mainClass') From 944f61c3b5820a331b12a087c747de1d3d965e16 Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Tue, 27 Nov 2018 17:40:15 -0500 Subject: [PATCH 2/3] Add --link-type command line argument to Python jgo Fixes #25 --- jgo/jgo.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jgo/jgo.py b/jgo/jgo.py index 7cd1ce5..e3c9a95 100644 --- a/jgo/jgo.py +++ b/jgo/jgo.py @@ -213,7 +213,7 @@ def jgo_main(argv=sys.argv[1:]): parser = argparse.ArgumentParser( description = 'Run Java main class from maven coordinates.', - usage = '%(prog)s [-v] [-u] [-U] [-m] [--ignore-jgorc] [--additional-jars jar [jar ...]] [--additional-endpoints endpoint [endpoint ...]] [JVM_OPTIONS [JVM_OPTIONS ...]] [main-args]', + usage = '%(prog)s [-v] [-u] [-U] [-m] [--ignore-jgorc] [--link-type type] [--additional-jars jar [jar ...]] [--additional-endpoints endpoint [endpoint ...]] [JVM_OPTIONS [JVM_OPTIONS ...]] [main-args]', epilog = epilog, formatter_class = argparse.RawTextHelpFormatter ) @@ -225,6 +225,7 @@ def jgo_main(argv=sys.argv[1:]): parser.add_argument('-a', '--additional-jars', nargs='+', help='Add additional jars to classpath', 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 ~/.jrunrc or \'hard\' if not specified.', choices=('hard', 'soft', 'copy')) try: @@ -492,6 +493,9 @@ def run(parser, argv=sys.argv[1:]): if args.verbose > 0: _logger.setLevel(logging.DEBUG) + if args.link_type is not None: + config.set('settings', 'links', args.link_type) + cache_dir = settings.get('cacheDir') m2_repo = settings.get('m2Repo') link_type = settings.get('links') From cc05988f0c9b2da5a25140b726660f1e91459991 Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Tue, 27 Nov 2018 17:54:49 -0500 Subject: [PATCH 3/3] Add `auto' linking option to Python jgo Fixes #22 --- jgo/jgo.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/jgo/jgo.py b/jgo/jgo.py index e3c9a95..52e1ee1 100644 --- a/jgo/jgo.py +++ b/jgo/jgo.py @@ -146,13 +146,30 @@ def executable_path_or_raise(tool): def executable_path(tool): return shutil.which(tool) -def link(source, link_name, link_type="hard"): - if link_type.lower() == "soft": - os.symlink(source, link_name) - elif link_type.lower() == "hard": - os.link(source, link_name) - else: - shutil.copyfile(source, link_name) +def link(source, link_name, link_type='auto'): + _logger.debug("Linking source %s to target %s with link_type %s", source, link_name, link_type) + if link_type.lower() == 'soft': + return os.symlink(source, link_name) + elif link_type.lower() == 'hard': + return os.link(source, link_name) + elif link_type.lower() == 'copy': + return shutil.copyfile(source, link_name) + elif link_type.lower() == 'auto': + try: + return link(source=source, link_name=link_name, link_type='hard') + except OSError as e: + if e.errno != 18: + raise e + try: + return link(source=source, link_name=link_name, link_type='soft') + except OSError as e: + pass + + return link(source=source, link_name=link_name, link_type='copy') + + raise Exception('Unable to link source {} to target {} with link_type {}', source, link_name, link_type) + + def m2_path(): return os.getenv("M2_REPO", (pathlib.Path.home() / '.m2').absolute()) @@ -225,7 +242,7 @@ def jgo_main(argv=sys.argv[1:]): parser.add_argument('-a', '--additional-jars', nargs='+', help='Add additional jars to classpath', 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 ~/.jrunrc or \'hard\' if not specified.', choices=('hard', 'soft', 'copy')) + 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 ~/.jrunrc or \'auto\' if not specified.', choices=('hard', 'soft', 'copy', 'auto')) try: @@ -271,7 +288,7 @@ def default_config(): config.add_section('settings') config.set('settings', 'm2Repo', os.path.join(str(pathlib.Path.home()), '.m2', 'repository')) config.set('settings', 'cacheDir', os.path.join(str(pathlib.Path.home()), '.jgo')) - config.set('settings', 'links', 'hard') + config.set('settings', 'links', 'auto') # repositories config.add_section('repositories') @@ -345,7 +362,7 @@ def resolve_dependencies( endpoint_string, cache_dir, m2_repo, - link_type='hard', + link_type='auto', update_cache=False, force_update=False, manage_dependencies=False,