def fetch(repositories_list, download_dir, maven_exec='mvn', temp_dir='tmp'): """ fetch(repositories_list, download_dir, maven_exec='mvn') Downloads specified maven dependencies, along with their dependencies, to the specified download_dir. repositories_list - list of strings in gradle format 'groupId:artifactId:version' (eg 'info.picocli:picocli:4.1.4') download_dir - folder where to download the maven .jar files maven_exec - maven command to use for this operation (default = 'mvn') temp_dir - folder to use for temporarily created files, such as the pom.xml file (default = 'tmp') """ if (type(repositories_list) == str): repo_list = [repositories_list] else: repo_list = repositories_list if (len(repo_list) <= 0): # no deps, do nothing return pom_file = path.join(temp_dir, 'mock-pom.xml') util.make_parent_dir(pom_file) with open(pom_file, 'w') as pout: pout.write( '<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>project</groupId> <artifactId>dependency</artifactId> <version>list</version> \n<dependencies>\n' ) for lib_str in repositories_list: tokens = lib_str.strip().split(':') if (len(tokens) != 3): error( 'invalid maven dependency string "%s"\nmaven dependencies must be in format of "groupId:artifactId:version"' % lib_str) return False pout.write(' <dependency>') pout.write(' <groupId>%s</groupId>' % tokens[0]) pout.write(' <artifactId>%s</artifactId>' % tokens[1]) pout.write(' <version>%s</version>' % tokens[2]) pout.write(' </dependency>') pout.write('</dependencies> </project>') print() print('Fetching Maven dependencies:\n\t', end='') print('\n\t'.join(repositories_list)) util.shell_command([ maven_exec, '-f', str(path.abspath(pom_file)), 'dependency:copy-dependencies', '-DoutputDirectory=%s' % path.abspath(download_dir) ]) print('Maven fetch complete') print()
def install_jfx_jmods(download_url, target_os_arch): print('\tInstalling JavaFX jmods for platform %s ...' % target_os_arch) zip_file = path.join(config.temp_dir,'javafx-11-0-2-jmods-%s.zip' % target_os_arch) dest_dir = config.native_jmod_dep_dir.replace(config.this_os_arch, target_os_arch) util.make_parent_dir(zip_file) download_from_url(download_url, zip_file) unzip_file(zip_file, config.temp_dir) util.make_dir(dest_dir) util.copy_files( util.list_files_by_extension( path.join(config.temp_dir,'javafx-jmods-11.0.2'),'.jmod' ), dest_dir ) print('\t... Installation of %s JavaFX jmods complete.' % target_os_arch)
def _java_command(command, args_list, temp_dir): command_args = ' '.join(map(util.safe_quote_string, args_list)) print() print('+' + '-' * 78 + '+') print('| ' + str(path.basename(command)).upper() + ' ' * (76 - len(command)) + '|') print('+' + '-' * 78 + '+') print(command, command_args) print(' ' * 10 + '-' * 60 + ' ' * 10) args_file = path.join(temp_dir, str(path.basename(command)) + '-args.txt') util.make_parent_dir(args_file) with open(args_file, 'w') as fout: fout.write(command_args) util.shell_command([command, '@%s' % args_file]) print('\n%s success!\n' % path.basename(command))
def jlink_module(module_name, module_locations, output_dir, temp_dir, main_class=None, jlink_exec='jlink'): # modular jlink example: jlink --output deploy/windows --module-path jmods/windows:out --add-modules cchall.jmodtest util.make_dir(temp_dir) util.make_parent_dir(output_dir) if path.exists(output_dir): # jlink forbids using an already existing dir for some reason shutil.rmtree(output_dir) jlink_args = [] jlink_args += ['--output', output_dir] jlink_args += ['--module-path', module_name] jlink_args += ['--module-path', os.pathsep.join(module_locations)] jlink_args += ['--add-modules', module_name] if main_class != None: jlink_args += [ '--launcher', 'launch=%s/%s' % (module_name, main_class) ] _java_command(command=jlink_exec, args_list=jlink_args, temp_dir=temp_dir)
%s/* %s/* %s/* %s/* """ % (config.temp_dir, config.build_dir, config.run_dir, config.maven_dep_dir) ) prev_modules = [] for m in config.module_list: package_name = java.to_package_name(m) package_path = package_name.replace('.','/') if m == config.main_module: main_class_path = path.join(config.module_dir, m, config.sources_dirname,config.main_class.replace('.','/')+'.java' ) controller_class_path = path.join(config.module_dir, m, config.sources_dirname, package_path, 'MainViewController.java') fxml_resource = path.join(config.module_dir, m, config.resources_dirname, package_path, 'MainView.fxml') bundle_resource = path.join(config.module_dir, m, config.resources_dirname, package_path, 'language_en.properties') util.make_parent_dir(main_class_path) util.make_parent_dir(controller_class_path) util.make_parent_dir(bundle_resource) util.make_parent_dir(fxml_resource) with open(main_class_path, 'w') as fout: fout.write("""package %(package)s; public class %(class)s extends javafx.application.Application{ public static void main(String[] args){ System.out.println("Starting..."); launch(); System.out.println("...Finished!"); } @Override public void start(javafx.stage.Stage stage) throws Exception {
%s/* %s/* %s/* %s/* """ % (config.temp_dir, config.build_dir, config.run_dir, config.maven_dep_dir)) prev_modules = [] for m in config.module_list: package_name = java.to_package_name(m) package_path = package_name.replace('.', '/') if m == config.main_module: main_class_path = path.join( config.module_dir, m, config.sources_dirname, config.main_class.replace('.', '/') + '.java') util.make_parent_dir(main_class_path) with open(main_class_path, 'w') as fout: fout.write( """package %(package)s; public class %(class)s { public static void main(String[] args){ System.out.println("Starting..."); for(int i = 0; i < args.length; i++){ System.out.println(i+": "+args[i]); } System.out.println("...Done"); } }""" % { 'package': package_name, 'class': path.basename(main_class_path).replace( '.java', '')