Skip to content

Add buildSuccess file to avoid over-zealous cache updates #54

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

Merged
merged 3 commits into from
Aug 28, 2019
Merged
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
11 changes: 8 additions & 3 deletions jgo/jgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def coordinates_from_endpoints(endpoints):
return [ep.get_coordinates() for ep in endpoints]

def workspace_dir_from_coordinates(coordinates, cache_dir):
workspace = os.path.join(cache_dir, *(coordinates[0][0].split('.') + coordinates[0][1:]))
workspace = os.path.join(cache_dir, *coordinates[0])
workspace = '+'.join([workspace] + ['-'.join(c) for c in coordinates[1:]])
return workspace

Expand Down Expand Up @@ -406,11 +406,12 @@ 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)
build_success_file = os.path.join(workspace, 'buildSuccess')

update_cache = True if force_update else update_cache
update_cache = update_cache \
or not os.path.isdir(workspace) \
or os.path.isdir(workspace) and not os.path.isfile(os.path.join(workspace, 'mainClass'))
or not os.path.isfile(build_success_file)

if not update_cache:
return primary_endpoint, workspace
Expand Down Expand Up @@ -513,6 +514,7 @@ def resolve_dependencies(
except FileExistsError as e:
# Do not throw exceptionif target file exists.
pass
pathlib.Path(build_success_file).touch(exist_ok=True)
return primary_endpoint, workspace


Expand Down Expand Up @@ -579,15 +581,17 @@ def run(parser, argv=sys.argv[1:], stdout=None, stderr=None):
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')
main_class_file = os.path.join(workspace, primary_endpoint.main_class) if primary_endpoint.main_class else os.path.join(workspace, 'mainClass')
try:
with open(main_class_file, 'r') as f:
main_class = f.readline()
return launch_java(workspace, jvm_args, main_class, *program_args, additional_jars=args.additional_jars, stdout=stdout, stderr=stderr, check=False)
except FileNotFoundError:
pass


if not primary_endpoint.main_class:
_logger.info('Inferring main class from jar manifest')
jar_path = glob.glob(os.path.join(workspace, primary_endpoint.jar_name()).replace(Endpoint.VERSION_RELEASE, '*').replace(Endpoint.VERSION_LATEST, '*'))[0]
with zipfile.ZipFile(jar_path) as jar_file:
with jar_file.open('META-INF/MANIFEST.MF') as manifest:
Expand All @@ -600,6 +604,7 @@ def run(parser, argv=sys.argv[1:], stdout=None, stderr=None):
break
if not main_class:
raise NoMainClassInManifest(jar_path)
_logger.info('Inferred main class: %s', main_class)
else:
main_class = primary_endpoint.main_class

Expand Down