diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml new file mode 100644 index 0000000..89a8979 --- /dev/null +++ b/.github/workflows/build-test.yaml @@ -0,0 +1,36 @@ +name: Java CI-CD + +on: + push: + branches: ['master'] + +jobs: + build-test: + runs-on: ubuntu-latest + + steps: + - name: checkout the code + uses: actions/checkout@v3 + + - name: setup java 17 + uses: actions/checkout@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: build with maven + run: mvn clean install + + - name: test with maven + run: mvn test + + - name: Sonar Analysis + uses: actions/check@v2 + + - name: sonarqube scan + uses: sonarqube/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..ab56252 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,30 @@ +name: CI/CD workflow for Maven Build and Sonar Code scan +on: + push: + branches: + - master + workflow_dispatch: +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn clean install + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master + with: + args: > + -Dsonar.projectKey=Github-Actions + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..20ecd99 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,30 @@ +pipeline { + agent any + tools { + maven 'Maven3' + } + stages { + stage('git-checkout') { + steps { + git branch: 'main', changelog: false, poll: false, + url: 'https://github.com/ash2code/Java-Hello-World.git' + } + } + stage('code-build') { + steps { + sh 'mvn clean package' + } + } + stage('sonar-analysis') { + steps { + withSonarQubeEnv('sonar') { // 'sonar' should match your SonarQube configuration in Jenkins + sh '''mvn clean verify sonar:sonar \ + -Dsonar.projectKey=Calculator \ + -Dsonar.projectName="Calculator" \ + -Dsonar.host.url=http://3.109.200.189:9000 \ + -Dsonar.login=sqp_985a8e41f28abf1fc4da1889ba6a427747c842ff''' + } + } + } + } +} diff --git a/notepad.txt b/notepad.txt new file mode 100644 index 0000000..ff885ee --- /dev/null +++ b/notepad.txt @@ -0,0 +1,9 @@ +india +aus +us +uk +wi +mnbn +,mnbjb +erwvy +kuuhkhjkhj diff --git a/pom.xml b/pom.xml index 05c1c77..c5ec407 100644 --- a/pom.xml +++ b/pom.xml @@ -1,41 +1,37 @@ - 4.0.0 - com.ravi.cal - RaviCalculator - 1.3 - jar - RaviCalculator - http://maven.apache.org - - UTF-8 - 1.6 - 1.6 - - - - junit - junit - 4.8.2 - test - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - - com.ravi.cal.RaviCalculator.Calculator - - - - - - + 4.0.0 + com.ravi.cal + RaviCalculator + 1.3 + jar + RaviCalculator + http://maven.apache.org + + UTF-8 + 1.7 1.7 + + + junit + junit + 4.8.2 + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + com.ravi.cal.RaviCalculator.Calculator + + + + + + diff --git a/src/main/java/com/ravi/cal/RaviCalculator/Calculator.java b/src/main/java/com/ravi/cal/RaviCalculator/Calculator.java index 092af4b..386912e 100644 --- a/src/main/java/com/ravi/cal/RaviCalculator/Calculator.java +++ b/src/main/java/com/ravi/cal/RaviCalculator/Calculator.java @@ -4,7 +4,7 @@ public class Calculator { private long first; private long second; - + public Calculator(long first, long second){ this.first = first; this.second=second; @@ -22,7 +22,7 @@ public long addFucn(long first, long second){ return first+second; } - + public long subFucn(long first, long second){ return second-first; @@ -32,12 +32,12 @@ public long mulFucn(long first, long second){ return first*second; } - - + //java code public static void main(String[] args) { long first = Long.parseLong(args[0]); long second = Long.parseLong(args[1]); + int a = 3; Calculator cal = new Calculator(first, second); String output = String.format("\n*** Your Results ***\n\nFirst: %d\nSecond: %d\n\nSum : %d\nDifference : %d\nProduct : %d\n\n", cal.first, cal.second, cal.addFucn(first, second), cal.subFucn(first, second), cal.mulFucn(first, second)); diff --git a/target/RaviCalculator-1.3.jar b/target/RaviCalculator-1.3.jar new file mode 100644 index 0000000..c4553b3 Binary files /dev/null and b/target/RaviCalculator-1.3.jar differ diff --git a/target/classes/com/ravi/cal/RaviCalculator/Calculator.class b/target/classes/com/ravi/cal/RaviCalculator/Calculator.class new file mode 100644 index 0000000..7fa3e07 Binary files /dev/null and b/target/classes/com/ravi/cal/RaviCalculator/Calculator.class differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..4099c7d --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.7 +groupId=com.ravi.cal +artifactId=RaviCalculator +version=1.3 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..d6f796a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +com/ravi/cal/RaviCalculator/Calculator.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..7648f90 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/ubuntu/JavaCalculator/src/main/java/com/ravi/cal/RaviCalculator/Calculator.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..c409e5a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com/ravi/cal/Calculator/CalculatorTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..b9c75f5 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/ubuntu/JavaCalculator/src/test/java/com/ravi/cal/RaviCalculator/CalculatorTest.java diff --git a/target/sonar/.sonar_lock b/target/sonar/.sonar_lock new file mode 100644 index 0000000..e69de29 diff --git a/target/sonar/report-task.txt b/target/sonar/report-task.txt new file mode 100644 index 0000000..54c433b --- /dev/null +++ b/target/sonar/report-task.txt @@ -0,0 +1,6 @@ +projectKey=Calculator +serverUrl=http://13.126.141.189:9000 +serverVersion=10.7.0.96327 +dashboardUrl=http://13.126.141.189:9000/dashboard?id=Calculator +ceTaskId=9ce7cecc-beca-45d0-9250-b414e8289df5 +ceTaskUrl=http://13.126.141.189:9000/api/ce/task?id=9ce7cecc-beca-45d0-9250-b414e8289df5 diff --git a/target/surefire-reports/TEST-com.ravi.cal.Calculator.CalculatorTest.xml b/target/surefire-reports/TEST-com.ravi.cal.Calculator.CalculatorTest.xml new file mode 100644 index 0000000..6288ed6 --- /dev/null +++ b/target/surefire-reports/TEST-com.ravi.cal.Calculator.CalculatorTest.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.ravi.cal.Calculator.CalculatorTest.txt b/target/surefire-reports/com.ravi.cal.Calculator.CalculatorTest.txt new file mode 100644 index 0000000..894947e --- /dev/null +++ b/target/surefire-reports/com.ravi.cal.Calculator.CalculatorTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.ravi.cal.Calculator.CalculatorTest +------------------------------------------------------------------------------- +Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.018 sec diff --git a/target/test-classes/com/ravi/cal/Calculator/CalculatorTest.class b/target/test-classes/com/ravi/cal/Calculator/CalculatorTest.class new file mode 100644 index 0000000..c58f1fd Binary files /dev/null and b/target/test-classes/com/ravi/cal/Calculator/CalculatorTest.class differ