Skip to content

Commit

Permalink
Merge pull request #114 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored Sep 6, 2022
2 parents d6e7ecf + 64931fb commit 38851af
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 116 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@ jobs:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
- name: Set version with Maven
# Only set the version for the CoMPAS Modules, excluding the RiseClipse Modules.
run: ./mvnw -B versions:set -DgroupId=org.lfenergy.compas.scl.validator -DnewVersion=${{ steps.extract_tagname.outputs.tagname }}
run: ./mvnw -B versions:set -DprocessAllModules=true -DnewVersion=${{ steps.extract_tagname.outputs.tagname }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy with Maven to GitHub Packages and Docker Hub
# We need to pass the Repository information, because these are missing/need to be overwritten for the
# RiseClipse Submodules for which we can't update the POM files.
run: |
./mvnw -B -s custom_maven_settings.xml \
-DaltDeploymentRepository=github-packages-compas::default::https://maven.pkg.github.com/com-pas/compas-scl-validator \
-Dmaven.deploy.skip=snapshots \
-Pjvm-image,release clean deploy
run: ./mvnw -B -s custom_maven_settings.xml -Pjvm-image,release clean deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ SPDX-License-Identifier: Apache-2.0
<artifactId>openpojo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,30 @@ void willDecode_WhenCalledWithNull_ThenFalseReturned() {
@Test
void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() {
var validationMessage = "Some validation error";
var ruleName = "Rule Name 1";
var lineNumber = 15;
var columnNumber = 34;

var message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<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:ColumnNumber>" + columnNumber + "</svs:ColumnNumber>"
+ "</svs:ValidationErrors>"
+ "</svs:SclValidateResponse>";

var result = decoder.decode(message);

assertNotNull(result);
assertEquals(1, result.getValidationErrorList().size());
assertEquals(validationMessage, result.getValidationErrorList().get(0).getMessage());

var validationError = result.getValidationErrorList().get(0);
assertEquals(validationMessage, validationError.getMessage());
assertEquals(ruleName, validationError.getRuleName());
assertEquals(lineNumber, validationError.getLineNumber());
assertEquals(columnNumber, validationError.getColumnNumber());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ void init() {
void encode_WhenCalledWithRequest_ThenRequestConvertedToString() {
var validationMessage = "Some Validation Message";
var ruleName = "Rule Name 1";
var linenumber = 15;
var lineNumber = 15;
var columnNumber = 34;

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

var result = encoder.encode(request);
Expand All @@ -46,7 +48,8 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() {
"<svs:ValidationErrors>" +
"<svs:Message>" + validationMessage + "</svs:Message>" +
"<svs:RuleName>" + ruleName + "</svs:RuleName>" +
"<svs:Linenumber>" + linenumber + "</svs:Linenumber>" +
"<svs:LineNumber>" + lineNumber + "</svs:LineNumber>" +
"<svs:ColumnNumber>" + columnNumber + "</svs:ColumnNumber>" +
"</svs:ValidationErrors>" +
"</svs:SclValidateResponse>";
assertNotNull(result);
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ SPDX-License-Identifier: Apache-2.0
<version>3.0</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion riseclipse/riseclipse-p2-to-m2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ SPDX-License-Identifier: Apache-2.0
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-eclipserun-plugin</artifactId>
<version>2.7.4</version>
<version>2.7.5</version>
<configuration>
<work>${project.build.directory}/maven/tmp/cbi</work>
<executionEnvironment>JavaSE-17</executionEnvironment>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public OclFileLoader(Path tempDirectoryPath, List<URI> oclFiles) {
// Create an OCL that creates a ResourceSet using the minimal EPackage.Registry
this.ocl = OCL.newInstance(registry);

// First make sure the directory for temporary file exists.
// First make sure the directory for temporary file exists and if not will be created.
var tempDirectory = tempDirectoryPath.toFile();
if (!tempDirectory.exists() && !tempDirectory.mkdirs()) {
throw new SclValidatorException(CREATE_OCL_TEMP_DIR_FAILED, "Unable to create temporary directory");
Expand All @@ -54,8 +54,7 @@ public OclFileLoader(Path tempDirectoryPath, List<URI> oclFiles) {
}

public void loadOCLDocuments() {
oclFiles.stream()
.forEach(this::addOCLDocument);
oclFiles.forEach(this::addOCLDocument);
}

public void addOCLDocument(URI oclUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ private void processDiagnostic(Diagnostic diagnostic, List<ValidationError> vali
if (validationError.isPresent()) {
validationErrors.add(validationError.get());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SCL Validation Error '{}' from Rule '{}' (Linenumber {})",
LOGGER.debug("SCL Validation Error '{}' from Rule '{}' (Line number {})",
validationError.get().getMessage(),
validationError.get().getRuleName(),
validationError.get().getLinenumber());
validationError.get().getLineNumber());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public static Optional<ValidationError> createValidationError(String message) {
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,
// The expected number of parts is found, the message and rule are set as-is, the line number
// is converted to a Integer value,
validationError.setRuleName(messageParts[1]);
validationError.setMessage(messageParts[4]);

try {
validationError.setLinenumber(Long.parseLong(messageParts[3]));
validationError.setLineNumber(Integer.parseInt(messageParts[3]));
} catch (NumberFormatException exp) {
validationError.setLinenumber(-1);
LOGGER.debug("Invalid linenumber '{}' found", messageParts[3], exp);
validationError.setLineNumber(-1);
LOGGER.debug("Invalid line number '{}' 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.NO_URI_PASSED;
import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.*;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
Expand All @@ -46,6 +46,38 @@ void setup() throws IOException {
.orElseThrow();
}

@Test
void constructor_WhenCalledWithUnCreatableDirectory_ThenExceptionThrown() {
var unCreatablePath = Path.of("/some-directory");
if (isWindows()) {
unCreatablePath = Path.of("C:/Windows/some-directory");
}

List<URI> fileList = List.of();
var directoryPath = unCreatablePath;
var exception = assertThrows(SclValidatorException.class, () -> new OclFileLoader(directoryPath, fileList));

assertEquals(CREATE_OCL_TEMP_DIR_FAILED, exception.getErrorCode());
}

@Test
void constructor_WhenCalledWithUnCreatableTempFile_ThenExceptionThrown() {
var unWritablePath = Path.of("/");
if (isWindows()) {
unWritablePath = Path.of("C:/Windows");
}

List<URI> fileList = List.of();
var directoryPath = unWritablePath;
var exception = assertThrows(SclValidatorException.class, () -> new OclFileLoader(directoryPath, fileList));

assertEquals(CREATE_OCL_TEMP_FILES_FAILED, exception.getErrorCode());
}

private boolean isWindows() {
return System.getProperty("os.name").contains("win");
}

@Test
void loadOCLDocuments_WhenCalled_ThenFilesFromListAreLoaded() throws IOException {
loader.loadOCLDocuments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ void validate_WhenCalled_ThenExpectedValidationErrorsReturned() throws IOExcepti
var firstMessage = result.get(0);
assertNotNull(firstMessage.getRuleName());
assertNotNull(firstMessage.getMessage());
assertTrue(firstMessage.getLinenumber() > 0);
assertTrue(firstMessage.getLineNumber() > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void createValidationError_WhenCalledWithoutParts_ThenSameMessageReturned() {

var validationError = result.get();
assertNull(validationError.getRuleName());
assertEquals(0, validationError.getLinenumber());
assertNull(validationError.getLineNumber());
assertNull(validationError.getColumnNumber());
assertEquals(message, validationError.getMessage());
}

Expand All @@ -56,29 +57,31 @@ void createValidationError_WhenCalledWithTooManyParts_ThenSameMessageReturned()

var validationError = result.get();
assertNull(validationError.getRuleName());
assertEquals(0, validationError.getLinenumber());
assertNull(validationError.getLineNumber());
assertNull(validationError.getColumnNumber());
assertEquals(message, validationError.getMessage());
}

@Test
void createValidationError_WhenCalledWithCorrectMessage_ThenConvertValidationErrorReturned() {
var message = "AnyLN (lnType=LN2) does not refer an existing LNodeType in DataTypeTemplates section";
var ruleName = "OCL/SemanticConstraints/AnyLN_RefersToLNodeType";
var linenumber = (long) 9;
var lineNumber = 9;

var result = createValidationError("ERROR;" + ruleName + ";scl-file.scd;" + linenumber + ";" + message);
var result = createValidationError("ERROR;" + ruleName + ";scl-file.scd;" + lineNumber + ";" + message);

assertNotNull(result);
assertFalse(result.isEmpty());

var validationError = result.get();
assertEquals(ruleName, validationError.getRuleName());
assertEquals(linenumber, validationError.getLinenumber());
assertEquals(lineNumber, validationError.getLineNumber());
assertNull(validationError.getColumnNumber());
assertEquals(message, validationError.getMessage());
}

@Test
void createValidationError_WhenCalledWithInvalidLinenumber_ThenNegativeLinenumberReturned() {
void createValidationError_WhenCalledWithInvalidLineNumber_ThenNegativeLineNumberReturned() {
var message = "AnyLN (lnType=LN2) does not refer an existing LNodeType in DataTypeTemplates section";
var ruleName = "OCL/SemanticConstraints/AnyLN_RefersToLNodeType";

Expand All @@ -89,7 +92,8 @@ void createValidationError_WhenCalledWithInvalidLinenumber_ThenNegativeLinenumbe

var validationError = result.get();
assertEquals(ruleName, validationError.getRuleName());
assertEquals(-1, validationError.getLinenumber());
assertEquals(-1, validationError.getLineNumber());
assertNull(validationError.getColumnNumber());
assertEquals(message, validationError.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ private Map<UUID, NsdocFile> getFilesFromDirectory(String directoryName) {
File directory = new File(directoryName);
if (directory.exists() && directory.isDirectory()) {
var files = directory.listFiles();
if (files != null) {
return Arrays.stream(files)
.filter(File::isFile)
.filter(file -> file.getName().endsWith(".nsdoc"))
.map(this::convertToNsdocFile)
.filter(Objects::nonNull)
.collect(Collectors.toMap(NsdocFile::getId, Function.identity()));
}
return Arrays.stream(files)
.filter(File::isFile)
.filter(file -> file.getName().endsWith(".nsdoc"))
.map(this::convertToNsdocFile)
.filter(Objects::nonNull)
.collect(Collectors.toMap(NsdocFile::getId, Function.identity()));
}
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ void getNsdocFiles_WhenCalledWithConfiguredDirectory_ThenExpectCorrectNumberOfEn

@Test
void getNsdocFiles_WhenCalledWithNonExistingDirectory_ThenNoEntriesReturned() {
finder = new NsdocFinder("./src/text/data/non-existing");
finder = new NsdocFinder("./src/test/data/non-existing");
var files = finder.getNsdocFiles();

assertNotNull(files);
assertEquals(0, files.size());
}

@Test
void getNsdocFiles_WhenCalledWithFileAndNotDirectory_ThenNoEntriesReturned() {
finder = new NsdocFinder("./src/test/data/nsdoc/invalid.doc");
var files = finder.getNsdocFiles();

assertNotNull(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ public class ValidationError {
namespace = SCL_VALIDATOR_SERVICE_V1_NS_URI)
private String ruleName;

@Schema(description = "The linenumber in the SCL file where the validation error occurred",
@Schema(description = "The line number in the SCL file where the validation error occurred",
example = "9")
@XmlElement(name = "Linenumber",
@XmlElement(name = "LineNumber",
namespace = SCL_VALIDATOR_SERVICE_V1_NS_URI)
private long linenumber;
private Integer lineNumber;

@Schema(description = "The column number on the line number in the SCL file where the validation error occurred",
example = "14")
@XmlElement(name = "ColumnNumber",
namespace = SCL_VALIDATOR_SERVICE_V1_NS_URI)
private Integer columnNumber;

public String getMessage() {
return message;
Expand All @@ -49,11 +55,19 @@ public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}

public long getLinenumber() {
return linenumber;
public Integer getLineNumber() {
return lineNumber;
}

public void setLineNumber(Integer lineNumber) {
this.lineNumber = lineNumber;
}

public Integer getColumnNumber() {
return columnNumber;
}

public void setLinenumber(long linenumber) {
this.linenumber = linenumber;
public void setColumnNumber(Integer columnNumber) {
this.columnNumber = columnNumber;
}
}
Loading

0 comments on commit 38851af

Please sign in to comment.