Just look for .properties
files:
def run(project_dir, main_class, specific_args):
classpath = []
for root, dirs, files in os.walk(project_dir):
classpath.extend(os.path.join(root, f) for f in files if f.endswith('.jar'))
if any(f.endswith('.properties') for f in files):
classpath.append(root)
classpath_augment = ':'.join(classpath)
print java_command, classpath_augment, main_class, specific_args
I took the liberty of simplifying your code somewhat; using a list to collect all classpath paths first, then use str.join()
to create a final string. This is faster than concatenating each new path one by one.
If you are using a very old Python version and any()
is not yet available, use a for
loop:
def run(project_dir, main_class, specific_args):
classpath = []
for root, dirs, files in os.walk(project_dir):
has_properties = False
for f in files:
if f.endswith('.jar'):
classpath.append(os.path.join(root, f))
if f.endswith('.properties'):
has_properties = True
if has_properties:
classpath.append(root)
classpath_augment = ':'.join(classpath)
print java_command, classpath_augment, main_class, specific_args