diff --git a/.github/workflows/build-and-analyze.yml b/.github/workflows/build-and-analyze.yml new file mode 100644 index 0000000..cb942a9 --- /dev/null +++ b/.github/workflows/build-and-analyze.yml @@ -0,0 +1,37 @@ +name: Java CI with Maven and SonarCloud + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + types: [opened, synchronize, reopened] + +jobs: + build-and-analyze: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Necessary for a comprehensive SonarCloud analysis + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + + - name: Cache Maven and SonarCloud packages + uses: actions/cache@v3 + with: + path: | + ~/.m2 + ~/.sonar/cache + key: ${{ runner.os }}-m2-sonar-${{ hashFiles('**/pom.xml') }} + + - name: Build and analyze with Maven + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: mvn -B verify --file pom.xml org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -PcoverageReport diff --git a/.github/workflows/sonatype-publish.yml b/.github/workflows/sonatype-publish.yml new file mode 100644 index 0000000..4f4319c --- /dev/null +++ b/.github/workflows/sonatype-publish.yml @@ -0,0 +1,37 @@ +name: Maven Library Publish + +on: + release: + types: [ created ] + +jobs: + publish: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 for deploy to Sonatype + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: 17 + server-id: central + server-username: MAVEN_USERNAME + server-password: MAVEN_CENTRAL_TOKEN + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Prepare Maven environnement with Java 17 for deployment to Sonatype + run: export MAVEN_OPTS="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED" + + - name: Publish to Apache Maven Central + run: mvn deploy -PsonatypeDeploy + env: + MAVEN_USERNAME: ${{ secrets.NEXUS_USERNAME }} + MAVEN_CENTRAL_TOKEN: ${{ secrets.NEXUS_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.gitignore b/.gitignore index 2f43530..e0684cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,33 @@ -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -# https://github.com/takari/maven-wrapper#usage-without-binary-jar -.mvn/wrapper/maven-wrapper.jar +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.idea/ -# Eclipse m2e generated files -# Eclipse Core -.project -# JDT-specific (Eclipse Java Development Tools) +### Eclipse ### +.apt_generated .classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +### maven ??### +target \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b3ad539 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2010 Bennu SpA Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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 OR COPYRIGHT HOLDERS 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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7628452 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +Bennu SpringBoot-Commons +=================== + +[![Maven Central](https://img.shields.io/maven-central/v/cl.bennu/spring-boot-commons?label=Maven%20Central&logo=sonatype)](https://search.maven.org/artifact/cl.bennu/spring-boot-commons) +[![License](https://img.shields.io/github/license/bennu/mybatis-commons?label=License&logo=opensourceinitiative)](https://opensource.org/license/mit-0) +[![Supported JVM Versions](https://img.shields.io/badge/JVM-17--21-brightgreen.svg?label=JVM&logo=openjdk)](https://adoptium.net/es/temurin/releases/) + +Bennu MyBatis-Commons, a package of Java utility classes for +classes that are repeated in our mybatis projects. + +The code is tested using the latest revision of the JDK for supported +LTS releases: 17 and 21. + +```xml + + cl.bennu + spring-boot-commons + 0.0.1 + +``` + +Building +-------- + +Building requires a Java JDK and [Apache Maven](https://maven.apache.org/). +The required Java version is found in the `pom.xml` as the `maven.compiler.source` property. + +From a command shell, run `mvn` without arguments to invoke the default Maven goal to run all tests and checks. + +License +------- + +This code is licensed under the [MIT License](https://opensource.org/license/mit). + +Dependencies +------------ + +- commons 1.2.0 +- spring-web 6.2.5 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..542c34a --- /dev/null +++ b/pom.xml @@ -0,0 +1,197 @@ + + + + 4.0.0 + + cl.bennu + spring-boot-commons + 0.0.1 + bennu-spring-boot-commons + Utilitarios bennu para SpringBoot + https://github.com/bennu/spring-boot-commons + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + + + + + + Bennu + soporte@bennu.cl + https://bennu.cl/ + Bennu SpA + https://github.com/bennu + + + + + scm:git:git@github.com:bennu/spring-boot-commons.git + scm:git:git@github.com:bennu/spring-boot-commons.git + git@github.com:bennu/spring-boot-commons.git + + + + 17 + 17 + 17 + 17 + UTF-8 + UTF-8 + + + + + cl.bennu + commons + 1.2.0 + + + + org.springframework + spring-web + 6.2.5 + + + + + + + sonatypeDeploy + + + + org.sonatype.central + central-publishing-maven-plugin + 0.3.0 + true + + central + true + true + published + + + + org.apache.maven.plugins + maven-source-plugin + 3.3.0 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.6.3 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + + + coverageReport + + + + maven-surefire-plugin + 3.2.5 + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + prepare-agent + + prepare-agent + + + + report + + report + + + + XML + + + + + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.10.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.3.1 + + + attach-sources + + jar-no-fork + + + + + + + + \ No newline at end of file diff --git a/src/main/java/cl/bennu/commons/controller/ExampleController.java b/src/main/java/cl/bennu/commons/controller/ExampleController.java new file mode 100644 index 0000000..eca6a53 --- /dev/null +++ b/src/main/java/cl/bennu/commons/controller/ExampleController.java @@ -0,0 +1,34 @@ +package cl.bennu.commons.controller; + +import cl.bennu.commons.controller.base.BaseController; +import cl.bennu.commons.domain.base.BaseDomain; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping(path = "/example", produces = MediaType.APPLICATION_JSON_VALUE) +public class ExampleController extends BaseController { + + @GetMapping + public List getAll() { + return null; + } + + @GetMapping("/{id}") + public BaseDomain getById(@PathVariable Long id) { + return null; + } + + @PostMapping + public void save(@RequestHeader(value = "Authorization", required = false) String token, @RequestBody BaseDomain baseDomain) { + + } + + @DeleteMapping("/{id}") + public void delete(@RequestHeader(value = "Authorization", required = false) String token, @PathVariable Long id) { + + } + +} diff --git a/src/main/java/cl/bennu/commons/controller/base/BaseController.java b/src/main/java/cl/bennu/commons/controller/base/BaseController.java new file mode 100644 index 0000000..3902ea0 --- /dev/null +++ b/src/main/java/cl/bennu/commons/controller/base/BaseController.java @@ -0,0 +1,18 @@ +package cl.bennu.commons.controller.base; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; + +@CrossOrigin +public abstract class BaseController { + + protected static ResponseEntity ok() { + return ResponseEntity.ok(HttpStatus.OK); + } + + protected static ResponseEntity ok(Object o) { + return ResponseEntity.ok().body(o); + } + +} diff --git a/src/main/java/cl/bennu/commons/controller/model/common/File.java b/src/main/java/cl/bennu/commons/controller/model/common/File.java new file mode 100644 index 0000000..d376a9d --- /dev/null +++ b/src/main/java/cl/bennu/commons/controller/model/common/File.java @@ -0,0 +1,16 @@ +package cl.bennu.commons.controller.model.common; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +public class File implements Serializable { + + private String data; + private String name; + private String contentType; + +} diff --git a/src/main/java/cl/bennu/commons/controller/model/common/Value.java b/src/main/java/cl/bennu/commons/controller/model/common/Value.java new file mode 100644 index 0000000..1e6587f --- /dev/null +++ b/src/main/java/cl/bennu/commons/controller/model/common/Value.java @@ -0,0 +1,15 @@ +package cl.bennu.commons.controller.model.common; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +public class Value implements Serializable { + + private Long id; + private String value; + +}