├── .config ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml └── pmd │ └── ruleset.xml ├── .gitattributes ├── .github ├── .lycheeignore ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── enhancement.yml │ └── question.yml ├── labels.yml └── workflows │ ├── broken-links.yml │ ├── check-build.yml │ ├── release.yml │ ├── sonar.yml │ ├── sync-labels.yml │ ├── test-deploy.yml │ └── update-from-template.yml ├── .gitignore ├── .idea ├── checkstyle-idea.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── externalDependencies.xml ├── inspectionProfiles │ └── Project_Default.xml └── saveactions_settings.xml ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── assets ├── Logo.png ├── Logo2.png ├── MigrationSequence.drawio ├── MigrationSequence_1.png ├── MigrationSequence_2.png ├── MigrationSequence_3.png └── MigrationSequence_4.png ├── micro-migration-demo ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── software │ └── xdev │ └── micromigration │ └── examples │ ├── explicit │ ├── MainExplicit.java │ └── scripts │ │ ├── UpdateToV1_0.java │ │ └── UpdateToV1_1.java │ ├── notification │ └── MainNotification.java │ ├── practical │ ├── embedded │ │ ├── MainPracticalWithMigrationEmbeddedStorageManager.java │ │ ├── UpdateToV1_0.java │ │ └── UpdateToV2_0.java │ ├── migration_manager │ │ ├── MainPracticalWithMigrationManager.java │ │ ├── UpdateToV1_0.java │ │ └── UpdateToV2_0.java │ ├── v0 │ │ ├── BusinessBranch.java │ │ └── Customer.java │ └── v1_and_higher │ │ ├── Address.java │ │ ├── BusinessBranch.java │ │ └── Customer.java │ └── reflective │ ├── MainReflective.java │ └── scripts │ ├── UpdateToV1_0.java │ └── UpdateToV1_1.java ├── micro-migration ├── pom.xml └── src │ ├── main │ └── java │ │ └── software │ │ └── xdev │ │ └── micromigration │ │ ├── eclipsestore │ │ ├── MigrationEmbeddedStorage.java │ │ ├── MigrationEmbeddedStorageManager.java │ │ ├── MigrationManager.java │ │ ├── MigrationScript.java │ │ └── TunnelingEmbeddedStorageManager.java │ │ ├── migrater │ │ ├── AbstractMigrater.java │ │ ├── ExplicitMigrater.java │ │ ├── MicroMigrater.java │ │ ├── VersionAlreadyRegisteredException.java │ │ └── reflection │ │ │ ├── ReflectiveMigrater.java │ │ │ └── ScriptInstantiationException.java │ │ ├── notification │ │ ├── AbstractScriptExecutionNotification.java │ │ ├── ScriptExecutionNotificationWithScriptReference.java │ │ └── ScriptExecutionNotificationWithoutScriptReference.java │ │ ├── scripts │ │ ├── Context.java │ │ ├── ReflectiveVersionMigrationScript.java │ │ ├── SimpleMigrationScript.java │ │ ├── SimpleTypedMigrationScript.java │ │ └── VersionAgnosticMigrationScript.java │ │ ├── version │ │ ├── MigrationVersion.java │ │ ├── Versioned.java │ │ ├── VersionedAndKeeperOfHistory.java │ │ ├── VersionedObject.java │ │ ├── VersionedObjectWithHistory.java │ │ ├── VersionedRoot.java │ │ └── VersionedRootWithHistory.java │ │ └── versionagnostic │ │ ├── VersionAgnosticMigrationEmbeddedStorageManager.java │ │ ├── VersionAgnosticMigrationManager.java │ │ └── VersionAgnosticTunnelingEmbeddedStorageManager.java │ └── test │ └── java │ └── software │ └── xdev │ └── micromigration │ ├── eclipsestore │ ├── integration │ │ ├── IntroduceMigrationOnExistingDatastoreTest.java │ │ ├── MigrationScriptAfterScriptTest.java │ │ ├── MigrationScriptWithNullSourceVersionTest.java │ │ ├── MultipleScriptsTest.java │ │ └── StoreStuffInMigrationStorageManagerTest.java │ ├── migrater │ │ └── ExplicitMigraterTest.java │ └── util │ │ └── MicroMigrationScriptDummy.java │ ├── migrater │ └── reflection │ │ ├── ReflectiveMigraterTest.java │ │ └── scripts │ │ ├── abstractReflectiveSuperClass │ │ ├── AbstractScript.java │ │ └── v1_ValidScript.java │ │ ├── abstractSuperClass │ │ ├── AbstractScript.java │ │ └── ValidScript.java │ │ ├── errorThrowing │ │ └── ErrorThrowingScript.java │ │ ├── exceptionThrowing │ │ └── ExceptionThrowingScript.java │ │ ├── includeSubPackages │ │ ├── ValidScript.java │ │ └── subpackage │ │ │ └── ValidScriptInSubpackage.java │ │ ├── moreClassesIncludingValid │ │ ├── IrrelevantClass.java │ │ └── ValidScript.java │ │ ├── noCorrectConstructor │ │ └── NoCorrectConstructorScript.java │ │ ├── reflectiveVersion │ │ └── v1_ValidScript.java │ │ └── valid │ │ └── ValidScript.java │ ├── scripts │ └── ReflectiveVersionMigrationScriptTest.java │ └── version │ └── MigrationVersionTest.java ├── mvnw ├── mvnw.cmd ├── pom.xml └── renovate.json5 /.config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Force sh files to have LF 5 | *.sh text eol=lf 6 | 7 | # Force MVN Wrapper Linux files LF 8 | mvnw text eol=lf 9 | .mvn/wrapper/maven-wrapper.properties text eol=lf 10 | -------------------------------------------------------------------------------- /.github/.lycheeignore: -------------------------------------------------------------------------------- 1 | # Ignorefile for broken link check 2 | localhost 3 | mvnrepository.com 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: 🐞 Bug 2 | description: Create a bug report for something that is broken 3 | labels: [bug] 4 | type: bug 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for reporting a bug. 10 | 11 | Please fill in as much information as possible about your bug so that we don't have to play "information ping-pong" and can help you immediately. 12 | 13 | - type: checkboxes 14 | id: checklist 15 | attributes: 16 | label: "Checklist" 17 | options: 18 | - label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/micro-migration/releases/latest)" 19 | required: true 20 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/micro-migration/issues) or [closed](https://github.com/xdev-software/micro-migration/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." 21 | required: true 22 | - label: "I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise." 23 | required: true 24 | - label: "This issue contains only one bug." 25 | required: true 26 | 27 | - type: input 28 | id: app-version 29 | attributes: 30 | label: Affected version 31 | description: "In which version did you encounter the bug?" 32 | placeholder: "x.x.x" 33 | validations: 34 | required: true 35 | 36 | - type: textarea 37 | id: description 38 | attributes: 39 | label: Description of the problem 40 | description: | 41 | Describe as exactly as possible what is not working. 42 | validations: 43 | required: true 44 | 45 | - type: textarea 46 | id: steps-to-reproduce 47 | attributes: 48 | label: Steps to reproduce the bug 49 | description: | 50 | What did you do for the bug to show up? 51 | 52 | If you can't cause the bug to show up again reliably (and hence don't have a proper set of steps to give us), please still try to give as many details as possible on how you think you encountered the bug. 53 | placeholder: | 54 | 1. Use '...' 55 | 2. Do '...' 56 | validations: 57 | required: true 58 | 59 | - type: textarea 60 | id: additional-information 61 | attributes: 62 | label: Additional information 63 | description: | 64 | Any other relevant information you'd like to include 65 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: 💬 Contact support 3 | url: https://xdev.software/en/services/support 4 | about: "If you need support as soon as possible or/and you can't wait for any pull request" 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.yml: -------------------------------------------------------------------------------- 1 | name: ✨ Feature/Enhancement 2 | description: Suggest a new feature or enhancement 3 | labels: [enhancement] 4 | type: feature 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for suggesting a new feature/enhancement. 10 | 11 | - type: checkboxes 12 | id: checklist 13 | attributes: 14 | label: "Checklist" 15 | options: 16 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/micro-migration/issues) or [closed](https://github.com/xdev-software/micro-migration/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." 17 | required: true 18 | - label: "I have taken the time to fill in all the required details. I understand that the feature request will be dismissed otherwise." 19 | required: true 20 | - label: "This issue contains only one feature request/enhancement." 21 | required: true 22 | 23 | - type: textarea 24 | id: description 25 | attributes: 26 | label: Description 27 | validations: 28 | required: true 29 | 30 | - type: textarea 31 | id: additional-information 32 | attributes: 33 | label: Additional information 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: ❓ Question 2 | description: Ask a question 3 | labels: [question] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for taking the time to fill out this form! 9 | 10 | - type: checkboxes 11 | id: checklist 12 | attributes: 13 | label: "Checklist" 14 | options: 15 | - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/micro-migration/issues) or [closed](https://github.com/xdev-software/micro-migration/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." 16 | required: true 17 | - label: "I have taken the time to fill in all the required details. I understand that the question will be dismissed otherwise." 18 | required: true 19 | 20 | - type: textarea 21 | id: what-is-the-question 22 | attributes: 23 | label: What is/are your question(s)? 24 | validations: 25 | required: true 26 | 27 | - type: textarea 28 | id: additional-information 29 | attributes: 30 | label: Additional information 31 | description: "Any other information you'd like to include - for instance logs, screenshots, etc." 32 | -------------------------------------------------------------------------------- /.github/labels.yml: -------------------------------------------------------------------------------- 1 | # Default 2 | ## Required for template 3 | - name: bug 4 | description: "Something isn't working" 5 | color: 'd73a4a' 6 | - name: enhancement 7 | description: New feature or request 8 | color: '#a2eeef' 9 | - name: question 10 | description: Information is requested 11 | color: '#d876e3' 12 | ## Others 13 | - name: duplicate 14 | description: This already exists 15 | color: '#cfd3d7' 16 | - name: good first issue 17 | description: Good for newcomers 18 | color: '#7057ff' 19 | - name: help wanted 20 | description: Extra attention is needed 21 | color: '#008672' 22 | - name: invalid 23 | description: "This doesn't seem right" 24 | color: '#e4e669' 25 | # Custom 26 | - name: automated 27 | description: Created by an automation 28 | color: '#000000' 29 | - name: "can't reproduce" 30 | color: '#e95f2c' 31 | - name: customer-requested 32 | description: Was requested by a customer of us 33 | color: '#068374' 34 | - name: stale 35 | color: '#ededed' 36 | - name: waiting-for-response 37 | description: If no response is received after a certain time the issue will be closed 38 | color: '#202020' 39 | -------------------------------------------------------------------------------- /.github/workflows/broken-links.yml: -------------------------------------------------------------------------------- 1 | name: Broken links 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "23 23 * * 0" 7 | 8 | permissions: 9 | issues: write 10 | 11 | jobs: 12 | link-checker: 13 | runs-on: ubuntu-latest 14 | timeout-minutes: 15 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - run: mv .github/.lycheeignore .lycheeignore 19 | 20 | - name: Link Checker 21 | id: lychee 22 | uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2 23 | with: 24 | fail: false # Don't fail on broken links, create an issue instead 25 | 26 | - name: Find already existing issue 27 | id: find-issue 28 | run: | 29 | echo "number=$(gh issue list -l 'bug' -l 'automated' -L 1 -S 'in:title \"Link Checker Report\"' -s 'open' --json 'number' --jq '.[].number')" >> $GITHUB_OUTPUT 30 | env: 31 | GH_TOKEN: ${{ github.token }} 32 | 33 | - name: Close issue if everything is fine 34 | if: env.lychee_exit_code == 0 && steps.find-issue.outputs.number != '' 35 | run: gh issue close -r 'not planned' ${{ steps.find-issue.outputs.number }} 36 | env: 37 | GH_TOKEN: ${{ github.token }} 38 | 39 | - name: Create Issue From File 40 | if: env.lychee_exit_code != 0 41 | uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd # v5 42 | with: 43 | issue-number: ${{ steps.find-issue.outputs.number }} 44 | title: Link Checker Report 45 | content-filepath: ./lychee/out.md 46 | labels: bug, automated 47 | -------------------------------------------------------------------------------- /.github/workflows/check-build.yml: -------------------------------------------------------------------------------- 1 | name: Check Build 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ develop ] 7 | paths-ignore: 8 | - '**.md' 9 | - '.config/**' 10 | - '.github/**' 11 | - '.idea/**' 12 | - 'assets/**' 13 | pull_request: 14 | branches: [ develop ] 15 | paths-ignore: 16 | - '**.md' 17 | - '.config/**' 18 | - '.github/**' 19 | - '.idea/**' 20 | - 'assets/**' 21 | 22 | env: 23 | PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} 24 | DEMO_MAVEN_MODULE: ${{ github.event.repository.name }}-demo 25 | 26 | jobs: 27 | build: 28 | runs-on: ubuntu-latest 29 | timeout-minutes: 30 30 | 31 | strategy: 32 | matrix: 33 | java: [17, 21] 34 | distribution: [temurin] 35 | 36 | steps: 37 | - uses: actions/checkout@v4 38 | 39 | - name: Set up JDK 40 | uses: actions/setup-java@v4 41 | with: 42 | distribution: ${{ matrix.distribution }} 43 | java-version: ${{ matrix.java }} 44 | cache: 'maven' 45 | 46 | - name: Build with Maven 47 | run: ./mvnw -B clean package 48 | 49 | - name: Check for uncommited changes 50 | run: | 51 | if [[ "$(git status --porcelain)" != "" ]]; then 52 | echo ---------------------------------------- 53 | echo git status 54 | echo ---------------------------------------- 55 | git status 56 | echo ---------------------------------------- 57 | echo git diff 58 | echo ---------------------------------------- 59 | git diff 60 | echo ---------------------------------------- 61 | echo Troubleshooting 62 | echo ---------------------------------------- 63 | echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && ./mvnw -B clean package" 64 | exit 1 65 | fi 66 | 67 | - name: Upload demo files 68 | uses: actions/upload-artifact@v4 69 | with: 70 | name: demo-files-java-${{ matrix.java }} 71 | path: ${{ env.DEMO_MAVEN_MODULE }}/target/${{ env.DEMO_MAVEN_MODULE }}.jar 72 | if-no-files-found: error 73 | 74 | checkstyle: 75 | runs-on: ubuntu-latest 76 | if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} 77 | timeout-minutes: 15 78 | 79 | strategy: 80 | matrix: 81 | java: [17] 82 | distribution: [temurin] 83 | 84 | steps: 85 | - uses: actions/checkout@v4 86 | 87 | - name: Set up JDK 88 | uses: actions/setup-java@v4 89 | with: 90 | distribution: ${{ matrix.distribution }} 91 | java-version: ${{ matrix.java }} 92 | cache: 'maven' 93 | 94 | - name: Run Checkstyle 95 | run: ./mvnw -B checkstyle:check -P checkstyle -T2C 96 | 97 | pmd: 98 | runs-on: ubuntu-latest 99 | if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} 100 | timeout-minutes: 15 101 | 102 | strategy: 103 | matrix: 104 | java: [17] 105 | distribution: [temurin] 106 | 107 | steps: 108 | - uses: actions/checkout@v4 109 | 110 | - name: Set up JDK 111 | uses: actions/setup-java@v4 112 | with: 113 | distribution: ${{ matrix.distribution }} 114 | java-version: ${{ matrix.java }} 115 | cache: 'maven' 116 | 117 | - name: Run PMD 118 | run: ./mvnw -B test pmd:aggregate-pmd-no-fork pmd:check -P pmd -DskipTests -T2C 119 | 120 | - name: Run CPD (Copy Paste Detector) 121 | run: ./mvnw -B pmd:aggregate-cpd pmd:cpd-check -P pmd -DskipTests -T2C 122 | 123 | - name: Upload report 124 | if: always() 125 | uses: actions/upload-artifact@v4 126 | with: 127 | name: pmd-report 128 | if-no-files-found: ignore 129 | path: | 130 | target/reports/** 131 | -------------------------------------------------------------------------------- /.github/workflows/sonar.yml: -------------------------------------------------------------------------------- 1 | name: Sonar 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ develop ] 7 | paths-ignore: 8 | - '**.md' 9 | - '.config/**' 10 | - '.github/**' 11 | - '.idea/**' 12 | - 'assets/**' 13 | pull_request: 14 | branches: [ develop ] 15 | paths-ignore: 16 | - '**.md' 17 | - '.config/**' 18 | - '.github/**' 19 | - '.idea/**' 20 | - 'assets/**' 21 | 22 | env: 23 | SONARCLOUD_ORG: ${{ github.event.organization.login }} 24 | SONARCLOUD_HOST: https://sonarcloud.io 25 | 26 | jobs: 27 | token-check: 28 | runs-on: ubuntu-latest 29 | if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/')) }} 30 | timeout-minutes: 5 31 | outputs: 32 | hasToken: ${{ steps.check-token.outputs.has }} 33 | steps: 34 | - id: check-token 35 | run: | 36 | [ -z $SONAR_TOKEN ] && echo "has=false" || echo "has=true" >> "$GITHUB_OUTPUT" 37 | env: 38 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 39 | 40 | sonar-scan: 41 | runs-on: ubuntu-latest 42 | needs: token-check 43 | if: ${{ needs.token-check.outputs.hasToken }} 44 | timeout-minutes: 30 45 | steps: 46 | - uses: actions/checkout@v4 47 | with: 48 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 49 | 50 | - name: Set up JDK 51 | uses: actions/setup-java@v4 52 | with: 53 | distribution: 'temurin' 54 | java-version: 17 55 | 56 | - name: Cache SonarCloud packages 57 | uses: actions/cache@v4 58 | with: 59 | path: ~/.sonar/cache 60 | key: ${{ runner.os }}-sonar 61 | restore-keys: ${{ runner.os }}-sonar 62 | 63 | - name: Cache Maven packages 64 | uses: actions/cache@v4 65 | with: 66 | path: ~/.m2 67 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 68 | restore-keys: ${{ runner.os }}-m2 69 | 70 | - name: Build with Maven 71 | run: | 72 | ./mvnw -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ 73 | -DskipTests \ 74 | -Dsonar.projectKey=${{ env.SONARCLOUD_ORG }}_${{ github.event.repository.name }} \ 75 | -Dsonar.organization=${{ env.SONARCLOUD_ORG }} \ 76 | -Dsonar.host.url=${{ env.SONARCLOUD_HOST }} 77 | env: 78 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any 79 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 80 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | name: Sync labels 2 | 3 | on: 4 | push: 5 | branches: develop 6 | paths: 7 | - .github/labels.yml 8 | 9 | workflow_dispatch: 10 | 11 | permissions: 12 | issues: write 13 | 14 | jobs: 15 | labels: 16 | runs-on: ubuntu-latest 17 | timeout-minutes: 10 18 | steps: 19 | - uses: actions/checkout@v4 20 | with: 21 | sparse-checkout: .github/labels.yml 22 | 23 | - uses: EndBug/label-sync@52074158190acb45f3077f9099fea818aa43f97a # v2 24 | with: 25 | config-file: .github/labels.yml 26 | -------------------------------------------------------------------------------- /.github/workflows/test-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Test Deployment 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | env: 7 | PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} 8 | 9 | jobs: 10 | publish-maven: 11 | runs-on: ubuntu-latest 12 | timeout-minutes: 60 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - name: Set up JDK 17 | uses: actions/setup-java@v4 18 | with: # running setup-java again overwrites the settings.xml 19 | distribution: 'temurin' 20 | java-version: '17' 21 | server-id: sonatype-central-portal 22 | server-username: MAVEN_CENTRAL_USERNAME 23 | server-password: MAVEN_CENTRAL_TOKEN 24 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 25 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} 26 | 27 | - name: Publish to Central Portal 28 | run: ../mvnw -B deploy -P publish-sonatype-central-portal -DskipTests 29 | working-directory: ${{ env.PRIMARY_MAVEN_MODULE }} 30 | env: 31 | MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_USERNAME }} 32 | MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_MAVEN_CENTRAL_PORTAL_TOKEN }} 33 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties 10 | .mvn/timing.properties 11 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 12 | .mvn/wrapper/maven-wrapper.jar 13 | 14 | 15 | # Compiled class file 16 | *.class 17 | 18 | # Log file 19 | *.log 20 | 21 | # BlueJ files 22 | *.ctxt 23 | 24 | # Mobile Tools for Java (J2ME) 25 | .mtj.tmp/ 26 | 27 | # Package/Binary Files don't belong into a git repo 28 | *.jar 29 | *.war 30 | *.nar 31 | *.ear 32 | *.zip 33 | *.tar.gz 34 | *.rar 35 | *.dll 36 | *.exe 37 | *.bin 38 | 39 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 40 | hs_err_pid* 41 | 42 | # JRebel 43 | **/resources/rebel.xml 44 | **/resources/rebel-remote.xml 45 | 46 | # eclispe stuff for root 47 | /.settings/ 48 | /.classpath 49 | /.project 50 | 51 | 52 | # eclispe stuff for modules 53 | /*/.metadata/ 54 | /*/.apt_generated_tests/ 55 | /*/.settings/ 56 | /*/.classpath 57 | /*/.project 58 | /*/RemoteSystemsTempFiles/ 59 | 60 | #custom 61 | .flattened-pom.xml 62 | .tern-project 63 | 64 | # == IntelliJ == 65 | *.iml 66 | *.ipr 67 | 68 | # Some files are user/installation independent and are used for configuring the IDE 69 | # See also https://stackoverflow.com/a/35279076 70 | 71 | .idea/* 72 | !.idea/saveactions_settings.xml 73 | !.idea/checkstyle-idea.xml 74 | !.idea/externalDependencies.xml 75 | 76 | !.idea/inspectionProfiles/ 77 | .idea/inspectionProfiles/* 78 | !.idea/inspectionProfiles/Project_Default.xml 79 | 80 | !.idea/codeStyles/ 81 | .idea/codeStyles/* 82 | !.idea/codeStyles/codeStyleConfig.xml 83 | !.idea/codeStyles/Project.xml 84 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.21.0 5 | JavaOnlyWithTests 6 | true 7 | true 8 | 12 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 99 | 100 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/externalDependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/saveactions_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.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 | # http://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 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 3.0.2 2 | * Migrated deployment to _Sonatype Maven Central Portal_ [#155](https://github.com/xdev-software/standard-maven-template/issues/155) 3 | * Updated dependencies 4 | 5 | # 3.0.1 6 | 7 | * Fix for ExplicitMigrater without any scripts 8 | 9 | # 3.0.0 10 | 11 | * Added support for EclipseStore v2 12 | * Having an empty version for the first migration-script is now allowed 13 | 14 | # 2.0.0 15 | _Major refactoring_ 16 | * Consolidated all previous modules into a single one 17 | * Dropped support for MicroStream as EclipseStore is it's successor 18 | * Refactored and adjusted code accordingly 19 | * Slimed down dependencies 20 | * Minimal required Java version: 17 21 | 22 | # 1.0.0 23 | * Added support for EclipseStore v1 24 | * Updated plenty of libraries 25 | 26 | # 0.0.9 27 | * Added support for MicroStream v8 28 | 29 | # 0.0.8 30 | * Access to the native embedded manager is now possible in the scripts (see ``VersionAgnosticMigrationEmbeddedStorageManager#getNativeStorageManager``) 31 | 32 | # 0.0.7 33 | * A lot of refactoring of the module structure 34 | * A migration history is now available and automatically stored 35 | 36 | # 0.0.6 37 | * Tried a new release-action...again. 38 | 39 | # 0.0.5 40 | * Tried a new release-action. 41 | 42 | # 0.0.4 43 | * Fixed setup. 0.0.3 was not working with the release setup. 44 | 45 | # 0.0.3 46 | * Restructured the complete maven modules. Multiple MicroStream-Versions are now supported. 47 | * Added plenty of documentation 48 | 49 | # 0.0.2 50 | * Updated MicroStream from v4 to v5. 51 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | We would absolutely love to get the community involved, and we welcome any form of contributions – comments and questions on different communication channels, issues and pull request and anything that you build and share using our components. 4 | 5 | ### Communication channels 6 | * Communication is primarily done using issues. 7 | * If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). 8 | * As a last resort measure or on otherwise important matter you may also [contact us directly](https://xdev.software/en/about-us/contact). 9 | 10 | ### Ways to help 11 | * **Report bugs**
Create an issue or send a pull request 12 | * **Send pull requests**
If you want to contribute code, check out the development instructions below. 13 | * However when contributing larger new features, please first discuss the change you wish to make via issue with the owners of this repository before making it.
Otherwise your work might be rejected and your effort was pointless. 14 | 15 | We also encourage you to read the [contribution instructions by GitHub](https://docs.github.com/en/get-started/quickstart/contributing-to-projects). 16 | 17 | ## Developing 18 | 19 | ### Software Requirements 20 | You should have the following things installed: 21 | * Git 22 | * Java 21 - should be as unmodified as possible (Recommended: [Eclipse Adoptium](https://adoptium.net/temurin/releases/)) 23 | * Maven (Note that the [Maven Wrapper](https://maven.apache.org/wrapper/) is shipped with the repo) 24 | 25 | ### Recommended setup 26 | * Install ``IntelliJ`` (Community Edition is sufficient) 27 | * Install the following plugins: 28 | * [Save Actions](https://plugins.jetbrains.com/plugin/22113) - Provides save actions, like running the formatter or adding ``final`` to fields 29 | * [SonarLint](https://plugins.jetbrains.com/plugin/7973-sonarlint) - CodeStyle/CodeAnalysis 30 | * You may consider disabling telemetry in the settings under ``Tools > Sonarlint -> About`` 31 | * [Checkstyle-IDEA](https://plugins.jetbrains.com/plugin/1065-checkstyle-idea) - CodeStyle/CodeAnalysis 32 | * Import the project 33 | * Ensure that everything is encoded in ``UTF-8`` 34 | * Ensure that the JDK/Java-Version is correct 35 | 36 | 37 | ## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/micro-migration/release.yml?branch=master)](https://github.com/xdev-software/micro-migration/actions/workflows/release.yml) 38 | 39 | Before releasing: 40 | * Consider doing a [test-deployment](https://github.com/xdev-software/micro-migration/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing. 41 | * Check the [changelog](CHANGELOG.md) 42 | 43 | If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes 44 | 45 | When the release is finished do the following: 46 | * Merge the auto-generated PR (with the incremented version number) back into the ``develop`` 47 | 48 | ### Release failures 49 | 50 | There are 2 modes of release failure: 51 | 1. The remote server was e.g. down and non of the artifacts got published 52 | 2. There was a build failure during release and only parts of the artifacts got released 53 | 54 | In case 1 we can re-release the existing version,
in case 2 we have to release a new version when we can't get the artifacts deleted (as is the case with Maven Central) 55 | 56 | #### How-to: Re-Releasing an existing version 57 | 58 | 1. Delete the release on GitHub 59 | 2. Delete the release Git tag from the repo (locally and remote!) 60 | 3. Delete the ``master``-Branch and re-create it from the ``develop`` branch (or reset it to the state before the release-workflow commits have been done) 61 | * This requires __temporarily__ removing the branch protection 62 | * Once this was done a new release is triggered immediately! 63 | 64 | #### How-to: Releasing a new version 65 | 66 | 1. Merge the ``master`` branch back into ``develop`` (or another temporary branch) 67 | 2. Make sure all master branch versions are prepared for a new release
e.g. if the broken release was ``1.0.0`` the version should now be at ``1.0.1-SNAPSHOT`` - the ``SNAPSHOT`` is important for the workflow! 68 | 3. Mark the broken release as broken e.g. inside the Changelog, GitHub Release page, etc.
69 | You can use something like this: 70 | ``` 71 | > [!WARNING] 72 | > This release is broken as my cat accidentally clicked the abort button during the process 73 | ``` 74 | 4. Merge the changes back into the ``master`` branch to trigger a new release 75 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/micro-migration/security/advisories/new). 6 | -------------------------------------------------------------------------------- /assets/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/micro-migration/6bcef292742c6dd07404281ab1aff895c0e232e2/assets/Logo.png -------------------------------------------------------------------------------- /assets/Logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/micro-migration/6bcef292742c6dd07404281ab1aff895c0e232e2/assets/Logo2.png -------------------------------------------------------------------------------- /assets/MigrationSequence.drawio: -------------------------------------------------------------------------------- 1 | 7V1bd6I6FP41fTxdgXDz0VtbusR2qp2OviGkiKK4ABX89ScoVK6KjiKek1ljhRBCsvPtvb+EZPsAmzP32ZIXY8lUkfFAA9V9gK0HmqZYFuAvP8XbpQgc3CVolq4GmfYJPX2DgsTgPm2pq8iOZXRM03D0RTxRMedzpDixNNmyzHU827dpxJ+6kDWUSugpspFO/dJVZxykUlxtf+EF6do4eLRA87sLMznMHLTEHsuquY4kwfYDbFqm6eyOZm4TGb7wQrns7nvKufpTMQvNnSI3iCtlyk1setUE7qepeI7Ze/mHEnbFrGRjGbQ4qK3jhSLAFV/4h98Gcuu+SB9gA83V4LClGLJt6wpOHDszAydQ+PDbnDtP8kw3/G7vIc1EuMxPcXunY3l/cCoITwb+ySMbnrbc6MWWF565uvMnKN0/jtyFz/Y3+SfhPd+6YTRNw7S2DYHN7T+cvmsiUlNdv5dlkGSbS0tBBwQYoNmRLQ05B/LVfnocqwoyZwi3Dd+33mMq1JRxBE1hmoUM2dFX8erKAbS1n+J+nvBu6rghNAjVkGN3t4RKGJYbFrFrZnBXFEOJgrBCxwsCiYJ2ckgVhA8izd4nbSF6ClxrBK5/BddaQbhS9C3xSkMQgxnLn4lXCNjDBV0Zr6HtJ3g9E68UXRSw7E0ByyQAK5wL2ISBTRV0bcBSxwGrWeZyEWRDloPcmNACIiaPwuwgp/fTfRUWRMWFyYRKG+lLis7oTDrpjaIdF5PUqWKBGVLhDPzYhqqv8KHmH3ZMTBtxLklWxvochTnwAyOZUtLEwpyrSA1Ubz3WHdRbyFulWGNKHdd7X946fkrd0LU5TnPMRVoPv2WVl32DYTuWOUWRKyOGYwFz0H74V3pB7ajcTo525gEcHVTHkrswDeyW7Mi2Y1oo1yTrs+3o4EfsHXmEjHfT1h3d9MU/Mh3HnOX2y/b2ur3YjUt8iymHJ9+66/d5I3hCS8V1eYD13Sn9ZK+0B7rh4n6nm+8vXXroNZjRl7tUNkCXXz6A0jJXHahC1WOh5LErZaaspEl9LTVrG3Wm6OLL0FDm3cWIZmripO2fL4Z/1OYIavi8rknNOnjbfkRt+MWOBzPX6Hy9jge0M1dmNWo0+1UTZ6yhevW12Kpr3Zbmf/R3fTBBz21ebNY1seXOxefhYvS8rol6ty19SuCjP43n2X0E5fkJyM3G9L332pU2mt0Fmiu1JaYzmdpdb810Wsryred/G3R3Jq07rfZS6q3X/nVJX3ud1qspTcYTqce4nVYdp4HgGvB+T4xWF6d1PYbttCS2M2n7ZW7emmuIdHFVpD5S3xClfmPS6QfP7Yu21MTl+d/zAT3Y4Gfunu3XE9cHp8807+1Zcv3nSU2c1g+u9V/pTn+4rZPUn/ppm7ftvW2/foz/Xbhem6fr1GvTjtRLcnf1ktxUvVrr1XDDzEQ4Hr9t1isFDufvmq8k/v8DZuTyliN0kFzMN8C0a2CEtFkJ0y5uVeiUVWmaKjEo5xqU9Yh22SFdW+4Ni8RK7W7jYzLFz2ys5C8W+HXeKnzrU8NKDrq9ug9eTfKVwasDDHpX8pJAziq7+yR9DqiP6WesbKx4y25v7Xabde9t/w06k0+9EyqDt1NYLMeZ/OXa7z1xgpUddqe/PHESy7P9vL+8GgP4S0MtXH5/gJ83xXITXVFvQPnrA8jbdCzn57Ehf6mm6p/nGYnZ74nabDD4mW5XFzXUx3knfhvUxfDlw/TTcfs1+fn3YkiPAT73RB1rQONV7zKDvv1TKywVb/jVBeKL34ttGteG9XO/9URNpY2p+rxNhzjdHH4Zc/nll1/rpBQOtFDaxFsoHW5h1c3ND2e5mb1JG5zS+TkEQtX4eXpaqCnigpqtcuh2TWWz6LaMGArSpdDt49M1ZdPt9MwH4duEbxO+XTm+nWM6qsm3qfQwnhBuQrgJ4b4fwn2Svbk94c6a+i2ZcLOArxrhDt/LRMTSR7ZTAt0eAQQRl0W3ARKAIJRCt2Hl6HYapoRuE7pN6Hbl6HaO6ago3WYI3SZ0m9DtO6bbJ9mb29PttMEpnW7ziUVjVaDbbIZYUgtQ3i1TXSpbU3urtScjSlW/QRY7pwAPa6gUds5Ujp1zhJ0Tdk7YefXZeY7pqCg75wk7J+ycsPM7Zucn2Zvbs/MsGloyO0+uDhduTs7pNLvrebaDZiXw7Uqs9T6+9aLsHkk7RsK3Cd8mfLtyfDvHdFSTb9PpzdKEbxO+Tfj2/fDtk+zN7fk22e6e3bmFozMUDc8A+aMctsT4DBydYMbnxmcoe7976KEJYM8FLF8QsMzxDbYlBmiAzJmATQZoSBV0bcAW2O9OAHsUh0UAW6kADfDcCDjJAA2pgq4N2P9rKALYUPC5jFtjBeguRANPm0yEGYwvc+6KSnroy4WaSM+xkkEmGWSSQWbJg8xrWBsmMZ/F3Xh8CTNeIN/jvtmr9FZym3MVfEPGPmfiG4hvIL7h7n0DZJhq+QYmPTK+vx1eV+mq5Ha8CjgGJj0qJI6BOAbiGO7fMbChblfGMfwP9yJcpWeT+0yq4EfIimLiR4gf+S/6ET4k9JXxIwUWN5S9mJgvvNUv+Z7yYmIJ3yfd+Wri4Hz3ey4U81erdpjjP55RdicdjCbNYYG5ddzk38iytwwI7EkQoB9BJAtxrWQ5MlmOfNHlyBfa1pBndXLWJtdu601ZOoe5ZxgjYoEIuSfk/g6XL59mkijmxgyfqwDD52DlGD5PGH42UqrE8PlTGT5xqoTWE1pffVqfZ2qqSet5QusJrSe0/r9N608zSTen9XwFQmLTfILWZ+wNp1k2LZXUBqPLzcAUei/ec2TL8UUD1AidvPgL8nyYypYScHa28JulAzDIf7UC6FgPsQXHXfBq/ZMO05LRP6KNsywXuHNQZNp+ZO27JbuzUgXJK1k3tgj3f3Xe+rvCVoGTh09FwTI2Z6Ol/TdAuSIy2Mf4ygcqCxxhSPMoOJK/hns5cKQXPnwgWY2rKQi74c5VswaS8gcZ8mcy5H895UyH1mi7SFlutfBHHW3F0heOfbfyD8RNZy30KVXcXIFtr7gYfWGjuPDCQQSaq9iTOSg9wwS2/7JmmH6u3MLmsIm1VlS6C2CZ3ohLD+wO9EAxGc/N+eFFbdcTb7hw7GbiLMBJj+7ZztktfUyeB/dRH2TQR3dXhyg5uruavenu6uSm6NQCxcK7qxOBMEoOX8EViD5+hygKbd9xFN04CorwCHlICzxkeMgJXHzc+w94BILAcDxk8TcQqFr46xSnoozi4CNPMbTABn8Tv2daMugKBNW8R9AVjWSyG5fdDHT8QdDVHmsUxUKaY/B3jUpMqRQGHH8QcCWHkOCyBsJXB1wYvyQMUlIkfokPz3DKHxkjc93eJ5SA4NsCUzgITOoyyAzfLyRHJkegiLEhe5FsCz+Dnd+YnMfsgb0r8LIwTw/pS4T5KWF6ojA3LWdsauZcNqJY3wcN2scJGjxEwwTlBA3ylQYfh69yylObAoafu2kIq4xZqNqZrJWvPUKGw8oo7P7GF9oX5ROn6hTNZlc/NzZcIn84mZbvtMCh/FdS2vQ8UBlKe1wBQ+/1o8qDiJLnqPWZSnt9DRXuQ0OppIamIoYX1VDhsIaWTMD4AsPMs4LOleKtrg9PcEvU0XGrR50bKI5NlMOVjLECo8qSMHZmwMMCOCsae5C/KaLYROxB4VyeAYUjBZ2NKXxqmaYTzW7Ji7FkqsjP8S8= -------------------------------------------------------------------------------- /assets/MigrationSequence_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/micro-migration/6bcef292742c6dd07404281ab1aff895c0e232e2/assets/MigrationSequence_1.png -------------------------------------------------------------------------------- /assets/MigrationSequence_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/micro-migration/6bcef292742c6dd07404281ab1aff895c0e232e2/assets/MigrationSequence_2.png -------------------------------------------------------------------------------- /assets/MigrationSequence_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/micro-migration/6bcef292742c6dd07404281ab1aff895c0e232e2/assets/MigrationSequence_3.png -------------------------------------------------------------------------------- /assets/MigrationSequence_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdev-software/micro-migration/6bcef292742c6dd07404281ab1aff895c0e232e2/assets/MigrationSequence_4.png -------------------------------------------------------------------------------- /micro-migration-demo/README.md: -------------------------------------------------------------------------------- 1 | # micro-migration-examples 2 | Examples for the MicroMigration-Library 3 | 4 | Currently contains four major examples: 5 | ## Example with `ExplicitMigrater` 6 | In the package `software.xdev.micromigration.examples.explicit` there is a simple example with explicitly listed upgrade scripts. 7 | This is the most straight forward approach to use migration scripts. 8 | 9 | ## Example with `ReflectiveMigrater` 10 | In package `software.xdev.micromigration.examples.reflective` a migrater which finds it's scripts through reflection is used. 11 | So here all `MicroMigrationScript`s in the defined `software.xdev.micromigration.examples.reflective.scripts` package are used. 12 | 13 | ## Practical examples 14 | The package `software.xdev.micromigration.examples.practical.embedded` contains examples 15 | that are just a bit more complex than the other examples and should allow an insight about the usage in a 16 | practical environment. 17 | 18 | There is one example implemented with the `MigrationEmbeddedStorageManager` and another with the 19 | plain `MigrationManager`, so it is clear what the difference between these two approaches is. 20 | In both implementations the first update migrates from version 0 to 1 and converts an "old" `BusinessBranch` 21 | to a newer one. The second update only adds more `Customer`s to the existing `BusinessBranch`. 22 | -------------------------------------------------------------------------------- /micro-migration-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | software.xdev 9 | micro-migration-root 10 | 3.0.3-SNAPSHOT 11 | 12 | 13 | micro-migration-demo 14 | 3.0.3-SNAPSHOT 15 | jar 16 | 17 | 18 | XDEV Software 19 | https://xdev.software 20 | 21 | 22 | 23 | 17 24 | ${javaVersion} 25 | 26 | UTF-8 27 | UTF-8 28 | 29 | 30 | 31 | 32 | software.xdev 33 | micro-migration 34 | ${project.version} 35 | 36 | 37 | 38 | org.slf4j 39 | slf4j-simple 40 | 2.0.17 41 | 42 | 43 | 44 | 45 | ${project.artifactId} 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-compiler-plugin 51 | 3.14.0 52 | 53 | ${maven.compiler.release} 54 | 55 | -proc:none 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/explicit/MainExplicit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.explicit; 17 | 18 | import java.util.Date; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 24 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 25 | import software.xdev.micromigration.examples.explicit.scripts.UpdateToV1_0; 26 | import software.xdev.micromigration.examples.explicit.scripts.UpdateToV1_1; 27 | import software.xdev.micromigration.migrater.ExplicitMigrater; 28 | 29 | 30 | /** 31 | * The most basic usage of micro migration. Here two {@link MigrationScript}s are explicitly registered and subsequently 32 | * executed. Easy. 33 | */ 34 | @SuppressWarnings("java:S2629") 35 | public final class MainExplicit 36 | { 37 | private static final Logger LOG = LoggerFactory.getLogger(MainExplicit.class); 38 | 39 | public static void main(final String[] args) 40 | { 41 | final ExplicitMigrater migrater = new ExplicitMigrater( 42 | new UpdateToV1_0(), 43 | new UpdateToV1_1() 44 | ); 45 | final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start(migrater); 46 | LOG.info(storageManager.root().toString()); 47 | if(storageManager.root() == null) 48 | { 49 | storageManager.setRoot("Hello World! @ " + new Date()); 50 | } 51 | storageManager.storeRoot(); 52 | storageManager.shutdown(); 53 | } 54 | 55 | private MainExplicit() 56 | { 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/explicit/scripts/UpdateToV1_0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.explicit.scripts; 17 | 18 | import java.util.Date; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 24 | import software.xdev.micromigration.eclipsestore.MigrationScript; 25 | import software.xdev.micromigration.scripts.Context; 26 | import software.xdev.micromigration.version.MigrationVersion; 27 | 28 | 29 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 30 | public class UpdateToV1_0 implements MigrationScript 31 | { 32 | private static final Logger LOG = LoggerFactory.getLogger(UpdateToV1_0.class); 33 | 34 | @Override 35 | public MigrationVersion getTargetVersion() 36 | { 37 | return new MigrationVersion(1, 0); 38 | } 39 | 40 | @Override 41 | public void migrate(final Context context) 42 | { 43 | LOG.info("Update {} executed", this.getTargetVersion()); 44 | context.getStorageManager().setRoot("Hello World! @ " + new Date() + " Update 1.0"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/explicit/scripts/UpdateToV1_1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.explicit.scripts; 17 | 18 | import java.util.Date; 19 | 20 | import org.slf4j.LoggerFactory; 21 | 22 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 23 | import software.xdev.micromigration.eclipsestore.MigrationScript; 24 | import software.xdev.micromigration.scripts.Context; 25 | import software.xdev.micromigration.version.MigrationVersion; 26 | 27 | 28 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 29 | public class UpdateToV1_1 implements MigrationScript 30 | { 31 | private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(UpdateToV1_1.class); 32 | 33 | @Override 34 | public MigrationVersion getTargetVersion() 35 | { 36 | return new MigrationVersion(1, 1); 37 | } 38 | 39 | @Override 40 | public void migrate(final Context context) 41 | { 42 | LOG.info("Update {} executed", this.getTargetVersion()); 43 | context.getStorageManager().setRoot("Hello World! @ " + new Date() + " Update 1.1"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/notification/MainNotification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.notification; 17 | 18 | import java.util.Date; 19 | import java.util.logging.Logger; 20 | 21 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 22 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 23 | import software.xdev.micromigration.migrater.ExplicitMigrater; 24 | import software.xdev.micromigration.scripts.Context; 25 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 26 | import software.xdev.micromigration.version.MigrationVersion; 27 | 28 | 29 | /** 30 | * Shows the basic registration of migration notifications ({@link ScriptExecutionNotification}). 31 | */ 32 | @SuppressWarnings("java:S2629") 33 | public final class MainNotification 34 | { 35 | public static void main(final String[] args) 36 | { 37 | final ExplicitMigrater migrater = new ExplicitMigrater( 38 | new MainNotification.UpdateToV1_0() 39 | ); 40 | migrater.registerNotificationConsumer( 41 | scriptExecutionNotification -> Logger.getGlobal() 42 | .info("Script " + scriptExecutionNotification.getExecutedScript().getClass().getSimpleName() 43 | + " executed.") 44 | ); 45 | final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start(migrater); 46 | Logger.getGlobal().info(storageManager.root().toString()); 47 | if(storageManager.root() == null) 48 | { 49 | storageManager.setRoot("Hello World! @ " + new Date()); 50 | } 51 | storageManager.storeRoot(); 52 | storageManager.shutdown(); 53 | } 54 | 55 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 56 | static class UpdateToV1_0 implements VersionAgnosticMigrationScript 57 | { 58 | @Override 59 | public MigrationVersion getTargetVersion() 60 | { 61 | return new MigrationVersion(1, 0); 62 | } 63 | 64 | @Override 65 | public void migrate(final Context context) 66 | { 67 | context.getStorageManager().setRoot("Hello World! @ " + new Date() + " Update 1.0"); 68 | } 69 | } 70 | 71 | private MainNotification() 72 | { 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/embedded/MainPracticalWithMigrationEmbeddedStorageManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.embedded; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 22 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 23 | import software.xdev.micromigration.examples.practical.v0.BusinessBranch; 24 | import software.xdev.micromigration.migrater.ExplicitMigrater; 25 | 26 | 27 | /** 28 | * A practical example of usage in a few steps: 29 | *
    30 | *
  • v0.0: Storage is created without any updates. Only stores a new {@link BusinessBranch} 31 | *
  • v1.0: The BusinessBranch has a new implementation {@link BusinessBranch}. 32 | * The old branch is converted to the new implementation through the {@link UpdateToV1_0} script. 33 | *
  • v2.0: A new customer is added through the {@link UpdateToV2_0} script. 34 | *
35 | * The storage is restarted after every update to simulate a complete lifecycle of the datastore. 36 | */ 37 | @SuppressWarnings("java:S2629") 38 | public final class MainPracticalWithMigrationEmbeddedStorageManager 39 | { 40 | private static final Logger LOG = LoggerFactory.getLogger(MainPracticalWithMigrationEmbeddedStorageManager.class); 41 | 42 | public static void main(final String[] args) 43 | { 44 | // V0.0 45 | final ExplicitMigrater emptyMigrater = new ExplicitMigrater(); 46 | try(final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start(emptyMigrater)) 47 | { 48 | storageManager.setRoot(BusinessBranch.createDummyBranch()); 49 | storageManager.storeRoot(); 50 | LOG.info(storageManager.root().toString()); 51 | } 52 | 53 | // V1.0 54 | final ExplicitMigrater migraterWithV1 = new ExplicitMigrater(new UpdateToV1_0()); 55 | try(final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start(migraterWithV1)) 56 | { 57 | LOG.info(storageManager.root().toString()); 58 | } 59 | 60 | // V2.0 61 | final ExplicitMigrater migraterWithV2 = new ExplicitMigrater( 62 | new UpdateToV1_0(), 63 | new UpdateToV2_0() 64 | ); 65 | try(final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start(migraterWithV2)) 66 | { 67 | LOG.info(storageManager.root().toString()); 68 | } 69 | } 70 | 71 | private MainPracticalWithMigrationEmbeddedStorageManager() 72 | { 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/embedded/UpdateToV1_0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.embedded; 17 | 18 | import java.util.logging.Logger; 19 | 20 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 21 | import software.xdev.micromigration.eclipsestore.MigrationScript; 22 | import software.xdev.micromigration.examples.practical.v1_and_higher.Address; 23 | import software.xdev.micromigration.examples.practical.v1_and_higher.BusinessBranch; 24 | import software.xdev.micromigration.examples.practical.v1_and_higher.Customer; 25 | import software.xdev.micromigration.scripts.Context; 26 | import software.xdev.micromigration.version.MigrationVersion; 27 | 28 | 29 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 30 | public class UpdateToV1_0 implements MigrationScript 31 | { 32 | @Override 33 | public MigrationVersion getTargetVersion() 34 | { 35 | return new MigrationVersion(1, 0); 36 | } 37 | 38 | @Override 39 | public void migrate( 40 | final Context context) 42 | { 43 | Logger.getGlobal().info("Executing Script for v1.0..."); 44 | final software.xdev.micromigration.examples.practical.v0.BusinessBranch oldBranch = 45 | context.getMigratingObject(); 46 | final BusinessBranch newBranch = 47 | new BusinessBranch(); 48 | for(final software.xdev.micromigration.examples.practical.v0.Customer oldCustomer : oldBranch.customers) 49 | { 50 | final Customer newCustomer = 51 | new Customer(); 52 | newCustomer.name = oldCustomer.name; 53 | newCustomer.address = new Address(); 54 | newCustomer.address.number = oldCustomer.number; 55 | newCustomer.address.street = oldCustomer.street; 56 | newCustomer.address.city = oldCustomer.city; 57 | newBranch.customers.add(newCustomer); 58 | } 59 | context.getStorageManager().setRoot(newBranch); 60 | context.getStorageManager().storeRoot(); 61 | Logger.getGlobal().info("Done executing Script for v1.0"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/embedded/UpdateToV2_0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.embedded; 17 | 18 | import java.util.logging.Logger; 19 | 20 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 21 | import software.xdev.micromigration.eclipsestore.MigrationScript; 22 | import software.xdev.micromigration.examples.practical.v1_and_higher.BusinessBranch; 23 | import software.xdev.micromigration.examples.practical.v1_and_higher.Customer; 24 | import software.xdev.micromigration.scripts.Context; 25 | import software.xdev.micromigration.version.MigrationVersion; 26 | 27 | 28 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 29 | public class UpdateToV2_0 implements MigrationScript 30 | { 31 | @Override 32 | public MigrationVersion getTargetVersion() 33 | { 34 | return new MigrationVersion(2, 0); 35 | } 36 | 37 | @Override 38 | public void migrate(final Context context) 39 | { 40 | Logger.getGlobal().info("Executing Script for v2.0..."); 41 | final BusinessBranch branch = context.getMigratingObject(); 42 | final Customer newCustomer = new Customer(); 43 | newCustomer.name = "Stevie Nicks"; 44 | newCustomer.address.number = 5; 45 | newCustomer.address.street = "Fleetwood Street"; 46 | newCustomer.address.city = "Phoenix"; 47 | branch.customers.add(newCustomer); 48 | context.getStorageManager().store(branch.customers); 49 | Logger.getGlobal().info("Done executing Script for v2.0"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/migration_manager/MainPracticalWithMigrationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.migration_manager; 17 | 18 | import org.eclipse.store.storage.embedded.types.EmbeddedStorage; 19 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import software.xdev.micromigration.eclipsestore.MigrationManager; 24 | import software.xdev.micromigration.examples.practical.v0.BusinessBranch; 25 | import software.xdev.micromigration.migrater.ExplicitMigrater; 26 | import software.xdev.micromigration.version.VersionedObject; 27 | 28 | 29 | /** 30 | * A practical example of usage in a few steps: 31 | *
    32 | *
  • v0.0: Storage is created without any updates. Only stores a new {@link BusinessBranch} 33 | *
  • v1.0: The BusinessBranch has a new implementation 34 | * {@link software.xdev.micromigration.examples.practical.v1_and_higher.BusinessBranch}. 35 | * The old branch is converted to the new implementation through the {@link UpdateToV1_0} script. 36 | *
  • v2.0: A new customer is added through the {@link UpdateToV2_0} script. 37 | *
38 | * The storage is restarted after every update to simulate a complete lifecycle of the datastore. 39 | */ 40 | @SuppressWarnings("java:S2629") 41 | public final class MainPracticalWithMigrationManager 42 | { 43 | private static final Logger LOG = LoggerFactory.getLogger(MainPracticalWithMigrationManager.class); 44 | 45 | /** 46 | * Suppressed Warning "unchecked" because it is given, that the correct object is returned. 47 | */ 48 | @SuppressWarnings("unchecked") 49 | public static void main(final String[] args) 50 | { 51 | // V0.0 52 | try(final EmbeddedStorageManager storageManager = EmbeddedStorage.start()) 53 | { 54 | final VersionedObject versionedBranch = 55 | new VersionedObject<>(BusinessBranch.createDummyBranch()); 56 | storageManager.setRoot(versionedBranch); 57 | storageManager.storeRoot(); 58 | LOG.info(storageManager.root().toString()); 59 | } 60 | 61 | // V1.0 62 | try(final EmbeddedStorageManager storageManager = EmbeddedStorage.start()) 63 | { 64 | final ExplicitMigrater migraterWithV1 = new ExplicitMigrater(new UpdateToV1_0()); 65 | final VersionedObject versionedBranch = 66 | (VersionedObject)storageManager.root(); 67 | new MigrationManager(versionedBranch, migraterWithV1, storageManager) 68 | .migrate(versionedBranch); 69 | LOG.info(storageManager.root().toString()); 70 | } 71 | 72 | // V2.0 73 | try(final EmbeddedStorageManager storageManager = EmbeddedStorage.start()) 74 | { 75 | final ExplicitMigrater migraterWithV2 = new ExplicitMigrater(new UpdateToV1_0(), new UpdateToV2_0()); 76 | final VersionedObject versionedBranch = 77 | (VersionedObject)storageManager.root(); 78 | new MigrationManager(versionedBranch, migraterWithV2, storageManager) 79 | .migrate(versionedBranch); 80 | LOG.info(storageManager.root().toString()); 81 | } 82 | } 83 | 84 | private MainPracticalWithMigrationManager() 85 | { 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/migration_manager/UpdateToV1_0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.migration_manager; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 22 | import software.xdev.micromigration.eclipsestore.MigrationScript; 23 | import software.xdev.micromigration.examples.practical.v0.BusinessBranch; 24 | import software.xdev.micromigration.examples.practical.v0.Customer; 25 | import software.xdev.micromigration.examples.practical.v1_and_higher.Address; 26 | import software.xdev.micromigration.scripts.Context; 27 | import software.xdev.micromigration.version.MigrationVersion; 28 | import software.xdev.micromigration.version.VersionedObject; 29 | 30 | 31 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 32 | public class UpdateToV1_0 implements MigrationScript> 33 | { 34 | private static final Logger LOG = LoggerFactory.getLogger(UpdateToV1_0.class); 35 | 36 | @Override 37 | public MigrationVersion getTargetVersion() 38 | { 39 | return new MigrationVersion(1, 0); 40 | } 41 | 42 | @Override 43 | public void migrate(final Context, MigrationEmbeddedStorageManager> context) 44 | { 45 | LOG.info("Executing Script for v1.0..."); 46 | final VersionedObject versionedBranch = context.getMigratingObject(); 47 | final BusinessBranch oldBranch = 48 | (BusinessBranch)versionedBranch.getObject(); 49 | final software.xdev.micromigration.examples.practical.v1_and_higher.BusinessBranch newBranch = 50 | new software.xdev.micromigration.examples.practical.v1_and_higher.BusinessBranch(); 51 | for(final Customer oldCustomer : oldBranch.customers) 52 | { 53 | final software.xdev.micromigration.examples.practical.v1_and_higher.Customer newCustomer = 54 | new software.xdev.micromigration.examples.practical.v1_and_higher.Customer(); 55 | newCustomer.name = oldCustomer.name; 56 | newCustomer.address = new Address(); 57 | newCustomer.address.number = oldCustomer.number; 58 | newCustomer.address.street = oldCustomer.street; 59 | newCustomer.address.city = oldCustomer.city; 60 | newBranch.customers.add(newCustomer); 61 | } 62 | versionedBranch.setObject(newBranch); 63 | context.getStorageManager().store(versionedBranch); 64 | LOG.info("Done executing Script for v1.0"); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/migration_manager/UpdateToV2_0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.migration_manager; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 22 | import software.xdev.micromigration.eclipsestore.MigrationScript; 23 | import software.xdev.micromigration.examples.practical.v1_and_higher.BusinessBranch; 24 | import software.xdev.micromigration.examples.practical.v1_and_higher.Customer; 25 | import software.xdev.micromigration.scripts.Context; 26 | import software.xdev.micromigration.version.MigrationVersion; 27 | import software.xdev.micromigration.version.VersionedObject; 28 | 29 | 30 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 31 | public class UpdateToV2_0 implements MigrationScript> 32 | { 33 | private static final Logger LOG = LoggerFactory.getLogger(UpdateToV2_0.class); 34 | 35 | @Override 36 | public MigrationVersion getTargetVersion() 37 | { 38 | return new MigrationVersion(2, 0); 39 | } 40 | 41 | @Override 42 | public void migrate(final Context, MigrationEmbeddedStorageManager> context) 43 | { 44 | LOG.info("Executing Script for v2.0..."); 45 | final VersionedObject versionedBranch = context.getMigratingObject(); 46 | final BusinessBranch branch = versionedBranch.getObject(); 47 | final Customer newCustomer = new Customer(); 48 | newCustomer.name = "Stevie Nicks"; 49 | newCustomer.address.number = 5; 50 | newCustomer.address.street = "Fleetwood Street"; 51 | newCustomer.address.city = "Phoenix"; 52 | branch.customers.add(newCustomer); 53 | context.getStorageManager().store(branch.customers); 54 | LOG.info("Done executing Script for v2.0"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/v0/BusinessBranch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.v0; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | 23 | @SuppressWarnings("checkstyle:VisibilityModifier") 24 | public class BusinessBranch 25 | { 26 | public final List customers = new ArrayList<>(); 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return "Branch v0\n" 32 | + "Customers:\n" 33 | + this.customers.stream() 34 | .map(c -> c.name) 35 | .collect(Collectors.joining("\n")); 36 | } 37 | 38 | public static BusinessBranch createDummyBranch() 39 | { 40 | final BusinessBranch branch = new BusinessBranch(); 41 | final Customer customer1 = new Customer(); 42 | customer1.name = "Mick Fleetwood"; 43 | customer1.number = 1; 44 | customer1.street = "Fleetwood Street"; 45 | customer1.city = "Redruth"; 46 | branch.customers.add(customer1); 47 | final Customer customer2 = new Customer(); 48 | customer2.name = "Lindsey Buckingham"; 49 | customer2.number = 2; 50 | customer2.street = "Mac Street"; 51 | customer2.city = "Palo Alto"; 52 | branch.customers.add(customer2); 53 | return branch; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/v0/Customer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.v0; 17 | 18 | @SuppressWarnings({"checkstyle:VisibilityModifier", "java:S1104"}) 19 | public class Customer 20 | { 21 | public String name; 22 | 23 | // Oversimplified old address format 24 | public int number; 25 | public String street; 26 | public String city; 27 | } 28 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/v1_and_higher/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.v1_and_higher; 17 | 18 | @SuppressWarnings({"checkstyle:VisibilityModifier", "java:S1104"}) 19 | public class Address 20 | { 21 | public int number; 22 | public String street; 23 | public String city; 24 | } 25 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/v1_and_higher/BusinessBranch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.v1_and_higher; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | 23 | @SuppressWarnings("checkstyle:VisibilityModifier") 24 | public class BusinessBranch 25 | { 26 | public final List customers = new ArrayList<>(); 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return "Branch v1 and higher\n" 32 | + "Customers:\n" 33 | + this.customers.stream() 34 | .map(c -> c.name) 35 | .collect(Collectors.joining("\n")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/practical/v1_and_higher/Customer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.practical.v1_and_higher; 17 | 18 | @SuppressWarnings({"checkstyle:VisibilityModifier", "java:S1104"}) 19 | public class Customer 20 | { 21 | public String name; 22 | public Address address = new Address(); 23 | } 24 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/reflective/MainReflective.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.reflective; 17 | 18 | import java.util.Date; 19 | import java.util.logging.Logger; 20 | 21 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 22 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 23 | import software.xdev.micromigration.migrater.reflection.ReflectiveMigrater; 24 | import software.xdev.micromigration.migrater.reflection.ScriptInstantiationException; 25 | 26 | 27 | /** 28 | * Shows the usage of the {@link ReflectiveMigrater}. Very simple. 29 | */ 30 | @SuppressWarnings("java:S2629") 31 | public final class MainReflective 32 | { 33 | public static void main(final String[] args) 34 | { 35 | try 36 | { 37 | final ReflectiveMigrater migrater = 38 | new ReflectiveMigrater("software.xdev.micromigration.examples.reflective.scripts"); 39 | final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start(migrater); 40 | Logger.getGlobal().info(storageManager.root().toString()); 41 | if(storageManager.root() == null) 42 | { 43 | storageManager.setRoot("Hello World! @ " + new Date()); 44 | } 45 | storageManager.storeRoot(); 46 | storageManager.shutdown(); 47 | } 48 | catch(final IllegalArgumentException | SecurityException | ScriptInstantiationException e) 49 | { 50 | throw new IllegalStateException("Could not initiate migration script", e); 51 | } 52 | } 53 | 54 | private MainReflective() 55 | { 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/reflective/scripts/UpdateToV1_0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.reflective.scripts; 17 | 18 | import java.util.Date; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 24 | import software.xdev.micromigration.eclipsestore.MigrationScript; 25 | import software.xdev.micromigration.scripts.Context; 26 | import software.xdev.micromigration.version.MigrationVersion; 27 | 28 | 29 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 30 | public class UpdateToV1_0 implements MigrationScript 31 | { 32 | private static final Logger LOG = LoggerFactory.getLogger(UpdateToV1_0.class); 33 | 34 | @Override 35 | public MigrationVersion getTargetVersion() 36 | { 37 | return new MigrationVersion(1, 0); 38 | } 39 | 40 | @Override 41 | public void migrate(final Context context) 42 | { 43 | LOG.info("Update {} executed", this.getTargetVersion()); 44 | context.getStorageManager().setRoot("Hello World! @ " + new Date() + " Update 1.0"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-migration-demo/src/main/java/software/xdev/micromigration/examples/reflective/scripts/UpdateToV1_1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software GmbH (https://xdev.software) 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 | * http://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 software.xdev.micromigration.examples.reflective.scripts; 17 | 18 | import java.util.Date; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 24 | import software.xdev.micromigration.eclipsestore.MigrationScript; 25 | import software.xdev.micromigration.scripts.Context; 26 | import software.xdev.micromigration.version.MigrationVersion; 27 | 28 | 29 | @SuppressWarnings({"checkstyle:TypeName", "java:S101"}) 30 | public class UpdateToV1_1 implements MigrationScript 31 | { 32 | private static final Logger LOG = LoggerFactory.getLogger(UpdateToV1_1.class); 33 | 34 | @Override 35 | public MigrationVersion getTargetVersion() 36 | { 37 | return new MigrationVersion(1, 1); 38 | } 39 | 40 | @Override 41 | public void migrate(final Context context) 42 | { 43 | LOG.info("Update {} executed", this.getTargetVersion()); 44 | context.getStorageManager().setRoot("Hello World! @ " + new Date() + " Update 1.1"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/eclipsestore/MigrationEmbeddedStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore; 17 | 18 | import java.nio.file.Path; 19 | import java.util.Objects; 20 | 21 | import org.eclipse.store.afs.nio.types.NioFileSystem; 22 | import org.eclipse.store.storage.embedded.types.EmbeddedStorage; 23 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation; 24 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager; 25 | import org.eclipse.store.storage.types.Storage; 26 | import org.eclipse.store.storage.types.StorageConfiguration; 27 | 28 | import software.xdev.micromigration.migrater.MicroMigrater; 29 | 30 | 31 | /** 32 | * Provides static utility calls to create the {@link MigrationEmbeddedStorageManager} for updateable datastores. 33 | * Basically a wrapper for the utility class {@link EmbeddedStorage}. 34 | */ 35 | public final class MigrationEmbeddedStorage 36 | { 37 | /** 38 | * Creates a {@link MigrationEmbeddedStorageManager} with the given {@link MicroMigrater}. Uses the 39 | * {@link EmbeddedStorageFoundation#New()} configuration for the actual {@link EmbeddedStorageManager}. 40 | *

Warning "resource" is suppressed because it is used and closed in the 41 | * {@link MigrationEmbeddedStorageManager}. 42 | * 43 | * @param migrater which is used as source for the migration scripts 44 | * @return the created storage manager with the given migrater 45 | */ 46 | @SuppressWarnings("java:S2095") 47 | public static MigrationEmbeddedStorageManager start(final MicroMigrater migrater) 48 | { 49 | Objects.requireNonNull(migrater); 50 | return new MigrationEmbeddedStorageManager( 51 | createStorageManager(), 52 | migrater 53 | ).start(); 54 | } 55 | 56 | /** 57 | * Creates a {@link MigrationEmbeddedStorageManager} with the given {@link MicroMigrater}. Uses the 58 | * {@link EmbeddedStorageFoundation#New()} configuration for the actual {@link EmbeddedStorageManager}. 59 | *

Warning "resource" is suppressed because it is used and closed in the 60 | * {@link MigrationEmbeddedStorageManager}. 61 | * 62 | * @param storageDirectory is used as the base directory for the datastore 63 | * @param migrater which is used as source for the migration scripts 64 | * @return the created storage manager with the given migrater 65 | */ 66 | @SuppressWarnings("java:S2095") 67 | public static MigrationEmbeddedStorageManager start( 68 | final Path storageDirectory, 69 | final MicroMigrater migrater 70 | ) 71 | { 72 | Objects.requireNonNull(migrater); 73 | Objects.requireNonNull(storageDirectory); 74 | 75 | return new MigrationEmbeddedStorageManager( 76 | createStorageManager(storageDirectory), 77 | migrater 78 | ).start(); 79 | } 80 | 81 | private static EmbeddedStorageManager createStorageManager(final Path storageDirectory) 82 | { 83 | final NioFileSystem fileSystem = NioFileSystem.New(); 84 | return EmbeddedStorageFoundation.New() 85 | .setConfiguration( 86 | StorageConfiguration.Builder() 87 | .setStorageFileProvider( 88 | Storage.FileProviderBuilder(fileSystem) 89 | .setDirectory(fileSystem.ensureDirectoryPath(storageDirectory.toAbsolutePath().toString())) 90 | .createFileProvider() 91 | ) 92 | .createConfiguration() 93 | ) 94 | .createEmbeddedStorageManager(); 95 | } 96 | 97 | private static EmbeddedStorageManager createStorageManager() 98 | { 99 | return EmbeddedStorageFoundation.New() 100 | .setConfiguration( 101 | StorageConfiguration.Builder().createConfiguration() 102 | ) 103 | .createEmbeddedStorageManager(); 104 | } 105 | 106 | private MigrationEmbeddedStorage() 107 | { 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/eclipsestore/MigrationEmbeddedStorageManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore; 17 | 18 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager; 19 | 20 | import software.xdev.micromigration.migrater.MicroMigrater; 21 | import software.xdev.micromigration.version.Versioned; 22 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 23 | 24 | 25 | /** 26 | * Specific implementation of the {@link VersionAgnosticMigrationEmbeddedStorageManager} for one specific version. 27 | * @see VersionAgnosticMigrationEmbeddedStorageManager 28 | */ 29 | public class MigrationEmbeddedStorageManager 30 | extends VersionAgnosticMigrationEmbeddedStorageManager 31 | { 32 | /** 33 | * @param nativeManager which will be used as the underlying storage manager. Almost all methods are only rerouted 34 | * to this native manager. Only {@link #start()}, {@link #root()} and {@link #setRoot(Object)} 35 | * are intercepted and a {@link Versioned} is placed between the requests. 36 | * @param migrater which is used as source for the migration scripts 37 | */ 38 | public MigrationEmbeddedStorageManager( 39 | final EmbeddedStorageManager nativeManager, 40 | final MicroMigrater migrater 41 | ) 42 | { 43 | super(new TunnelingEmbeddedStorageManager(nativeManager), migrater); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/eclipsestore/MigrationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore; 17 | 18 | import java.util.function.Consumer; 19 | import java.util.function.Supplier; 20 | 21 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager; 22 | 23 | import software.xdev.micromigration.migrater.MicroMigrater; 24 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 25 | import software.xdev.micromigration.version.MigrationVersion; 26 | import software.xdev.micromigration.version.Versioned; 27 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationManager; 28 | 29 | 30 | /** 31 | * Specific implementation of the {@link VersionAgnosticMigrationManager}. 32 | * 33 | * @see VersionAgnosticMigrationManager 34 | */ 35 | public class MigrationManager extends VersionAgnosticMigrationManager 36 | { 37 | /** 38 | * Much more complicated constructor than 39 | * {@link MigrationManager#MigrationManager(Versioned, MicroMigrater, EmbeddedStorageManager)} 40 | * 41 | * @param currentVersionGetter which supplies the current version of the object to update. 42 | * @param currentVersionSetter which sets the new version of the object in some membervariable. This Consumer is 43 | * not 44 | * supposed to store the version, but only save it in some membervariable to be stored 45 | * after. 46 | * @param currentVersionStorer which is supposed to store the new version of the object somewhere in the datastore. 47 | * @param migrater does the actual migration with the given {@link VersionAgnosticMigrationScript} 48 | * @param storageManager for the {@link VersionAgnosticMigrationScript}s to use. Is not used for the storing 49 | * of the new version. 50 | */ 51 | public MigrationManager( 52 | final Supplier currentVersionGetter, 53 | final Consumer currentVersionSetter, 54 | final Consumer currentVersionStorer, 55 | final MicroMigrater migrater, 56 | final EmbeddedStorageManager storageManager 57 | ) 58 | { 59 | super( 60 | currentVersionGetter, 61 | currentVersionSetter, 62 | currentVersionStorer, 63 | migrater, 64 | new MigrationEmbeddedStorageManager(storageManager, migrater)); 65 | } 66 | 67 | /** 68 | * Simple Constructor. 69 | * 70 | * @param versionedObject which provides getter and setter for the current version. This object will be stored 71 | * after 72 | * the {@link VersionAgnosticMigrationScript}s are executed. 73 | * @param migrater does the actual migration with the given {@link VersionAgnosticMigrationScript} 74 | * @param storageManager for the {@link VersionAgnosticMigrationScript}s to use. Is not used for the storing of 75 | * the 76 | * new version. 77 | */ 78 | public MigrationManager( 79 | final Versioned versionedObject, 80 | final MicroMigrater migrater, 81 | final EmbeddedStorageManager storageManager 82 | ) 83 | { 84 | super(versionedObject, migrater, new MigrationEmbeddedStorageManager(storageManager, migrater)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/eclipsestore/MigrationScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore; 17 | 18 | import software.xdev.micromigration.scripts.Context; 19 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 20 | 21 | 22 | /** 23 | * Interface for scripts to migrate / update datastores. 24 | *

25 | * One script is supposed to bring a datastore from a lower version to the target version. After the 26 | * {@link VersionAgnosticMigrationScript#migrate(Context)} method is called, the target version is reached. 27 | *

28 | * This is a shorthand for {@link VersionAgnosticMigrationScript} 29 | */ 30 | public interface MigrationScript extends VersionAgnosticMigrationScript 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/migrater/AbstractMigrater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater; 17 | 18 | import java.time.Clock; 19 | import java.time.LocalDateTime; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | import java.util.TreeSet; 24 | import java.util.function.Consumer; 25 | 26 | import software.xdev.micromigration.notification.ScriptExecutionNotificationWithScriptReference; 27 | import software.xdev.micromigration.scripts.Context; 28 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 29 | import software.xdev.micromigration.version.MigrationVersion; 30 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 31 | 32 | 33 | /** 34 | * Provides the basic functionality to apply {@link VersionAgnosticMigrationScript}s to a datastore. 35 | */ 36 | public abstract class AbstractMigrater implements MicroMigrater 37 | { 38 | private final List> notificationConsumers = 39 | new ArrayList<>(); 40 | private Clock clock = Clock.systemDefaultZone(); 41 | 42 | @Override 43 | public void registerNotificationConsumer( 44 | final Consumer notificationConsumer) 45 | { 46 | this.notificationConsumers.add(notificationConsumer); 47 | } 48 | 49 | @Override 50 | public > MigrationVersion migrateToNewest( 51 | final MigrationVersion fromVersion, 52 | final E storageManager, 53 | final Object root 54 | ) 55 | { 56 | Objects.requireNonNull(storageManager); 57 | 58 | final TreeSet> sortedScripts = this.getSortedScripts(); 59 | if(!sortedScripts.isEmpty()) 60 | { 61 | return this.migrateToVersion( 62 | fromVersion, 63 | this.getSortedScripts().last().getTargetVersion(), 64 | storageManager, 65 | root 66 | ); 67 | } 68 | return fromVersion; 69 | } 70 | 71 | @SuppressWarnings("unchecked") 72 | @Override 73 | public > MigrationVersion migrateToVersion( 74 | final MigrationVersion fromVersion, 75 | final MigrationVersion targetVersion, 76 | final E storageManager, 77 | final Object objectToMigrate 78 | ) 79 | { 80 | Objects.requireNonNull(targetVersion); 81 | Objects.requireNonNull(storageManager); 82 | 83 | MigrationVersion updateVersionWhichWasExecuted = fromVersion; 84 | for(final VersionAgnosticMigrationScript script : this.getSortedScripts()) 85 | { 86 | final VersionAgnosticMigrationScript castedScript = (VersionAgnosticMigrationScript)script; 87 | if((fromVersion == null || MigrationVersion.COMPARATOR.compare(fromVersion, script.getTargetVersion()) < 0) 88 | && MigrationVersion.COMPARATOR.compare(script.getTargetVersion(), targetVersion) <= 0) 89 | { 90 | LocalDateTime startDate = null; 91 | final MigrationVersion versionBeforeUpdate = updateVersionWhichWasExecuted; 92 | if(!this.notificationConsumers.isEmpty()) 93 | { 94 | startDate = LocalDateTime.now(this.clock); 95 | } 96 | updateVersionWhichWasExecuted = 97 | this.migrateWithScript(castedScript, storageManager, objectToMigrate); 98 | if(!this.notificationConsumers.isEmpty()) 99 | { 100 | final ScriptExecutionNotificationWithScriptReference scriptNotification = 101 | new ScriptExecutionNotificationWithScriptReference( 102 | script, 103 | versionBeforeUpdate, 104 | updateVersionWhichWasExecuted, 105 | startDate, 106 | LocalDateTime.now(this.clock) 107 | ); 108 | this.notificationConsumers.forEach(consumer -> consumer.accept(scriptNotification)); 109 | } 110 | } 111 | } 112 | return updateVersionWhichWasExecuted; 113 | } 114 | 115 | @SuppressWarnings("unchecked") 116 | private > MigrationVersion migrateWithScript( 117 | final VersionAgnosticMigrationScript script, 118 | final E storageManager, 119 | final Object objectToMigrate 120 | ) 121 | { 122 | final T castedObjectToMigrate = (T)objectToMigrate; 123 | script.migrate(new Context<>(castedObjectToMigrate, storageManager)); 124 | return script.getTargetVersion(); 125 | } 126 | 127 | /** 128 | * Checks if the given {@link VersionAgnosticMigrationScript} is not already registered in the 129 | * {@link #getSortedScripts()}. 130 | * 131 | * @param scriptToCheck It's target version is checked, if it is not already registered. 132 | * @throws VersionAlreadyRegisteredException if script is already registered. 133 | */ 134 | protected void checkIfVersionIsAlreadyRegistered(final VersionAgnosticMigrationScript scriptToCheck) 135 | { 136 | // Check if same version is not already registered 137 | for(final VersionAgnosticMigrationScript alreadyRegisteredScript : this.getSortedScripts()) 138 | { 139 | if(MigrationVersion.COMPARATOR.compare( 140 | alreadyRegisteredScript.getTargetVersion(), 141 | scriptToCheck.getTargetVersion()) == 0) 142 | { 143 | // Two scripts with the same version are not allowed to get registered. 144 | throw new VersionAlreadyRegisteredException( 145 | alreadyRegisteredScript.getTargetVersion(), 146 | alreadyRegisteredScript, 147 | scriptToCheck 148 | ); 149 | } 150 | } 151 | } 152 | 153 | /** 154 | * Change used clock for notifications from {@link #registerNotificationConsumer(Consumer)}. 155 | * 156 | * @param clock is used when a 157 | * {@link software.xdev.micromigration.notification.ScriptExecutionNotificationWithoutScriptReference} 158 | * is created 159 | * @return self 160 | */ 161 | public AbstractMigrater withClock(final Clock clock) 162 | { 163 | this.clock = clock; 164 | return this; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/migrater/ExplicitMigrater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater; 17 | 18 | import java.util.TreeSet; 19 | 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | 22 | 23 | /** 24 | * Contains all the available scripts to migrate the datastore to a certain version. 25 | *

26 | * This class needs explicit scripts which are then included in the migration process. 27 | */ 28 | public class ExplicitMigrater extends AbstractMigrater 29 | { 30 | private final TreeSet> sortedScripts = new TreeSet<>( 31 | VersionAgnosticMigrationScript.COMPARATOR); 32 | 33 | /** 34 | * @param scripts are all the scripts that are executed, if the current version is lower than this of the 35 | * script
36 | * Versions of the scripts must be unique. That means that no version is allowed multiple times in 37 | * the migrater. 38 | * @throws VersionAlreadyRegisteredException if two scripts have the same version 39 | */ 40 | @SuppressWarnings("PMD.UseArraysAsList") 41 | public ExplicitMigrater(final VersionAgnosticMigrationScript... scripts) 42 | { 43 | for(final VersionAgnosticMigrationScript script : scripts) 44 | { 45 | this.checkIfVersionIsAlreadyRegistered(script); 46 | this.sortedScripts.add(script); 47 | } 48 | } 49 | 50 | @Override 51 | public TreeSet> getSortedScripts() 52 | { 53 | return this.sortedScripts; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/migrater/MicroMigrater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater; 17 | 18 | import java.util.TreeSet; 19 | import java.util.function.Consumer; 20 | 21 | import software.xdev.micromigration.notification.ScriptExecutionNotificationWithScriptReference; 22 | import software.xdev.micromigration.scripts.Context; 23 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 24 | import software.xdev.micromigration.version.MigrationVersion; 25 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 26 | 27 | 28 | /** 29 | * Executes all the available scripts to migrate the datastore to a certain version. 30 | */ 31 | public interface MicroMigrater 32 | { 33 | /** 34 | * @return all the contained {@link VersionAgnosticMigrationScript}s, sorted by their {@link MigrationVersion} 35 | * ascending. 36 | */ 37 | @SuppressWarnings("java:S1452") 38 | TreeSet> getSortedScripts(); 39 | 40 | /** 41 | * Executes all the scripts that are available to the migrater. Only scripts with a higher target version than the 42 | * given fromVersion are executed.
Scripts are executed one after another from the lowest to the highest 43 | * version. 44 | *

45 | * Example:
46 | * Current version is 1.0.0
Scripts for v1.1.0, v2.0.0 and v1.2.1 are available
Scripts are chain executed 47 | * like v1.1.0 then v1.2.1 then v2.0.0 48 | * 49 | * @param fromVersion is the current version of the datastore. Scripts for lower versions then the fromVersion 50 | * are not executed. 51 | * @param storageManager is relayed to the scripts {@link VersionAgnosticMigrationScript#migrate(Context)} method. 52 | * This way the script can call 53 | * {@link VersionAgnosticMigrationEmbeddedStorageManager#store(Object)} or another method on 54 | * the storage manager. 55 | * @param root is relayed to the scripts {@link VersionAgnosticMigrationScript#migrate(Context)} method. 56 | * This way the script can change something within the root object. 57 | * @param the {@link VersionAgnosticMigrationEmbeddedStorageManager} which contains the migrating 58 | * object 59 | * @return the target version of the last executed script 60 | */ 61 | > MigrationVersion migrateToNewest( 62 | MigrationVersion fromVersion, 63 | E storageManager, 64 | Object root 65 | ); 66 | 67 | /** 68 | * Executes all the scripts that are available to the migrater until the given targetVersion is reached. Only 69 | * scripts with a higher target version than the given fromVersion are executed.
Scripts are executed one after 70 | * another from the lowest to the highest version. 71 | *

72 | * Example:
73 | * Current version is 1.0.0
Scripts for v1.1.0, v2.0.0 and v1.2.1 are available
Scripts are chain executed 74 | * like v1.1.0 then v1.2.1 then v2.0.0 75 | * 76 | * @param fromVersion is the current version of the datastore. Scripts for lower versions then the fromVersion 77 | * are not executed. 78 | * @param targetVersion is the highest allowed script version. Scripts which have a higher version won't be 79 | * exectued. 80 | * @param storageManager is relayed to the scripts {@link VersionAgnosticMigrationScript#migrate(Context)} method. 81 | * This way the script can call EmbeddedStorageManager#store or another method on the 82 | * storage 83 | * manager. 84 | * @param objectToMigrate is relayed to the scripts {@link VersionAgnosticMigrationScript#migrate(Context)} method. 85 | * This way the script can change something within the object to migrate. 86 | * @param the {@link VersionAgnosticMigrationEmbeddedStorageManager} which contains the migrating 87 | * object 88 | * @return the target version of the last executed script 89 | */ 90 | > MigrationVersion migrateToVersion( 91 | MigrationVersion fromVersion, 92 | MigrationVersion targetVersion, 93 | E storageManager, 94 | Object objectToMigrate 95 | ); 96 | 97 | /** 98 | * Registers a callback to take action when a script is executed. 99 | * 100 | * @param notificationConsumer is executed when a script is used from this migrater. 101 | */ 102 | void registerNotificationConsumer( 103 | Consumer notificationConsumer); 104 | } 105 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/migrater/VersionAlreadyRegisteredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater; 17 | 18 | import java.util.Objects; 19 | 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | /** 25 | * Exception that should be used if two scripts with the same version exist. 26 | */ 27 | @SuppressWarnings({"java:S1948", "java:S1452"}) 28 | public class VersionAlreadyRegisteredException extends RuntimeException 29 | { 30 | /** 31 | * The already registered script with the same version 32 | */ 33 | private final MigrationVersion alreadyRegisteredVersion; 34 | /** 35 | * The version of the already registered script 36 | */ 37 | private final VersionAgnosticMigrationScript alreadyRegisteredScript; 38 | /** 39 | * The script with the same version as {@link #alreadyRegisteredScript}, which should be registered as well 40 | */ 41 | private final VersionAgnosticMigrationScript newScriptToRegister; 42 | 43 | /** 44 | * @param alreadyRegisteredVersion The version of the already registered script 45 | * @param alreadyRegisteredScript The already registered script with the same version 46 | * @param newScriptToRegister The script with the same version as alreadyRegisteredScript, which should be 47 | * registered as well 48 | */ 49 | public VersionAlreadyRegisteredException( 50 | final MigrationVersion alreadyRegisteredVersion, 51 | final VersionAgnosticMigrationScript alreadyRegisteredScript, 52 | final VersionAgnosticMigrationScript newScriptToRegister 53 | ) 54 | { 55 | super("Version " + alreadyRegisteredVersion.toString() 56 | + " is already registered. Versions must be unique within the migrater."); 57 | this.alreadyRegisteredVersion = Objects.requireNonNull(alreadyRegisteredVersion); 58 | this.alreadyRegisteredScript = Objects.requireNonNull(alreadyRegisteredScript); 59 | this.newScriptToRegister = Objects.requireNonNull(newScriptToRegister); 60 | } 61 | 62 | /** 63 | * @return the version of the already registered script 64 | */ 65 | public MigrationVersion getAlreadyRegisteredVersion() 66 | { 67 | return this.alreadyRegisteredVersion; 68 | } 69 | 70 | /** 71 | * @return the already registered script with the same version 72 | */ 73 | public VersionAgnosticMigrationScript getAlreadyRegisteredScript() 74 | { 75 | return this.alreadyRegisteredScript; 76 | } 77 | 78 | /** 79 | * @return the script with the same version as {@link #getAlreadyRegisteredScript()}, which should be registered as 80 | * well 81 | */ 82 | public VersionAgnosticMigrationScript getNewScriptToRegister() 83 | { 84 | return this.newScriptToRegister; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/migrater/reflection/ReflectiveMigrater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.io.UncheckedIOException; 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.lang.reflect.Modifier; 23 | import java.net.URL; 24 | import java.util.ArrayList; 25 | import java.util.Enumeration; 26 | import java.util.List; 27 | import java.util.TreeSet; 28 | 29 | import software.xdev.micromigration.migrater.AbstractMigrater; 30 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 31 | 32 | 33 | /** 34 | * Contains all the available scripts to migrate the datastore to a certain version. 35 | *

36 | * Searches all implementation of {@link VersionAgnosticMigrationScript} in the specified package and it's the sub 37 | * packages. 38 | *

39 | *

40 | * Reflection source: https://stackoverflow.com/a/520344 41 | *

42 | * @author AB 43 | */ 44 | public class ReflectiveMigrater extends AbstractMigrater 45 | { 46 | private static final String CLASS_EXTENSION = ".class"; 47 | 48 | private final TreeSet> sortedScripts = new TreeSet<>( 49 | VersionAgnosticMigrationScript.COMPARATOR); 50 | 51 | /** 52 | * @param packagePath defines the package in which {@link VersionAgnosticMigrationScript}s will be searched. Also 53 | * searches through all sub packages of packagePath 54 | * @throws ScriptInstantiationException if a class in the given package could not be instantiated 55 | */ 56 | @SuppressWarnings("unchecked") 57 | public ReflectiveMigrater(final String packagePath) 58 | { 59 | getClasses(packagePath) 60 | .stream() 61 | .filter(c -> !Modifier.isAbstract(c.getModifiers())) 62 | .filter(VersionAgnosticMigrationScript.class::isAssignableFrom) 63 | .map(c -> (Class)c) 64 | .map(this::instantiateClass) 65 | .forEach(instantiateScript -> { 66 | this.checkIfVersionIsAlreadyRegistered(instantiateScript); 67 | this.sortedScripts.add(instantiateScript); 68 | }); 69 | } 70 | 71 | @SuppressWarnings("rawtypes") 72 | private VersionAgnosticMigrationScript instantiateClass( 73 | final Class scriptClass) 74 | { 75 | try 76 | { 77 | return scriptClass.getDeclaredConstructor().newInstance(); 78 | } 79 | catch(final InstantiationException 80 | | IllegalAccessException 81 | | IllegalArgumentException 82 | | InvocationTargetException 83 | | NoSuchMethodException 84 | | SecurityException e 85 | ) 86 | { 87 | throw new ScriptInstantiationException("Could not instantiate class " + scriptClass.getName(), e); 88 | } 89 | } 90 | 91 | /** 92 | * Scans all classes accessible from the context class loader which belong to the given package and subpackages. 93 | * 94 | * @param packageName The base package 95 | * @return The classes 96 | */ 97 | private static List> getClasses(final String packageName) 98 | { 99 | try 100 | { 101 | final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 102 | assert classLoader != null; 103 | final String path = packageName.replace('.', '/'); 104 | final Enumeration resources = classLoader.getResources(path); 105 | final List dirs = new ArrayList<>(); 106 | while(resources.hasMoreElements()) 107 | { 108 | final URL resource = resources.nextElement(); 109 | dirs.add(new File(resource.getFile())); 110 | } 111 | final ArrayList> classes = new ArrayList<>(); 112 | for(final File directory : dirs) 113 | { 114 | classes.addAll(findClasses(directory, packageName)); 115 | } 116 | return classes; 117 | } 118 | catch(final ClassNotFoundException e) 119 | { 120 | throw new IllegalStateException("Unable to find class", e); 121 | } 122 | catch(final IOException ioe) 123 | { 124 | throw new UncheckedIOException(ioe); 125 | } 126 | } 127 | 128 | /** 129 | * Recursive method used to find all classes in a given directory and subdirs. 130 | * 131 | * @param directory The base directory 132 | * @param packageName The package name for classes found inside the base directory 133 | * @return The classes 134 | */ 135 | private static List> findClasses(final File directory, final String packageName) 136 | throws ClassNotFoundException 137 | { 138 | if(!directory.exists()) 139 | { 140 | return new ArrayList<>(); 141 | } 142 | 143 | final List> classes = new ArrayList<>(); 144 | for(final File file : directory.listFiles()) 145 | { 146 | if(file.isDirectory()) 147 | { 148 | assert !file.getName().contains("."); 149 | classes.addAll(findClasses(file, packageName + "." + file.getName())); 150 | } 151 | else if(file.getName().endsWith(CLASS_EXTENSION)) 152 | { 153 | classes.add(Class.forName( 154 | packageName + '.' + file.getName() 155 | .substring(0, file.getName().length() - CLASS_EXTENSION.length()))); 156 | } 157 | } 158 | return classes; 159 | } 160 | 161 | @Override 162 | public TreeSet> getSortedScripts() 163 | { 164 | return this.sortedScripts; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/migrater/reflection/ScriptInstantiationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection; 17 | 18 | /** 19 | * Holds information about exceptions if a script class can not be instantiated. 20 | */ 21 | public class ScriptInstantiationException extends RuntimeException 22 | { 23 | /** 24 | * @param message for the exception 25 | * @param cause of the exception 26 | */ 27 | public ScriptInstantiationException(final String message, final Throwable cause) 28 | { 29 | super(message, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/notification/AbstractScriptExecutionNotification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.notification; 17 | 18 | import java.time.LocalDateTime; 19 | 20 | import software.xdev.micromigration.migrater.MicroMigrater; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | /** 25 | * Contains data about the execution of a script by a {@link MicroMigrater}. 26 | */ 27 | public abstract class AbstractScriptExecutionNotification 28 | { 29 | private final MigrationVersion sourceVersion; 30 | private final MigrationVersion targetVersion; 31 | private final LocalDateTime startDate; 32 | private final LocalDateTime endDate; 33 | 34 | /** 35 | * @param sourceVersion original version of the object before executing the script 36 | * @param targetVersion version of the object after executing the script 37 | * @param startDate time when the script was started 38 | * @param endDate time when the script has finished 39 | */ 40 | protected AbstractScriptExecutionNotification( 41 | final MigrationVersion sourceVersion, 42 | final MigrationVersion targetVersion, 43 | final LocalDateTime startDate, 44 | final LocalDateTime endDate 45 | ) 46 | { 47 | super(); 48 | this.sourceVersion = sourceVersion; 49 | this.targetVersion = targetVersion; 50 | this.startDate = startDate; 51 | this.endDate = endDate; 52 | } 53 | 54 | /** 55 | * @return the original version of the object before executing the script 56 | */ 57 | public MigrationVersion getSourceVersion() 58 | { 59 | return this.sourceVersion; 60 | } 61 | 62 | /** 63 | * @return the version of the object after executing the script 64 | */ 65 | public MigrationVersion getTargetVersion() 66 | { 67 | return this.targetVersion; 68 | } 69 | 70 | /** 71 | * @return the time when the script was started 72 | */ 73 | public LocalDateTime getStartDate() 74 | { 75 | return this.startDate; 76 | } 77 | 78 | /** 79 | * @return time when the script has finished 80 | */ 81 | public LocalDateTime getEndDate() 82 | { 83 | return this.endDate; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/notification/ScriptExecutionNotificationWithScriptReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.notification; 17 | 18 | import java.time.LocalDateTime; 19 | 20 | import software.xdev.micromigration.migrater.MicroMigrater; 21 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 22 | import software.xdev.micromigration.version.MigrationVersion; 23 | 24 | 25 | /** 26 | * Contains data about the execution of a script by a {@link MicroMigrater}. 27 | */ 28 | public class ScriptExecutionNotificationWithScriptReference extends AbstractScriptExecutionNotification 29 | { 30 | private final VersionAgnosticMigrationScript executedScript; 31 | 32 | /** 33 | * @param executedScript script that was executed 34 | * @param sourceVersion original version of the object before executing the script 35 | * @param targetVersion version of the object after executing the script 36 | * @param startDate time when the script was started 37 | * @param endDate time when the script has finished 38 | */ 39 | public ScriptExecutionNotificationWithScriptReference( 40 | final VersionAgnosticMigrationScript executedScript, 41 | final MigrationVersion sourceVersion, 42 | final MigrationVersion targetVersion, 43 | final LocalDateTime startDate, 44 | final LocalDateTime endDate 45 | ) 46 | { 47 | super( 48 | sourceVersion, 49 | targetVersion, 50 | startDate, 51 | endDate 52 | ); 53 | this.executedScript = executedScript; 54 | } 55 | 56 | /** 57 | * @return the script that was executed 58 | */ 59 | @SuppressWarnings("java:S1452") 60 | public VersionAgnosticMigrationScript getExecutedScript() 61 | { 62 | return this.executedScript; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/notification/ScriptExecutionNotificationWithoutScriptReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.notification; 17 | 18 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 19 | 20 | /** 21 | * Same as {@link ScriptExecutionNotificationWithScriptReference} but instead of referencing 22 | * the {@link VersionAgnosticMigrationScript} directly, only the name of the script is 23 | * extracted through the class name. 24 | *

25 | * "Why?!" - If you want to persist say a history of your applied scripts in your database and 26 | * you reference your scripts directly, these classes are referenced in your datastore. 27 | * That shouldn't be a problem. Except when you refactor or delete these scripts. 28 | * Usually what's really important is the name of the script. 29 | */ 30 | public class ScriptExecutionNotificationWithoutScriptReference extends AbstractScriptExecutionNotification 31 | { 32 | private final String executedScriptName; 33 | 34 | /** 35 | * @param originalNotification where the reference to the script is deleted and the class name is extracted. 36 | */ 37 | public ScriptExecutionNotificationWithoutScriptReference( 38 | final ScriptExecutionNotificationWithScriptReference originalNotification) 39 | { 40 | super( 41 | originalNotification.getSourceVersion(), 42 | originalNotification.getTargetVersion(), 43 | originalNotification.getStartDate(), 44 | originalNotification.getEndDate() 45 | ); 46 | this.executedScriptName = originalNotification.getExecutedScript().getClass().getSimpleName(); 47 | } 48 | 49 | /** 50 | * @return the name of the script that was extracted. 51 | */ 52 | public String getExecutedScriptName() 53 | { 54 | return this.executedScriptName; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/scripts/Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.scripts; 17 | 18 | /** 19 | * Container that holds necessary information for the execution of an {@link VersionAgnosticMigrationScript} 20 | */ 21 | public class Context 22 | { 23 | private final T migratingObject; 24 | private final E storageManager; 25 | 26 | /** 27 | * @param migratingObject that must be migrated to a new version 28 | * @param storageManager where the migratingObject is stored 29 | */ 30 | public Context( 31 | final T migratingObject, 32 | final E storageManager 33 | ) 34 | { 35 | super(); 36 | this.migratingObject = migratingObject; 37 | this.storageManager = storageManager; 38 | } 39 | 40 | /** 41 | * @return the current object where the migration is executed upon 42 | */ 43 | public T getMigratingObject() 44 | { 45 | return this.migratingObject; 46 | } 47 | 48 | /** 49 | * @return the responsible storage manager for the migrating object 50 | */ 51 | public E getStorageManager() 52 | { 53 | return this.storageManager; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/scripts/ReflectiveVersionMigrationScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.scripts; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 23 | 24 | 25 | /** 26 | * Script which creates the target version of the script through the class name. 27 | *

28 | * Class name has to be in the scheme:
29 | * 30 | * vM_Classname
vM_m_Classname
vM_m_m_Classname
31 | *
32 | * Where v is short for version and is a constant (just a char),
33 | * M is a integer for the major version,
34 | * m is a integer for the minor version
35 | * Classname is a custom String that the user can choose.
36 | * This scheme can basically be extended infinetly. For example: v1_1_2_2_MyUpdateScript 37 | *

38 | * Therefore the character _ can only be used as a seperator of versions and may not be used for other 39 | * purposes. 40 | *

41 | * If the class name has the wrong format, an {@link Error} is thrown. 42 | */ 43 | public abstract class ReflectiveVersionMigrationScript< 44 | T, 45 | E extends VersionAgnosticMigrationEmbeddedStorageManager> 46 | implements VersionAgnosticMigrationScript 47 | { 48 | private static final char PREFIX = 'v'; 49 | private static final String VERSION_SEPERATOR = "_"; 50 | private static final String WRONG_FORMAT_ERROR_MESSAGE = 51 | "Script has invalid class name. Either rename the class to a valid script class name, or implement method " 52 | + "getTargetVersion()."; 53 | 54 | private final MigrationVersion version; 55 | 56 | /** 57 | * @throws Error if the class name has the wrong format 58 | */ 59 | protected ReflectiveVersionMigrationScript() 60 | { 61 | this.version = this.createTargetVersionFromClassName(); 62 | } 63 | 64 | private MigrationVersion createTargetVersionFromClassName() 65 | { 66 | final String implementationClassName = this.getClass().getSimpleName(); 67 | if(PREFIX != implementationClassName.charAt(0)) 68 | { 69 | throw new IllegalArgumentException(WRONG_FORMAT_ERROR_MESSAGE); 70 | } 71 | final String implementationClassNameWithoutPrefix = implementationClassName.substring(1); 72 | final String[] classNameParts = implementationClassNameWithoutPrefix.split(VERSION_SEPERATOR); 73 | if(classNameParts.length < 2) 74 | { 75 | throw new IllegalArgumentException(WRONG_FORMAT_ERROR_MESSAGE); 76 | } 77 | try 78 | { 79 | final List versionNumbers = new ArrayList<>(); 80 | for(int i = 0; i < classNameParts.length - 1; i++) 81 | { 82 | versionNumbers.add(Integer.parseInt(classNameParts[i])); 83 | } 84 | return new MigrationVersion(versionNumbers); 85 | } 86 | catch(final NumberFormatException e) 87 | { 88 | throw new IllegalArgumentException(WRONG_FORMAT_ERROR_MESSAGE, e); 89 | } 90 | } 91 | 92 | @Override 93 | public MigrationVersion getTargetVersion() 94 | { 95 | return this.version; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/scripts/SimpleMigrationScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.scripts; 17 | 18 | import java.util.function.Consumer; 19 | 20 | import software.xdev.micromigration.version.MigrationVersion; 21 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 22 | 23 | 24 | /** 25 | * Provides a simple way to create a migration script with the necessary version and {@link Consumer}. 26 | */ 27 | public class SimpleMigrationScript> 28 | extends SimpleTypedMigrationScript 29 | { 30 | /** 31 | * @param targetVersion to which the script is updating the object 32 | * @param consumer which consumes the object and updates it to the target version 33 | */ 34 | public SimpleMigrationScript( 35 | final MigrationVersion targetVersion, 36 | final Consumer> consumer 37 | ) 38 | { 39 | super(targetVersion, consumer); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/scripts/SimpleTypedMigrationScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.scripts; 17 | 18 | import java.util.Objects; 19 | import java.util.function.Consumer; 20 | 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 23 | 24 | 25 | /** 26 | * Provides a simple way to create a migration script with the necessary version and {@link Consumer}. 27 | */ 28 | public class SimpleTypedMigrationScript> 29 | implements VersionAgnosticMigrationScript 30 | { 31 | private final MigrationVersion version; 32 | private final Consumer> consumer; 33 | 34 | /** 35 | * @param version of the datastore after this script is executed 36 | * @param consumer which is executed to reach the given datastore version 37 | */ 38 | public SimpleTypedMigrationScript( 39 | final MigrationVersion version, 40 | final Consumer> consumer 41 | ) 42 | { 43 | Objects.requireNonNull(version); 44 | Objects.requireNonNull(consumer); 45 | this.version = version; 46 | this.consumer = consumer; 47 | } 48 | 49 | @Override 50 | public MigrationVersion getTargetVersion() 51 | { 52 | return this.version; 53 | } 54 | 55 | @Override 56 | public void migrate(final Context context) 57 | { 58 | this.consumer.accept(context); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/scripts/VersionAgnosticMigrationScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.scripts; 17 | 18 | import java.util.Comparator; 19 | 20 | import software.xdev.micromigration.version.MigrationVersion; 21 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 22 | 23 | 24 | /** 25 | * Interface for scripts to migrate / update datastores. 26 | *

27 | * One script is supposed to bring a datastore from a lower version to the target version. After the 28 | * {@link VersionAgnosticMigrationScript#migrate(Context)} method is called, the target version is reached. 29 | */ 30 | public interface VersionAgnosticMigrationScript> 31 | { 32 | /** 33 | * @return the version of the datastore after this script is executed. 34 | */ 35 | MigrationVersion getTargetVersion(); 36 | 37 | /** 38 | * Execute logic to migrate the given datastore to a newer version of the store. After executing the 39 | * {@link #getTargetVersion()} is reached. 40 | * 41 | * @param context that holds necessary data for the migration 42 | */ 43 | void migrate(Context context); 44 | 45 | /** 46 | * Provides a {@link Comparator} that compares the {@link #getTargetVersion()} of the given scripts 47 | */ 48 | Comparator> COMPARATOR = 49 | (o1, o2) -> MigrationVersion.COMPARATOR.compare(o1.getTargetVersion(), o2.getTargetVersion()); 50 | } 51 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/MigrationVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import java.util.Arrays; 19 | import java.util.Comparator; 20 | import java.util.List; 21 | 22 | 23 | /** 24 | * Defines one version of the EclipseStore datastore. 25 | */ 26 | public class MigrationVersion 27 | { 28 | private final int[] versions; 29 | 30 | /** 31 | * @param versions as integers. For example 1.0.2 would be an array of [1,0,2] 32 | */ 33 | public MigrationVersion(final int... versions) 34 | { 35 | if(versions == null || versions.length == 0) 36 | { 37 | this.versions = new int[]{0}; 38 | } 39 | else 40 | { 41 | this.versions = versions; 42 | } 43 | } 44 | 45 | /** 46 | * @param versionsAsList as integers. For example 1.0.2 would be a list of [1,0,2] 47 | */ 48 | public MigrationVersion(final List versionsAsList) 49 | { 50 | if(versionsAsList == null || versionsAsList.isEmpty()) 51 | { 52 | this.versions = new int[]{0}; 53 | } 54 | else 55 | { 56 | final int[] versionsAsArray = new int[versionsAsList.size()]; 57 | for(int i = 0; i < versionsAsArray.length; i++) 58 | { 59 | versionsAsArray[i] = versionsAsList.get(i); 60 | } 61 | this.versions = versionsAsArray; 62 | } 63 | } 64 | 65 | /** 66 | * @return versions as an array of integers. For example 1.0.2 would be an array of [1,0,2] 67 | */ 68 | public int[] getVersions() 69 | { 70 | return this.versions; 71 | } 72 | 73 | @Override 74 | public String toString() 75 | { 76 | final StringBuilder sb = new StringBuilder("v"); 77 | for(final int version : this.versions) 78 | { 79 | sb.append(version).append('.'); 80 | } 81 | sb.deleteCharAt(sb.length() - 1); 82 | return sb.toString(); 83 | } 84 | 85 | @Override 86 | public int hashCode() 87 | { 88 | final int prime = 31; 89 | int result = 1; 90 | result = prime * result + Arrays.hashCode(this.versions); 91 | return result; 92 | } 93 | 94 | @Override 95 | public boolean equals(final Object obj) 96 | { 97 | if(this == obj) 98 | { 99 | return true; 100 | } 101 | if(obj == null) 102 | { 103 | return false; 104 | } 105 | if(this.getClass() != obj.getClass()) 106 | { 107 | return false; 108 | } 109 | final MigrationVersion other = (MigrationVersion)obj; 110 | return Arrays.equals(this.versions, other.versions); 111 | } 112 | 113 | /** 114 | * Provides a {@link Comparator} that compares the {@link #getVersions()} of the given versions 115 | */ 116 | public static final Comparator COMPARATOR = 117 | Comparator.comparing(MigrationVersion::getVersions, Arrays::compare); 118 | } 119 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/Versioned.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | /** 19 | * Interface used by the MigrationManagers for easier versioning of objects. 20 | */ 21 | public interface Versioned 22 | { 23 | /** 24 | * @param version to set the current version of the object 25 | */ 26 | void setVersion(MigrationVersion version); 27 | 28 | /** 29 | * @return the current version of the object 30 | */ 31 | MigrationVersion getVersion(); 32 | } 33 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/VersionedAndKeeperOfHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import java.util.List; 19 | 20 | import software.xdev.micromigration.notification.ScriptExecutionNotificationWithoutScriptReference; 21 | 22 | /** 23 | * Interface used by the MigrationManagers for easier versioning of objects 24 | * and to keep and read the migration history. 25 | */ 26 | public interface VersionedAndKeeperOfHistory extends Versioned 27 | { 28 | /** 29 | * Adds the information about the executed script to the history book. 30 | * @param executedScriptInformation information about the executed script 31 | */ 32 | void addExecutedScript(ScriptExecutionNotificationWithoutScriptReference executedScriptInformation); 33 | 34 | /** 35 | * @return the complete migration history. That means information about every executed script. 36 | */ 37 | List getMigrationHistory(); 38 | } 39 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/VersionedObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import java.util.Objects; 19 | 20 | 21 | /** 22 | * Simple container to hold a specific object and a correlating version for it. 23 | * 24 | * @param type of the object that's contained 25 | */ 26 | public class VersionedObject implements Versioned 27 | { 28 | private MigrationVersion currentVersion; 29 | private T actualObject; 30 | 31 | /** 32 | * @param actualObject set the actual object which is versioned 33 | */ 34 | public VersionedObject(final T actualObject) 35 | { 36 | this.actualObject = actualObject; 37 | this.currentVersion = new MigrationVersion(0); 38 | } 39 | 40 | @Override 41 | public void setVersion(final MigrationVersion version) 42 | { 43 | Objects.requireNonNull(version); 44 | this.currentVersion = version; 45 | } 46 | 47 | @Override 48 | public MigrationVersion getVersion() 49 | { 50 | return this.currentVersion; 51 | } 52 | 53 | /** 54 | * @param actualObject which is versioned 55 | */ 56 | public void setObject(final T actualObject) 57 | { 58 | this.actualObject = actualObject; 59 | } 60 | 61 | /** 62 | * @return the actual object which is versioned 63 | */ 64 | public T getObject() 65 | { 66 | return this.actualObject; 67 | } 68 | 69 | @Override 70 | public String toString() 71 | { 72 | return this.currentVersion.toString() + "\n" + this.actualObject; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/VersionedObjectWithHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | import software.xdev.micromigration.notification.ScriptExecutionNotificationWithoutScriptReference; 23 | 24 | 25 | /** 26 | * This class is inserted as the root of the datastore and contains only the current version, the actual 27 | * root object and the history of executed scripts. 28 | */ 29 | public class VersionedObjectWithHistory extends VersionedObject implements VersionedAndKeeperOfHistory 30 | { 31 | private final List migrationHistory; 32 | 33 | /** 34 | * @param actualRoot which is stored in the datastore and defined by the user 35 | */ 36 | public VersionedObjectWithHistory(final Object actualRoot) 37 | { 38 | super(actualRoot); 39 | this.migrationHistory = new ArrayList<>(); 40 | } 41 | 42 | @Override 43 | public void addExecutedScript(final ScriptExecutionNotificationWithoutScriptReference executedScriptInformation) 44 | { 45 | this.migrationHistory.add(Objects.requireNonNull(executedScriptInformation)); 46 | } 47 | 48 | @Override 49 | public List getMigrationHistory() 50 | { 51 | return this.migrationHistory; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/VersionedRoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import java.util.Objects; 19 | 20 | 21 | /** 22 | * This class is inserted as the root of the datastore and contains only the current version and the actual root 23 | * object. 24 | */ 25 | public class VersionedRoot implements Versioned 26 | { 27 | private MigrationVersion currentVersion; 28 | private Object actualRoot; 29 | 30 | /** 31 | * @param actualRoot which is stored in the datastore and defined by the user 32 | */ 33 | public VersionedRoot(final Object actualRoot) 34 | { 35 | this.actualRoot = actualRoot; 36 | this.currentVersion = new MigrationVersion(0); 37 | } 38 | 39 | @Override 40 | public void setVersion(final MigrationVersion version) 41 | { 42 | Objects.requireNonNull(version); 43 | this.currentVersion = version; 44 | } 45 | 46 | @Override 47 | public MigrationVersion getVersion() 48 | { 49 | return this.currentVersion; 50 | } 51 | 52 | /** 53 | * @param actualRoot which is stored in the datastore and defined by the user 54 | */ 55 | public void setRoot(final Object actualRoot) 56 | { 57 | this.actualRoot = actualRoot; 58 | } 59 | 60 | /** 61 | * @return the actual root, that's defined by the user 62 | */ 63 | public Object getRoot() 64 | { 65 | return this.actualRoot; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/version/VersionedRootWithHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | import software.xdev.micromigration.notification.ScriptExecutionNotificationWithoutScriptReference; 23 | 24 | 25 | /** 26 | * This class is inserted as the root of the datastore and contains only the current version, the actual root object 27 | * and the history of executed scripts. 28 | */ 29 | public class VersionedRootWithHistory extends VersionedRoot implements VersionedAndKeeperOfHistory 30 | { 31 | private final List migrationHistory; 32 | 33 | /** 34 | * @param actualRoot which is stored in the datastore and defined by the user 35 | */ 36 | public VersionedRootWithHistory(final Object actualRoot) 37 | { 38 | super(actualRoot); 39 | this.migrationHistory = new ArrayList<>(); 40 | } 41 | 42 | @Override 43 | public void addExecutedScript(final ScriptExecutionNotificationWithoutScriptReference executedScriptInformation) 44 | { 45 | this.migrationHistory.add(Objects.requireNonNull(executedScriptInformation)); 46 | } 47 | 48 | /** 49 | * @return the complete migration history. That means information about every executed script. 50 | */ 51 | @Override 52 | public List getMigrationHistory() 53 | { 54 | return this.migrationHistory; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/versionagnostic/VersionAgnosticMigrationEmbeddedStorageManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.versionagnostic; 17 | 18 | import java.util.List; 19 | import java.util.Objects; 20 | 21 | import software.xdev.micromigration.migrater.MicroMigrater; 22 | import software.xdev.micromigration.notification.ScriptExecutionNotificationWithoutScriptReference; 23 | import software.xdev.micromigration.version.MigrationVersion; 24 | import software.xdev.micromigration.version.Versioned; 25 | import software.xdev.micromigration.version.VersionedRoot; 26 | import software.xdev.micromigration.version.VersionedRootWithHistory; 27 | 28 | 29 | /** 30 | * Wrapper class for the {@link org.eclipse.store.storage.embedded.types.EmbeddedStorageManager} interface. 31 | *

32 | * Basically it intercepts storing the root object and places a {@link Versioned} in front of it. This means the root 33 | * object of the datastore is then versioned.
Internally uses the {@link VersionAgnosticMigrationManager} to do the 34 | * actual migration. 35 | *

36 | * {@code VersionAgnostic} because it should be independent of the actual implementation used. 37 | * 38 | * @param class of itself to be able to return the actual class and not just a generic class 39 | * @param The actually used EmbeddedStorageManager 40 | */ 41 | public abstract class VersionAgnosticMigrationEmbeddedStorageManager 42 | implements AutoCloseable 43 | { 44 | private final MicroMigrater migrater; 45 | private VersionedRootWithHistory versionRoot; 46 | private final VersionAgnosticTunnelingEmbeddedStorageManager tunnelingManager; 47 | 48 | /** 49 | * @param tunnelingManager which will be used as the underlying storage manager. Almost all methods are only 50 | * rerouted to this native manager. Only {@link #start()}, {@link #root()} and 51 | * {@link #setRoot(Object)} are intercepted and a {@link Versioned} is placed between the 52 | * requests. 53 | * @param migrater which is used as source for the migration scripts 54 | */ 55 | protected VersionAgnosticMigrationEmbeddedStorageManager( 56 | final VersionAgnosticTunnelingEmbeddedStorageManager tunnelingManager, 57 | final MicroMigrater migrater 58 | ) 59 | { 60 | this.tunnelingManager = Objects.requireNonNull(tunnelingManager); 61 | this.migrater = Objects.requireNonNull(migrater); 62 | } 63 | 64 | /** 65 | * @return the native EmbeddedStorageManager 66 | */ 67 | public E getNativeStorageManager() 68 | { 69 | return this.getTunnelingManager().getNativeStorageManager(); 70 | } 71 | 72 | /** 73 | * @return the used {@link VersionAgnosticTunnelingEmbeddedStorageManager} 74 | */ 75 | protected VersionAgnosticTunnelingEmbeddedStorageManager getTunnelingManager() 76 | { 77 | return this.tunnelingManager; 78 | } 79 | 80 | /** 81 | * Checks if the root object is of the instance of {@link Versioned}. If it is not, the root will be replaced with 82 | * the versioned root and the actual root object will be put inside the versioned root. 83 | *

84 | * After starting the storage manager, all the available update scripts are executed in order until the newest 85 | * version of the datastore is reached. 86 | * 87 | * @return itself 88 | */ 89 | @SuppressWarnings({"unchecked", "rawtypes"}) 90 | public T start() 91 | { 92 | this.tunnelingManager.start(); 93 | if(this.tunnelingManager.root() instanceof final VersionedRootWithHistory versionedRootWithHistory) 94 | { 95 | this.versionRoot = versionedRootWithHistory; 96 | } 97 | else 98 | { 99 | // Build VersionedRootWithHistory around actual root, set by user. 100 | this.versionRoot = new VersionedRootWithHistory(this.tunnelingManager.root()); 101 | this.tunnelingManager.setRoot(this.versionRoot); 102 | this.tunnelingManager.storeRoot(); 103 | } 104 | new VersionAgnosticMigrationManager( 105 | this.versionRoot, 106 | this.migrater, 107 | this 108 | ).migrate(this.versionRoot.getRoot()); 109 | return (T)this; 110 | } 111 | 112 | /** 113 | * @return current version that's managed 114 | */ 115 | public MigrationVersion getCurrentVersion() 116 | { 117 | return this.versionRoot.getVersion(); 118 | } 119 | 120 | /** 121 | * @return the actual root object 122 | */ 123 | public Object root() 124 | { 125 | return this.versionRoot.getRoot(); 126 | } 127 | 128 | /** 129 | * @return the actual root object 130 | */ 131 | public List getMigrationHistory() 132 | { 133 | return this.versionRoot.getMigrationHistory(); 134 | } 135 | 136 | /** 137 | * Sets the actual root element (not the versioned root) 138 | * 139 | * @param newRoot to set 140 | * @return the set object 141 | */ 142 | public Object setRoot(final Object newRoot) 143 | { 144 | this.versionRoot.setRoot(newRoot); 145 | return newRoot; 146 | } 147 | 148 | /** 149 | * Stores the {@link VersionedRoot} and the actual root object. 150 | * 151 | * @return what EmbeddedStorageManager#storeRoot returns 152 | */ 153 | public long storeRoot() 154 | { 155 | this.tunnelingManager.store(this.versionRoot); 156 | return this.tunnelingManager.store(this.versionRoot.getRoot()); 157 | } 158 | 159 | /** 160 | * Stores the objectToStore 161 | * 162 | * @param objectToStore which is stored 163 | * @return what EmbeddedStorageManager#store returns 164 | */ 165 | public long store(final Object objectToStore) 166 | { 167 | return this.tunnelingManager.store(objectToStore); 168 | } 169 | 170 | /** 171 | * Shuts down the datastore. 172 | * 173 | * @return what EmbeddedStorageManager#storeRoot shutdown 174 | */ 175 | public boolean shutdown() 176 | { 177 | return this.tunnelingManager.shutdown(); 178 | } 179 | 180 | /** 181 | * Closes the datastore. 182 | */ 183 | @Override 184 | public void close() 185 | { 186 | this.tunnelingManager.close(); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /micro-migration/src/main/java/software/xdev/micromigration/versionagnostic/VersionAgnosticTunnelingEmbeddedStorageManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.versionagnostic; 17 | 18 | /** 19 | * Wrapper class for the {@link org.eclipse.store.storage.embedded.types.EmbeddedStorageManager} interface. 20 | *

21 | * It's simply an interface to not directly depend on the underlying framework, but still use its functionality. 22 | *

23 | *

24 | * {@code VersionAgnostic} because it should be independent of the actual implementation used. 25 | *

26 | * 27 | * @param Represents the actually used EmbeddedStorageManager 28 | */ 29 | public interface VersionAgnosticTunnelingEmbeddedStorageManager 30 | extends AutoCloseable 31 | { 32 | /** 33 | * Simply relais the method-call to the EmbeddedStorageManager 34 | * 35 | * @return what the actual EmbeddedStorageManager returns 36 | */ 37 | T start(); 38 | 39 | /** 40 | * Simply relais the method-call to the EmbeddedStorageManager 41 | * 42 | * @return what the actual EmbeddedStorageManager returns 43 | */ 44 | Object root(); 45 | 46 | /** 47 | * Simply relais the method-call to the EmbeddedStorageManager 48 | * 49 | * @param newRoot whatever the actual EmbeddedStorageManager uses this for 50 | * @return what the actual EmbeddedStorageManager returns 51 | */ 52 | Object setRoot(Object newRoot); 53 | 54 | /** 55 | * Simply relais the method-call to the EmbeddedStorageManager 56 | * 57 | * @return what the actual EmbeddedStorageManager returns 58 | */ 59 | long storeRoot(); 60 | 61 | /** 62 | * Simply relais the method-call to the EmbeddedStorageManager 63 | * 64 | * @return what the actual EmbeddedStorageManager returns 65 | */ 66 | boolean shutdown(); 67 | 68 | /** 69 | * Simply relais the method-call to the EmbeddedStorageManager 70 | * 71 | * @return what the actual EmbeddedStorageManager returns 72 | */ 73 | boolean isAcceptingTasks(); 74 | 75 | /** 76 | * Simply relais the method-call to the EmbeddedStorageManager 77 | * 78 | * @return what the actual EmbeddedStorageManager returns 79 | */ 80 | boolean isRunning(); 81 | 82 | /** 83 | * Simply relais the method-call to the EmbeddedStorageManager 84 | * 85 | * @return what the actual EmbeddedStorageManager returns 86 | */ 87 | boolean isStartingUp(); 88 | 89 | /** 90 | * Simply relais the method-call to the EmbeddedStorageManager 91 | * 92 | * @return what the actual EmbeddedStorageManager returns 93 | */ 94 | boolean isShuttingDown(); 95 | 96 | /** 97 | * Simply relais the method-call to the EmbeddedStorageManager 98 | */ 99 | void checkAcceptingTasks(); 100 | 101 | /** 102 | * Simply relais the method-call to the EmbeddedStorageManager 103 | * 104 | * @return what the actual EmbeddedStorageManager returns 105 | */ 106 | long initializationTime(); 107 | 108 | /** 109 | * Simply relais the method-call to the EmbeddedStorageManager 110 | * 111 | * @return what the actual EmbeddedStorageManager returns 112 | */ 113 | long operationModeTime(); 114 | 115 | /** 116 | * Simply relais the method-call to the EmbeddedStorageManager 117 | * 118 | * @return what the actual EmbeddedStorageManager returns 119 | */ 120 | boolean isActive(); 121 | 122 | /** 123 | * Simply relais the method-call to the EmbeddedStorageManager 124 | * 125 | * @param nanoTimeBudget whatever the actual EmbeddedStorageManager uses this for 126 | * @return what the actual EmbeddedStorageManager returns 127 | */ 128 | boolean issueGarbageCollection(long nanoTimeBudget); 129 | 130 | /** 131 | * Simply relais the method-call to the EmbeddedStorageManager 132 | * 133 | * @param nanoTimeBudget whatever the actual EmbeddedStorageManager uses this for 134 | * @return what the actual EmbeddedStorageManager returns 135 | */ 136 | boolean issueFileCheck(long nanoTimeBudget); 137 | 138 | /** 139 | * Simply relais the method-call to the EmbeddedStorageManager 140 | * 141 | * @param instance whatever the actual EmbeddedStorageManager uses this for 142 | * @return what the actual EmbeddedStorageManager returns 143 | */ 144 | long store(Object instance); 145 | 146 | /** 147 | * @return the actual EmbeddedStorageManager 148 | */ 149 | T getNativeStorageManager(); 150 | 151 | /** 152 | * Simply relais the method-call to the EmbeddedStorageManager 153 | */ 154 | @Override 155 | void close(); 156 | } 157 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/eclipsestore/integration/IntroduceMigrationOnExistingDatastoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore.integration; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import java.nio.file.Path; 21 | 22 | import org.eclipse.store.storage.embedded.types.EmbeddedStorage; 23 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager; 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.io.TempDir; 26 | 27 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 28 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 29 | import software.xdev.micromigration.eclipsestore.util.MicroMigrationScriptDummy; 30 | import software.xdev.micromigration.migrater.ExplicitMigrater; 31 | import software.xdev.micromigration.version.MigrationVersion; 32 | 33 | 34 | class IntroduceMigrationOnExistingDatastoreTest 35 | { 36 | static final String ROOT = "OriginalRoot"; 37 | 38 | @Test 39 | void checkIntroducingMigrationOnExistingDatastoreMigrationEmbeddedStorageManager(@TempDir final Path storageFolder) 40 | { 41 | try(final EmbeddedStorageManager storageManager = EmbeddedStorage.start(storageFolder)) 42 | { 43 | storageManager.setRoot(ROOT); 44 | storageManager.storeRoot(); 45 | } 46 | 47 | final ExplicitMigrater migrater = new ExplicitMigrater( 48 | new MicroMigrationScriptDummy(new MigrationVersion(1)) 49 | ); 50 | try(final MigrationEmbeddedStorageManager migrationStorageManager = MigrationEmbeddedStorage.start( 51 | storageFolder, 52 | migrater)) 53 | { 54 | assertEquals(ROOT, migrationStorageManager.root()); 55 | assertEquals(1, migrationStorageManager.getCurrentVersion().getVersions()[0]); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/eclipsestore/integration/MigrationScriptWithNullSourceVersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore.integration; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNull; 20 | 21 | import java.nio.file.Path; 22 | 23 | import org.eclipse.store.storage.embedded.types.EmbeddedStorage; 24 | import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager; 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.io.TempDir; 27 | 28 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 29 | import software.xdev.micromigration.eclipsestore.MigrationManager; 30 | import software.xdev.micromigration.migrater.ExplicitMigrater; 31 | import software.xdev.micromigration.scripts.SimpleTypedMigrationScript; 32 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 33 | import software.xdev.micromigration.version.MigrationVersion; 34 | import software.xdev.micromigration.version.Versioned; 35 | import software.xdev.micromigration.version.VersionedObject; 36 | 37 | 38 | class MigrationScriptWithNullSourceVersionTest 39 | { 40 | public static class EmptyVersionedRoot implements Versioned 41 | { 42 | private MigrationVersion version; 43 | 44 | @Override 45 | public void setVersion(final MigrationVersion version) 46 | { 47 | this.version = version; 48 | } 49 | 50 | @Override 51 | public MigrationVersion getVersion() 52 | { 53 | return this.version; 54 | } 55 | } 56 | 57 | @Test 58 | void updateFromEmptyVersion(@TempDir final Path storageFolder) 59 | { 60 | // First run without any migration script 61 | try(final EmbeddedStorageManager storageManager = this.startEmbeddedStorageManagerWithPath(storageFolder)) 62 | { 63 | final EmptyVersionedRoot firstRoot = new EmptyVersionedRoot(); 64 | storageManager.setRoot(firstRoot); 65 | storageManager.storeRoot(); 66 | assertNull(firstRoot.getVersion()); 67 | } 68 | 69 | // Run with one migration script 70 | final VersionAgnosticMigrationScript, MigrationEmbeddedStorageManager> firstScript = 71 | new SimpleTypedMigrationScript<>( 72 | new MigrationVersion(1), 73 | context -> { 74 | } 75 | ); 76 | 77 | try(final EmbeddedStorageManager storageManager = this.startEmbeddedStorageManagerWithPath(storageFolder)) 78 | { 79 | new MigrationManager( 80 | (Versioned)storageManager.root(), 81 | new ExplicitMigrater(firstScript), 82 | storageManager 83 | ) 84 | .migrate(storageManager.root()); 85 | final EmptyVersionedRoot currentRoot = (EmptyVersionedRoot)storageManager.root(); 86 | assertEquals(new MigrationVersion(1), currentRoot.getVersion()); 87 | } 88 | } 89 | 90 | @Test 91 | void updateWithNoScripts(@TempDir final Path storageFolder) 92 | { 93 | // First run without any migration script 94 | try(final EmbeddedStorageManager storageManager = this.startEmbeddedStorageManagerWithPath(storageFolder)) 95 | { 96 | final EmptyVersionedRoot firstRoot = new EmptyVersionedRoot(); 97 | storageManager.setRoot(firstRoot); 98 | storageManager.storeRoot(); 99 | assertNull(firstRoot.getVersion()); 100 | } 101 | 102 | try(final EmbeddedStorageManager storageManager = this.startEmbeddedStorageManagerWithPath(storageFolder)) 103 | { 104 | new MigrationManager( 105 | (Versioned)storageManager.root(), 106 | new ExplicitMigrater(), 107 | storageManager 108 | ) 109 | .migrate(storageManager.root()); 110 | final EmptyVersionedRoot currentRoot = (EmptyVersionedRoot)storageManager.root(); 111 | assertNull(currentRoot.getVersion()); 112 | } 113 | } 114 | 115 | private EmbeddedStorageManager startEmbeddedStorageManagerWithPath(final Path storageFolder) 116 | { 117 | return EmbeddedStorage.start(storageFolder); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/eclipsestore/integration/MultipleScriptsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore.integration; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import java.nio.file.Path; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.io.TempDir; 25 | 26 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 27 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 28 | import software.xdev.micromigration.migrater.ExplicitMigrater; 29 | import software.xdev.micromigration.migrater.VersionAlreadyRegisteredException; 30 | import software.xdev.micromigration.scripts.SimpleTypedMigrationScript; 31 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 32 | import software.xdev.micromigration.version.MigrationVersion; 33 | 34 | 35 | class MultipleScriptsTest 36 | { 37 | @Test 38 | void checkMigrationWithTwoScriptsAtOnceMigrationEmbeddedStorageManager(@TempDir final Path storageFolder) 39 | { 40 | final VersionAgnosticMigrationScript firstScript = 41 | new SimpleTypedMigrationScript<>( 42 | new MigrationVersion(1), 43 | context -> context.getStorageManager().setRoot(1) 44 | ); 45 | final VersionAgnosticMigrationScript secondScript = 46 | new SimpleTypedMigrationScript<>( 47 | new MigrationVersion(2), 48 | context -> context.getStorageManager().setRoot(2) 49 | ); 50 | final ExplicitMigrater migrater = new ExplicitMigrater(firstScript, secondScript); 51 | try(final MigrationEmbeddedStorageManager migrationStorageManager = MigrationEmbeddedStorage.start( 52 | storageFolder, 53 | migrater)) 54 | { 55 | assertEquals(2, migrationStorageManager.root()); 56 | assertEquals(new MigrationVersion(2), migrationStorageManager.getCurrentVersion()); 57 | } 58 | } 59 | 60 | @Test 61 | void checkMigrationWithTwoScriptsWithSameVersion() 62 | { 63 | final VersionAgnosticMigrationScript firstScript = 64 | new SimpleTypedMigrationScript<>( 65 | new MigrationVersion(1), 66 | context -> context.getStorageManager().setRoot(1) 67 | ); 68 | final VersionAgnosticMigrationScript secondScript = 69 | new SimpleTypedMigrationScript<>( 70 | new MigrationVersion(1), 71 | context -> context.getStorageManager().setRoot(2) 72 | ); 73 | Assertions.assertThrows(VersionAlreadyRegisteredException.class, () -> 74 | new ExplicitMigrater(firstScript, secondScript) 75 | ); 76 | } 77 | 78 | @Test 79 | void checkMigrationWithThreeScriptsWithSameVersion() 80 | { 81 | final VersionAgnosticMigrationScript firstScript = 82 | new SimpleTypedMigrationScript<>( 83 | new MigrationVersion(1), 84 | context -> context.getStorageManager().setRoot(1) 85 | ); 86 | final VersionAgnosticMigrationScript secondScript = 87 | new SimpleTypedMigrationScript<>( 88 | new MigrationVersion(2), 89 | context -> context.getStorageManager().setRoot(2) 90 | ); 91 | final VersionAgnosticMigrationScript thirdScript = 92 | new SimpleTypedMigrationScript<>( 93 | new MigrationVersion(1), 94 | context -> context.getStorageManager().setRoot(3) 95 | ); 96 | Assertions.assertThrows(VersionAlreadyRegisteredException.class, () -> 97 | new ExplicitMigrater(firstScript, secondScript, thirdScript) 98 | ); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/eclipsestore/integration/StoreStuffInMigrationStorageManagerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore.integration; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | 21 | import java.nio.file.Path; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.io.TempDir; 25 | 26 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 27 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 28 | import software.xdev.micromigration.migrater.ExplicitMigrater; 29 | import software.xdev.micromigration.scripts.SimpleTypedMigrationScript; 30 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 31 | import software.xdev.micromigration.version.MigrationVersion; 32 | 33 | 34 | class StoreStuffInMigrationStorageManagerTest 35 | { 36 | static class RootClass 37 | { 38 | private final ChildClass child = new ChildClass(); 39 | } 40 | 41 | 42 | static class ChildClass 43 | { 44 | private int i; 45 | } 46 | 47 | @Test 48 | void checkStoringSomethingAfterUpdating(@TempDir final Path storageFolder) 49 | { 50 | final VersionAgnosticMigrationScript script = 51 | new SimpleTypedMigrationScript<>( 52 | new MigrationVersion(1), 53 | context -> { 54 | } 55 | ); 56 | final ExplicitMigrater migrater = new ExplicitMigrater(script); 57 | // Create new store and change stored object 58 | try(final MigrationEmbeddedStorageManager migrationStorageManager = MigrationEmbeddedStorage.start( 59 | storageFolder, 60 | migrater)) 61 | { 62 | migrationStorageManager.setRoot(new RootClass()); 63 | migrationStorageManager.storeRoot(); 64 | final RootClass storedRoot = (RootClass)migrationStorageManager.root(); 65 | assertEquals(0, storedRoot.child.i); 66 | ((RootClass)migrationStorageManager.root()).child.i = 1; 67 | migrationStorageManager.store(storedRoot.child); 68 | assertEquals(1, storedRoot.child.i); 69 | } 70 | // Check if stored object is correct 71 | try(final MigrationEmbeddedStorageManager migrationStorageManager = MigrationEmbeddedStorage.start( 72 | storageFolder, 73 | migrater)) 74 | { 75 | final RootClass storedRoot = (RootClass)migrationStorageManager.root(); 76 | assertNotNull(storedRoot); 77 | assertEquals(1, storedRoot.child.i); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/eclipsestore/migrater/ExplicitMigraterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore.migrater; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import java.nio.file.Path; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.io.TempDir; 25 | 26 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorage; 27 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 28 | import software.xdev.micromigration.eclipsestore.util.MicroMigrationScriptDummy; 29 | import software.xdev.micromigration.migrater.ExplicitMigrater; 30 | import software.xdev.micromigration.scripts.SimpleTypedMigrationScript; 31 | import software.xdev.micromigration.version.MigrationVersion; 32 | 33 | 34 | class ExplicitMigraterTest 35 | { 36 | 37 | @Test 38 | void checkGetSortedScriptsEmpty() 39 | { 40 | final ExplicitMigrater migrater = new ExplicitMigrater(); 41 | assertEquals(0, migrater.getSortedScripts().size()); 42 | } 43 | 44 | @Test 45 | void checkGetSortedScriptsSorted() 46 | { 47 | final ExplicitMigrater migrater = new ExplicitMigrater( 48 | new MicroMigrationScriptDummy(new MigrationVersion(1)), 49 | new MicroMigrationScriptDummy(new MigrationVersion(2)) 50 | ); 51 | assertEquals(1, migrater.getSortedScripts().first().getTargetVersion().getVersions()[0]); 52 | assertEquals(2, migrater.getSortedScripts().last().getTargetVersion().getVersions()[0]); 53 | } 54 | 55 | @Test 56 | void checkGetSortedScriptsUnsorted() 57 | { 58 | final ExplicitMigrater migrater = new ExplicitMigrater( 59 | new MicroMigrationScriptDummy(new MigrationVersion(2)), 60 | new MicroMigrationScriptDummy(new MigrationVersion(1)) 61 | ); 62 | assertEquals(1, migrater.getSortedScripts().first().getTargetVersion().getVersions()[0]); 63 | assertEquals(2, migrater.getSortedScripts().last().getTargetVersion().getVersions()[0]); 64 | } 65 | 66 | @Test 67 | void checkWrongTypedVersionedScript(@TempDir final Path storageFolder) 68 | { 69 | try(final MigrationEmbeddedStorageManager storageManager = MigrationEmbeddedStorage.start( 70 | storageFolder, 71 | new ExplicitMigrater())) 72 | { 73 | storageManager.setRoot("SomeString"); 74 | storageManager.storeRoot(); 75 | } 76 | final ExplicitMigrater migrater = new ExplicitMigrater( 77 | new SimpleTypedMigrationScript( 78 | new MigrationVersion(1), 79 | context -> context.getStorageManager().setRoot(context.getMigratingObject() + 1) 80 | ) 81 | ); 82 | Assertions.assertThrows( 83 | ClassCastException.class, 84 | () -> MigrationEmbeddedStorage.start(storageFolder, migrater)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/eclipsestore/util/MicroMigrationScriptDummy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.eclipsestore.util; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class MicroMigrationScriptDummy 25 | implements VersionAgnosticMigrationScript 26 | { 27 | private final MigrationVersion version; 28 | 29 | public MicroMigrationScriptDummy(final MigrationVersion version) 30 | { 31 | this.version = version; 32 | } 33 | 34 | @Override 35 | public MigrationVersion getTargetVersion() 36 | { 37 | return this.version; 38 | } 39 | 40 | @Override 41 | public void migrate(final Context context) 42 | { 43 | // Don't do anything. 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/ReflectiveMigraterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import org.junit.jupiter.api.Assertions; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import software.xdev.micromigration.migrater.reflection.scripts.abstractReflectiveSuperClass.v1_ValidScript; 24 | 25 | 26 | class ReflectiveMigraterTest 27 | { 28 | @Test 29 | void testValidScript() 30 | { 31 | final ReflectiveMigrater migrater = 32 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.valid"); 33 | assertEquals(1, migrater.getSortedScripts().size()); 34 | assertEquals( 35 | software.xdev.micromigration.migrater.reflection.scripts.valid.ValidScript.class, 36 | migrater.getSortedScripts().first().getClass() 37 | ); 38 | } 39 | 40 | @Test 41 | void testValidScriptWithIrrelevantClasses() 42 | { 43 | final ReflectiveMigrater migrater = 44 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts" 45 | + ".moreClassesIncludingValid"); 46 | assertEquals(1, migrater.getSortedScripts().size()); 47 | assertEquals( 48 | software.xdev.micromigration.migrater.reflection.scripts.moreClassesIncludingValid.ValidScript.class, 49 | migrater.getSortedScripts().first().getClass() 50 | ); 51 | } 52 | 53 | @Test 54 | void testValidScriptWithSubpackages() 55 | { 56 | final ReflectiveMigrater migrater = 57 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.includeSubPackages"); 58 | assertEquals(2, migrater.getSortedScripts().size()); 59 | assertEquals( 60 | software.xdev.micromigration.migrater.reflection.scripts.includeSubPackages.ValidScript.class, 61 | migrater.getSortedScripts().first().getClass() 62 | ); 63 | assertEquals( 64 | software.xdev.micromigration.migrater.reflection.scripts.includeSubPackages.subpackage 65 | .ValidScriptInSubpackage.class, 66 | migrater.getSortedScripts().last().getClass() 67 | ); 68 | } 69 | 70 | @Test 71 | void testPackageWithNoScript() 72 | { 73 | final ReflectiveMigrater migrater = 74 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.packageNotExisting"); 75 | assertEquals(0, migrater.getSortedScripts().size()); 76 | } 77 | 78 | @Test 79 | void testExceptionThrowingScript() 80 | { 81 | Assertions.assertThrows(ScriptInstantiationException.class, () -> { 82 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.exceptionThrowing"); 83 | }); 84 | } 85 | 86 | @Test 87 | void testErrorThrowingScript() 88 | { 89 | Assertions.assertThrows(ScriptInstantiationException.class, () -> { 90 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.errorThrowing"); 91 | }); 92 | } 93 | 94 | @Test 95 | void testNoCorrectConstructor() 96 | { 97 | Assertions.assertThrows(ScriptInstantiationException.class, () -> { 98 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.noCorrectConstructor"); 99 | }); 100 | } 101 | 102 | @Test 103 | void testAbstractSuperClass() 104 | { 105 | final ReflectiveMigrater migrater = 106 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.abstractSuperClass"); 107 | assertEquals(1, migrater.getSortedScripts().size()); 108 | assertEquals( 109 | software.xdev.micromigration.migrater.reflection.scripts.abstractSuperClass.ValidScript.class, 110 | migrater.getSortedScripts().first().getClass() 111 | ); 112 | } 113 | 114 | @Test 115 | void testReflectiveVersion() 116 | { 117 | final ReflectiveMigrater migrater = 118 | new ReflectiveMigrater("software.xdev.micromigration.migrater.reflection.scripts.reflectiveVersion"); 119 | assertEquals(1, migrater.getSortedScripts().size()); 120 | assertEquals( 121 | software.xdev.micromigration.migrater.reflection.scripts.reflectiveVersion.v1_ValidScript.class, 122 | migrater.getSortedScripts().first().getClass() 123 | ); 124 | } 125 | 126 | @Test 127 | void testReflectiveSuperClass() 128 | { 129 | final ReflectiveMigrater migrater = 130 | new ReflectiveMigrater( 131 | "software.xdev.micromigration.migrater.reflection.scripts.abstractReflectiveSuperClass"); 132 | assertEquals(1, migrater.getSortedScripts().size()); 133 | assertEquals( 134 | v1_ValidScript.class, 135 | migrater.getSortedScripts().first().getClass() 136 | ); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/abstractReflectiveSuperClass/AbstractScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.abstractReflectiveSuperClass; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.ReflectiveVersionMigrationScript; 20 | 21 | 22 | public abstract class AbstractScript extends ReflectiveVersionMigrationScript 23 | { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/abstractReflectiveSuperClass/v1_ValidScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.abstractReflectiveSuperClass; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | 21 | 22 | @SuppressWarnings("checkstyle:TypeName") 23 | public class v1_ValidScript extends AbstractScript 24 | { 25 | @Override 26 | public void migrate(final Context context) 27 | { 28 | // Do nothing 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/abstractSuperClass/AbstractScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.abstractSuperClass; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 20 | import software.xdev.micromigration.version.MigrationVersion; 21 | 22 | 23 | public abstract class AbstractScript implements VersionAgnosticMigrationScript 24 | { 25 | @Override 26 | public MigrationVersion getTargetVersion() 27 | { 28 | return new MigrationVersion(1); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/abstractSuperClass/ValidScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.abstractSuperClass; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | 21 | 22 | public class ValidScript extends AbstractScript 23 | { 24 | @Override 25 | public void migrate(final Context context) 26 | { 27 | // Do nothing 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/errorThrowing/ErrorThrowingScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.errorThrowing; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class ErrorThrowingScript implements VersionAgnosticMigrationScript 25 | { 26 | public ErrorThrowingScript() 27 | { 28 | throw new Error(); 29 | } 30 | 31 | @Override 32 | public MigrationVersion getTargetVersion() 33 | { 34 | return new MigrationVersion(1); 35 | } 36 | 37 | @Override 38 | public void migrate(final Context context) 39 | { 40 | // Do nothing 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/exceptionThrowing/ExceptionThrowingScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.exceptionThrowing; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class ExceptionThrowingScript implements VersionAgnosticMigrationScript 25 | { 26 | public ExceptionThrowingScript() throws Exception 27 | { 28 | throw new Exception(); 29 | } 30 | 31 | @Override 32 | public MigrationVersion getTargetVersion() 33 | { 34 | return new MigrationVersion(1); 35 | } 36 | 37 | @Override 38 | public void migrate(final Context context) 39 | { 40 | // Do nothing 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/includeSubPackages/ValidScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.includeSubPackages; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class ValidScript implements VersionAgnosticMigrationScript 25 | { 26 | @Override 27 | public MigrationVersion getTargetVersion() 28 | { 29 | return new MigrationVersion(1); 30 | } 31 | 32 | @Override 33 | public void migrate(final Context context) 34 | { 35 | // Do nothing 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/includeSubPackages/subpackage/ValidScriptInSubpackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.includeSubPackages.subpackage; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class ValidScriptInSubpackage implements VersionAgnosticMigrationScript 25 | { 26 | @Override 27 | public MigrationVersion getTargetVersion() 28 | { 29 | return new MigrationVersion(2); 30 | } 31 | 32 | @Override 33 | public void migrate(final Context context) 34 | { 35 | // Do nothing 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/moreClassesIncludingValid/IrrelevantClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.moreClassesIncludingValid; 17 | 18 | public class IrrelevantClass 19 | { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/moreClassesIncludingValid/ValidScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.moreClassesIncludingValid; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class ValidScript implements VersionAgnosticMigrationScript 25 | { 26 | @Override 27 | public MigrationVersion getTargetVersion() 28 | { 29 | return new MigrationVersion(1); 30 | } 31 | 32 | @Override 33 | public void migrate(final Context context) 34 | { 35 | // Do nothing 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/noCorrectConstructor/NoCorrectConstructorScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.noCorrectConstructor; 17 | 18 | import java.util.logging.Logger; 19 | 20 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 21 | import software.xdev.micromigration.scripts.Context; 22 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 23 | import software.xdev.micromigration.version.MigrationVersion; 24 | 25 | 26 | public class NoCorrectConstructorScript 27 | implements VersionAgnosticMigrationScript 28 | { 29 | private final String argument; 30 | 31 | public NoCorrectConstructorScript(final String argument) 32 | { 33 | this.argument = argument; 34 | } 35 | 36 | @Override 37 | public MigrationVersion getTargetVersion() 38 | { 39 | return new MigrationVersion(1); 40 | } 41 | 42 | @Override 43 | public void migrate(final Context context) 44 | { 45 | Logger.getGlobal().info(this.argument); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/reflectiveVersion/v1_ValidScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.reflectiveVersion; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.ReflectiveVersionMigrationScript; 21 | 22 | 23 | @SuppressWarnings("checkstyle:TypeName") 24 | public class v1_ValidScript extends ReflectiveVersionMigrationScript 25 | { 26 | @Override 27 | public void migrate(final Context context) 28 | { 29 | // Do nothing 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/migrater/reflection/scripts/valid/ValidScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.migrater.reflection.scripts.valid; 17 | 18 | import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager; 19 | import software.xdev.micromigration.scripts.Context; 20 | import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | 23 | 24 | public class ValidScript implements VersionAgnosticMigrationScript 25 | { 26 | @Override 27 | public MigrationVersion getTargetVersion() 28 | { 29 | return new MigrationVersion(1); 30 | } 31 | 32 | @Override 33 | public void migrate(final Context context) 34 | { 35 | // Do nothing 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/scripts/ReflectiveVersionMigrationScriptTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.scripts; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import software.xdev.micromigration.version.MigrationVersion; 22 | import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; 23 | 24 | 25 | @SuppressWarnings({"checkstyle:TypeName", "checkstyle:MethodName"}) 26 | class ReflectiveVersionMigrationScriptTest 27 | { 28 | public static class v1_CorrectClassName extends ReflectiveVersionMigrationScriptDummy 29 | { 30 | } 31 | 32 | @Test 33 | void correctName_v1_CorrectClassName() 34 | { 35 | Assertions.assertEquals(new MigrationVersion(1), new v1_CorrectClassName().getTargetVersion()); 36 | } 37 | 38 | public static class v1_1_CorrectClassName extends ReflectiveVersionMigrationScriptDummy 39 | { 40 | } 41 | 42 | @Test 43 | void correctName_v1_1_CorrectClassName() 44 | { 45 | Assertions.assertEquals(new MigrationVersion(1, 1), new v1_1_CorrectClassName().getTargetVersion()); 46 | } 47 | 48 | public static class v1_1_1_CorrectClassName extends ReflectiveVersionMigrationScriptDummy 49 | { 50 | } 51 | 52 | @Test 53 | void correctName_v1_1_1_CorrectClassName() 54 | { 55 | Assertions.assertEquals(new MigrationVersion(1, 1, 1), new v1_1_1_CorrectClassName().getTargetVersion()); 56 | } 57 | 58 | public static class v10_1_1_CorrectClassName extends ReflectiveVersionMigrationScriptDummy 59 | { 60 | } 61 | 62 | @Test 63 | void correctName_v10_1_1_CorrectClassName() 64 | { 65 | Assertions.assertEquals(new MigrationVersion(10, 1, 1), new v10_1_1_CorrectClassName().getTargetVersion()); 66 | } 67 | 68 | public static class v10_10_1_CorrectClassName extends ReflectiveVersionMigrationScriptDummy 69 | { 70 | } 71 | 72 | @Test 73 | void correctName_v10_10_1_CorrectClassName() 74 | { 75 | Assertions.assertEquals(new MigrationVersion(10, 10, 1), new v10_10_1_CorrectClassName().getTargetVersion()); 76 | } 77 | 78 | public static class v10_10_10_CorrectClassName extends ReflectiveVersionMigrationScriptDummy 79 | { 80 | } 81 | 82 | @Test 83 | void correctName_v10_10_10_CorrectClassName() 84 | { 85 | Assertions.assertEquals(new MigrationVersion(10, 10, 10), new v10_10_10_CorrectClassName().getTargetVersion()); 86 | } 87 | 88 | public static class a1_InvalidClassName extends ReflectiveVersionMigrationScriptDummy 89 | { 90 | } 91 | 92 | @Test 93 | void invalidName_a1_InvalidClassName() 94 | { 95 | Assertions.assertThrows(IllegalArgumentException.class, a1_InvalidClassName::new); 96 | } 97 | 98 | public static class foo1_InvalidClassName extends ReflectiveVersionMigrationScriptDummy 99 | { 100 | } 101 | 102 | @Test 103 | void invalidName_foo1_InvalidClassName() 104 | { 105 | Assertions.assertThrows(IllegalArgumentException.class, foo1_InvalidClassName::new); 106 | } 107 | 108 | public static class InvalidClassName extends ReflectiveVersionMigrationScriptDummy 109 | { 110 | } 111 | 112 | @Test 113 | void invalidName_InvalidClassName() 114 | { 115 | Assertions.assertThrows(IllegalArgumentException.class, InvalidClassName::new); 116 | } 117 | 118 | public static class InvalidClassName_v1 extends ReflectiveVersionMigrationScriptDummy 119 | { 120 | } 121 | 122 | @Test 123 | void invalidName_InvalidClassName_v1() 124 | { 125 | Assertions.assertThrows(IllegalArgumentException.class, InvalidClassName_v1::new); 126 | } 127 | 128 | public static class v1_k_InvalidClassName extends ReflectiveVersionMigrationScriptDummy 129 | { 130 | } 131 | 132 | @Test 133 | void invalidName_v1_k_InvalidClassName() 134 | { 135 | Assertions.assertThrows(IllegalArgumentException.class, v1_k_InvalidClassName::new); 136 | } 137 | 138 | public static class v1_k_2_InvalidClassName extends ReflectiveVersionMigrationScriptDummy 139 | { 140 | } 141 | 142 | @Test 143 | void invalidName_v1_k_2_InvalidClassName() 144 | { 145 | Assertions.assertThrows(IllegalArgumentException.class, v1_k_2_InvalidClassName::new); 146 | } 147 | 148 | public static class v2147483648_InvalidClassName extends ReflectiveVersionMigrationScriptDummy 149 | { 150 | } 151 | 152 | @Test 153 | void invalidName_v2147483648_InvalidClassName() 154 | { 155 | Assertions.assertThrows(IllegalArgumentException.class, v2147483648_InvalidClassName::new); 156 | } 157 | 158 | public static class v___InvalidClassName extends ReflectiveVersionMigrationScriptDummy 159 | { 160 | } 161 | 162 | @Test 163 | void invalidName_v___InvalidClassName() 164 | { 165 | Assertions.assertThrows(IllegalArgumentException.class, v___InvalidClassName::new); 166 | } 167 | 168 | public static class ReflectiveVersionMigrationScriptDummy 169 | extends ReflectiveVersionMigrationScript> 171 | { 172 | @Override 173 | public void migrate( 174 | final Context> context) 175 | { 176 | // Dummy 177 | } 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /micro-migration/src/test/java/software/xdev/micromigration/version/MigrationVersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2021 XDEV Software (https://xdev.software) 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 | * http://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 software.xdev.micromigration.version; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | 23 | class MigrationVersionTest 24 | { 25 | @Test 26 | void checkToStringv1() 27 | { 28 | final MigrationVersion version = new MigrationVersion(1); 29 | assertEquals("v1", version.toString()); 30 | } 31 | 32 | @Test 33 | void checkToStringv11() 34 | { 35 | final MigrationVersion version = new MigrationVersion(1, 1); 36 | assertEquals("v1.1", version.toString()); 37 | } 38 | 39 | @Test 40 | void checkToStringv111() 41 | { 42 | final MigrationVersion version = new MigrationVersion(1, 1, 1); 43 | assertEquals("v1.1.1", version.toString()); 44 | } 45 | 46 | @Test 47 | void checkToStringv0() 48 | { 49 | final MigrationVersion version = new MigrationVersion(0); 50 | assertEquals("v0", version.toString()); 51 | } 52 | 53 | @Test 54 | void checkToStringvNull() 55 | { 56 | final MigrationVersion version = new MigrationVersion(); 57 | assertEquals("v0", version.toString()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | software.xdev 8 | micro-migration-root 9 | 3.0.3-SNAPSHOT 10 | pom 11 | 12 | 13 | XDEV Software 14 | https://xdev.software 15 | 16 | 17 | 18 | micro-migration 19 | micro-migration-demo 20 | 21 | 22 | 23 | UTF-8 24 | UTF-8 25 | 26 | 27 | 28 | 29 | Apache-2.0 30 | https://www.apache.org/licenses/LICENSE-2.0.txt 31 | repo 32 | 33 | 34 | 35 | 36 | 37 | checkstyle 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-checkstyle-plugin 43 | 3.6.0 44 | 45 | 46 | com.puppycrawl.tools 47 | checkstyle 48 | 10.24.0 49 | 50 | 51 | 52 | .config/checkstyle/checkstyle.xml 53 | true 54 | 55 | 56 | 57 | 58 | check 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | pmd 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-pmd-plugin 73 | 3.26.0 74 | 75 | true 76 | true 77 | 78 | .config/pmd/ruleset.xml 79 | 80 | 81 | 82 | 83 | net.sourceforge.pmd 84 | pmd-core 85 | 7.13.0 86 | 87 | 88 | net.sourceforge.pmd 89 | pmd-java 90 | 7.13.0 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | org.apache.maven.plugins 101 | maven-jxr-plugin 102 | 3.6.0 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "rebaseWhen": "behind-base-branch", 4 | "packageRules": [ 5 | { 6 | "description": "Group Eclipse Store", 7 | "matchPackagePatterns": [ 8 | "^org.eclipse.store" 9 | ], 10 | "datasources": [ 11 | "maven" 12 | ], 13 | "groupName": "org.eclipse.store" 14 | }, 15 | { 16 | "description": "Ignore project internal dependencies", 17 | "packagePattern": "^software.xdev:micro-migration", 18 | "datasources": [ 19 | "maven" 20 | ], 21 | "enabled": false 22 | }, 23 | { 24 | "description": "Group net.sourceforge.pmd", 25 | "matchPackagePatterns": [ 26 | "^net.sourceforge.pmd" 27 | ], 28 | "datasources": [ 29 | "maven" 30 | ], 31 | "groupName": "net.sourceforge.pmd" 32 | } 33 | ] 34 | } 35 | --------------------------------------------------------------------------------