108 private String short_description;
109
110 /** Default short description of the package */
111 private static String default_short_description = "Generated by jpkg";
112
113 /** Long description of the package */
114 private String long_description;
115
116 /** Default long description of the package */
117 private static String default_long_description
118 = " This package was automatically generated from the corresponding Jigsaw module.\n"
119 + " Information on Jigsaw is available at http://openjdk.java.net/projects/jigsaw.";
120
121 /** Packaging-system dependent additional metadata */
122 private File extra_metadata;
123
124 private File natlibs;
125 private File natcmds;
126 private File config_dir;
127
128 // Installed size
129 private Integer installedSize = null;
130
131 // Platform boot module
132 private static final String BOOT_MODULE = "jdk.base";
133
134 private static void createTempWorkDir()
135 throws Command.Exception
136 {
137 try {
138 tmp_dst = File.createTempFile("jigsaw",null);
139 Files.delete(tmp_dst);
140 Files.mkdirs(tmp_dst, "jigsaw temp directory");
141 }
142 catch (IOException x) {
143 throw new Command.Exception(x);
144 }
145 }
146
147
153 ModuleInfo info = getModuleInfo(mf);
154 return info.id().version().toString();
155 }
156
157 protected void go(SimpleLibrary lib)
158 throws Command.Exception
159 {
160 while (hasArg()) {
161 File outputfile = null;
162 try {
163 String modulename = takeArg();
164 String version = getModuleVersion(modulename);
165 String outputfilename = modulename + '@'+ version + ".jmod";
166 if (verbose)
167 System.out.println("Creating module file "
168 + outputfilename + " for "
169 + modulename);
170 outputfile = new File(destination, outputfilename);
171 ModuleFileWriter writer
172 = new ModuleFileWriter(outputfile, (fast || jigsawDevMode));
173 writer.writeModule(classes, natlibs, natcmds, config_dir);
174 }
175 catch (IOException x) {
176 if (outputfile != null && !outputfile.delete()) {
177 Throwable t
178 = new IOException(outputfile +
179 ": Cannot delete").initCause(x);
180 throw new Command.Exception((IOException)t);
181 }
182 throw new Command.Exception(x);
183 }
184 }
185 finishArgs();
186 }
187 }
188
189 static private ModuleInfo getModuleInfo(Manifest mf)
190 throws Command.Exception
191 {
192 try {
193 final String MINFO_CLASS = "module-info.class";
311 * package version is module's version
312 * package dependecies are module's required dependencies
313 *
314 * @param manifest The module's manifest
315 */
316 private void writeMetaData(Manifest manifest)
317 throws Command.Exception
318 {
319 boolean bootmodule = BOOT_MODULE.equals(manifest.module());
320 createMetaDataDir();
321 ModuleInfo info = getModuleInfo(manifest);
322
323 // Create the control file, and fill in dependency and provides info
324 try (PrintStream control
325 = new PrintStream(new File(tmp_metadata_dst, "control"))) {
326 control.format("Package: %s%n"
327 + "Version: %s%n"
328 + "Section: misc%n"
329 + "Priority: optional%n"
330 + "Architecture: "
331 + System.getProperty("os.arch") + "%n",
332 info.id().name(),
333 translateVersion(info.id().version().toString()));
334
335 // If either maintainer name or e-mail is declared as parameter, use it
336 if (null != maintainer_name || null != maintainer_email) {
337 control.format("Maintainer: %s %s%n",
338 maintainer_name == null? default_maintainer_name : maintainer_name,
339 maintainer_email == null? default_maintainer_email : maintainer_email);
340 }
341 // Otherwise, if there is no extra metadata, use defaults
342 else if (null == extra_metadata) {
343 control.format("Maintainer: %s %s%n",
344 default_maintainer_name,
345 default_maintainer_email);
346 }
347
348 // If either short or long description is declared as parameter, use it
349 if (null != short_description || null != long_description) {
350 control.format("Description: %s%n"
351 + "%s%n",
574 if (verbose)
575 System.out.println("Creating binary Debian package for " + manifest.module());
576
577 createTempWorkDir();
578 if (null != includes) {
579 try {
580 Files.copyTree(includes, tmp_dst);
581 } catch (IOException x) {
582 throw new Command.Exception(x);
583 }
584 }
585 preinstallModule(manifest);
586 packModule(manifest);
587 writeMetaData(manifest);
588 buildPackage();
589 cleanup();
590 }
591 }
592 }
593
594 private static Map<String,Class<? extends Command<SimpleLibrary>>> commands
595 = new HashMap<>();
596
597 static {
598 commands.put("deb", Deb.class);
599 commands.put("jmod", Jmod.class);
600 }
601
602 private OptionParser parser;
603
604 private static OptionSpec<File> resourcePath; // ##
605
606 private void usage() {
607 out.format("%n");
608 out.format("usage: jpkg [-v] [-L <library>] [-r <resource-dir>] [-i <include-dir>] [-m <module-dir>] [-d <output-dir>] [-c <command>] [-n <name>] [-e <e-mail@address>] [-s <short description>] [-l <long description>] [-x <extra metadata>] [deb|jmod] <module-name>%n");
609 out.format("%n");
610 try {
611 parser.printHelpOn(out);
612 } catch (IOException x) {
613 throw new AssertionError(x);
614 }
719 .describedAs("dir")
720 .ofType(File.class));
721
722 OptionSpec<File> nativeLibs
723 = (parser.accepts("natlib", "Directory with native libs")
724 .withRequiredArg()
725 .describedAs("dir")
726 .ofType(File.class));
727
728 OptionSpec<File> nativeCmds
729 = (parser.accepts("natcmd", "Directory with native launchers")
730 .withRequiredArg()
731 .describedAs("dir")
732 .ofType(File.class));
733
734 OptionSpec<File> config
735 = (parser.accepts("config", "Directory with configuration")
736 .withRequiredArg()
737 .describedAs("dir")
738 .ofType(File.class));
739
740 if (args.length == 0) {
741 usage();
742 return;
743 }
744
745 OptionSet opts = parser.parse(args);
746 if (opts.has("h")) {
747 usage();
748 return;
749 }
750 if (opts.has("v"))
751 verbose = true;
752 if (opts.has("fast"))
753 fast = true;
754 List<String> words = opts.nonOptionArguments();
755 if (words.isEmpty()) {
756 usage();
757 return;
758 }
790 + (maintainer_email.endsWith(">") ? "" : ">") ;
791 }
792 if (opts.has(shortDescription))
793 short_description = opts.valueOf(shortDescription);
794 if (opts.has(longDescription))
795 long_description = opts.valueOf(longDescription);
796 if (opts.has(extraMetadata))
797 extra_metadata = opts.valueOf(extraMetadata);
798 if (opts.has(nativeLibs)) {
799 natlibs = opts.valueOf(nativeLibs);
800 checkPathArgument(natlibs, "Native library");
801 }
802 if (opts.has(nativeCmds)) {
803 natcmds = opts.valueOf(nativeCmds);
804 checkPathArgument(natcmds, "Native command");
805 }
806 if (opts.has(config)) {
807 config_dir = opts.valueOf(config);
808 checkPathArgument(config_dir, "Config");
809 }
810 if (opts.has(isize))
811 installedSize = opts.valueOf(isize);
812
813 if (cmd == Deb.class)
814 (new Deb()).run(null, opts);
815 else if (cmd == Jmod.class)
816 (new Jmod()).run(null, opts);
817 }
818
819 /**
820 * Helper method to check if a path exists before using it further.
821 *
822 * @param path to check
823 * @param type of path being checked
824 *
825 * @throws Command.Exception if path doesn't exist
826 */
827 private static final void checkIfPathExists(File path, String type)
828 throws Command.Exception {
829
830 if (!path.exists())
831 throw new Command.Exception("%s path doesn't exist: %s",
832 type, path);
833 }
834
835 /**
836 * Helper method to check if a path is readable before using it further.
837 *
838 * @param path to check
839 * @param type of path being checked
840 *
841 * @throws Command.Exception if path isn't readable
842 */
843 private static final void checkIfPathIsReadable(File path, String type)
844 throws Command.Exception {
845
846 if (!path.canRead())
847 throw new Command.Exception("%s path isn't readable: %s",
848 type, path);
849 }
850
851 /**
852 * Helper method to check if a path is a directory before using it further.
853 *
854 * @param path to check
855 * @param type of path being checked
856 *
857 * @throws Command.Exception if path is not a directory
858 */
859 private static final void checkIfPathIsDirectory(File path, String type)
860 throws Command.Exception {
861
862 if (!path.isDirectory())
863 throw new Command.Exception("%s path is not a directory: %s",
864 type, path);
865 }
866
867 /**
868 * Helper method to check if a path argument is valid.
869 *
870 * @param path to check
871 * @param type of path being checked
872 *
873 * @throws Command.Exception if path is not a directory
874 */
875 private static final void checkPathArgument(File path, String type)
876 throws Command.Exception {
877
878 checkIfPathExists(path, type);
879 checkIfPathIsReadable(path, type);
880 checkIfPathIsDirectory(path, type);
881 }
882
883 private Packager() { }
884
885 public static void main(String[] args) throws Exception {
886 try {
887 run(args);
888 } catch (OptionException x) {
889 err.println(x.getMessage());
890 System.exit(1);
891 } catch (Command.Exception x) {
892 err.println(x.getMessage());
893 x.printStackTrace();
894 System.exit(1);
895 }
896 }
897
|
108 private String short_description;
109
110 /** Default short description of the package */
111 private static String default_short_description = "Generated by jpkg";
112
113 /** Long description of the package */
114 private String long_description;
115
116 /** Default long description of the package */
117 private static String default_long_description
118 = " This package was automatically generated from the corresponding Jigsaw module.\n"
119 + " Information on Jigsaw is available at http://openjdk.java.net/projects/jigsaw.";
120
121 /** Packaging-system dependent additional metadata */
122 private File extra_metadata;
123
124 private File natlibs;
125 private File natcmds;
126 private File config_dir;
127
128 // default architecture is any
129 private ModuleArchitecture modArch = ModuleArchitecture.ANY;
130
131 // Installed size
132 private Integer installedSize = null;
133
134 // Platform boot module
135 private static final String BOOT_MODULE = "jdk.base";
136
137 private static void createTempWorkDir()
138 throws Command.Exception
139 {
140 try {
141 tmp_dst = File.createTempFile("jigsaw",null);
142 Files.delete(tmp_dst);
143 Files.mkdirs(tmp_dst, "jigsaw temp directory");
144 }
145 catch (IOException x) {
146 throw new Command.Exception(x);
147 }
148 }
149
150
156 ModuleInfo info = getModuleInfo(mf);
157 return info.id().version().toString();
158 }
159
160 protected void go(SimpleLibrary lib)
161 throws Command.Exception
162 {
163 while (hasArg()) {
164 File outputfile = null;
165 try {
166 String modulename = takeArg();
167 String version = getModuleVersion(modulename);
168 String outputfilename = modulename + '@'+ version + ".jmod";
169 if (verbose)
170 System.out.println("Creating module file "
171 + outputfilename + " for "
172 + modulename);
173 outputfile = new File(destination, outputfilename);
174 ModuleFileWriter writer
175 = new ModuleFileWriter(outputfile, (fast || jigsawDevMode));
176 writer.writeModule(classes, natlibs, natcmds, config_dir, modArch);
177 }
178 catch (IOException x) {
179 if (outputfile != null && !outputfile.delete()) {
180 Throwable t
181 = new IOException(outputfile +
182 ": Cannot delete").initCause(x);
183 throw new Command.Exception((IOException)t);
184 }
185 throw new Command.Exception(x);
186 }
187 }
188 finishArgs();
189 }
190 }
191
192 static private ModuleInfo getModuleInfo(Manifest mf)
193 throws Command.Exception
194 {
195 try {
196 final String MINFO_CLASS = "module-info.class";
314 * package version is module's version
315 * package dependecies are module's required dependencies
316 *
317 * @param manifest The module's manifest
318 */
319 private void writeMetaData(Manifest manifest)
320 throws Command.Exception
321 {
322 boolean bootmodule = BOOT_MODULE.equals(manifest.module());
323 createMetaDataDir();
324 ModuleInfo info = getModuleInfo(manifest);
325
326 // Create the control file, and fill in dependency and provides info
327 try (PrintStream control
328 = new PrintStream(new File(tmp_metadata_dst, "control"))) {
329 control.format("Package: %s%n"
330 + "Version: %s%n"
331 + "Section: misc%n"
332 + "Priority: optional%n"
333 + "Architecture: "
334 + System.getProperty("os.arch") + "%n", // ## update to use archOpt
335 info.id().name(),
336 translateVersion(info.id().version().toString()));
337
338 // If either maintainer name or e-mail is declared as parameter, use it
339 if (null != maintainer_name || null != maintainer_email) {
340 control.format("Maintainer: %s %s%n",
341 maintainer_name == null? default_maintainer_name : maintainer_name,
342 maintainer_email == null? default_maintainer_email : maintainer_email);
343 }
344 // Otherwise, if there is no extra metadata, use defaults
345 else if (null == extra_metadata) {
346 control.format("Maintainer: %s %s%n",
347 default_maintainer_name,
348 default_maintainer_email);
349 }
350
351 // If either short or long description is declared as parameter, use it
352 if (null != short_description || null != long_description) {
353 control.format("Description: %s%n"
354 + "%s%n",
577 if (verbose)
578 System.out.println("Creating binary Debian package for " + manifest.module());
579
580 createTempWorkDir();
581 if (null != includes) {
582 try {
583 Files.copyTree(includes, tmp_dst);
584 } catch (IOException x) {
585 throw new Command.Exception(x);
586 }
587 }
588 preinstallModule(manifest);
589 packModule(manifest);
590 writeMetaData(manifest);
591 buildPackage();
592 cleanup();
593 }
594 }
595 }
596
597 private static final Map<String,Class<? extends Command<SimpleLibrary>>> commands
598 = new HashMap<>();
599
600 static {
601 commands.put("deb", Deb.class);
602 commands.put("jmod", Jmod.class);
603 }
604
605 private OptionParser parser;
606
607 private static OptionSpec<File> resourcePath; // ##
608
609 private void usage() {
610 out.format("%n");
611 out.format("usage: jpkg [-v] [-L <library>] [-r <resource-dir>] [-i <include-dir>] [-m <module-dir>] [-d <output-dir>] [-c <command>] [-n <name>] [-e <e-mail@address>] [-s <short description>] [-l <long description>] [-x <extra metadata>] [deb|jmod] <module-name>%n");
612 out.format("%n");
613 try {
614 parser.printHelpOn(out);
615 } catch (IOException x) {
616 throw new AssertionError(x);
617 }
722 .describedAs("dir")
723 .ofType(File.class));
724
725 OptionSpec<File> nativeLibs
726 = (parser.accepts("natlib", "Directory with native libs")
727 .withRequiredArg()
728 .describedAs("dir")
729 .ofType(File.class));
730
731 OptionSpec<File> nativeCmds
732 = (parser.accepts("natcmd", "Directory with native launchers")
733 .withRequiredArg()
734 .describedAs("dir")
735 .ofType(File.class));
736
737 OptionSpec<File> config
738 = (parser.accepts("config", "Directory with configuration")
739 .withRequiredArg()
740 .describedAs("dir")
741 .ofType(File.class));
742 OptionSpec<String> osOpt
743 = (parser.accepts("os", "Target Operating System of the module")
744 .withRequiredArg()
745 .describedAs("os")
746 .ofType(String.class));
747 OptionSpec<String> archOpt
748 = (parser.accepts("arch", "Target Architecture of the module")
749 .withRequiredArg()
750 .describedAs("arch")
751 .ofType(String.class));
752
753 if (args.length == 0) {
754 usage();
755 return;
756 }
757
758 OptionSet opts = parser.parse(args);
759 if (opts.has("h")) {
760 usage();
761 return;
762 }
763 if (opts.has("v"))
764 verbose = true;
765 if (opts.has("fast"))
766 fast = true;
767 List<String> words = opts.nonOptionArguments();
768 if (words.isEmpty()) {
769 usage();
770 return;
771 }
803 + (maintainer_email.endsWith(">") ? "" : ">") ;
804 }
805 if (opts.has(shortDescription))
806 short_description = opts.valueOf(shortDescription);
807 if (opts.has(longDescription))
808 long_description = opts.valueOf(longDescription);
809 if (opts.has(extraMetadata))
810 extra_metadata = opts.valueOf(extraMetadata);
811 if (opts.has(nativeLibs)) {
812 natlibs = opts.valueOf(nativeLibs);
813 checkPathArgument(natlibs, "Native library");
814 }
815 if (opts.has(nativeCmds)) {
816 natcmds = opts.valueOf(nativeCmds);
817 checkPathArgument(natcmds, "Native command");
818 }
819 if (opts.has(config)) {
820 config_dir = opts.valueOf(config);
821 checkPathArgument(config_dir, "Config");
822 }
823 modArch = ModuleArchitecture.create(opts.valueOf(osOpt),
824 opts.valueOf(archOpt));
825 if (opts.has(isize))
826 installedSize = opts.valueOf(isize);
827
828 if (cmd == Deb.class)
829 (new Deb()).run(null, opts);
830 else if (cmd == Jmod.class)
831 (new Jmod()).run(null, opts);
832 }
833
834 /**
835 * Helper method to check if a path exists before using it further.
836 *
837 * @param path to check
838 * @param type of path being checked
839 *
840 * @throws Command.Exception if path doesn't exist
841 */
842 private static void checkIfPathExists(File path, String type)
843 throws Command.Exception
844 {
845 if (!path.exists())
846 throw new Command.Exception("%s path doesn't exist: %s",
847 type, path);
848 }
849
850 /**
851 * Helper method to check if a path is readable before using it further.
852 *
853 * @param path to check
854 * @param type of path being checked
855 *
856 * @throws Command.Exception if path isn't readable
857 */
858 private static void checkIfPathIsReadable(File path, String type)
859 throws Command.Exception
860 {
861 if (!path.canRead())
862 throw new Command.Exception("%s path isn't readable: %s",
863 type, path);
864 }
865
866 /**
867 * Helper method to check if a path is a directory before using it further.
868 *
869 * @param path to check
870 * @param type of path being checked
871 *
872 * @throws Command.Exception if path is not a directory
873 */
874 private static void checkIfPathIsDirectory(File path, String type)
875 throws Command.Exception
876 {
877 if (!path.isDirectory())
878 throw new Command.Exception("%s path is not a directory: %s",
879 type, path);
880 }
881
882 /**
883 * Helper method to check if a path argument is valid.
884 *
885 * @param path to check
886 * @param type of path being checked
887 *
888 * @throws Command.Exception if path is not a directory
889 */
890 private static void checkPathArgument(File path, String type)
891 throws Command.Exception
892 {
893 checkIfPathExists(path, type);
894 checkIfPathIsReadable(path, type);
895 checkIfPathIsDirectory(path, type);
896 }
897
898 private Packager() { }
899
900 public static void main(String[] args) throws Exception {
901 try {
902 run(args);
903 } catch (OptionException x) {
904 err.println(x.getMessage());
905 System.exit(1);
906 } catch (Command.Exception x) {
907 err.println(x.getMessage());
908 x.printStackTrace();
909 System.exit(1);
910 }
911 }
912
|