Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate jacoco report in conformance suite #21102

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-fapi-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/deployment/server/webapps ./product-is/oidc-fapi-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/components/plugins ./product-is/oidc-fapi-conformance-tests/${{ env.PRODUCT_IS_DIR }}/repository/components/dropins ./product-is/oidc-fapi-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,115 @@
/*
* 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;

/**
* Utility class for code coverage related operations.
*/
public class CodeCoverageUtils {
madurangasiriwardena marked this conversation as resolved.
Show resolved Hide resolved
madurangasiriwardena marked this conversation as resolved.
Show resolved Hide resolved

private static final int BUFFER_SIZE = 1024;
private static final String INVALID_EXTENSION_ERROR = "Invalid extension: %s is invalid";
private static final String EXTRACTION_ERROR = "Error on archive extraction";

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this to be synchronized here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with #21108


if (!jarFilePath.endsWith(".war") && !jarFilePath.endsWith(".jar")) {
throw new IllegalArgumentException(String.format(INVALID_EXTENSION_ERROR, jarFilePath));
}

String jarFileName = new File(jarFilePath).getName();
String tempExtractedDir = new File(tempDir, jarFileName.substring(0, jarFileName.lastIndexOf('.'))).getPath();

try {
extractFile(jarFilePath, tempExtractedDir);
} catch (IOException e) {
throw new IOException("Could not extract the file " + jarFileName, e);
}
return tempExtractedDir;
}

/**
* Scan given directory for include and exclude patterns.
*
* @param jarExtractedDir - Path 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 path cannot be found.
*/
public static String[] scanDirectory(String jarExtractedDir, String[] includes,
String[] excludes) throws IOException {

DirectoryScanner ds = new DirectoryScanner();
madurangasiriwardena marked this conversation as resolved.
Show resolved Hide resolved

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

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

private static void extractFile(String sourceFilePath, String extractedDir) throws IOException {

byte[] buf = new byte[BUFFER_SIZE];
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(sourceFilePath))) {
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
File newFile = new File(extractedDir, zipEntry.getName());
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs()) {
throw new IOException("Failed to create directory " + newFile);
}
} else {
File parent = newFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IOException("Failed to create directory " + parent);
}
try (FileOutputStream fos = new FileOutputStream(newFile)) {
int len;
while ((len = zipInputStream.read(buf)) > 0) {
fos.write(buf, 0, len);
}
}
}
zipInputStream.closeEntry();
}
} catch (IOException e) {
throw new IOException(EXTRACTION_ERROR, e);
}
}
}
Loading