Skip to content

Commit d6ce70f

Browse files
Merge pull request #18 from codecov/update-repo
fix: update repo with calculator app and GHA + CircleCI
2 parents 37135d7 + 3b6bc39 commit d6ce70f

File tree

10 files changed

+158
-135
lines changed

10 files changed

+158
-135
lines changed

.circleci/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2.1
2+
orbs:
3+
codecov: codecov/codecov@3
4+
5+
jobs:
6+
build:
7+
docker:
8+
- image: cimg/openjdk:18.0.2
9+
steps:
10+
- checkout
11+
- run:
12+
name: Install dependencies
13+
command: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
14+
- run:
15+
name: Run tests and collect coverage
16+
command: mvn -B test
17+
- codecov/upload
18+
19+
workflow:
20+
version: 2.1
21+
build-test:
22+
jobs:
23+
- build

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: maven
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Workflow for Codecov example-java-maven
2+
on: [push, pull_request]
3+
jobs:
4+
run:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v2
9+
- name: Set up JDK 18
10+
uses: actions/setup-java@v1
11+
with:
12+
java-version: 18
13+
- name: Install dependencies
14+
run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
15+
- name: Run tests and collect coverage
16+
run: mvn -B test
17+
- name: Upload coverage to Codecov
18+
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
target/
2-
org.jacoco.examples.maven.java.iml
3-
.idea

README.md

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,17 @@
1-
# [Codecov][1] Java Maven Example
1+
# [Codecov](https://codecov.io) Java Maven Example
2+
[![codecov](https://codecov.io/github/codecov/example-java-maven/branch/main/graph/badge.svg?token=ob1cArXXM6)](https://app.codecov.io/github/codecov/example-java-maven)
23
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bi.8713187.xyz%2Fcodecov%2Fexample-java-maven.svg?type=shield)](https://app.fossa.com/projects/git%2Bi.8713187.xyz%2Fcodecov%2Fexample-java-maven?ref=badge_shield)
34

4-
## Guide
5-
### Travis Setup
5+
This example repository shows how Codecov can be integrated with a simple java-maven project. It uses **GitHub Actions** and **CircleCI** as CI/CD providers and **Jacoco** as the coverage provider.
66

7-
Add to your `.travis.yml` file.
8-
```yml
9-
language: java
7+
For more information, please see the links below.
108

11-
# Cobertura is not supported in JDK11 so you must downgrade the JDK that Travis uses if you want to use Cobertura with Travis.
12-
# See https://github.com/cobertura/cobertura/issues/381
13-
jdk:
14-
- openjdk8
15-
16-
script: "mvn cobertura:cobertura"
17-
18-
after_success:
19-
- bash <(curl -s https://codecov.io/bash)
20-
```
21-
### Produce Coverage Reports
22-
#### Add Cobertura plugin
23-
```xml
24-
<plugin>
25-
<groupId>org.codehaus.mojo</groupId>
26-
<artifactId>cobertura-maven-plugin</artifactId>
27-
<version>2.7</version>
28-
<configuration>
29-
<formats>
30-
<format>html</format>
31-
<format>xml</format>
32-
</formats>
33-
<check />
34-
</configuration>
35-
</plugin>
36-
```
37-
Call `mvn cobertura:cobertura` during your CI tests, [see here](https://github.com/codecov/example-java-maven/blob/master/.travis.yml#L4)
38-
39-
## Caveats
40-
### Private Repos
41-
Add to your `.travis.yml` file.
42-
```yml
43-
after_success:
44-
- bash <(curl -s https://codecov.io/bash) -t uuid-repo-token
45-
```
46-
## Support
47-
### FAQ
48-
- Q: Is there a Gradle example?<br/>A: **Yes**, enter [codecov/example-gradle][2]
49-
- Q: Is there a Android example?<br/>A: **Yes**, enter [codecov/example-android][3]
50-
- Q: Is there a JaCoCo example?<br/>A: **Yes**, enter [codecov/example-java][4]
51-
52-
1. More documentation at https://docs.codecov.io
53-
2. Configure codecov through the `codecov.yml` https://docs.codecov.io/docs/codecov-yaml
54-
55-
We are happy to help if you have any questions. Please contact email our Support at [[email protected]](mailto:[email protected])
56-
57-
[1]: https://codecov.io/
58-
[2]: https://github.com/codecov/example-gradle
59-
[3]: https://github.com/codecov/example-android
60-
[4]: https://github.com/codecov/example-java
9+
## Links
10+
- [Quick Start](https://docs.codecov.com/docs/quick-start)
11+
- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial)
12+
- [Community Boards](https://community.codecov.io)
13+
- [Support](https://codecov.io/support)
14+
- [Documentation](https://docs.codecov.io)
6115

6216

6317
## License

pom.xml

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,51 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<!--
4-
Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors
5-
All rights reserved. This program and the accompanying materials
6-
are made available under the terms of the Eclipse Public License v1.0
7-
which accompanies this distribution, and is available at
8-
http://www.eclipse.org/legal/epl-v10.html
9-
10-
Contributors:
11-
Marc R. Hoffmann - initial API and implementation
12-
-->
13-
14-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<project>
164
<modelVersion>4.0.0</modelVersion>
5+
<groupId>io.codecov</groupId>
6+
<artifactId>example-java</artifactId>
7+
<version>1.0</version>
178

18-
<groupId>org.jacoco</groupId>
19-
<artifactId>org.jacoco.examples.maven.java</artifactId>
20-
<version>1.0-SNAPSHOT</version>
21-
<packaging>jar</packaging>
22-
23-
<name>Cobertura Maven plug-in example for Java project</name>
24-
<url>http://cobertura.github.io/cobertura/</url>
9+
<name>Codecov example Java repository</name>
10+
<url>http://github.com/codecov/example-java</url>
11+
<properties>
12+
<maven.compiler.source>18</maven.compiler.source>
13+
<maven.compiler.target>18</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
2516

2617
<dependencies>
2718
<dependency>
2819
<groupId>junit</groupId>
2920
<artifactId>junit</artifactId>
30-
<version>4.12</version>
21+
<version>4.13.2</version>
3122
<scope>test</scope>
3223
</dependency>
3324
</dependencies>
3425

3526
<build>
36-
<sourceDirectory>src/main/java</sourceDirectory>
3727
<plugins>
3828
<plugin>
39-
<groupId>org.apache.maven.plugins</groupId>
40-
<artifactId>maven-compiler-plugin</artifactId>
41-
<version>3.1</version>
42-
<configuration>
43-
<source>1.7</source>
44-
<target>1.7</target>
45-
</configuration>
46-
</plugin>
47-
<plugin>
48-
<groupId>org.codehaus.mojo</groupId>
49-
<artifactId>cobertura-maven-plugin</artifactId>
50-
<version>2.7</version>
51-
<configuration>
52-
<formats>
53-
<format>html</format>
54-
<format>xml</format>
55-
</formats>
56-
<check />
57-
</configuration>
29+
<groupId>org.jacoco</groupId>
30+
<artifactId>jacoco-maven-plugin</artifactId>
31+
<version>0.8.8</version>
32+
<executions>
33+
<execution>
34+
<id>prepare-agent</id>
35+
<goals>
36+
<goal>prepare-agent</goal>
37+
</goals>
38+
</execution>
39+
<execution>
40+
<id>report</id>
41+
<phase>test</phase>
42+
<goals>
43+
<goal>report</goal>
44+
</goals>
45+
</execution>
46+
</executions>
5847
</plugin>
5948
</plugins>
60-
</build>
49+
</build>
6150

6251
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package calculator;
2+
3+
public class Calculator {
4+
public static double add(double x, double y) {
5+
return x + y;
6+
}
7+
8+
public static double subtract(double x, double y) {
9+
return x - y;
10+
}
11+
12+
public static double multiply(double x, double y) {
13+
return x * y;
14+
}
15+
16+
public static double divide(double x, double y) {
17+
if (y == 0) {
18+
System.out.println("Cannot divide by 0");
19+
return 0;
20+
}
21+
return x / y;
22+
}
23+
}

src/main/java/org/jacoco/examples/maven/java/HelloWorld.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package calculator;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
public class CalculatorTest {
8+
private static final double DELTA = 0.001;
9+
10+
@Test
11+
public void testAdd() {
12+
assertEquals(Calculator.add(1, 2), 3.0, DELTA);
13+
assertEquals(Calculator.add(1.0, 2.0), 3.0, DELTA);
14+
assertEquals(Calculator.add(0, 2.0), 2.0, DELTA);
15+
assertEquals(Calculator.add(2.0, 0), 2.0, DELTA);
16+
assertEquals(Calculator.add(-4, 2.0), -2.0, DELTA);
17+
}
18+
19+
@Test
20+
public void testSubtract() {
21+
assertEquals(Calculator.subtract(1, 2), -1.0, DELTA);
22+
assertEquals(Calculator.subtract(2, 1), 1.0, DELTA);
23+
assertEquals(Calculator.subtract(1.0, 2.0), -1.0, DELTA);
24+
assertEquals(Calculator.subtract(0, 2.0), -2.0, DELTA);
25+
assertEquals(Calculator.subtract(2.0, 0), 2.0, DELTA);
26+
assertEquals(Calculator.subtract(-4, 2.0), -6.0, DELTA);
27+
}
28+
29+
@Test
30+
public void testMultiply() {
31+
assertEquals(Calculator.multiply(1, 2), 2.0, DELTA);
32+
assertEquals(Calculator.multiply(1.0, 2.0), 2.0, DELTA);
33+
assertEquals(Calculator.multiply(0, 2.0), 0.0, DELTA);
34+
assertEquals(Calculator.multiply(2.0, 0), 0.0, DELTA);
35+
assertEquals(Calculator.multiply(-4, 2.0), -8.0, DELTA);
36+
}
37+
38+
@Test
39+
public void testDivide() {
40+
assertEquals(Calculator.divide(1, 2), 0.5, DELTA);
41+
assertEquals(Calculator.divide(1.0, 2.0), 0.5, DELTA);
42+
assertEquals(Calculator.divide(0, 2.0), 0, DELTA);
43+
assertEquals(Calculator.divide(-4, 2.0), -2.0, DELTA);
44+
// assertEquals(Calculator.divide(2.0, 0), 0.0, DELTA);
45+
}
46+
}

src/test/java/org/jacoco/examples/maven/java/HelloWorldTest.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)