-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate jacoco report in conformance suite
- Loading branch information
Maduranga Siriwardena
committed
Sep 13, 2024
1 parent
d0f4913
commit a4a9dc8
Showing
6 changed files
with
489 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
modules/integration/tests-common/jacoco-report-generator/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
140 changes: 140 additions & 0 deletions
140
...oco-report-generator/src/main/java/org/wso2/carbon/identity/jacoco/CodeCoverageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.