├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ └── publish.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main └── java └── org └── cadixdev └── atlas ├── Atlas.java ├── AtlasTransformerContext.java ├── jar ├── JarFile.java ├── JarPath.java ├── JarVisitOption.java └── package-info.java ├── package-info.java └── util ├── CompositeClassProvider.java ├── JarRepacker.java └── NIOHelper.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Java sources 2 | *.java text diff=java 3 | *.gradle text diff=java 4 | *.gradle.kts text diff=java 5 | 6 | # These files are text and should be normalized (Convert crlf => lf) 7 | *.css text diff=css 8 | *.df text 9 | *.htm text diff=html 10 | *.html text diff=html 11 | *.js text 12 | *.jsp text 13 | *.jspf text 14 | *.jspx text 15 | *.properties text 16 | *.tld text 17 | *.tag text 18 | *.tagx text 19 | *.xml text 20 | 21 | # These files are binary and should be left untouched 22 | # (binary is a macro for -text -diff) 23 | *.class binary 24 | *.dll binary 25 | *.ear binary 26 | *.jar binary 27 | *.so binary 28 | *.war binary 29 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/about-codeowners/ 2 | 3 | * @jamierocks 4 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Central 2 | 3 | # Only run publish for develop! 4 | on: 5 | push: 6 | branches: [ develop ] 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Set up JDK 1.8 16 | uses: actions/setup-java@v1 17 | with: 18 | java-version: 8 19 | 20 | - name: Build with Gradle 21 | run: ./gradlew build 22 | 23 | - name: Publish to Sonatype 24 | run: ./gradlew uploadArchives 25 | env: 26 | ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.ORG_GRADLE_PROJECT_ossrhUsername }} 27 | ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.ORG_GRADLE_PROJECT_ossrhPassword }} 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,linux,gradle,intellij+all 3 | # Edit at https://www.gitignore.io/?templates=java,linux,gradle,intellij+all 4 | 5 | ### Intellij+all ### 6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 7 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 8 | 9 | # User-specific stuff 10 | .idea/**/workspace.xml 11 | .idea/**/tasks.xml 12 | .idea/**/usage.statistics.xml 13 | .idea/**/dictionaries 14 | .idea/**/shelf 15 | 16 | # Generated files 17 | .idea/**/contentModel.xml 18 | 19 | # Sensitive or high-churn files 20 | .idea/**/dataSources/ 21 | .idea/**/dataSources.ids 22 | .idea/**/dataSources.local.xml 23 | .idea/**/sqlDataSources.xml 24 | .idea/**/dynamic.xml 25 | .idea/**/uiDesigner.xml 26 | .idea/**/dbnavigator.xml 27 | 28 | # Gradle 29 | .idea/**/gradle.xml 30 | .idea/**/libraries 31 | 32 | # Gradle and Maven with auto-import 33 | # When using Gradle or Maven with auto-import, you should exclude module files, 34 | # since they will be recreated, and may cause churn. Uncomment if using 35 | # auto-import. 36 | # .idea/modules.xml 37 | # .idea/*.iml 38 | # .idea/modules 39 | # *.iml 40 | # *.ipr 41 | 42 | # CMake 43 | cmake-build-*/ 44 | 45 | # Mongo Explorer plugin 46 | .idea/**/mongoSettings.xml 47 | 48 | # File-based project format 49 | *.iws 50 | 51 | # IntelliJ 52 | out/ 53 | 54 | # mpeltonen/sbt-idea plugin 55 | .idea_modules/ 56 | 57 | # JIRA plugin 58 | atlassian-ide-plugin.xml 59 | 60 | # Cursive Clojure plugin 61 | .idea/replstate.xml 62 | 63 | # Crashlytics plugin (for Android Studio and IntelliJ) 64 | com_crashlytics_export_strings.xml 65 | crashlytics.properties 66 | crashlytics-build.properties 67 | fabric.properties 68 | 69 | # Editor-based Rest Client 70 | .idea/httpRequests 71 | 72 | # Android studio 3.1+ serialized cache file 73 | .idea/caches/build_file_checksums.ser 74 | 75 | ### Intellij+all Patch ### 76 | # Ignores the whole .idea folder and all .iml files 77 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 78 | 79 | .idea/ 80 | 81 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 82 | 83 | *.iml 84 | modules.xml 85 | .idea/misc.xml 86 | *.ipr 87 | 88 | # Sonarlint plugin 89 | .idea/sonarlint 90 | 91 | ### Java ### 92 | # Compiled class file 93 | *.class 94 | 95 | # Log file 96 | *.log 97 | 98 | # BlueJ files 99 | *.ctxt 100 | 101 | # Mobile Tools for Java (J2ME) 102 | .mtj.tmp/ 103 | 104 | # Package Files # 105 | *.jar 106 | *.war 107 | *.nar 108 | *.ear 109 | *.zip 110 | *.tar.gz 111 | *.rar 112 | 113 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 114 | hs_err_pid* 115 | 116 | ### Linux ### 117 | *~ 118 | 119 | # temporary files which can be created if a process still has a handle open of a deleted file 120 | .fuse_hidden* 121 | 122 | # KDE directory preferences 123 | .directory 124 | 125 | # Linux trash folder which might appear on any partition or disk 126 | .Trash-* 127 | 128 | # .nfs files are created when an open file is removed but is still being accessed 129 | .nfs* 130 | 131 | ### Gradle ### 132 | .gradle 133 | build/ 134 | 135 | # Ignore Gradle GUI config 136 | gradle-app.setting 137 | 138 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 139 | !gradle-wrapper.jar 140 | 141 | # Cache of project 142 | .gradletasknamecache 143 | 144 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 145 | # gradle/wrapper/gradle-wrapper.properties 146 | 147 | ### Gradle Patch ### 148 | **/build/ 149 | 150 | # End of https://www.gitignore.io/api/java,linux,gradle,intellij+all 151 | 152 | # Temporary 153 | run/ 154 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Atlas 2 | ===== 3 | 4 | Atlas is a *plain-and-simple* binary transformer for Java artifacts, providing a simple API 5 | to manipulate Jars as you see fit. 6 | 7 | ```java 8 | try (final Atlas atlas = new Atlas()) { 9 | atlas.install(ctx -> new JarEntryRemappingTransformer( 10 | new LorenzRemapper(mappings) 11 | )); 12 | atlas.run(Paths.get("input.jar"), Paths.get("output.jar")); 13 | } 14 | ``` 15 | 16 | ## License 17 | 18 | Atlas is made available under the **Mozilla Public License 2.0**, you can find a copy within 19 | Atlas' binary, or within [this repository](LICENSE.txt). 20 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'maven' 3 | 4 | sourceCompatibility = javaVersion 5 | targetCompatibility = javaVersion 6 | 7 | group = 'org.cadixdev' 8 | archivesBaseName = project.name.toLowerCase() 9 | version = '0.3.0-SNAPSHOT' 10 | 11 | repositories { 12 | mavenCentral() 13 | if (bombeVersion.endsWith('-SNAPSHOT')) { 14 | maven { 15 | url 'https://oss.sonatype.org/content/groups/public/' 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | compile "org.ow2.asm:asm-commons:$asmVersion" 22 | compile "org.cadixdev:bombe:$bombeVersion" 23 | compile "org.cadixdev:bombe-jar:$bombeVersion" 24 | } 25 | 26 | processResources { 27 | from 'LICENSE.txt' 28 | } 29 | 30 | task javadocJar(type: Jar, dependsOn: 'javadoc') { 31 | from javadoc.destinationDir 32 | classifier = 'javadoc' 33 | } 34 | 35 | task sourcesJar(type: Jar, dependsOn: 'classes') { 36 | from sourceSets.main.allSource 37 | classifier = 'sources' 38 | } 39 | 40 | jar { 41 | manifest.attributes("Automatic-Module-Name": "${project.group}.atlas") 42 | } 43 | 44 | artifacts { 45 | archives javadocJar 46 | archives sourcesJar 47 | } 48 | 49 | if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { 50 | apply plugin: 'signing' 51 | signing { 52 | required { !version.endsWith('-SNAPSHOT') && gradle.taskGraph.hasTask(tasks.uploadArchives) } 53 | sign configurations.archives 54 | } 55 | } 56 | 57 | uploadArchives { 58 | repositories { 59 | mavenDeployer { 60 | // Maven Central 61 | if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { 62 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 63 | 64 | repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') { 65 | authentication(userName: ossrhUsername, password: ossrhPassword) 66 | } 67 | 68 | snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') { 69 | authentication(userName: ossrhUsername, password: ossrhPassword) 70 | } 71 | } 72 | 73 | pom { 74 | artifactId = project.archivesBaseName 75 | 76 | project { 77 | name = project.name 78 | description = project.description 79 | packaging = 'jar' 80 | url = project.url 81 | inceptionYear = project.inceptionYear 82 | 83 | scm { 84 | url = 'https://github.com/CadixDev/Atlas' 85 | connection = 'scm:git:https://github.com/CadixDev/Atlas.git' 86 | developerConnection = 'scm:git:git@github.com:CadixDev/Atlas.git' 87 | } 88 | 89 | issueManagement { 90 | system = 'GitHub' 91 | url = 'https://github.com/CadixDev/Atlas/issues' 92 | } 93 | 94 | licenses { 95 | license { 96 | name = 'Mozilla Public License 2.0' 97 | url = 'https://opensource.org/licenses/MPL-2.0' 98 | distribution = 'repo' 99 | } 100 | } 101 | 102 | developers { 103 | developer { 104 | id = 'jamierocks' 105 | name = 'Jamie Mansfield' 106 | email = 'jmansfield@cadixdev.org' 107 | url = 'https://www.jamiemansfield.me/' 108 | timezone = 'Europe/London' 109 | } 110 | } 111 | } 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project Information 2 | name = Atlas 3 | url = https://github.com/CadixDev/Atlas 4 | description = Plain-and-simple binary transformer for Java artifacts 5 | inceptionYear = 2019 6 | 7 | # Build Settings 8 | javaVersion = 1.8 9 | asmVersion = 7.1 10 | bombeVersion = 0.5.0-SNAPSHOT 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadixDev/Atlas/5dd628a8669e3a207a3286c8e9c9f910ea9f3d29/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = name 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/org/cadixdev/atlas/Atlas.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | */ 6 | 7 | package org.cadixdev.atlas; 8 | 9 | import org.cadixdev.atlas.jar.JarFile; 10 | import org.cadixdev.atlas.util.CompositeClassProvider; 11 | import org.cadixdev.atlas.util.JarRepacker; 12 | import org.cadixdev.bombe.analysis.InheritanceProvider; 13 | import org.cadixdev.bombe.analysis.asm.ClassProviderInheritanceProvider; 14 | import org.cadixdev.bombe.provider.ClassProvider; 15 | import org.cadixdev.bombe.jar.JarEntryTransformer; 16 | 17 | import java.io.Closeable; 18 | import java.io.IOException; 19 | import java.nio.file.Path; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.concurrent.ExecutorService; 23 | import java.util.concurrent.Executors; 24 | import java.util.function.Function; 25 | 26 | /** 27 | * An Atlas describes {@link JarEntryTransformer transformations}, and an environment 28 | * to transform Java binaries. 29 | * 30 | *
Atlases are independent of the specific binary being processed, allowing them to
31 | * be used for multiple binary transformations.
32 | *
33 | * @author Jamie Mansfield
34 | * @since 0.1.0
35 | */
36 | public class Atlas implements Closeable {
37 |
38 | private final List
86 | * The classpath is a list of paths that correspond to jar files, classes within
87 | * those jars will be made available to the inheritance provider.
88 | *
89 | * @return The classpath
90 | */
91 | public List Only one context will be created per Atlas run.
17 | *
18 | * @author Jamie Mansfield
19 | * @since 0.1.0
20 | */
21 | public class AtlasTransformerContext {
22 |
23 | private final InheritanceProvider inheritanceProvider;
24 |
25 | AtlasTransformerContext(final InheritanceProvider inheritanceProvider) {
26 | this.inheritanceProvider = inheritanceProvider;
27 | }
28 |
29 | /**
30 | * Gets the {@link InheritanceProvider inheritance provider} for the JAR
31 | * Atlas is processing.
32 | *
33 | * @return The inheritance provider
34 | */
35 | public InheritanceProvider inheritanceProvider() {
36 | return this.inheritanceProvider;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/cadixdev/atlas/jar/JarFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This Source Code Form is subject to the terms of the Mozilla Public
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 | */
6 |
7 | package org.cadixdev.atlas.jar;
8 |
9 | import org.cadixdev.atlas.util.NIOHelper;
10 | import org.cadixdev.bombe.jar.AbstractJarEntry;
11 | import org.cadixdev.bombe.provider.ClassProvider;
12 | import org.cadixdev.bombe.jar.JarClassEntry;
13 | import org.cadixdev.bombe.jar.JarEntryTransformer;
14 | import org.cadixdev.bombe.jar.JarManifestEntry;
15 | import org.cadixdev.bombe.jar.JarResourceEntry;
16 | import org.cadixdev.bombe.jar.JarServiceProviderConfigurationEntry;
17 | import org.cadixdev.bombe.jar.ServiceProviderConfiguration;
18 |
19 | import java.io.Closeable;
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.nio.file.FileSystem;
23 | import java.nio.file.Files;
24 | import java.nio.file.Path;
25 | import java.nio.file.attribute.FileTime;
26 | import java.util.Map;
27 | import java.util.Objects;
28 | import java.util.concurrent.CompletableFuture;
29 | import java.util.concurrent.CompletionException;
30 | import java.util.concurrent.ConcurrentHashMap;
31 | import java.util.concurrent.ExecutionException;
32 | import java.util.concurrent.ExecutorService;
33 | import java.util.concurrent.Executors;
34 | import java.util.jar.Manifest;
35 | import java.util.stream.Stream;
36 |
37 | /**
38 | * A representation of a JAR file, with the class entries cached.
39 | *
40 | * @author Jamie Mansfield
41 | * @since 0.1.0
42 | */
43 | public class JarFile implements ClassProvider, Closeable {
44 |
45 | private final Path path;
46 | private final FileSystem fs;
47 | private final Map
66 | * {@link JarClassEntry Class entries} will be cached upon use.
67 | *
68 | * @param path The path of the entry
69 | * @return The entry, or {@code null} if no entry for the path exists
70 | * @throws IOException Should an issue occur reading the entry
71 | */
72 | public AbstractJarEntry get(final JarPath path) throws IOException {
73 | final Path entry = this.fs.getPath("/", path.getName());
74 | if (Files.notExists(entry)) return null;
75 |
76 | if ("META-INF/MANIFEST.MF".equals(path.getName())) {
77 | return _readManifest(entry);
78 | }
79 | else if (path.getName().startsWith("META-INF/services/")) {
80 | return _readServiceConfig(entry);
81 | }
82 | else if (path.getName().endsWith(".class")) {
83 | return this.getClass(path);
84 | }
85 | else {
86 | return _readResource(entry);
87 | }
88 | }
89 |
90 | /**
91 | * Gets the cached class entry, of the given
92 | * {@link JarPath JAR path}.
93 | *
94 | * @param path The class's JAR entry path
95 | * @return The class entry, or {@code null} if not present
96 | */
97 | public JarClassEntry getClass(final JarPath path) {
98 | return this.cache.computeIfAbsent(path, p -> {
99 | final Path entry = this.fs.getPath("/", p.getName());
100 | if (Files.notExists(entry)) return null;
101 | try {
102 | return _readClass(entry);
103 | }
104 | catch (final IOException ignored) {
105 | return null;
106 | }
107 | });
108 | }
109 |
110 | /**
111 | * Gets the cached class entry, of the given name.
112 | *
113 | * @param name The class name
114 | * @return The class entry, or {@code null} if not present
115 | */
116 | public JarClassEntry getClass(final String name) {
117 | return this.getClass(new JarPath(name));
118 | }
119 |
120 | /**
121 | * Walks through the jar entries within the JAR file, omitting those targeted
122 | * by a {@link JarVisitOption}.
123 | *
124 | * @param options The visit options to use, while walking
125 | * @return The jar entries
126 | * @throws IOException Should an issue with reading occur
127 | */
128 | public Stream
153 | * This will use {@link Executors#newWorkStealingPool()} as the executor service,
154 | * use {@link #transform(Path, ExecutorService, JarEntryTransformer...)} if you
155 | * wish to control this.
156 | *
157 | * @param export The JAR path to write to
158 | * @param transformers The transformers to use
159 | * @throws IOException Should an issue with reading or writing occur
160 | */
161 | public void transform(final Path export, final JarEntryTransformer... transformers) throws IOException {
162 | final ExecutorService executorService = Executors.newWorkStealingPool();
163 | try {
164 | this.transform(export, executorService, transformers);
165 | }
166 | finally {
167 | executorService.shutdown();
168 | }
169 | }
170 |
171 | /**
172 | * Transforms the JAR file, with the given {@link JarEntryTransformer}s, writing
173 | * to the given output JAR path.
174 | *
175 | * @param export The JAR path to write to
176 | * @param executorService The executor service to use
177 | * @param transformers The transformers to use
178 | * @throws IOException Should an issue with reading or writing occur
179 | * @since 0.2.1
180 | */
181 | public void transform(final Path export, final ExecutorService executorService, final JarEntryTransformer... transformers) throws IOException {
182 | Files.deleteIfExists(export);
183 | try (final FileSystem fs = NIOHelper.openZip(export, true)) {
184 | final CompletableFuture
248 | * The eventual result of transformation is ignored, and not written to file.
249 | * {@link #transform(Path, ExecutorService, JarEntryTransformer...)} should be used if such
250 | * behaviour is desired.
251 | *
252 | * This will use {@link Executors#newWorkStealingPool()} as the executor service, use
253 | * {@link #process(ExecutorService, JarEntryTransformer...)} if you wish to control this.
254 | *
255 | * @param transformers The transformers to use
256 | * @throws IOException Should an issue with reading occur
257 | * @since 0.2.2
258 | */
259 | public void process(final JarEntryTransformer... transformers) throws IOException {
260 | final ExecutorService executorService = Executors.newWorkStealingPool();
261 | try {
262 | this.process(executorService, transformers);
263 | }
264 | finally {
265 | executorService.shutdown();
266 | }
267 | }
268 |
269 | /**
270 | * Processes the JAR file, running the given {@link JarEntryTransformer jar entry transformers}
271 | * for each path within the jar.
272 | *
273 | * The eventual result of transformation is ignored, and not written to file.
274 | * {@link #transform(Path, ExecutorService, JarEntryTransformer...)} should be used if such
275 | * behaviour is desired.
276 | *
277 | * @param executorService The executor service to use
278 | * @param transformers The transformers to use
279 | * @throws IOException Should an issue with reading occur
280 | * @since 0.2.2
281 | */
282 | public void process(final ExecutorService executorService, final JarEntryTransformer... transformers)
283 | throws IOException {
284 | final CompletableFuture {@link org.cadixdev.bombe.jar.JarClassEntry Class entries} will be
13 | * cached, to avoid making lots of IO calls.
14 | */
15 | package org.cadixdev.atlas.jar;
16 |
--------------------------------------------------------------------------------
/src/main/java/org/cadixdev/atlas/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This Source Code Form is subject to the terms of the Mozilla Public
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 | */
6 |
7 | /**
8 | * Atlas - a framework for making binary transformations to JAR files,
9 | * independent of the artifacts being transformed.
10 | *
11 | * The framework revolves around {@link org.cadixdev.atlas.Atlas atlasses},
12 | * which describes the environment for transformations to be applied and
13 | * the transformations to make.
14 | */
15 | package org.cadixdev.atlas;
16 |
--------------------------------------------------------------------------------
/src/main/java/org/cadixdev/atlas/util/CompositeClassProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This Source Code Form is subject to the terms of the Mozilla Public
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 | */
6 |
7 | package org.cadixdev.atlas.util;
8 |
9 | import org.cadixdev.bombe.provider.ClassProvider;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * A {@link ClassProvider class provider} backed by many other class providers.
15 | *
16 | * @author Jamie Mansfield
17 | * @since 0.1.0
18 | */
19 | public class CompositeClassProvider implements ClassProvider {
20 |
21 | private final List
41 | * In order to maintain compatibility with the jars Atlas produces, this method will check first if
42 | * the output jar has any manifest file at all, and if it does, if it is retrievable by {@link JarInputStream}.
43 | *
44 | * If the output jar does have a manifest file that {@link JarInputStream} can't access, then this method will repack
45 | * the jar to fix the issue. For performance reasons Atlas remapping process remaps jar entries in parallel, and it
46 | * uses the NIO zip file system API, which we have no control of. Since this repacking process is a simple copy it is
47 | * still very fast (compared to the remapping operation).
48 | *
49 | * @param outputJar The jar produced by the atlas transformation.
50 | * @throws IOException If an IO error occurs.
51 | */
52 | public static void verifyJarManifest(final Path outputJar) throws IOException {
53 | final boolean maybeNeedsRepack;
54 | try (final JarInputStream input = new JarInputStream(Files.newInputStream(outputJar))) {
55 | maybeNeedsRepack = input.getManifest() == null;
56 | }
57 | if (maybeNeedsRepack) {
58 | final boolean hasManifest;
59 | try (final JarFile outputJarFile = new JarFile(outputJar.toFile())) {
60 | hasManifest = outputJarFile.getManifest() != null;
61 | }
62 | if (hasManifest) {
63 | fixJarManifest(outputJar);
64 | }
65 | }
66 | }
67 |
68 | /**
69 | * Given that the output jar needs to be fixed, repack the given jar with the {@code META-INF/MANIFEST.MF} file as
70 | * the first entry.
71 | *
72 | * @param outputJar The file to repack.
73 | * @throws IOException If an IO error occurs.
74 | * @see #verifyJarManifest(Path)
75 | */
76 | private static void fixJarManifest(final Path outputJar) throws IOException {
77 | final byte[] buffer = new byte[8192];
78 |
79 | final Path tempOut = Files.createTempFile(outputJar.getParent(), "atlas", "jar");
80 | try {
81 | try (final JarOutputStream out = new JarOutputStream(Files.newOutputStream(tempOut));
82 | final JarFile jarFile = new JarFile(outputJar.toFile())) {
83 |
84 | final boolean skipManifest = copyManifest(jarFile, out);
85 |
86 | final Enumeration