Skip to content

Commit

Permalink
Merge pull request #105 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored Aug 23, 2022
2 parents f15abbb + 4cc27f7 commit d6e7ecf
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 83 deletions.
34 changes: 10 additions & 24 deletions .github/workflows/automate-projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,17 @@ jobs:

if: ${{ (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
steps:
- name: add-new-issues-to-repository-based-project-column
uses: docker://takanabe/github-actions-automate-projects:v0.0.1
if: github.event_name == 'issues' && github.event.action == 'opened'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PROJECT_URL: https://github.com/com-pas/compas-scl-validator/projects/1
GITHUB_PROJECT_COLUMN_NAME: To do
- name: add-new-pull-request-to-repository-based-project-column
uses: docker://takanabe/github-actions-automate-projects:v0.0.1
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.action == 'opened'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PROJECT_URL: https://github.com/com-pas/compas-scl-validator/projects/1
GITHUB_PROJECT_COLUMN_NAME: To do
- name: add-new-issues-to-organization-based-project-column
uses: docker://takanabe/github-actions-automate-projects:v0.0.1
if: github.event_name == 'issues' && github.event.action == 'opened'
env:
GITHUB_TOKEN: ${{ secrets.ORG_GITHUB_ACTION_SECRET }}
GITHUB_PROJECT_URL: https://github.com/orgs/com-pas/projects/1
GITHUB_PROJECT_COLUMN_NAME: To do
uses: alex-page/[email protected]
with:
project: CoMPAS Issues Overview Board
column: To do
repo-token: ${{ secrets.ORG_GITHUB_ACTION_SECRET }}
- name: add-new-pull-request-to-organization-based-project-column
uses: docker://takanabe/github-actions-automate-projects:v0.0.1
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.action == 'opened'
env:
GITHUB_TOKEN: ${{ secrets.ORG_GITHUB_ACTION_SECRET }}
GITHUB_PROJECT_URL: https://github.com/orgs/com-pas/projects/2
GITHUB_PROJECT_COLUMN_NAME: To do
uses: alex-page/[email protected]
with:
project: CoMPAS Pull Request Overview Board
column: To do
repo-token: ${{ secrets.ORG_GITHUB_ACTION_SECRET }}
7 changes: 4 additions & 3 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker Register
uses: actions/cache@v3
with:
Expand All @@ -39,6 +37,9 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Cache Docker Register
uses: actions/cache@v3
with:
Expand All @@ -42,13 +35,22 @@ jobs:
- name: Extract tag name
id: extract_tagname
shell: bash
# Extra the tagname form the git reference, value of GITHUB_REF will be something like refs/tags/<tag_name>.
# Extract the tag name from the git reference, value of GITHUB_REF will be something like refs/tags/<tag_name>.
run: echo "##[set-output name=tagname;]$(echo ${GITHUB_REF##*/})"

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v20
Expand Down
44 changes: 31 additions & 13 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ jobs:
fetch-depth: 0
submodules: 'true'

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
Expand All @@ -49,20 +44,43 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'

- name: Set Common Sonar Variables
id: sonar_env
run: |
echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
-Dsonar.projectKey=com-pas_compas-scl-validator \
-Dsonar.organization=com-pas )"
- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v20
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
- name: Build and analyze
- name: Build and analyze (Pull Request)
if: ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
./mvnw -B -s custom_maven_settings.xml -Psonar \
${{ steps.sonar_env.outputs.sonar_opts }} \
-Dsonar.pullrequest.branch=${{ github.ref_name }} \
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
-Dsonar.pullrequest.base=${{ github.base_ref }} \
-Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
- name: Build and analyze (Push)
if: ${{ github.event_name == 'push' }}
env:
GITHUB_USERNAME: "OWNER"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
./mvnw -s custom_maven_settings.xml -B -Psonar \
-Dsonar.projectKey=com-pas_compas-scl-validator \
-Dsonar.organization=com-pas \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
./mvnw -B -s custom_maven_settings.xml -Psonar \
${{ steps.sonar_env.outputs.sonar_opts }} \
-Dsonar.branch.name=${{ github.ref_name }} \
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@ void init() {
@Test
void encode_WhenCalledWithRequest_ThenRequestConvertedToString() {
var validationMessage = "Some Validation Message";
var ruleName = "Rule Name 1";
var linenumber = 15;

var request = new SclValidateResponse();
request.setValidationErrorList(new ArrayList<>());
var validationError = new ValidationError();
validationError.setMessage(validationMessage);
validationError.setRuleName(ruleName);
validationError.setLinenumber(linenumber);
request.getValidationErrorList().add(validationError);

var result = encoder.encode(request);

var expectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<svs:SclValidateResponse xmlns:svs=\"" + SCL_VALIDATOR_SERVICE_V1_NS_URI + "\">" +
"<svs:ValidationErrors><svs:Message>" + validationMessage + "</svs:Message></svs:ValidationErrors>" +
"<svs:ValidationErrors>" +
"<svs:Message>" + validationMessage + "</svs:Message>" +
"<svs:RuleName>" + ruleName + "</svs:RuleName>" +
"<svs:Linenumber>" + linenumber + "</svs:Linenumber>" +
"</svs:ValidationErrors>" +
"</svs:SclValidateResponse>";
assertNotNull(result);
assertEquals(expectedResult, result);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SPDX-License-Identifier: Apache-2.0
<compas.core.version>0.9.1</compas.core.version>

<quarkus.platform.version>2.10.3.Final</quarkus.platform.version>
<slf4j.version>1.7.36</slf4j.version>
<slf4j.version>2.0.0</slf4j.version>
<openpojo.version>0.9.1</openpojo.version>
</properties>

Expand Down Expand Up @@ -265,7 +265,7 @@ SPDX-License-Identifier: Apache-2.0
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.LOADING_CUSTOM_OCL_FILES_FAILED;
import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.LOADING_OCL_FILES_FAILED;
Expand Down Expand Up @@ -54,7 +53,7 @@ protected List<URI> getDefaultOclFilesFromClasspath() {
try (var walk = Files.walk(oclDirectoryPath)) {
return walk.filter(filter)
.map(path -> URI.createURI(path.toUri().toString()))
.collect(Collectors.toList());
.toList();
}
}
} else {
Expand All @@ -64,7 +63,7 @@ protected List<URI> getDefaultOclFilesFromClasspath() {
.map(Path::toFile)
.filter(File::isFile)
.map(file -> URI.createFileURI(file.getAbsolutePath()))
.collect(Collectors.toList());
.toList();
}
}
} else {
Expand Down Expand Up @@ -93,7 +92,7 @@ protected List<URI> getFilesFromDirectory(String directoryName, Predicate<Path>
.map(Path::toFile)
.filter(File::isFile)
.map(file -> URI.createFileURI(file.getAbsolutePath()))
.collect(Collectors.toList());
.toList();
}
}
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.ArrayList;
import java.util.List;

import static org.lfenergy.compas.scl.validator.util.MessageUtil.cleanupMessage;
import static org.lfenergy.compas.scl.validator.util.MessageUtil.createValidationError;

public class SclRiseClipseValidator implements SclValidator {
private static final Logger LOGGER = LoggerFactory.getLogger(SclRiseClipseValidator.class);
Expand Down Expand Up @@ -77,12 +77,16 @@ public List<ValidationError> validate(SclFileType type, String sclData) {
private void processDiagnostic(Diagnostic diagnostic, List<ValidationError> validationErrors) {
// If there are children in the diagnostic there are validation errors to be processed.
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
var validationError = new ValidationError();
validationErrors.add(validationError);

String message = cleanupMessage(childDiagnostic.getMessage());
validationError.setMessage(message);
LOGGER.debug("SCL Validation Error '{}'", message);
var validationError = createValidationError(childDiagnostic.getMessage());
if (validationError.isPresent()) {
validationErrors.add(validationError.get());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SCL Validation Error '{}' from Rule '{}' (Linenumber {})",
validationError.get().getMessage(),
validationError.get().getRuleName(),
validationError.get().getLinenumber());
}
}

// Also process the children of the children.
processDiagnostic(childDiagnostic, validationErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,46 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.util;

import org.lfenergy.compas.scl.validator.model.ValidationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;

public class MessageUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageUtil.class);

MessageUtil() {
throw new UnsupportedOperationException("MessageUtil class");
}

public static String cleanupMessage(String message) {
String cleanedMessage = message;
if (cleanedMessage != null
&& cleanedMessage.toUpperCase().startsWith("ERROR;")) {
cleanedMessage = cleanedMessage.substring(6);
public static Optional<ValidationError> createValidationError(String message) {
if (message == null || message.isBlank()) {
return Optional.empty();
}
return cleanedMessage;

var validationError = new ValidationError();
var messageParts = message.split(";");
if (messageParts.length == 5) {
// The expected number of parts is found, the message and rule are set as-is, the linenumber is converted
// to a Long value,
validationError.setRuleName(messageParts[1]);
validationError.setMessage(messageParts[4]);

try {
validationError.setLinenumber(Long.parseLong(messageParts[3]));
} catch (NumberFormatException exp) {
validationError.setLinenumber(-1);
LOGGER.debug("Invalid linenumber '{}' found", messageParts[3], exp);
}
} else if (messageParts.length == 2) {
// It seems like an old message that starts with 'ERROR;', so only set the second part as Message
validationError.setMessage(messageParts[1]);
} else {
// If we can split it correctly, just put the message as-is to the response.
validationError.setMessage(message);
}

return Optional.of(validationError);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ void validate_WhenCalled_ThenExpectedValidationErrorsReturned() throws IOExcepti

assertNotNull(result);
assertEquals(15, result.size());

// Check if parsing of the message is still working.
var firstMessage = result.get(0);
assertNotNull(firstMessage.getRuleName());
assertNotNull(firstMessage.getMessage());
assertTrue(firstMessage.getLinenumber() > 0);
}
}
Loading

0 comments on commit d6e7ecf

Please sign in to comment.