From 69598880bd5619e6597d38aa4ba24bdb7c7a7fdb Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Sun, 14 Aug 2022 23:32:24 -0700 Subject: [PATCH 1/9] Move to caluclator --- .github/workflows/ci.yml | 18 +++++ .travis.yml | 9 --- pom.xml | 80 +++++++------------ src/Calculator.java | 7 ++ src/CalculatorTest.java | 12 +++ .../examples/maven/java/HelloWorld.java | 13 --- .../examples/maven/java/HelloWorldTest.java | 22 ----- 7 files changed, 66 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 src/Calculator.java create mode 100644 src/CalculatorTest.java delete mode 100644 src/main/java/org/jacoco/examples/maven/java/HelloWorld.java delete mode 100644 src/test/java/org/jacoco/examples/maven/java/HelloWorldTest.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..20c7de6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: Workflow for Codecov example-java +on: [push, pull_request] +jobs: + run: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up JDK 18 + uses: actions/setup-java@v1 + with: + java-version: 18 + - name: Test with Maven + run: mvn -B test --file pom.xml + - name: ls + run: ls + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 665c26e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: java -sudo: false # faster builds - -jdk: - - oraclejdk11 - - oraclejdk14 - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/pom.xml b/pom.xml index 8923188..30a14e2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,70 +1,48 @@ - - - + 4.0.0 + io.codecov + example-java + 1.0 - org.jacoco - org.jacoco.examples.maven.java - 1.0-SNAPSHOT - jar - - JaCoCo Maven plug-in example for Java project - http://www.eclemma.org/jacoco + Codecov example Java repository + http://github.com/codecov/example-java + 18 UTF-8 - 1.8 - 1.8 junit junit - 4.13.2 + 5.7.1 test - src/main/java - - - org.jacoco - jacoco-maven-plugin - 0.8.7 - - - - prepare-agent - - - - report - test - - report - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + + diff --git a/src/Calculator.java b/src/Calculator.java new file mode 100644 index 0000000..efa95f0 --- /dev/null +++ b/src/Calculator.java @@ -0,0 +1,7 @@ +package io.codecov; + +public class Calculator { + public int add(int x, int y) { + return x + y + } +} diff --git a/src/CalculatorTest.java b/src/CalculatorTest.java new file mode 100644 index 0000000..c03a822 --- /dev/null +++ b/src/CalculatorTest.java @@ -0,0 +1,12 @@ +package io.codecov; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CalculatorTest { + @Test + public void testAdd() { + assertEquals(new Calculator.add(1, 1), 2); + } +} diff --git a/src/main/java/org/jacoco/examples/maven/java/HelloWorld.java b/src/main/java/org/jacoco/examples/maven/java/HelloWorld.java deleted file mode 100644 index 15edac4..0000000 --- a/src/main/java/org/jacoco/examples/maven/java/HelloWorld.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.jacoco.examples.maven.java; - -public class HelloWorld { - - public String getMessage(boolean bigger) { - if (bigger) { - return "Hello Universe!"; - } else { - return "Hello World!"; - } - } - -} diff --git a/src/test/java/org/jacoco/examples/maven/java/HelloWorldTest.java b/src/test/java/org/jacoco/examples/maven/java/HelloWorldTest.java deleted file mode 100644 index 6b8451e..0000000 --- a/src/test/java/org/jacoco/examples/maven/java/HelloWorldTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.jacoco.examples.maven.java; - -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -public class HelloWorldTest { - - private HelloWorld subject; - - @Before - public void setup() { - subject = new HelloWorld(); - } - - @Test - public void testGetMessage() { - assertEquals("Hello World!", subject.getMessage(false)); - } - -} From 8a1bb0b57fc063a0562d6c0e316e3ef1d2b2a221 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:07:19 -0700 Subject: [PATCH 2/9] maven --- .github/workflows/{ci.yml => ci-maven.yml} | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename .github/workflows/{ci.yml => ci-maven.yml} (72%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci-maven.yml similarity index 72% rename from .github/workflows/ci.yml rename to .github/workflows/ci-maven.yml index 20c7de6..66987f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci-maven.yml @@ -1,4 +1,4 @@ -name: Workflow for Codecov example-java +name: Workflow for Codecov example-java using Maven on: [push, pull_request] jobs: run: @@ -10,6 +10,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 18 + - name: Install dependencies + run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V - name: Test with Maven run: mvn -B test --file pom.xml - name: ls From 9c93db971039de623d37af3437217b8acd5dd642 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:10:00 -0700 Subject: [PATCH 3/9] plugins --- pom.xml | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 30a14e2..8925cee 100644 --- a/pom.xml +++ b/pom.xml @@ -23,26 +23,28 @@ - - org.jacoco - jacoco-maven-plugin - 0.8.8 - - - prepare-agent - - prepare-agent - - - - report - test - - report - - - - + + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + + From 13ce5beca9e905f16b6e717231edd6f7a1c900a6 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:11:27 -0700 Subject: [PATCH 4/9] version of junit to 4.13.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8925cee..7e9935f 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ junit junit - 5.7.1 + 4.13.2 test From 8c39974e5899bca59004d1255d51abc60732de06 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:45:28 -0700 Subject: [PATCH 5/9] Update dir structure --- .gitignore | 1 + pom.xml | 3 ++- src/Calculator.java | 7 ------- src/main/java/calculator/Calculator.java | 7 +++++++ src/{ => test/java/calculator}/CalculatorTest.java | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .gitignore delete mode 100644 src/Calculator.java create mode 100644 src/main/java/calculator/Calculator.java rename src/{ => test/java/calculator}/CalculatorTest.java (65%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/pom.xml b/pom.xml index 7e9935f..8959d20 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,8 @@ Codecov example Java repository http://github.com/codecov/example-java - 18 + 18 + 18 UTF-8 diff --git a/src/Calculator.java b/src/Calculator.java deleted file mode 100644 index efa95f0..0000000 --- a/src/Calculator.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.codecov; - -public class Calculator { - public int add(int x, int y) { - return x + y - } -} diff --git a/src/main/java/calculator/Calculator.java b/src/main/java/calculator/Calculator.java new file mode 100644 index 0000000..86a68eb --- /dev/null +++ b/src/main/java/calculator/Calculator.java @@ -0,0 +1,7 @@ +package calculator; + +public class Calculator { + public static int add(int x, int y) { + return x + y; + } +} diff --git a/src/CalculatorTest.java b/src/test/java/calculator/CalculatorTest.java similarity index 65% rename from src/CalculatorTest.java rename to src/test/java/calculator/CalculatorTest.java index c03a822..fc08b21 100644 --- a/src/CalculatorTest.java +++ b/src/test/java/calculator/CalculatorTest.java @@ -1,4 +1,4 @@ -package io.codecov; +package calculator; import static org.junit.Assert.*; @@ -7,6 +7,6 @@ public class CalculatorTest { @Test public void testAdd() { - assertEquals(new Calculator.add(1, 1), 2); + assertEquals(new Calculator().add(1, 1), 2); } } From cf7246ca530a4d92439dccdfcbc4e4d158523fd3 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:48:18 -0700 Subject: [PATCH 6/9] Update calculator --- src/main/java/calculator/Calculator.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/calculator/Calculator.java b/src/main/java/calculator/Calculator.java index 86a68eb..4ab41f8 100644 --- a/src/main/java/calculator/Calculator.java +++ b/src/main/java/calculator/Calculator.java @@ -1,7 +1,23 @@ package calculator; public class Calculator { - public static int add(int x, int y) { + public static double add(double x, double y) { return x + y; } + + public static double subtract(double x, double y) { + return x - y; + } + + public static double multiply(double x, double y) { + return x * y; + } + + public static double divide(double x, double y) { + if (y == 0) { + System.out.println("Cannot divide by 0"); + return 0; + } + return x / y; + } } From 7d5ff74696f1b92b4ac950284809fc8232497cce Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:52:46 -0700 Subject: [PATCH 7/9] Update tests --- .github/workflows/ci-maven.yml | 2 -- src/test/java/calculator/CalculatorTest.java | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-maven.yml b/.github/workflows/ci-maven.yml index 66987f6..ee78883 100644 --- a/.github/workflows/ci-maven.yml +++ b/.github/workflows/ci-maven.yml @@ -14,7 +14,5 @@ jobs: run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V - name: Test with Maven run: mvn -B test --file pom.xml - - name: ls - run: ls - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/src/test/java/calculator/CalculatorTest.java b/src/test/java/calculator/CalculatorTest.java index fc08b21..4735e30 100644 --- a/src/test/java/calculator/CalculatorTest.java +++ b/src/test/java/calculator/CalculatorTest.java @@ -5,8 +5,10 @@ import org.junit.Test; public class CalculatorTest { + private static final double DELTA = 0.001; + @Test public void testAdd() { - assertEquals(new Calculator().add(1, 1), 2); + assertEquals(new Calculator().add(1, 1), 2, DELTA); } } From f34cf056e38cacb53fef76257cd53711593f041e Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 15 Aug 2022 12:56:59 -0700 Subject: [PATCH 8/9] Add all tests --- src/test/java/calculator/CalculatorTest.java | 36 ++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/test/java/calculator/CalculatorTest.java b/src/test/java/calculator/CalculatorTest.java index 4735e30..0f860a3 100644 --- a/src/test/java/calculator/CalculatorTest.java +++ b/src/test/java/calculator/CalculatorTest.java @@ -1,6 +1,6 @@ package calculator; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -9,6 +9,38 @@ public class CalculatorTest { @Test public void testAdd() { - assertEquals(new Calculator().add(1, 1), 2, DELTA); + assertEquals(Calculator.add(1, 2), 3.0, DELTA); + assertEquals(Calculator.add(1.0, 2.0), 3.0, DELTA); + assertEquals(Calculator.add(0, 2.0), 2.0, DELTA); + assertEquals(Calculator.add(2.0, 0), 2.0, DELTA); + assertEquals(Calculator.add(-4, 2.0), -2.0, DELTA); + } + + @Test + public void testSubtract() { + assertEquals(Calculator.subtract(1, 2), -1.0, DELTA); + assertEquals(Calculator.subtract(2, 1), 1.0, DELTA); + assertEquals(Calculator.subtract(1.0, 2.0), -1.0, DELTA); + assertEquals(Calculator.subtract(0, 2.0), -2.0, DELTA); + assertEquals(Calculator.subtract(2.0, 0), 2.0, DELTA); + assertEquals(Calculator.subtract(-4, 2.0), -6.0, DELTA); + } + + @Test + public void testMultiply() { + assertEquals(Calculator.multiply(1, 2), 2.0, DELTA); + assertEquals(Calculator.multiply(1.0, 2.0), 2.0, DELTA); + assertEquals(Calculator.multiply(0, 2.0), 0.0, DELTA); + assertEquals(Calculator.multiply(2.0, 0), 0.0, DELTA); + assertEquals(Calculator.multiply(-4, 2.0), -8.0, DELTA); + } + + @Test + public void testDivide() { + assertEquals(Calculator.divide(1, 2), 0.5, DELTA); + assertEquals(Calculator.divide(1.0, 2.0), 0.5, DELTA); + assertEquals(Calculator.divide(0, 2.0), 0, DELTA); + assertEquals(Calculator.divide(-4, 2.0), -2.0, DELTA); + // assertEquals(Calculator.divide(2.0, 0), 0.0, DELTA); } } From ea816710a3f143c9de818814342c450937b4fb0d Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Wed, 24 Aug 2022 17:24:25 -0700 Subject: [PATCH 9/9] strip repository to be a placeholder --- .github/dependabot.yml | 7 -- .github/workflows/ci-maven.yml | 18 ----- .gitignore | 1 - README.md | 77 +++----------------- pom.xml | 51 ------------- src/main/java/calculator/Calculator.java | 23 ------ src/test/java/calculator/CalculatorTest.java | 46 ------------ 7 files changed, 12 insertions(+), 211 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/ci-maven.yml delete mode 100644 .gitignore delete mode 100644 pom.xml delete mode 100644 src/main/java/calculator/Calculator.java delete mode 100644 src/test/java/calculator/CalculatorTest.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index a217b34..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: maven - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/.github/workflows/ci-maven.yml b/.github/workflows/ci-maven.yml deleted file mode 100644 index ee78883..0000000 --- a/.github/workflows/ci-maven.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Workflow for Codecov example-java using Maven -on: [push, pull_request] -jobs: - run: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up JDK 18 - uses: actions/setup-java@v1 - with: - java-version: 18 - - name: Install dependencies - run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V - - name: Test with Maven - run: mvn -B test --file pom.xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2f7896d..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/README.md b/README.md index f9764b7..ad1db91 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,17 @@ -# [Codecov][0] Java Example - -[![Build Status](https://travis-ci.org/codecov/example-java.svg?branch=master)](https://travis-ci.org/codecov/example-java) -[![codecov](https://codecov.io/gh/codecov/example-java/branch/master/graph/badge.svg)](https://codecov.io/gh/codecov/example-java) +# [Codecov](https://codecov.io) Java [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java?ref=badge_shield) -## Guide - -### Travis Setup - -Add the following to your `.travis.yml`: -```yml -language: java -after_success: - - bash <(curl -s https://codecov.io/bash) -``` - -### Produce Coverage Reports -1. Add JaCoCo Plugin to your pom.xml file, [see here](https://github.com/codecov/example-java/blob/master/pom.xml#L43-L61) - -## Caveats - -#### Private Repo -You will need to add the following your `.travis.yml`: -```yml -env: - global: - - CODECOV_TOKEN=:uuid-repo-token -``` - -#### JaCoCo Reports - -- Make sure you are using the latest version of JaCoCo. There are issues with previous versions of JaCoCo. -- JaCoCo reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired. - -## Support - -### FAQ -- Q: How do I enable multi-module projects?
A: In your `pom.xml` file please append a list of modules in your projects: -```xml - - - module_a/ - module_b/ - - -``` -- Q: Seeing `Skipping JaCoCo execution due to missing execution data file`?
A: Please see [http://stackoverflow.com/questions/18107375/...](http://stackoverflow.com/questions/18107375/getting-skipping-jacoco-execution-due-to-missing-execution-data-file-upon-exec). -- We should talk about using other CIs here. -- Q: Does Codecov accept `jacoco.exec` reports?
A: **No**, these files are not supported. Please produce a `xml` file as detailed in the pom.xml file at [codecov/example-java][1]. -- Q: Is there a Gradle example?
A: **Yes**, enter [codecov/example-gradle][2] -- Q: Is there a Android example?
A: **Yes**, enter [codecov/example-android][3] -- Q: Is there a Maven example?
A: **Yes**, enter [codecov/example-maven][4] - -1. More documentation at https://docs.codecov.io -2. Configure codecov through the `codecov.yml` https://docs.codecov.io/docs/codecov-yaml -3. View source and learn more about [Codecov Global Uploader](https://github.com/codecov/codecov-bash) - -We are happy to help if you have any questions. Please contact email our Support at [support@codecov.io](mailto:support@codecov.io) +This repository points to other example repositories on how Codecov can be integrated with a simple Java project. -[0]: https://codecov.io/ -[1]: https://github.com/codecov/example-java -[2]: https://github.com/codecov/example-gradle -[3]: https://github.com/codecov/example-android -[4]: https://github.com/codecov/example-java-maven -[5]: https://docs.codecov.io/docs/about-the-codecov-bash-uploader#section-upload-token +- [example-java-gradle](https://github.com/codecov/example-java-gradle) +- [example-java-maven](https://github.com/codecov/example-java-maven) +- [example-java-android](https://github.com/codecov/example-java-android) +For more information, please see the links below. -## License -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java?ref=badge_large) +## Links +- [Quick Start](https://docs.codecov.com/docs/quick-start) +- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial) +- [Community Boards](https://community.codecov.io) +- [Support](https://codecov.io/support) +- [Documentation](https://docs.codecov.io) diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 8959d20..0000000 --- a/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - 4.0.0 - io.codecov - example-java - 1.0 - - Codecov example Java repository - http://github.com/codecov/example-java - - 18 - 18 - UTF-8 - - - - - junit - junit - 4.13.2 - test - - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.8 - - - prepare-agent - - prepare-agent - - - - report - test - - report - - - - - - - - diff --git a/src/main/java/calculator/Calculator.java b/src/main/java/calculator/Calculator.java deleted file mode 100644 index 4ab41f8..0000000 --- a/src/main/java/calculator/Calculator.java +++ /dev/null @@ -1,23 +0,0 @@ -package calculator; - -public class Calculator { - public static double add(double x, double y) { - return x + y; - } - - public static double subtract(double x, double y) { - return x - y; - } - - public static double multiply(double x, double y) { - return x * y; - } - - public static double divide(double x, double y) { - if (y == 0) { - System.out.println("Cannot divide by 0"); - return 0; - } - return x / y; - } -} diff --git a/src/test/java/calculator/CalculatorTest.java b/src/test/java/calculator/CalculatorTest.java deleted file mode 100644 index 0f860a3..0000000 --- a/src/test/java/calculator/CalculatorTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package calculator; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class CalculatorTest { - private static final double DELTA = 0.001; - - @Test - public void testAdd() { - assertEquals(Calculator.add(1, 2), 3.0, DELTA); - assertEquals(Calculator.add(1.0, 2.0), 3.0, DELTA); - assertEquals(Calculator.add(0, 2.0), 2.0, DELTA); - assertEquals(Calculator.add(2.0, 0), 2.0, DELTA); - assertEquals(Calculator.add(-4, 2.0), -2.0, DELTA); - } - - @Test - public void testSubtract() { - assertEquals(Calculator.subtract(1, 2), -1.0, DELTA); - assertEquals(Calculator.subtract(2, 1), 1.0, DELTA); - assertEquals(Calculator.subtract(1.0, 2.0), -1.0, DELTA); - assertEquals(Calculator.subtract(0, 2.0), -2.0, DELTA); - assertEquals(Calculator.subtract(2.0, 0), 2.0, DELTA); - assertEquals(Calculator.subtract(-4, 2.0), -6.0, DELTA); - } - - @Test - public void testMultiply() { - assertEquals(Calculator.multiply(1, 2), 2.0, DELTA); - assertEquals(Calculator.multiply(1.0, 2.0), 2.0, DELTA); - assertEquals(Calculator.multiply(0, 2.0), 0.0, DELTA); - assertEquals(Calculator.multiply(2.0, 0), 0.0, DELTA); - assertEquals(Calculator.multiply(-4, 2.0), -8.0, DELTA); - } - - @Test - public void testDivide() { - assertEquals(Calculator.divide(1, 2), 0.5, DELTA); - assertEquals(Calculator.divide(1.0, 2.0), 0.5, DELTA); - assertEquals(Calculator.divide(0, 2.0), 0, DELTA); - assertEquals(Calculator.divide(-4, 2.0), -2.0, DELTA); - // assertEquals(Calculator.divide(2.0, 0), 0.0, DELTA); - } -}