From 87e64673091ebf2fdffed0a70abe94ad22ef1515 Mon Sep 17 00:00:00 2001 From: Pedro Xavier Leite Cavadas <24527258+lengors@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:16:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20Initialize=20repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/CODEOWNERS | 3 + .github/FUNDING.yml | 2 + .github/ISSUE_TEMPLATE/bug_report.yml | 45 ++ .github/ISSUE_TEMPLATE/config.yml | 12 + .github/ISSUE_TEMPLATE/create_task.yml | 31 ++ .github/ISSUE_TEMPLATE/feature_request.yml | 45 ++ .github/PULL_REQUEST_TEMPLATE.md | 17 + .../workflows/publish-to-maven-central.yml | 61 +++ .github/workflows/static-code-analysis.yml | 38 ++ .github/workflows/validate-pull-request.yml | 51 +++ .gitignore | 65 +++ .mvn/wrapper/maven-wrapper.properties | 19 + .releaserc.yml | 22 + CHANGELOG.md | 19 + CODE_OF_CONDUCT.md | 131 ++++++ CONTRIBUTING.md | 70 +++ LICENSE | 24 + README.md | 58 +++ SECURITY.md | 5 + mvnw | 259 +++++++++++ mvnw.cmd | 149 +++++++ pom.xml | 413 ++++++++++++++++++ settings.xml | 13 + .../lengors/maven_java_template/Example.java | 28 ++ .../maven_java_template/package-info.java | 5 + .../maven_java_template/ExampleTest.java | 36 ++ .../maven_java_template/package-info.java | 4 + 27 files changed, 1625 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/create_task.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/publish-to-maven-central.yml create mode 100644 .github/workflows/static-code-analysis.yml create mode 100644 .github/workflows/validate-pull-request.yml create mode 100644 .gitignore create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 .releaserc.yml create mode 100644 CHANGELOG.md create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 SECURITY.md create mode 100755 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 settings.xml create mode 100644 src/main/java/io/github/lengors/maven_java_template/Example.java create mode 100644 src/main/java/io/github/lengors/maven_java_template/package-info.java create mode 100644 src/test/java/io/github/lengors/maven_java_template/ExampleTest.java create mode 100644 src/test/java/io/github/lengors/maven_java_template/package-info.java diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..c0ae686 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# Default code owners + +* @lengors \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..539de14 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +--- +patreon: lengors \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..33d15d2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,45 @@ +--- +name: Bug report +description: Report a bug +labels: + - bug +body: + - type: markdown + attributes: + value: ⚠️ Make sure to search for existing issues, discussions or pull requests before creating a new issue. + - type: textarea + attributes: + label: Current behavior + description: A clear and concise description of what the bug is. + validations: + required: true + - type: textarea + attributes: + label: Expected behavior + description: A clear and concise description of what you expected to happen. + validations: + required: true + - type: textarea + attributes: + label: Steps to reproduce + description: Steps to reproduce the behavior. + validations: + required: true + - type: textarea + attributes: + label: Screenshots + description: If applicable, add screenshots to help explain your problem. + validations: + required: false + - type: textarea + attributes: + label: Additional context + description: Add any other context about the problem here. + validations: + required: false + - type: textarea + attributes: + label: Related issues, discussions or pull requests + description: Link to related issues, discussions or pull requests. + validations: + required: false \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..df82724 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,12 @@ +--- +blank_issues_enabled: false +contact_links: + - name: General + url: https://github.com/lengors/java-template/discussions/new?category=general + about: Chat about anything and everything here + - name: Ideas + url: https://github.com/lengors/java-template/discussions/new?category=ideas + about: Share ideas for new features + - name: Questions + url: https://github.com/lengors/java-template/discussions/new?category=q-a + about: Ask the community for help \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/create_task.yml b/.github/ISSUE_TEMPLATE/create_task.yml new file mode 100644 index 0000000..0c2afef --- /dev/null +++ b/.github/ISSUE_TEMPLATE/create_task.yml @@ -0,0 +1,31 @@ +--- +name: Create task +description: Create a task +body: + - type: markdown + attributes: + value: ⚠️ Make sure to search for existing issues, discussions or pull requests before creating a new issue. + - type: textarea + attributes: + label: Description + description: A clear and concise description of what the chore is. + validations: + required: true + - type: textarea + attributes: + label: Screenshots + description: If applicable, add screenshots to help explain your problem. + validations: + required: false + - type: textarea + attributes: + label: Additional context + description: Add any other context about the chore here. + validations: + required: false + - type: textarea + attributes: + label: Related issues, discussions or pull requests + description: Link to related issues, discussions or pull requests. + validations: + required: false \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..b81862b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,45 @@ +--- +name: Feature request +description: Request a new feature +labels: + - enhancement +body: + - type: markdown + attributes: + value: ⚠️ Make sure to search for existing issues, discussions or pull requests before creating a new issue. + - type: textarea + attributes: + label: Description + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + validations: + required: true + - type: textarea + attributes: + label: Proposed solution + description: A clear and concise description of what you want to happen. + validations: + required: true + - type: textarea + attributes: + label: Alternatives considered + description: A clear and concise description of any alternative solutions or features you've considered. + validations: + required: false + - type: textarea + attributes: + label: Screenshots + description: If applicable, add screenshots to help explain your problem or suggestion. + validations: + required: false + - type: textarea + attributes: + label: Additional context + description: Add any other context about the problem here. + validations: + required: false + - type: textarea + attributes: + label: Related issues, discussions or pull requests + description: Link to related issues, discussions or pull requests. + validations: + required: false \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..7e8bfa5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ + diff --git a/.github/workflows/publish-to-maven-central.yml b/.github/workflows/publish-to-maven-central.yml new file mode 100644 index 0000000..7c512a0 --- /dev/null +++ b/.github/workflows/publish-to-maven-central.yml @@ -0,0 +1,61 @@ +--- +name: Publish package to maven central + +on: + push: + branches: + - main + - beta + - alpha + - dev + +jobs: + deploy-and-publish: + name: Deploy and publish package + runs-on: ubuntu-latest + environment: deployment + steps: + - name: Create GitHub app token + uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.GH_APP_ID }} + private-key: ${{ secrets.GH_PRIVATE_KEY }} + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + persist-credentials: false + - name: Import GPG key + id: import-gpg + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + - name: Setup JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: temurin + cache: maven + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} + - name: Publish package + id: semantic + uses: cycjimmy/semantic-release-action@v4 + with: + extra_plugins: | + @semantic-release/exec + semantic-release-gitmoji + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + GIT_AUTHOR_NAME: ${{ steps.import-gpg.outputs.name }} + GIT_AUTHOR_EMAIL: ${{ steps.import-gpg.outputs.email }} + GIT_COMMITTER_NAME: ${{ steps.import-gpg.outputs.name }} + GIT_COMMITTER_EMAIL: ${{ steps.import-gpg.outputs.email }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} diff --git a/.github/workflows/static-code-analysis.yml b/.github/workflows/static-code-analysis.yml new file mode 100644 index 0000000..4b8a0fa --- /dev/null +++ b/.github/workflows/static-code-analysis.yml @@ -0,0 +1,38 @@ +--- +name: Static code analysis + +on: + push: + branches: + - main + - beta + - alpha + - dev + pull_request: + branches: + - main + - beta + - alpha + - dev + +jobs: + code-analysis: + name: Static code analysis + environment: code-analysis + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "temurin" + cache: maven + - name: Perform static code analysis + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./mvnw -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dgpg.skip -Dsonar.projectKey=lengors_maven-java-template diff --git a/.github/workflows/validate-pull-request.yml b/.github/workflows/validate-pull-request.yml new file mode 100644 index 0000000..82556bf --- /dev/null +++ b/.github/workflows/validate-pull-request.yml @@ -0,0 +1,51 @@ +--- +name: Validate pull request + +on: + pull_request: + branches: + - main + - beta + - alpha + - dev + +jobs: + check-style: + name: Check code style + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: temurin + cache: maven + - name: Perform style check + run: ./mvnw checkstyle:check + + build-and-test: + name: Build and test project + strategy: + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + distribution: + - temurin + - zulu + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: ${{ matrix.distribution }} + cache: maven + - name: Perform build and tests + run: ./mvnw clean package + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b072c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +# Build files +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +.idea/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..f95f1ee --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip diff --git a/.releaserc.yml b/.releaserc.yml new file mode 100644 index 0000000..23d6418 --- /dev/null +++ b/.releaserc.yml @@ -0,0 +1,22 @@ +--- +branches: + - main + - name: beta + prerelease: true + - name: alpha + prerelease: true + - name: dev + prerelease: true +plugins: + - "semantic-release-gitmoji" + - - "@semantic-release/changelog" + - changelogFile: CHANGELOG.md + - - "@semantic-release/exec" + - prepareCmd: "./mvnw versions:set -DnewVersion=${nextRelease.version}" + publishCmd: "./mvnw deploy -s ./settings.xml" + - "@semantic-release/github" + - - "@semantic-release/git" + - assets: + - CHANGELOG.md + - pom.xml + message: "🔖 Update `package.json` to `${nextRelease.version}` [skip release]\n\n${nextRelease.notes}" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e627715 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# v1.0.0 (2024-08-10) + +## ✨ New Features +- [`3cdd57c`](https://github.com/lengors/maven-java-template/commit/3cdd57c) Add example code + +# v1.0.0-beta.1 (2024-08-10) + +## ✨ New Features +- [`3cdd57c`](https://github.com/lengors/maven-java-template/commit/3cdd57c) Add example code + +# v1.0.0-alpha.1 (2024-08-10) + +## ✨ New Features +- [`3cdd57c`](https://github.com/lengors/maven-java-template/commit/3cdd57c) Add example code + +# v1.0.0-dev.1 (2024-08-10) + +## ✨ New Features +- [`3cdd57c`](https://github.com/lengors/maven-java-template/commit/3cdd57c) Add example code diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..54e2e06 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,131 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +- Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or + advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email + address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at [lengors.bot@gmail.com](lengors.bot@gmail.com). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c80d895 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,70 @@ +# Contribution Guidelines + +First off, thanks for showing interest in contributing to the **maven-java-template** project! Your contributions help make this template a more robust starting point for Java projects using Maven, and I'm excited to see what improvements and ideas you bring to the table. + +This repository is a template intended to be cloned and customized for various Maven-based Java projects. While it’s primarily a starting point, there’s always room for enhancements, whether that’s improving the template itself or refining the tools and processes it includes. I welcome your contributions, big or small! + +Before continuing though, please refer to our [Code of Conduct](./CODE_OF_CONDUCT.md) to learn more about our values and expectations for contributors. + +## Table of Contents + +- [Contribution Guidelines](#contribution-guidelines) + - [Table of Contents](#table-of-contents) + - [How Can I Contribute?](#how-can-i-contribute) + - [Reporting Bugs](#reporting-bugs) + - [Suggesting Features or Enhancements](#suggesting-features-or-enhancements) + - [Other suggestions](#other-suggestions) + - [Pull Requests](#pull-requests) + - [Code Style](#code-style) + - [License](#license) + +## How Can I Contribute? + +You can contribute to the **maven-java-template** in a few ways. The easiest method is to [start a discussion](https://github.com/lengors/maven-java-template/discussions) or [open an issue](https://github.com/lengors/maven-java-template/issues) on the [repository](https://github.com/lengors/maven-java-template). If you’re feeling ambitious, feel free to jump right into coding and submit a [pull request](https://github.com/lengors/maven-java-template/pulls). + +The preferred method of contribution is to start a discussion so that both the maintainers and the community are made aware of your suggestion and/or improvement and so that both can assess if it makes sense to promote the discussion into an issue worth tracking. It should be noted that even if the discussion is promoted to an issue, it may never end up being worked on, as the need for the proposed changes may vary over time. + +The details for the various ways of contributing are as described below: + +### Reporting Bugs + +If you discover a bug or unexpected behavior, please [post a question on our community](https://github.com/lengors/maven-java-template/discussions/new?category=q-a), [start a general discussion](https://github.com/lengors/maven-java-template/discussions/new?category=general) or [report the bug as an isuse](https://github.com/lengors/maven-java-template/issues/new?template=bug_report.yml) and follow the instructions there. +Please be as descriptive as possible, including steps to reproduce the issue and any relevant details. + +### Suggesting Features or Enhancements + +We welcome your ideas for new features or improvements to existing ones. To suggest a feature, [share your idea with the community](https://github.com/lengors/maven-java-template/discussions/new?category=ideas) or [request a feature as an issue](https://github.com/lengors/maven-java-template/issues/new?template=feature_request.yml) and follow the instructions there. Please be as descriptive as possible. You may even include implementation proposals! + +### Other suggestions + +If you instead want to suggest improvements to documentation, deployment pipelines and build processes, or report other issues or suggestions, please [start a general discussion](https://github.com/lengors/maven-java-template/discussions/new?category=general) or [create a task for us](https://github.com/lengors/maven-java-template/issues/new?template=create_task.yml) and follow the instructions there. Please be as descriptive as possible and select the appropriate labels. + +### Pull Requests + +We also encourage direct contributions that improve the project through pull requests. To submit your changes, follow these steps: + +1. Fork the project. +2. Create a branch for your feature, bug fix or other changes. +3. Implement your changes and ensure they adhere to our code style and conventions. +4. Write tests to validate your changes (if applicable). +5. Submit a pull request (PR) to our [GitHub repository](https://github.com/lengors/maven-java-template). + +Your PR will be reviewed by project maintainers. If necessary, we may request further changes before merging. + +## Code Style + +To maintain a consistent codebase, we use [Checkstyle](https://checkstyle.org/) with its default settings. Make sure to run Checkstyle locally before pushing your changes to catch any issues early. + +For commits, we’re keeping it fun and expressive with [Gitmoji](https://gitmoji.dev/). Use Gitmoji to prefix your commit messages, making them both informative and visually appealing. It's also important for our build system as it will automatically generate a new version following the [Semantic Versioning 2.0.0](https://semver.org/) specification. + +If you're new to Gitmoji, here’s a quick example: + +``` +✨ Add new feature to handle user authentication +``` + +## License + +By contributing to **maven-java-template**, you agree that your contributions will be licensed under [The Unlicense](./LICENSE). This means your contributions will be in the public domain, making them available for anyone to use for any purpose. + +Thanks again for helping make **maven-java-template** a better tool for everyone. Your contributions are truly valued, and I look forward to working together! \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c577b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bb62bc --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Welcome to Maven Java Template · [![GitHub license](https://img.shields.io/github/license/lengors/maven-java-template?color=blue)](https://github.com/facebook/react/blob/main/LICENSE) [![javadoc](https://javadoc.io/badge2/io.github.lengors/maven-java-template/javadoc.svg?color=red)](https://javadoc.io/doc/io.github.lengors/maven-java-template) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=lengors_maven-java-template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=lengors_maven-java-template) + +Welcome to **maven-java-template**, a flexible starting point for creating Maven-based Java projects. This template is designed to streamline the setup process for new Java projects, incorporating essential plugins and dependencies to get you up and running quickly. + +## Features + +- **Dependencies**: Preconfigured with Lombok, Checker Framework, Mockito, and JUnit. +- **Plugins**: Includes Checkstyle, Source, Javadoc, GPG, Central Publishing, JaCoCo, Checker Framework, Jar, and Assembly. +- **Branching Strategy**: Four branches (`main`, `beta`, `alpha`, and `dev`) to manage different stages of development and release. +- **CI/CD Pipelines**: Automated checks for code style, build, testing, static code analysis, and publishing to Maven Central. + +## Getting Started + +#### Clone the repository + +```bash +git clone https://github.com/lengors/maven-java-template.git +cd maven-java-template +``` + +#### Build the project + +Ensure you have Maven and JDK installed. Run: + +```bash +./mvnw clean install +``` + +#### Run tests + +```bash +./mvnw clean test +``` + +## Usage + +This template is designed to be as customizable as you need. You can modify dependencies, plugins, or other configurations to suit your specific project needs. + +### Configuration + +- **GPG Signing**: Ensure GPG is set up in your environment with the necessary private key. The passphrase can be set via the `MAVEN_GPG_PASSPHRASE` environment variable or directly in the `pom.xml`. +- **Maven Central Publishing**: Set your Maven Central credentials in your `settings.xml` file or via environment variables `MAVEN_CENTRAL_USERNAME` and `MAVEN_CENTRAL_PASSWORD`. +- **Publishing Releases**: The publishing action relies on [semantic-release](https://semantic-release.gitbook.io/semantic-release/) and [semantic-release-action](https://github.com/cycjimmy/semantic-release-action). The `.releaserc.yml` file defines the release pipeline and automates versioning based on semantic versioning. +- **Jar and Assembly Plugins**: The `jar` and `assembly` plugins are configured in separate Maven profiles (`jar` and `assemble`, respectively). These profiles are intended for building final applications and should be activated only if you’re creating a standalone application. For libraries, these profiles can be removed as they aren’t necessary. + +## Documentation and Resources + +For detailed guides and additional information, please refer to our [GitHub Wiki](https://github.com/lengors/maven-java-template/wiki). + +If you wish to check the detailed API documentation, visit the [Javadoc](https://javadoc.io/doc/io.github.lengors/maven-java-template) page. + +## Contributing + +Contributions are welcome! Please refer to our [Contribution Guidelines](./CONTRIBUTING.md) for more information on how to get involved. + +## License + +This project is licensed under [The Unlicense](./LICENSE), which places it in the public domain. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..2c02558 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,5 @@ +# Reporting Security Issues + +If you believe you have found a security vulnerability in **maven-java-template**, we encourage you to let us know right away. We will investigate all legitimate reports and do our best to quickly fix the problem. + +Please report the issue at: [Report a vulnerability](https://github.com/lengors/maven-java-template/security/advisories/new) \ No newline at end of file diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..19529dd --- /dev/null +++ b/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..66d5004 --- /dev/null +++ b/pom.xml @@ -0,0 +1,413 @@ + + + + 4.0.0 + + io.github.lengors + maven-java-template + 1.0.0 + maven-java-template + https://github.com/lengors/maven-java-template + Template repository for maven projects written in java. + + + + lengors + 24527258+lengors@users.noreply.github.com + + + + + https://github.com/lengors/maven-java-template + + + + + The Unlicense + https://unlicense.org/UNLICENSE + + + + + + UTF-8 + + + 21 + 21 + + + 0.5.0 + 3.46.0 + 3.4.0 + 1.18.20.0 + 3.13.0 + 3.7.1 + 5.12.0 + 3.8.0 + 1.18.34 + 0.8.12 + 3.3.1 + 5.10.3 + 3.2.4 + 3.4.2 + + + lengors-github + https://sonarcloud.io + + + + + + + org.junit + junit-bom + ${maven.junit.version} + pom + import + + + + + + + + org.checkerframework + checker-qual + ${maven.checkerframework.version} + + + + org.projectlombok + lombok + ${maven.lombok.version} + provided + + + + org.junit.jupiter + junit-jupiter + test + + + + org.mockito + mockito-core + ${maven.mockito.version} + + + org.mockito + mockito-junit-jupiter + ${maven.mockito.version} + test + + + + + target/generated-sources/delombok + target/generated-test-sources/delombok + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven.checkstyle.version} + + + src/main/java + src/test/java + + + + + + org.projectlombok + lombok-maven-plugin + ${maven.delombok.version} + + + org.projectlombok + lombok + ${maven.lombok.version} + + + + + delombok + generate-sources + + delombok + + + false + src/main/java + + + + test-delombok + generate-test-sources + + testDelombok + + + false + src/test/java + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.version} + + + attach-sources + verify + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven.javadoc.version} + + + attach-javadocs + + jar + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven.gpg.version} + + ${MAVEN_GPG_KEYNAME} + + + + sign-artifacts + verify + + sign + + + + + + + org.sonatype.central + central-publishing-maven-plugin + ${maven.central-publishing.version} + true + + central + true + published + + + + + org.jacoco + jacoco-maven-plugin + ${maven.jacoco.version} + + + prepare-agent + + prepare-agent + + + + report + + report + + + + XML + + + + + + + + + + + + + checkerframework + + + [1.8,) + + + + + maven-compiler-plugin + ${maven.compiler.version} + + true + + + org.checkerframework + checker + ${maven.checkerframework.version} + + + + + org.checkerframework.checker.nullness.NullnessChecker + + + -Xmaxerrs + 10000 + -Xmaxwarns + 10000 + + + + + + + + + checkerframework-jdk8 + + 1.8 + + + + 9+181-r4173-1 + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + + copy + + process-sources + + com.google.errorprone:javac:${javac.version}:jar + ${project.build.directory}/javac + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -J-Xbootclasspath/p:${project.build.directory}/javac/javac-${javac.version}.jar + + + + + + + + + checkerframework-jdk9orlater + + [9,) + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED + + + + + + + + + jar + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven.jar.version} + + + + true + io.github.lengors.maven_java_template.Example + + + + + + + + + + assemble + + + + org.apache.maven.plugins + maven-assembly-plugin + ${maven.assembly.version} + + + + io.github.lengors.maven_java_template.Example + + + + jar-with-dependencies + + + + + package + + single + + + + + + + + + \ No newline at end of file diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..fc82c27 --- /dev/null +++ b/settings.xml @@ -0,0 +1,13 @@ + + + + + central + ${MAVEN_CENTRAL_USERNAME} + ${MAVEN_CENTRAL_PASSWORD} + + + \ No newline at end of file diff --git a/src/main/java/io/github/lengors/maven_java_template/Example.java b/src/main/java/io/github/lengors/maven_java_template/Example.java new file mode 100644 index 0000000..995999b --- /dev/null +++ b/src/main/java/io/github/lengors/maven_java_template/Example.java @@ -0,0 +1,28 @@ +package io.github.lengors.maven_java_template; + +/** + * Example for project template. + */ +public final class Example { + private Example() { + throw new UnsupportedOperationException(); + } + + /** + * Example method. + * + * @return Value for example method + */ + public static String example() { + return "Hello, World!"; + } + + /** + * Example for main method. + * + * @param arguments Arguments for example program + */ + public static void main(final String[] arguments) { + + } +} diff --git a/src/main/java/io/github/lengors/maven_java_template/package-info.java b/src/main/java/io/github/lengors/maven_java_template/package-info.java new file mode 100644 index 0000000..0479123 --- /dev/null +++ b/src/main/java/io/github/lengors/maven_java_template/package-info.java @@ -0,0 +1,5 @@ + +/** + * Example package for project template. + */ +package io.github.lengors.maven_java_template; diff --git a/src/test/java/io/github/lengors/maven_java_template/ExampleTest.java b/src/test/java/io/github/lengors/maven_java_template/ExampleTest.java new file mode 100644 index 0000000..b5e6eb0 --- /dev/null +++ b/src/test/java/io/github/lengors/maven_java_template/ExampleTest.java @@ -0,0 +1,36 @@ +package io.github.lengors.maven_java_template; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.platform.commons.util.ReflectionUtils; + +/** + * Example test suite for {@link Example}. + */ +public class ExampleTest { + /** + * Exampel test for {@link Example#Example()}. + */ + @Test + public void shouldThrowUnsupportedOperationExceptionWhenInstantiateExample() { + Assertions.assertThrows(UnsupportedOperationException.class, () -> { + ReflectionUtils.newInstance(Example.class); + }); + } + + /** + * Exampel test for {@link Example#example()}. + */ + @Test + public void shouldGetHelloWorldFromExampleFunction() { + Assertions.assertEquals("Hello, World!", Example.example()); + } + + /** + * Exampel test for {@link Example#main(String[])}. + */ + @Test + public void shouldExecuteMainFunctionWithoutErrors() { + Example.main(new String[] {}); + } +} diff --git a/src/test/java/io/github/lengors/maven_java_template/package-info.java b/src/test/java/io/github/lengors/maven_java_template/package-info.java new file mode 100644 index 0000000..0236498 --- /dev/null +++ b/src/test/java/io/github/lengors/maven_java_template/package-info.java @@ -0,0 +1,4 @@ +/** + * Example package for project template. + */ +package io.github.lengors.maven_java_template;