diff --git a/COPYING b/COPYING deleted file mode 100644 index ed990f8cd..000000000 --- a/COPYING +++ /dev/null @@ -1,621 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. 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 -them 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 prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. 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. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey 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; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If 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 convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU 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 that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - 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. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -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. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/COPYING.LGPL b/COPYING.LGPL deleted file mode 100644 index 0a041280b..000000000 --- a/COPYING.LGPL +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - 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 that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU 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 as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/LICENSE b/LICENSE deleted file mode 100644 index ca468ddd7..000000000 --- a/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -All code herein is licensed under the LGPLv3 license. - -Please see COPYING.LGPL and COPYING for more information - -ModLauncher - for launching Java programs with in-flight transformation ability. - - Copyright (C) 2017-2019 cpw - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, version 3 of the License. - - 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 Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . diff --git a/LICENSE.txt b/LICENSE.txt index 249debe26..e2290338a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -27,6 +27,25 @@ purpose of the LGPL. Mods and others using this code via ordinary Java mechanics for referencing libraries are specifically not bound by Forge's license for the Mod code. +=== ModLauncher === + +You can find a copy of the LGPLv3 attached below. + +ModLauncher - for launching Java programs with in-flight transformation ability. + + Copyright (C) 2017-2019 cpw + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, version 3 of the License. + + 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . === MCP Data === This software includes data from the Minecraft Coder Pack (MCP), with kind permission @@ -120,7 +139,7 @@ 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 @@ -521,3 +540,171 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS + +========================================================================= + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + 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 that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU 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 as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/build.gradle b/build.gradle index 2b43b9339..bf0c86d42 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,12 @@ allprojects { dependencyUpdates.rejectVersionIf { isNonStable(it.candidate.version) } + configurations { + all.collect { configuration -> + configuration.exclude group: 'cpw.mods', module: 'modlauncher' + } + } + java { withSourcesJar() toolchain { @@ -103,6 +109,6 @@ subprojects { subProject -> } changelog { - from "1.0" + from "6.0" } } diff --git a/codestyle.xml b/codestyle.xml deleted file mode 100644 index 9c557a282..000000000 --- a/codestyle.xml +++ /dev/null @@ -1,5 +0,0 @@ - - \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0251198ad..74a185f31 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,6 @@ mergetool_version=2.0.0 accesstransformers_version=11.0.1 coremods_version=7.0.3 eventbus_version=8.0.1 -modlauncher_version=11.0.3 securejarhandler_version=3.0.7 bootstraplauncher_version=1.1.8 asm_version=9.5 @@ -29,7 +28,7 @@ gson_version=2.10 apache_commons_lang3_version=3.12.0 jopt_simple_version=5.0.4 commons_io_version=2.11.0 - +powermock_version=2.0.9 jmh_version=1.37 org.gradle.configuration-cache=true diff --git a/loader/build.gradle b/loader/build.gradle index 2a52ef74c..844366f5e 100644 --- a/loader/build.gradle +++ b/loader/build.gradle @@ -6,6 +6,11 @@ checkJarCompatibility { isAPI = true } +sourceSets { + jmh + testJars +} + dependencies { compileOnly("org.jetbrains:annotations:${jetbrains_annotations_version}") @@ -21,7 +26,6 @@ dependencies { api("org.apache.commons:commons-lang3:${apache_commons_lang3_version}") api("com.electronwill.night-config:core:${nightconfig_version}") api("com.electronwill.night-config:toml:${nightconfig_version}") - api("cpw.mods:modlauncher:${modlauncher_version}") api("net.neoforged:coremods:${coremods_version}") api("com.mojang:logging:${mojang_logging_version}") api "net.neoforged:JarJarSelector:${jarjar_version}" @@ -51,6 +55,15 @@ dependencies { testImplementation("org.assertj:assertj-core:3.25.3") testImplementation("org.junit.jupiter:junit-jupiter-engine:$jupiter_version") testImplementation('com.google.jimfs:jimfs:1.3.0') + testImplementation("org.powermock:powermock-core:${powermock_version}") + testImplementation("org.powermock:powermock-reflect:${powermock_version}") + testCompileOnly(sourceSets.testJars.output) + + jmhImplementation(sourceSets.main.output) + jmhImplementation(sourceSets.testJars.output) + jmhImplementation("org.openjdk.jmh:jmh-core:${jmh_version}") + jmhImplementation("org.powermock:powermock-core:${powermock_version}") + jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:${jmh_version}") // Provides the JUnit project as a BOM entry constraints { @@ -58,6 +71,64 @@ dependencies { } } +configurations.jmhImplementation.extendsFrom(configurations.implementation) + +var testJars = tasks.register(sourceSets.testJars.jarTaskName, Jar) { + archiveClassifier = 'testsjar' + from sourceSets.testJars.output +} + +test { + inputs.file(testJars.flatMap(AbstractArchiveTask::getArchiveFile)) + + useJUnitPlatform() + + systemProperty 'testJars.location', testJars.map(tj -> tj.archiveFile.get().asFile).get() + + jvmArgs( + '--add-opens', 'java.base/java.lang=ALL-UNNAMED', + '--add-opens', 'java.base/java.lang.invoke=ALL-UNNAMED' + ) +} + +tasks.register('jmh', JavaExec) { + dependsOn('jmhClasses') + mainClass = 'org.openjdk.jmh.Main' + + final results = file("${project.reportsDir}/jmh/result.json") + doFirst { + results.parentFile.mkdirs() + + jvmArgs('--add-opens', 'java.base/java.lang.invoke=ALL-UNNAMED') + } + + args = [ + 'cpw.mods.modlauncher.benchmarks.TransformBenchmark', + '-bm', 'avgt', + '-prof', 'stack', + '-prof', 'jfr', + '-r', '3s', + '-w', '3s', + '-wi', '3', + '-i', '3', + '-f', '3', + '-tu', 'us', + '-rf', 'json', + '-rff', results + ] + if (project.hasProperty('jmhVendor') && project.hasProperty('jmhVersion')) { + final specifiedVendor = project.property('jmhVendor').toString() + final actualVendor = specifiedVendor.endsWith('-J9') ? specifiedVendor.substring(0, specifiedVendor.length() - 3) : specifiedVendor + javaLauncher.set(javaToolchains.launcherFor { + it.vendor.set(JvmVendorSpec."${actualVendor.toUpperCase(Locale.ROOT)}" as JvmVendorSpec) + it.languageVersion.set(JavaLanguageVersion.of(project.property('jmhVersion') as int)) + it.implementation.set(specifiedVendor.endsWith('-J9') ? JvmImplementation.J9 : JvmImplementation.VENDOR_SPECIFIC) + }) + } else { + javaLauncher.set(javaToolchains.launcherFor(java.toolchain)) + } +} + spotless { java { // courtesy of diffplug/spotless#240 diff --git a/src/jmh/java/cpw/mods/modlauncher/benchmarks/TransformBenchmark.java b/loader/src/jmh/java/cpw/mods/modlauncher/benchmarks/TransformBenchmark.java similarity index 60% rename from src/jmh/java/cpw/mods/modlauncher/benchmarks/TransformBenchmark.java rename to loader/src/jmh/java/cpw/mods/modlauncher/benchmarks/TransformBenchmark.java index aca199083..42fae4097 100644 --- a/src/jmh/java/cpw/mods/modlauncher/benchmarks/TransformBenchmark.java +++ b/loader/src/jmh/java/cpw/mods/modlauncher/benchmarks/TransformBenchmark.java @@ -1,31 +1,29 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.benchmarks; -import cpw.mods.modlauncher.*; +import static cpw.mods.modlauncher.api.LambdaExceptionUtils.uncheck; + +import cpw.mods.modlauncher.ClassTransformer; +import cpw.mods.modlauncher.LaunchPluginHandler; +import cpw.mods.modlauncher.ModuleLayerHandler; +import cpw.mods.modlauncher.TransformStore; +import cpw.mods.modlauncher.TransformerAuditTrail; +import cpw.mods.modlauncher.TransformingClassLoader; import cpw.mods.modlauncher.api.ITransformerActivity; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.ClassNode; -import org.openjdk.jmh.annotations.*; -import org.powermock.reflect.Whitebox; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -33,8 +31,15 @@ import java.util.EnumSet; import java.util.List; import java.util.Map; - -import static cpw.mods.modlauncher.api.LambdaExceptionUtils.uncheck; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.powermock.reflect.Whitebox; @State(Scope.Benchmark) public class TransformBenchmark { @@ -47,8 +52,8 @@ public void setup() throws Exception { final TransformStore transformStore = new TransformStore(); final ModuleLayerHandler layerHandler = Whitebox.invokeConstructor(ModuleLayerHandler.class); final LaunchPluginHandler lph = new LaunchPluginHandler(layerHandler); - classTransformer = uncheck(()->Whitebox.invokeConstructor(ClassTransformer.class, new Class[] { transformStore.getClass(), lph.getClass(), TransformingClassLoader.class }, new Object[] { transformStore, lph, null})); - transform = uncheck(()->classTransformer.getClass().getDeclaredMethod("transform", byte[].class, String.class,String.class)); + classTransformer = uncheck(() -> Whitebox.invokeConstructor(ClassTransformer.class, new Class[] { transformStore.getClass(), lph.getClass(), TransformingClassLoader.class }, new Object[] { transformStore, lph, null })); + transform = uncheck(() -> classTransformer.getClass().getDeclaredMethod("transform", byte[].class, String.class, String.class)); transform.setAccessible(true); Map plugins = Whitebox.getInternalState(lph, "plugins"); try (InputStream is = getClass().getClassLoader().getResourceAsStream("cpw/mods/modlauncher/testjar/TestClass.class")) { @@ -86,7 +91,7 @@ public EnumSet handlesClass(final Type classType, final boolean isEmpty) @Benchmark public int transformNoop() { - byte[] result = uncheck(()->(byte[])transform.invoke(classTransformer,new byte[0], "test.MyClass","jmh")); + byte[] result = uncheck(() -> (byte[]) transform.invoke(classTransformer, new byte[0], "test.MyClass", "jmh")); return result.length + 1; } @@ -99,7 +104,7 @@ public void clearLog() { @Benchmark public int transformDummyClass() { - byte[] result = uncheck(()->(byte[])transform.invoke(classTransformer,classBytes, "cpw.mods.modlauncher.testjar.TestClass","jmh")); + byte[] result = uncheck(() -> (byte[]) transform.invoke(classTransformer, classBytes, "cpw.mods.modlauncher.testjar.TestClass", "jmh")); return result.length + 1; } } diff --git a/src/jmh/java/module-info.java b/loader/src/jmh/java/module-info.java similarity index 100% rename from src/jmh/java/module-info.java rename to loader/src/jmh/java/module-info.java diff --git a/src/main/java/cpw/mods/modlauncher/ArgumentHandler.java b/loader/src/main/java/cpw/mods/modlauncher/ArgumentHandler.java similarity index 78% rename from src/main/java/cpw/mods/modlauncher/ArgumentHandler.java rename to loader/src/main/java/cpw/mods/modlauncher/ArgumentHandler.java index 3b2d735ba..d74916480 100644 --- a/src/main/java/cpw/mods/modlauncher/ArgumentHandler.java +++ b/loader/src/main/java/cpw/mods/modlauncher/ArgumentHandler.java @@ -1,31 +1,32 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; -import joptsimple.*; -import joptsimple.util.*; -import org.jetbrains.annotations.NotNull; - -import java.nio.file.*; -import java.util.*; -import java.util.function.*; +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.ITransformationService; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import joptsimple.OptionParser; +import joptsimple.OptionSet; +import joptsimple.OptionSpec; +import joptsimple.util.PathConverter; +import joptsimple.util.PathProperties; public class ArgumentHandler { private String[] args; @@ -82,7 +83,7 @@ public V value(OptionSpec option) { } @Override - public @NotNull List values(OptionSpec option) { + public List values(OptionSpec option) { checkOwnership(option); return set.valuesOf(option); } @@ -108,7 +109,7 @@ public String[] buildArgumentList() { private void addOptionToString(OptionSpec option, OptionSet optionSet, List appendTo) { if (optionSet.has(option)) { - appendTo.add("--"+option.options().get(0)); + appendTo.add("--" + option.options().get(0)); appendTo.add(option.value(optionSet).toString()); } } diff --git a/loader/src/main/java/cpw/mods/modlauncher/BootstrapLaunchConsumer.java b/loader/src/main/java/cpw/mods/modlauncher/BootstrapLaunchConsumer.java new file mode 100644 index 000000000..3b3047b66 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/BootstrapLaunchConsumer.java @@ -0,0 +1,24 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +import java.util.function.Consumer; + +public class BootstrapLaunchConsumer implements Consumer { + @Override + public void accept(final String[] strings) { + Launcher.main(strings); + } +} diff --git a/src/main/java/cpw/mods/modlauncher/ClassTransformer.java b/loader/src/main/java/cpw/mods/modlauncher/ClassTransformer.java similarity index 84% rename from src/main/java/cpw/mods/modlauncher/ClassTransformer.java rename to loader/src/main/java/cpw/mods/modlauncher/ClassTransformer.java index a0451dff6..c8bc75903 100644 --- a/src/main/java/cpw/mods/modlauncher/ClassTransformer.java +++ b/loader/src/main/java/cpw/mods/modlauncher/ClassTransformer.java @@ -1,38 +1,51 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; -import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; -import org.apache.logging.log4j.*; -import org.objectweb.asm.*; -import org.objectweb.asm.tree.*; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.ITransformerActivity; +import cpw.mods.modlauncher.api.TargetType; +import cpw.mods.modlauncher.api.TransformerVoteResult; +import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.security.*; -import java.util.*; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; import java.util.function.Supplier; -import java.util.stream.*; - -import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; +import org.objectweb.asm.tree.MethodNode; /** * Transforms classes using the supplied launcher services @@ -74,13 +87,13 @@ byte[] transform(byte[] inputClass, String className, final String reason) { if (inputClass.length > 0) { final ClassReader classReader = new ClassReader(inputClass); classReader.accept(clazz, ClassReader.EXPAND_FRAMES); - digest = ()->getSha256().digest(inputClass); + digest = () -> getSha256().digest(inputClass); empty = false; } else { clazz.name = classDesc.getInternalName(); clazz.version = 52; clazz.superName = "java/lang/Object"; - digest = ()->getSha256().digest(EMPTY); + digest = () -> getSha256().digest(EMPTY); empty = true; } auditTrail.addReason(classDesc.getClassName(), reason); @@ -138,6 +151,7 @@ byte[] transform(byte[] inputClass, String className, final String reason) { } private static Path tempDir; + private void dumpClass(final byte[] clazz, String className) { if (tempDir == null) { synchronized (ClassTransformer.class) { @@ -177,7 +191,7 @@ private T performVote(List> transformers, T node, VotingCont if (results.containsKey(TransformerVoteResult.YES)) { final ITransformer transformer = results.get(TransformerVoteResult.YES).get(0).getTransformer(); node = transformer.transform(node, context); - auditTrail.addTransformerAuditTrail(context.getClassName(), ((TransformerHolder)transformer).owner(), transformer); + auditTrail.addTransformerAuditTrail(context.getClassName(), ((TransformerHolder) transformer).owner(), transformer); transformers.remove(transformer); continue; } @@ -185,8 +199,7 @@ private T performVote(List> transformers, T node, VotingCont if (results.containsKey(TransformerVoteResult.DEFER)) { throw new VoteDeadlockException(results.get(TransformerVoteResult.DEFER), node.getClass()); } - } - while (!transformers.isEmpty()); + } while (!transformers.isEmpty()); return node; } diff --git a/src/main/java/cpw/mods/modlauncher/DefaultLaunchHandlerService.java b/loader/src/main/java/cpw/mods/modlauncher/DefaultLaunchHandlerService.java similarity index 50% rename from src/main/java/cpw/mods/modlauncher/DefaultLaunchHandlerService.java rename to loader/src/main/java/cpw/mods/modlauncher/DefaultLaunchHandlerService.java index 15dd81399..daf0c0ef4 100644 --- a/src/main/java/cpw/mods/modlauncher/DefaultLaunchHandlerService.java +++ b/loader/src/main/java/cpw/mods/modlauncher/DefaultLaunchHandlerService.java @@ -1,27 +1,24 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; - -import java.lang.reflect.*; -import java.nio.file.*; +import cpw.mods.modlauncher.api.ILaunchHandlerService; +import cpw.mods.modlauncher.api.NamedPath; +import cpw.mods.modlauncher.api.ServiceRunner; +import java.lang.reflect.Method; +import java.nio.file.FileSystems; /** * Default launch handler service - will launch minecraft @@ -37,7 +34,6 @@ public String name() { @Override public ServiceRunner launchService(String[] arguments, ModuleLayer gameLayer) { - return () -> { final Class mcClass = Class.forName(gameLayer.findModule("minecraft").orElseThrow(), "net.minecraft.client.main.Main"); final Method mcClassMethod = mcClass.getMethod("main", String[].class); @@ -47,6 +43,6 @@ public ServiceRunner launchService(String[] arguments, ModuleLayer gameLayer) { @Override public NamedPath[] getPaths() { - return new NamedPath[] {new NamedPath("launch",FileSystems.getDefault().getPath(LAUNCH_PATH_STRING))}; + return new NamedPath[] { new NamedPath("launch", FileSystems.getDefault().getPath(LAUNCH_PATH_STRING)) }; } } diff --git a/src/main/java/cpw/mods/modlauncher/EnumerationHelper.java b/loader/src/main/java/cpw/mods/modlauncher/EnumerationHelper.java similarity index 66% rename from src/main/java/cpw/mods/modlauncher/EnumerationHelper.java rename to loader/src/main/java/cpw/mods/modlauncher/EnumerationHelper.java index b64e38b23..f144c15ed 100644 --- a/src/main/java/cpw/mods/modlauncher/EnumerationHelper.java +++ b/loader/src/main/java/cpw/mods/modlauncher/EnumerationHelper.java @@ -1,25 +1,22 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2020 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2020 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import java.net.URL; -import java.util.*; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/src/main/java/cpw/mods/modlauncher/Environment.java b/loader/src/main/java/cpw/mods/modlauncher/Environment.java similarity index 60% rename from src/main/java/cpw/mods/modlauncher/Environment.java rename to loader/src/main/java/cpw/mods/modlauncher/Environment.java index 1c09e341d..8344370f1 100644 --- a/src/main/java/cpw/mods/modlauncher/Environment.java +++ b/loader/src/main/java/cpw/mods/modlauncher/Environment.java @@ -1,27 +1,25 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.ILaunchHandlerService; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.TypesafeMap; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; - -import java.util.*; +import java.util.Optional; import java.util.function.Function; /** diff --git a/loader/src/main/java/cpw/mods/modlauncher/InvalidLauncherSetupException.java b/loader/src/main/java/cpw/mods/modlauncher/InvalidLauncherSetupException.java new file mode 100644 index 000000000..e57de7600 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/InvalidLauncherSetupException.java @@ -0,0 +1,21 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +public class InvalidLauncherSetupException extends IllegalStateException { + InvalidLauncherSetupException(final String s) { + super(s); + } +} diff --git a/src/main/java/cpw/mods/modlauncher/LaunchPluginHandler.java b/loader/src/main/java/cpw/mods/modlauncher/LaunchPluginHandler.java similarity index 68% rename from src/main/java/cpw/mods/modlauncher/LaunchPluginHandler.java rename to loader/src/main/java/cpw/mods/modlauncher/LaunchPluginHandler.java index f395314cf..f907094fc 100644 --- a/src/main/java/cpw/mods/modlauncher/LaunchPluginHandler.java +++ b/loader/src/main/java/cpw/mods/modlauncher/LaunchPluginHandler.java @@ -1,67 +1,70 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; +import static cpw.mods.modlauncher.LogMarkers.LAUNCHPLUGIN; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; + import cpw.mods.jarhandling.SecureJar; import cpw.mods.modlauncher.api.IEnvironment; import cpw.mods.modlauncher.api.IModuleLayerManager; import cpw.mods.modlauncher.api.NamedPath; +import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; import cpw.mods.modlauncher.util.ServiceLoaderUtils; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.VisibleForTesting; -import org.objectweb.asm.*; -import org.objectweb.asm.tree.*; -import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; - -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static cpw.mods.modlauncher.LogMarkers.*; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; public class LaunchPluginHandler { private static final Logger LOGGER = LogManager.getLogger(); private final Map plugins; public LaunchPluginHandler(final ModuleLayerHandler layerHandler) { - this(ServiceLoaderUtils.streamServiceLoader(()->ServiceLoader.load(layerHandler.getLayer(IModuleLayerManager.Layer.BOOT).orElseThrow(), ILaunchPluginService.class), - e->LOGGER.fatal(MODLAUNCHER, "Encountered serious error loading launch plugin service. Things will not work well", e))); + this(ServiceLoaderUtils.streamServiceLoader(() -> ServiceLoader.load(layerHandler.getLayer(IModuleLayerManager.Layer.BOOT).orElseThrow(), ILaunchPluginService.class), + e -> LOGGER.fatal(MODLAUNCHER, "Encountered serious error loading launch plugin service. Things will not work well", e))); } @VisibleForTesting public LaunchPluginHandler(Stream plugins) { this.plugins = plugins.collect(Collectors.toMap(ILaunchPluginService::name, Function.identity())); - final var modlist = this.plugins.entrySet().stream().map(e->Map.of( + final var modlist = this.plugins.entrySet().stream().map(e -> Map.of( "name", e.getKey(), "type", "PLUGINSERVICE", "file", ServiceLoaderUtils.fileNameFor(e.getValue().getClass()))) .toList(); - if (Launcher.INSTANCE!=null) { + if (Launcher.INSTANCE != null) { Launcher.INSTANCE.environment().getProperty(IEnvironment.Keys.MODLIST.get()) - .ifPresentOrElse(mods->mods.addAll(modlist),() -> { + .ifPresentOrElse(mods -> mods.addAll(modlist), () -> { throw new RuntimeException("The MODLIST isn't set, huh?"); }); } - LOGGER.debug(MODLAUNCHER,"Found launch plugins: [{}]", ()-> String.join(",", this.plugins.keySet())); + LOGGER.debug(MODLAUNCHER, "Found launch plugins: [{}]", () -> String.join(",", this.plugins.keySet())); } public Optional get(final String name) { @@ -79,12 +82,12 @@ public EnumMap> computeLa } } } - LOGGER.debug(LAUNCHPLUGIN, "LaunchPluginService {}", ()->phaseObjectEnumMap); + LOGGER.debug(LAUNCHPLUGIN, "LaunchPluginService {}", () -> phaseObjectEnumMap); return phaseObjectEnumMap; } void offerScanResultsToPlugins(List scanResults) { - plugins.forEach((n,p)->p.addResources(scanResults)); + plugins.forEach((n, p) -> p.addResources(scanResults)); } int offerClassNodeToPlugins(final ILaunchPluginService.Phase phase, final List plugins, @Nullable final ClassNode node, final Type className, TransformerAuditTrail auditTrail, final String reason) { @@ -103,6 +106,6 @@ int offerClassNodeToPlugins(final ILaunchPluginService.Phase phase, final Listp.initializeLaunch((s->transformerLoader.buildTransformedClassNodeFor(s, k)), specialPaths)); + plugins.forEach((k, p) -> p.initializeLaunch((s -> transformerLoader.buildTransformedClassNodeFor(s, k)), specialPaths)); } } diff --git a/src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java b/loader/src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java similarity index 64% rename from src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java rename to loader/src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java index 00c882e44..08e291b4d 100644 --- a/src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java +++ b/loader/src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java @@ -1,33 +1,35 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; + +import cpw.mods.modlauncher.api.ILaunchHandlerService; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.NamedPath; import cpw.mods.modlauncher.util.ServiceLoaderUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.*; - -import static cpw.mods.modlauncher.LogMarkers.*; - /** * Identifies the launch target and dispatches to it */ @@ -36,9 +38,9 @@ class LaunchServiceHandler { private final Map launchHandlerLookup; public LaunchServiceHandler(final ModuleLayerHandler layerHandler) { - this.launchHandlerLookup = ServiceLoaderUtils.streamServiceLoader(()->ServiceLoader.load(layerHandler.getLayer(IModuleLayerManager.Layer.BOOT).orElseThrow(), ILaunchHandlerService.class), sce -> LOGGER.fatal("Encountered serious error loading transformation service, expect problems", sce)) + this.launchHandlerLookup = ServiceLoaderUtils.streamServiceLoader(() -> ServiceLoader.load(layerHandler.getLayer(IModuleLayerManager.Layer.BOOT).orElseThrow(), ILaunchHandlerService.class), sce -> LOGGER.fatal("Encountered serious error loading transformation service, expect problems", sce)) .collect(Collectors.toMap(ILaunchHandlerService::name, LaunchServiceHandlerDecorator::new)); - LOGGER.debug(MODLAUNCHER,"Found launch services [{}]", () -> String.join(",",launchHandlerLookup.keySet())); + LOGGER.debug(MODLAUNCHER, "Found launch services [{}]", () -> String.join(",", launchHandlerLookup.keySet())); } public Optional findLaunchHandler(final String name) { @@ -56,7 +58,7 @@ private void launch(String target, String[] arguments, ModuleLayer gameLayer, Tr static List hideAccessToken(String[] arguments) { final ArrayList output = new ArrayList<>(); for (int i = 0; i < arguments.length; i++) { - if (i > 0 && Objects.equals(arguments[i-1], "--accessToken")) { + if (i > 0 && Objects.equals(arguments[i - 1], "--accessToken")) { output.add("❄❄❄❄❄❄❄❄"); } else { output.add(arguments[i]); diff --git a/loader/src/main/java/cpw/mods/modlauncher/LaunchServiceHandlerDecorator.java b/loader/src/main/java/cpw/mods/modlauncher/LaunchServiceHandlerDecorator.java new file mode 100644 index 000000000..ec598eb82 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/LaunchServiceHandlerDecorator.java @@ -0,0 +1,30 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +import cpw.mods.modlauncher.api.ILaunchHandlerService; + +/** + * Decorates {@link ILaunchHandlerService} for use by the system + */ +record LaunchServiceHandlerDecorator(ILaunchHandlerService service) { + public void launch(String[] arguments, ModuleLayer gameLayer) { + try { + this.service.launchService(arguments, gameLayer).run(); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/cpw/mods/modlauncher/Launcher.java b/loader/src/main/java/cpw/mods/modlauncher/Launcher.java similarity index 65% rename from src/main/java/cpw/mods/modlauncher/Launcher.java rename to loader/src/main/java/cpw/mods/modlauncher/Launcher.java index a247d65af..a34f0f5fb 100644 --- a/src/main/java/cpw/mods/modlauncher/Launcher.java +++ b/loader/src/main/java/cpw/mods/modlauncher/Launcher.java @@ -1,33 +1,34 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; + import cpw.mods.jarhandling.SecureJar; -import cpw.mods.modlauncher.api.*; -import org.apache.logging.log4j.LogManager; +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.ILaunchHandlerService; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.ITransformationService; +import cpw.mods.modlauncher.api.TypesafeMap; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; - -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static cpw.mods.modlauncher.LogMarkers.*; +import org.apache.logging.log4j.LogManager; /** * Entry point for the ModLauncher. @@ -46,14 +47,14 @@ public class Launcher { private Launcher() { INSTANCE = this; - LogManager.getLogger().info(MODLAUNCHER,"ModLauncher {} starting: java version {} by {}; OS {} arch {} version {}", ()->IEnvironment.class.getPackage().getImplementationVersion(), () -> System.getProperty("java.version"), ()->System.getProperty("java.vendor"), ()->System.getProperty("os.name"), ()->System.getProperty("os.arch"), ()->System.getProperty("os.version")); + LogManager.getLogger().info(MODLAUNCHER, "ModLauncher {} starting: java version {} by {}; OS {} arch {} version {}", () -> IEnvironment.class.getPackage().getImplementationVersion(), () -> System.getProperty("java.version"), () -> System.getProperty("java.vendor"), () -> System.getProperty("os.name"), () -> System.getProperty("os.arch"), () -> System.getProperty("os.version")); this.moduleLayerHandler = new ModuleLayerHandler(); this.launchService = new LaunchServiceHandler(this.moduleLayerHandler); this.blackboard = new TypesafeMap(); this.environment = new Environment(this); - environment.computePropertyIfAbsent(IEnvironment.Keys.MLSPEC_VERSION.get(), s->IEnvironment.class.getPackage().getSpecificationVersion()); - environment.computePropertyIfAbsent(IEnvironment.Keys.MLIMPL_VERSION.get(), s->IEnvironment.class.getPackage().getImplementationVersion()); - environment.computePropertyIfAbsent(IEnvironment.Keys.MODLIST.get(), s->new ArrayList<>()); + environment.computePropertyIfAbsent(IEnvironment.Keys.MLSPEC_VERSION.get(), s -> IEnvironment.class.getPackage().getSpecificationVersion()); + environment.computePropertyIfAbsent(IEnvironment.Keys.MLIMPL_VERSION.get(), s -> IEnvironment.class.getPackage().getImplementationVersion()); + environment.computePropertyIfAbsent(IEnvironment.Keys.MODLIST.get(), s -> new ArrayList<>()); this.transformStore = new TransformStore(); this.transformationServicesHandler = new TransformationServicesHandler(this.transformStore, this.moduleLayerHandler); this.argumentHandler = new ArgumentHandler(); @@ -64,12 +65,12 @@ public static void main(String... args) { var props = System.getProperties(); if (props.getProperty("java.vm.name").contains("OpenJ9")) { System.err.printf(""" - WARNING: OpenJ9 is detected. This is definitely unsupported and you may encounter issues and significantly worse performance. - For support and performance reasons, we recommend installing a temurin JVM from https://adoptium.net/ - JVM information: %s %s %s - """, props.getProperty("java.vm.vendor"), props.getProperty("java.vm.name"), props.getProperty("java.vm.version")); + WARNING: OpenJ9 is detected. This is definitely unsupported and you may encounter issues and significantly worse performance. + For support and performance reasons, we recommend installing a temurin JVM from https://adoptium.net/ + JVM information: %s %s %s + """, props.getProperty("java.vm.vendor"), props.getProperty("java.vm.name"), props.getProperty("java.vm.version")); } - LogManager.getLogger().info(MODLAUNCHER,"ModLauncher running: args {}", () -> LaunchServiceHandler.hideAccessToken(args)); + LogManager.getLogger().info(MODLAUNCHER, "ModLauncher running: args {}", () -> LaunchServiceHandler.hideAccessToken(args)); LogManager.getLogger().info(MODLAUNCHER, "JVM identified as {} {} {}", props.getProperty("java.vm.vendor"), props.getProperty("java.vm.name"), props.getProperty("java.vm.version")); new Launcher().run(args); } @@ -86,7 +87,7 @@ private void run(String... args) { scanResults.getOrDefault(IModuleLayerManager.Layer.PLUGIN, List.of()) .stream() .mapMulti((resource, action) -> resource.resources().forEach(action)) - .forEach(np->this.moduleLayerHandler.addToLayer(IModuleLayerManager.Layer.PLUGIN, np)); + .forEach(np -> this.moduleLayerHandler.addToLayer(IModuleLayerManager.Layer.PLUGIN, np)); this.moduleLayerHandler.buildLayer(IModuleLayerManager.Layer.PLUGIN); final var gameResults = this.transformationServicesHandler.triggerScanCompletion(this.moduleLayerHandler) .stream().collect(Collectors.groupingBy(ITransformationService.Resource::target)); @@ -94,7 +95,7 @@ private void run(String... args) { .flatMap(m -> m.getOrDefault(IModuleLayerManager.Layer.GAME, List.of()).stream()) .mapMulti((resource, action) -> resource.resources().forEach(action)) .toList(); - gameContents.forEach(j->this.moduleLayerHandler.addToLayer(IModuleLayerManager.Layer.GAME, j)); + gameContents.forEach(j -> this.moduleLayerHandler.addToLayer(IModuleLayerManager.Layer.GAME, j)); this.transformationServicesHandler.initialiseServiceTransformers(); this.launchPlugins.offerScanResultsToPlugins(gameContents); this.launchService.validateLaunchTarget(this.argumentHandler); diff --git a/loader/src/main/java/cpw/mods/modlauncher/LogMarkers.java b/loader/src/main/java/cpw/mods/modlauncher/LogMarkers.java new file mode 100644 index 000000000..5a8409942 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/LogMarkers.java @@ -0,0 +1,24 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; + +class LogMarkers { + static final Marker MODLAUNCHER = MarkerManager.getMarker("MODLAUNCHER"); + static final Marker CLASSLOADING = MarkerManager.getMarker("CLASSLOADING").addParents(MODLAUNCHER); + static final Marker LAUNCHPLUGIN = MarkerManager.getMarker("LAUNCHPLUGIN").addParents(MODLAUNCHER); +} diff --git a/src/main/java/cpw/mods/modlauncher/ModuleLayerHandler.java b/loader/src/main/java/cpw/mods/modlauncher/ModuleLayerHandler.java similarity index 70% rename from src/main/java/cpw/mods/modlauncher/ModuleLayerHandler.java rename to loader/src/main/java/cpw/mods/modlauncher/ModuleLayerHandler.java index 4bb7bfb46..87d46aac5 100644 --- a/src/main/java/cpw/mods/modlauncher/ModuleLayerHandler.java +++ b/loader/src/main/java/cpw/mods/modlauncher/ModuleLayerHandler.java @@ -1,19 +1,15 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; @@ -23,10 +19,14 @@ import cpw.mods.jarhandling.SecureJar; import cpw.mods.modlauncher.api.IModuleLayerManager; import cpw.mods.modlauncher.api.NamedPath; - import java.lang.module.Configuration; import java.lang.module.ModuleFinder; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumMap; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -37,6 +37,7 @@ private record PathOrJar(NamedPath path, SecureJar jar) { static PathOrJar from(SecureJar jar) { return new PathOrJar(null, jar); } + static PathOrJar from(NamedPath path) { return new PathOrJar(path, null); } @@ -45,6 +46,7 @@ SecureJar build() { return jar != null ? jar : SecureJar.from(path.paths()); } } + private final EnumMap> layers = new EnumMap<>(Layer.class); private final EnumMap completedLayers = new EnumMap<>(Layer.class); @@ -53,18 +55,19 @@ SecureJar build() { // Create a new ModuleClassLoader from the boot module layer if it doesn't exist already. // This allows us to launch without BootstrapLauncher. ModuleClassLoader cl = classLoader instanceof ModuleClassLoader moduleCl ? moduleCl - : new ModuleClassLoader("BOOT", ModuleLayer.boot().configuration(), List.of()); - completedLayers.put(Layer.BOOT, new LayerInfo(getClass().getModule().getLayer(), cl)); + : new ModuleClassLoader("BOOT", ModuleLayer.boot().configuration(), List.of()); + var ownLayer = Objects.requireNonNullElse(getClass().getModule().getLayer(), ModuleLayer.boot()); + completedLayers.put(Layer.BOOT, new LayerInfo(ownLayer, cl)); } void addToLayer(final Layer layer, final SecureJar jar) { if (completedLayers.containsKey(layer)) throw new IllegalStateException("Layer already populated"); - layers.computeIfAbsent(layer, l->new ArrayList<>()).add(PathOrJar.from(jar)); + layers.computeIfAbsent(layer, l -> new ArrayList<>()).add(PathOrJar.from(jar)); } void addToLayer(final Layer layer, final NamedPath namedPath) { if (completedLayers.containsKey(layer)) throw new IllegalStateException("Layer already populated"); - layers.computeIfAbsent(layer, l->new ArrayList<>()).add(PathOrJar.from(namedPath)); + layers.computeIfAbsent(layer, l -> new ArrayList<>()).add(PathOrJar.from(namedPath)); } public LayerInfo buildLayer(final Layer layer, BiFunction, ModuleClassLoader> classLoaderSupplier) { @@ -72,19 +75,20 @@ public LayerInfo buildLayer(final Layer layer, BiFunctionli.layer().configuration()).toList(), ModuleFinder.of(), targets); - final var allParents = Arrays.stream(layer.getParent()).map(completedLayers::get).map(LayerInfo::layer).mapMulti((moduleLayer, comp)-> { + final var newConf = Configuration.resolveAndBind(JarModuleFinder.of(finder), Arrays.stream(layer.getParent()).map(completedLayers::get).map(li -> li.layer().configuration()).toList(), ModuleFinder.of(), targets); + final var allParents = Arrays.stream(layer.getParent()).map(completedLayers::get).map(LayerInfo::layer).mapMulti((moduleLayer, comp) -> { comp.accept(moduleLayer); moduleLayer.parents().forEach(comp); }).toList(); final var classLoader = classLoaderSupplier.apply(newConf, allParents); - final var modController = ModuleLayer.defineModules(newConf, Arrays.stream(layer.getParent()).map(completedLayers::get).map(LayerInfo::layer).toList(), f->classLoader); + final var modController = ModuleLayer.defineModules(newConf, Arrays.stream(layer.getParent()).map(completedLayers::get).map(LayerInfo::layer).toList(), f -> classLoader); completedLayers.put(layer, new LayerInfo(modController.layer(), classLoader)); classLoader.setFallbackClassLoader(completedLayers.get(Layer.BOOT).cl()); return new LayerInfo(modController.layer(), classLoader); } + public LayerInfo buildLayer(final Layer layer) { - return buildLayer(layer, (cf, p) -> new ModuleClassLoader("LAYER "+layer.name(), cf, p)); + return buildLayer(layer, (cf, p) -> new ModuleClassLoader("LAYER " + layer.name(), cf, p)); } @Override diff --git a/src/main/java/cpw/mods/modlauncher/PredicateVisitor.java b/loader/src/main/java/cpw/mods/modlauncher/PredicateVisitor.java similarity index 75% rename from src/main/java/cpw/mods/modlauncher/PredicateVisitor.java rename to loader/src/main/java/cpw/mods/modlauncher/PredicateVisitor.java index 2955b016d..4e39477f1 100644 --- a/src/main/java/cpw/mods/modlauncher/PredicateVisitor.java +++ b/loader/src/main/java/cpw/mods/modlauncher/PredicateVisitor.java @@ -1,19 +1,15 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; @@ -26,7 +22,7 @@ public class PredicateVisitor extends ClassVisitor { private static final int ASM_API = Opcodes.ASM9; - + private ITransformerVotingContext.MethodPredicate methodPredicate; private ITransformerVotingContext.FieldPredicate fieldPredicate; private ITransformerVotingContext.ClassPredicate classPredicate; @@ -67,5 +63,4 @@ public MethodVisitor visitMethod(final int access, final String name, final Stri public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { result = classPredicate == null || classPredicate.test(version, access, name, signature, superName, interfaces); } - } diff --git a/src/main/java/cpw/mods/modlauncher/TestingLaunchHandlerService.java b/loader/src/main/java/cpw/mods/modlauncher/TestingLaunchHandlerService.java similarity index 61% rename from src/main/java/cpw/mods/modlauncher/TestingLaunchHandlerService.java rename to loader/src/main/java/cpw/mods/modlauncher/TestingLaunchHandlerService.java index e374aa747..9ff5e3535 100644 --- a/src/main/java/cpw/mods/modlauncher/TestingLaunchHandlerService.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TestingLaunchHandlerService.java @@ -1,27 +1,25 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; +import cpw.mods.modlauncher.api.ILaunchHandlerService; import cpw.mods.modlauncher.api.ServiceRunner; - -import java.lang.invoke.*; +import java.lang.invoke.LambdaConversionException; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; /** * Test harness launch service - this will do nothing, but will take "test.harness" and offer it to the transformer diff --git a/src/main/java/cpw/mods/modlauncher/TransformList.java b/loader/src/main/java/cpw/mods/modlauncher/TransformList.java similarity index 55% rename from src/main/java/cpw/mods/modlauncher/TransformList.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformList.java index 6b23fcbef..755b1f55b 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformList.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformList.java @@ -1,28 +1,24 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; - -import java.util.*; +import cpw.mods.modlauncher.api.ITransformer; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantReadWriteLock; /** * Holds onto a specific list of transformers targetting a particular node type @@ -38,6 +34,7 @@ public class TransformList { /** * Testing only + * * @return a map */ private Map>> getTransformers() { @@ -48,11 +45,14 @@ void addTransformer(TransformTargetLabel targetLabel, ITransformer transforme // thread safety - compute if absent to insert the list transformers.computeIfAbsent(targetLabel, v -> new ArrayList<>()); // thread safety - compute if present to mutate the list under the protection of the CHM - transformers.computeIfPresent(targetLabel, (k,l)-> { l.add(transformer); return l;}); + transformers.computeIfPresent(targetLabel, (k, l) -> { + l.add(transformer); + return l; + }); } List> getTransformersForLabel(TransformTargetLabel label) { // thread safety - compute if absent to insert the list - return transformers.computeIfAbsent(label, v-> new ArrayList<>()); + return transformers.computeIfAbsent(label, v -> new ArrayList<>()); } } diff --git a/src/main/java/cpw/mods/modlauncher/TransformStore.java b/loader/src/main/java/cpw/mods/modlauncher/TransformStore.java similarity index 66% rename from src/main/java/cpw/mods/modlauncher/TransformStore.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformStore.java index fd52cb3b0..f7792e6ac 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformStore.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformStore.java @@ -1,31 +1,34 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; + +import cpw.mods.modlauncher.api.ITransformationService; +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.TargetType; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.objectweb.asm.tree.*; - -import java.util.*; - -import static cpw.mods.modlauncher.LogMarkers.*; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; +import org.objectweb.asm.tree.MethodNode; /** * Transformer store - holds all the transformers @@ -61,7 +64,7 @@ List> getTransformersFor(String className, TargetType void addTransformer(TransformTargetLabel targetLabel, ITransformer transformer, ITransformationService service) { - LOGGER.debug(MODLAUNCHER,"Adding transformer {} to {}", () -> transformer, () -> targetLabel); + LOGGER.debug(MODLAUNCHER, "Adding transformer {} to {}", () -> transformer, () -> targetLabel); classNeedsTransforming.add(targetLabel.getClassName().getInternalName()); final TransformList transformList = (TransformList) this.transformers.get(targetLabel.getTargetType()); transformList.addTransformer(targetLabel, new TransformerHolder<>(transformer, service)); diff --git a/src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java b/loader/src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java similarity index 72% rename from src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java index df9ac7053..a42b8cfa0 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java @@ -1,50 +1,49 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; -import org.objectweb.asm.*; -import org.objectweb.asm.tree.*; +import static cpw.mods.modlauncher.api.TargetType.CLASS; +import static cpw.mods.modlauncher.api.TargetType.FIELD; +import static cpw.mods.modlauncher.api.TargetType.METHOD; -import java.util.*; - -import static cpw.mods.modlauncher.api.TargetType.*; +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.TargetType; +import java.util.Objects; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; /** * Detailed targetting information */ public final class TransformTargetLabel { - private final Type className; private final String elementName; private final Type elementDescriptor; private final TargetType labelType; - + TransformTargetLabel(ITransformer.Target target) { this(target.className(), target.elementName(), target.elementDescriptor(), target.targetType()); } + private TransformTargetLabel(String className, String elementName, String elementDescriptor, TargetType labelType) { this.className = Type.getObjectType(className.replace('.', '/')); this.elementName = elementName; this.elementDescriptor = elementDescriptor.length() > 0 ? Type.getMethodType(elementDescriptor) : Type.VOID_TYPE; this.labelType = labelType; } + public TransformTargetLabel(String className, String fieldName) { this(className, fieldName, "", FIELD); } diff --git a/src/main/java/cpw/mods/modlauncher/TransformationServiceDecorator.java b/loader/src/main/java/cpw/mods/modlauncher/TransformationServiceDecorator.java similarity index 52% rename from src/main/java/cpw/mods/modlauncher/TransformationServiceDecorator.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformationServiceDecorator.java index 404a51eaa..58ed8e428 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformationServiceDecorator.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformationServiceDecorator.java @@ -1,33 +1,37 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; + +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.ITransformationService; +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; +import cpw.mods.modlauncher.api.TargetType; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.VisibleForTesting; -import java.util.*; -import java.util.stream.*; - -import static cpw.mods.modlauncher.LogMarkers.*; - /** * Decorates {@link cpw.mods.modlauncher.api.ITransformationService} to track state and other runtime metadata. */ @@ -43,12 +47,12 @@ public TransformationServiceDecorator(ITransformationService service) { void onLoad(IEnvironment env, Set otherServices) { try { - LOGGER.debug(MODLAUNCHER,"Loading service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Loading service {}", this.service::name); this.service.onLoad(env, otherServices); this.isValid = true; - LOGGER.debug(MODLAUNCHER,"Loaded service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Loaded service {}", this.service::name); } catch (IncompatibleEnvironmentException e) { - LOGGER.error(MODLAUNCHER,"Service failed to load {}", this.service.name(), e); + LOGGER.error(MODLAUNCHER, "Service failed to load {}", this.service.name(), e); this.isValid = false; } } @@ -58,13 +62,13 @@ boolean isValid() { } void onInitialize(IEnvironment environment) { - LOGGER.debug(MODLAUNCHER,"Initializing transformation service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Initializing transformation service {}", this.service::name); this.service.initialize(environment); - LOGGER.debug(MODLAUNCHER,"Initialized transformation service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Initialized transformation service {}", this.service::name); } public void gatherTransformers(TransformStore transformStore) { - LOGGER.debug(MODLAUNCHER,"Initializing transformers for transformation service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Initializing transformers for transformation service {}", this.service::name); final List> transformers = this.service.transformers(); Objects.requireNonNull(transformers, "The transformers list should not be null"); transformers.forEach(xform -> { @@ -73,19 +77,19 @@ public void gatherTransformers(TransformStore transformStore) { final Set> targets = xform.targets(); if (!targets.isEmpty()) { final Map, List> targetTypeListMap = targets.stream() - .map(TransformTargetLabel::new) - .collect(Collectors.groupingBy(TransformTargetLabel::getTargetType)); + .map(TransformTargetLabel::new) + .collect(Collectors.groupingBy(TransformTargetLabel::getTargetType)); if (targetTypeListMap.keySet().size() > 1 || !targetTypeListMap.containsKey(targetType)) { - LOGGER.error(MODLAUNCHER,"Invalid target {} for transformer {}", targetType, xform); + LOGGER.error(MODLAUNCHER, "Invalid target {} for transformer {}", targetType, xform); throw new IllegalArgumentException("The transformer contains invalid targets"); } targetTypeListMap.values() - .stream() - .flatMap(Collection::stream) - .forEach(target -> transformStore.addTransformer(target, xform, service)); + .stream() + .flatMap(Collection::stream) + .forEach(target -> transformStore.addTransformer(target, xform, service)); } }); - LOGGER.debug(MODLAUNCHER,"Initialized transformers for transformation service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Initialized transformers for transformation service {}", this.service::name); } ITransformationService getService() { @@ -93,9 +97,9 @@ ITransformationService getService() { } List runScan(final Environment environment) { - LOGGER.debug(MODLAUNCHER,"Beginning scan trigger - transformation service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "Beginning scan trigger - transformation service {}", this.service::name); final List scanResults = this.service.beginScanning(environment); - LOGGER.debug(MODLAUNCHER,"End scan trigger - transformation service {}", this.service::name); + LOGGER.debug(MODLAUNCHER, "End scan trigger - transformation service {}", this.service::name); return scanResults; } diff --git a/src/main/java/cpw/mods/modlauncher/TransformationServicesHandler.java b/loader/src/main/java/cpw/mods/modlauncher/TransformationServicesHandler.java similarity index 58% rename from src/main/java/cpw/mods/modlauncher/TransformationServicesHandler.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformationServicesHandler.java index 6b4209eb8..f5c24c183 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformationServicesHandler.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformationServicesHandler.java @@ -1,36 +1,38 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; +import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER; + +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.ITransformationService; +import cpw.mods.modlauncher.api.NamedPath; import cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService; import cpw.mods.modlauncher.util.ServiceLoaderUtils; -import joptsimple.*; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.function.BiFunction; +import java.util.stream.Collectors; +import joptsimple.OptionParser; +import joptsimple.OptionSet; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.function.*; -import java.util.stream.*; - -import static cpw.mods.modlauncher.LogMarkers.*; - class TransformationServicesHandler { private static final Logger LOGGER = LogManager.getLogger(); private Map serviceLookup; @@ -51,13 +53,13 @@ List initializeTransformationServices(ArgumentH } TransformingClassLoader buildTransformingClassLoader(final LaunchPluginHandler pluginHandler, final Environment environment, final ModuleLayerHandler layerHandler) { - final var layerInfo = layerHandler.buildLayer(IModuleLayerManager.Layer.GAME, (cf, parents)->new TransformingClassLoader(transformStore, pluginHandler, environment, cf, parents)); - layerHandler.updateLayer(IModuleLayerManager.Layer.PLUGIN, li->li.cl().setFallbackClassLoader(layerInfo.cl())); + final var layerInfo = layerHandler.buildLayer(IModuleLayerManager.Layer.GAME, (cf, parents) -> new TransformingClassLoader(transformStore, pluginHandler, environment, cf, parents)); + layerHandler.updateLayer(IModuleLayerManager.Layer.PLUGIN, li -> li.cl().setFallbackClassLoader(layerInfo.cl())); return (TransformingClassLoader) layerInfo.cl(); } private void processArguments(ArgumentHandler argumentHandler, Environment environment) { - LOGGER.debug(MODLAUNCHER,"Configuring option handling for services"); + LOGGER.debug(MODLAUNCHER, "Configuring option handling for services"); argumentHandler.processArguments(environment, this::computeArgumentsForServices, this::offerArgumentResultsToServices); } @@ -65,7 +67,7 @@ private void processArguments(ArgumentHandler argumentHandler, Environment envir private void computeArgumentsForServices(OptionParser parser) { serviceLookup.values().stream() .map(TransformationServiceDecorator::getService) - .forEach(service->service.arguments((a, b) -> parser.accepts(service.name() + "." + a, b))); + .forEach(service -> service.arguments((a, b) -> parser.accepts(service.name() + "." + a, b))); } private void offerArgumentResultsToServices(OptionSet optionSet, BiFunction resultHandler) { @@ -75,24 +77,23 @@ private void offerArgumentResultsToServices(OptionSet optionSet, BiFunction s.gatherTransformers(transformStore)); } private void initialiseTransformationServices(Environment environment) { - LOGGER.debug(MODLAUNCHER,"Transformation services initializing"); + LOGGER.debug(MODLAUNCHER, "Transformation services initializing"); serviceLookup.values().forEach(s -> s.onInitialize(environment)); } private List runScanningTransformationServices(Environment environment) { - LOGGER.debug(MODLAUNCHER,"Transformation services begin scanning"); + LOGGER.debug(MODLAUNCHER, "Transformation services begin scanning"); return serviceLookup.values() .stream() - .map(s -> s.runScan(environment)) - .mapMulti(Iterable::forEach) + .map(s -> s.runScan(environment)).mapMulti(Iterable::forEach) .toList(); } @@ -100,45 +101,42 @@ private void validateTransformationServices() { if (serviceLookup.values().stream().filter(d -> !d.isValid()).count() > 0) { final List services = serviceLookup.values().stream().filter(d -> !d.isValid()).map(TransformationServiceDecorator::getService).collect(Collectors.toList()); final String names = services.stream().map(ITransformationService::name).collect(Collectors.joining(",")); - LOGGER.error(MODLAUNCHER,"Found {} services that failed to load : [{}]", services.size(), names); - throw new InvalidLauncherSetupException("Invalid Services found "+names); + LOGGER.error(MODLAUNCHER, "Found {} services that failed to load : [{}]", services.size(), names); + throw new InvalidLauncherSetupException("Invalid Services found " + names); } } private void loadTransformationServices(Environment environment) { - LOGGER.debug(MODLAUNCHER,"Transformation services loading"); + LOGGER.debug(MODLAUNCHER, "Transformation services loading"); serviceLookup.values().forEach(s -> s.onLoad(environment, serviceLookup.keySet())); } void discoverServices(final ArgumentHandler.DiscoveryData discoveryData) { LOGGER.debug(MODLAUNCHER, "Discovering transformation services"); var bootLayer = layerHandler.getLayer(IModuleLayerManager.Layer.BOOT).orElseThrow(); - var earlyDiscoveryServices = ServiceLoaderUtils.streamServiceLoader(()->ServiceLoader.load(bootLayer, ITransformerDiscoveryService.class), sce -> LOGGER.fatal(MODLAUNCHER, "Encountered serious error loading transformation discoverer, expect problems", sce)) + var earlyDiscoveryServices = ServiceLoaderUtils.streamServiceLoader(() -> ServiceLoader.load(bootLayer, ITransformerDiscoveryService.class), sce -> LOGGER.fatal(MODLAUNCHER, "Encountered serious error loading transformation discoverer, expect problems", sce)) .toList(); var additionalPaths = earlyDiscoveryServices.stream() - .map(s->s.candidates(discoveryData.gameDir(), discoveryData.launchTarget())) + .map(s -> s.candidates(discoveryData.gameDir(), discoveryData.launchTarget())) .mapMulti(Iterable::forEach) .toList(); - LOGGER.debug(MODLAUNCHER, "Found additional transformation services from discovery services: {}", ()->additionalPaths.stream().map(ap->Arrays.toString(ap.paths())).collect(Collectors.joining())); - additionalPaths.forEach(np->layerHandler.addToLayer(IModuleLayerManager.Layer.SERVICE, np)); + LOGGER.debug(MODLAUNCHER, "Found additional transformation services from discovery services: {}", () -> additionalPaths.stream().map(ap -> Arrays.toString(ap.paths())).collect(Collectors.joining())); + additionalPaths.forEach(np -> layerHandler.addToLayer(IModuleLayerManager.Layer.SERVICE, np)); var serviceLayer = layerHandler.buildLayer(IModuleLayerManager.Layer.SERVICE); - earlyDiscoveryServices.forEach(s->s.earlyInitialization(discoveryData.launchTarget(), discoveryData.arguments())); - serviceLookup = ServiceLoaderUtils.streamServiceLoader(()->ServiceLoader.load(serviceLayer.layer(), ITransformationService.class), sce -> LOGGER.fatal(MODLAUNCHER, "Encountered serious error loading transformation service, expect problems", sce)) + earlyDiscoveryServices.forEach(s -> s.earlyInitialization(discoveryData.launchTarget(), discoveryData.arguments())); + serviceLookup = ServiceLoaderUtils.streamServiceLoader(() -> ServiceLoader.load(serviceLayer.layer(), ITransformationService.class), sce -> LOGGER.fatal(MODLAUNCHER, "Encountered serious error loading transformation service, expect problems", sce)) .collect(Collectors.toMap(ITransformationService::name, TransformationServiceDecorator::new)); - var modlist = serviceLookup.entrySet().stream().map(e->Map.of( + var modlist = serviceLookup.entrySet().stream().map(e -> Map.of( "name", e.getKey(), "type", "TRANSFORMATIONSERVICE", - "file", ServiceLoaderUtils.fileNameFor(e.getValue().getClass()) - )).toList(); - Launcher.INSTANCE.environment().getProperty(IEnvironment.Keys.MODLIST.get()).ifPresent(ml->ml.addAll(modlist)); - LOGGER.debug(MODLAUNCHER,"Found transformer services : [{}]", () -> String.join(",",serviceLookup.keySet())); + "file", ServiceLoaderUtils.fileNameFor(e.getValue().getClass()))).toList(); + Launcher.INSTANCE.environment().getProperty(IEnvironment.Keys.MODLIST.get()).ifPresent(ml -> ml.addAll(modlist)); + LOGGER.debug(MODLAUNCHER, "Found transformer services : [{}]", () -> String.join(",", serviceLookup.keySet())); } public List triggerScanCompletion(IModuleLayerManager moduleLayerManager) { return serviceLookup.values().stream() - .map(tsd->tsd.onCompleteScan(moduleLayerManager)) - .mapMulti(Iterable::forEach) + .map(tsd -> tsd.onCompleteScan(moduleLayerManager)).mapMulti(Iterable::forEach) .toList(); - } } diff --git a/src/main/java/cpw/mods/modlauncher/TransformerAuditTrail.java b/loader/src/main/java/cpw/mods/modlauncher/TransformerAuditTrail.java similarity index 75% rename from src/main/java/cpw/mods/modlauncher/TransformerAuditTrail.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformerAuditTrail.java index 6b3836892..77b6e3dd4 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformerAuditTrail.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformerAuditTrail.java @@ -1,19 +1,15 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; @@ -23,8 +19,10 @@ import cpw.mods.modlauncher.api.ITransformerActivity; import cpw.mods.modlauncher.api.ITransformerAuditTrail; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; - -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -56,7 +54,7 @@ public Type getType() { } public String getActivityString() { - return this.type.getLabel() + ":"+ String.join(":",this.context); + return this.type.getLabel() + ":" + String.join(":", this.context); } } @@ -69,7 +67,7 @@ public void addPluginCustomAuditTrail(String clazz, ILaunchPluginService plugin, } public void addPluginAuditTrail(String clazz, ILaunchPluginService plugin, ILaunchPluginService.Phase phase) { - getTransformerActivities(clazz).add(new TransformerActivity(ITransformerActivity.Type.PLUGIN, plugin.name(), phase.name().substring(0,1))); + getTransformerActivities(clazz).add(new TransformerActivity(ITransformerActivity.Type.PLUGIN, plugin.name(), phase.name().substring(0, 1))); } public void addTransformerAuditTrail(String clazz, ITransformationService transformService, ITransformer transformer) { @@ -82,8 +80,9 @@ private String[] concat(String first, String[] rest) { System.arraycopy(rest, 0, res, 1, rest.length); return res; } + private List getTransformerActivities(final String clazz) { - return audit.computeIfAbsent(clazz, k->new ArrayList<>()); + return audit.computeIfAbsent(clazz, k -> new ArrayList<>()); } @Override diff --git a/src/main/java/cpw/mods/modlauncher/TransformerClassWriter.java b/loader/src/main/java/cpw/mods/modlauncher/TransformerClassWriter.java similarity index 90% rename from src/main/java/cpw/mods/modlauncher/TransformerClassWriter.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformerClassWriter.java index 325d5b500..b0b01544d 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformerClassWriter.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformerClassWriter.java @@ -1,25 +1,26 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; import cpw.mods.modlauncher.api.ITransformerActivity; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.objectweb.asm.ClassReader; @@ -28,9 +29,6 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - class TransformerClassWriter extends ClassWriter { private static final Logger LOGGER = LogManager.getLogger(); private static final Map CLASS_PARENTS = new ConcurrentHashMap<>(); @@ -78,7 +76,6 @@ protected String getCommonSuperClass(final String type1, final String type2) { return type; } - private Set getSupers(final String typeName) { computeHierarchy(typeName); return CLASS_HIERARCHIES.get(typeName); @@ -131,7 +128,7 @@ private void computeHierarchyFromClass(final String name, final Class clazz) hierarchies.add("java/lang/Object"); } IS_INTERFACE.put(name, clazz.isInterface()); - Arrays.stream(clazz.getInterfaces()).forEach(c->{ + Arrays.stream(clazz.getInterfaces()).forEach(c -> { String n = c.getName().replace('.', '/'); if (!CLASS_HIERARCHIES.containsKey(n)) computeHierarchyFromClass(n, c); @@ -164,7 +161,6 @@ private void computeHierarchyFromFile(final String className) { } private class SuperCollectingVisitor extends ClassVisitor { - public SuperCollectingVisitor() { super(Opcodes.ASM9); } @@ -181,7 +177,7 @@ public void visit(final int version, final int access, final String name, final hierarchies.add("java/lang/Object"); } IS_INTERFACE.put(name, (access & Opcodes.ACC_INTERFACE) != 0); - Arrays.stream(interfaces).forEach(n->{ + Arrays.stream(interfaces).forEach(n -> { computeHierarchy(n); hierarchies.add(n); hierarchies.addAll(CLASS_HIERARCHIES.get(n)); diff --git a/src/main/java/cpw/mods/modlauncher/TransformerHolder.java b/loader/src/main/java/cpw/mods/modlauncher/TransformerHolder.java similarity index 55% rename from src/main/java/cpw/mods/modlauncher/TransformerHolder.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformerHolder.java index 9c6a2a5f9..ef0dc6870 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformerHolder.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformerHolder.java @@ -1,26 +1,24 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; - -import org.jetbrains.annotations.NotNull; +import cpw.mods.modlauncher.api.ITransformationService; +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.ITransformerVotingContext; +import cpw.mods.modlauncher.api.TargetType; +import cpw.mods.modlauncher.api.TransformerVoteResult; import java.util.Set; public class TransformerHolder implements ITransformer { @@ -32,19 +30,16 @@ public TransformerHolder(final ITransformer wrapped, ITransformationService o this.owner = owner; } - @NotNull @Override public T transform(final T input, final ITransformerVotingContext context) { return wrapped.transform(input, context); } - @NotNull @Override public TransformerVoteResult castVote(final ITransformerVotingContext context) { return wrapped.castVote(context); } - @NotNull @Override public Set> targets() { return wrapped.targets(); diff --git a/loader/src/main/java/cpw/mods/modlauncher/TransformerVote.java b/loader/src/main/java/cpw/mods/modlauncher/TransformerVote.java new file mode 100644 index 000000000..d0d2080ce --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformerVote.java @@ -0,0 +1,36 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.TransformerVoteResult; + +class TransformerVote { + private final ITransformer transformer; + private final TransformerVoteResult result; + + TransformerVote(TransformerVoteResult vr, ITransformer transformer) { + this.transformer = transformer; + this.result = vr; + } + + TransformerVoteResult getResult() { + return result; + } + + ITransformer getTransformer() { + return transformer; + } +} diff --git a/src/main/java/cpw/mods/modlauncher/TransformingClassLoader.java b/loader/src/main/java/cpw/mods/modlauncher/TransformingClassLoader.java similarity index 73% rename from src/main/java/cpw/mods/modlauncher/TransformingClassLoader.java rename to loader/src/main/java/cpw/mods/modlauncher/TransformingClassLoader.java index 89343a57f..e3d5bd992 100644 --- a/src/main/java/cpw/mods/modlauncher/TransformingClassLoader.java +++ b/loader/src/main/java/cpw/mods/modlauncher/TransformingClassLoader.java @@ -1,29 +1,26 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; import cpw.mods.cl.ModuleClassLoader; -import cpw.mods.modlauncher.api.*; -import org.jetbrains.annotations.VisibleForTesting; - +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.ITransformerActivity; import java.lang.module.Configuration; -import java.util.*; +import java.util.List; +import org.jetbrains.annotations.VisibleForTesting; /** * Module transforming class loader @@ -32,6 +29,7 @@ public class TransformingClassLoader extends ModuleClassLoader { static { ClassLoader.registerAsParallelCapable(); } + private final ClassTransformer classTransformer; public TransformingClassLoader(TransformStore transformStore, LaunchPluginHandler pluginHandler, IModuleLayerManager moduleLayerHandler) { @@ -48,7 +46,7 @@ public TransformingClassLoader(TransformStore transformStore, LaunchPluginHandle public TransformingClassLoader(TransformStore transformStore, LaunchPluginHandler pluginHandler, final Environment environment, final Configuration configuration, List parentLayers, ClassLoader parentClassLoader) { super("TRANSFORMER", configuration, parentLayers, parentClassLoader); TransformerAuditTrail tat = new TransformerAuditTrail(); - environment.computePropertyIfAbsent(IEnvironment.Keys.AUDITTRAIL.get(), v->tat); + environment.computePropertyIfAbsent(IEnvironment.Keys.AUDITTRAIL.get(), v -> tat); this.classTransformer = new ClassTransformer(transformStore, pluginHandler, this, tat); } diff --git a/loader/src/main/java/cpw/mods/modlauncher/VoteDeadlockException.java b/loader/src/main/java/cpw/mods/modlauncher/VoteDeadlockException.java new file mode 100644 index 000000000..582852060 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/VoteDeadlockException.java @@ -0,0 +1,24 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +import java.util.List; + +/** + * Exception thrown when a vote impass occurs + */ +public class VoteDeadlockException extends RuntimeException { + VoteDeadlockException(List> votes, Class aClass) {} +} diff --git a/loader/src/main/java/cpw/mods/modlauncher/VoteRejectedException.java b/loader/src/main/java/cpw/mods/modlauncher/VoteRejectedException.java new file mode 100644 index 000000000..29132a0ec --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/VoteRejectedException.java @@ -0,0 +1,24 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher; + +import java.util.List; + +/** + * Exception thrown when a voter rejects the entire configuration + */ +public class VoteRejectedException extends RuntimeException { + VoteRejectedException(List> votes, Class aClass) {} +} diff --git a/src/main/java/cpw/mods/modlauncher/VotingContext.java b/loader/src/main/java/cpw/mods/modlauncher/VotingContext.java similarity index 72% rename from src/main/java/cpw/mods/modlauncher/VotingContext.java rename to loader/src/main/java/cpw/mods/modlauncher/VotingContext.java index 83da229b1..a28a11aad 100644 --- a/src/main/java/cpw/mods/modlauncher/VotingContext.java +++ b/loader/src/main/java/cpw/mods/modlauncher/VotingContext.java @@ -1,28 +1,29 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher; -import cpw.mods.modlauncher.api.*; -import org.objectweb.asm.tree.*; - +import cpw.mods.modlauncher.api.ITransformerActivity; +import cpw.mods.modlauncher.api.ITransformerVotingContext; import java.util.List; import java.util.function.Supplier; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; +import org.objectweb.asm.tree.FieldNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; /** * The internal vote context structure. @@ -111,11 +112,11 @@ public boolean applyInstructionPredicate(InsnPredicate insnPredicate) { private Object[] toObjectArray(final AbstractInsnNode insnNode) { if (insnNode instanceof MethodInsnNode) { final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - return new Object[] {methodInsnNode.name, methodInsnNode.desc, methodInsnNode.owner, methodInsnNode.itf}; + return new Object[] { methodInsnNode.name, methodInsnNode.desc, methodInsnNode.owner, methodInsnNode.itf }; } if (insnNode instanceof FieldInsnNode) { final FieldInsnNode fieldInsnNode = (FieldInsnNode) insnNode; - return new Object[] {fieldInsnNode.name, fieldInsnNode.desc, fieldInsnNode.owner}; + return new Object[] { fieldInsnNode.name, fieldInsnNode.desc, fieldInsnNode.owner }; } return EMPTY; } diff --git a/src/main/java/cpw/mods/modlauncher/api/IEnvironment.java b/loader/src/main/java/cpw/mods/modlauncher/api/IEnvironment.java similarity index 78% rename from src/main/java/cpw/mods/modlauncher/api/IEnvironment.java rename to loader/src/main/java/cpw/mods/modlauncher/api/IEnvironment.java index ca3af3cf0..4a61a6d43 100644 --- a/src/main/java/cpw/mods/modlauncher/api/IEnvironment.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/IEnvironment.java @@ -1,28 +1,26 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; - -import java.nio.file.*; -import java.util.*; -import java.util.function.*; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; /** * System environment. Global properties relevant to the current environment and lookups to find global artifacts @@ -31,6 +29,7 @@ public interface IEnvironment { /** * Get a property from the Environment + * * @param key to find * @param Type of key * @return the value @@ -40,12 +39,13 @@ public interface IEnvironment { /** * Compute a new value for insertion into the environment, if not already present. * - * @param key to insert + * @param key to insert * @param valueFunction the supplier of a value - * @param Type of key + * @param Type of key * @return The value of the key */ T computePropertyIfAbsent(TypesafeMap.Key key, final Function, ? extends T> valueFunction); + /** * Find the named {@link ILaunchPluginService} * @@ -93,7 +93,7 @@ final class Keys { * A simple List of Maps for Mod data. Map keys should include a "name" and "description". "file" and "type" are * populated automatically, as is "name". */ - public static final Supplier>>> MODLIST = buildKey("modlist", List.class); + public static final Supplier>>> MODLIST = buildKey("modlist", List.class); /** * The specification version for ModLauncher. */ @@ -104,7 +104,6 @@ final class Keys { public static final Supplier> MLIMPL_VERSION = buildKey("mlimplVersion", String.class); } - static Supplier> buildKey(String name, Class clazz) { return new TypesafeMap.KeyBuilder<>(name, clazz, IEnvironment.class); } diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/ILaunchHandlerService.java b/loader/src/main/java/cpw/mods/modlauncher/api/ILaunchHandlerService.java new file mode 100644 index 000000000..594289b96 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ILaunchHandlerService.java @@ -0,0 +1,28 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +/** + * A singleton instance of this is loaded by the system to designate the launch target + */ +public interface ILaunchHandlerService { + String name(); + + ServiceRunner launchService(String[] arguments, ModuleLayer gameLayer); + + default NamedPath[] getPaths() { + return new NamedPath[0]; + } +} diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/IModuleLayerManager.java b/loader/src/main/java/cpw/mods/modlauncher/api/IModuleLayerManager.java new file mode 100644 index 000000000..9cd42db03 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/IModuleLayerManager.java @@ -0,0 +1,38 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +import java.util.Optional; + +public interface IModuleLayerManager { + Optional getLayer(Layer layer); + + enum Layer { + BOOT(), + SERVICE(BOOT), + PLUGIN(BOOT), + GAME(PLUGIN, SERVICE); + + private final Layer[] parent; + + Layer(final Layer... parent) { + this.parent = parent; + } + + public Layer[] getParent() { + return parent; + } + } +} diff --git a/src/main/java/cpw/mods/modlauncher/api/ITransformationService.java b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformationService.java similarity index 72% rename from src/main/java/cpw/mods/modlauncher/api/ITransformationService.java rename to loader/src/main/java/cpw/mods/modlauncher/api/ITransformationService.java index f9df325eb..91923dd79 100644 --- a/src/main/java/cpw/mods/modlauncher/api/ITransformationService.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformationService.java @@ -1,29 +1,25 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; import cpw.mods.jarhandling.SecureJar; -import joptsimple.*; -import org.jetbrains.annotations.NotNull; - -import java.util.*; -import java.util.function.*; +import java.util.List; +import java.util.Set; +import java.util.function.BiFunction; +import joptsimple.OptionSpec; +import joptsimple.OptionSpecBuilder; /** * Users who wish to provide a mod service which plugs into this API @@ -38,7 +34,6 @@ public interface ITransformationService { * * @return the name of the mod service */ - @NotNull String name(); /** @@ -47,11 +42,9 @@ public interface ITransformationService { * * @param argumentBuilder a function mapping name, description to a set of JOptSimple properties for that argument */ - default void arguments(BiFunction argumentBuilder) { - } + default void arguments(BiFunction argumentBuilder) {} - default void argumentValues(OptionResult option) { - } + default void argumentValues(OptionResult option) {} /** * Initialize your service. @@ -61,6 +54,7 @@ default void argumentValues(OptionResult option) { void initialize(IEnvironment environment); record Resource(IModuleLayerManager.Layer target, List resources) {} + /** * Scan for mods (but don't classload them), identify metadata that might drive * game functionality, return list of elements and target module layer (One of PLUGIN or GAME) @@ -91,16 +85,14 @@ default List completeScan(IModuleLayerManager layerManager) { * The {@link ITransformer} is the fundamental operator of the system. * * @return A list of transformers for your ITransformationService. This is called after {@link #onLoad(IEnvironment, Set)} - * and {@link #initialize(IEnvironment)}, so you can return an appropriate Transformer set for the environment - * you find yourself in. + * and {@link #initialize(IEnvironment)}, so you can return an appropriate Transformer set for the environment + * you find yourself in. */ - @NotNull List> transformers(); interface OptionResult { V value(OptionSpec options); - @NotNull List values(OptionSpec options); } } diff --git a/src/main/java/cpw/mods/modlauncher/api/ITransformer.java b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformer.java similarity index 85% rename from src/main/java/cpw/mods/modlauncher/api/ITransformer.java rename to loader/src/main/java/cpw/mods/modlauncher/api/ITransformer.java index 714c288ab..9bcb65825 100644 --- a/src/main/java/cpw/mods/modlauncher/api/ITransformer.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformer.java @@ -1,37 +1,30 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; -import org.jetbrains.annotations.NotNull; +import java.util.Set; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.MethodNode; -import java.util.*; - /** * A transformer is injected into the modding ClassLoader. It can manipulate any item * it is designated to target. */ public interface ITransformer { - - String[] DEFAULT_LABEL = {"default"}; + String[] DEFAULT_LABEL = { "default" }; /** * Transform the input to the ITransformer's desire. The context from the last vote is @@ -40,9 +33,8 @@ public interface ITransformer { * @param input The ASM input node, which can be mutated directly * @param context The voting context * @return An ASM node of the same type as that supplied. It will be used for subsequent - * rounds of voting. + * rounds of voting. */ - @NotNull T transform(T input, ITransformerVotingContext context); /** @@ -69,7 +61,6 @@ public interface ITransformer { * @param context The context of the vote * @return A TransformerVoteResult indicating the desire of this transformer */ - @NotNull TransformerVoteResult castVote(ITransformerVotingContext context); /** @@ -79,10 +70,8 @@ public interface ITransformer { * * @return The set of targets this transformer wishes to apply to */ - @NotNull Set> targets(); - - @NotNull + TargetType getTargetType(); /** @@ -94,6 +83,7 @@ default String[] labels() { /** * Simple data holder indicating where the {@link ITransformer} can target. + * * @param className The name of the class being targetted * @param elementName The name of the element being targetted. This is the field name for a field, * the method name for a method. Empty string for other types @@ -108,7 +98,6 @@ record Target(String className, String elementName, String elementDescriptor, * @param className The name of the class * @return A target for the named class */ - @NotNull public static Target targetClass(String className) { return new Target<>(className, "", "", TargetType.CLASS); } @@ -119,10 +108,10 @@ public static Target targetClass(String className) { * @param className The name of the class * @return A target for the named class */ - @NotNull public static Target targetPreClass(String className) { return new Target<>(className, "", "", TargetType.PRE_CLASS); } + /** * Convenience method return a {@link Target} for a method * @@ -131,7 +120,6 @@ public static Target targetPreClass(String className) { * @param methodDescriptor The method's descriptor string * @return A target for the named method */ - @NotNull public static Target targetMethod(String className, String methodName, String methodDescriptor) { return new Target<>(className, methodName, methodDescriptor, TargetType.METHOD); } @@ -143,7 +131,6 @@ public static Target targetMethod(String className, String methodNam * @param fieldName The name of the field * @return A target for the named field */ - @NotNull public static Target targetField(String className, String fieldName) { return new Target<>(className, fieldName, "", TargetType.FIELD); } diff --git a/src/main/java/cpw/mods/modlauncher/api/ITransformerActivity.java b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerActivity.java similarity index 57% rename from src/main/java/cpw/mods/modlauncher/api/ITransformerActivity.java rename to loader/src/main/java/cpw/mods/modlauncher/api/ITransformerActivity.java index c694e2376..9c983709d 100644 --- a/src/main/java/cpw/mods/modlauncher/api/ITransformerActivity.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerActivity.java @@ -1,19 +1,15 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerAuditTrail.java b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerAuditTrail.java new file mode 100644 index 000000000..85a5dc31e --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerAuditTrail.java @@ -0,0 +1,35 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +import java.util.List; + +public interface ITransformerAuditTrail { + /** + * Retrieve the list of activities for the specified class + * + * @param className Class name + * @return a read only list of activities + */ + List getActivityFor(String className); + + /** + * Retrieve a formatted string summarizing actions for the supplied class + * + * @param clazz The class + * @return A formatted string + */ + String getAuditString(String clazz); +} diff --git a/src/main/java/cpw/mods/modlauncher/api/ITransformerVotingContext.java b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerVotingContext.java similarity index 79% rename from src/main/java/cpw/mods/modlauncher/api/ITransformerVotingContext.java rename to loader/src/main/java/cpw/mods/modlauncher/api/ITransformerVotingContext.java index d39645c06..c727f4ecc 100644 --- a/src/main/java/cpw/mods/modlauncher/api/ITransformerVotingContext.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ITransformerVotingContext.java @@ -1,19 +1,15 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/IncompatibleEnvironmentException.java b/loader/src/main/java/cpw/mods/modlauncher/api/IncompatibleEnvironmentException.java new file mode 100644 index 000000000..71937a651 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/IncompatibleEnvironmentException.java @@ -0,0 +1,24 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +/** + * Indicate an incompatible environment to the modlauncher system. + */ +public class IncompatibleEnvironmentException extends Exception { + public IncompatibleEnvironmentException(String message) { + super(message); + } +} diff --git a/src/main/java/cpw/mods/modlauncher/api/LambdaExceptionUtils.java b/loader/src/main/java/cpw/mods/modlauncher/api/LambdaExceptionUtils.java similarity index 82% rename from src/main/java/cpw/mods/modlauncher/api/LambdaExceptionUtils.java rename to loader/src/main/java/cpw/mods/modlauncher/api/LambdaExceptionUtils.java index 2f57b95a4..ac333ac7f 100644 --- a/src/main/java/cpw/mods/modlauncher/api/LambdaExceptionUtils.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/LambdaExceptionUtils.java @@ -1,30 +1,28 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; -import java.util.function.*; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; /** * From stackoverflow: https://stackoverflow.com/a/27644392 */ public class LambdaExceptionUtils { - /** * .forEach(rethrowConsumer(name -> System.out.println(Class.forName(name)))); or .forEach(rethrowConsumer(ClassNameUtil::println)); */ diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/NamedPath.java b/loader/src/main/java/cpw/mods/modlauncher/api/NamedPath.java new file mode 100644 index 000000000..e98ddaab8 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/NamedPath.java @@ -0,0 +1,19 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +import java.nio.file.Path; + +public record NamedPath(String name, Path... paths) {} diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/ServiceRunner.java b/loader/src/main/java/cpw/mods/modlauncher/api/ServiceRunner.java new file mode 100644 index 000000000..d5f03538b --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/ServiceRunner.java @@ -0,0 +1,24 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2022 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +/** + * A type of Runnable that throws a Throwable. Allows for tidier implementations than Callable + */ +public interface ServiceRunner { + void run() throws Throwable; + + ServiceRunner NOOP = () -> {}; +} diff --git a/src/main/java/cpw/mods/modlauncher/api/TargetType.java b/loader/src/main/java/cpw/mods/modlauncher/api/TargetType.java similarity index 92% rename from src/main/java/cpw/mods/modlauncher/api/TargetType.java rename to loader/src/main/java/cpw/mods/modlauncher/api/TargetType.java index 23185aca1..325bdbca1 100644 --- a/src/main/java/cpw/mods/modlauncher/api/TargetType.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/TargetType.java @@ -1,13 +1,12 @@ package cpw.mods.modlauncher.api; import cpw.mods.modlauncher.TransformList; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldNode; -import org.objectweb.asm.tree.MethodNode; - import java.util.Map; import java.util.function.Supplier; import java.util.stream.Stream; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; +import org.objectweb.asm.tree.MethodNode; /** * Specifies the target type for the {@link ITransformer.Target}. Note that the type of the transformer T @@ -31,7 +30,7 @@ public final class TargetType { * Target a field. The {@link ITransformer} T variable must refer to {@link org.objectweb.asm.tree.FieldNode} */ public static final TargetType FIELD = new TargetType<>("FIELD", FieldNode.class); - + public static final TargetType[] VALUES = new TargetType[] { PRE_CLASS, CLASS, METHOD, FIELD }; private final String name; @@ -45,12 +44,12 @@ private TargetType(String name, Class nodeType) { public Class getNodeType() { return this.nodeType; } - + public static TargetType byName(String name) { return Stream.of(VALUES) - .filter(type -> type.name.equals(name)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("No TargetType of name " + name + " found")); + .filter(type -> type.name.equals(name)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("No TargetType of name " + name + " found")); } @SuppressWarnings("unchecked") diff --git a/loader/src/main/java/cpw/mods/modlauncher/api/TransformerVoteResult.java b/loader/src/main/java/cpw/mods/modlauncher/api/TransformerVoteResult.java new file mode 100644 index 000000000..f376bc891 --- /dev/null +++ b/loader/src/main/java/cpw/mods/modlauncher/api/TransformerVoteResult.java @@ -0,0 +1,19 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.api; + +public enum TransformerVoteResult { + YES, DEFER, NO, REJECT +} diff --git a/src/main/java/cpw/mods/modlauncher/api/TypesafeMap.java b/loader/src/main/java/cpw/mods/modlauncher/api/TypesafeMap.java similarity index 81% rename from src/main/java/cpw/mods/modlauncher/api/TypesafeMap.java rename to loader/src/main/java/cpw/mods/modlauncher/api/TypesafeMap.java index 158b96656..35f2cc197 100644 --- a/src/main/java/cpw/mods/modlauncher/api/TypesafeMap.java +++ b/loader/src/main/java/cpw/mods/modlauncher/api/TypesafeMap.java @@ -1,27 +1,29 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.api; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; -import java.util.function.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; +import java.util.function.Supplier; /** * Typed key-value map, similar to the AttributeKey netty stuff. Uses lambda interfaces for get/set. @@ -31,8 +33,7 @@ public final class TypesafeMap { private final ConcurrentHashMap, Object> map = new ConcurrentHashMap<>(); private final ConcurrentHashMap> keys = new ConcurrentHashMap<>(); - public TypesafeMap() { - } + public TypesafeMap() {} public TypesafeMap(Class owner) { KeyBuilder.keyBuilders.getOrDefault(owner, Collections.emptyList()).forEach(kb -> kb.buildKey(this)); diff --git a/src/main/java/cpw/mods/modlauncher/log/ExtraDataTextRenderer.java b/loader/src/main/java/cpw/mods/modlauncher/log/ExtraDataTextRenderer.java similarity index 71% rename from src/main/java/cpw/mods/modlauncher/log/ExtraDataTextRenderer.java rename to loader/src/main/java/cpw/mods/modlauncher/log/ExtraDataTextRenderer.java index 12cbfe19f..076469a93 100644 --- a/src/main/java/cpw/mods/modlauncher/log/ExtraDataTextRenderer.java +++ b/loader/src/main/java/cpw/mods/modlauncher/log/ExtraDataTextRenderer.java @@ -1,19 +1,15 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.log; @@ -21,9 +17,8 @@ import cpw.mods.modlauncher.Launcher; import cpw.mods.modlauncher.api.IEnvironment; import cpw.mods.modlauncher.api.ITransformerAuditTrail; -import org.apache.logging.log4j.core.pattern.TextRenderer; - import java.util.Optional; +import org.apache.logging.log4j.core.pattern.TextRenderer; public class ExtraDataTextRenderer implements TextRenderer { private final TextRenderer wrapped; @@ -32,9 +27,7 @@ public class ExtraDataTextRenderer implements TextRenderer { ExtraDataTextRenderer(final TextRenderer wrapped) { this.wrapped = wrapped; - this.auditData = Optional.ofNullable(Launcher.INSTANCE). - map(Launcher::environment). - flatMap(env -> env.getProperty(IEnvironment.Keys.AUDITTRAIL.get())); + this.auditData = Optional.ofNullable(Launcher.INSTANCE).map(Launcher::environment).flatMap(env -> env.getProperty(IEnvironment.Keys.AUDITTRAIL.get())); } @Override @@ -52,7 +45,7 @@ public void render(final String input, final StringBuilder output, final String currentClass.remove(); if (classContext != null) { final Optional auditLine = auditData.map(data -> data.getAuditString(classContext.getClassName())); - wrapped.render(" {"+ auditLine.orElse("") +"}", output, "StackTraceElement.Transformers"); + wrapped.render(" {" + auditLine.orElse("") + "}", output, "StackTraceElement.Transformers"); } return; } @@ -65,7 +58,6 @@ public void render(final StringBuilder input, final StringBuilder output) { } private static class TransformerContext { - private String className; private String methodName; @@ -87,7 +79,7 @@ public String getMethodName() { @Override public String toString() { - return getClassName()+"."+getMethodName(); + return getClassName() + "." + getMethodName(); } } } diff --git a/src/main/java/cpw/mods/modlauncher/log/MLClassLoaderContextSelector.java b/loader/src/main/java/cpw/mods/modlauncher/log/MLClassLoaderContextSelector.java similarity index 99% rename from src/main/java/cpw/mods/modlauncher/log/MLClassLoaderContextSelector.java rename to loader/src/main/java/cpw/mods/modlauncher/log/MLClassLoaderContextSelector.java index 16ca8df2a..bb6df9730 100644 --- a/src/main/java/cpw/mods/modlauncher/log/MLClassLoaderContextSelector.java +++ b/loader/src/main/java/cpw/mods/modlauncher/log/MLClassLoaderContextSelector.java @@ -8,7 +8,6 @@ * As all {@link ModuleClassLoader}s should get the same log4j context, we just return a static string with "MCL", otherwise we use the default logic */ public class MLClassLoaderContextSelector extends ClassLoaderContextSelector { - @Override protected String toContextMapKey(ClassLoader loader) { if (loader instanceof ModuleClassLoader) { diff --git a/src/main/java/cpw/mods/modlauncher/log/TransformingThrowablePatternConverter.java b/loader/src/main/java/cpw/mods/modlauncher/log/TransformingThrowablePatternConverter.java similarity index 70% rename from src/main/java/cpw/mods/modlauncher/log/TransformingThrowablePatternConverter.java rename to loader/src/main/java/cpw/mods/modlauncher/log/TransformingThrowablePatternConverter.java index a2da11b13..8b5c66564 100644 --- a/src/main/java/cpw/mods/modlauncher/log/TransformingThrowablePatternConverter.java +++ b/loader/src/main/java/cpw/mods/modlauncher/log/TransformingThrowablePatternConverter.java @@ -1,31 +1,30 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.log; +import java.util.Collections; import joptsimple.internal.Strings; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.core.pattern.*; - -import java.util.Collections; +import org.apache.logging.log4j.core.pattern.ConverterKeys; +import org.apache.logging.log4j.core.pattern.PatternConverter; +import org.apache.logging.log4j.core.pattern.PlainTextRenderer; +import org.apache.logging.log4j.core.pattern.TextRenderer; +import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter; /** * Started as a copy of {@link org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter} because @@ -34,12 +33,13 @@ @Plugin(name = "TransformingThrowablePatternConverter", category = PatternConverter.CATEGORY) @ConverterKeys({ "tEx" }) public class TransformingThrowablePatternConverter extends ThrowablePatternConverter { - static final String SUFFIXFLAG="☃☃☃☃☃SUFFIXFLAG☃☃☃☃☃"; + static final String SUFFIXFLAG = "☃☃☃☃☃SUFFIXFLAG☃☃☃☃☃"; + /** * @param name Name of converter. * @param style CSS style for output. * @param options options, may be null. - * @param config config. + * @param config config. */ protected TransformingThrowablePatternConverter(final Configuration config, final String[] options) { super("TransformingThrowable", "throwable", options, config); @@ -70,8 +70,8 @@ public void format(final LogEvent event, final StringBuilder toAppendTo) { /** * Gets an instance of the class. * - * @param config The current Configuration. - * @param options pattern options, may be null. If first element is "short", + * @param config The current Configuration. + * @param options pattern options, may be null. If first element is "short", * only the first line of the throwable will be formatted. * @return instance of class. */ @@ -79,7 +79,6 @@ public static TransformingThrowablePatternConverter newInstance(final Configurat return new TransformingThrowablePatternConverter(config, options); } - public static String generateEnhancedStackTrace(final Throwable throwable) { final ThrowableProxy proxy = new ThrowableProxy(throwable); final StringBuilder buffer = new StringBuilder(); diff --git a/src/main/java/cpw/mods/modlauncher/serviceapi/ILaunchPluginService.java b/loader/src/main/java/cpw/mods/modlauncher/serviceapi/ILaunchPluginService.java similarity index 78% rename from src/main/java/cpw/mods/modlauncher/serviceapi/ILaunchPluginService.java rename to loader/src/main/java/cpw/mods/modlauncher/serviceapi/ILaunchPluginService.java index 64c990084..c8adfcc4d 100644 --- a/src/main/java/cpw/mods/modlauncher/serviceapi/ILaunchPluginService.java +++ b/loader/src/main/java/cpw/mods/modlauncher/serviceapi/ILaunchPluginService.java @@ -1,34 +1,28 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.serviceapi; import cpw.mods.jarhandling.SecureJar; import cpw.mods.modlauncher.api.NamedPath; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.ClassNode; - import java.nio.file.Path; import java.util.EnumSet; import java.util.List; -import java.util.Map; import java.util.function.Consumer; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; /** * Loaded from the initial classpath of the system to identify plugins that wish to work across the system. @@ -92,20 +86,22 @@ class ComputeFlags { /** * If this plugin wants to receive the {@link ClassNode} into {@link #processClass} + * * @param classType the class to consider - * @param isEmpty if the class is empty at present (indicates no backing file found) + * @param isEmpty if the class is empty at present (indicates no backing file found) * @return the set of Phases the plugin wishes to be called back with */ EnumSet handlesClass(Type classType, final boolean isEmpty); /** * If this plugin wants to receive the {@link ClassNode} into {@link #processClass} + * * @param classType the class to consider - * @param isEmpty if the class is empty at present (indicates no backing file found) - * @param reason Reason for transformation request. - * "classloading" - cpw.mods.modlauncher.api.ITransformerActivity#CLASSLOADING_REASON - * "computing_frames" - cpw.mods.modlauncher.api.ITransformerActivity#COMPUTING_FRAMES_REASON - * or the name of an {@link ILaunchPluginService} + * @param isEmpty if the class is empty at present (indicates no backing file found) + * @param reason Reason for transformation request. + * "classloading" - cpw.mods.modlauncher.api.ITransformerActivity#CLASSLOADING_REASON + * "computing_frames" - cpw.mods.modlauncher.api.ITransformerActivity#COMPUTING_FRAMES_REASON + * or the name of an {@link ILaunchPluginService} * @return the set of Phases the plugin wishes to be called back with */ default EnumSet handlesClass(Type classType, final boolean isEmpty, final String reason) { @@ -119,7 +115,7 @@ default EnumSet handlesClass(Type classType, final boolean isEmpty, final * One of {@link #processClass(Phase, ClassNode, Type)}, {@link #processClass(Phase, ClassNode, Type, String)} * or {@link #processClassWithFlags(Phase, ClassNode, Type, String)} must be implemented. * - * @param phase The phase of the supplied class node + * @param phase The phase of the supplied class node * @param classNode the classnode to process * @param classType the name of the class * @return true if the classNode needs rewriting using COMPUTE_FRAMES or false if it needs no NO_REWRITE @@ -132,10 +128,10 @@ default boolean processClass(final Phase phase, ClassNode classNode, final Type * Each class loaded is offered to the plugin for processing. * Ordering between plugins is not known. * - * @param phase The phase of the supplied class node + * @param phase The phase of the supplied class node * @param classNode the classnode to process * @param classType the name of the class - * @param reason Reason for transformation. "classloading" or the name of an {@link ILaunchPluginService} + * @param reason Reason for transformation. "classloading" or the name of an {@link ILaunchPluginService} * @return true if the classNode needs rewriting using COMPUTE_FRAMES or false if it needs no NO_REWRITE */ default boolean processClass(final Phase phase, ClassNode classNode, final Type classType, String reason) { @@ -146,10 +142,10 @@ default boolean processClass(final Phase phase, ClassNode classNode, final Type * Each class loaded is offered to the plugin for processing. * Ordering between plugins is not known. * - * @param phase The phase of the supplied class node + * @param phase The phase of the supplied class node * @param classNode the classnode to process * @param classType the name of the class - * @param reason Reason for transformation. "classloading" or the name of an {@link ILaunchPluginService} + * @param reason Reason for transformation. "classloading" or the name of an {@link ILaunchPluginService} * @return The {@link ComputeFlags} for this class */ default int processClassWithFlags(final Phase phase, ClassNode classNode, final Type classType, String reason) { @@ -161,7 +157,7 @@ default int processClassWithFlags(final Phase phase, ClassNode classNode, final * for example. * * @param resource The resource to be considered by this plugin. - * @param name A name for this resource. + * @param name A name for this resource. */ default void offerResource(Path resource, String name) {} @@ -172,7 +168,8 @@ default void offerResource(Path resource, String name) {} */ default void addResources(List resources) {} - default void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] specialPaths) {} + default void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] specialPaths) {} + /** * Get a plugin specific extension object from the plugin. This can be used to expose proprietary interfaces * to Launchers without ModLauncher needing to understand them. @@ -180,18 +177,19 @@ default void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] * @param The type of the extension * @return An extension object */ - default T getExtension() {return null;} + default T getExtension() { + return null; + } /** * Receives a call immediately after handlesClass for any transformer that declares an interest. * * the consumer can be called repeatedly to generate new AuditTrail entries in the audit log. * - * @param className className that is being transformed + * @param className className that is being transformed * @param auditDataAcceptor accepts an array of strings to add a new audit trail record with the data */ - default void customAuditConsumer(String className, Consumer auditDataAcceptor) { - } + default void customAuditConsumer(String className, Consumer auditDataAcceptor) {} interface ITransformerLoader { byte[] buildTransformedClassNodeFor(final String className) throws ClassNotFoundException; diff --git a/src/main/java/cpw/mods/modlauncher/serviceapi/ITransformerDiscoveryService.java b/loader/src/main/java/cpw/mods/modlauncher/serviceapi/ITransformerDiscoveryService.java similarity index 62% rename from src/main/java/cpw/mods/modlauncher/serviceapi/ITransformerDiscoveryService.java rename to loader/src/main/java/cpw/mods/modlauncher/serviceapi/ITransformerDiscoveryService.java index 8e4e7ce09..51322725f 100644 --- a/src/main/java/cpw/mods/modlauncher/serviceapi/ITransformerDiscoveryService.java +++ b/loader/src/main/java/cpw/mods/modlauncher/serviceapi/ITransformerDiscoveryService.java @@ -1,25 +1,20 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.serviceapi; import cpw.mods.modlauncher.api.NamedPath; - import java.nio.file.Path; import java.util.List; @@ -30,6 +25,7 @@ public interface ITransformerDiscoveryService { /** * Return a list of additional paths to be added to transformer service discovery during loading. + * * @param gameDirectory The root game directory * @return The list of services */ @@ -41,7 +37,7 @@ public interface ITransformerDiscoveryService { * Defaults to calling {@link #candidates(Path)} * * @param gameDirectory The root game directory - * @param launchTarget The launch target + * @param launchTarget The launch target * @return The list of services */ default List candidates(final Path gameDirectory, final String launchTarget) { @@ -53,9 +49,7 @@ default List candidates(final Path gameDirectory, final String launch * been built. * * @param launchTarget The launch target - * @param arguments The full command arguments to the game + * @param arguments The full command arguments to the game */ - default void earlyInitialization(final String launchTarget, final String[] arguments) { - - } + default void earlyInitialization(final String launchTarget, final String[] arguments) {} } diff --git a/src/main/java/cpw/mods/modlauncher/util/ServiceLoaderUtils.java b/loader/src/main/java/cpw/mods/modlauncher/util/ServiceLoaderUtils.java similarity index 67% rename from src/main/java/cpw/mods/modlauncher/util/ServiceLoaderUtils.java rename to loader/src/main/java/cpw/mods/modlauncher/util/ServiceLoaderUtils.java index 0d014229e..d3213b252 100644 --- a/src/main/java/cpw/mods/modlauncher/util/ServiceLoaderUtils.java +++ b/loader/src/main/java/cpw/mods/modlauncher/util/ServiceLoaderUtils.java @@ -1,25 +1,20 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2021 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.util; import cpw.mods.niofs.union.UnionFileSystem; - import java.nio.file.Path; import java.util.Objects; import java.util.ServiceConfigurationError; @@ -34,7 +29,7 @@ public static Stream streamServiceLoader(Supplier> slSup } public static Stream streamWithErrorHandling(ServiceLoader sl, Consumer errorConsumer) { - return sl.stream().map(p->{ + return sl.stream().map(p -> { try { return p.get(); } catch (ServiceConfigurationError sce) { @@ -52,7 +47,7 @@ public static String fileNameFor(Class clazz) { return clazz.getModule().getLayer().configuration() .findModule(clazz.getModule().getName()) - .flatMap(rm->rm.reference().location()) + .flatMap(rm -> rm.reference().location()) .map(Path::of) .map(p -> p.getFileSystem() instanceof UnionFileSystem ufs ? ufs.getPrimaryPath() : p) .map(p -> p.getFileName().toString()) diff --git a/loader/src/main/resources/META-INF/services/java.util.function.Consumer b/loader/src/main/resources/META-INF/services/java.util.function.Consumer new file mode 100644 index 000000000..1235c96a6 --- /dev/null +++ b/loader/src/main/resources/META-INF/services/java.util.function.Consumer @@ -0,0 +1 @@ +cpw.mods.modlauncher.BootstrapLaunchConsumer \ No newline at end of file diff --git a/src/test/java/cpw/mods/modlauncher/test/ClassTransformerTests.java b/loader/src/test/java/cpw/mods/modlauncher/test/ClassTransformerTests.java similarity index 75% rename from src/test/java/cpw/mods/modlauncher/test/ClassTransformerTests.java rename to loader/src/test/java/cpw/mods/modlauncher/test/ClassTransformerTests.java index 77989f814..d7a8edbf2 100644 --- a/src/test/java/cpw/mods/modlauncher/test/ClassTransformerTests.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/ClassTransformerTests.java @@ -1,33 +1,40 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; -import cpw.mods.modlauncher.*; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import cpw.mods.modlauncher.ClassTransformer; +import cpw.mods.modlauncher.LaunchPluginHandler; +import cpw.mods.modlauncher.ModuleLayerHandler; +import cpw.mods.modlauncher.TransformStore; +import cpw.mods.modlauncher.TransformTargetLabel; +import cpw.mods.modlauncher.TransformingClassLoader; import cpw.mods.modlauncher.api.ITransformationService; import cpw.mods.modlauncher.api.ITransformer; import cpw.mods.modlauncher.api.ITransformerVotingContext; import cpw.mods.modlauncher.api.TargetType; import cpw.mods.modlauncher.api.TransformerVoteResult; +import java.util.Collections; +import java.util.Set; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.MarkerManager; import org.apache.logging.log4j.core.config.Configurator; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; @@ -36,11 +43,6 @@ import org.objectweb.asm.tree.FieldNode; import org.powermock.reflect.Whitebox; -import java.util.Collections; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - /** * Test core transformer functionality */ @@ -52,21 +54,19 @@ void testClassTransformer() throws Exception { final TransformStore transformStore = new TransformStore(); final ModuleLayerHandler layerHandler = Whitebox.invokeConstructor(ModuleLayerHandler.class); final LaunchPluginHandler lph = new LaunchPluginHandler(layerHandler); - final ClassTransformer classTransformer = Whitebox.invokeConstructor(ClassTransformer.class, new Class[] { transformStore.getClass(), lph.getClass(), TransformingClassLoader.class }, new Object[] { transformStore, lph, null}); + final ClassTransformer classTransformer = Whitebox.invokeConstructor(ClassTransformer.class, new Class[] { transformStore.getClass(), lph.getClass(), TransformingClassLoader.class }, new Object[] { transformStore, lph, null }); final ITransformationService dummyService = new MockTransformerService(); Whitebox.invokeMethod(transformStore, "addTransformer", new TransformTargetLabel("test.MyClass", TargetType.CLASS), classTransformer(), dummyService); - byte[] result = Whitebox.invokeMethod(classTransformer, "transform", new Class[]{byte[].class, String.class,String.class}, new byte[0], "test.MyClass","testing"); + byte[] result = Whitebox.invokeMethod(classTransformer, "transform", new Class[] { byte[].class, String.class, String.class }, new byte[0], "test.MyClass", "testing"); assertAll("Class loads and is valid", () -> assertNotNull(result), // () -> assertNotNull(new TransformingClassLoader(transformStore, lph, FileSystems.getDefault().getPath(".")).getClass("test.MyClass", result)), - () -> - { + () -> { ClassReader cr = new ClassReader(result); ClassNode cn = new ClassNode(); cr.accept(cn, 0); assertTrue(cn.fields.stream().anyMatch(f -> f.name.equals("testfield"))); - } - ); + }); ClassNode dummyClass = new ClassNode(); dummyClass.superName = "java/lang/Object"; @@ -76,36 +76,31 @@ void testClassTransformer() throws Exception { ClassWriter cw = new ClassWriter(Opcodes.ASM5); dummyClass.accept(cw); Whitebox.invokeMethod(transformStore, "addTransformer", new TransformTargetLabel("test.DummyClass", "dummyfield"), fieldNodeTransformer1(), dummyService); - byte[] result1 = Whitebox.invokeMethod(classTransformer, "transform", new Class[]{byte[].class, String.class, String.class}, cw.toByteArray(), "test.DummyClass", "testing"); + byte[] result1 = Whitebox.invokeMethod(classTransformer, "transform", new Class[] { byte[].class, String.class, String.class }, cw.toByteArray(), "test.DummyClass", "testing"); assertAll("Class loads and is valid", () -> assertNotNull(result1), // () -> assertNotNull(new TransformingClassLoader(transformStore, lph, FileSystems.getDefault().getPath(".")).getClass("test.DummyClass", result1)), - () -> - { + () -> { ClassReader cr = new ClassReader(result1); ClassNode cn = new ClassNode(); cr.accept(cn, 0); assertEquals("CHEESE", cn.fields.get(0).value); - } - ); + }); } private ITransformer fieldNodeTransformer1() { return new ITransformer<>() { - @NotNull @Override public FieldNode transform(FieldNode input, ITransformerVotingContext context) { input.value = "CHEESE"; return input; } - @NotNull @Override public TransformerVoteResult castVote(ITransformerVotingContext context) { return TransformerVoteResult.YES; } - @NotNull @Override public Set> targets() { return Collections.emptySet(); @@ -120,22 +115,19 @@ public TargetType getTargetType() { private ITransformer classTransformer() { return new ITransformer<>() { - @NotNull @Override public ClassNode transform(ClassNode input, ITransformerVotingContext context) { - input.superName="java/lang/Object"; + input.superName = "java/lang/Object"; FieldNode fn = new FieldNode(Opcodes.ACC_PUBLIC, "testfield", "Ljava/lang/String;", null, null); input.fields.add(fn); return input; } - @NotNull @Override public TransformerVoteResult castVote(ITransformerVotingContext context) { return TransformerVoteResult.YES; } - @NotNull @Override public Set> targets() { return Collections.emptySet(); diff --git a/src/test/java/cpw/mods/modlauncher/test/EnumerationHelperTest.java b/loader/src/test/java/cpw/mods/modlauncher/test/EnumerationHelperTest.java similarity index 55% rename from src/test/java/cpw/mods/modlauncher/test/EnumerationHelperTest.java rename to loader/src/test/java/cpw/mods/modlauncher/test/EnumerationHelperTest.java index ed77ccaf5..27237d106 100644 --- a/src/test/java/cpw/mods/modlauncher/test/EnumerationHelperTest.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/EnumerationHelperTest.java @@ -1,34 +1,37 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2020 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2020 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; -import cpw.mods.modlauncher.EnumerationHelper; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.*; +import cpw.mods.modlauncher.EnumerationHelper; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Optional; +import java.util.Vector; import java.util.function.Function; import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; class EnumerationHelperTest { - @Test void merge() { final List strs1 = Arrays.asList("one", "two", "three"); @@ -44,9 +47,9 @@ void fromOptional() { final Function> function = EnumerationHelper.fromOptional(Optional::ofNullable); assertTrue(function.apply("result").hasMoreElements(), "has more"); assertFalse(function.apply(null).hasMoreElements(), "has no more"); - assertEquals("result", function.apply("result").nextElement(),"returns element as first result"); + assertEquals("result", function.apply("result").nextElement(), "returns element as first result"); final Enumeration result = function.apply("result"); result.nextElement(); assertFalse(result.hasMoreElements(), "has no more"); } -} \ No newline at end of file +} diff --git a/loader/src/test/java/cpw/mods/modlauncher/test/MockLauncherHandlerService.java b/loader/src/test/java/cpw/mods/modlauncher/test/MockLauncherHandlerService.java new file mode 100644 index 000000000..e97db7535 --- /dev/null +++ b/loader/src/test/java/cpw/mods/modlauncher/test/MockLauncherHandlerService.java @@ -0,0 +1,33 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.test; + +import cpw.mods.modlauncher.api.ILaunchHandlerService; +import cpw.mods.modlauncher.api.ServiceRunner; + +/** + * Mock launch handler for testing + */ +public class MockLauncherHandlerService implements ILaunchHandlerService { + @Override + public String name() { + return "mockLaunch"; + } + + @Override + public ServiceRunner launchService(String[] arguments, ModuleLayer gameLayer) { + return ServiceRunner.NOOP; + } +} diff --git a/src/test/java/cpw/mods/modlauncher/test/MockTransformerService.java b/loader/src/test/java/cpw/mods/modlauncher/test/MockTransformerService.java similarity index 63% rename from src/test/java/cpw/mods/modlauncher/test/MockTransformerService.java rename to loader/src/test/java/cpw/mods/modlauncher/test/MockTransformerService.java index 5e78e45be..246739d40 100644 --- a/src/test/java/cpw/mods/modlauncher/test/MockTransformerService.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/MockTransformerService.java @@ -1,35 +1,41 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; import cpw.mods.jarhandling.SecureJar; -import cpw.mods.modlauncher.api.*; -import joptsimple.*; -import org.jetbrains.annotations.NotNull; -import org.objectweb.asm.*; -import org.objectweb.asm.tree.*; - +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.IModuleLayerManager; +import cpw.mods.modlauncher.api.ITransformationService; +import cpw.mods.modlauncher.api.ITransformer; +import cpw.mods.modlauncher.api.ITransformerVotingContext; +import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; +import cpw.mods.modlauncher.api.TargetType; +import cpw.mods.modlauncher.api.TransformerVoteResult; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.*; -import java.util.function.*; -import java.util.stream.*; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import joptsimple.ArgumentAcceptingOptionSpec; +import joptsimple.OptionSpecBuilder; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; /** * Test Launcher Service @@ -40,7 +46,6 @@ public class MockTransformerService implements ITransformationService { private List modList; private String state; - @NotNull @Override public String name() { return "test"; @@ -62,21 +67,19 @@ public void initialize(IEnvironment environment) { } @Override - public void onLoad(IEnvironment env, Set otherServices) throws IncompatibleEnvironmentException { - - } + public void onLoad(IEnvironment env, Set otherServices) throws IncompatibleEnvironmentException {} @Override public List beginScanning(IEnvironment environment) { - if (System.getProperty("testJars.location")!=null) { + if (System.getProperty("testJars.location") != null) { SecureJar testjar = SecureJar.from(Path.of(System.getProperty("testJars.location"))); return List.of(new Resource(IModuleLayerManager.Layer.PLUGIN, List.of(testjar))); - } else if (System.getProperty("test.harness")!=null) { + } else if (System.getProperty("test.harness") != null) { return List.of(new Resource(IModuleLayerManager.Layer.PLUGIN, Arrays.stream(System.getProperty("test.harness").split(",")) - .map(FileSystems.getDefault()::getPath) - .map(SecureJar::from) - .toList())); + .map(FileSystems.getDefault()::getPath) + .map(SecureJar::from) + .toList())); } else { return List.of(); } @@ -84,7 +87,7 @@ public List beginScanning(IEnvironment environment) { @Override public List completeScan(IModuleLayerManager layerManager) { - if (System.getProperty("testJars.location")!=null) { + if (System.getProperty("testJars.location") != null) { SecureJar testjar = SecureJar.from(Path.of(System.getProperty("testJars.location"))); return List.of(new Resource(IModuleLayerManager.Layer.GAME, List.of(testjar))); } else { @@ -92,7 +95,6 @@ public List completeScan(IModuleLayerManager layerManager) { } } - @NotNull @Override public List> transformers() { return Stream.of(new ClassNodeTransformer(modList)).collect(Collectors.toList()); @@ -105,7 +107,6 @@ static class ClassNodeTransformer implements ITransformer { this.classNames = classNames; } - @NotNull @Override public ClassNode transform(ClassNode input, ITransformerVotingContext context) { FieldNode fn = new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "testfield", "Ljava/lang/String;", null, "CHEESE!"); @@ -113,13 +114,11 @@ public ClassNode transform(ClassNode input, ITransformerVotingContext context) { return input; } - @NotNull @Override public TransformerVoteResult castVote(ITransformerVotingContext context) { return TransformerVoteResult.YES; } - @NotNull @Override public Set> targets() { return classNames.stream().map(Target::targetClass).collect(Collectors.toSet()); @@ -130,5 +129,4 @@ public TargetType getTargetType() { return TargetType.CLASS; } } - } diff --git a/src/test/java/cpw/mods/modlauncher/test/PluginTests.java b/loader/src/test/java/cpw/mods/modlauncher/test/PluginTests.java similarity index 63% rename from src/test/java/cpw/mods/modlauncher/test/PluginTests.java rename to loader/src/test/java/cpw/mods/modlauncher/test/PluginTests.java index 128e3db9b..8c74e970f 100644 --- a/src/test/java/cpw/mods/modlauncher/test/PluginTests.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/PluginTests.java @@ -1,35 +1,29 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; +import static org.junit.jupiter.api.Assertions.assertEquals; + import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; +import java.nio.file.Path; +import java.util.EnumSet; import org.junit.jupiter.api.Test; import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; -import java.nio.file.Path; -import java.util.EnumSet; - -import static org.junit.jupiter.api.Assertions.assertEquals; - class PluginTests { - @Test void pluginTests() { ILaunchPluginService plugin = new ILaunchPluginService() { @@ -39,9 +33,7 @@ public String name() { } @Override - public void offerResource(final Path resource, final String name) { - - } + public void offerResource(final Path resource, final String name) {} @Override public boolean processClass(final Phase phase, final ClassNode classNode, final Type classType) { diff --git a/src/test/java/cpw/mods/modlauncher/test/TransformationServiceDecoratorTests.java b/loader/src/test/java/cpw/mods/modlauncher/test/TransformationServiceDecoratorTests.java similarity index 79% rename from src/test/java/cpw/mods/modlauncher/test/TransformationServiceDecoratorTests.java rename to loader/src/test/java/cpw/mods/modlauncher/test/TransformationServiceDecoratorTests.java index 9e228214e..854039038 100644 --- a/src/test/java/cpw/mods/modlauncher/test/TransformationServiceDecoratorTests.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/TransformationServiceDecoratorTests.java @@ -1,23 +1,22 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertTrue; + import cpw.mods.modlauncher.TransformList; import cpw.mods.modlauncher.TransformStore; import cpw.mods.modlauncher.TransformTargetLabel; @@ -26,19 +25,17 @@ import cpw.mods.modlauncher.api.ITransformerVotingContext; import cpw.mods.modlauncher.api.TargetType; import cpw.mods.modlauncher.api.TransformerVoteResult; -import org.jetbrains.annotations.NotNull; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.powermock.reflect.Whitebox; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertTrue; - class TransformationServiceDecoratorTests { private final ClassNodeTransformer classNodeTransformer = new ClassNodeTransformer(); private final MethodNodeTransformer methodNodeTransformer = new MethodNodeTransformer(); @@ -46,7 +43,6 @@ class TransformationServiceDecoratorTests { @Test void testGatherTransformersNormally() throws Exception { MockTransformerService mockTransformerService = new MockTransformerService() { - @NotNull @Override public List> transformers() { return Stream.of(classNodeTransformer, methodNodeTransformer).collect(Collectors.toList()); @@ -60,12 +56,11 @@ public List> transformers() { Set targettedClasses = Whitebox.getInternalState(store, "classNeedsTransforming"); assertAll( () -> assertTrue(transformers.containsKey(TargetType.CLASS), "transformers contains class"), - () -> assertTrue(getTransformers(transformers.get(TargetType.CLASS)).values().stream().flatMap(Collection::stream).allMatch(s -> Whitebox.getInternalState(s,"wrapped") == classNodeTransformer), "transformers contains classTransformer"), + () -> assertTrue(getTransformers(transformers.get(TargetType.CLASS)).values().stream().flatMap(Collection::stream).allMatch(s -> Whitebox.getInternalState(s, "wrapped") == classNodeTransformer), "transformers contains classTransformer"), () -> assertTrue(targettedClasses.contains("cheese/Puffs"), "targetted classes contains class name cheese/Puffs"), () -> assertTrue(transformers.containsKey(TargetType.METHOD), "transformers contains method"), - () -> assertTrue(getTransformers(transformers.get(TargetType.METHOD)).values().stream().flatMap(Collection::stream).allMatch(s -> Whitebox.getInternalState(s,"wrapped") == methodNodeTransformer), "transformers contains methodTransformer"), - () -> assertTrue(targettedClasses.contains("cheesy/PuffMethod"), "targetted classes contains class name cheesy/PuffMethod") - ); + () -> assertTrue(getTransformers(transformers.get(TargetType.METHOD)).values().stream().flatMap(Collection::stream).allMatch(s -> Whitebox.getInternalState(s, "wrapped") == methodNodeTransformer), "transformers contains methodTransformer"), + () -> assertTrue(targettedClasses.contains("cheesy/PuffMethod"), "targetted classes contains class name cheesy/PuffMethod")); } private static Map>> getTransformers(TransformList list) { @@ -75,20 +70,18 @@ private static Map>> getTransform throw new RuntimeException(e); } } + private static class ClassNodeTransformer implements ITransformer { - @NotNull @Override public ClassNode transform(ClassNode input, ITransformerVotingContext context) { return input; } - @NotNull @Override public TransformerVoteResult castVote(ITransformerVotingContext context) { return TransformerVoteResult.YES; } - @NotNull @Override public Set> targets() { return Stream.of(Target.targetClass("cheese.Puffs")).collect(Collectors.toSet()); @@ -101,19 +94,16 @@ public TargetType getTargetType() { } private static class MethodNodeTransformer implements ITransformer { - @NotNull @Override public MethodNode transform(MethodNode input, ITransformerVotingContext context) { return input; } - @NotNull @Override public TransformerVoteResult castVote(ITransformerVotingContext context) { return TransformerVoteResult.YES; } - @NotNull @Override public Set> targets() { return Stream.of(Target.targetMethod("cheesy.PuffMethod", "fish", "()V")).collect(Collectors.toSet()); diff --git a/src/test/java/cpw/mods/modlauncher/test/TransformingClassLoaderTests.java b/loader/src/test/java/cpw/mods/modlauncher/test/TransformingClassLoaderTests.java similarity index 74% rename from src/test/java/cpw/mods/modlauncher/test/TransformingClassLoaderTests.java rename to loader/src/test/java/cpw/mods/modlauncher/test/TransformingClassLoaderTests.java index ac0d12579..7d2f2cc6a 100644 --- a/src/test/java/cpw/mods/modlauncher/test/TransformingClassLoaderTests.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/TransformingClassLoaderTests.java @@ -1,33 +1,33 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; +import static org.junit.jupiter.api.Assertions.assertEquals; + import cpw.mods.cl.JarModuleFinder; import cpw.mods.jarhandling.SecureJar; -import cpw.mods.modlauncher.*; +import cpw.mods.modlauncher.Environment; +import cpw.mods.modlauncher.LaunchPluginHandler; +import cpw.mods.modlauncher.Launcher; +import cpw.mods.modlauncher.ModuleLayerHandler; +import cpw.mods.modlauncher.TransformStore; +import cpw.mods.modlauncher.TransformationServiceDecorator; +import cpw.mods.modlauncher.TransformingClassLoader; import cpw.mods.modlauncher.api.IEnvironment; import cpw.mods.modlauncher.api.ITransformer; import cpw.mods.modlauncher.api.TypesafeMap; -import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.Test; -import org.powermock.reflect.Whitebox; - import java.lang.module.Configuration; import java.lang.module.ModuleFinder; import java.lang.reflect.Constructor; @@ -36,8 +36,8 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.powermock.reflect.Whitebox; /** * Test class loader @@ -48,7 +48,6 @@ class TransformingClassLoaderTests { @Test void testClassLoader() throws Exception { MockTransformerService mockTransformerService = new MockTransformerService() { - @NotNull @Override public List> transformers() { return Stream.of(new ClassNodeTransformer(List.of(TARGET_CLASS))).collect(Collectors.toList()); @@ -60,14 +59,14 @@ public List> transformers() { LaunchPluginHandler lph = new LaunchPluginHandler(layerHandler); TransformationServiceDecorator sd = Whitebox.invokeConstructor(TransformationServiceDecorator.class, mockTransformerService); sd.gatherTransformers(transformStore); - - Environment environment = Whitebox.invokeConstructor(Environment.class, new Class[]{ Launcher.class }, new Object[]{ null }); + + Environment environment = Whitebox.invokeConstructor(Environment.class, new Class[] { Launcher.class }, new Object[] { null }); new TypesafeMap(IEnvironment.class); Constructor constructor = Whitebox.getConstructor(TransformingClassLoader.class, TransformStore.class, LaunchPluginHandler.class, Environment.class, Configuration.class, List.class); Configuration configuration = createTestJarsConfiguration(); TransformingClassLoader tcl = constructor.newInstance(transformStore, lph, environment, configuration, List.of(ModuleLayer.boot())); ModuleLayer.boot().defineModules(configuration, s -> tcl); - + final Class aClass = Class.forName(TARGET_CLASS, true, tcl); assertEquals(Whitebox.getField(aClass, "testfield").getType(), String.class); assertEquals(Whitebox.getField(aClass, "testfield").get(null), "CHEESE!"); @@ -75,7 +74,7 @@ public List> transformers() { final Class newClass = tcl.loadClass(TARGET_CLASS); assertEquals(aClass, newClass, "Class instance is the same from Class.forName and tcl.loadClass"); } - + private Configuration createTestJarsConfiguration() { SecureJar testJars = SecureJar.from(Path.of(System.getProperty("testJars.location"))); JarModuleFinder finder = JarModuleFinder.of(testJars); diff --git a/src/test/java/cpw/mods/modlauncher/test/TypesafeMapTests.java b/loader/src/test/java/cpw/mods/modlauncher/test/TypesafeMapTests.java similarity index 59% rename from src/test/java/cpw/mods/modlauncher/test/TypesafeMapTests.java rename to loader/src/test/java/cpw/mods/modlauncher/test/TypesafeMapTests.java index 17649dc72..5da1ebfe5 100644 --- a/src/test/java/cpw/mods/modlauncher/test/TypesafeMapTests.java +++ b/loader/src/test/java/cpw/mods/modlauncher/test/TypesafeMapTests.java @@ -1,29 +1,26 @@ /* * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ package cpw.mods.modlauncher.test; -import cpw.mods.modlauncher.api.TypesafeMap; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import cpw.mods.modlauncher.api.TypesafeMap; import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** * Typesafe map tests @@ -33,25 +30,20 @@ class TypesafeMapTests { void testTypesafeMapKey() { TypesafeMap context = new TypesafeMap(); assertThrows(IllegalArgumentException.class, - () -> - { + () -> { TypesafeMap.Key.getOrCreate(context, "testkey1", String.class); TypesafeMap.Key.getOrCreate(context, "testkey1", Integer.class); - } - ); + }); assertAll( - () -> - { + () -> { TypesafeMap.Key.getOrCreate(context, "testkey1", String.class); TypesafeMap.Key.getOrCreate(context, "testkey1", String.class); }, - () -> - { + () -> { TypesafeMap.Key.getOrCreate(context, "testkey1", String.class); TypesafeMap.Key.getOrCreate(context, "testkey2", Integer.class); - } - ); + }); } @Test diff --git a/loader/src/test/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService b/loader/src/test/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService new file mode 100644 index 000000000..71f32f299 --- /dev/null +++ b/loader/src/test/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService @@ -0,0 +1 @@ +cpw.mods.modlauncher.test.MockLauncherHandlerService \ No newline at end of file diff --git a/loader/src/testJars/java/cpw/mods/modlauncher/testjar/ITestServiceLoader.java b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/ITestServiceLoader.java new file mode 100644 index 000000000..f75e1e6ab --- /dev/null +++ b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/ITestServiceLoader.java @@ -0,0 +1,17 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2020 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.testjar; + +public interface ITestServiceLoader {} diff --git a/loader/src/testJars/java/cpw/mods/modlauncher/testjar/ResourceLoadingClass.java b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/ResourceLoadingClass.java new file mode 100644 index 000000000..17459c216 --- /dev/null +++ b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/ResourceLoadingClass.java @@ -0,0 +1,21 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.testjar; + +import java.net.URL; + +public class ResourceLoadingClass { + public final URL resource = getClass().getResource("ResourceLoadingFile"); +} diff --git a/loader/src/testJars/java/cpw/mods/modlauncher/testjar/TestClass.java b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/TestClass.java new file mode 100644 index 000000000..abf3d3505 --- /dev/null +++ b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/TestClass.java @@ -0,0 +1,30 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2019 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.testjar; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Test class loaded by tests and manipulated by transformers + */ +public class TestClass { + private String cheese = "FISH"; + + private String testMethod(String cheese) { + String wheee = "HELLO"; + return Stream.of(cheese, wheee).collect(Collectors.joining(" ")); + } +} diff --git a/loader/src/testJars/java/cpw/mods/modlauncher/testjar/TestServiceLoader.java b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/TestServiceLoader.java new file mode 100644 index 000000000..c37c00536 --- /dev/null +++ b/loader/src/testJars/java/cpw/mods/modlauncher/testjar/TestServiceLoader.java @@ -0,0 +1,17 @@ +/* + * ModLauncher - for launching Java programs with in-flight transformation ability. + * Copyright (C) 2017-2020 cpw + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cpw.mods.modlauncher.testjar; + +public class TestServiceLoader implements ITestServiceLoader {} diff --git a/src/testJars/java/module-info.java b/loader/src/testJars/java/module-info.java similarity index 97% rename from src/testJars/java/module-info.java rename to loader/src/testJars/java/module-info.java index d0ef44b61..7d359f7cb 100644 --- a/src/testJars/java/module-info.java +++ b/loader/src/testJars/java/module-info.java @@ -1,5 +1,5 @@ module cpw.mods.modlauncher.testjars { exports cpw.mods.modlauncher.testjar; - + provides cpw.mods.modlauncher.testjar.ITestServiceLoader with cpw.mods.modlauncher.testjar.TestServiceLoader; } diff --git a/src/testJars/resources/cpw/mods/modlauncher/testjar/ResourceLoadingFile b/loader/src/testJars/resources/cpw/mods/modlauncher/testjar/ResourceLoadingFile similarity index 100% rename from src/testJars/resources/cpw/mods/modlauncher/testjar/ResourceLoadingFile rename to loader/src/testJars/resources/cpw/mods/modlauncher/testjar/ResourceLoadingFile diff --git a/src/main/java/cpw/mods/modlauncher/BootstrapLaunchConsumer.java b/src/main/java/cpw/mods/modlauncher/BootstrapLaunchConsumer.java deleted file mode 100644 index a0a6e3d4d..000000000 --- a/src/main/java/cpw/mods/modlauncher/BootstrapLaunchConsumer.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -import java.util.function.Consumer; - -public class BootstrapLaunchConsumer implements Consumer { - @Override - public void accept(final String[] strings) { - Launcher.main(strings); - } -} diff --git a/src/main/java/cpw/mods/modlauncher/InvalidLauncherSetupException.java b/src/main/java/cpw/mods/modlauncher/InvalidLauncherSetupException.java deleted file mode 100644 index cf51eaf26..000000000 --- a/src/main/java/cpw/mods/modlauncher/InvalidLauncherSetupException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -public class InvalidLauncherSetupException extends IllegalStateException { - InvalidLauncherSetupException(final String s) { - super(s); - } -} diff --git a/src/main/java/cpw/mods/modlauncher/LaunchServiceHandlerDecorator.java b/src/main/java/cpw/mods/modlauncher/LaunchServiceHandlerDecorator.java deleted file mode 100644 index 8d14ee844..000000000 --- a/src/main/java/cpw/mods/modlauncher/LaunchServiceHandlerDecorator.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -import cpw.mods.modlauncher.api.*; - -/** - * Decorates {@link ILaunchHandlerService} for use by the system - */ -record LaunchServiceHandlerDecorator(ILaunchHandlerService service) { - - public void launch(String[] arguments, ModuleLayer gameLayer) { - try { - this.service.launchService(arguments, gameLayer).run(); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } -} diff --git a/src/main/java/cpw/mods/modlauncher/LogMarkers.java b/src/main/java/cpw/mods/modlauncher/LogMarkers.java deleted file mode 100644 index 1b81b3fab..000000000 --- a/src/main/java/cpw/mods/modlauncher/LogMarkers.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -import org.apache.logging.log4j.*; - -class LogMarkers { - static final Marker MODLAUNCHER = MarkerManager.getMarker("MODLAUNCHER"); - static final Marker CLASSLOADING = MarkerManager.getMarker("CLASSLOADING").addParents(MODLAUNCHER); - static final Marker LAUNCHPLUGIN = MarkerManager.getMarker("LAUNCHPLUGIN").addParents(MODLAUNCHER); -} diff --git a/src/main/java/cpw/mods/modlauncher/TransformerVote.java b/src/main/java/cpw/mods/modlauncher/TransformerVote.java deleted file mode 100644 index 05b5d99d6..000000000 --- a/src/main/java/cpw/mods/modlauncher/TransformerVote.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -import cpw.mods.modlauncher.api.*; - -class TransformerVote { - private final ITransformer transformer; - private final TransformerVoteResult result; - - TransformerVote(TransformerVoteResult vr, ITransformer transformer) { - this.transformer = transformer; - this.result = vr; - } - - TransformerVoteResult getResult() { - return result; - } - - ITransformer getTransformer() { - return transformer; - } -} diff --git a/src/main/java/cpw/mods/modlauncher/VoteDeadlockException.java b/src/main/java/cpw/mods/modlauncher/VoteDeadlockException.java deleted file mode 100644 index 622977e8b..000000000 --- a/src/main/java/cpw/mods/modlauncher/VoteDeadlockException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -import java.util.*; - -/** - * Exception thrown when a vote impass occurs - */ -public class VoteDeadlockException extends RuntimeException { - VoteDeadlockException(List> votes, Class aClass) { - } -} diff --git a/src/main/java/cpw/mods/modlauncher/VoteRejectedException.java b/src/main/java/cpw/mods/modlauncher/VoteRejectedException.java deleted file mode 100644 index 285e8d266..000000000 --- a/src/main/java/cpw/mods/modlauncher/VoteRejectedException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher; - -import java.util.*; - -/** - * Exception thrown when a voter rejects the entire configuration - */ -public class VoteRejectedException extends RuntimeException { - VoteRejectedException(List> votes, Class aClass) { - } -} diff --git a/src/main/java/cpw/mods/modlauncher/api/ILaunchHandlerService.java b/src/main/java/cpw/mods/modlauncher/api/ILaunchHandlerService.java deleted file mode 100644 index 41d61b9da..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/ILaunchHandlerService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -/** - * A singleton instance of this is loaded by the system to designate the launch target - */ -public interface ILaunchHandlerService { - String name(); - - ServiceRunner launchService(String[] arguments, ModuleLayer gameLayer); - - default NamedPath[] getPaths() { return new NamedPath[0]; } -} diff --git a/src/main/java/cpw/mods/modlauncher/api/IModuleLayerManager.java b/src/main/java/cpw/mods/modlauncher/api/IModuleLayerManager.java deleted file mode 100644 index d723730a3..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/IModuleLayerManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -import java.util.Optional; - -public interface IModuleLayerManager { - Optional getLayer(Layer layer); - - enum Layer { - BOOT(), - SERVICE(BOOT), - PLUGIN(BOOT), - GAME(PLUGIN, SERVICE); - - private final Layer[] parent; - - Layer(final Layer... parent) { - this.parent = parent; - } - - public Layer[] getParent() { - return parent; - } - } -} diff --git a/src/main/java/cpw/mods/modlauncher/api/ITransformerAuditTrail.java b/src/main/java/cpw/mods/modlauncher/api/ITransformerAuditTrail.java deleted file mode 100644 index f70f8c473..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/ITransformerAuditTrail.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -import java.util.List; - -public interface ITransformerAuditTrail { - /** - * Retrieve the list of activities for the specified class - * @param className Class name - * @return a read only list of activities - */ - List getActivityFor(String className); - - /** - * Retrieve a formatted string summarizing actions for the supplied class - * @param clazz The class - * @return A formatted string - */ - String getAuditString(String clazz); -} diff --git a/src/main/java/cpw/mods/modlauncher/api/IncompatibleEnvironmentException.java b/src/main/java/cpw/mods/modlauncher/api/IncompatibleEnvironmentException.java deleted file mode 100644 index a73c72994..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/IncompatibleEnvironmentException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -/** - * Indicate an incompatible environment to the modlauncher system. - */ -public class IncompatibleEnvironmentException extends Exception { - public IncompatibleEnvironmentException(String message) { - super(message); - } -} diff --git a/src/main/java/cpw/mods/modlauncher/api/NamedPath.java b/src/main/java/cpw/mods/modlauncher/api/NamedPath.java deleted file mode 100644 index 29a3f7d80..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/NamedPath.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2021 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -import java.nio.file.Path; - -public record NamedPath(String name, Path... paths) { -} diff --git a/src/main/java/cpw/mods/modlauncher/api/ServiceRunner.java b/src/main/java/cpw/mods/modlauncher/api/ServiceRunner.java deleted file mode 100644 index f130a1598..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/ServiceRunner.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2022 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -/** - * A type of Runnable that throws a Throwable. Allows for tidier implementations than Callable - */ -public interface ServiceRunner { - void run() throws Throwable; - - ServiceRunner NOOP = () -> {}; -} diff --git a/src/main/java/cpw/mods/modlauncher/api/TransformerVoteResult.java b/src/main/java/cpw/mods/modlauncher/api/TransformerVoteResult.java deleted file mode 100644 index db864cb88..000000000 --- a/src/main/java/cpw/mods/modlauncher/api/TransformerVoteResult.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.api; - -public enum TransformerVoteResult { - YES, DEFER, NO, REJECT -} - diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java deleted file mode 100644 index d87957be6..000000000 --- a/src/main/java/module-info.java +++ /dev/null @@ -1,22 +0,0 @@ -module cpw.mods.modlauncher { - requires java.base; - requires org.apache.logging.log4j; - requires org.objectweb.asm.tree; - requires org.apache.logging.log4j.core; - requires jopt.simple; - requires cpw.mods.securejarhandler; - requires static org.jetbrains.annotations; - exports cpw.mods.modlauncher.log; - exports cpw.mods.modlauncher.serviceapi; - exports cpw.mods.modlauncher.api; - exports cpw.mods.modlauncher.util; - exports cpw.mods.modlauncher; - uses cpw.mods.modlauncher.api.ILaunchHandlerService; - uses cpw.mods.modlauncher.api.ITransformationService; - uses cpw.mods.modlauncher.serviceapi.ILaunchPluginService; - uses cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService; - provides cpw.mods.modlauncher.api.ILaunchHandlerService with - cpw.mods.modlauncher.DefaultLaunchHandlerService, cpw.mods.modlauncher.TestingLaunchHandlerService; - // for bootstrap launcher to find us without having to expose our Launcher main method - provides java.util.function.Consumer with cpw.mods.modlauncher.BootstrapLaunchConsumer; -} \ No newline at end of file diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 5a898d32a..000000000 --- a/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,26 +0,0 @@ -Manifest-Version: 1.0 - -Name: cpw/mods/modlauncher/api/ -Specification-Title: modlauncher -Specification-Vendor: forge -Specification-Version: 7.0 -Implementation-Title: modlauncher -Implementation-Version: 9.0.1+0+master.09c65e8 -Implementation-Vendor: forge -Implementation-Timestamp: 2021-06-09T01:29:30.431684967Z -Git-Commit: 09c65e8 -Git-Branch: master -Build-Number: 0 - -Name: cpw/mods/modlauncher/cpw.mods.modlauncher.serviceapi/ -Specification-Title: modlauncherserviceapi -Specification-Vendor: forge -Specification-Version: 7.0 -Implementation-Title: modlauncher -Implementation-Version: 9.0.1+0+master.09c65e8 -Implementation-Vendor: forge -Implementation-Timestamp: 2021-06-09T01:29:30.433729643Z -Git-Commit: 09c65e8 -Git-Branch: master -Build-Number: 0 - diff --git a/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService b/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService deleted file mode 100644 index 376cedcc1..000000000 --- a/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService +++ /dev/null @@ -1,2 +0,0 @@ -cpw.mods.modlauncher.DefaultLaunchHandlerService -cpw.mods.modlauncher.TestingLaunchHandlerService \ No newline at end of file diff --git a/src/main/resources/log4j2.component.properties b/src/main/resources/log4j2.component.properties deleted file mode 100644 index 3dbdc7d44..000000000 --- a/src/main/resources/log4j2.component.properties +++ /dev/null @@ -1 +0,0 @@ -Log4jContextSelector=cpw.mods.modlauncher.log.MLClassLoaderContextSelector \ No newline at end of file diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml deleted file mode 100644 index 78664cbd6..000000000 --- a/src/main/resources/log4j2.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/java/cpw/mods/modlauncher/test/ClassLoaderAPITest.java b/src/test/java/cpw/mods/modlauncher/test/ClassLoaderAPITest.java deleted file mode 100644 index cad9f9187..000000000 --- a/src/test/java/cpw/mods/modlauncher/test/ClassLoaderAPITest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2020 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - - -package cpw.mods.modlauncher.test; - -import cpw.mods.modlauncher.Launcher; -import cpw.mods.modlauncher.api.IModuleLayerManager; -import org.junit.jupiter.api.Test; - -import java.util.ServiceLoader; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -class ClassLoaderAPITest { - @Test - void testGetResources() throws ClassNotFoundException { - Launcher.main("--version", "1.0", "--launchTarget", "mockLaunch", "--test.mods", "A,B,C,cpw.mods.modlauncher.testjar.TestClass", "--accessToken", "SUPERSECRET!"); - ModuleLayer layer = Launcher.INSTANCE.findLayerManager() - .flatMap(manager -> manager.getLayer(IModuleLayerManager.Layer.GAME)) - .orElseThrow(); - final Class service = Thread.currentThread().getContextClassLoader().loadClass("cpw.mods.modlauncher.testjar.ITestServiceLoader"); - getClass().getModule().addUses(service); - - final ServiceLoader load = ServiceLoader.load(layer, service); - assertTrue(load.iterator().hasNext()); - } -} diff --git a/src/test/java/cpw/mods/modlauncher/test/LauncherTests.java b/src/test/java/cpw/mods/modlauncher/test/LauncherTests.java deleted file mode 100644 index 1c440c5fb..000000000 --- a/src/test/java/cpw/mods/modlauncher/test/LauncherTests.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.test; - -import cpw.mods.modlauncher.ArgumentHandler; -import cpw.mods.modlauncher.Launcher; -import cpw.mods.modlauncher.TransformationServiceDecorator; -import cpw.mods.modlauncher.api.IEnvironment; -import cpw.mods.modlauncher.api.IModuleLayerManager; -import cpw.mods.modlauncher.api.ITransformationService; -import joptsimple.OptionSet; -import joptsimple.OptionSpec; -import org.junit.jupiter.api.Test; -import org.powermock.reflect.Whitebox; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Field; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test overall launcher - */ -class LauncherTests { - @Test - void testLauncher() throws Exception { - Launcher.main("--version", "1.0", "--launchTarget", "mockLaunch", "--test.mods", "A,B,C,cpw.mods.modlauncher.testjar.TestClass", "--accessToken", "SUPERSECRET!"); - Launcher instance = Launcher.INSTANCE; - final Map services = Whitebox.getInternalState(Whitebox.getInternalState(instance, "transformationServicesHandler"), "serviceLookup"); - final List launcherServices = services.values().stream() - .map(dec -> Whitebox.getInternalState(dec, "service")) - .toList(); - assertAll("services are present and correct", - () -> assertEquals(1, launcherServices.size(), "Found 1 service"), - () -> assertEquals(MockTransformerService.class, launcherServices.get(0).getClass(), "Found Test Launcher Service") - ); - - final ArgumentHandler argumentHandler = Whitebox.getInternalState(instance, "argumentHandler"); - final OptionSet options = Whitebox.getInternalState(argumentHandler, "optionSet"); - Map> optionsMap = options.specs().stream().collect(Collectors.toMap(s -> String.join(",", s.options()), s -> s, (u, u2) -> u)); - - assertAll("options are correctly setup", - () -> assertTrue(optionsMap.containsKey("version"), "Version field is correct"), - () -> assertTrue(optionsMap.containsKey("test.mods"), "Test service option is correct") - ); - - final MockTransformerService mockTransformerService = (MockTransformerService) launcherServices.get(0); - assertAll("test launcher service is correctly configured", - () -> assertIterableEquals(Arrays.asList("A", "B", "C", "cpw.mods.modlauncher.testjar.TestClass"), Whitebox.getInternalState(mockTransformerService, "modList"), "modlist is configured"), - () -> assertEquals("INITIALIZED", Whitebox.getInternalState(mockTransformerService, "state"), "Initialized was called") - ); - - assertAll( - () -> assertNotNull(instance.environment().getProperty(IEnvironment.Keys.VERSION.get())) - ); - - try { - final Stream transformedFields = Stream.of(Class.forName("cpw.mods.modlauncher.testjar.TestClass", true, Whitebox.getInternalState(Launcher.INSTANCE, "classLoader")).getDeclaredFields()); - assertTrue(transformedFields.anyMatch(f -> f.getName().equals("testfield")), "Found transformed field"); - final Module testJarsModule = Launcher.INSTANCE.findLayerManager() - .flatMap(m -> m.getLayer(IModuleLayerManager.Layer.PLUGIN)) - .flatMap(l -> l.findModule("cpw.mods.modlauncher.testjars")) - .orElseThrow(); - final Stream untransformedFields = Stream.of(Class.forName(testJarsModule, "cpw.mods.modlauncher.testjar.TestClass").getDeclaredFields()); - assertTrue(untransformedFields.noneMatch(f -> f.getName().equals("testfield")), "Didn't find transformed field"); - - Class resClass = Class.forName("cpw.mods.modlauncher.testjar.ResourceLoadingClass", true, Whitebox.getInternalState(Launcher.INSTANCE, "classLoader")); - assertFindResource(resClass); - } catch (ClassNotFoundException e) { - fail("Can't load class"); - } - } - - private void assertFindResource(Class loaded) throws Exception { - Object instance = loaded.getDeclaredConstructor().newInstance(); - URL resource = (URL) Whitebox.getField(loaded, "resource").get(instance); - assertNotNull(resource, "Resource not found"); - // assert that we can find something in the resource, so we know it loaded properly - try (InputStream in = resource.openStream(); - Scanner scanner = new Scanner(new InputStreamReader(in, StandardCharsets.UTF_8))) { - assertTrue(scanner.nextLine().contains("Loaded successfully!"), "Resource has incorrect content"); - } - } -} diff --git a/src/test/java/cpw/mods/modlauncher/test/MockLauncherHandlerService.java b/src/test/java/cpw/mods/modlauncher/test/MockLauncherHandlerService.java deleted file mode 100644 index 359d3e987..000000000 --- a/src/test/java/cpw/mods/modlauncher/test/MockLauncherHandlerService.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.test; - -import cpw.mods.modlauncher.api.*; - -/** - * Mock launch handler for testing - */ -public class MockLauncherHandlerService implements ILaunchHandlerService { - @Override - public String name() { - return "mockLaunch"; - } - - @Override - public ServiceRunner launchService(String[] arguments, ModuleLayer gameLayer) { - return ServiceRunner.NOOP; - } -} diff --git a/src/test/java/cpw/mods/modlauncher/test/TestingLHTests.java b/src/test/java/cpw/mods/modlauncher/test/TestingLHTests.java deleted file mode 100644 index fcb16eb26..000000000 --- a/src/test/java/cpw/mods/modlauncher/test/TestingLHTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.test; - -import cpw.mods.modlauncher.Launcher; -import cpw.mods.modlauncher.api.ServiceRunner; -import org.apache.logging.log4j.LogManager; -import org.junit.jupiter.api.Test; - -import java.util.concurrent.Callable; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -class TestingLHTests { - boolean calledback; - - @Test - void testTestingLaunchHandler() { - System.setProperty("test.harness", "build/classes/java/testJars"); - System.setProperty("test.harness.callable", "cpw.mods.modlauncher.test.TestingLHTests$TestCallback"); - calledback = false; - TestCallback.callable = () -> { - calledback = true; - LogManager.getLogger().info("Hello", new Throwable()); - }; - Launcher.main("--version", "1.0", "--launchTarget", "testharness"); - assertTrue(calledback, "We got called back"); - } - - public static class TestCallback { - private static ServiceRunner callable; - public static ServiceRunner supplier() { - return callable; - } - } -} diff --git a/src/test/java/module-info.java b/src/test/java/module-info.java deleted file mode 100644 index 823c8f315..000000000 --- a/src/test/java/module-info.java +++ /dev/null @@ -1,20 +0,0 @@ -open module cpw.mods.modlauncher.test { - requires cpw.mods.modlauncher; - requires cpw.mods.securejarhandler; - requires static cpw.mods.modlauncher.testjars; - - requires org.junit.jupiter.api; - requires powermock.core; - requires powermock.reflect; - requires org.objectweb.asm; - requires org.objectweb.asm.tree; - requires org.apache.logging.log4j; - requires org.apache.logging.log4j.core; - requires jopt.simple; - requires static org.jetbrains.annotations; - - exports cpw.mods.modlauncher.test; - - provides cpw.mods.modlauncher.api.ILaunchHandlerService with cpw.mods.modlauncher.test.MockLauncherHandlerService; - provides cpw.mods.modlauncher.api.ITransformationService with cpw.mods.modlauncher.test.MockTransformerService; -} diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml deleted file mode 100644 index a43313e86..000000000 --- a/src/test/resources/log4j2.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/testJars/java/cpw/mods/modlauncher/testjar/ITestServiceLoader.java b/src/testJars/java/cpw/mods/modlauncher/testjar/ITestServiceLoader.java deleted file mode 100644 index ddd1964c2..000000000 --- a/src/testJars/java/cpw/mods/modlauncher/testjar/ITestServiceLoader.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2020 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.testjar; - -public interface ITestServiceLoader { -} diff --git a/src/testJars/java/cpw/mods/modlauncher/testjar/ResourceLoadingClass.java b/src/testJars/java/cpw/mods/modlauncher/testjar/ResourceLoadingClass.java deleted file mode 100644 index 95c03ec97..000000000 --- a/src/testJars/java/cpw/mods/modlauncher/testjar/ResourceLoadingClass.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.testjar; - -import java.net.URL; - -public class ResourceLoadingClass { - - public final URL resource = getClass().getResource("ResourceLoadingFile"); - -} \ No newline at end of file diff --git a/src/testJars/java/cpw/mods/modlauncher/testjar/TestClass.java b/src/testJars/java/cpw/mods/modlauncher/testjar/TestClass.java deleted file mode 100644 index 082994536..000000000 --- a/src/testJars/java/cpw/mods/modlauncher/testjar/TestClass.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2019 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.testjar; - -import java.util.stream.*; - -/** - * Test class loaded by tests and manipulated by transformers - */ -public class TestClass { - private String cheese = "FISH"; - - private String testMethod(String cheese) { - String wheee = "HELLO"; - return Stream.of(cheese, wheee).collect(Collectors.joining(" ")); - } -} diff --git a/src/testJars/java/cpw/mods/modlauncher/testjar/TestServiceLoader.java b/src/testJars/java/cpw/mods/modlauncher/testjar/TestServiceLoader.java deleted file mode 100644 index 0ce07155c..000000000 --- a/src/testJars/java/cpw/mods/modlauncher/testjar/TestServiceLoader.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * ModLauncher - for launching Java programs with in-flight transformation ability. - * - * Copyright (C) 2017-2020 cpw - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package cpw.mods.modlauncher.testjar; - -public class TestServiceLoader implements ITestServiceLoader { -}