Skip to content

Commit

Permalink
Generate jacoco report in conformance suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Maduranga Siriwardena committed Sep 13, 2024
1 parent d0f4913 commit a4a9dc8
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 3 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/fapi-oidc-conformance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,34 @@ jobs:
name: test-logs
path: ./*log.txt

- name: Archive Jacoco results
- name: Archive Jacoco exec
uses: actions/upload-artifact@v4
if: always()
with:
name: jacoco-exec
path: ./jacoco.exec

- name: Build Jacoco Report Generator
run: |
cd ./product-is/modules/integration/tests-common/jacoco-report-generator
mvn clean install
ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
JAR_NAME="${ARTIFACT_ID}-${VERSION}.jar"
echo "JAR_NAME=${JAR_NAME}" >> $GITHUB_ENV
echo "Report generator jar name: $JAR_NAME"
- name: Generate Jacoco Report
run: |
java -jar ./product-is/modules/integration/tests-common/jacoco-report-generator/target/${{ env.JAR_NAME }} ./jacoco.exec ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/deployment/server/webapps ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/components/plugins ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/components/dropins ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/lib/runtimes/cxf3
- name: Archive Jacoco report
uses: actions/upload-artifact@v4
if: always()
with:
name: jacoco-xml
path: ./report/jacoco.xml

- name: Send Email
if: always()
run: |
Expand Down
25 changes: 23 additions & 2 deletions .github/workflows/oidc-conformance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,34 @@ jobs:
name: test-logs
path: ./*log.txt

- name: Archive Jacoco results
uses: actions/upload-artifact@v3
- name: Archive Jacoco exec
uses: actions/upload-artifact@v4
if: always()
with:
name: jacoco-exec
path: ./jacoco.exec

- name: Build Jacoco Report Generator
run: |
cd ./product-is/modules/integration/tests-common/jacoco-report-generator
mvn clean install
ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
JAR_NAME="${ARTIFACT_ID}-${VERSION}.jar"
echo "JAR_NAME=${JAR_NAME}" >> $GITHUB_ENV
echo "Report generator jar name: $JAR_NAME"
- name: Generate Jacoco Report
run: |
java -jar ./product-is/modules/integration/tests-common/jacoco-report-generator/target/${{ env.JAR_NAME }} ./jacoco.exec ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/deployment/server/webapps ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/components/plugins ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/components/dropins ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/lib/runtimes/cxf3
- name: Archive Jacoco report
uses: actions/upload-artifact@v4
if: always()
with:
name: jacoco-xml
path: ./report/jacoco.xml

- name: Send Email
if: always()
run: |
Expand Down
95 changes: 95 additions & 0 deletions modules/integration/tests-common/jacoco-report-generator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
~
~ WSO2 LLC. 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wso2.is</groupId>
<artifactId>identity-integration-tests</artifactId>
<version>7.0.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>jacoco-report-generator</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.jacoco.version>0.8.12</org.jacoco.version>
<plexus-utils.version>4.0.1</plexus-utils.version>
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>${org.jacoco.version}</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.report</artifactId>
<version>${org.jacoco.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexus-utils.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.jacoco:org.jacoco.core</include>
<include>org.jacoco:org.jacoco.report</include>
<include>org.codehaus.plexus:plexus-utils</include>
<include>org.ow2.asm:asm</include>
<include>org.ow2.asm:asm-tree</include>
<include>org.ow2.asm:asm-commons</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.wso2.carbon.identity.jacoco.ReportGenerator</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. 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.
*/
package org.wso2.carbon.identity.jacoco;

import org.codehaus.plexus.util.DirectoryScanner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class CodeCoverageUtils {

/**
* Extract jar files given at jar file path
*
* @param jarFilePath - Jar file patch
* @return - Jar file extracted directory.
* @throws IOException - Throws if jar extraction fails
*/
public synchronized static String extractJarFile(String jarFilePath, File tempDir)
throws IOException {

if (!jarFilePath.endsWith(".war") && !jarFilePath.endsWith(".jar")) {
throw new IllegalArgumentException("Invalid extension" + jarFilePath + " is invalid");
}

String fileSeparator = (File.separatorChar == '\\') ? "\\" : File.separator;
String jarFileName = jarFilePath;

if (jarFilePath.lastIndexOf(fileSeparator) != -1) {
jarFileName = jarFilePath.substring(jarFilePath.lastIndexOf(fileSeparator) + 1);
}

String tempExtractedDir = null;
try {
tempExtractedDir = tempDir + File.separator +
jarFileName.substring(0, jarFileName.lastIndexOf('.'));

extractFile(jarFilePath, tempExtractedDir);
} catch (IOException e) {
System.out.println("Could not extract the file " + jarFileName);
}
return tempExtractedDir;
}

/**
* Method to scan given directory for include and exclude patterns.
*
* @param jarExtractedDir - Patch to check for given include/exclude pattern
* @param includes - Include pattern array
* @param excludes - Exclude class pattern array
* @return - Included files
* @throws IOException - Throws if given directory patch cannot be found.
*/
public static String[] scanDirectory(String jarExtractedDir, String[] includes,
String[] excludes) throws IOException {
DirectoryScanner ds = new DirectoryScanner();

ds.setIncludes(includes);
ds.setExcludes(excludes);
ds.setBasedir(new File(jarExtractedDir));
ds.setCaseSensitive(true);

ds.scan();
return ds.getIncludedFiles();
}

public static void extractFile(String sourceFilePath, String extractedDir) throws IOException {
FileOutputStream fileoutputstream = null;
String fileDestination = extractedDir + File.separator;
byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
try {
zipinputstream = new ZipInputStream(new FileInputStream(sourceFilePath));
zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
//for each entry to be extracted
String entryName = fileDestination + zipentry.getName();
entryName = entryName.replace('/', File.separatorChar);
entryName = entryName.replace('\\', File.separatorChar);
int n;
File newFile = new File(entryName);
if (zipentry.isDirectory()) {
if (!newFile.exists()) {
if (!newFile.mkdirs()) {
throw new IOException("Error occurred created new directory");
}
}
zipentry = zipinputstream.getNextEntry();
continue;
} else {
File resourceFile =
new File(entryName.substring(0, entryName.lastIndexOf(File.separator)));
if (!resourceFile.exists()) {
if (!resourceFile.mkdirs()) {
break;
}
}
}
fileoutputstream = new FileOutputStream(entryName);
while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
fileoutputstream.write(buf, 0, n);
}
fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}
zipinputstream.close();
} catch (IOException e) {
System.out.println("Error on archive extraction ");
throw new IOException("Error on archive extraction ", e);
} finally {
if (fileoutputstream != null) {
fileoutputstream.close();
}
if (zipinputstream != null) {
zipinputstream.close();
}
}
}
}
Loading

0 comments on commit a4a9dc8

Please sign in to comment.