diff --git a/.gitignore b/.gitignore index 086645cbf..7fde9493a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store .AppleDouble +*.iml ._* *~ /build/shared/reference.zip diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..f95b306dc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +git: + depth: 1 + +language: java + +jdk: + - openjdk11 + +before_install: + - sudo apt-get -qq update + - sudo apt-get install ant-optional + - sudo apt-get install wget + - wget --no-check-certificate https://www-us.apache.org/dist//ant/binaries/apache-ant-1.10.7-bin.tar.gz + - tar -xzvf apache-ant-1.10.7-bin.tar.gz + - export PATH=`pwd`/apache-ant-1.10.7/bin:$PATH + +services: + - xvfb + +before_script: + - export DISPLAY=:99.0 + - cd build + +script: + - ant clean + - ant build diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..13bec8dfd --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,1009 @@ +Introduction +==================================================================================================== +We use GPL v2 for the parts of the project that we've developed ourselves. +For the 'core' library, it's LGPL, for everything else, it's GPL. + +Over the course of many years of development, files being moved around, +and other code being added and removed, the license information has become +quite a mess. Please help us clean this up so that others are properly +credited and licenses are consistently/correctly noted: +https://github.com/processing/processing/issues/224 + +
+
+ + +GNU GPL License +---------------------------------------------------------------------------------------------------- +License for processing outside of core: + +``` + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. +``` + +
+
+ +GNU LGPL License +---------------------------------------------------------------------------------------------------- +License for core: + +``` +GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +[ This is the first released version of the Lesser GPL. +It also counts as the successor of the GNU Library Public +License, version 2, hence the version number 2.1. ] + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + +To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + +Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + +When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + +We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + +For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + +Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + +You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + +2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) The modified work must itself be a software library. + +b) You must cause the files modified to carry prominent notices +stating that you changed the files and the date of any change. + +c) You must cause the whole of the work to be licensed at no +charge to all third parties under the terms of this License. + +d) If a facility in the modified Library refers to a function or a +table of data to be supplied by an application program that uses +the facility, other than as an argument passed when the facility +is invoked, then you must make a good faith effort to ensure that, +in the event an application does not supply such function or +table, the facility still operates, and performs whatever part of +its purpose remains meaningful. + +(For example, a function in a library to compute square roots has +a purpose that is entirely well-defined independent of the +application. Therefore, Subsection 2d requires that any +application-supplied function or table used by this function must +be optional: if the application does not supply it, the square +root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + +Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + +a) Accompany the work with the complete corresponding +machine-readable source code for the Library including whatever +changes were used in the work (which must be distributed under +Sections 1 and 2 above); and, if the work is an executable linked +with the Library, with the complete machine-readable "work that +uses the Library", as object code and/or source code, so that the +user can modify the Library and then relink to produce a modified +executable containing the modified Library. (It is understood +that the user who changes the contents of definitions files in the +Library will not necessarily be able to recompile the application +to use the modified definitions.) + +b) Use a suitable shared library mechanism for linking with the +Library. A suitable mechanism is one that (1) uses at run time a +copy of the library already present on the user's computer system, +rather than copying library functions into the executable, and (2) +will operate properly with a modified version of the library, if +the user installs one, as long as the modified version is +interface-compatible with the version that the work was made with. + +c) Accompany the work with a written offer, valid for at +least three years, to give the same user the materials +specified in Subsection 6a, above, for a charge no more +than the cost of performing this distribution. + +d) If distribution of the work is made by offering access to copy +from a designated place, offer equivalent access to copy the above +specified materials from the same place. + +e) Verify that the user has already received a copy of these +materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + +It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + +7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + +a) Accompany the combined library with a copy of the same work +based on the Library, uncombined with any other library +facilities. This must be distributed under the terms of the +Sections above. + +b) Give prominent notice with the combined library of the fact +that part of it is a work based on the Library, and explaining +where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + +11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. +``` + +
+
+ +Third Party Open Source Software Used +---------------------------------------------------------------------------------------------------- + - [Ant](https://ant.apache.org) by [The Apache Software Foundation](https://www.apache.org) under the [Apache v2 License](https://www.apache.org/licenses/LICENSE-2.0). + - [Ant-contrib](http://ant-contrib.sourceforge.net) by the Ant-Contrib Project under the [Apache 1.1 License](https://sourceforge.net/p/ant-contrib/code/HEAD/tree/ant-contrib/trunk/docs/LICENSE.txt). + - [Antlr 2](https://www.antlr2.org) under [Public Domain](https://www.antlr2.org/license.html). + - Processing has a modified copy of appbundler under. It is is a fork of [Oracle's now-defunct appbundler project](https://web.archive.org/web/20161220062720/https://java.net/projects/appbundler) with contributions from [InfiniteKind](https://bitbucket.org/infinitekind/appbundler), both under the [GPL v2 license with classpath exception](https://openjdk.java.net/legal/gplv2+ce.html). + - [ICU4J](http://site.icu-project.org) from IBM under the [ICU License](http://source.icu-project.org/repos/icu/icu/tags/release-57-1/LICENSE). + - [Java Development Tools](https://www.eclipse.org/jdt/) by the [Eclipse Foundation](https://www.eclipse.org) under the [Eclipse Public License v2](https://www.eclipse.org/legal/epl-2.0/). + - [Java Native Access](https://github.com/java-native-access/jna) dual licensed under the [Apache v2 License and LGPL](https://github.com/java-native-access/jna/blob/master/LICENSE). + - [JOGL](http://jogamp.org/jogl/www/) by [Jogamp](http://jogamp.org) under the [CC BY 3.0 US license](https://creativecommons.org/licenses/by/3.0/us/). + - [OpenJFX 11](https://openjfx.io) by Oracle under the [GPL v2 with classpath exception](https://openjdk.java.net/legal/gplv2+ce.html). + - [OpenJDK 11](https://openjdk.java.net/projects/jdk/11/) by Oracle under the [GPL v2 with classpath exception](https://openjdk.java.net/legal/gplv2+ce.html) + - `org.netbeans.swing.outline` from [Netbeans](http://netbeans.apache.org) dual licensed under the [GNU GPL v2 and CDDL licenses](http://wiki.netbeans.org/FaqWhyCDDLAndGPL) + - Some text used from [Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:Copyrights) under the [CC BY-SA](https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License) license. + + +
+
+ +Other License Bodies +---------------------------------------------------------------------------------------------------- +Text of other relevant licenses... + +
+ +**IBM Public License Version 1.0** +the original document can be found at: +http://oss.software.ibm.com/developerworks/opensource/license10.html + +``` +IBM Public License Version 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS IBM +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF +THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of International Business Machines Corporation ("IBM"), +the Original Program, and + +b) in the case of each Contributor, + +i) changes to the Program, and + +ii) additions to the Program; +where such changes and/or additions to the Program originate from and +are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program by such +Contributor itself or anyone acting on such Contributor's +behalf. Contributions do not include additions to the Program which: +(i) are separate modules of software distributed in conjunction with +the Program under their own license agreement, and (ii) are not +derivative works of the Program. + +"Contributor" means IBM and any other entity that distributes the +Program. + +"Licensed Patents " mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. + + +"Original Program" means the original version of the software +accompanying this Agreement as released by IBM, including source code, +object code and documentation, if any. + +"Program" means the Original Program and Contributions. + +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. + + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution of such +Contributor, if any, and such derivative works, in source code and +object code form. + +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, if +any, in source code and object code form. This patent license shall +apply to the combination of the Contribution and the Program if, at +the time the Contribution is added by the Contributor, such addition +of the Contribution causes such combination to be covered by the +Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder. + +c) Recipient understands that although each Contributor grants the +licenses to its Contributions set forth herein, no assurances are +provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility +to secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow +Recipient to distribute the Program, it is Recipient's responsibility +to acquire that license before distributing the Program. + +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. + + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form +under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and + +b) its license agreement: + +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose; + +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental and +consequential damages, such as lost profits; + +iii) states that any provisions which differ from this Agreement are +offered by that Contributor alone and not by any other party; and + +iv) states that source code for the Program is available from such +Contributor, and informs licensees how to obtain it in a reasonable +manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the +Program. + +Each Contributor must include the following in a conspicuous location +in the Program: + +Copyright 2003, International Business Machines Corporation and +others. All Rights Reserved. + +In addition, each Contributor must identify itself as the originator +of its Contribution, if any, in a manner that reasonably allows +subsequent Recipients to identify the originator of the Contribution. + + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use +of the Program, the Contributor who includes the Program in a +commercial product offering should do so in a manner which does not +create potential liability for other Contributors. Therefore, if a +Contributor includes the Program in a commercial product offering, +such Contributor ("Commercial Contributor") hereby agrees to defend +and indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") arising +from claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the acts +or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property +infringement. In order to qualify, an Indemnified Contributor must: a) +promptly notify the Commercial Contributor in writing of such claim, +and b) allow the Commercial Contributor to control, and cooperate with +the Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such +claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages. + + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY +WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement, including but not limited to +the risks and costs of program errors, compliance with applicable +laws, damage to or loss of data, programs or equipment, and +unavailability or interruption of operations. + + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR +ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and +enforceable. + +If Recipient institutes patent litigation against a Contributor with +respect to a patent applicable to software (including a cross-claim or +counterclaim in a lawsuit), then any patent licenses granted by that +Contributor to such Recipient under this Agreement shall terminate as +of the date such litigation is filed. In addition, If Recipient +institutes patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Program +itself (excluding combinations of the Program with other software or +hardware +``` diff --git a/app/build.xml b/app/build.xml index b6d97218a..bef3f06b7 100644 --- a/app/build.xml +++ b/app/build.xml @@ -13,14 +13,14 @@ - + - + @@ -30,22 +30,19 @@ + nowarn="true"> - diff --git a/app/lib/jna-platform.jar b/app/lib/jna-platform.jar index d0fd2e4f5..472268182 100644 Binary files a/app/lib/jna-platform.jar and b/app/lib/jna-platform.jar differ diff --git a/app/lib/jna.jar b/app/lib/jna.jar index 25243176e..0b5fabdd8 100644 Binary files a/app/lib/jna.jar and b/app/lib/jna.jar differ diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 16a31bf80..d2c58921e 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -75,6 +75,10 @@ public class Platform { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + static public boolean isInit() { + return inst != null; + } + static public void init() { try { @@ -339,10 +343,10 @@ public class Platform { File[] plugins = getContentFile("../PlugIns").listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return dir.isDirectory() && - name.endsWith(".jdk") && !name.startsWith("."); + name.contains("jdk") && !name.startsWith("."); } }); - return new File(plugins[0], "Contents/Home/jre"); + return new File(plugins[0], "Contents/Home"); } // On all other platforms, it's the 'java' folder adjacent to Processing return getContentFile("java"); @@ -412,4 +416,4 @@ public class Platform { static public int getSystemDPI() { return inst.getSystemDPI(); } -} \ No newline at end of file +} diff --git a/app/src/processing/app/platform/LinuxPlatform.java b/app/src/processing/app/platform/LinuxPlatform.java index fe3d7ce85..56c7859de 100644 --- a/app/src/processing/app/platform/LinuxPlatform.java +++ b/app/src/processing/app/platform/LinuxPlatform.java @@ -40,20 +40,6 @@ public class LinuxPlatform extends DefaultPlatform { public void initBase(Base base) { super.initBase(base); - String javaVendor = System.getProperty("java.vendor"); - String javaVM = System.getProperty("java.vm.name"); - if (javaVendor == null || - (!javaVendor.contains("Sun") && !javaVendor.contains("Oracle")) || - javaVM == null || !javaVM.contains("Java")) { - Messages.showWarning("Not fond of this Java VM", - "Processing requires Java 8 from Oracle.\n" + - "Other versions such as OpenJDK, IcedTea,\n" + - "and GCJ are strongly discouraged. Among other things, you're\n" + - "likely to run into problems with sketch window size and\n" + - "placement. For more background, please read the wiki:\n" + - "https://github.com/processing/processing/wiki/Supported-Platforms#linux", null); - } - // Set x11 WM_CLASS property which is used as the application // name by Gnome3 and other window managers. // https://github.com/processing/processing/issues/2534 diff --git a/app/src/processing/app/platform/ThinkDifferent.java b/app/src/processing/app/platform/ThinkDifferent.java index dc905c62a..01c9823bc 100644 --- a/app/src/processing/app/platform/ThinkDifferent.java +++ b/app/src/processing/app/platform/ThinkDifferent.java @@ -24,11 +24,15 @@ package processing.app.platform; import java.awt.event.*; import java.io.File; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.List; import javax.swing.*; -import com.apple.eawt.*; -import com.apple.eawt.AppEvent.*; +import com.apple.eawt.Application; import processing.app.*; import processing.app.ui.About; @@ -65,44 +69,40 @@ public class ThinkDifferent { if (adapter == null) { adapter = new ThinkDifferent(); //base); } - - application.setAboutHandler(new AboutHandler() { - public void handleAbout(AboutEvent ae) { - new About(null); - } - }); - - application.setPreferencesHandler(new PreferencesHandler() { - public void handlePreferences(PreferencesEvent arg0) { - base.handlePrefs(); - } + + setHandler(application, "setAboutHandler", (proxy, method, args) -> { + new About(null); + return null; }); - application.setOpenFileHandler(new OpenFilesHandler() { - public void openFiles(OpenFilesEvent event) { - for (File file : event.getFiles()) { - base.handleOpen(file.getAbsolutePath()); - } - } - }); - - application.setPrintFileHandler(new PrintFilesHandler() { - public void printFiles(PrintFilesEvent event) { - // TODO not yet implemented - } - }); - - application.setQuitHandler(new QuitHandler() { - public void handleQuitRequestWith(QuitEvent event, QuitResponse response) { - if (base.handleQuit()) { - response.performQuit(); - } else { - response.cancelQuit(); - } - } + setHandler(application, "setPreferencesHandler", (proxy, method, args) -> { + base.handlePrefs(); + return null; }); - // Set the menubar to be used when nothing else is open. + setHandler(application, "setOpenFileHandler", (proxy, method, args) -> { + Method m = args[0].getClass().getMethod("getFiles"); + for (File file : (List) m.invoke(args[0])) { + base.handleOpen(file.getAbsolutePath()); + } + return null; + }); + + setHandler(application, "setPrintFileHandler", (proxy, method, args) -> { + // TODO not yet implemented + return null; + }); + + setHandler(application, "setQuitHandler", (proxy, method, args) -> { + if (base.handleQuit()) { + args[1].getClass().getMethod("performQuit").invoke(args[1]); + } else { + args[1].getClass().getMethod("cancelQuit").invoke(args[1]); + } + return null; + }); + + // Set the menubar to be used when nothing else is open. JMenuBar defaultMenuBar = new JMenuBar(); JMenu fileMenu = buildFileMenu(base); defaultMenuBar.add(fileMenu); @@ -117,12 +117,12 @@ public class ThinkDifferent { e.printStackTrace(); // oh well, never mind } // } else { -// // The douchebags at Oracle didn't feel that a working f*king menubar -// // on OS X was important enough to make it into the 7u40 release. +// // The douchebags at Oracle didn't feel that a working f*king menubar +// // on OS X was important enough to make it into the 7u40 release. // //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8007267 // // It languished in the JDK 8 source and has been backported for 7u60: // //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8022667 -// +// // JFrame offscreen = new JFrame(); // offscreen.setUndecorated(true); // offscreen.setJMenuBar(defaultMenuBar); @@ -131,12 +131,51 @@ public class ThinkDifferent { // offscreen.setVisible(true); // } } - + // public ThinkDifferent(Base base) { // this.base = base; // } + /** + * Sets a handler on an instance of {@link Application}, taking into account JVM version + * differences. + * + * @param app an instance of {@link Application} + * @param name the "set handler" method name + * @param handler the handler + */ + private static void setHandler(Application app, String name, InvocationHandler handler) { + // Determine which version of com.apple.eawt.Application to use and pass it a handler of the + // appropriate type + Method[] methods = app.getClass().getMethods(); + for (Method m : methods) { + if (!name.equals(m.getName())) { + continue; + } + if (m.getParameterCount() != 1) { + continue; + } + Class paramType = m.getParameterTypes()[0]; + try { + // Allow a null handler + Object proxy = null; + if (handler != null) { + proxy = Proxy.newProxyInstance( + paramType.getClassLoader(), new Class[] { paramType }, handler); + } + m.invoke(app, proxy); + } catch (IllegalArgumentException ex) { + // TODO: Print error?: method doesn't take an interface, etc. + } catch (IllegalAccessException ex) { + // TODO: Print error?: Other method invocation problem + } catch (InvocationTargetException ex) { + ex.getCause().printStackTrace(); + // TODO: Print ex.getCause() a different way? + } + break; + } + } /** * Gimpy file menu to be used on OS X when no sketches are open. @@ -162,7 +201,7 @@ public class ThinkDifferent { fileMenu.add(item); item = Toolkit.newJMenuItemShift(Language.text("menu.file.sketchbook"), 'K'); - item.addActionListener(new ActionListener() { + item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { base.getNextMode().showSketchbookFrame(); diff --git a/app/src/processing/app/platform/WindowsPlatform.java b/app/src/processing/app/platform/WindowsPlatform.java index 3c4759a37..fd29eed58 100644 --- a/app/src/processing/app/platform/WindowsPlatform.java +++ b/app/src/processing/app/platform/WindowsPlatform.java @@ -64,10 +64,16 @@ public class WindowsPlatform extends DefaultPlatform { "\\" + APP_NAME.toLowerCase() + ".exe \"%1\""; static final String REG_DOC = APP_NAME + ".Document"; + // Starting with Java 9, the scaling is done automatically. If DPI is + // used to scaling within the application, one ends up with 2x the + // expected scale. See JEP 263. + private static final int WINDOWS_NATIVE_DPI = 96; public void initBase(Base base) { super.initBase(base); + checkAssociations(); + //checkQuickTime(); checkPath(); @@ -627,56 +633,9 @@ public class WindowsPlatform extends DefaultPlatform { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - // Need to extend com.sun.jna.platform.win32.User32 to access - // Win32 function GetDpiForSystem() - interface ExtUser32 extends StdCallLibrary, com.sun.jna.platform.win32.User32 { - ExtUser32 INSTANCE = (ExtUser32) Native.loadLibrary("user32", ExtUser32.class, W32APIOptions.DEFAULT_OPTIONS); - - public int GetDpiForSystem(); - - public int SetProcessDpiAwareness(int value); - - public final int DPI_AWARENESS_INVALID = -1; - public final int DPI_AWARENESS_UNAWARE = 0; - public final int DPI_AWARENESS_SYSTEM_AWARE = 1; - public final int DPI_AWARENESS_PER_MONITOR_AWARE = 2; - - public Pointer SetThreadDpiAwarenessContext(Pointer dpiContext); - - public final Pointer DPI_AWARENESS_CONTEXT_UNAWARE = new Pointer(-1); - public final Pointer DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = new Pointer(-2); - public final Pointer DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = new Pointer(-3); - } - - - static private int detected = detectSystemDPI(); - - public int getSystemDPI() { - if (detected == -1) { - return super.getSystemDPI(); - } - return detected; + // Note that this is supported "natively" within Java - See JEP 263. + return WINDOWS_NATIVE_DPI; } - - public static int detectSystemDPI() { - try { - ExtUser32.INSTANCE.SetProcessDpiAwareness(ExtUser32.DPI_AWARENESS_SYSTEM_AWARE); - } catch (Throwable e) { - // Ignore error - } - try { - ExtUser32.INSTANCE.SetThreadDpiAwarenessContext(ExtUser32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE); - } catch (Throwable e) { - // Ignore error (call valid only on Windows 10) - } - try { - return ExtUser32.INSTANCE.GetDpiForSystem(); - } catch (Throwable e) { - // DPI detection failed, fall back with default - System.out.println("DPI detection failed, fallback to 96 dpi"); - return -1; - } - } } diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index b63084c63..c3e6c617c 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -76,12 +76,17 @@ public class JEditTextArea extends JComponent /** The size of the offset between the leftmost padding and the code */ public static final int leftHandGutter = 6; + private final Segment TEST_SEGMENT; + private InputMethodSupport inputMethodSupport; private TextAreaDefaults defaults; private Brackets bracketHelper = new Brackets(); + private FontMetrics cachedPartialPixelWidthFont; + private float partialPixelWidth; + /** * Creates a new JEditTextArea with the specified settings. @@ -90,6 +95,9 @@ public class JEditTextArea extends JComponent public JEditTextArea(TextAreaDefaults defaults, InputHandler inputHandler) { this.defaults = defaults; + char[] testSegmentContents = {'w'}; + TEST_SEGMENT = new Segment(testSegmentContents, 0, 1); + // Enable the necessary events enableEvents(AWTEvent.KEY_EVENT_MASK); @@ -113,6 +121,8 @@ public class JEditTextArea extends JComponent lineSegment = new Segment(); bracketLine = bracketPosition = -1; blink = true; + cachedPartialPixelWidthFont = null; + partialPixelWidth = 0; // Initialize the GUI setLayout(new ScrollLayout()); @@ -632,7 +642,7 @@ public class JEditTextArea extends JComponent // If syntax coloring is disabled, do simple translation if (tokenMarker == null) { lineSegment.count = offset; - return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); + return x + getTabbedTextWidth(lineSegment, fm, x, painter, 0); } else { // If syntax coloring is enabled, we have to do this @@ -664,10 +674,10 @@ public class JEditTextArea extends JComponent int length = tokens.length; if (offset + segmentOffset < lineSegment.offset + length) { lineSegment.count = offset - (lineSegment.offset - segmentOffset); - return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); + return x + getTabbedTextWidth(lineSegment, fm, x, painter, 0); } else { lineSegment.count = length; - x += Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); + x += getTabbedTextWidth(lineSegment, fm, x, painter, 0); lineSegment.offset += length; } tokens = tokens.next; @@ -1310,6 +1320,72 @@ public class JEditTextArea extends JComponent return CharacterKinds.Other; } + /** + * Get the width in pixels of a segment of text within the IDE. + * + *

+ * Fractional-font aware implementation of Utilities.getTabbedTextWidth that determines if there + * are fractional character widths present in a font in order to return a more accurate pixel + * width for an input segment. + *

+ * + * @param s The segment of text for which a pixel width should be returned. + * @param metrics The metrics for the font in which the given segment will be drawn. + * @param x The x origin. + * @param expander The strategy for converting tabs into characters. + * @param startOffset The offset to apply before the text will be drawn. + * @return The width of the input segment in pixels with fractional character widths considered. + */ + private int getTabbedTextWidth(Segment s, FontMetrics metrics, float x, TabExpander expander, + int startOffset) { + + float additionalOffset = getPartialPixelWidth(metrics, x, expander, startOffset) * s.length(); + + return (int) Math.round( + Utilities.getTabbedTextWidth(s, metrics, x, expander, startOffset) + additionalOffset + ); + } + + /** + * Get any partial widths applied within a font. + * + *

+ * Get any partial widths applied within a font, caching results for the latest requested font + * (as identified via a FontMetrics object). Note that this is calculated for a sample character + * and is only valid for extrapolation in a monospaced font (that one might want to use in an + * IDE). + *

+ * + * @param candidateMetrics The FontMetrics for which partial character pixel widths should be + * returned. + * @param x The x origin. + * @param expander The strategy for converting tabs into characters. + * @param startOffset The offset to apply before the text will be drawn. + * @return The partial width of a sample character within a font. + */ + private float getPartialPixelWidth(FontMetrics candidateMetrics, float x, TabExpander expander, + int startOffset) { + + // See https://github.com/sampottinger/processing/issues/103 + // Requires reference not object equality check + if (candidateMetrics != cachedPartialPixelWidthFont) { + float withFractional = Utilities.getTabbedTextWidth​( + TEST_SEGMENT, + candidateMetrics, + x, + expander, + startOffset + ); + + int withoutFractional = (int) withFractional; + + partialPixelWidth = withFractional - withoutFractional; + cachedPartialPixelWidthFont = candidateMetrics; + } + + return partialPixelWidth; + } + protected void setNewSelectionWord( int line, int offset ) { if (getLineLength(line) == 0) { diff --git a/app/src/processing/app/tools/InstallCommander.java b/app/src/processing/app/tools/InstallCommander.java index 518789d4c..a846208da 100644 --- a/app/src/processing/app/tools/InstallCommander.java +++ b/app/src/processing/app/tools/InstallCommander.java @@ -161,4 +161,4 @@ public class InstallCommander implements Tool { list.append(jar.getAbsolutePath()); } } -} \ No newline at end of file +} diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 6780a5310..0e9ab769e 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2898,7 +2898,6 @@ public abstract class Editor extends JFrame implements RunnerListener { * Show an exception in the editor status bar. */ public void statusError(Exception e) { - e.printStackTrace(); // if (e == null) { // System.err.println("Editor.statusError() was passed a null exception."); // return; @@ -2909,9 +2908,7 @@ public abstract class Editor extends JFrame implements RunnerListener { // Make sure something is printed into the console // Status bar is volatile - if (!re.isStackTraceEnabled()) { - System.err.println(re.getMessage()); - } + System.err.println(re.getMessage()); // Move the cursor to the line before updating the status bar, otherwise // status message might get hidden by a potential message caused by moving @@ -2940,6 +2937,8 @@ public abstract class Editor extends JFrame implements RunnerListener { textarea.getLineStopOffset(line) - 1); } } + } else { + e.printStackTrace(); } // Since this will catch all Exception types, spend some time figuring diff --git a/app/test/resources/annotations.expected b/app/test/resources/annotations.expected deleted file mode 100644 index 76d6b79a8..000000000 --- a/app/test/resources/annotations.expected +++ /dev/null @@ -1,53 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.io.Serializable; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class annotations extends PApplet { - - - -public void setup() { - size(200,200); -} - -@Deprecated -public void banana() { - println("hey"); -} - -@SuppressWarnings({"serial", "rawtypes"}) -class Banana implements Serializable { - -} - -@SuppressWarnings("serial") -class Apple implements Serializable { - -} - -@javax.annotation.Generated(value = {"com.mrfeinberg.ImmortalAroma" -}, - comments="Shazam!", - date="2001-07-04T12:08:56.235-0700") -class Pear {} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "annotations" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1064.expected b/app/test/resources/bug1064.expected deleted file mode 100644 index d77173b44..000000000 --- a/app/test/resources/bug1064.expected +++ /dev/null @@ -1,29 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1064 extends PApplet { - public void setup() { -// import "; - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1064" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug136.expected b/app/test/resources/bug136.expected deleted file mode 100644 index 9909098a3..000000000 --- a/app/test/resources/bug136.expected +++ /dev/null @@ -1,41 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.Collections; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug136 extends PApplet { - - -java.util.List alist = Collections.synchronizedList(new ArrayList()); - -public void setup() { -size(400, 200); -alist.add("hello"); -} - -public void draw() { -rect(width/4, height/4, width/2, height/2); -synchronized(alist) { -alist.get(0); -} -} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug136" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1362.expected b/app/test/resources/bug1362.expected deleted file mode 100644 index 00c81e622..000000000 --- a/app/test/resources/bug1362.expected +++ /dev/null @@ -1,29 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1362 extends PApplet { - public void setup() { -if (true) {} else { new String(); } - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1362" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1442.expected b/app/test/resources/bug1442.expected deleted file mode 100644 index d48380587..000000000 --- a/app/test/resources/bug1442.expected +++ /dev/null @@ -1,28 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1442 extends PApplet { - -public float a() { - return 1.0f; -} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1442" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1511.expected b/app/test/resources/bug1511.expected deleted file mode 100644 index ca423630f..000000000 --- a/app/test/resources/bug1511.expected +++ /dev/null @@ -1,37 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.io.StringWriter; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1511 extends PApplet { - public void setup() { -// \u00df - -/** -* a -*/ - - - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1511" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1512.expected b/app/test/resources/bug1512.expected deleted file mode 100644 index bb2bd9aa0..000000000 --- a/app/test/resources/bug1512.expected +++ /dev/null @@ -1,29 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1512 extends PApplet { - public void setup() { -println("oi/*"); - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1512" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1518a.expected b/app/test/resources/bug1518a.expected deleted file mode 100644 index 49c81c14c..000000000 --- a/app/test/resources/bug1518a.expected +++ /dev/null @@ -1,45 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.ArrayList; -import java.util.List; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1518a extends PApplet { - - - - -public void setup() -{ -List list = new ArrayList(); -list.add("foo"); -list.add("bar"); -list.add("baz"); - -binarySearch(list, "bar"); -} - -static int binarySearch(List> list, T -key) { -return 0; -} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1518a" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1518b.expected b/app/test/resources/bug1518b.expected deleted file mode 100644 index 2ca376adf..000000000 --- a/app/test/resources/bug1518b.expected +++ /dev/null @@ -1,43 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.ArrayList; -import java.util.List; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1518b extends PApplet { - - - - -public void setup() -{ -List list = new ArrayList(); -list.add("foo"); -list.add("bar"); -list.add("baz"); -} - -static int binarySearch(List> list, T -key) { -return 0; -} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1518b" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1519.pde b/app/test/resources/bug1519.pde deleted file mode 100644 index 6f6057304..000000000 --- a/app/test/resources/bug1519.pde +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -void setup() -{ -List list = new ArrayList(); -List>> listOfLists = new ArrayList>(); -listOfLists.add(list); -} diff --git a/app/test/resources/bug1525.expected b/app/test/resources/bug1525.expected deleted file mode 100644 index c1337f7b2..000000000 --- a/app/test/resources/bug1525.expected +++ /dev/null @@ -1,31 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1525 extends PApplet { - public void setup() { -if (frameCount > (frameRate - 1)) { - println("My head asplode!"); -} - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1525" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug1534.expected b/app/test/resources/bug1534.expected deleted file mode 100644 index 1b61ca49c..000000000 --- a/app/test/resources/bug1534.expected +++ /dev/null @@ -1,29 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1534 extends PApplet { - public void setup() { -char c = '\"'; - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1534" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug16.pde b/app/test/resources/bug16.pde deleted file mode 100644 index d78728479..000000000 --- a/app/test/resources/bug16.pde +++ /dev/null @@ -1,9 +0,0 @@ -println("Here comes an unterminated comment!") - -/* - banana - apple - pear -* / - -println("Do you see what I did there?") diff --git a/app/test/resources/bug1936.expected b/app/test/resources/bug1936.expected deleted file mode 100644 index dd06677b0..000000000 --- a/app/test/resources/bug1936.expected +++ /dev/null @@ -1,29 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug1936 extends PApplet { - public void setup() { -char a = PApplet.parseChar(PApplet.parseByte(PApplet.parseInt("15"))); - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug1936" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug281.expected b/app/test/resources/bug281.expected deleted file mode 100644 index ffc6ea519..000000000 --- a/app/test/resources/bug281.expected +++ /dev/null @@ -1,32 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug281 extends PApplet { - public void setup() { -if ( "monopoly".charAt( 3 ) == '(' ) -{ - println("parcheesi"); -} - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug281" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug315g.expected b/app/test/resources/bug315g.expected deleted file mode 100644 index ef5cdffa6..000000000 --- a/app/test/resources/bug315g.expected +++ /dev/null @@ -1,35 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug315g extends PApplet { - public void setup() { -size(480, 120); -smooth(); -int y; -y = 60; -int d; -d = 80; -ellipse(75, y, d, d); - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug315g" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug4.expected b/app/test/resources/bug4.expected deleted file mode 100644 index 661de7b80..000000000 --- a/app/test/resources/bug4.expected +++ /dev/null @@ -1,30 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug4 extends PApplet { - public void setup() { -int x = 12; -float u = (PApplet.parseFloat(x)/width); - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug4" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug4.pde b/app/test/resources/bug4.pde deleted file mode 100644 index ee3e1a234..000000000 --- a/app/test/resources/bug4.pde +++ /dev/null @@ -1,2 +0,0 @@ -int x = 12; -float u = (float(x)/width); \ No newline at end of file diff --git a/app/test/resources/bug400g.expected b/app/test/resources/bug400g.expected deleted file mode 100644 index 92dc4f577..000000000 --- a/app/test/resources/bug400g.expected +++ /dev/null @@ -1,34 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug400g extends PApplet { - -//// -public void setup(){ - size(100,100); - - if(true){ - } - else{ // Syntax error on token "else", } expected - } -} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug400g" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug405.expected b/app/test/resources/bug405.expected deleted file mode 100644 index 48497bec0..000000000 --- a/app/test/resources/bug405.expected +++ /dev/null @@ -1,3 +0,0 @@ -for (int i : new int[] {1,2,3}) { - println(i); -} diff --git a/app/test/resources/bug420.expected b/app/test/resources/bug420.expected deleted file mode 100644 index 8ea69d2a7..000000000 --- a/app/test/resources/bug420.expected +++ /dev/null @@ -1,6 +0,0 @@ -int[] a = new int[] { - 1, 2, 3, 4, 5 -}; -for (int i: a) { - print(i); -} diff --git a/app/test/resources/bug427g.expected b/app/test/resources/bug427g.expected deleted file mode 100644 index aebd13672..000000000 --- a/app/test/resources/bug427g.expected +++ /dev/null @@ -1,38 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug427g extends PApplet { - -static final boolean DEBUG = true; - -public void setup() { - MyClass x = new MyClass(); -} - -public class MyClass { - public MyClass() { - if (DEBUG) println("Debug"); - } -} - - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug427g" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug481.expected b/app/test/resources/bug481.expected deleted file mode 100644 index 10d76993b..000000000 --- a/app/test/resources/bug481.expected +++ /dev/null @@ -1,32 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.applet.Applet; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug481 extends PApplet { - public void setup() { - -Class[] abc = new Class[]{Applet.class}; - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug481" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug598.expected b/app/test/resources/bug598.expected deleted file mode 100644 index e3c91eef6..000000000 --- a/app/test/resources/bug598.expected +++ /dev/null @@ -1,70 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import static java.lang.Math.tanh; -import java.util.concurrent.Callable; -import java.util.List; -import java.util.Comparator; -import java.util.Map; -import java.util.Collection; -import java.util.Arrays; -import java.util.HashSet; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug598 extends PApplet { - -// java 5 torture test - - - - - - - - - - - -private static Comparator rotarapmoc = new Comparator() { - public int compare(final String o1, final String o2) - { - return o1.charAt(o1.length() - 1) - o2.charAt(o2.length() - 1); - } -}; - -final void printClass(T t) { - println(t.getClass()); -} -public final List sortem(final String... strings) { - Arrays.sort(strings, rotarapmoc); - return Arrays.asList(strings); -} - -final Map> -charlesDeGaulle = new HashMap>(); - -public void setup() { - charlesDeGaulle.put("banana", new HashSet()); - charlesDeGaulle.get("banana").add(0); - System.out.println(sortem("aztec", "maya", "spanish", "portuguese")); - printClass(12.d); -} - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug598" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug5a.expected b/app/test/resources/bug5a.expected deleted file mode 100644 index c29588dfc..000000000 --- a/app/test/resources/bug5a.expected +++ /dev/null @@ -1,30 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug5a extends PApplet { - public void setup() { -println("The next line should not cause a failure."); -// no newline after me - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug5a" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/resources/bug5b.expected b/app/test/resources/bug5b.expected deleted file mode 100644 index 058be9ab3..000000000 --- a/app/test/resources/bug5b.expected +++ /dev/null @@ -1,30 +0,0 @@ -import processing.core.*; -import processing.data.*; -import processing.event.*; -import processing.opengl.*; - -import java.util.HashMap; -import java.util.ArrayList; -import java.io.File; -import java.io.BufferedReader; -import java.io.PrintWriter; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public class bug5b extends PApplet { - public void setup() { -println("The next line should not cause a failure."); -/* no newline after me */ - noLoop(); - } - - static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "bug5b" }; - if (passedArgs != null) { - PApplet.main(concat(appletArgs, passedArgs)); - } else { - PApplet.main(appletArgs); - } - } -} diff --git a/app/test/src/test/processing/mode/java/ParserTests.java b/app/test/src/test/processing/mode/java/ParserTests.java deleted file mode 100644 index 4f565a7d0..000000000 --- a/app/test/src/test/processing/mode/java/ParserTests.java +++ /dev/null @@ -1,304 +0,0 @@ -package test.processing.mode.java; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static test.processing.mode.java.ProcessingTestUtil.COMPILER; -import static test.processing.mode.java.ProcessingTestUtil.preprocess; -import static test.processing.mode.java.ProcessingTestUtil.res; - -import java.io.File; -import java.io.FileWriter; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.BeforeClass; -import org.junit.Test; - -import processing.app.SketchException; -import processing.app.exec.ProcessResult; -import antlr.RecognitionException; - -public class ParserTests { - - @BeforeClass - public static void init() { - ProcessingTestUtil.init(); - } - - static void expectRecognitionException(final String id, - final String expectedMessage, - final int expectedLine) { - try { - preprocess(id, res(id + ".pde")); - fail("Expected to fail with \"" + expectedMessage + "\" on line " - + expectedLine); - } catch (RecognitionException e) { - assertEquals(expectedMessage, e.getMessage()); - assertEquals(expectedLine, e.getLine()); - } catch (Exception e) { - if (!e.equals(e.getCause()) && e.getCause() != null) - fail(e.getCause().toString()); - else - fail(e.toString()); - } - } - - static void expectRunnerException(final String id, - final String expectedMessage, - final int expectedLine) { - try { - preprocess(id, res(id + ".pde")); - fail("Expected to fail with \"" + expectedMessage + "\" on line " - + expectedLine); - } catch (SketchException e) { - assertEquals(expectedMessage, e.getMessage()); - assertEquals(expectedLine, e.getCodeLine()); - } catch (Exception e) { - if (!e.equals(e.getCause()) && e.getCause() != null) - fail(e.getCause().toString()); - else - fail(e.toString()); - } - } - - static void expectCompilerException(final String id, - final String expectedMessage, - final int expectedLine) { - try { - final String program = ProcessingTestUtil - .preprocess(id, res(id + ".pde")); - final ProcessResult compilerResult = COMPILER.compile(id, program); - if (compilerResult.succeeded()) { - fail("Expected to fail with \"" + expectedMessage + "\" on line " - + expectedLine); - } - final String e = compilerResult.getStderr().split("\n")[0]; - final Matcher m = Pattern.compile(":(\\d+):\\s+(.+)$").matcher(e); - m.find(); - assertEquals(expectedMessage, m.group(2)); - assertEquals(String.valueOf(expectedLine), m.group(1)); - } catch (Exception e) { - if (!e.equals(e.getCause()) && e.getCause() != null) - fail(e.getCause().toString()); - else - fail(e.toString()); - } - } - - static void expectGood(final String id) { - try { - final String program = ProcessingTestUtil - .preprocess(id, res(id + ".pde")); - final ProcessResult compilerResult = COMPILER.compile(id, program); - if (!compilerResult.succeeded()) { - System.err.println(program); - System.err.println("----------------------------"); - System.err.println(compilerResult.getStderr()); - fail("Compilation failed with status " + compilerResult.getResult()); - } - - final File expectedFile = res(id + ".expected"); - if (expectedFile.exists()) { - final String expected = ProcessingTestUtil.read(expectedFile); - assertEquals(expected, program); - } else { - System.err.println("WARN: " + id - + " does not have an expected output file. Generating."); - final FileWriter sug = new FileWriter(res(id + ".expected")); - sug.write(ProcessingTestUtil.normalize(program)); - sug.close(); - } - - } catch (Exception e) { - if (!e.equals(e.getCause()) && e.getCause() != null) - fail(e.getCause().toString()); - else - fail(e.toString()); - } - } - - @Test - public void bug4() { - expectGood("bug4"); - } - - @Test - public void bug5a() { - expectGood("bug5a"); - } - - @Test - public void bug5b() { - expectGood("bug5b"); - } - - @Test - public void bug6() { - expectRecognitionException("bug6", "expecting EOF, found '/'", 1); - } - - @Test - public void bug16() { - expectRunnerException("bug16", "Unclosed /* comment */", 2); - } - - @Test - public void bug136() { - expectGood("bug136"); - } - - @Test - public void bug196() { - expectRecognitionException("bug196", - "Web colors must be exactly 6 hex digits. This looks like 5.", 4); - } - - @Test - public void bug281() { - expectGood("bug281"); - } - - @Test - public void bug481() { - expectGood("bug481"); - } - - @Test - public void bug507() { - expectRecognitionException("bug507", "expecting EOF, found 'else'", 5); - } - - @Test - public void bug598() { - expectGood("bug598"); - } - - @Test - public void bug631() { - expectGood("bug631"); - } - - @Test - public void bug763() { - expectRunnerException("bug763", "Unterminated string constant", 6); - } - - @Test - public void bug820() { - expectCompilerException("bug820", "error: variable x1 is already defined in method setup()", 18); - } - - @Test - public void bug1064() { - expectGood("bug1064"); - } - - @Test - public void bug1145() { - expectCompilerException("bug1145", "error: '.' expected", 6); - } - - @Test - public void bug1362() { - expectGood("bug1362"); - } - - @Test - public void bug1390() { - expectGood("bug1390"); - } - - @Test - public void bug1442() { - expectGood("bug1442"); - } - - @Test - public void bug1511() { - expectGood("bug1511"); - } - - @Test - public void bug1512() { - expectGood("bug1512"); - } - - @Test - public void bug1514a() { - expectGood("bug1514a"); - } - - @Test - public void bug1514b() { - expectGood("bug1514b"); - } - - @Test - public void bug1515() { - expectGood("bug1515"); - } - - @Test - public void bug1516() { - expectGood("bug1516"); - } - - @Test - public void bug1517() { - expectGood("bug1517"); - } - - @Test - public void bug1518a() { - expectGood("bug1518a"); - } - - @Test - public void bug1518b() { - expectGood("bug1518b"); - } - - @Test - public void bug1519() { - expectRecognitionException("bug1519", "Maybe too many > characters?", 7); - } - - @Test - public void bug1525() { - expectGood("bug1525"); - } - - @Test - public void bug1532() { - expectRecognitionException("bug1532", "unexpected token: break", 50); - } - - @Test - public void bug1534() { - expectGood("bug1534"); - } - - @Test - public void bug1936() { - expectGood("bug1936"); - } - - @Test - public void bug315g() { - expectGood("bug315g"); - } - - @Test - public void bug400g() { - expectGood("bug400g"); - } - - @Test - public void bug427g() { - expectGood("bug427g"); - } - - @Test - public void annotations() { - expectGood("annotations"); - } -} diff --git a/build/.gitignore b/build/.gitignore index 290988977..177ce2a9b 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,2 +1,8 @@ work javadoc + +jre/bin-test +macosx/javafx-sdk-11.0.2 +macosx/jdk-0u4.tgz +macosx/jdk-11.0.4+11 +macosx/jfx-11.0.2.zip diff --git a/build/build.xml b/build/build.xml index c7061c2c3..2500ded8a 100644 --- a/build/build.xml +++ b/build/build.xml @@ -1,6 +1,14 @@ + + + + + + + + @@ -27,52 +35,66 @@ - + - + - + - + - - + + - - + + - - + + - + + + + + + + + - - - + + + + + + + + + + @@ -84,71 +106,89 @@ --> - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + + - - - - - - + + + - - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -210,16 +250,108 @@ --> - - + + + + + - + - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,37 +364,47 @@ classpath="jre/downloader.jar" /> - + + - + - - + + - - + + - + component="JDK" + flavor="${jdk.downloader}" + path="${jdk.tgz.path}" /> - - + + + + @@ -271,8 +413,7 @@ - + @@ -299,7 +440,7 @@ - + @@ -307,18 +448,40 @@ - + + + + + + + + + + + + + + + + + + + + + + - + + - + - + @@ -506,27 +669,51 @@
- - - ======================================================= - Processing for Mac OS X can only be built on Mac OS X. + + + + + + ======================================================= + Processing for Mac can only be built on *nix systems. - Bye. - ======================================================= - - + Bye. + ======================================================= + + + + + - - - - - + - + + + + + + + + + + + + + + + + + + + + + @@ -539,24 +726,21 @@ signature="Pde3" icon="macosx/processing.icns" copyright="© The Processing Foundation" - getInfo="${version}, Copyright © The Processing Foundation" shortVersion="${version}" version="${revision}" - javafx="true" - minimumSystem="10.8.5" mainClassName="processing.app.BaseSplash"> + jdk1.7.0_40.jdk, so we'll need to strip that out. --> - + @@ -591,7 +775,7 @@ - + @@ -777,19 +1005,24 @@ - - - ======================================================= - Processing for Linux can only be built on *nix systems. + + + + + + ======================================================= + Processing for Linux can only be built on *nix systems. - Bye. - ======================================================= - + Bye. + ======================================================= + - + + + - + @@ -829,6 +1062,25 @@ + + + + + + + + + + + + + + + + + + + @@ -860,7 +1112,7 @@ Cannot use ant version of tar because it doesn't preserve properties. --> @@ -875,37 +1127,52 @@ --> - + - - + + - + + + + - + + + + + + + + + + + + + - + - + - + - + @@ -926,7 +1193,7 @@ - + @@ -985,7 +1252,7 @@ - + @@ -995,10 +1262,10 @@ - + - + @@ -1064,18 +1331,10 @@ - - ======================================================= - Processing for Windows can only be built on windows. - - Bye. - ======================================================= - - - + - + @@ -1088,10 +1347,10 @@ https://github.com/processing/processing/issues/3624 --> - + - + @@ -1109,6 +1368,34 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -1123,12 +1410,31 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -1138,6 +1444,14 @@ + + + + + + + + @@ -1145,22 +1459,32 @@ - - + + + + + + + + + + + + + @@ -1168,7 +1492,7 @@ --> - + @@ -1190,7 +1514,7 @@ excludes="java/**" /> --> - + - + @@ -1402,7 +1726,7 @@ remove the spaces for depth since it should be double dash, but screws up commen - + diff --git a/build/jre/build.xml b/build/jre/build.xml index db3c84e6e..69c8109e8 100644 --- a/build/jre/build.xml +++ b/build/jre/build.xml @@ -1,49 +1,71 @@ - - + + + + + - - - - - - - - - + + + + + - - - - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + - + - - - + + diff --git a/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java b/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java new file mode 100644 index 000000000..7ede8c52b --- /dev/null +++ b/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java @@ -0,0 +1,85 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2019 The Processing Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * Utility to generate download URLs from AdoptOpenJDK. + */ +public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { + + private static final String BASE_URL = "https://github.com/AdoptOpenJDK/openjdk%d-binaries/releases/download/jdk-%d.%d.%d%%2B%d/OpenJDK%dU-%s_%d.%d.%d_%d.%s"; + + @Override + public String buildUrl(String platform, String component, int train, int version, int update, + int build, String flavor, String hash) { + + if (!component.equalsIgnoreCase("jdk")) { + throw new RuntimeException("Can only generate JDK download URLs for AdoptOpenJDK."); + } + + String filename = buildDownloadRemoteFilename(platform); + String fileExtension = buildFileExtension(platform); + return String.format( + BASE_URL, + train, + train, + version, + update, + build, + train, + filename, + train, + version, + update, + build, + fileExtension + ); + } + + /** + * Build a the filename (the "flavor") that is expected on AdoptOpenJDK. + * + * @param downloadPlatform The platform for which the download URL is being generated like + * "macos" or "linux64". + * @return The artifact name without extension like "jdk_x64_mac_hotspot". + */ + private String buildDownloadRemoteFilename(String downloadPlatform) { + switch (downloadPlatform.toLowerCase()) { + case "windows32": return "jdk_x86-32_windows_hotspot"; + case "windows64": return "jdk_x64_windows_hotspot"; + case "macosx64": return "jdk_x64_mac_hotspot"; + case "linux32": throw new RuntimeException("Linux32 not supported by AdoptOpenJDK."); + case "linux64": return "jdk_x64_linux_hotspot"; + case "linuxarm": return "jdk_aarch64_linux_hotspot"; + default: throw new RuntimeException("Unknown platform: " + downloadPlatform); + } + } + + /** + * Determine the download file extension. + * + * @param downloadPlatform The platform for which the download URL is being generated like + * "macos" or "linux64". + * @return The file extension without leading period like "zip" or "tar.gz". + */ + private String buildFileExtension(String downloadPlatform) { + return downloadPlatform.startsWith("windows") ? "zip" : "tar.gz"; + } +} diff --git a/build/jre/src/DownloadItem.java b/build/jre/src/DownloadItem.java new file mode 100644 index 000000000..30e716f43 --- /dev/null +++ b/build/jre/src/DownloadItem.java @@ -0,0 +1,77 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014-19 The Processing Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +import java.util.Optional; + + +/** + * Data structure describing an item to be downloaded as part the Processing build. + */ +public class DownloadItem { + + private String url; + private String localPath; + private Optional cookie; + + /** + * Create a new download item. + * + * @param newUrl The remote URL at which the download can be found (via GET). + * @param newLocalPath The local path to which the file should be written. + * @param newCookie Optional cookie that, if present, should be given to the server along with the + * GET request for the download contents. + */ + public DownloadItem(String newUrl, String newLocalPath, Optional newCookie) { + url = newUrl; + localPath = newLocalPath; + cookie = newCookie; + } + + /** + * Determine where the download can be requested. + * + * @return The remote URL at which the download can be found (via GET). + */ + public String getUrl() { + return url; + } + + /** + * Determine to where the download should be saved. + * + * @return The local path to which the file should be written. + */ + public String getLocalPath() { + return localPath; + } + + /** + * Determine if and what cookie should be given as part of the download request. + * + * @return Optional cookie that, if present, should be given to the server along with the + * GET request for the download contents. Should be ignored otherwise. + */ + public Optional getCookie() { + return cookie; + } + + +} diff --git a/build/jre/src/DownloadUrlGenerator.java b/build/jre/src/DownloadUrlGenerator.java new file mode 100644 index 000000000..02e0d62c4 --- /dev/null +++ b/build/jre/src/DownloadUrlGenerator.java @@ -0,0 +1,84 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014-19 The Processing Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +import java.util.Optional; + +/** + * Abstract base class for strategy to generate download URLs. + */ +public abstract class DownloadUrlGenerator { + + /** + * Determine the URL at which the artifact can be downloaded. + * + * @param platform The platform for which the download URL is being generated like "macos" or + * "linux64". + * @param component The component to download like "JDK", "JRE", or "JFX". + * @param train The JDK train (like 1 or 11). + * @param version The JDK version (like 8 or 1). + * @param update The update (like 13). + * @param build The build number (like 133). + * @param flavor The flavor like "macosx-x64.dmg". + * @param hash The hash like "d54c1d3a095b4ff2b6607d096fa80163". + */ + public abstract String buildUrl(String platform, String component, int train, int version, + int update, int build, String flavor, String hash); + + /** + * Get the cookie that should be used in downloading the target component. + * + * @return Optional that is empty if no cookie should be used or optional with the string cookie + * value if one should be used. + */ + public Optional getCookie() { + return Optional.empty(); + } + + /** + * Determine the name of the file to which the remote file should be saved. + * + * @param downloadPlatform The platform for which the download URL is being generated like + * "macos" or "linux64". + * @param component The component to download like "JDK", "JRE", or "JFX". + * @param train The JDK train (like 1 or 11). + * @param version The JDK version (like 8 or 1). + * @param update The update (like 13). + * @param build The build number (like 133). + * @param flavor The flavor like "macosx-x64.dmg". + * @param hash The hash like "d54c1d3a095b4ff2b6607d096fa80163". + */ + public String getLocalFilename(String downloadPlatform, String component, int train, int version, + int update, int build, String flavor, String hash) { + + String baseFilename = component.toLowerCase(); + + String versionStr; + if (update == 0) { + versionStr = String.format("-%d-%s", version, flavor); + } else { + versionStr = String.format("-%du%d-%s", version, update, flavor); + } + + return baseFilename + versionStr; + } + +} diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index b25fb58b8..8828cb595 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -1,3 +1,24 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014-19 The Processing Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + import java.io.*; import java.net.*; import java.util.*; @@ -7,66 +28,134 @@ import org.apache.tools.ant.Task; /** - * Ant Task for downloading the latest JRE or JDK from Oracle. + * Ant Task for downloading the latest JRE, JDK, or OpenJFX release. */ public class Downloader extends Task { - static final String COOKIE = - "oraclelicense=accept-securebackup-cookie"; + private static final boolean PRINT_LOGGING = true; - private int version; // Java 8 + private boolean openJdk; // If using openJDK. + private String platform; // macos + private int train; // Java 11 (was 1 through Java 8) + private int version; // 0 (was 8 prior to Java 9) private int update; // Update 131 private int build; // Build 11 // https://gist.github.com/P7h/9741922 // http://stackoverflow.com/q/10268583 private String hash; // d54c1d3a095b4ff2b6607d096fa80163 - private boolean jdk; // false if JRE + private String component; // "JRE", "JDK", or "JFX" - private String flavor; + private String flavor; // Like "zip" private String path; // target path + /** + * Create a new downloader without tag attributes filled in. + **/ public Downloader() { } + /** + * Set the platform being used. + * + * @param platform The platfom for which files are being downloaded like macosx. + */ + public void setPlatform(String platform) { + this.platform = platform; + } + /** + * Indicate if the OpenJDK is being used. + * + * @param openJdk True if OpenJDK is being used. False if Oracle JDK is being used. + */ + public void setOpenJdk(boolean openJdk) { + this.openJdk = openJdk; + } + + /** + * Specify the build train being used. + * + * @param train The build train like 1 (Java 8 and before) or 11 (Java 11). + */ + public void setTrain(int train) { + this.train = train; + } + + /** + * Set the version to download within the given build train. + * + * @param version The version within the train to use like 0 for "11.0.1_13". + */ public void setVersion(int version) { this.version = version; } - + /** + * Set the update number to download within the given build train. + * + * @param update The update within the version to use like 1 for "11.0.1_13". + */ public void setUpdate(int update) { this.update = update; } - + /** + * Set the build number to download. + * + * @param build The build number to use within the build train like 13 for "11.0.1_13". + */ public void setBuild(int build) { this.build = build; } - + /** + * Set the expected hash of the download. + * + * @param hash The hash set. + */ public void setHash(String hash) { this.hash = hash; } - - public void setJDK(boolean jdk) { - this.jdk = jdk; + /** + * Indicate what component or release type of Java is being downloaded. + * + * @param component The component to download like "JDK", "JRE", or "OpenJFX". + */ + public void setComponent(String component) { + this.component = component; } - + /** + * Indicate the file flavor to be downloaded. + * + * @param flavor The flavor of file (dependent on platform) to be downloaded. Like "-x64.tar.gz". + */ public void setFlavor(String flavor) { this.flavor = flavor; } - + /** + * Set the path to which the file should be downloaded. + * + * @param path The path to which the file should be downloaded. + */ public void setPath(String path) { this.path = path; } - + /** + * Download the JDK or JRE. + */ public void execute() throws BuildException { - if (version == 0) { + if (train == 0) { + // 1 if prior to Java 9 + throw new BuildException("Train (i.e. 1 or 11) must be set"); + } + + boolean isJava11 = train == 11; + if (!isJava11 && version == 0) { throw new BuildException("Version (i.e. 7 or 8) must be set"); } @@ -90,33 +179,38 @@ public class Downloader extends Task { } } - + /** + * Download the package from AdoptOpenJDK or Oracle. + */ void download() throws IOException { - String filename = (jdk ? "jdk" : "jre") + - (update == 0 ? - String.format("-%d-%s", version, flavor) : - String.format("-%du%d-%s", version, update, flavor)); + DownloadItem downloadItem; + // Determine url generator for task + Optional downloadItemMaybe = getDownloadItem(); + if (downloadItemMaybe.isEmpty()) { + return; // There is nothing to do. + } else { + downloadItem = downloadItemMaybe.get(); + } + + // Build URL and path if (path == null) { - path = filename; + path = downloadItem.getLocalPath(); } - String url = "http://download.oracle.com/otn-pub/java/jdk/" + - (update == 0 ? - String.format("%d-b%02d/", version, build) : - String.format("%du%d-b%02d/", version, update, build)); + String url = downloadItem.getUrl(); - // URL format changed starting with 8u121 - if (update >= 121) { - url += hash + "/"; - } - - // Finally, add the filename to the end - url += filename; + // Downlaod + println("Attempting download at " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); - conn.setRequestProperty("Cookie", COOKIE); + + Optional cookieMaybe = downloadItem.getCookie(); + + if (cookieMaybe.isPresent()) { + conn.setRequestProperty("Cookie", cookieMaybe.get()); + } //printHeaders(conn); //conn.connect(); @@ -125,7 +219,7 @@ public class Downloader extends Task { List location = headers.get("Location"); if (location.size() == 1) { url = location.get(0); - System.out.println("Redirecting to " + url); + println("Redirecting to " + url); } else { throw new BuildException("Got " + location.size() + " locations."); } @@ -136,7 +230,11 @@ public class Downloader extends Task { conn.setRequestProperty("Cookie", cookie); } } - conn.setRequestProperty("Cookie", COOKIE); + + if (cookieMaybe.isPresent()) { + conn.setRequestProperty("Cookie", cookieMaybe.get()); + } + conn.connect(); } @@ -144,7 +242,10 @@ public class Downloader extends Task { InputStream input = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(input); File outputFile = new File(path); //folder, filename); - System.out.format("Downloading %s from %s%n", outputFile.getAbsolutePath(), url); + + String msg = String.format("Downloading %s from %s%n", outputFile.getAbsolutePath(), url); + println(msg); + // Write to a temp file so that we don't have an incomplete download // masquerading as a good archive. File tempFile = File.createTempFile("download", "", outputFile.getParentFile()); @@ -175,19 +276,107 @@ public class Downloader extends Task { } } - + /** + * Print the headers used for {URLConnection}. + */ static void printHeaders(URLConnection conn) { Map> headers = conn.getHeaderFields(); Set>> entrySet = headers.entrySet(); for (Map.Entry> entry : entrySet) { String headerName = entry.getKey(); - System.out.println("Header Name:" + headerName); + println("Header Name:" + headerName); List headerValues = entry.getValue(); for (String value : headerValues) { - System.out.print("Header value:" + value); + print("Header value:" + value); } - System.out.println(); - System.out.println(); + printEmptyLine(); + printEmptyLine(); } } + + /** + * Get the item to be downloaded for this task. + * + * @return The to be downloaded or empty if there is no download required. + */ + private Optional getDownloadItem() { + // Determine download type + boolean isJavaDownload = component.equalsIgnoreCase("jdk"); + isJavaDownload = isJavaDownload || component.equalsIgnoreCase("jre"); + + boolean isJfxDownload = component.equalsIgnoreCase("jfx"); + + DownloadUrlGenerator downloadUrlGenerator; + + // Determine url generator + if (isJavaDownload) { + if (openJdk) { + downloadUrlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); + } else { + downloadUrlGenerator = new OracleDownloadUrlGenerator(); + } + } else if (isJfxDownload) { + if (openJdk) { + downloadUrlGenerator = new GluonHqDownloadUrlGenerator(); + } else { + return Optional.empty(); // Nothing to download + } + } else { + throw new RuntimeException("Do not know how to download: " + component); + } + + // Build download item + String path = downloadUrlGenerator.getLocalFilename( + platform, + component, + train, + version, + update, + build, + flavor, + hash + ); + + String url = downloadUrlGenerator.buildUrl( + platform, + component, + train, + version, + update, + build, + flavor, + hash + ); + + return Optional.of(new DownloadItem(url, path, downloadUrlGenerator.getCookie())); + } + + /** + * Print a line out to console if logging is enabled. + * + * @param message The message to be printed. + */ + private static void println(String message) { + if (PRINT_LOGGING) { + System.out.println(message); + } + } + + /** + * Print a line out to console if logging is enabled without a newline. + * + * @param message The message to be printed. + */ + private static void print(String message) { + if (PRINT_LOGGING) { + System.out.print(message); + } + } + + /** + * Print an empty line to the system.out. + */ + private static void printEmptyLine() { + println(""); + } } diff --git a/build/jre/src/GluonHqDownloadUrlGenerator.java b/build/jre/src/GluonHqDownloadUrlGenerator.java new file mode 100644 index 000000000..d11fc5df3 --- /dev/null +++ b/build/jre/src/GluonHqDownloadUrlGenerator.java @@ -0,0 +1,50 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014-19 The Processing Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +/** + * URL generator for downloading JFX directly from OpenJFX's sponsor Gluon. + */ +public class GluonHqDownloadUrlGenerator extends DownloadUrlGenerator { + + private static final String TEMPLATE_URL = "http://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; + + @Override + public String buildUrl(String platform, String component, int train, int version, int update, + int build, String flavor, String hash) { + + String platformLower = platform.toLowerCase(); + + String platformShort; + if (platformLower.contains("linux")) { + platformShort = "linux"; + } else if (platformLower.contains("mac")) { + platformShort = "mac"; + } else if (platformLower.contains("windows")) { + platformShort = "windows"; + } else { + throw new RuntimeException("Unsupported platform for JFX: " + platform); + } + + return String.format(TEMPLATE_URL, train, version, update, platformShort); + } + +} diff --git a/build/jre/src/OracleDownloadUrlGenerator.java b/build/jre/src/OracleDownloadUrlGenerator.java new file mode 100644 index 000000000..2984bfa1c --- /dev/null +++ b/build/jre/src/OracleDownloadUrlGenerator.java @@ -0,0 +1,72 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014-19 The Processing Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +import java.util.Optional; + +/** + * Utility to generate the download URL from Oracle. + */ +public class OracleDownloadUrlGenerator extends DownloadUrlGenerator { + private static final String COOKIE = + "oraclelicense=accept-securebackup-cookie"; + + + @Override + public String buildUrl(String platform, String component, int train, int version, int update, + int build, String flavor, String hash) { + + if (!component.equalsIgnoreCase("jdk")) { + throw new RuntimeException("Can only generate JDK download URLs for Oracle."); + } + + String filename = getLocalFilename( + platform, + component, + train, + version, + update, + build, + flavor, + hash + ); + + String url = "http://download.oracle.com/otn-pub/java/jdk/" + + (update == 0 ? + String.format("%d-b%02d/", version, build) : + String.format("%du%d-b%02d/", version, update, build)); + + // URL format changed starting with 8u121 + if (update >= 121) { + url += hash + "/"; + } + + // Finally, add the filename to the end + url += filename; + + return url; + } + + public Optional getCookie() { + return Optional.of(COOKIE); + } + +} diff --git a/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java b/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java new file mode 100644 index 000000000..4a07fa990 --- /dev/null +++ b/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java @@ -0,0 +1,128 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2012-19 The Processing Foundation + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class AdoptOpenJdkDownloadUrlGeneratorTest { + + private static final String EXPECTED_WIN64_URL = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_x64_windows_hotspot_11.0.1_13.zip"; + private static final String EXPECTED_MAC_URL = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_x64_mac_hotspot_11.0.1_13.tar.gz"; + private static final String EXPECTED_LINUX_URL = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_x64_linux_hotspot_11.0.1_13.tar.gz"; + private static final String EXPECTED_LINUX_URL_ARM = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.1_13.tar.gz"; + + private static final String COMPONENT = "jdk"; + private static final int TRAIN = 11; + private static final int VERSION = 0; + private static final int UPDATE = 1; + private static final int BUILD = 13; + private static final String FLAVOR_SUFFIX = "-x64.tar.gz"; + private static final String HASH = ""; + + private AdoptOpenJdkDownloadUrlGenerator urlGenerator; + + @Before + public void setUp() throws Exception { + urlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); + } + + @Test + public void testBuildUrlWindows() { + String url = urlGenerator.buildUrl( + "windows64", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "windows" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_WIN64_URL, + url + ); + } + + @Test + public void testBuildUrlMac() { + String url = urlGenerator.buildUrl( + "macosx64", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "mac" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_MAC_URL, + url + ); + } + + @Test + public void testBuildUrlLinux64() { + String url = urlGenerator.buildUrl( + "linux64", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "linux64" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_LINUX_URL, + url + ); + } + + @Test + public void testBuildUrlLinuxArm() { + String url = urlGenerator.buildUrl( + "linuxArm", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "linuxArm" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_LINUX_URL_ARM, + url + ); + } + +} diff --git a/build/jre/test/GluonHqDownloadUrlGeneratorTest.java b/build/jre/test/GluonHqDownloadUrlGeneratorTest.java new file mode 100644 index 000000000..0f1ca2faa --- /dev/null +++ b/build/jre/test/GluonHqDownloadUrlGeneratorTest.java @@ -0,0 +1,108 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2012-19 The Processing Foundation + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class GluonHqDownloadUrlGeneratorTest { + + private static final String EXPECTED_WIN64_URL = "http://gluonhq.com/download/javafx-11-0-2-sdk-windows/"; + private static final String EXPECTED_MAC_URL = "http://gluonhq.com/download/javafx-11-0-2-sdk-mac"; + private static final String EXPECTED_LINUX_URL = "http://gluonhq.com/download/javafx-11-0-2-sdk-linux/"; + + private static final String COMPONENT = "jfx"; + private static final int TRAIN = 11; + private static final int VERSION = 0; + private static final int UPDATE = 2; + private static final int BUILD = 0; + private static final String FLAVOR_SUFFIX = ".zip"; + private static final String HASH = ""; + + private AdoptOpenJdkDownloadUrlGenerator urlGenerator; + + @Before + public void setUp() throws Exception { + urlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); + } + + @Test + public void testBuildUrlWindows() { + String url = urlGenerator.buildUrl( + "windows64", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "windows" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_WIN64_URL, + url + ); + } + + @Test + public void testBuildUrlMac() { + String url = urlGenerator.buildUrl( + "macosx64", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "mac" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_MAC_URL, + url + ); + } + + @Test + public void testBuildUrlLinux() { + String url = urlGenerator.buildUrl( + "linux64", + COMPONENT, + TRAIN, + VERSION, + UPDATE, + BUILD, + "linux64" + FLAVOR_SUFFIX, + HASH + ); + + assertEquals( + EXPECTED_LINUX_URL, + url + ); + } + +} diff --git a/build/jre/test/OracleDownloadUrlGeneratorTest.java b/build/jre/test/OracleDownloadUrlGeneratorTest.java new file mode 100644 index 000000000..2124c210f --- /dev/null +++ b/build/jre/test/OracleDownloadUrlGeneratorTest.java @@ -0,0 +1,59 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2012-19 The Processing Foundation + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import static org.junit.Assert.assertEquals; + +public class OracleDownloadUrlGeneratorTest { + + private static final String EXPECTED_URL = "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-macosx-x64.dmg"; + + private OracleDownloadUrlGenerator urlGenerator; + + @Before + public void setUp() throws Exception { + urlGenerator = new OracleDownloadUrlGenerator(); + } + + @Test + public void testBuildUrl() { + String url = urlGenerator.buildUrl( + "macos", + "jdk", + 1, + 8, + 131, + 11, + "macosx-x64.dmg", + "d54c1d3a095b4ff2b6607d096fa80163" + ); + + assertEquals( + EXPECTED_URL, + url + ); + } + +} diff --git a/build/library/ant-contrib-0.6.jar b/build/library/ant-contrib-0.6.jar new file mode 100644 index 000000000..db90b0aae Binary files /dev/null and b/build/library/ant-contrib-0.6.jar differ diff --git a/build/library/ant-contrib-LICENSE.txt b/build/library/ant-contrib-LICENSE.txt new file mode 100644 index 000000000..4d8c2fb7a --- /dev/null +++ b/build/library/ant-contrib-LICENSE.txt @@ -0,0 +1,47 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001-2003 Ant-Contrib project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Ant-Contrib project (http://sourceforge.net/projects/ant-contrib)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The name Ant-Contrib must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact + * ant-contrib-developers@lists.sourceforge.net. + * + * 5. Products derived from this software may not be called "Ant-Contrib" + * nor may "Ant-Contrib" appear in their names without prior written + * permission of the Ant-Contrib project. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE ANT-CONTRIB PROJECT OR ITS + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ diff --git a/build/linux/processing b/build/linux/processing index 078b2428b..711147d91 100755 --- a/build/linux/processing +++ b/build/linux/processing @@ -1,11 +1,11 @@ #!/bin/sh -# This script runs Processing, using the JRE in the Processing +# This script runs Processing, using the JRE in the Processing # installation directory. # If your system needs a different version of Java than what's included # in the download, replace the 'java' folder with the contents of a new -# Oracle JRE (Java 8 only), or create a symlink named "java" in the +# Oracle JRE (Java 8 only), or create a symlink named "java" in the # Processing installation directory that points to the JRE home directory. # This must be a Sun/Oracle JDK. For more details, see here: # https://github.com/processing/processing/wiki/Supported-Platforms @@ -104,7 +104,7 @@ cmd_name='processing-java' if [ $current_name = $cmd_name ] then - java -Djna.nosys=true -Djava.ext.dirs="$APPDIR"/java/lib/ext -Xmx256m processing.mode.java.Commander "$@" + java -Djna.nosys=true -Xmx512m processing.mode.java.Commander "$@" exit $? else # Start Processing in the same directory as this script @@ -115,5 +115,5 @@ else fi cd "$APPDIR" - java -splash:lib/about-1x.png -Djna.nosys=true -Djava.ext.dirs="$APPDIR"/java/lib/ext -Xmx256m processing.app.Base "$SKETCH" & + java -splash:lib/about-1x.png -Djna.nosys=true -Xmx512m processing.app.Base "$SKETCH" & fi diff --git a/build/macosx/appbundler.jar b/build/macosx/appbundler.jar index 42cc8f18c..62a658d51 100644 Binary files a/build/macosx/appbundler.jar and b/build/macosx/appbundler.jar differ diff --git a/build/macosx/appbundler/README.md b/build/macosx/appbundler/README.md index 626dc3bab..84add4dba 100644 --- a/build/macosx/appbundler/README.md +++ b/build/macosx/appbundler/README.md @@ -1,13 +1,13 @@ appbundler ========== -This is a fork of the [infinitekind fork](https://bitbucket.org/infinitekind/appbundler) of Oracle's appbundler. +This is a fork of the [infinitekind fork](https://bitbucket.org/infinitekind/appbundler) of Oracle's appbundler. (Many thanks for their additional work!) This fork covers several additional features (ability to remove JavaFX -binaries, a rewritten Info.plist writer, etc). See changes in the commits to this source. +binaries, a rewritten Info.plist writer, etc). See changes in the commits to this source. appbundler itself is under the GPL v2 with classpath license. And here's the README from the [infinitekind fork](https://bitbucket.org/infinitekind/appbundler): -A fork of the [Java Application Bundler](https://svn.java.net/svn/appbundler~svn) +A fork of the [Java Application Bundler](https://svn.java.net/svn/appbundler~svn) with the following changes: - The native binary is created as universal (32/64) @@ -16,7 +16,7 @@ with the following changes: - Allows to specify the name of the executable instead of using the default `"JavaAppLauncher"` **(contributed by Karl von Randow)** - Adds `classpathref` support to the `bundleapp` task - Adds support for `JVMArchs` and `LSArchitecturePriority` keys -- Allows to specify a custom value for `CFBundleVersion` +- Allows to specify a custom value for `CFBundleVersion` - Allows specifying registered file extensions using `CFBundleDocumentTypes` - Passes to the Java application a set of environment variables with the paths of the OSX special folders and whether the application is running in the @@ -34,11 +34,11 @@ These are the environment variables passed to the JVM: Example: - - - + @@ -61,7 +61,7 @@ Example: icon="${bundle.icon}" name="Images" role="editor"> - + - - + @@ -90,7 +89,7 @@ questions. --> - + diff --git a/build/macosx/appbundler/doc/appbundler.html b/build/macosx/appbundler/doc/appbundler.html index aa4468487..5c213e908 100644 --- a/build/macosx/appbundler/doc/appbundler.html +++ b/build/macosx/appbundler/doc/appbundler.html @@ -73,6 +73,13 @@ questions. Corresponds to the CFBundleIconFile key in the Info.plist file. No + + hideDockIcon + Set to true to prevent display of the application icon on the Mac OS X dock. + Corresponds to the LSUIElement key in the Info.plist file. + (Details) + No + shortversion The release version number string for the application. @@ -100,10 +107,86 @@ questions. file. No + + privileged + Bool value if the bundled application is to be launched as privileged. + No + mainclassname The name of the bundled application's main class. + Yes, alternative to jnlplaunchername Yes + + + plistClassPaths + A comma-separated list of classpath-elements which are used for the java application. + $APP_ROOT is replaced by the path of the .app-bundle. Required only if not + the libraries specified by the classpath and librarypath should be used. + No + + + jvmRequired + Specifies the required Java virtual machine version. + No (defaults to 1.7) + + + jrePreferred + If set to true, a Java Runtime Edition is required for execution. If both jrePreferred and jdkPreferred are set true, then a JRE is preferred but a JDK ia also accepted. + No + + + jdkPreferred + If set to true, a Java Development Kit is required for execution. If both jrePreferred and jdkPreferred are set true, then a JRE is preferred but a JDK ia also accepted. + No + + + minimumSystemVersion + Indicates the minimum version of OS X required for this app to run. + Corresponds to the LSMinimumSystemVersion key in the Info.plist + file. + (Details) + No + + + jnlplaunchername + The name of the bundled applications's jnlp file. The file has to be be copied to the Contents/Java folder. It has to be present during execution of the application. This serves as option to deliver signed applications based upon JNLP files. The application can then be signed and the signature won't break when modifying the JNLP file. + No, alternative to mainclassname + + + workingdirectory + Specifies the working directory of the application. + $APP_ROOT is replaced by the path of the .app-bundle. + No + + + privileged + If set, the application is started with administrator privileges. + No + + + highResolutionCapable + Sets the High Resolution Capable flag. + Corresponds to the NSHighResolutionCapable key in the Info.plist + file. + No + + + supportsAutomaticGraphicsSwitching + Allow OpenGL applications to utilize the integrated GPU. + Corresponds to the NSSupportsAutomaticGraphicsSwitching key in the Info.plist + No + + + ignorePSN + If set to true, the -psn... arguments passed by the OS + to the application is filtered out. + No + + + isDebug + If set to true, additiona console output will be produced during startup. + No @@ -137,6 +220,23 @@ Entries will be copied to the Contents/MacOS/ folder of the generated b

option

Specifies a command-line option to be passed to the JVM at startup.

+

Options may be named, which allows the bundled Java program +itself to override the option (e.g. to adjust heap settings). Changes will take effect upon restart of the +application. Assuming your CFBundleIdentifier (settable via the attribute identifier) +is com.oracle.appbundler. Then you can override a named option by calling +

import java.util.prefs.Preferences; + [...] + Preferences jvmOptions = Preferences.userRoot().node("/com/oracle/appbundler/JVMOptions"); + jvmOptions.put("name", "value"); // use option name and desired value here + jvmOptions.flush(); +The corresponding entries will be stored in a file called +~/Library/Preferences/com.oracle.appbundler.plist. To manipulate the file +without Java's Preferences from the command line, you should use the tool +defaults. +For example, to add an entry via the command line, use: + defaults write com.oracle.appbundler /com/oracle/appbundler/ -dict-add JVMOptions/ '{"name"="value";}' +Of named options, only the value is passed to the JVM, not the name. The name merely serves as identifier. +

@@ -148,6 +248,11 @@ Entries will be copied to the Contents/MacOS/ folder of the generated b + + + + +
AttributeThe option value. Yes
nameThe option name.No

argument

@@ -165,6 +270,218 @@ Entries will be copied to the Contents/MacOS/ folder of the generated b +

environment

+

Specifies an environment variable set via LSEnvironment entry in the Info.plist file. See the + Apple Documentation for details.

+

The string $APP_ROOT will be replaced by the application bundle path in all environment variables on runtime.

+ + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
nameThe variable name.Yes
valueThe variable value.Yes
+ +

architecture

+

Specifies the elements of the LSArchitecturePriority array in Info.plist. +(Details)

+ + + + + + + + + + + +
AttributeDescriptionRequired
nameThe architecture name.Yes
+ +

plistentry

+

Adds an arbitrary entry to the generated Info.plist.

+ + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
keyThe entry's key.Yes
valueThe entry's value.Yes
typeThe entry's type.No (defaults to String)
+ + +

scheme

+

Specifies a protocol for which the bundled application should be registered as a handler.

+ + + + + + + + + + + +
AttributeDescriptionRequired
valueThe protocol scheme.Yes
+ +

bundledocument

+

Describes a document associated with your application.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionCorresponding CFBundleDocumentTypes keyRequired
contentTypesA comma-separated list of Uniform Type Identifiers defining each a supported file type. + If you reference custom filetypes, declare them using a typedeclaration. + If set, extensions and isPackage are ignored. See the UTI reference for a list of default UTIs.LSItemContentTypesYes (or extensions)
extensionsA comma-separated list of filename extensions (minus the leading period) to map to this document type.CFBundleTypeExtensionsYes (or contentTypes)
iconThe name of the icon file (.icns) to associate with this OS X document type.CFBundleTypeIconFileNo (But recommended)
nameThe abstract name for the document type.CFBundleTypeNameNo (But recommended)
roleThis key specifies the app's role with respect to the type. The value can be Editor, Viewer, Shell, or None.CFBundleTypeRoleNo (default: Editor)
handlerRankDetermines how Launch Services ranks this app among the apps that declare themselves editors or viewers of files of this type. The possible values are: Owner (this app is the creator of files of this type), Alternate (this app is a secondary viewer of files of this type), None (this app must never be used to open files of this type, but it accepts drops of files of this type), Default (default; this app doesn't accept drops of files of this type). LSHandlerRankNo
isPackageSpecifies whether the document is distributed as a bundle. If set to true, the bundle directory is treated as a file.LSTypeIsPackageNo (default: false)
exportableTypesA comma-separated list of Uniform Type Identifiers defining a supported file type to which this document can export its content. + If you reference custom filetypes, declare them using a typedeclaration. + See also the Additional Document Type Considerations of the Document-Based App Programming Guide for Mac. + NSExportableTypesNo
+ +

typedeclaration

+

Declares a new Uniform Type Identifier. +Required if you reference non-system UTIs in bundledocument's contentTypes or exportableTypes

. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionCorresponding UT...TypeDeclarations keyRequired
identifierThe unique UTI for the declared type. Following the reverse-DNS format beginning with com.companyName is a simple way to ensure uniqueness.UTTypeIdentifierYes
descriptionA user-visible description of this type.UTTypeDescriptionNo
iconThe name of the icon file (.icns) to associate with this UTI.UTTypeIconFileNo
referenceUrlThe URL of a reference document describing this type.UTTypeReferenceURLNo
conformsToA comma-separated list of UTIs to which this identifier conforms. + Although a custom UTI can conform to any UTI, public.data or com.apple.package must be at the root of the conformance hierarchy.UTTypeConformsToNo (defaults to public.data)
extensionsA comma-separated list of filename extensions (minus the leading period) to map to this UTI.UTTypeTagSpecification -> public.filename-extensionNo (but recommended)
mimeTypesA comma-separated list of mime types which identify this UTI.UTTypeTagSpecification -> public.mime-typeNo
osTypesComma-separated list of four-character codes formerly used to identify types. + Only specify OSTypes if you really know what you're doing.UTTypeTagSpecification -> com.apple.ostypeNo
importedIf set to true, the declaration is listed under the UTImportedTypeDeclarations key. + Otherwise, it is listed under UTExportedTypeDeclarations. + If your code relies on third-party UTI types that may not be present on the system, you should declare those UTIs as imported types.-No
+

Examples

Generate a launcher for the "Swing Set" demo, bundling the JRE defined by the JAVA_HOME environment variable with the resulting executable.

@@ -187,9 +504,57 @@ environment variable with the resulting executable.

<runtime dir="${env.JAVA_HOME}"/> <classpath file="/Library/Java/Demos/JFC/SwingSet2/SwingSet2.jar"/> <option value="-Dapple.laf.useScreenMenuBar=true"/> + <scheme value="mailto"/> </bundleapp> </target> +

Example 2: JNLP Launcher

+

Generate a launcher for a JNLP File, copy it into the package and sign the package. You need to have a Developer ID Profile to sign the application.

+

You can now dynamically modify the zip content (only the JNLP file), deliver it with your web service and the application should directly unpack and can be run

+
+<-- Define the appbundler task -->
+<taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask"/>
+
+<-- Create the app bundle -->
+<target name="bundle-swingset" depends="package">
+
+    <mkdir dir="./app">
+
+    <bundleapp outputdirectory="./app"
+        name="SwingSet2"
+        displayname="SwingSet 2"
+        identifier="com.oracle.javax.swing.SwingSet2"
+        shortversion="1.0"
+        icon="icon.icns"
+        applicationCategory="public.app-category.developer-tools"
+        jnlplaunchername="Contents/_CodeSignature/SwingSet2.jnlp">
+        
+        <value="-Xdock:icon=Contents/Resources/icon.icns" />
+        <option value="-Dapple.laf.useScreenMenuBar=true"/>
+    </bundleapp>
+
+    <!-- Optionally copy an original file -->
+    <copy todir="./SwingSet2.app/Contents/_CodeSignature" includeemptydirs="true" overwrite="false">
+        <fileset dir=".">
+            <include name="**/*.jnlp" />
+        </fileset>
+    </copy>
+	
+    <!-- Sign File -->
+    <exec executable="codesign" os="Mac OS X" failonerror="true">
+        <arg value="-f" />
+        <arg value="--deep" />
+        <arg value="-s" />
+        <arg value="Developer ID Application" />
+        <arg value="./app/SwingSet2.app" />
+    </exec>
+
+    <zip destfile="./SwingSet2.app.zip" basedir="${copyroot}/app"></zip>
+</target>
+
+
+
+
\ No newline at end of file diff --git a/build/macosx/appbundler/native/main.m b/build/macosx/appbundler/native/main.m index cfcc5a9e7..510c371d7 100644 --- a/build/macosx/appbundler/native/main.m +++ b/build/macosx/appbundler/native/main.m @@ -27,6 +27,7 @@ #import #include #include +#include #define JAVA_LAUNCH_ERROR "JavaLaunchError" @@ -34,15 +35,34 @@ #define WORKING_DIR "WorkingDirectory" #define JVM_MAIN_CLASS_NAME_KEY "JVMMainClassName" #define JVM_OPTIONS_KEY "JVMOptions" +#define JVM_DEFAULT_OPTIONS_KEY "JVMDefaultOptions" #define JVM_ARGUMENTS_KEY "JVMArguments" +#define JVM_CLASSPATH_KEY "JVMClassPath" +#define JVM_VERSION_KEY "JVMVersion" +#define JRE_PREFERRED_KEY "JREPreferred" +#define JDK_PREFERRED_KEY "JDKPreferred" +#define JVM_DEBUG_KEY "JVMDebug" +#define IGNORE_PSN_KEY "IgnorePSN" #define JVM_RUN_PRIVILEGED "JVMRunPrivileged" +#define JVM_RUN_JNLP "JVMJNLPLauncher" +#define JVM_RUN_JAR "JVMJARLauncher" + #define UNSPECIFIED_ERROR "An unknown error occurred." #define APP_ROOT_PREFIX "$APP_ROOT" +#define JVM_RUNTIME "$JVM_RUNTIME" -#define LIBJLI_DYLIB "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib" +#define JAVA_RUNTIME "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" +#define LIBJLI_DY_LIB "lib/jli/libjli.dylib" +#define DEPLOY_LIB "lib/deploy.jar" + +//* + #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) +/*/ + #define DLog(...) do { } while (0) +//*/ typedef int (JNICALL *JLI_Launch_t)(int argc, char ** argv, int jargc, const char** jargv, @@ -56,15 +76,32 @@ typedef int (JNICALL *JLI_Launch_t)(int argc, char ** argv, jboolean javaw, jint ergo); -int launch(char *); +static char** progargv = NULL; +static int progargc = 0; +static int launchCount = 0; + +const char * tmpFile(); +int launch(char *, int, char **); + +NSString * findJavaDylib (NSString *, bool, bool, bool, bool); +NSString * findJREDylib (int, bool, bool); +NSString * findJDKDylib (int, bool, bool); +int extractMajorVersion (NSString *); +NSString * convertRelativeFilePath(NSString *); +NSString * addDirectoryToSystemArguments(NSUInteger, NSSearchPathDomainMask, NSString *, NSMutableArray *); +void addModifierFlagToSystemArguments(NSEventModifierFlags, NSString *, NSEventModifierFlags, NSMutableArray *); int main(int argc, char *argv[]) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int result; @try { - launch(argv[0]); + if ((argc > 1) && (launchCount == 0)) { + progargc = argc - 1; + progargv = &argv[1]; + } + + launch(argv[0], progargc, progargv); result = 0; } @catch (NSException *exception) { NSAlert *alert = [[NSAlert alloc] init]; @@ -80,14 +117,11 @@ int main(int argc, char *argv[]) { return result; } -int launch(char *commandName) { +int launch(char *commandName, int progargc, char *progargv[]) { - //Attempt to disable Inertia scroll - //From https://developer.apple.com/library/mac/releasenotes/DriversKernelHardware/RN-MagicMouse/ - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" - forKey:@"AppleMomentumScrollSupported"]; - [defaults registerDefaults:appDefaults]; + // Preparation for jnlp launcher arguments + const char *const_jargs = NULL; + const char *const_appclasspath = NULL; // Get the main bundle NSBundle *mainBundle = [NSBundle mainBundle]; @@ -95,39 +129,120 @@ int launch(char *commandName) { // Get the main bundle's info dictionary NSDictionary *infoDictionary = [mainBundle infoDictionary]; + // Test for debugging (but only on the second runthrough) + bool isDebugging = [[infoDictionary objectForKey:@JVM_DEBUG_KEY] boolValue]; + + if (isDebugging) { + DLog(@"\n\n\n\nLoading Application '%@'", [infoDictionary objectForKey:@"CFBundleName"]); + } + // Set the working directory based on config, defaulting to the user's home directory NSString *workingDir = [infoDictionary objectForKey:@WORKING_DIR]; if (workingDir != nil) { workingDir = [workingDir stringByReplacingOccurrencesOfString:@APP_ROOT_PREFIX withString:[mainBundle bundlePath]]; } else { - workingDir = NSHomeDirectory(); + workingDir = [[NSFileManager defaultManager] currentDirectoryPath]; + workingDir = NSHomeDirectory(); // REVIEW: Check which if these ones is realy the users home directory ... + } + if (isDebugging) { + DLog(@"Working Directory: '%@'", convertRelativeFilePath(workingDir)); } chdir([workingDir UTF8String]); // execute privileged NSString *privileged = [infoDictionary objectForKey:@JVM_RUN_PRIVILEGED]; - if (privileged != nil && getuid() != 0) { + if ( privileged != nil && getuid() != 0 ) { NSDictionary *error = [NSDictionary new]; + NSString *script = [NSString stringWithFormat:@"do shell script \"\\\"%@\\\" > /dev/null 2>&1 &\" with administrator privileges", [NSString stringWithCString:commandName encoding:NSASCIIStringEncoding]]; + + if (isDebugging) { + DLog(@"script: %@", script); + } + NSAppleScript *appleScript = [[NSAppleScript new] initWithSource:script]; if ([appleScript executeAndReturnError:&error]) { // This means we successfully elevated the application and can stop in here. - return 0; // Should this return 'error' instead? [fry] + return 0; } } // Locate the JLI_Launch() function NSString *runtime = [infoDictionary objectForKey:@JVM_RUNTIME_KEY]; + NSString *runtimePath = [[mainBundle builtInPlugInsPath] stringByAppendingPathComponent:runtime]; + + NSString *jvmRequired = [infoDictionary objectForKey:@JVM_VERSION_KEY]; + bool exactVersionMatch = false; + bool jrePreferred = [[infoDictionary objectForKey:@JRE_PREFERRED_KEY] boolValue]; + bool jdkPreferred = [[infoDictionary objectForKey:@JDK_PREFERRED_KEY] boolValue]; + + if (jrePreferred && jdkPreferred) { + DLog(@"Specifying both JRE- and JDK-preferred means neither is preferred"); + jrePreferred = false; + jdkPreferred = false; + } + + // check for jnlp launcher name + // This basically circumvents the security problems introduced with 10.8.4 that JNLP Files must be signed to execute them without CTRL+CLick -> Open + // See: How to sign (dynamic) JNLP files for OSX 10.8.4 and Gatekeeper http://stackoverflow.com/questions/16958130/how-to-sign-dynamic-jnlp-files-for-osx-10-8-4-and-gatekeeper + // There is no solution to properly sign a dynamic jnlp file to date. Both Apple and Oracle have open rdars/tickets on this. + // The following mechanism encapsulates a JNLP file/template. It makes a temporary copy when executing. This ensures that the JNLP file can be updates from the server at runtime. + // YES, this may insert additional security threats, but it is still the only way to avoid permission problems. + // It is highly recommended that the resulting .app container is being signed with a certificate from Apple - otherwise you will not need this mechanism. + // Moved up here to check if we want to launch a JNLP. If so: make sure the version is below 9 + NSString *jnlplauncher = [infoDictionary objectForKey:@JVM_RUN_JNLP]; + if ( jnlplauncher != nil ) { + int required = 8; + if ( jvmRequired != nil ) { + required = extractMajorVersion (jvmRequired); + if (required > 8) { required = 8; } + } + + exactVersionMatch = true; + jvmRequired = [NSString stringWithFormat:@"1.%i", required]; + DLog(@"Will Require a JVM version '%i' due to JNLP restrictions", required); + } + + NSString *javaDylib; + + // If a runtime is set, we really want it. If it is not there, we will fail later on. + if (runtime != nil) { + NSString *dylibRelPath = @"Contents/Home/jre"; + javaDylib = [[runtimePath stringByAppendingPathComponent:dylibRelPath] stringByAppendingPathComponent:@LIBJLI_DY_LIB]; + BOOL isDir; + NSFileManager *fm = [[NSFileManager alloc] init]; + BOOL javaDylibFileExists = [fm fileExistsAtPath:javaDylib isDirectory:&isDir]; + if (!javaDylibFileExists || isDir) { + dylibRelPath = @"Contents/Home"; + javaDylib = [[runtimePath stringByAppendingPathComponent:dylibRelPath] stringByAppendingPathComponent:@LIBJLI_DY_LIB]; + javaDylibFileExists = [fm fileExistsAtPath:javaDylib isDirectory:&isDir]; + if (!javaDylibFileExists || isDir) { + javaDylib = NULL; + } + } + if (isDebugging) { + DLog(@"Java Runtime (%@) Relative Path: '%@' (dylib: %@)", runtime, runtimePath, javaDylib); + } + } + else { + // Search for the runtimePath, then make it a libjli.dylib path. + runtimePath = findJavaDylib (jvmRequired, jrePreferred, jdkPreferred, isDebugging, exactVersionMatch); + javaDylib = [runtimePath stringByAppendingPathComponent:@LIBJLI_DY_LIB]; + + if (isDebugging) { + DLog(@"Java Runtime Dylib Path: '%@'", convertRelativeFilePath(javaDylib)); + } + } const char *libjliPath = NULL; - if (runtime != nil) { - NSString *runtimePath = [[[NSBundle mainBundle] builtInPlugInsPath] stringByAppendingPathComponent:runtime]; - libjliPath = [[runtimePath stringByAppendingPathComponent:@"Contents/Home/jre/lib/jli/libjli.dylib"] fileSystemRepresentation]; - } else { - libjliPath = LIBJLI_DYLIB; + if (javaDylib != nil) + { + libjliPath = [javaDylib fileSystemRepresentation]; } + DLog(@"Launchpath: %s", libjliPath); + void *libJLI = dlopen(libjliPath, RTLD_LAZY); JLI_Launch_t jli_LaunchFxnPtr = NULL; @@ -136,123 +251,338 @@ int launch(char *commandName) { } if (jli_LaunchFxnPtr == NULL) { + NSString *msg; + + if (runtime == nil && jvmRequired != nil) { + int required = extractMajorVersion (jvmRequired); + + if (required < 7) { required = 7; } + + if (jdkPreferred) { + NSString *msga = NSLocalizedString(@"JDKxLoadFullError", @UNSPECIFIED_ERROR); + msg = [NSString stringWithFormat:msga, required]; + } + else { + NSString *msga = NSLocalizedString(@"JRExLoadFullError", @UNSPECIFIED_ERROR); + msg = [NSString stringWithFormat:msga, required]; + } + } + else { + msg = NSLocalizedString(@"JRELoadError", @UNSPECIFIED_ERROR); + } + + DLog(@"Error launching JVM Runtime (%@) Relative Path: '%@' (dylib: %@)\n error: %@", + runtime, runtimePath, javaDylib, msg); + [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR - reason:NSLocalizedString(@"JRELoadError", @UNSPECIFIED_ERROR) - userInfo:nil] raise]; + reason:msg userInfo:nil] raise]; } + // Set the class path + NSFileManager *defaultFileManager = [NSFileManager defaultManager]; + NSString *mainBundlePath = [mainBundle bundlePath]; + + // make sure the bundle path does not contain a colon, as that messes up the java.class.path, + // because colons are used a path separators and cannot be escaped. + + // funny enough, Finder does not let you create folder with colons in their names, + // but when you create a folder with a slash, e.g. "audio/video", it is accepted + // and turned into... you guessed it, a colon: + // "audio:video" + if ([mainBundlePath rangeOfString:@":"].location != NSNotFound) { + [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR + reason:NSLocalizedString(@"BundlePathContainsColon", @UNSPECIFIED_ERROR) + userInfo:nil] raise]; + } + if (isDebugging) { + NSLog(@"Main Bundle Path: '%@'", mainBundlePath); + } + + // Set the class path + NSString *javaPath = [mainBundlePath stringByAppendingString:@"/Contents/Java"]; + NSMutableArray *systemArguments = [[NSMutableArray alloc] init]; + NSMutableString *classPath = [NSMutableString stringWithString:@"-Djava.class.path="]; + + // Set the library path + NSString *libraryPath = [NSString stringWithFormat:@"-Djava.library.path=%@/Contents/MacOS", mainBundlePath]; + [systemArguments addObject:libraryPath]; + + // Get the VM options + NSMutableArray *options = [[infoDictionary objectForKey:@JVM_OPTIONS_KEY] mutableCopy]; + if (options == nil) { + options = [NSMutableArray array]; + } + + // Get the VM default options + NSArray *defaultOptions = [NSArray array]; + NSDictionary *defaultOptionsDict = [infoDictionary objectForKey:@JVM_DEFAULT_OPTIONS_KEY]; + if (defaultOptionsDict != nil) { + NSMutableDictionary *defaults = [NSMutableDictionary dictionaryWithDictionary: defaultOptionsDict]; + // Replace default options with user specific options, if available + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + // Create special key that should be used by Java's java.util.Preferences impl + // Requires us to use "/" + bundleIdentifier.replace('.', '/') + "/JVMOptions/" as node on the Java side + // Beware: bundleIdentifiers shorter than 3 segments are placed in a different file! + // See java/util/prefs/MacOSXPreferences.java of OpenJDK for details + NSString *bundleDictionaryKey = [mainBundle bundleIdentifier]; + bundleDictionaryKey = [bundleDictionaryKey stringByReplacingOccurrencesOfString:@"." withString:@"/"]; + bundleDictionaryKey = [NSString stringWithFormat: @"/%@/", bundleDictionaryKey]; + + NSDictionary *bundleDictionary = [userDefaults dictionaryForKey: bundleDictionaryKey]; + if (bundleDictionary != nil) { + NSDictionary *jvmOptionsDictionary = [bundleDictionary objectForKey: @"JVMOptions/"]; + for (NSString *key in jvmOptionsDictionary) { + NSString *value = [jvmOptionsDictionary objectForKey:key]; + [defaults setObject: value forKey: key]; + } + } + defaultOptions = [defaults allValues]; + } + + // Get the application arguments + NSMutableArray *arguments = [[infoDictionary objectForKey:@JVM_ARGUMENTS_KEY] mutableCopy]; + if (arguments == nil) { + arguments = [NSMutableArray array]; + } + + // Check for a defined JAR File below the Contents/Java folder + // If set, use this instead of a classpath setting + NSString *jarlauncher = [infoDictionary objectForKey:@JVM_RUN_JAR]; + // Get the main class name NSString *mainClassName = [infoDictionary objectForKey:@JVM_MAIN_CLASS_NAME_KEY]; - if (mainClassName == nil) { + + if ( jnlplauncher != nil ) { + + const_appclasspath = [[runtimePath stringByAppendingPathComponent:@DEPLOY_LIB] fileSystemRepresentation]; + + // JNLP Launcher found, need to modify quite a bit now + [options addObject:@"-classpath"]; + [options addObject:[NSString stringWithFormat:@"%s", const_appclasspath]]; + + // unset the original classpath + classPath = nil; + + // Main Class is javaws + mainClassName=@"com.sun.javaws.Main"; + + // Optional stuff that javaws would do as well + [options addObject:@"-Dsun.awt.warmup=true"]; + [options addObject:@"-Xverify:remote"]; + [options addObject:@"-Djnlpx.remove=true"]; + [options addObject:@"-DtrustProxy=true"]; + + [options addObject:[NSString stringWithFormat:@"-Djava.security.policy=file:%@/lib/security/javaws.policy", runtimePath]]; + [options addObject:[NSString stringWithFormat:@"-Xbootclasspath/a:%@/lib/javaws.jar:%@/lib/deploy.jar:%@/lib/plugin.jar", runtimePath, runtimePath, runtimePath]]; + + // Argument that javaws does also + // [arguments addObject:@"-noWebStart"]; + + // Copy the jnlp to a temporary location + NSError *copyerror = nil; + NSString *tempFileName = [NSString stringWithCString:tmpFile() encoding:NSASCIIStringEncoding]; + // File now exists. + [defaultFileManager removeItemAtPath:tempFileName error:NULL]; + + // Check if this is absolute or relative (else) + NSString *jnlpPath = [mainBundlePath stringByAppendingPathComponent:jnlplauncher]; + if ( ![defaultFileManager fileExistsAtPath:jnlpPath] ) { + jnlpPath = [javaPath stringByAppendingPathComponent:jnlplauncher]; + } + + [defaultFileManager copyItemAtURL:[NSURL fileURLWithPath:jnlpPath] toURL:[NSURL fileURLWithPath:tempFileName] error:©error]; + if ( copyerror != nil ) { + NSLog(@"Error: %@", copyerror); + [[NSException exceptionWithName:@"Error while copying JNLP File" + reason:@"File copy error" + userInfo:copyerror.userInfo] raise]; + } + + // Add the jnlp as argument so that javaws.Main can read and delete it + [arguments addObject:tempFileName]; + + } else + // Either mainClassName or jarLauncher has to be set since this is not a jnlpLauncher + if ( mainClassName == nil && jarlauncher == nil ) { [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR reason:NSLocalizedString(@"MainClassNameRequired", @UNSPECIFIED_ERROR) userInfo:nil] raise]; } - // Set the class path - NSString *mainBundlePath = [mainBundle bundlePath]; - NSString *javaPath = - [mainBundlePath stringByAppendingString:@"/Contents/Java"]; - // Changed Contents/Java to the old Contents/Resources/Java [fry] - //[mainBundlePath stringByAppendingString:@"/Contents/Resources/Java"]; - // Removed the /Classes, because the P5 compiler (ECJ?) will throw an - // error if it doesn't exist. But it's harmless to leave the root dir, - // since it will always exist, and I guess if you wanted to put .class - // files in there, they'd work. If I knew more Cocoa, I'd just make this - // an empty string to start, to be appended a few lines later. [fry] - //NSMutableString *classPath = [NSMutableString stringWithFormat:@"-Djava.class.path=%@/Classes", javaPath]; - NSMutableString *classPath = [NSMutableString stringWithFormat:@"-Djava.class.path=%@", javaPath]; - - NSFileManager *defaultFileManager = [NSFileManager defaultManager]; - NSArray *javaDirectoryContents = - [defaultFileManager contentsOfDirectoryAtPath:javaPath error:nil]; - if (javaDirectoryContents == nil) { - [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR - reason:NSLocalizedString(@"JavaDirectoryNotFound", @UNSPECIFIED_ERROR) - userInfo:nil] raise]; + if (isDebugging) { + DLog(@"Main Class Name: '%@'", mainClassName); } - for (NSString *file in javaDirectoryContents) { - if ([file hasSuffix:@".jar"]) { - [classPath appendFormat:@":%@/%@", javaPath, file]; + // If a jar file is defined as launcher, disacard the javaPath + if ( jarlauncher != nil ) { + [classPath appendFormat:@":%@/%@", javaPath, jarlauncher]; + } else { + + NSArray *cp = [infoDictionary objectForKey:@JVM_CLASSPATH_KEY]; + if (cp == nil) { + + // Implicit classpath, so use the contents of the "Java" folder to build an explicit classpath + + [classPath appendFormat:@"%@/Classes", javaPath]; + NSFileManager *defaultFileManager = [NSFileManager defaultManager]; + NSArray *javaDirectoryContents = [defaultFileManager contentsOfDirectoryAtPath:javaPath error:nil]; + if (javaDirectoryContents == nil) { + [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR + reason:NSLocalizedString(@"JavaDirectoryNotFound", @UNSPECIFIED_ERROR) + userInfo:nil] raise]; + } + + for (NSString *file in javaDirectoryContents) { + if ([file hasSuffix:@".jar"]) { + [classPath appendFormat:@":%@/%@", javaPath, file]; + } + } + + } else { + + // Explicit ClassPath + + int k = 0; + for (NSString *file in cp) { + if (k++ > 0) [classPath appendString:@":"]; // add separator if needed + file = [file stringByReplacingOccurrencesOfString:@APP_ROOT_PREFIX withString:[mainBundle bundlePath]]; + [classPath appendString:file]; + } } } - /* - // search the 'lib' subfolder as well [fry] - NSString *libPath = - [mainBundlePath stringByAppendingString:@"/Contents/Resources/Java/lib"]; - NSArray *libDirectoryContents = - [defaultFileManager contentsOfDirectoryAtPath:libPath error:nil]; - if (libDirectoryContents != nil) { - for (NSString *file in libDirectoryContents) { - if ([file hasSuffix:@".jar"]) { - [classPath appendFormat:@":%@/%@", libPath, file]; - } - } - } - */ - - // Set the library path - NSString *libraryPath = [NSString stringWithFormat:@"-Djava.library.path=:%@/Contents/Java:%@/Contents/MacOS", mainBundlePath, mainBundlePath]; - - // Get the VM options - NSArray *options = [infoDictionary objectForKey:@JVM_OPTIONS_KEY]; - if (options == nil) { - options = [NSArray array]; - } - - // Get the application arguments - NSArray *arguments = [infoDictionary objectForKey:@JVM_ARGUMENTS_KEY]; - if (arguments == nil) { - arguments = [NSArray array]; + if ( classPath != nil ) { + [systemArguments addObject:classPath]; } // Set OSX special folders - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, - NSUserDomainMask, YES); - NSString *basePath = [paths objectAtIndex:0]; - NSString *libraryDirectory = [NSString stringWithFormat:@"-DLibraryDirectory=%@", basePath]; + NSString * libraryDirectory = addDirectoryToSystemArguments(NSLibraryDirectory, NSUserDomainMask, @"LibraryDirectory", systemArguments); + addDirectoryToSystemArguments(NSDocumentDirectory, NSUserDomainMask, @"DocumentsDirectory", systemArguments); + addDirectoryToSystemArguments(NSApplicationSupportDirectory, NSUserDomainMask, @"ApplicationSupportDirectory", systemArguments); + addDirectoryToSystemArguments(NSCachesDirectory, NSUserDomainMask, @"CachesDirectory", systemArguments); + addDirectoryToSystemArguments(NSApplicationDirectory, NSUserDomainMask, @"ApplicationDirectory", systemArguments); + addDirectoryToSystemArguments(NSAutosavedInformationDirectory, NSUserDomainMask, @"AutosavedInformationDirectory", systemArguments); + addDirectoryToSystemArguments(NSDesktopDirectory, NSUserDomainMask, @"DesktopDirectory", systemArguments); + addDirectoryToSystemArguments(NSDownloadsDirectory, NSUserDomainMask, @"DownloadsDirectory", systemArguments); + addDirectoryToSystemArguments(NSMoviesDirectory, NSUserDomainMask, @"MoviesDirectory", systemArguments); + addDirectoryToSystemArguments(NSMusicDirectory, NSUserDomainMask, @"MusicDirectory", systemArguments); + addDirectoryToSystemArguments(NSPicturesDirectory, NSUserDomainMask, @"PicturesDirectory", systemArguments); + addDirectoryToSystemArguments(NSSharedPublicDirectory, NSUserDomainMask, @"SharedPublicDirectory", systemArguments); - paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, - NSUserDomainMask, YES); - basePath = [paths objectAtIndex:0]; - NSString *documentsDirectory = [NSString stringWithFormat:@"-DDocumentsDirectory=%@", basePath]; + addDirectoryToSystemArguments(NSLibraryDirectory, NSLocalDomainMask, @"SystemLibraryDirectory", systemArguments); + addDirectoryToSystemArguments(NSApplicationSupportDirectory, NSLocalDomainMask, @"SystemApplicationSupportDirectory", systemArguments); + addDirectoryToSystemArguments(NSCachesDirectory, NSLocalDomainMask, @"SystemCachesDirectory", systemArguments); + addDirectoryToSystemArguments(NSApplicationDirectory, NSLocalDomainMask, @"SystemApplicationDirectory", systemArguments); + addDirectoryToSystemArguments(NSUserDirectory, NSLocalDomainMask, @"SystemUserDirectory", systemArguments); - paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, - NSUserDomainMask, YES); - basePath = [paths objectAtIndex:0]; - NSString *applicationSupportDirectory = [NSString stringWithFormat:@"-DApplicationSupportDirectory=%@", basePath]; + // get the user's home directory, independent of the sandbox container + int bufsize; + if ((bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) != -1) { + char buffer[bufsize]; + struct passwd pwd, *result = NULL; + if (getpwuid_r(getuid(), &pwd, buffer, bufsize, &result) == 0 && result) { + [systemArguments addObject:[NSString stringWithFormat:@"-DUserHome=%s", pwd.pw_dir]]; + } + } - paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, - NSUserDomainMask, YES); - basePath = [paths objectAtIndex:0]; - NSString *cachesDirectory = [NSString stringWithFormat:@"-DCachesDirectory=%@", basePath]; - - NSString *sandboxEnabled = @"true"; - if ([basePath rangeOfString:@"Containers"].location == NSNotFound) { - sandboxEnabled = @"false"; + //Sandbox + NSString *containersDirectory = [libraryDirectory stringByAppendingPathComponent:@"Containers"]; + NSString *sandboxEnabled = @"false"; + BOOL isDir; + NSFileManager *fm = [[NSFileManager alloc] init]; + BOOL containersDirExists = [fm fileExistsAtPath:containersDirectory isDirectory:&isDir]; + if (containersDirExists && isDir) { + sandboxEnabled = @"true"; } NSString *sandboxEnabledVar = [NSString stringWithFormat:@"-DSandboxEnabled=%@", sandboxEnabled]; + [systemArguments addObject:sandboxEnabledVar]; + + + // Mojave Dark Mode enabled? + NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; + BOOL isDarkMode = (osxMode != nil && [osxMode isEqualToString:@"Dark"]); + + NSString *darkModeEnabledVar = [NSString stringWithFormat:@"-DDarkMode=%s", + (isDarkMode ? "true" : "false")]; + [systemArguments addObject:darkModeEnabledVar]; + + // Check for modifier keys on app launch + + // Since [NSEvent modifierFlags] is only available since OS X 10.6., only add properties if supported. + if ([NSEvent respondsToSelector:@selector(modifierFlags)]) { + NSEventModifierFlags launchModifierFlags = [NSEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; + + [systemArguments addObject:[NSString stringWithFormat:@"-DLaunchModifierFlags=%lu", (unsigned long)launchModifierFlags]]; + + addModifierFlagToSystemArguments(NSEventModifierFlagCapsLock, @"LaunchModifierFlagCapsLock", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagShift, @"LaunchModifierFlagShift", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagControl, @"LaunchModifierFlagControl", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagOption, @"LaunchModifierFlagOption", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagCommand, @"LaunchModifierFlagCommand", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagNumericPad, @"LaunchModifierFlagNumericPad", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagHelp, @"LaunchModifierFlagHelp", launchModifierFlags, systemArguments); + addModifierFlagToSystemArguments(NSEventModifierFlagFunction, @"LaunchModifierFlagFunction", launchModifierFlags, systemArguments); + } + + + + // Remove -psn argument + int newProgargc = progargc; + char *newProgargv[newProgargc]; + for (int i = 0; i < progargc; i++) { + newProgargv[i] = progargv[i]; + } + + bool ignorePSN = [[infoDictionary objectForKey:@IGNORE_PSN_KEY] boolValue]; + if (ignorePSN) { + NSString *psnRegexp = @"^-psn_\\d_\\d+$"; + NSPredicate *psnTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", psnRegexp]; + + int shift = 0; + int i = 0; + while (i < newProgargc) { + NSString *s = [NSString stringWithFormat:@"%s", newProgargv[i]]; + if ([psnTest evaluateWithObject: s]){ + shift++; + newProgargc--; + } + newProgargv[i] = newProgargv[i+shift]; + i++; + } + } + + // replace $APP_ROOT in environment variables + NSDictionary* environment = [[NSProcessInfo processInfo] environment]; + for (NSString* key in environment) { + NSString* value = [environment objectForKey:key]; + NSString* newValue = [value stringByReplacingOccurrencesOfString:@APP_ROOT_PREFIX withString:[mainBundle bundlePath]]; + if (! [newValue isEqualToString:value]) { + setenv([key UTF8String], [newValue UTF8String], 1); + } + } // Initialize the arguments to JLI_Launch() // +5 due to the special directories and the sandbox enabled property - int argc = 1 + [options count] + 2 + [arguments count] + 1 + 5; + int argc = 1 + [systemArguments count] + [options count] + [defaultOptions count] + 1 + [arguments count] + newProgargc; char *argv[argc]; int i = 0; argv[i++] = commandName; - argv[i++] = strdup([classPath UTF8String]); - argv[i++] = strdup([libraryPath UTF8String]); - argv[i++] = strdup([libraryDirectory UTF8String]); - argv[i++] = strdup([documentsDirectory UTF8String]); - argv[i++] = strdup([applicationSupportDirectory UTF8String]); - argv[i++] = strdup([cachesDirectory UTF8String]); - argv[i++] = strdup([sandboxEnabledVar UTF8String]); + for (NSString *systemArgument in systemArguments) { + argv[i++] = strdup([systemArgument UTF8String]); + } for (NSString *option in options) { option = [option stringByReplacingOccurrencesOfString:@APP_ROOT_PREFIX withString:[mainBundle bundlePath]]; + option = [option stringByReplacingOccurrencesOfString:@JVM_RUNTIME withString:runtimePath]; argv[i++] = strdup([option UTF8String]); + if (isDebugging) { DLog(@"Option: %@",option); } + } + + for (NSString *defaultOption in defaultOptions) { + defaultOption = [defaultOption stringByReplacingOccurrencesOfString:@APP_ROOT_PREFIX withString:[mainBundle bundlePath]]; + argv[i++] = strdup([defaultOption UTF8String]); + if (isDebugging) { DLog(@"DefaultOption: %@",defaultOption); } } argv[i++] = strdup([mainClassName UTF8String]); @@ -262,16 +592,361 @@ int launch(char *commandName) { argv[i++] = strdup([argument UTF8String]); } + int ctr = 0; + for (ctr = 0; ctr < newProgargc; ctr++) { + argv[i++] = newProgargv[ctr]; + } + + // Print the full command line for debugging purposes... + if (isDebugging) { + DLog(@"Command line passed to application:"); + int j=0; + for(j=0; j= jvmRequired && !exactMatch) || (version == jvmRequired && exactMatch) ) { + if (isDebugging) { + DLog (@"JRE version qualifies"); + } + return @JAVA_RUNTIME; + } + } + } + @catch (NSException *exception) + { + DLog (@"JRE search exception: '%@'", [exception reason]); + } + + return nil; +} + +// Having failed to find a JRE in the usual location, see if a JDK is installed +// (probably in /Library/Java/JavaVirtualMachines). If so, return address of +// dylib in the JRE within the JDK. +/** + * Searches for a JDK dylib of the specified version or later. + */ +NSString * findJDKDylib ( + int jvmRequired, + bool isDebugging, + bool exactMatch) +{ + @try + { + NSTask *task = [[NSTask alloc] init]; + [task setLaunchPath:@"/usr/libexec/java_home"]; + + NSArray *args = [NSArray arrayWithObjects: @"-v", [NSString stringWithFormat:@"1.%i%@", jvmRequired, exactMatch?@"":@"+"], nil]; + [task setArguments:args]; + + NSPipe *stdout = [NSPipe pipe]; + [task setStandardOutput:stdout]; + + NSPipe *stderr = [NSPipe pipe]; + [task setStandardError:stderr]; + + [task setStandardInput:[NSPipe pipe]]; + + NSFileHandle *outHandle = [stdout fileHandleForReading]; + NSFileHandle *errHandle = [stderr fileHandleForReading]; + + [task launch]; + [task waitUntilExit]; + [task release]; + + NSData *data1 = [outHandle readDataToEndOfFile]; + NSData *data2 = [errHandle readDataToEndOfFile]; + + NSString *outRead = [[NSString alloc] initWithData:data1 + encoding:NSUTF8StringEncoding]; + NSString *errRead = [[NSString alloc] initWithData:data2 + encoding:NSUTF8StringEncoding]; + + // If matching JDK not found, outRead will include something like + // "Unable to find any JVMs matching version "1.X"." + if ( errRead != nil + && [errRead rangeOfString:@"Unable"].location != NSNotFound ) + { + if (isDebugging) { DLog (@"No matching JDK found."); } + return nil; + } + + int version = 0; + + NSRange vrange = [outRead rangeOfString:@"jdk1."]; + if (vrange.location == NSNotFound) { + // try the changed version layout from version 9 + vrange = [outRead rangeOfString:@"jdk-"]; + vrange.location += 4; + } else { + // otherwise remove the leading jdk + vrange.location += 3; + } + + if (vrange.location != NSNotFound) { + NSString *vstring = [outRead substringFromIndex:(vrange.location)]; + + vrange = [vstring rangeOfString:@"/"]; + vstring = [vstring substringToIndex:vrange.location]; + + version = extractMajorVersion(vstring); + + if (isDebugging) { + DLog (@"Found a Java %@ JDK", vstring); + DLog (@"Looks like major version %d", extractMajorVersion(vstring)); + } + } + + if ( (version >= jvmRequired && !exactMatch) || (version == jvmRequired && exactMatch) ) { + if (isDebugging) { + DLog (@"JDK version qualifies"); + } + + NSString *outread2 = [outRead stringByTrimmingCharactersInSet:[NSCharacterSet + whitespaceAndNewlineCharacterSet]]; + + // Return location where LIBJLI_DY_LIB is located. Note that the path was + // shortemed between JDK 8 and JDK 9. + if (version > 8) { + return outread2; + } + else { + return [outread2 stringByAppendingPathComponent:@"jre"]; + } + } + } + @catch (NSException *exception) + { + DLog (@"JDK search exception: '%@'", [exception reason]); + } + + return nil; +} + + +/** + * Extract the Java major version number from a string. We expect the input + * to look like either either "1.X", "1.X.Y_ZZ" or "X.Y.ZZ", and the + * returned result will be the integral value of X. Any failure to parse the + * string will return 0. + */ +int extractMajorVersion (NSString *vstring) { + if (vstring == nil) { return 0; } + + // Expecting either a java version of form 1.X, 1.X.Y_ZZ or jdk1.X.Y_ZZ. + // Strip everything from start and ending that aren't part of the version number + NSCharacterSet* nonDigits = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet]; + vstring = [vstring stringByTrimmingCharactersInSet:nonDigits]; + + if([vstring hasPrefix:@"1."]) { // this is the version < 9 layout. Remove the leading "1." + vstring = [vstring substringFromIndex:2]; + } + + // the next integer token should be the major version, so read everything up to the first decimal point, if any + NSUInteger versionEndLoc = [vstring rangeOfString:@"."].location; + if (versionEndLoc != NSNotFound) { + vstring = [vstring substringToIndex:versionEndLoc]; + } + + return [vstring intValue]; +} + + +NSString * convertRelativeFilePath(NSString * path) { + return [path stringByStandardizingPath]; +} + +NSString * addDirectoryToSystemArguments(NSUInteger searchPath, NSSearchPathDomainMask domainMask, + NSString *systemProperty, NSMutableArray *systemArguments) { + NSArray *paths = NSSearchPathForDirectoriesInDomains(searchPath,domainMask, YES); + if ([paths count] > 0) { + NSString *basePath = [paths objectAtIndex:0]; + NSString *directory = [NSString stringWithFormat:@"-D%@=%@", systemProperty, basePath]; + [systemArguments addObject:directory]; + return basePath; + } + return nil; +} + +void addModifierFlagToSystemArguments(NSEventModifierFlags mask, NSString *systemProperty, NSEventModifierFlags modifierFlags, NSMutableArray *systemArguments) { + NSString *modifierFlagValue = (modifierFlags & mask) ? @"true" : @"false"; + NSString *modifierFlagVar = [NSString stringWithFormat:@"-D%@=%@", systemProperty, modifierFlagValue]; + [systemArguments addObject:modifierFlagVar]; +} diff --git a/build/macosx/appbundler/res/de.lproj/Localizable.strings b/build/macosx/appbundler/res/de.lproj/Localizable.strings new file mode 100644 index 000000000..59f745d0c --- /dev/null +++ b/build/macosx/appbundler/res/de.lproj/Localizable.strings @@ -0,0 +1,7 @@ +"JRELoadError" = "Die Java Laufzeitumgebung konnte nicht geladen werden."; +"JRExLoadError" = "Die Java %d Laufzeitumgebung konnte nicht geladen werden."; +"JRExLoadFullError" = "Diese Anwendung benötigt die Java %d Laufzeitumgebung oder höher auf Ihrem Computer installiert sein. Bitte installieren Sie die neueste Version von Java von www.java.com und erneut versuchen."; +"JDKxLoadFullError" = "Diese Anwendung benötigt die Java %d Laufzeitumgebung oder höher auf Ihrem Computer installiert sein. Bitte installieren Sie die neueste JDK von Oracle.com und erneut versuchen."; +"MainClassNameRequired" = "Hauptklassenname ist erforderlich."; +"JavaDirectoryNotFound" = "Das Java Verzeichnis ist nicht vorhanden."; +"BundlePathContainsColon" = "Kann nicht vom einem Ordner aus starten, der \"/\" in seinem Namen enthält."; diff --git a/build/macosx/appbundler/res/en.lproj/Localizable.strings b/build/macosx/appbundler/res/en.lproj/Localizable.strings index 0d306aaaf..b052770d6 100644 --- a/build/macosx/appbundler/res/en.lproj/Localizable.strings +++ b/build/macosx/appbundler/res/en.lproj/Localizable.strings @@ -1,3 +1,7 @@ "JRELoadError" = "Unable to load Java Runtime Environment."; +"JRExLoadError" = "Unable to load a Java %d Runtime Environment."; +"JRExLoadFullError" = "This application requires that Java %d or later be installed on your computer. Please download and install the latest version of Java from www.java.com and try again."; +"JDKxLoadFullError" = "This application requires that a Java %d JDK or later be installed on your computer. Please download and install the latest Java JDK from Oracle.com and try again."; "MainClassNameRequired" = "Main class name is required."; "JavaDirectoryNotFound" = "Unable to enumerate Java directory contents."; +"BundlePathContainsColon" = "Cannot launch from folder that contains a \"/\" in its name."; diff --git a/build/macosx/appbundler/res/fr.lproj/Localizable.strings b/build/macosx/appbundler/res/fr.lproj/Localizable.strings new file mode 100644 index 000000000..693b44a37 --- /dev/null +++ b/build/macosx/appbundler/res/fr.lproj/Localizable.strings @@ -0,0 +1,7 @@ +"JRELoadError" = "Impossible d'utiliser un environnement Java."; +"JRExLoadError" = "Impossible d'utiliser un environnement Java %d."; +"JRExLoadFullError" = "Ce logiciel nécessite que Java %d ou plus récent être installés sur votre ordinateur. S'il vous plaît télécharger et installer la dernière version de Java à partir de www.java.com et essayez à nouveau."; +"JDKxLoadFullError" = "Ce logiciel nécessite que Java %d JDK ou plus récent être installés sur votre ordinateur. S'il vous plaît télécharger et installer le JDK plus récente de Oracle.com et essayez à nouveau."; +"MainClassNameRequired" = "Principal nom de classe est nécessaire."; +"JavaDirectoryNotFound" = "Impossible d'énumérer répertoire Java contenu."; +"BundlePathContainsColon" = "Pas de commencer à partir d'un dossier qui contient un \"/\" dans son nom."; \ No newline at end of file diff --git a/build/macosx/appbundler/src/com/oracle/appbundler/AppBundlerTask.java b/build/macosx/appbundler/src/com/oracle/appbundler/AppBundlerTask.java index df4c26bc7..dada42075 100644 --- a/build/macosx/appbundler/src/com/oracle/appbundler/AppBundlerTask.java +++ b/build/macosx/appbundler/src/com/oracle/appbundler/AppBundlerTask.java @@ -42,9 +42,14 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Task; @@ -56,704 +61,892 @@ import org.apache.tools.ant.types.resources.FileResource; * App bundler Ant task. */ public class AppBundlerTask extends Task { - // Output folder for generated bundle - private File outputDirectory = null; + // Output folder for generated bundle + private File outputDirectory = null; - // General bundle properties - private String name = null; - private String displayName = null; - private String identifier = null; - private File iconFile = null; - private String executableName = EXECUTABLE_NAME; + // General bundle properties + private String name = null; + private String displayName = null; + private String identifier = null; + private File icon = null; + private String executableName = EXECUTABLE_NAME; - private String shortVersion = null; //"1.0"; - private String version = null; //"1.0"; - private String signature = "????"; - private String copyright = null; //""; - private String getInfo = null; - private String privileged = null; - private String workingDirectory = null; + private String shortVersion = "1.0"; + private String version = "1.0"; + private String signature = "????"; + private String copyright = ""; + private String privileged = null; + private String workingDirectory = null; + private String minimumSystemVersion = null; - private String applicationCategory = null; - private boolean highResolutionCapable = true; - // Oracle Java 8 requires 10.8.3 or later, so require it here. - private String minimumSystem = "10.8.3"; - // By default, don't embed Java FX. - private boolean javafx = false; + private String jvmRequired = null; + private boolean jrePreferred = false; + private boolean jdkPreferred = false; - // JVM info properties - private String mainClassName = null; - private FileSet runtime = null; - private ArrayList classPath = new ArrayList<>(); - private ArrayList libraryPath = new ArrayList<>(); - private ArrayList options = new ArrayList<>(); - private ArrayList arguments = new ArrayList<>(); - private ArrayList architectures = new ArrayList<>(); - private ArrayList bundleDocuments = new ArrayList<>(); + private String applicationCategory = null; - private Reference classPathRef; + private boolean highResolutionCapable = true; + private boolean supportsAutomaticGraphicsSwitching = true; + private boolean hideDockIcon = false; + private boolean isDebug = false; + private boolean ignorePSN = false; - private static final String EXECUTABLE_NAME = "JavaAppLauncher"; - private static final String DEFAULT_ICON_NAME = "GenericApp.icns"; - private static final String OS_TYPE_CODE = "APPL"; + // JVM info properties + private String mainClassName = null; + private String jnlpLauncherName = null; + private String jarLauncherName = null; + private Runtime runtime = null; + private ArrayList classPath = new ArrayList<>(); + private ArrayList libraryPath = new ArrayList<>(); + private ArrayList