├── .asf.yaml ├── .gitattributes ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── codeql-analysis.yml │ ├── dependency-review.yml │ ├── maven.yml │ └── scorecards-analysis.yml ├── .gitignore ├── BUILDING.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE-asm6.2.1.txt ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE-NOTES.txt ├── SECURITY.md ├── ant ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── weaver │ │ │ └── ant │ │ │ ├── AbstractWeaverTask.java │ │ │ ├── CleanTask.java │ │ │ ├── InlineProperties.java │ │ │ ├── WeaveTask.java │ │ │ ├── WeaverSettings.java │ │ │ └── package-info.java │ └── resources │ │ └── org │ │ └── apache │ │ └── commons │ │ └── weaver │ │ └── ant │ │ └── antlib.xml │ └── site │ ├── markdown │ └── index.md │ └── resources │ └── profile.japicmp ├── build-tools ├── pom.xml └── src │ └── main │ └── resources │ └── org │ └── apache │ └── commons │ └── weaver │ ├── checkstyle.xml │ ├── findbugs-exclude-filter.xml │ └── pmd.xml ├── dist ├── pom.xml └── src │ └── assembly │ ├── bin.xml │ └── src.xml ├── maven-plugin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── weaver │ │ │ └── maven │ │ │ ├── AbstractCWMojo.java │ │ │ ├── AbstractPrepareMojo.java │ │ │ ├── AbstractWeaveMojo.java │ │ │ ├── JavaLoggingToMojoLoggingRedirector.java │ │ │ ├── PrepareMojo.java │ │ │ ├── TestPrepareMojo.java │ │ │ ├── TestWeaveMojo.java │ │ │ ├── WeaveMojo.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── m2e │ │ └── lifecycle-mapping-metadata.xml │ └── site │ └── resources │ ├── japicmp-post-analysis.groovy │ └── profile.japicmp ├── modules ├── normalizer │ ├── pom.xml │ └── src │ │ ├── it │ │ └── sample │ │ │ ├── build.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── weaver │ │ │ └── normalizer │ │ │ └── example │ │ │ ├── Assertions.java │ │ │ ├── ContrivedWrapper.java │ │ │ ├── InstanceMembers.java │ │ │ └── StaticMembers.java │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── commons │ │ │ │ └── weaver │ │ │ │ └── normalizer │ │ │ │ ├── Normalizer.java │ │ │ │ ├── NormalizerWeaver.java │ │ │ │ ├── Utils.java │ │ │ │ └── package-info.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── org.apache.commons.weaver.spi.Weaver │ │ ├── site │ │ └── markdown │ │ │ └── index.md │ │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── weaver │ │ └── normalizer │ │ └── UtilsTest.java ├── pom.xml ├── privilizer │ ├── api │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── commons │ │ │ │ └── weaver │ │ │ │ └── privilizer │ │ │ │ ├── Privileged.java │ │ │ │ ├── Privilizing.java │ │ │ │ └── package-info.java │ │ │ └── site │ │ │ └── resources │ │ │ └── profile.japicmp │ ├── pom.xml │ ├── src │ │ └── site │ │ │ └── markdown │ │ │ └── index.md │ └── weaver │ │ ├── pom.xml │ │ └── src │ │ ├── it │ │ ├── sample │ │ │ ├── invoker.properties │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── org │ │ │ │ │ └── apache │ │ │ │ │ └── commons │ │ │ │ │ └── weaver │ │ │ │ │ └── privilizer │ │ │ │ │ └── example │ │ │ │ │ ├── MethodReferencesUsingBlueprints.java │ │ │ │ │ ├── NoArgs.java │ │ │ │ │ ├── Overloading.java │ │ │ │ │ ├── PrivateMethods.java │ │ │ │ │ ├── Setup.java │ │ │ │ │ ├── StaticNoArgs.java │ │ │ │ │ ├── StaticOverloading.java │ │ │ │ │ ├── StaticPrivateMethods.java │ │ │ │ │ ├── StaticUsingArgs.java │ │ │ │ │ ├── UsingArgs.java │ │ │ │ │ ├── UsingBlueprints.java │ │ │ │ │ └── Utils.java │ │ │ │ └── test │ │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── apache │ │ │ │ │ └── commons │ │ │ │ │ └── weaver │ │ │ │ │ └── privilizer │ │ │ │ │ └── example │ │ │ │ │ ├── MethodReferencesUsingBlueprintsTest.java │ │ │ │ │ ├── NoArgsTest.java │ │ │ │ │ ├── OverloadingTest.java │ │ │ │ │ ├── PrivateMethodsTest.java │ │ │ │ │ ├── StaticNoArgsTest.java │ │ │ │ │ ├── StaticOverloadingTest.java │ │ │ │ │ ├── StaticPrivateMethodsTest.java │ │ │ │ │ ├── StaticUsingArgsTest.java │ │ │ │ │ ├── UsingArgsTest.java │ │ │ │ │ └── UsingBlueprintsTest.java │ │ │ │ └── resources │ │ │ │ └── java.policy │ │ └── settings.xml │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── weaver │ │ │ └── privilizer │ │ │ ├── AccessLevel.java │ │ │ ├── ActionGenerator.java │ │ │ ├── BlueprintingVisitor.java │ │ │ ├── Field.java │ │ │ ├── FieldAccess.java │ │ │ ├── InlineNestedPrivilegedCalls.java │ │ │ ├── Policy.java │ │ │ ├── Privilized.java │ │ │ ├── Privilizer.java │ │ │ ├── PrivilizerCleaner.java │ │ │ ├── PrivilizerWeaver.java │ │ │ ├── PrivilizingVisitor.java │ │ │ └── package-info.java │ │ └── resources │ │ └── META-INF │ │ └── services │ │ ├── org.apache.commons.weaver.spi.Cleaner │ │ └── org.apache.commons.weaver.spi.Weaver └── src │ └── site │ └── markdown │ └── index.md ├── parent └── pom.xml ├── pom.xml ├── processor ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── weaver │ │ ├── CleanProcessor.java │ │ ├── Consumes.java │ │ ├── Finder.java │ │ ├── Inflater.java │ │ ├── LocalWeaveEnvironment.java │ │ ├── ProcessorBase.java │ │ ├── Produces.java │ │ ├── WeaveProcessor.java │ │ ├── lifecycle │ │ ├── WeaveLifecycle.java │ │ ├── WeaveLifecycleToken.java │ │ └── package-info.java │ │ ├── model │ │ ├── AnnotatedElements.java │ │ ├── NestedWeavable.java │ │ ├── ScanRequest.java │ │ ├── ScanResult.java │ │ ├── Scanner.java │ │ ├── Weavable.java │ │ ├── WeavableClass.java │ │ ├── WeavableConstructor.java │ │ ├── WeavableConstructorParameter.java │ │ ├── WeavableExecutable.java │ │ ├── WeavableField.java │ │ ├── WeavableMethod.java │ │ ├── WeavableMethodParameter.java │ │ ├── WeavablePackage.java │ │ ├── WeavableParameter.java │ │ ├── WeaveEnvironment.java │ │ ├── WeaveInterest.java │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── spi │ │ ├── Cleaner.java │ │ ├── WeaveLifecycleProvider.java │ │ ├── Weaver.java │ │ └── package-info.java │ │ └── utils │ │ ├── Annotations.java │ │ ├── Args.java │ │ ├── Providers.java │ │ ├── URLArray.java │ │ └── package-info.java │ ├── site │ ├── markdown │ │ └── index.md │ └── resources │ │ └── profile.japicmp │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── weaver │ │ ├── FinderTest.java │ │ ├── test │ │ ├── CleanProcessorTest.java │ │ ├── WeaveProcessorTest.java │ │ ├── WeaverTestBase.java │ │ ├── beans │ │ │ ├── AbstractTestBean.java │ │ │ ├── ComplexAnnotations.java │ │ │ ├── TestAnnotation.java │ │ │ ├── TestBeanInterface.java │ │ │ ├── TestBeanWithClassAnnotation.java │ │ │ └── TestBeanWithMethodAnnotation.java │ │ └── weaver │ │ │ ├── TestCleaner.java │ │ │ └── TestWeaver.java │ │ └── utils │ │ ├── ArgsTest.java │ │ └── ProvidersTest.java │ └── resources │ └── META-INF │ └── services │ ├── org.apache.commons.weaver.spi.Cleaner │ └── org.apache.commons.weaver.spi.Weaver └── src ├── changes ├── changes.xml └── release-notes.vm └── site ├── markdown ├── building.md └── index.md ├── resources ├── download_weaver.cgi ├── images │ ├── weaver-logo-white.png │ ├── weaver-logo-white.xcf │ ├── weaver.png │ └── weaver.svg └── profile.jacoco ├── site.xml └── xdoc ├── download_weaver.xml ├── issue-tracking.xml └── mail-lists.xml /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Weaver" 18 | homepage: https://commons.apache.org/weaver/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | issues_bot_dependabot: notifications@commons.apache.org 27 | pullrequests_bot_dependabot: notifications@commons.apache.org 28 | issues_bot_codecov-commenter: notifications@commons.apache.org 29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 30 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | * text=auto 17 | *.patch -text 18 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "weekly" 22 | day: "friday" 23 | - package-ecosystem: "github-actions" 24 | directory: "/" 25 | schedule: 26 | interval: "weekly" 27 | day: "friday" 28 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! 21 | 22 | Before you push a pull request, review this list: 23 | 24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. 25 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. 26 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice. 27 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 28 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge. 29 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Dependency Review' 19 | on: [pull_request] 20 | 21 | permissions: 22 | contents: read 23 | 24 | jobs: 25 | dependency-review: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: 'Checkout Repository' 29 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 30 | - name: 'Dependency Review PR' 31 | uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 32 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Java CI 17 | 18 | on: [push, pull_request, workflow_dispatch] 19 | 20 | permissions: 21 | contents: read 22 | 23 | jobs: 24 | build: 25 | timeout-minutes: 7 26 | continue-on-error: ${{ matrix.experimental }} 27 | strategy: 28 | matrix: 29 | java: [ 8, 11 ] 30 | os: [ubuntu-latest] 31 | experimental: [true] # allow builds to continue to debug test fails 32 | # Don't need 33 | include: 34 | - java: 8 35 | os: macos-13 36 | experimental: false 37 | - java: 8 38 | os: windows-latest 39 | experimental: false 40 | # Fails with Unsupported class file major version 61 (= 17) 41 | - java: 17 42 | experimental: true 43 | os: ubuntu-latest 44 | # - java: 18-ea 45 | # experimental: true 46 | 47 | runs-on: ${{ matrix.os }} 48 | steps: 49 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 50 | with: 51 | persist-credentials: false 52 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 53 | with: 54 | path: ~/.m2/repository 55 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 56 | restore-keys: | 57 | ${{ runner.os }}-maven- 58 | - name: Set up JDK ${{ matrix.java }} 59 | uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1 60 | with: 61 | distribution: 'temurin' 62 | java-version: ${{ matrix.java }} 63 | - name: Build with Maven 64 | run: mvn --errors --show-version --batch-mode --no-transfer-progress 65 | -------------------------------------------------------------------------------- /.github/workflows/scorecards-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache license, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the license for the specific language governing permissions and 14 | # limitations under the license. 15 | 16 | name: "Scorecards supply-chain security" 17 | 18 | on: 19 | branch_protection_rule: 20 | schedule: 21 | - cron: "30 1 * * 6" # Weekly on Saturdays 22 | push: 23 | branches: [ "master" ] 24 | 25 | permissions: read-all 26 | 27 | jobs: 28 | 29 | analysis: 30 | 31 | name: "Scorecards analysis" 32 | runs-on: ubuntu-latest 33 | permissions: 34 | # Needed to upload the results to the code-scanning dashboard. 35 | security-events: write 36 | actions: read 37 | id-token: write # This is required for requesting the JWT 38 | contents: read # This is required for actions/checkout 39 | 40 | steps: 41 | 42 | - name: "Checkout code" 43 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 44 | with: 45 | persist-credentials: false 46 | 47 | - name: "Run analysis" 48 | uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # 2.4.2 49 | with: 50 | results_file: results.sarif 51 | results_format: sarif 52 | # A read-only PAT token, which is sufficient for the action to function. 53 | # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188 54 | repo_token: ${{ secrets.GITHUB_TOKEN }} 55 | # Publish the results for public repositories to enable scorecard badges. 56 | # For more details: https://github.com/ossf/scorecard-action#publishing-results 57 | publish_results: true 58 | 59 | - name: "Upload artifact" 60 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2 61 | with: 62 | name: SARIF file 63 | path: results.sarif 64 | retention-days: 5 65 | 66 | - name: "Upload to code-scanning" 67 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 68 | with: 69 | sarif_file: results.sarif 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .classpath 3 | .project 4 | .settings 5 | .DS_Store 6 | dependency-reduced-pom.xml 7 | *.iml 8 | *.ipr 9 | *.iws 10 | *.swp 11 | .gitignore.swp 12 | docs/reference/src/main/docbook/en-US/version_info.xml 13 | .idea 14 | .forge_settings 15 | .factorypath 16 | -------------------------------------------------------------------------------- /BUILDING.txt: -------------------------------------------------------------------------------- 1 | link src/site/markdown/building.md -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /LICENSE-asm6.2.1.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2000-2011 INRIA, France Telecom 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holders nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Weaver 2 | Copyright 2012-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (https://www.apache.org/). 6 | -------------------------------------------------------------------------------- /RELEASE-NOTES.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Weaver 2.0 2 | RELEASE NOTES 3 | 4 | The Apache Commons team is pleased to announce the release of Apache Commons Weaver 2.0 5 | 6 | Apache Commons Weaver provides an easy way to enhance compiled Java 7 | classes by generating ("weaving") bytecode into those classes. 8 | 9 | Requires Java 8 or above. 10 | 11 | Changes in this version include: 12 | 13 | New features: 14 | o WEAVER-19: Upgrade to Java 8. 15 | o WEAVER-24: Blueprint method references. 16 | 17 | Fixed Bugs: 18 | o WEAVER-16: NullPointerException when weaving class with no package. 19 | o WEAVER-17: Maven plugin was packaged without its (generated) HelpMojo class. 20 | o WEAVER-23: Privilizer Weaver computes Object for all variable types in catch context. 21 | 22 | Changes: 23 | o WEAVER-20: Remove commons-io, commons-collections dependencies. 24 | o WEAVER-21: Upgrade xbean-finder to v4.9. 25 | o WEAVER-22: Upgrade modules to ASM 6.2.1. 26 | o WEAVER-25: Reject blueprint methods that access entities that would be inaccessible. 27 | o WEAVER-26: Upgrade to commons-parent v47. 28 | 29 | 30 | Historical list of changes: https://commons.apache.org/proper/commons-weaver/changes-report.html 31 | 32 | For complete information on Apache Commons Weaver, including instructions on how to submit bug reports, 33 | patches, or suggestions for improvement, see the Apache Commons Weaver website: 34 | 35 | https://commons.apache.org/proper/commons-weaver 36 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /ant/src/main/java/org/apache/commons/weaver/ant/AbstractWeaverTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.ant; 20 | 21 | import org.apache.tools.ant.BuildException; 22 | import org.apache.tools.ant.Project; 23 | import org.apache.tools.ant.Task; 24 | import org.apache.tools.ant.types.Reference; 25 | 26 | /** 27 | * Abstract weaver Ant task. Manages settings for file system-based weaving. 28 | */ 29 | public abstract class AbstractWeaverTask extends Task { 30 | private WeaverSettings settings; 31 | 32 | /** 33 | * Create a new {@link AbstractWeaverTask} instance. 34 | * @param project owner 35 | */ 36 | protected AbstractWeaverTask(final Project project) { 37 | setProject(project); 38 | } 39 | 40 | /** 41 | * Add a nested {@link WeaverSettings}. 42 | * @param settings to add 43 | */ 44 | public void add(final WeaverSettings settings) { 45 | if (this.settings != null) { 46 | throw new BuildException("settings already specified"); 47 | } 48 | this.settings = settings; 49 | } 50 | 51 | /** 52 | * Gets the {@link WeaverSettings} in use. 53 | * @return {@link WeaverSettings} 54 | */ 55 | public WeaverSettings getSettings() { 56 | return settings; 57 | } 58 | 59 | /** 60 | * Sets a project reference to a {@link WeaverSettings} object. 61 | * @param refid key 62 | */ 63 | public void setSettingsRef(final String refid) { 64 | final WeaverSettings settings = new WeaverSettings(getProject()); 65 | settings.setRefid(new Reference(getProject(), refid)); 66 | add(settings); 67 | } 68 | } -------------------------------------------------------------------------------- /ant/src/main/java/org/apache/commons/weaver/ant/CleanTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.ant; 20 | 21 | import org.apache.commons.lang3.Validate; 22 | import org.apache.commons.weaver.CleanProcessor; 23 | import org.apache.tools.ant.BuildException; 24 | import org.apache.tools.ant.Project; 25 | 26 | /** 27 | * Clean Ant task. 28 | */ 29 | public class CleanTask extends AbstractWeaverTask { 30 | /** 31 | * Create a new {@link CleanTask} instance. 32 | * @param project owner 33 | */ 34 | public CleanTask(final Project project) { 35 | super(project); 36 | } 37 | 38 | /** 39 | * Execute the clean task. 40 | */ 41 | @Override 42 | public void execute() { 43 | try { 44 | final WeaverSettings settings = Validate.notNull(getSettings(), "settings"); 45 | new CleanProcessor(settings.getClasspathEntries(), settings.getTarget(), settings.getProperties()).clean(); 46 | } catch (final Exception e) { 47 | throw new BuildException(e); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ant/src/main/java/org/apache/commons/weaver/ant/InlineProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.ant; 20 | 21 | import java.util.Properties; 22 | 23 | import org.apache.commons.lang3.StringUtils; 24 | import org.apache.tools.ant.DynamicElementNS; 25 | 26 | /** 27 | *

Structure to allow inline specification of properties.

28 | *

Example: 29 | * {pre}<foo>foo-value</foo> 30 | * <bar>bar-value</bar> 31 | * <baz>baz 32 | * -nextline-value</baz> 33 | * {/pre} 34 | *

35 | */ 36 | public class InlineProperties implements DynamicElementNS { 37 | /** 38 | * Represents a single inline property. 39 | */ 40 | public final class InlineProperty { 41 | private final String name; 42 | 43 | private InlineProperty(final String name) { 44 | this.name = name; 45 | } 46 | 47 | /** 48 | * Add text to this property. 49 | * @param text to add 50 | */ 51 | public void addText(final String text) { 52 | final String value; 53 | if (properties.containsKey(name)) { 54 | value = StringUtils.join(properties.getProperty(name), text); 55 | } else { 56 | value = text; 57 | } 58 | properties.setProperty(name, value); 59 | } 60 | } 61 | 62 | /** 63 | * {@link Properties} object maintained by the {@link InlineProperties}. 64 | */ 65 | final Properties properties = new Properties(); 66 | 67 | /** 68 | * Handle the specified nested element. 69 | * @param uri String URI 70 | * @param localName local element name 71 | * @param qName qualified name 72 | * @return InlineProperty 73 | */ 74 | @Override 75 | public InlineProperty createDynamicElement(final String uri, final String localName, final String qName) { 76 | return new InlineProperty(localName); 77 | } 78 | } -------------------------------------------------------------------------------- /ant/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.ant; 20 | 21 | import org.apache.commons.lang3.Validate; 22 | import org.apache.commons.weaver.WeaveProcessor; 23 | import org.apache.tools.ant.BuildException; 24 | import org.apache.tools.ant.Project; 25 | 26 | /** 27 | * Weave Ant task. 28 | */ 29 | public class WeaveTask extends AbstractWeaverTask { 30 | /** 31 | * Create a new {@link WeaveTask} instance. 32 | * @param project owner 33 | */ 34 | public WeaveTask(final Project project) { 35 | super(project); 36 | } 37 | 38 | /** 39 | * Execute the weave task. 40 | */ 41 | @Override 42 | public void execute() { 43 | try { 44 | final WeaverSettings settings = Validate.notNull(getSettings(), "settings"); 45 | new WeaveProcessor(settings.getClasspathEntries(), settings.getTarget(), settings.getProperties()).weave(); 46 | } catch (final Exception e) { 47 | throw new BuildException(e); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ant/src/main/java/org/apache/commons/weaver/ant/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Integration with Apache Ant. 20 | */ 21 | package org.apache.commons.weaver.ant; -------------------------------------------------------------------------------- /ant/src/main/resources/org/apache/commons/weaver/ant/antlib.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ant/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | ## Apache Commons Weaver Antlib 21 | 22 | Provides an Antlib in the `antlib:org.apache.commons.weaver.ant` namespace, 23 | consisting of the following tasks: 24 | 25 | ### clean 26 | 27 | Invokes available [Cleaner][cleaner] implementations. 28 | 29 | ### weave 30 | 31 | Invokes available [Weaver][weaver] implementations. 32 | 33 | 34 | Both the **weave** and **clean** tasks are parameterized either by 35 | nesting or by reference (via the `settingsref` attribute) with a 36 | custom type: 37 | 38 | ### settings 39 | 40 | * `target` attribute - specifies the location of the classfiles to weave 41 | * `classpath` attribute - path string (incompatible with `classpathref`) 42 | * `classpathref` attribute - refid of an Ant **path** 43 | (incompatible with `classpath`) 44 | * `includesystemclasspath` - specifies whether to include the system classpath 45 | * nested `propertyset` - Ant **PropertySet** 46 | * nested `properties` - specifies properties using the names and text values 47 | of nested elements (looks like Maven POM properties) 48 | 49 | 50 | [cleaner]: ../../apidocs/org/apache/commons/weaver/spi/Cleaner.html 51 | [weaver]: ../../apidocs/org/apache/commons/weaver/spi/Weaver.html 52 | -------------------------------------------------------------------------------- /ant/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /build-tools/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | org.apache.commons 23 | commons-weaver-base 24 | 2.1-SNAPSHOT 25 | 26 | 4.0.0 27 | commons-weaver-build-tools 28 | Apache Commons Weaver Build Tools 29 | Provide common setup, from http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html 30 | 31 | 32 | 33 | 34 | 35 | com.github.siom79.japicmp 36 | japicmp-maven-plugin 37 | 38 | true 39 | 40 | 41 | 42 | 43 | 44 | 45 | maven-source-plugin 46 | 47 | true 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-jar-plugin 53 | 54 | 55 | attach-test-jar 56 | 57 | 58 | 59 | 60 | 61 | org.apache.maven.plugins 62 | maven-javadoc-plugin 63 | 64 | 65 | **/* 66 | 67 | 68 | 69 | 70 | create-javadoc-jar 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /build-tools/src/main/resources/org/apache/commons/weaver/findbugs-exclude-filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 23 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /dist/src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.artifactId}-${project.version} 26 | false 27 | 28 | 29 | false 30 | false 31 | 32 | 33 | 34 | 35 | 36 | ${project.basedir}/.. 37 | 38 | LICENSE*.txt 39 | NOTICE.txt 40 | RELEASE-NOTES.txt 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /dist/src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.artifactId}-${project.version}-src 26 | 27 | 28 | ${project.basedir}/.. 29 | 30 | ${project.build.directory}/** 31 | .*/** 32 | **/${project.build.directory}/** 33 | **/.*/** 34 | **/dependency-reduced-pom.xml 35 | 36 | 37 | 38 | 39 | 40 | ${project.basedir}/../src/site/markdown/building.md 41 | / 42 | BUILDING.txt 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractPrepareMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.maven; 20 | 21 | import java.io.File; 22 | import java.util.List; 23 | import java.util.Properties; 24 | 25 | import org.apache.commons.weaver.CleanProcessor; 26 | import org.apache.maven.plugin.MojoExecutionException; 27 | 28 | /** 29 | * Implements weaver preparation. 30 | */ 31 | public abstract class AbstractPrepareMojo extends AbstractCWMojo { 32 | 33 | @Override 34 | protected void doExecute(final File target, final List classpath, final Properties config) 35 | throws MojoExecutionException { 36 | if (!target.isDirectory()) { 37 | return; 38 | } 39 | try { 40 | new CleanProcessor(classpath, target, config).clean(); 41 | } catch (final Exception e) { 42 | throw new MojoExecutionException("cleaning failed due to " + e.getMessage(), e); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.maven; 20 | 21 | import java.io.File; 22 | import java.util.List; 23 | import java.util.Properties; 24 | 25 | import org.apache.commons.weaver.WeaveProcessor; 26 | import org.apache.maven.plugin.MojoExecutionException; 27 | 28 | /** 29 | * Defines common properties. 30 | */ 31 | public abstract class AbstractWeaveMojo extends AbstractCWMojo { 32 | 33 | @Override 34 | protected void doExecute(final File target, final List classpath, final Properties config) 35 | throws MojoExecutionException { 36 | try { 37 | new WeaveProcessor(classpath, target, config).weave(); 38 | } catch (final Exception e) { 39 | throw new MojoExecutionException("weaving failed due to " + e.getMessage(), e); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/PrepareMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.maven; 20 | 21 | import java.io.File; 22 | 23 | import org.apache.maven.model.Build; 24 | import org.apache.maven.plugins.annotations.LifecyclePhase; 25 | import org.apache.maven.plugins.annotations.Mojo; 26 | import org.apache.maven.plugins.annotations.Parameter; 27 | import org.apache.maven.plugins.annotations.ResolutionScope; 28 | 29 | /** 30 | * Goal to clean woven classes. 31 | */ 32 | @Mojo( 33 | name = "prepare", 34 | defaultPhase = LifecyclePhase.INITIALIZE, 35 | requiresDependencyCollection = ResolutionScope.RUNTIME_PLUS_SYSTEM, 36 | requiresDependencyResolution = ResolutionScope.RUNTIME_PLUS_SYSTEM 37 | ) 38 | public class PrepareMojo extends AbstractPrepareMojo { 39 | /** 40 | * {@link Build#getOutputDirectory()}. 41 | */ 42 | @Parameter(readonly = true, required = true, defaultValue = "${project.build.outputDirectory}") 43 | protected File target; 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | protected File getTarget() { 50 | return target; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestPrepareMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.maven; 20 | 21 | import java.io.File; 22 | 23 | import org.apache.commons.weaver.maven.AbstractCWMojo.TestScope; 24 | import org.apache.maven.model.Build; 25 | import org.apache.maven.plugins.annotations.LifecyclePhase; 26 | import org.apache.maven.plugins.annotations.Mojo; 27 | import org.apache.maven.plugins.annotations.Parameter; 28 | import org.apache.maven.plugins.annotations.ResolutionScope; 29 | 30 | /** 31 | * Goal to clean woven test classes. 32 | */ 33 | @Mojo( 34 | name = "test-prepare", 35 | defaultPhase = LifecyclePhase.INITIALIZE, 36 | requiresDependencyCollection = ResolutionScope.TEST, 37 | requiresDependencyResolution = ResolutionScope.TEST 38 | ) 39 | @TestScope 40 | public class TestPrepareMojo extends AbstractPrepareMojo { 41 | /** 42 | * {@link Build#getTestOutputDirectory()}. 43 | */ 44 | @Parameter(readonly = true, required = true, defaultValue = "${project.build.testOutputDirectory}") 45 | protected File target; 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | protected File getTarget() { 52 | return target; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.maven; 20 | 21 | import java.io.File; 22 | import java.util.List; 23 | 24 | import org.apache.commons.weaver.maven.AbstractCWMojo.TestScope; 25 | import org.apache.maven.model.Build; 26 | import org.apache.maven.plugins.annotations.LifecyclePhase; 27 | import org.apache.maven.plugins.annotations.Mojo; 28 | import org.apache.maven.plugins.annotations.Parameter; 29 | import org.apache.maven.plugins.annotations.ResolutionScope; 30 | import org.apache.maven.project.MavenProject; 31 | 32 | /** 33 | * Goal to weave test classes. 34 | */ 35 | @Mojo( 36 | name = "test-weave", 37 | defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, 38 | requiresDependencyCollection = ResolutionScope.TEST, 39 | requiresDependencyResolution = ResolutionScope.TEST 40 | ) 41 | @TestScope 42 | public class TestWeaveMojo extends AbstractWeaveMojo { 43 | 44 | /** 45 | * {@link MavenProject#getTestClasspathElements()}. 46 | */ 47 | @Parameter(readonly = true, required = true, defaultValue = "${project.testClasspathElements}") 48 | protected List classpath; 49 | 50 | /** 51 | * {@link Build#getTestOutputDirectory()}. 52 | */ 53 | @Parameter(readonly = true, required = true, defaultValue = "${project.build.testOutputDirectory}") 54 | protected File target; 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | protected File getTarget() { 61 | return target; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.maven; 20 | 21 | import java.io.File; 22 | 23 | import org.apache.maven.model.Build; 24 | import org.apache.maven.plugins.annotations.LifecyclePhase; 25 | import org.apache.maven.plugins.annotations.Mojo; 26 | import org.apache.maven.plugins.annotations.Parameter; 27 | import org.apache.maven.plugins.annotations.ResolutionScope; 28 | 29 | /** 30 | * Goal to weave classes. 31 | */ 32 | @Mojo( 33 | name = "weave", 34 | defaultPhase = LifecyclePhase.PROCESS_CLASSES, 35 | requiresDependencyCollection = ResolutionScope.RUNTIME_PLUS_SYSTEM, 36 | requiresDependencyResolution = ResolutionScope.RUNTIME_PLUS_SYSTEM 37 | ) 38 | public class WeaveMojo extends AbstractWeaveMojo { 39 | 40 | /** 41 | * {@link Build#getOutputDirectory()}. 42 | */ 43 | @Parameter(readonly = true, required = true, defaultValue = "${project.build.outputDirectory}") 44 | protected File target; 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | @Override 50 | protected File getTarget() { 51 | return target; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /maven-plugin/src/main/java/org/apache/commons/weaver/maven/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Integration with Apache Maven. 20 | */ 21 | package org.apache.commons.weaver.maven; -------------------------------------------------------------------------------- /maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | prepare 26 | test-prepare 27 | 28 | 29 | 30 | 31 | true 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | weave 40 | test-weave 41 | 42 | 43 | 44 | 45 | true 46 | false 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /maven-plugin/src/site/resources/japicmp-post-analysis.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | def it = jApiClasses.iterator() 21 | while (it.hasNext()) { 22 | def jApiClass = it.next() 23 | // look for false positive on introduced superclass level 24 | def jApiSuperclass = jApiClass.getSuperclass() 25 | def newSuper = jApiSuperclass.getNewSuperclassName() 26 | if (newSuper.isPresent() && newSuper.get().endsWith(".AbstractCWMojo")) { 27 | jApiSuperclass.getCompatibilityChanges().clear(); 28 | } 29 | } 30 | return jApiClasses 31 | -------------------------------------------------------------------------------- /maven-plugin/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /modules/normalizer/src/it/sample/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.commons.lang3.reflect.TypeLiteral, 44 | org.apache.commons.weaver.normalizer.example.ContrivedWrapper 45 | 46 | org.apache.commons.weaver.normalizer.example.normalized 47 | 48 | 49 | 50 | 51 | 52 | 53 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /modules/normalizer/src/it/sample/src/main/java/org/apache/commons/weaver/normalizer/example/ContrivedWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.normalizer.example; 20 | 21 | public abstract class ContrivedWrapper { 22 | public final Object value; 23 | 24 | protected ContrivedWrapper(Object value) { 25 | this.value = value; 26 | } 27 | 28 | protected ContrivedWrapper(int value) { 29 | this.value = Integer.valueOf(value); 30 | } 31 | 32 | @Override 33 | public final boolean equals(Object obj) { 34 | if (obj == this) { 35 | return true; 36 | } 37 | if (!(obj instanceof ContrivedWrapper)) { 38 | return false; 39 | } 40 | final ContrivedWrapper other = (ContrivedWrapper) obj; 41 | return value.equals(other.value); 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return 41 << 4 | value.hashCode(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /modules/normalizer/src/it/sample/src/main/java/org/apache/commons/weaver/normalizer/example/InstanceMembers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.normalizer.example; 20 | 21 | import org.apache.commons.lang3.reflect.TypeLiteral; 22 | 23 | public class InstanceMembers { 24 | public final TypeLiteral stringType = new TypeLiteral() { }; 25 | public final TypeLiteral stringType2 = new TypeLiteral() { }; 26 | public final TypeLiteral> integerIterableType = new TypeLiteral>() { }; 27 | 28 | public final ContrivedWrapper wrappedObject = new ContrivedWrapper(new Object()) { }; 29 | public final ContrivedWrapper wrappedString = new ContrivedWrapper("foo") { }; 30 | public final ContrivedWrapper wrappedString2 = new ContrivedWrapper("foo") { }; 31 | public final ContrivedWrapper wrappedInteger = new ContrivedWrapper(Integer.valueOf(1)) { }; 32 | public final ContrivedWrapper wrappedInt = new ContrivedWrapper(1) { }; 33 | } 34 | -------------------------------------------------------------------------------- /modules/normalizer/src/it/sample/src/main/java/org/apache/commons/weaver/normalizer/example/StaticMembers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.normalizer.example; 20 | 21 | import org.apache.commons.lang3.reflect.TypeLiteral; 22 | 23 | public final class StaticMembers { 24 | private StaticMembers() { 25 | } 26 | 27 | public static final TypeLiteral STRING_TYPE = new TypeLiteral() { }; 28 | public static final TypeLiteral STRING_TYPE2 = new TypeLiteral() { }; 29 | public static final TypeLiteral> INTEGER_ITERABLE_TYPE = new TypeLiteral>() { }; 30 | 31 | public static final ContrivedWrapper WRAPPED_OBJECT = new ContrivedWrapper(new Object()) { }; 32 | public static final ContrivedWrapper WRAPPED_STRING = new ContrivedWrapper("foo") { }; 33 | public static final ContrivedWrapper WRAPPED_STRING2 = new ContrivedWrapper("foo") { }; 34 | public static final ContrivedWrapper WRAPPED_INTEGER = new ContrivedWrapper(Integer.valueOf(1)) { }; 35 | public static final ContrivedWrapper WRAPPED_INT = new ContrivedWrapper(1) { }; 36 | } 37 | -------------------------------------------------------------------------------- /modules/normalizer/src/main/java/org/apache/commons/weaver/normalizer/NormalizerWeaver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.normalizer; 20 | 21 | import org.apache.commons.weaver.model.Scanner; 22 | import org.apache.commons.weaver.model.WeaveEnvironment; 23 | import org.apache.commons.weaver.spi.Weaver; 24 | 25 | /** 26 | * The purpose of the normalizer module is to merge identical anonymous class definitions into a single type, thereby 27 | * "normalizing" them and reducing their collective footprint on your archive and more importantly on your JVM. 28 | */ 29 | public class NormalizerWeaver implements Weaver { 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public boolean process(final WeaveEnvironment environment, final Scanner scanner) { 36 | return new Normalizer(environment).normalize(scanner); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modules/normalizer/src/main/java/org/apache/commons/weaver/normalizer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Implements the Normalizer weaver, whose purpose is to collapse identical 20 | * anonymous class definitions into a single one. 21 | */ 22 | package org.apache.commons.weaver.normalizer; -------------------------------------------------------------------------------- /modules/normalizer/src/main/resources/META-INF/services/org.apache.commons.weaver.spi.Weaver: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # this class gets picked up by the WeaveProcessor 19 | org.apache.commons.weaver.normalizer.NormalizerWeaver 20 | -------------------------------------------------------------------------------- /modules/normalizer/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | ## Apache Commons Weaver Normalizer 21 | 22 | The Normalizer module merges identical anonymous class definitions into 23 | a single type, thereby "normalizing" them and reducing their 24 | collective footprint on your archive and more importantly on your JVM. 25 | 26 | Considers only the simplest case in which: 27 | 28 | - no methods are implemented 29 | 30 | - the constructor only calls the super constructor 31 | 32 | An anonymous class which violates these restrictions will be considered 33 | too complex and skipped in the interest of correctness. 34 | 35 | 36 | ### Configuration 37 | The [NormalizerWeaver][normalizerWeaver] supports the following options: 38 | 39 | - `normalizer.superTypes` : comma-delimited list of types whose 40 | subclasses/implementations should be normalized, e.g. 41 | `javax.enterprise.util.TypeLiteral`. 42 | 43 | - `normalizer.targetPackage` : package to which merged types should be added. 44 | 45 | 46 | [normalizerWeaver]: ../../../apidocs/org/apache/commons/weaver/normalizer/NormalizerWeaver.html 47 | -------------------------------------------------------------------------------- /modules/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | commons-weaver-parent 24 | org.apache.commons 25 | 2.1-SNAPSHOT 26 | ../parent/pom.xml 27 | 28 | 29 | commons-weaver-modules-parent 30 | pom 31 | 32 | Apache Commons Weaver Modules aggregator project 33 | Hosts weaver modules. 34 | 35 | 36 | privilizer 37 | normalizer 38 | 39 | 40 | -------------------------------------------------------------------------------- /modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privileged.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Marks a method as needing to execute in a privileged fashion in secured 28 | * environments. 29 | */ 30 | @Target(ElementType.METHOD) 31 | @Retention(RetentionPolicy.CLASS) 32 | public @interface Privileged { 33 | } 34 | -------------------------------------------------------------------------------- /modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that a certain set of method calls should be "blueprint privilized," i.e., 26 | * their method bodies should be (recursively) copied for privileged invocation 27 | * per the privilizer policy with which the blueprint privilizer weaver is invoked. 28 | */ 29 | @Target(ElementType.TYPE) 30 | public @interface Privilizing { 31 | /** 32 | * Models calls to blueprint methods defined on a specific class. 33 | */ 34 | @interface CallTo { 35 | /** 36 | * The class owning one or more blueprint method. 37 | * @return {@link Class} 38 | */ 39 | Class value(); 40 | 41 | /** 42 | * The names of the blueprint methods. 43 | * @return {@link String}[] 44 | */ 45 | String[] methods() default { }; 46 | } 47 | 48 | /** 49 | * List of blueprint calls. 50 | * @return {@link CallTo}[] 51 | */ 52 | CallTo[] value(); 53 | } 54 | -------------------------------------------------------------------------------- /modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Defines the annotations that drive the privilizer weaver. 20 | */ 21 | package org.apache.commons.weaver.privilizer; -------------------------------------------------------------------------------- /modules/privilizer/api/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /modules/privilizer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.apache.commons 25 | commons-weaver-modules-parent 26 | 2.1-SNAPSHOT 27 | 28 | 29 | commons-weaver-privilizer-parent 30 | pom 31 | 32 | Apache Commons Weaver Privilizer Parent POM 33 | 34 | 35 | Privilizer provides machinery to automate the handling of Java Security access controls in code. 36 | 37 | 38 | 39 | api 40 | weaver 41 | 42 | 43 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/invoker.properties: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | // 18 | 19 | invoker.goals=clean install 20 | invoker.profiles.2=sec 21 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/MethodReferencesUsingBlueprints.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import java.util.function.BiFunction; 22 | import java.util.function.BinaryOperator; 23 | import java.util.function.IntSupplier; 24 | import java.util.function.Supplier; 25 | import java.util.function.UnaryOperator; 26 | 27 | import org.apache.commons.weaver.privilizer.Privilizing; 28 | import org.apache.commons.weaver.privilizer.Privilizing.CallTo; 29 | 30 | @Privilizing({ @CallTo(Utils.class), @CallTo(value = Utils.More.class, methods = "getProperty") }) 31 | public class MethodReferencesUsingBlueprints { 32 | 33 | public String utilsReadPublicConstant() { 34 | final Supplier s = Utils::readPublicConstant; 35 | return s.get(); 36 | } 37 | 38 | public int utilsReadPrivateField() { 39 | final IntSupplier s = Utils::readPrivateField; 40 | return s.getAsInt(); 41 | } 42 | 43 | public String utilsGetProperty() { 44 | final Supplier s = Utils::getProperty; 45 | return s.get(); 46 | } 47 | 48 | public String utilsGetProperty(int i, String key) { 49 | final BiFunction f = Utils::getProperty; 50 | return f.apply(i, key); 51 | } 52 | 53 | public String utilsGetProperty(String key) { 54 | final UnaryOperator o = Utils::getProperty; 55 | return o.apply(key); 56 | } 57 | 58 | public String moreGetProperty() { 59 | final Supplier s = Utils.More::getProperty; 60 | return s.get(); 61 | } 62 | 63 | public String moreGetTopStackElementClassName() { 64 | final Supplier s = Utils.More::getTopStackElementClassName; 65 | return s.get(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/NoArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privileged; 22 | 23 | public class NoArgs { 24 | 25 | @Privileged 26 | void throwAwayFoo() { 27 | System.getProperty("foo"); 28 | } 29 | 30 | @Privileged 31 | String getFoo() { 32 | return System.getProperty("foo"); 33 | } 34 | 35 | @Privileged 36 | Boolean getTrue() { 37 | System.getProperty("foo"); 38 | return Boolean.TRUE; 39 | } 40 | 41 | @Privileged 42 | boolean getFalse() { 43 | System.getProperty("foo"); 44 | return false; 45 | } 46 | 47 | public static class CheckedException1 extends Exception { 48 | private static final long serialVersionUID = 1L; 49 | } 50 | 51 | public static class CheckedException2 extends Exception { 52 | private static final long serialVersionUID = 1L; 53 | } 54 | 55 | @Privileged 56 | void throwingCheckedException1() throws CheckedException1 { 57 | System.getProperty("foo"); 58 | throw new CheckedException1(); 59 | } 60 | 61 | @Privileged 62 | Integer throwingCheckedException2() throws CheckedException1, CheckedException2 { 63 | System.getProperty("foo"); 64 | throw new CheckedException2(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/Overloading.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privileged; 22 | 23 | public class Overloading { 24 | 25 | @Privileged 26 | String get() { 27 | return System.getProperty("foo"); 28 | } 29 | 30 | @Privileged 31 | String get(String s) { 32 | return System.getProperty(s); 33 | } 34 | 35 | @Privileged 36 | String get(int i, char c, short s) { 37 | return System.getProperty(new String(new char[] { (char) i, c, (char) s })); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/PrivateMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privileged; 22 | 23 | public class PrivateMethods { 24 | public String get(String s) { 25 | return getProperty(s); 26 | } 27 | 28 | @Privileged 29 | private String getProperty(String s) { 30 | return System.getProperty(s); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/Setup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.commons.weaver.privilizer.example; 17 | 18 | import java.security.AccessController; 19 | import java.security.PrivilegedAction; 20 | 21 | final class Setup { 22 | private Setup() { 23 | } 24 | 25 | /** 26 | * This simply allows us to set up test classes by doing 27 | * privileged things without granting privileges to the test 28 | * code itself and thus making it impossible to test the effects 29 | * of privilization. 30 | */ 31 | public static void setProperty(final String name, final String value) { 32 | AccessController.doPrivileged(new PrivilegedAction() { 33 | public Void run() { 34 | System.setProperty(name, value); 35 | return null; 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/StaticNoArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privileged; 22 | 23 | public abstract class StaticNoArgs { 24 | private StaticNoArgs() { 25 | } 26 | 27 | @Privileged 28 | static void throwAwayFoo() { 29 | System.getProperty("foo"); 30 | } 31 | 32 | @Privileged 33 | static String getFoo() { 34 | return System.getProperty("foo"); 35 | } 36 | 37 | @Privileged 38 | static Boolean getTrue() { 39 | System.getProperty("foo"); 40 | return Boolean.TRUE; 41 | } 42 | 43 | @Privileged 44 | static boolean getFalse() { 45 | System.getProperty("foo"); 46 | return false; 47 | } 48 | 49 | public static class CheckedException1 extends Exception { 50 | private static final long serialVersionUID = 1L; 51 | } 52 | 53 | public static class CheckedException2 extends Exception { 54 | private static final long serialVersionUID = 1L; 55 | } 56 | 57 | @Privileged 58 | static void throwingCheckedException1() throws CheckedException1 { 59 | System.getProperty("foo"); 60 | throw new CheckedException1(); 61 | } 62 | 63 | @Privileged 64 | static Integer throwingCheckedException2() throws CheckedException1, CheckedException2 { 65 | System.getProperty("foo"); 66 | throw new CheckedException2(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/StaticOverloading.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privileged; 22 | 23 | public abstract class StaticOverloading { 24 | private StaticOverloading() { 25 | } 26 | 27 | @Privileged 28 | static String get() { 29 | return System.getProperty("foo"); 30 | } 31 | 32 | @Privileged 33 | static String get(String s) { 34 | return System.getProperty(s); 35 | } 36 | 37 | @Privileged 38 | static String get(int i, char c, short s) { 39 | return System.getProperty(new String(new char[] { (char) i, c, (char) s })); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privileged; 22 | 23 | public abstract class StaticPrivateMethods { 24 | private StaticPrivateMethods() { 25 | } 26 | 27 | public static String get(String s) { 28 | return getProperty(s); 29 | } 30 | 31 | @Privileged 32 | private static String getProperty(String s) { 33 | return System.getProperty(s); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import java.util.ArrayList; 22 | 23 | import org.apache.commons.lang3.ArrayUtils; 24 | import org.apache.commons.weaver.privilizer.Privileged; 25 | 26 | public abstract class StaticUsingArgs { 27 | 28 | private StaticUsingArgs() { 29 | } 30 | 31 | @Privileged 32 | static String getProperty(String name) { 33 | return System.getProperty(name); 34 | } 35 | 36 | @Privileged 37 | static String[] getProperties(String... names) { 38 | if (names == null) { 39 | return null; 40 | } 41 | final ArrayList result = new ArrayList(); 42 | // in reality one would delegate to #getProperty to minimize the scope 43 | // of the privileged action 44 | for (String name : names) { 45 | result.add(System.getProperty(name)); 46 | } 47 | return result.toArray(ArrayUtils.EMPTY_STRING_ARRAY); 48 | } 49 | 50 | @Privileged 51 | static void throwAwayProperty(int first, String middle, char last) { 52 | System.getProperty(new StringBuilder().append((char) first).append(middle).append(last).toString()); 53 | } 54 | 55 | @Privileged 56 | static Object assembleAndGetProperty(char first, CharSequence middle, int last) { 57 | return System.getProperty(new StringBuilder().append(first).append(middle).append((char) last).toString()); 58 | } 59 | 60 | public static class CheckedException1 extends Exception { 61 | private static final long serialVersionUID = 1L; 62 | } 63 | 64 | public static class CheckedException2 extends Exception { 65 | private static final long serialVersionUID = 1L; 66 | } 67 | 68 | @Privileged 69 | static int throwingCheckedException(int which, String propertyToGet) throws CheckedException1, CheckedException2 { 70 | System.getProperty(propertyToGet); 71 | switch (which) { 72 | case 1: 73 | throw new CheckedException1(); 74 | case 2: 75 | throw new CheckedException2(); 76 | default: 77 | return which; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/UsingArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import java.util.ArrayList; 22 | 23 | import org.apache.commons.lang3.ArrayUtils; 24 | import org.apache.commons.weaver.privilizer.Privileged; 25 | 26 | public class UsingArgs { 27 | 28 | @Privileged 29 | String getProperty(String name) { 30 | return System.getProperty(name); 31 | } 32 | 33 | @Privileged 34 | String[] getProperties(String... names) { 35 | if (names == null) { 36 | return null; 37 | } 38 | final ArrayList result = new ArrayList(); 39 | // in reality one would delegate to #getProperty to minimize the scope 40 | // of the privileged action 41 | for (String name : names) { 42 | result.add(System.getProperty(name)); 43 | } 44 | return result.toArray(ArrayUtils.EMPTY_STRING_ARRAY); 45 | } 46 | 47 | @Privileged 48 | void throwAwayProperty(int first, String middle, char last) { 49 | System.getProperty(new StringBuilder().append((char) first).append(middle).append(last).toString()); 50 | } 51 | 52 | @Privileged 53 | Object assembleAndGetProperty(char first, CharSequence middle, int last) { 54 | return System.getProperty(new StringBuilder().append(first).append(middle).append((char) last).toString()); 55 | } 56 | 57 | public static class CheckedException1 extends Exception { 58 | private static final long serialVersionUID = 1L; 59 | } 60 | 61 | public static class CheckedException2 extends Exception { 62 | private static final long serialVersionUID = 1L; 63 | } 64 | 65 | @Privileged 66 | int throwingCheckedException(int which, String propertyToGet) throws CheckedException1, CheckedException2 { 67 | System.getProperty(propertyToGet); 68 | switch (which) { 69 | case 1: 70 | throw new CheckedException1(); 71 | case 2: 72 | throw new CheckedException2(); 73 | default: 74 | return which; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import org.apache.commons.weaver.privilizer.Privilizing; 22 | import org.apache.commons.weaver.privilizer.Privilizing.CallTo; 23 | 24 | @Privilizing({ @CallTo(Utils.class), @CallTo(value = Utils.More.class, methods = "getProperty") }) 25 | public class UsingBlueprints { 26 | 27 | public String utilsReadPublicConstant() { 28 | return Utils.readPublicConstant(); 29 | } 30 | 31 | public int utilsReadPrivateField() { 32 | return Utils.readPrivateField(); 33 | } 34 | 35 | public String utilsGetProperty() { 36 | return Utils.getProperty(); 37 | } 38 | 39 | public String utilsGetProperty(int i, String key) { 40 | return Utils.getProperty(i, key); 41 | } 42 | 43 | public String utilsGetProperty(String key) { 44 | return Utils.getProperty(key); 45 | } 46 | 47 | public String moreGetProperty() { 48 | return Utils.More.getProperty(); 49 | } 50 | 51 | public String moreGetTopStackElementClassName() { 52 | return Utils.More.getTopStackElementClassName(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | public final class Utils { 22 | public static final class More { 23 | private More() { 24 | } 25 | 26 | public static String getProperty() { 27 | return Utils.getProperty("bar"); 28 | } 29 | 30 | public static String getTopStackElementClassName() { 31 | return Thread.currentThread().getStackTrace()[1].getClassName(); 32 | } 33 | } 34 | 35 | private Utils() { 36 | } 37 | 38 | public static final String FOO = "foo".intern(); 39 | 40 | public static String readPublicConstant() { 41 | return FOO; 42 | } 43 | 44 | public static String getProperty() { 45 | return getProperty("foo"); 46 | } 47 | 48 | public static String getProperty(int i, String key) { 49 | if (i <= 0) { 50 | return getProperty(key); 51 | } 52 | int counter = i; 53 | return getProperty(--counter, key); 54 | } 55 | 56 | public static String getProperty(String key) { 57 | return System.getProperty(key); 58 | } 59 | 60 | private static Integer n; 61 | static { 62 | n = Integer.valueOf(999); 63 | } 64 | 65 | public static int readPrivateField() { 66 | return n; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertFalse; 23 | import static org.junit.Assert.assertSame; 24 | import static org.junit.Assert.fail; 25 | 26 | import org.apache.commons.weaver.privilizer.example.NoArgs.CheckedException1; 27 | import org.apache.commons.weaver.privilizer.example.NoArgs.CheckedException2; 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | 31 | public class NoArgsTest { 32 | private NoArgs noArgs; 33 | 34 | @Before 35 | public void setUp() throws Exception { 36 | Setup.setProperty("foo", "foo-value"); 37 | noArgs = new NoArgs(); 38 | } 39 | 40 | @Test 41 | public void testThrowAwayFoo() { 42 | noArgs.throwAwayFoo(); 43 | } 44 | 45 | @Test 46 | public void testGetFoo() { 47 | assertEquals("foo-value", noArgs.getFoo()); 48 | } 49 | 50 | @Test 51 | public void testGetTrue() { 52 | assertSame(Boolean.TRUE, noArgs.getTrue()); 53 | } 54 | 55 | @Test 56 | public void testGetFalse() { 57 | assertFalse(noArgs.getFalse()); 58 | } 59 | 60 | @Test 61 | public void testThrowingCheckedException1() { 62 | try { 63 | noArgs.throwingCheckedException1(); 64 | fail(); 65 | } catch (CheckedException1 e) { 66 | } 67 | } 68 | 69 | @Test 70 | public void testThrowingCheckedException2() { 71 | try { 72 | noArgs.throwingCheckedException2(); 73 | } catch (CheckedException1 e) { 74 | } catch (CheckedException2 e) { 75 | return; 76 | } 77 | fail(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | public class OverloadingTest { 27 | private Overloading overloading; 28 | 29 | @Before 30 | public void setUp() throws Exception { 31 | Setup.setProperty("foo", "foo-value"); 32 | Setup.setProperty("bar", "bar-value"); 33 | Setup.setProperty("baz", "baz-value"); 34 | overloading = new Overloading(); 35 | } 36 | 37 | @Test 38 | public void testNoArgs() { 39 | assertEquals("foo-value", overloading.get()); 40 | } 41 | 42 | @Test 43 | public void testStringArg() { 44 | assertEquals("bar-value", overloading.get("bar")); 45 | } 46 | 47 | @Test 48 | public void testCharishArgs() { 49 | assertEquals("baz-value", overloading.get('b', 'a', (short) 'z')); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | public class PrivateMethodsTest { 27 | private PrivateMethods privateMethods; 28 | 29 | @Before 30 | public void setUp() throws Exception { 31 | Setup.setProperty("foo", "foo-value"); 32 | Setup.setProperty("bar", "bar-value"); 33 | Setup.setProperty("baz", "baz-value"); 34 | privateMethods = new PrivateMethods(); 35 | } 36 | 37 | @Test 38 | public void testGet() { 39 | assertEquals("foo-value", privateMethods.get("foo")); 40 | assertEquals("bar-value", privateMethods.get("bar")); 41 | assertEquals("baz-value", privateMethods.get("baz")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertFalse; 23 | import static org.junit.Assert.assertSame; 24 | import static org.junit.Assert.fail; 25 | 26 | import org.apache.commons.weaver.privilizer.example.StaticNoArgs.CheckedException1; 27 | import org.apache.commons.weaver.privilizer.example.StaticNoArgs.CheckedException2; 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | 31 | public class StaticNoArgsTest { 32 | @Before 33 | public void setUp() throws Exception { 34 | Setup.setProperty("foo", "foo-value"); 35 | } 36 | 37 | @Test 38 | public void testThrowAwayFoo() { 39 | StaticNoArgs.throwAwayFoo(); 40 | } 41 | 42 | @Test 43 | public void testGetFoo() { 44 | assertEquals("foo-value", StaticNoArgs.getFoo()); 45 | } 46 | 47 | @Test 48 | public void testGetTrue() { 49 | assertSame(Boolean.TRUE, StaticNoArgs.getTrue()); 50 | } 51 | 52 | @Test 53 | public void testGetFalse() { 54 | assertFalse(StaticNoArgs.getFalse()); 55 | } 56 | 57 | @Test 58 | public void testThrowingCheckedException1() { 59 | try { 60 | StaticNoArgs.throwingCheckedException1(); 61 | fail(); 62 | } catch (CheckedException1 e) { 63 | } 64 | } 65 | 66 | @Test 67 | public void testThrowingCheckedException2() { 68 | try { 69 | StaticNoArgs.throwingCheckedException2(); 70 | } catch (CheckedException1 e) { 71 | } catch (CheckedException2 e) { 72 | return; 73 | } 74 | fail(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | public class StaticOverloadingTest { 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | Setup.setProperty("foo", "foo-value"); 31 | Setup.setProperty("bar", "bar-value"); 32 | Setup.setProperty("baz", "baz-value"); 33 | } 34 | 35 | @Test 36 | public void testNoArgs() { 37 | assertEquals("foo-value", StaticOverloading.get()); 38 | } 39 | 40 | @Test 41 | public void testStringArg() { 42 | assertEquals("bar-value", StaticOverloading.get("bar")); 43 | } 44 | 45 | @Test 46 | public void testCharishArgs() { 47 | assertEquals("baz-value", StaticOverloading.get('b', 'a', (short) 'z')); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer.example; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | public class StaticPrivateMethodsTest { 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | Setup.setProperty("foo", "foo-value"); 31 | Setup.setProperty("bar", "bar-value"); 32 | Setup.setProperty("baz", "baz-value"); 33 | } 34 | 35 | @Test 36 | public void testGet() { 37 | assertEquals("foo-value", StaticPrivateMethods.get("foo")); 38 | assertEquals("bar-value", StaticPrivateMethods.get("bar")); 39 | assertEquals("baz-value", StaticPrivateMethods.get("baz")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/sample/src/test/resources/java.policy: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | // 18 | // Allows unit tests to run with a Java Security Manager 19 | // 20 | 21 | grant 22 | { 23 | // let everyone read target dir 24 | permission java.io.FilePermission "${preserve.project.build.directory}${/}-", "read"; 25 | }; 26 | 27 | // we don't care about the permissions of the testing infrastructure, 28 | // including maven; 29 | grant codeBase "file://${local-repo}/org/apache/maven/-" 30 | { 31 | permission java.security.AllPermission; 32 | }; 33 | 34 | // junit; 35 | grant codeBase "file://${local-repo}/junit/-" 36 | { 37 | permission java.security.AllPermission; 38 | }; 39 | 40 | // surefire booter; 41 | grant codeBase "file://${project.build.directory}/surefire/-" 42 | { 43 | permission java.security.AllPermission; 44 | }; 45 | 46 | // classes under test 47 | grant codeBase "file://${project.build.outputDirectory}/-" 48 | { 49 | permission java.util.PropertyPermission "foo", "read,write"; 50 | permission java.util.PropertyPermission "bar", "read,write"; 51 | permission java.util.PropertyPermission "baz", "read,write"; 52 | permission java.lang.RuntimePermission "accessDeclaredMembers"; 53 | permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; 54 | }; 55 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/it/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | it-repo 26 | 27 | true 28 | 29 | 30 | 31 | local.central 32 | @localRepositoryUrl@ 33 | 34 | true 35 | 36 | 37 | true 38 | 39 | 40 | 41 | 42 | 43 | local.central 44 | @localRepositoryUrl@ 45 | 46 | true 47 | 48 | 49 | true 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer; 20 | 21 | import java.util.Objects; 22 | 23 | import org.apache.commons.lang3.StringUtils; 24 | import org.apache.commons.lang3.Validate; 25 | import org.objectweb.asm.Type; 26 | 27 | /** 28 | * Represents a Java field. 29 | */ 30 | public class Field { 31 | /** 32 | * Access modifier. 33 | */ 34 | public final int access; 35 | 36 | /** 37 | * Field name. 38 | */ 39 | public final String name; 40 | 41 | /** 42 | * Field type. 43 | */ 44 | public final Type type; 45 | 46 | /** 47 | * Create a new {@link Field}. 48 | * @param access modifier 49 | * @param name of field 50 | * @param type of field 51 | */ 52 | public Field(final int access, final String name, final Type type) { 53 | this.access = access; 54 | this.name = Validate.notNull(name); 55 | this.type = Validate.notNull(type); 56 | } 57 | 58 | /** 59 | * Considers name and type. 60 | * @param obj to check for equality 61 | * @return whether equal 62 | */ 63 | @Override 64 | public boolean equals(final Object obj) { 65 | if (obj == this) { 66 | return true; 67 | } 68 | if (!(obj instanceof Field)) { 69 | return false; 70 | } 71 | final Field other = (Field) obj; 72 | return StringUtils.equals(other.name, name) && Objects.equals(other.type, type); 73 | } 74 | 75 | /** 76 | * Considers name and type. 77 | * @return hashCode 78 | */ 79 | @Override 80 | public int hashCode() { 81 | return Objects.hash(name, type); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer; 20 | 21 | import org.objectweb.asm.Type; 22 | 23 | /** 24 | * Models the action of accessing a field by extending {@link Field} with an 25 | * accessing type. 26 | */ 27 | public class FieldAccess extends Field { 28 | /** 29 | * {@link Type} from which field is accessed. 30 | */ 31 | public final Type owner; 32 | 33 | /** 34 | * Create a new {@link FieldAccess}. 35 | * @param access operation 36 | * @param owner {@link Type} from which field is accessed. 37 | * @param name of field 38 | * @param type of field 39 | */ 40 | public FieldAccess(final int access, final Type owner, final String name, final Type type) { 41 | super(access, name, type); 42 | this.owner = owner; 43 | } 44 | 45 | /** 46 | * Compare against {@code obj} for equality. 47 | * @param obj to compare 48 | * @return whether Objects are equal 49 | */ 50 | @Override 51 | public boolean equals(final Object obj) { 52 | if (obj == this) { 53 | return true; 54 | } 55 | if (!(obj instanceof FieldAccess)) { 56 | return false; 57 | } 58 | return super.equals(obj) && ((FieldAccess) obj).owner.equals(owner); 59 | } 60 | 61 | /** 62 | * Generate a hashCode. 63 | * @return int 64 | */ 65 | @Override 66 | public int hashCode() { 67 | final int result = super.hashCode() << 4; 68 | return result | owner.hashCode(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer; 20 | 21 | import java.security.PrivilegedAction; 22 | import java.util.Locale; 23 | 24 | import org.apache.commons.lang3.StringUtils; 25 | 26 | /** 27 | * Weaving policy: when to use {@link PrivilegedAction}s. 28 | */ 29 | public enum Policy { 30 | /** 31 | * Disables weaving. 32 | */ 33 | NEVER, 34 | 35 | /** 36 | * Weaves such that the check for an active {@link SecurityManager} is done once only. 37 | */ 38 | ON_INIT, 39 | 40 | /** 41 | * Weaves such that the check for an active {@link SecurityManager} is done for each {@link Privileged} method 42 | * execution. 43 | */ 44 | DYNAMIC, 45 | 46 | /** 47 | * Weaves such that {@link Privileged} methods are always executed as such. 48 | */ 49 | ALWAYS; 50 | 51 | /** 52 | * Gets the {@link Policy} value that should be used as a default. 53 | * @return {@link Policy#DYNAMIC} 54 | */ 55 | public static Policy defaultValue() { 56 | return DYNAMIC; 57 | } 58 | 59 | /** 60 | * Parse from a {@link String} returning {@link #defaultValue()} for blank/null input. 61 | * @param str to parse 62 | * @return {@link Policy} 63 | */ 64 | public static Policy parse(final String str) { 65 | if (StringUtils.isBlank(str)) { 66 | return defaultValue(); 67 | } 68 | return valueOf(str.trim().toUpperCase(Locale.US)); 69 | } 70 | 71 | /** 72 | * Learn whether this is a conditional {@link Policy}. 73 | * @return {@code this == ON_INIT || this == DYNAMIC} 74 | */ 75 | public boolean isConditional() { 76 | return this == ON_INIT || this == DYNAMIC; 77 | } 78 | } -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilized.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.privilizer; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Class-retention annotation to mark privilized classes. 26 | */ 27 | @Target(ElementType.TYPE) 28 | public @interface Privilized { 29 | /** 30 | * Name of {@link Policy} with which privilized weaving was performed. 31 | * @return {@link String} 32 | */ 33 | String value(); 34 | } -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Defines the Privilizer Weaver. 20 | */ 21 | package org.apache.commons.weaver.privilizer; 22 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/resources/META-INF/services/org.apache.commons.weaver.spi.Cleaner: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # this class gets picked up by the CleanProcessor 19 | org.apache.commons.weaver.privilizer.PrivilizerCleaner 20 | -------------------------------------------------------------------------------- /modules/privilizer/weaver/src/main/resources/META-INF/services/org.apache.commons.weaver.spi.Weaver: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # this class gets picked up by the WeaveProcessor 19 | org.apache.commons.weaver.privilizer.PrivilizerWeaver 20 | -------------------------------------------------------------------------------- /modules/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | ## Apache Commons Weaver Modules 21 | 22 | This is the parent Apache Maven module for the weaver modules provided 23 | with Apache Commons Weaver. See [Modules](modules.html). 24 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/CleanProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver; 20 | 21 | import java.io.File; 22 | import java.util.List; 23 | import java.util.Properties; 24 | import java.util.ServiceLoader; 25 | import java.util.logging.Logger; 26 | 27 | import org.apache.commons.weaver.lifecycle.WeaveLifecycle; //NOPMD used in Javadoc 28 | import org.apache.commons.weaver.model.WeaveEnvironment; 29 | import org.apache.commons.weaver.spi.Cleaner; 30 | 31 | /** 32 | * Implements {@link WeaveLifecycle#CLEAN}. 33 | */ 34 | public class CleanProcessor extends ProcessorBase { 35 | 36 | /** 37 | * Create a new {@link CleanProcessor} instance using the {@link ServiceLoader} mechanism. 38 | * 39 | * @param classpath not {@code null} 40 | * @param target not {@code null} 41 | * @param configuration not {@code null} 42 | */ 43 | public CleanProcessor(final List classpath, final File target, final Properties configuration) { 44 | this(classpath, target, configuration, getServiceInstances(Cleaner.class)); 45 | } 46 | 47 | /** 48 | * Create a new {@link CleanProcessor} instance. 49 | * 50 | * @param classpath not {@code null} 51 | * @param target not {@code null} 52 | * @param configuration not {@code null} 53 | * @param providers not (@code null} 54 | */ 55 | public CleanProcessor(final List classpath, final File target, final Properties configuration, 56 | final Iterable providers) { 57 | super(classpath, target, configuration, providers); 58 | } 59 | 60 | /** 61 | * Clean specified targets. 62 | */ 63 | public void clean() { 64 | if (!target.exists()) { 65 | log.warning(() -> String.format("Target directory %s does not exist; nothing to do!", target)); 66 | } 67 | for (final Cleaner cleaner : providers) { 68 | final WeaveEnvironment env = new LocalWeaveEnvironment(target, classLoader, configuration, 69 | Logger.getLogger(cleaner.getClass().getName())); 70 | cleaner.clean(env, finder); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/Consumes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Inherited; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | import org.apache.commons.weaver.spi.WeaveLifecycleProvider; 29 | 30 | /** 31 | * Mark a {@link WeaveLifecycleProvider} as consuming the output of additional 32 | * {@link WeaveLifecycleProvider}s for the same lifecycle stage. 33 | */ 34 | @Documented 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Target(ElementType.TYPE) 37 | @Inherited 38 | public @interface Consumes { 39 | /** 40 | * The consumed types. 41 | * @return array of {@link WeaveLifecycleProvider} subclasses 42 | */ 43 | Class>[] value(); 44 | } 45 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver; 20 | 21 | import java.io.File; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.io.OutputStream; 25 | import java.util.Properties; 26 | import java.util.logging.Logger; 27 | 28 | import org.apache.commons.lang3.Validate; 29 | import org.apache.commons.weaver.model.WeaveEnvironment; 30 | 31 | class LocalWeaveEnvironment extends WeaveEnvironment { 32 | 33 | private final File target; 34 | 35 | protected LocalWeaveEnvironment(final File target, final ClassLoader classLoader, final Properties config, 36 | final Logger log) { 37 | super(classLoader, config, log); 38 | Validate.notNull(target, "target"); 39 | this.target = target; 40 | } 41 | 42 | @Override 43 | public boolean deleteResource(final String name) { 44 | return new File(target, name).delete(); 45 | } 46 | 47 | @Override 48 | protected OutputStream getOutputStream(final String resourceName) throws IOException { 49 | final File file = new File(target, resourceName); 50 | final File parent = file.getParentFile(); 51 | if (parent.exists()) { 52 | Validate.validState(parent.isDirectory(), "Cannot write %s to non-directory parent", file); 53 | } else { 54 | Validate.validState(parent.mkdirs(), "Unable to create output directory %s", parent); 55 | } 56 | return new FileOutputStream(file); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/Produces.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Inherited; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | import org.apache.commons.weaver.spi.WeaveLifecycleProvider; 29 | 30 | /** 31 | * Mark a {@link WeaveLifecycleProvider} as creating output that is consumed by additional 32 | * {@link WeaveLifecycleProvider}s for the same lifecycle stage. 33 | */ 34 | @Documented 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Target(ElementType.TYPE) 37 | @Inherited 38 | public @interface Produces { 39 | /** 40 | * The consuming types. 41 | * @return array of {@link WeaveLifecycleProvider} subclasses 42 | */ 43 | Class>[] value(); 44 | } 45 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver; 20 | 21 | import java.io.File; 22 | import java.util.List; 23 | import java.util.Properties; 24 | import java.util.ServiceLoader; 25 | import java.util.logging.Logger; 26 | 27 | import org.apache.commons.weaver.lifecycle.WeaveLifecycle; //NOPMD used in Javadoc 28 | import org.apache.commons.weaver.model.WeaveEnvironment; 29 | import org.apache.commons.weaver.spi.Weaver; 30 | 31 | /** 32 | * Implements {@link WeaveLifecycle#WEAVE}. 33 | */ 34 | public class WeaveProcessor extends ProcessorBase { 35 | 36 | /** 37 | * Create a new {@link WeaveProcessor} instance using the {@link ServiceLoader} mechanism. 38 | * 39 | * @param classpath not {@code null} 40 | * @param target not {@code null} 41 | * @param configuration not {@code null} 42 | */ 43 | public WeaveProcessor(final List classpath, final File target, final Properties configuration) { 44 | super(classpath, target, configuration, getServiceInstances(Weaver.class)); 45 | } 46 | 47 | /** 48 | * Create a new {@link WeaveProcessor} instance. 49 | * 50 | * @param classpath not {@code null} 51 | * @param target not {@code null} 52 | * @param configuration not {@code null} 53 | * @param providers not (@code null} 54 | */ 55 | public WeaveProcessor(final List classpath, final File target, final Properties configuration, 56 | final Iterable providers) { 57 | super(classpath, target, configuration, providers); 58 | } 59 | 60 | /** 61 | * Weave classes in target directory. 62 | */ 63 | public void weave() { 64 | if (!target.exists()) { 65 | log.warning(() -> String.format("Target directory %s does not exist; nothing to do!", target)); 66 | } 67 | for (final Weaver weaver : providers) { 68 | final WeaveEnvironment env = new LocalWeaveEnvironment(target, classLoader, configuration, 69 | Logger.getLogger(weaver.getClass().getName())); 70 | weaver.process(env, finder); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/lifecycle/WeaveLifecycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.weaver.lifecycle; 21 | 22 | /** 23 | * Defines the parts of the weave lifecycle. 24 | * 25 | * @since 1.2 26 | */ 27 | public enum WeaveLifecycle { 28 | /** 29 | * Depicts the 'clean' stage of the lifecycle. 30 | */ 31 | CLEAN, 32 | 33 | /** 34 | * Depicts the 'weave' stage of the lifecycle. 35 | */ 36 | WEAVE; 37 | } 38 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/lifecycle/WeaveLifecycleToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.lifecycle; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Defines token classes corresponding to the elements of the {@link WeaveLifecycle}. 29 | * 30 | * @since 1.2 31 | */ 32 | public class WeaveLifecycleToken { 33 | /** 34 | * Declares the association between a {@link WeaveLifecycleToken} and an element of the {@link WeaveLifecycle}. 35 | */ 36 | @Documented 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | public @interface Represents { 40 | /** 41 | * The {@link WeaveLifecycle} stage represented by the annotated {@link WeaveLifecycleToken} type. 42 | * @return {@link WeaveLifecycle} 43 | */ 44 | WeaveLifecycle value(); 45 | } 46 | 47 | /** 48 | * Represents {@link WeaveLifecycle#CLEAN}. 49 | */ 50 | @Represents(WeaveLifecycle.CLEAN) 51 | public static final class Clean extends WeaveLifecycleToken { 52 | } 53 | 54 | /** 55 | * Represents {@link WeaveLifecycle#WEAVE}. 56 | */ 57 | @Represents(WeaveLifecycle.WEAVE) 58 | public static final class Weave extends WeaveLifecycleToken { 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/lifecycle/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * Weave lifecycle package. 22 | * @since 1.2 23 | */ 24 | package org.apache.commons.weaver.lifecycle; -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/AnnotatedElements.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.lang.annotation.RetentionPolicy; //NOPMD used in Javadoc 23 | import java.lang.reflect.AnnotatedElement; 24 | 25 | /** 26 | * Interface defining a means of iterating over a particular type of 27 | * {@link AnnotatedElement} as well as filtering by annotation type (including 28 | * annotations with {@link RetentionPolicy#CLASS} retention in addition to those 29 | * with {@link RetentionPolicy#RUNTIME} retention. 30 | * @param element type 31 | */ 32 | public interface AnnotatedElements extends Iterable { 33 | /** 34 | * Filter by annotation type. 35 | * @param annotationType filter 36 | * @return {@link AnnotatedElements}, narrowed 37 | */ 38 | AnnotatedElements with(Class annotationType); 39 | } 40 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/NestedWeavable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | /** 22 | * Describes a {@link Weavable} that lives inside some other {@link Weavable}. 23 | * @param own type 24 | * @param weavable target type 25 | * @param enclosing weavable type 26 | * @param parent target type 27 | */ 28 | public abstract class NestedWeavable 29 | , 30 | TARGET, 31 | PARENT extends Weavable, 32 | PARENT_TARGET> 33 | extends Weavable { 34 | 35 | private final PARENT parent; 36 | 37 | /** 38 | * Create a new {@link NestedWeavable} instance. 39 | * @param target element 40 | * @param parent enclosing 41 | */ 42 | protected NestedWeavable(final TARGET target, final PARENT parent) { 43 | super(target); 44 | this.parent = parent; 45 | } 46 | 47 | /** 48 | * Gets the parent. 49 | * @return {@code PARENT} 50 | */ 51 | public PARENT getParent() { 52 | return parent; 53 | } 54 | 55 | /** 56 | * Implement {@link Comparable}. 57 | * @param obj {@code SELF} 58 | * @return int per {@link Comparable#compareTo(Object)} contract 59 | */ 60 | @Override 61 | public final int compareTo(final SELF obj) { 62 | final int result = getParent().compareTo(obj.getParent()); 63 | return result == 0 ? localCompareTo(obj) : result; 64 | } 65 | 66 | /** 67 | * Compare against {@code o} without respect to {@link #getParent()}. 68 | * @param obj SELF{@code SELF} 69 | * @return int per {@link Comparable#compareTo(Object)} contract 70 | */ 71 | protected abstract int localCompareTo(SELF obj); 72 | } 73 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/Scanner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | /** 22 | * Scanner interface. 23 | */ 24 | public interface Scanner { 25 | 26 | /** 27 | * Perform the requested scan. 28 | * 29 | * @param request to process 30 | * @return {@link ScanResult} 31 | */ 32 | ScanResult scan(ScanRequest request); 33 | } 34 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavableConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.reflect.Constructor; 22 | 23 | /** 24 | * {@link Weavable} {@link Constructor}. 25 | * 26 | * @param type constructed 27 | */ 28 | public class WeavableConstructor extends 29 | WeavableExecutable, Constructor, T, WeavableConstructorParameter> { 30 | 31 | /** 32 | * Create a new {@link WeavableConstructor} instance. 33 | * @param target {@link Constructor} 34 | * @param parent enclosing {@link WeavableClass} 35 | */ 36 | public WeavableConstructor(final Constructor target, final WeavableClass parent) { 37 | super(target, parent); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | protected Class[] getParameterTypes() { 45 | return getTarget().getParameterTypes(); 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | protected WeavableConstructorParameter createParameter(final int index) { 53 | return new WeavableConstructorParameter<>(Integer.valueOf(index), this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavableConstructorParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.reflect.Constructor; 22 | 23 | /** 24 | * {@link Weavable} {@link Constructor} parameter. 25 | * 26 | * @param constructed type 27 | */ 28 | public class WeavableConstructorParameter extends 29 | WeavableParameter, WeavableConstructor, Constructor, T> { 30 | 31 | /** 32 | * Create a new {@link WeavableConstructorParameter} instance. 33 | * @param target parameter index 34 | * @param parent declaring {@link WeavableConstructor} 35 | */ 36 | public WeavableConstructorParameter(final Integer target, final WeavableConstructor parent) { 37 | super(target, parent); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavableField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.reflect.Field; 22 | 23 | /** 24 | * Represents a {@link Weavable} {@link Field}. 25 | * 26 | * @param enclosing type 27 | */ 28 | public class WeavableField extends NestedWeavable, Field, WeavableClass, Class> { 29 | 30 | /** 31 | * Create a new {@link WeavableField} instance. 32 | * @param target field 33 | * @param parent enclosing {@link WeavableClass} 34 | */ 35 | public WeavableField(final Field target, final WeavableClass parent) { 36 | super(target, parent); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | @Override 43 | protected int localCompareTo(final WeavableField obj) { 44 | return getTarget().getName().compareTo(obj.getTarget().getName()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavableMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | /** 24 | * Represents a {@link Weavable} {@link Method}. 25 | * 26 | * @param enclosing type 27 | */ 28 | public class WeavableMethod extends WeavableExecutable, Method, T, WeavableMethodParameter> { 29 | 30 | /** 31 | * Create a new {@link WeavableMethod} instance. 32 | * @param target method 33 | * @param parent enclosing {@link WeavableClass} 34 | */ 35 | public WeavableMethod(final Method target, final WeavableClass parent) { 36 | super(target, parent); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | @Override 43 | protected Class[] getParameterTypes() { 44 | return getTarget().getParameterTypes(); 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | protected int localCompareTo(final WeavableMethod obj) { 52 | final int result = getTarget().getName().compareTo(obj.getTarget().getName()); 53 | return result == 0 ? super.localCompareTo(obj) : result; 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | protected WeavableMethodParameter createParameter(final int index) { 61 | return new WeavableMethodParameter<>(Integer.valueOf(index), this); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavableMethodParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | /** 24 | * {@link Weavable} {@link Method} parameter. 25 | * 26 | * @param type of enclosing class 27 | */ 28 | public class WeavableMethodParameter extends 29 | WeavableParameter, WeavableMethod, Method, T> { 30 | 31 | /** 32 | * Create a new {@link WeavableMethodParameter} instance. 33 | * @param target index 34 | * @param parent declaring {@link WeavableMethod} 35 | */ 36 | public WeavableMethodParameter(final Integer target, final WeavableMethod parent) { 37 | super(target, parent); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavablePackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.util.Collections; 22 | import java.util.Comparator; 23 | import java.util.concurrent.ConcurrentNavigableMap; 24 | import java.util.concurrent.ConcurrentSkipListMap; 25 | 26 | /** 27 | * {@link Weavable} {@link Package}. 28 | */ 29 | public class WeavablePackage extends Weavable { 30 | private static final Comparator CMP = Comparator.nullsFirst(Comparator 31 | .comparing(WeavablePackage::getTarget, Comparator.nullsFirst(Comparator.comparing(Package::getName)))); 32 | 33 | private final ConcurrentNavigableMap> clazzes = new ConcurrentSkipListMap<>(); 34 | 35 | /** 36 | * Create a new {@link WeavablePackage} instance. 37 | * @param target package 38 | */ 39 | public WeavablePackage(final Package target) { 40 | super(target); 41 | } 42 | 43 | /** 44 | * Gets a {@link WeavableClass} representing {@code cls}. 45 | * @param cls to wrap 46 | * @param generic type of {@code cls} 47 | * @return {@link WeavableClass} 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public synchronized WeavableClass getWeavable(final Class cls) { 51 | return (WeavableClass) clazzes.computeIfAbsent(cls.getName(), k -> new WeavableClass<>(cls, this)); 52 | } 53 | 54 | /** 55 | * Gets enclosed {@link WeavableClass}es. 56 | * @return {@link Iterable} 57 | */ 58 | public Iterable> getClasses() { 59 | return Collections.unmodifiableCollection(clazzes.values()); 60 | } 61 | 62 | /** 63 | * Implement {@link Comparable}. 64 | * @param arg0 {@link WeavablePackage} to compare against 65 | * @return int per {@link Comparable#compareTo(Object)} contract 66 | */ 67 | @Override 68 | public int compareTo(final WeavablePackage arg0) { 69 | return CMP.compare(this, arg0); 70 | } 71 | 72 | /** 73 | * {@inheritDoc} 74 | */ 75 | @Override 76 | public String toString() { 77 | if (getTarget() == null) { 78 | return "Weavable default package"; 79 | } 80 | return super.toString(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeavableParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.model; 20 | 21 | import java.lang.reflect.Member; 22 | 23 | /** 24 | * Represents the parameter of an executable. 25 | * 26 | * @param own type 27 | * @param {@link WeavableExecutable} type 28 | * @param target executable of parent 29 | * @param executable's owning type 30 | */ 31 | public abstract class WeavableParameter 32 | , 33 | PARENT extends WeavableExecutable, 34 | PARENT_TARGET extends Member, 35 | T> 36 | extends NestedWeavable { 37 | 38 | /** 39 | * Create a new {@link WeavableParameter} instance. 40 | * @param target index 41 | * @param parent executable 42 | */ 43 | protected WeavableParameter(final Integer target, final PARENT parent) { 44 | super(target, parent); 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | protected int localCompareTo(final SELF obj) { 52 | return getTarget().compareTo(getTarget()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/WeaveInterest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.weaver.model; 21 | 22 | import java.lang.annotation.Annotation; 23 | import java.lang.annotation.ElementType; 24 | 25 | /** 26 | * Weave interest composed of annotation type and target element type. 27 | */ 28 | public final class WeaveInterest { 29 | 30 | /** 31 | * Gets a {@link WeaveInterest}. 32 | * @param annotationType observed annotation type 33 | * @param target attached element type 34 | * @return {@link WeaveInterest} 35 | */ 36 | public static WeaveInterest of(final Class annotationType, final ElementType target) { 37 | return new WeaveInterest(annotationType, target); 38 | } 39 | 40 | /** 41 | * Observed annotation type. 42 | */ 43 | public final Class annotationType; 44 | 45 | /** 46 | * Attached element type. 47 | */ 48 | public final ElementType target; 49 | 50 | private WeaveInterest(final Class annotationType, final ElementType target) { 51 | this.annotationType = annotationType; 52 | this.target = target; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/model/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Defines a domain model for weaving operations. 20 | */ 21 | package org.apache.commons.weaver.model; -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Defines the objects needed to perform file system-based weaving. 20 | */ 21 | package org.apache.commons.weaver; -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/spi/Cleaner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.spi; 20 | 21 | import org.apache.commons.weaver.lifecycle.WeaveLifecycle; 22 | import org.apache.commons.weaver.lifecycle.WeaveLifecycleToken.Clean; 23 | import org.apache.commons.weaver.model.Scanner; 24 | import org.apache.commons.weaver.model.WeaveEnvironment; 25 | 26 | /** 27 | * SPI to provide a means for a weaver module to remove woven classes during incremental builds, if necessary. 28 | * Implements the {@code CLEAN} stage of the {@link WeaveLifecycle}. 29 | */ 30 | public interface Cleaner extends WeaveLifecycleProvider { 31 | /** 32 | * Using the supplied {@link Scanner}, clean a {@link WeaveEnvironment}. 33 | * 34 | * @param environment to use 35 | * @param scanner to use 36 | * @return whether any work was done. 37 | */ 38 | boolean clean(WeaveEnvironment environment, Scanner scanner); 39 | } 40 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/spi/WeaveLifecycleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.spi; 20 | 21 | import org.apache.commons.weaver.lifecycle.WeaveLifecycle; //NOPMD used in Javadoc 22 | import org.apache.commons.weaver.lifecycle.WeaveLifecycleToken; 23 | 24 | /** 25 | * Marker interface for commons-weaver lifecycle providers. 26 | * @param indicates a stage of the {@link WeaveLifecycle} 27 | * @since 1.2 28 | */ 29 | public interface WeaveLifecycleProvider { 30 | } 31 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.spi; 20 | 21 | import org.apache.commons.weaver.lifecycle.WeaveLifecycle; 22 | import org.apache.commons.weaver.lifecycle.WeaveLifecycleToken.Weave; 23 | import org.apache.commons.weaver.model.Scanner; 24 | import org.apache.commons.weaver.model.WeaveEnvironment; 25 | 26 | /** 27 | * A {@link Weaver} implementation implements the {@code WEAVE} stage of the {@link WeaveLifecycle} by performing the 28 | * byte code enhancement in the classes. 29 | */ 30 | public interface Weaver extends WeaveLifecycleProvider { 31 | /** 32 | * Using the supplied {@link Scanner}, process a {@link WeaveEnvironment}. 33 | * 34 | * @param environment to use 35 | * @param scanner to use 36 | * @return whether any work was done. 37 | */ 38 | boolean process(WeaveEnvironment environment, Scanner scanner); 39 | } 40 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Defines the weaver module service provider interface (SPI). 20 | */ 21 | package org.apache.commons.weaver.spi; -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/utils/Args.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.utils; 20 | 21 | /** 22 | * Argument/Parameter-related utilities. 23 | */ 24 | public final class Args { 25 | 26 | private Args() { 27 | } 28 | 29 | /** 30 | * Compare two parameter type arrays. 31 | * 32 | * @param paramTypes1 33 | * lhs 34 | * @param paramTypes2 35 | * rhs 36 | * @return {@code int} as specified by {@link java.util.Comparator#compare(Object, Object)} 37 | */ 38 | @SuppressWarnings("PMD.UseVarargs") // not needed for comparing one array to another 39 | public static int compare(final Class[] paramTypes1, final Class[] paramTypes2) { 40 | for (int param = 0; param < paramTypes1.length; param++) { 41 | if (param >= paramTypes2.length) { 42 | return 1; 43 | } 44 | final int test = paramTypes1[param].getName().compareTo(paramTypes2[param].getName()); 45 | if (test == 0) { 46 | continue; 47 | } 48 | return test; 49 | } 50 | if (paramTypes1.length == paramTypes2.length) { 51 | return 0; 52 | } 53 | return -1; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/utils/URLArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.utils; 20 | 21 | import java.io.File; 22 | import java.net.MalformedURLException; 23 | import java.net.URL; 24 | import java.util.Collection; 25 | import java.util.stream.Stream; 26 | 27 | /** 28 | * {@link URL} Array utilities. 29 | */ 30 | public final class URLArray { 31 | /** 32 | * Convert an {@link Iterable} of file system paths. 33 | * @param files to convert 34 | * @return URL[] 35 | */ 36 | public static URL[] fromPaths(final Iterable files) { 37 | return fromFiles(() -> stream(files).map(e -> e == null ? null : new File(e)).iterator()); 38 | } 39 | 40 | /** 41 | * Convert an {@link Iterable} of {@link File}s. 42 | * @param files to convert 43 | * @return URL[] 44 | */ 45 | public static URL[] fromFiles(final Iterable files) { 46 | return fromFiles(stream(files)); 47 | } 48 | 49 | private static URL[] fromFiles(final Stream files) { 50 | return files.map(f -> { 51 | if (f == null) { 52 | return null; 53 | } 54 | try { 55 | return f.toURI().toURL(); 56 | } catch (final MalformedURLException e) { 57 | // this shouldn't happen 58 | throw new IllegalArgumentException(e); 59 | } 60 | }).toArray(URL[]::new); 61 | } 62 | 63 | private static Stream stream(final Iterable iterable) { 64 | if (iterable instanceof Collection) { 65 | return ((Collection) iterable).stream(); 66 | } 67 | final Stream.Builder builder = Stream.builder(); 68 | iterable.forEach(builder); 69 | return builder.build(); 70 | } 71 | 72 | private URLArray() { 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /processor/src/main/java/org/apache/commons/weaver/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Provides helpful utility classes. 20 | */ 21 | package org.apache.commons.weaver.utils; -------------------------------------------------------------------------------- /processor/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | ## Apache Commons Weaver Processor 21 | 22 | This module provides the `org.apache.commons:commons-weaver` artifact. 23 | It defines the Apache Commons Weaver SPI as well as the basic build-time 24 | (filesystem-based) processors that detect, configure, and invoke available 25 | modules. 26 | 27 | ### WeaveProcessor 28 | The [WeaveProcessor][wp] invokes available implementations of the 29 | [Weaver][weaver] SPI. 30 | 31 | ### CleanProcessor 32 | The [CleanProcessor][cp] invokes available implementations of the 33 | [Cleaner][cleaner] SPI. 34 | 35 | [cp]: apidocs/org/apache/commons/weaver/CleanProcessor.html 36 | [wp]: apidocs/org/apache/commons/weaver/WeaveProcessor.html 37 | [cleaner]: apidocs/org/apache/commons/weaver/spi/Cleaner.html 38 | [weaver]: apidocs/org/apache/commons/weaver/spi/Weaver.html 39 | -------------------------------------------------------------------------------- /processor/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/CleanProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test; 20 | 21 | import java.io.File; 22 | import java.util.Properties; 23 | 24 | import org.apache.commons.weaver.CleanProcessor; 25 | import org.apache.commons.weaver.test.beans.TestBeanWithClassAnnotation; 26 | import org.apache.commons.weaver.test.beans.TestBeanWithMethodAnnotation; 27 | import org.junit.Assert; 28 | import org.junit.Test; 29 | 30 | /** 31 | * Test the {@link CleanProcessor} 32 | */ 33 | public class CleanProcessorTest extends WeaverTestBase { 34 | 35 | @Test 36 | public void testWeaveVisiting() throws Exception { 37 | addClassForScanning(TestBeanWithMethodAnnotation.class); 38 | addClassForScanning(TestBeanWithClassAnnotation.class); 39 | 40 | final Properties config = new Properties(); 41 | config.put("configKey", "configValue"); 42 | 43 | final CleanProcessor cp = new CleanProcessor(getClassPathEntries(), getTargetFolder(), config); 44 | cp.clean(); 45 | 46 | Assert.assertFalse(new File(getTargetFolder(), TestBeanWithMethodAnnotation.class.getName().replace('.', 47 | File.separatorChar) 48 | + ".class").exists()); 49 | Assert.assertFalse(new File(getTargetFolder(), TestBeanWithClassAnnotation.class.getName().replace('.', 50 | File.separatorChar) 51 | + ".class").exists()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test; 20 | 21 | import java.util.Arrays; 22 | import java.util.Properties; 23 | 24 | import org.apache.commons.weaver.test.beans.TestBeanWithClassAnnotation; 25 | import org.apache.commons.weaver.test.beans.TestBeanWithMethodAnnotation; 26 | import org.apache.commons.weaver.test.weaver.TestWeaver; 27 | import org.apache.commons.weaver.WeaveProcessor; 28 | 29 | import org.junit.Assert; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test the {@link WeaveProcessor} 34 | */ 35 | public class WeaveProcessorTest extends WeaverTestBase { 36 | 37 | @Test 38 | public void testWeaveVisiting() throws Exception { 39 | addClassForScanning(TestBeanWithMethodAnnotation.class); 40 | addClassForScanning(TestBeanWithClassAnnotation.class); 41 | 42 | final Properties config = new Properties(); 43 | config.put("configKey", "configValue"); 44 | 45 | final WeaveProcessor wp = new WeaveProcessor(getClassPathEntries(), getTargetFolder(), config); 46 | 47 | TestWeaver.wovenClasses.clear(); 48 | TestWeaver.wovenMethods.clear(); 49 | 50 | wp.weave(); 51 | 52 | Assert.assertEquals(1, TestWeaver.wovenClasses.size()); 53 | Assert.assertEquals(TestBeanWithClassAnnotation.class, TestWeaver.wovenClasses.get(0)); 54 | 55 | Assert.assertEquals(1, TestWeaver.wovenMethods.size()); 56 | Assert.assertEquals(TestBeanWithMethodAnnotation.class, TestWeaver.wovenMethods.get(0).getDeclaringClass()); 57 | 58 | Assert.assertEquals(1, TestWeaver.implementors.size()); 59 | Assert.assertEquals(TestBeanWithClassAnnotation.class, TestWeaver.implementors.get(0)); 60 | 61 | Assert.assertEquals(2, TestWeaver.subclasses.size()); 62 | Assert.assertTrue(TestWeaver.subclasses.containsAll(Arrays.> asList( 63 | TestBeanWithClassAnnotation.class, TestBeanWithMethodAnnotation.class))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/beans/AbstractTestBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test.beans; 20 | 21 | public abstract class AbstractTestBean { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/beans/TestAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test.beans; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Test marker annotation to test the scanning 28 | */ 29 | @Target({ElementType.METHOD, ElementType.TYPE}) 30 | @Retention(RetentionPolicy.CLASS) 31 | public @interface TestAnnotation { 32 | } 33 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test.beans; 20 | 21 | public interface TestBeanInterface { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithClassAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test.beans; 20 | 21 | /** 22 | * Simple test bean 23 | */ 24 | @TestAnnotation 25 | public class TestBeanWithClassAnnotation extends AbstractTestBean implements TestBeanInterface { 26 | @SuppressWarnings("unused") 27 | private int someMethod() { 28 | return 42; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/beans/TestBeanWithMethodAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test.beans; 20 | 21 | /** 22 | * Simple test bean 23 | */ 24 | public class TestBeanWithMethodAnnotation extends AbstractTestBean { 25 | @TestAnnotation 26 | private int annotatedMethod() { 27 | return 42; 28 | } 29 | 30 | @SuppressWarnings("unused") 31 | private int nonAnnotatedMethod() { 32 | return 21; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/test/weaver/TestCleaner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.weaver.test.weaver; 20 | 21 | import java.lang.annotation.ElementType; 22 | 23 | import org.apache.commons.weaver.model.ScanRequest; 24 | import org.apache.commons.weaver.model.Scanner; 25 | import org.apache.commons.weaver.model.WeavableClass; 26 | import org.apache.commons.weaver.model.WeaveEnvironment; 27 | import org.apache.commons.weaver.model.WeaveInterest; 28 | import org.apache.commons.weaver.spi.Cleaner; 29 | import org.apache.commons.weaver.test.beans.TestAnnotation; 30 | 31 | public class TestCleaner implements Cleaner { 32 | 33 | @Override 34 | public boolean clean(final WeaveEnvironment environment, final Scanner scanner) { 35 | boolean result = false; 36 | 37 | final ScanRequest scanRequest = 38 | new ScanRequest().add(WeaveInterest.of(TestAnnotation.class, ElementType.TYPE)).add( 39 | WeaveInterest.of(TestAnnotation.class, ElementType.METHOD)); 40 | 41 | for (final WeavableClass weavableClass : scanner.scan(scanRequest).getClasses()) { 42 | if (!environment.deleteClassfile(weavableClass.getTarget())) { 43 | break; 44 | } 45 | result = true; 46 | } 47 | return result; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /processor/src/test/java/org/apache/commons/weaver/utils/ArgsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.weaver.utils; 21 | 22 | import static org.junit.Assert.*; 23 | 24 | import org.apache.commons.lang3.ArrayUtils; 25 | import org.junit.Test; 26 | 27 | /** 28 | * {@link Args} tests. 29 | */ 30 | public class ArgsTest { 31 | 32 | @Test 33 | public void testCompare() { 34 | assertTrue(Args.compare(ArrayUtils.EMPTY_CLASS_ARRAY, ArrayUtils.EMPTY_CLASS_ARRAY) == 0); 35 | assertTrue(Args.compare(ArrayUtils.EMPTY_CLASS_ARRAY, new Class[] { String.class }) < 0); 36 | assertTrue(Args.compare(new Class[] { String.class }, ArrayUtils.EMPTY_CLASS_ARRAY) > 0); 37 | assertTrue(Args.compare(new Class[] { String.class }, new Class[] { String.class }) == 0); 38 | assertTrue(Args.compare(new Class[] { int.class }, new Class[] { String.class }) < 0); 39 | assertTrue(Args.compare(new Class[] { String.class }, new Class[] { int.class }) > 0); 40 | assertTrue(Args.compare(new Class[] { int.class, String.class }, new Class[] { int.class, String.class}) == 0); 41 | assertTrue(Args.compare(new Class[] { String.class, String.class }, new Class[] { String.class, String.class}) == 0); 42 | assertTrue(Args.compare(new Class[] { String.class, int.class }, new Class[] { String.class, String.class}) < 0); 43 | assertTrue(Args.compare(new Class[] { String.class, String.class }, new Class[] { String.class, int.class}) > 0); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /processor/src/test/resources/META-INF/services/org.apache.commons.weaver.spi.Cleaner: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # this class gets picked up by the CleanProcessor 19 | org.apache.commons.weaver.test.weaver.TestCleaner 20 | -------------------------------------------------------------------------------- /processor/src/test/resources/META-INF/services/org.apache.commons.weaver.spi.Weaver: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # this class gets picked up by the WeaveProcessor 19 | org.apache.commons.weaver.test.weaver.TestWeaver 20 | -------------------------------------------------------------------------------- /src/site/markdown/building.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Apache Maven 3 is required to build Apache Commons Weaver, using Java 8. 21 | 22 | ### Site building issues 23 | Apache Commons Weaver uses the japicmp report for API compatibility reporting. 24 | This requires that the `package` goal be invoked in the same Maven run as the 25 | `site` goal. 26 | 27 | -------------------------------------------------------------------------------- /src/site/resources/download_weaver.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* 5 | -------------------------------------------------------------------------------- /src/site/resources/images/weaver-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-weaver/fc23593a570468f89dddf09638ca3768f450ea9a/src/site/resources/images/weaver-logo-white.png -------------------------------------------------------------------------------- /src/site/resources/images/weaver-logo-white.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-weaver/fc23593a570468f89dddf09638ca3768f450ea9a/src/site/resources/images/weaver-logo-white.xcf -------------------------------------------------------------------------------- /src/site/resources/images/weaver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-weaver/fc23593a570468f89dddf09638ca3768f450ea9a/src/site/resources/images/weaver.png -------------------------------------------------------------------------------- /src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Commons Weaver 21 | /images/weaver-logo-white.png 22 | /index.html 23 | 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | --------------------------------------------------------------------------------