Skip to content

Commit

Permalink
Merge pull request #2 from fugerit-org/branch-sonarcloud
Browse files Browse the repository at this point in the history
Better test coverage
  • Loading branch information
fugerit79 authored Sep 6, 2023
2 parents 25331cc + c90c5a6 commit d0924c4
Show file tree
Hide file tree
Showing 23 changed files with 467 additions and 213 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build_maven_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: CI build maven package

on:
push:
branches:
- main
- develop
- branch-sonarcloud
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'corretto'
cache: maven
- name: Build with Maven
run: mvn -P full,coverage,metadata -B package --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/[email protected]
55 changes: 55 additions & 0 deletions .github/workflows/sonarcloud-maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Sonar Cloud Maven Build
on:
# Trigger analysis when pushing in master or pull requests, and when creating
# a pull request.
push:
branches:
- main
- branch-sonarcloud
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
cache: 'maven'
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Maven version
run: mvn -v
env:
# Needed to get some information about the pull request, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Build and analyze
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage -Pcoverage,sonarfugerit -Dsonar.projectKey=fugerit-org_${{github.event.repository.name}}
env:
# Needed to get some information about the pull request, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
70 changes: 0 additions & 70 deletions .github/workflows/sonarcloud.yml

This file was deleted.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [Sonar cloud workflow](.github/workflows/sonarcloud-maven.yml)
- [Maven build workflow](.github/workflows/build_maven_package.yml)
- keep a changelog badge

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CellParent( Cell cell ) {
/* (non-Javadoc)
* @see org.fugerit.java.doc.mod.itext.ParentElement#add(com.lowagie.text.Element)
*/
public void add(Element element) throws Exception {
public void add(Element element) {
this.cell.addElement( element );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public DocumentParent( Document document) {
/* (non-Javadoc)
* @see org.fugerit.java.doc.mod.itext.ParentElement#add(com.lowagie.text.Element)
*/
public void add(Element element) throws Exception {
public void add(Element element) {
this.document.add( element );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.fugerit.java.doc.mod.openpdf.helpers;

import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import org.fugerit.java.core.log.LogFacade;
import org.fugerit.java.doc.base.model.DocBarcode;
import org.fugerit.java.doc.base.model.DocBorders;
import org.fugerit.java.doc.base.model.DocCell;
Expand All @@ -20,13 +20,17 @@

import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.alignment.HorizontalAlignment;
import com.lowagie.text.alignment.VerticalAlignment;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OpenPdfDocTableHelper {

private OpenPdfDocTableHelper() {}
Expand Down Expand Up @@ -84,7 +88,7 @@ private static void handleAligns( DocCell docCell, Cell cell ) {
}
}

private static List<Font> handleContent( Table table, CellParent cellParent, DocCell docCell, Cell cell, OpenPdfHelper docHelper ) throws Exception {
private static List<Font> handleContent( Table table, CellParent cellParent, DocCell docCell, Cell cell, OpenPdfHelper docHelper ) throws DocumentException, IOException {
List<Font> fontList = new ArrayList<>();
Iterator<DocElement> itCurrent = docCell.docElements();
while ( itCurrent.hasNext() ) {
Expand All @@ -96,23 +100,20 @@ private static List<Font> handleContent( Table table, CellParent cellParent, Doc
cellParent.add( paragraph );
} else if ( docElement instanceof DocPhrase ) {
DocPhrase docPhrase = (DocPhrase)docElement;
//setStyle( docCell , docPara );
log.trace( "docCell -> {}, docPara : {}", docCell, cell );
cellParent.add( OpenPpfDocHandler.createPhrase( docPhrase, docHelper, fontList ) );
} else if ( docElement instanceof DocTable ) {
LogFacade.getLog().debug( "nested table" );
table.insertTable( createTable( (DocTable)docElement, docHelper ) );
} else if ( docElement instanceof DocImage ) {
LogFacade.getLog().debug( "cell DocImage : "+docElement );
cellParent.add( OpenPpfDocHandler.createImage( (DocImage)docElement ) );
} else if ( docElement instanceof DocBarcode ) {
LogFacade.getLog().info( "cell DocBarcode : "+docElement );
cellParent.add( OpenPpfDocHandler.createBarcode( (DocBarcode)docElement, docHelper ) );
}
}
return fontList;
}

private static boolean handleCell( Table table, DocCell docCell, boolean startHeader, DocTable docTable, OpenPdfHelper docHelper ) throws Exception {
private static boolean handleCell( Table table, DocCell docCell, boolean startHeader, DocTable docTable, OpenPdfHelper docHelper ) throws DocumentException, IOException {
OpenPpfDocHandler.setStyle( docTable, docCell );
Cell cell = new Cell();
if ( docCell.isHeader() ) {
Expand Down Expand Up @@ -144,7 +145,7 @@ private static boolean handleCell( Table table, DocCell docCell, boolean startHe
if ( listChunk.size() == fontList.size() ) {
for ( int k=0; k<listChunk.size(); k++ ) {
Chunk c = (Chunk)listChunk.get( k );
Font f = (Font) fontList.get( k );
Font f = fontList.get( k );
c.setFont( f );
}
}
Expand All @@ -154,7 +155,7 @@ private static boolean handleCell( Table table, DocCell docCell, boolean startHe
return startHeader;
}

protected static Table createTable( DocTable docTable, OpenPdfHelper docHelper ) throws Exception {
protected static Table createTable( DocTable docTable, OpenPdfHelper docHelper ) throws DocumentException, IOException {

boolean startHeader = false;
Table table = new Table( docTable.getColumns() );
Expand All @@ -176,7 +177,7 @@ protected static Table createTable( DocTable docTable, OpenPdfHelper docHelper )
if ( cw != null ) {
float[] w = new float[ cw.length ];
for ( int k=0; k<w.length; k++ ) {
w[k] = (float)((float)cw[k]/(float)100);
w[k] = ((float)cw[k]/(float)100);
}
table.setWidths( w );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package org.fugerit.java.doc.mod.openpdf.helpers;

import java.awt.Color;
import java.io.IOException;

import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.doc.base.model.DocPara;
import org.fugerit.java.doc.base.xml.DocModelUtils;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.pdf.BaseFont;

public class OpenPdfFontHelper {

private OpenPdfFontHelper() {}

public static BaseFont createBaseFontSafe( String name, String encoding, boolean embedded) {
BaseFont result = null;
try {
result = BaseFont.createFont(name, encoding, embedded);
} catch (DocumentException | IOException e) {
throw new ConfigRuntimeException( e );
}
return result;
}

private static int handleFontStyle( int style, int fontStyle ) {
if ( fontStyle == DocPara.STYLE_BOLD ) {
style = Font.BOLD;
Expand All @@ -23,7 +38,7 @@ private static int handleFontStyle( int style, int fontStyle ) {
return style;
}

protected static Font createFont( String fontName, String fontPath, int fontSize, int fontStyle, OpenPdfHelper docHelper, String color ) throws Exception {
protected static Font createFont( String fontName, String fontPath, int fontSize, int fontStyle, OpenPdfHelper docHelper, String color ) throws DocumentException, IOException {
Font font = null;
int size = fontSize;
int style = Font.NORMAL;
Expand Down
Loading

0 comments on commit d0924c4

Please sign in to comment.