Skip to content

Commit

Permalink
Merge pull request #273 from Imvertor/Development
Browse files Browse the repository at this point in the history
Development branch naar master t.b.v. release 1.67
  • Loading branch information
melsk-r authored Jun 17, 2022
2 parents 1c2e10d + 10335c8 commit a576168
Show file tree
Hide file tree
Showing 97 changed files with 4,947 additions and 926 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@
<artifactId>saxon-ext-file</artifactId>
<version>1.1</version>
</dependency>


<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>3.0.0</version>
</dependency>

</dependencies>

<build>
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/nl/imvertor/ChainTranslateAndReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ public static void main(String[] args) {

if (configurator.isTrue("cli","createyaml",false))
succeeds = succeeds && (new YamlCompiler()).run();

// finally, a regression test if requested
if (configurator.isTrue("cli","regression",false)) {
configurator.setXParm("cli/identifier","DEVELOPMENT");
succeeds = succeeds && (new RegressionExtractor()).run();
}
}
// finally, a regression test if requested, independent of success/failure of the chain
if (configurator.isTrue("cli","regression",false)) {
configurator.setXParm("cli/identifier","DEVELOPMENT");
(new RegressionExtractor()).run();
}
} catch (Exception e) {

} catch (Exception e) {
configurator.getRunner().error(logger,"Step-level system error - Please notify your system administrator: " + e.getMessage(),e);
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/nl/imvertor/ConfigCompiler/ConfigCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.log4j.Logger;

import nl.imvertor.common.Configurator;
import nl.imvertor.common.Step;
import nl.imvertor.common.Transformer;
import nl.imvertor.common.file.AnyFolder;
Expand Down Expand Up @@ -85,6 +86,18 @@ public boolean run() throws Exception{
}
}

// create simple metamodel representation
succeeds = succeeds ? transformer.transformStep("properties/WORK_CONFIG_FILE", "properties/WORK_METAMODEL_FILE", "properties/IMVERTOR_METAMODEL_XSLPATH") : false ;
if (succeeds) {
XmlFile metamodelFile = new XmlFile(configurator.getXParm("properties/WORK_METAMODEL_FILE"));
XmlFile appModFile = new XmlFile(etcFolder,"metamodel.xml");
metamodelFile.copyFile(appModFile);
// copy the XSD
XmlFile managedMetamodelFile = new XmlFile(Configurator.getInstance().getBaseFolder().getCanonicalPath() + "/etc/xsd/metamodel/metamodel.xsd");
XmlFile targetMetamodelFile = new XmlFile(etcFolder.getCanonicalPath() + "/xsd/metamodel/metamodel.xsd");
managedMetamodelFile.copyFile(targetMetamodelFile);
}

configurator.setStepDone(STEP_NAME);

// save any changes to the work configuration for report and future steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private boolean transformByFullBatch() throws Exception {

}

private boolean transformDocx(AnyFile mswordFile) throws IOException, ConfiguratorException {
private boolean transformDocx(AnyFile mswordFile) throws Exception {

OsExecutor osExecutor = new OsExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void passGIThub(File officeFile) throws Exception {

String gitemail = configurator.getServerProperty("git.email" + postfix); // email address
String gituser = configurator.getServerProperty("git.user" + postfix); // user name
String gitpass = configurator.getServerProperty("git.pass" + postfix); // password
String gitpass = configurator.getServerProperty("git.pass" + postfix, false); // password
String gittoken = configurator.getServerProperty("git.token" + postfix); // personal access token
String gitlocal = configurator.getServerProperty("git.local" + postfix); // location of local git repositories

Expand Down
118 changes: 69 additions & 49 deletions src/main/java/nl/imvertor/RegressionExtractor/RegressionExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Vector;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jena.util.FileUtils;
import org.apache.log4j.Logger;

import nl.armatiek.saxon.extensions.http.SendRequest;
Expand All @@ -56,7 +56,7 @@ public class RegressionExtractor extends Step {
public static final String VC_IDENTIFIER = "$Id: ReleaseCompiler.java 7473 2016-03-22 07:30:03Z arjan $";

public static Transformer transformer;

/**
* run the step
*/
Expand Down Expand Up @@ -88,8 +88,8 @@ public boolean run() throws Exception{
String r = Configurator.getInstance().getXParm("cli/regowner",false);
String[] regOwners = StringUtils.split(r.replace(" ", ""),';');

AnyFolder regfolder = new AnyFolder(configurator.getXParm("cli/regfolder"));
configurator.getRunner().info(logger,"Regression testing bulk mode: " + configurator.getXParm("cli/regfolder"));
AnyFolder regfolder = new AnyFolder(configurator.getXParm("system/managedregtestfolder"));
configurator.getRunner().info(logger,"Regression testing bulk mode: " + configurator.getXParm("system/managedregtestfolder"));
Iterator<File> owners = Arrays.asList(regfolder.listFiles()).iterator();
while (owners.hasNext()) {
AnyFile owner = new AnyFile(owners.next());
Expand Down Expand Up @@ -132,21 +132,25 @@ public boolean run() throws Exception{
// Single test: in TranslateAndReport chain
configurator.getRunner().info(logger,"Regression testing this model");
String subpath = configurator.getXParm("cli/owner") + "/" + configurator.getXParm("appinfo/subpath");
AnyFolder regFolder = new AnyFolder(configurator.getXParm("cli/regfolder"));
AnyFolder refFolder = new AnyFolder(regFolder,"ref/" + subpath);
AnyFolder tstFolder = new AnyFolder(regFolder,"tst/" + subpath);
AnyFolder outFolder = new AnyFolder(regFolder,"out/" + subpath);
// Maak de test folder leeg en maak een workfolder
tstFolder.deleteDirectory();
tstFolder.mkdirs();
// copy the chain results to tst folder
String ownerName = configurator.getXParm("cli/owner");
AnyFolder appFolder = new AnyFolder(workFolder,ownerName + "/app");
appFolder.copy(tstFolder);
// Run the test
Integer diffsfound = testFileByFile(configurator,refFolder,tstFolder,outFolder,identifier,compareMethod);
if (diffsfound != 0)
logger.warn("Regression: " + (compareMethod.equals("raw") ? "some" : diffsfound) + " differences in " + tstFolder);
AnyFolder regFolder = new AnyFolder(configurator.getXParm("system/managedregtestfolder"));
if (regFolder.isDirectory()) {
AnyFolder refFolder = new AnyFolder(regFolder,"ref/" + subpath);
AnyFolder tstFolder = new AnyFolder(regFolder,"tst/" + subpath);
AnyFolder outFolder = new AnyFolder(regFolder,"out/" + subpath);
// Maak de test folder leeg en maak een workfolder
tstFolder.deleteDirectory();
tstFolder.mkdirs();
// copy the chain results to tst folder
String ownerName = configurator.getXParm("cli/owner");
AnyFolder appFolder = new AnyFolder(workFolder,ownerName + "/app");
appFolder.copy(tstFolder);
// Run the test
Integer diffsfound = testFileByFile(configurator,refFolder,tstFolder,outFolder,identifier,compareMethod);
if (diffsfound != 0)
logger.warn("Regression: " + (compareMethod.equals("raw") ? "some" : diffsfound) + " differences in " + tstFolder);
} else {
logger.error("Managed regression folder not found: " + regFolder.getName());
}
} else {
// Single test: in regression chain (identifier is usually the owner name)
configurator.getRunner().info(logger,"Regression testing single model: " + configurator.getXParm("cli/tstfolder"));
Expand Down Expand Up @@ -287,35 +291,42 @@ private Integer canonizeFolder(AnyFolder folder,XslFile xslFilterFile, boolean c
runner.debug(logger,"CHAIN","Serializing folder: " + folder);
Integer diffsfound = 0;

String folderPath = folder.getCanonicalPath();
String canonFolderPath = folderPath + "-canon";
// remove the canonical folder when exists
(new AnyFolder(canonFolderPath)).deleteDirectory();
Vector<String> files = folder.listFilesToVector(true); // returns list of canonical paths
for (int i = 0; i < files.size(); i++) {
// "canonize" the file, replace existing file by the canonized form
String origPath = files.get(i);
String type = FileUtils.getFilenameExt(origPath).toLowerCase();
String relPath = StringUtils.substringAfter(origPath, folderPath);
String canonPath = folderPath + "-canon" + relPath;
AnyFile fileOrFolder = new AnyFile(origPath);
if (fileOrFolder.isFile()) {
if (type.equals("xml") || type.equals("xsd") || type.equals("xhtml")) {
// Compare XML contents
xslFilterFile.setParm("file-path", relPath);
xslFilterFile.setParm("file-type", type);
xslFilterFile.transform(origPath, canonPath);
if (compare) diffsfound += compare(canonPath);
} else if (type.equals("xmi") || type.equals("png") || type.equals("html")) {
// skip these files
} else {
// compare raw, unprocessed contents
fileOrFolder.copyFile(canonPath);
if (compare) diffsfound += compare(canonPath);
if (folder.isDirectory()) {
String folderPath = folder.getCanonicalPath();
String canonFolderPath = folderPath + "-canon";
// remove the canonical folder when exists
(new AnyFolder(canonFolderPath)).deleteDirectory();
Vector<String> files = folder.listFilesToVector(true); // returns list of canonical paths
for (int i = 0; i < files.size(); i++) {
// "canonize" the file, replace existing file by the canonized form
String origPath = files.get(i);
String type = FilenameUtils.getExtension(origPath).toLowerCase();
String relPath = StringUtils.substringAfter(origPath, folderPath);
String canonPath = folderPath + "-canon" + relPath;
AnyFile fileOrFolder = new AnyFile(origPath);
if (fileOrFolder.isFile()) {
if (type.equals("xml") || type.equals("xsd") || type.equals("xhtml")) {
// Compare XML contents
xslFilterFile.setParm("file-path", relPath);
xslFilterFile.setParm("file-type", type);
xslFilterFile.transform(origPath, canonPath);
// canoniseer, vervang het resultaat
canonicalize(new XmlFile(canonPath));
if (compare) diffsfound += compare(canonPath);
} else if (type.equals("xmi") || type.equals("png") || type.equals("html")) {
// skip these files
} else {
// compare raw, unprocessed contents
fileOrFolder.copyFile(canonPath);
if (compare) diffsfound += compare(canonPath);
}
}
}
}
return diffsfound;
}
return diffsfound;
} else {
runner.error(logger,"Regression folder not found: " + folder + ", please complete regression setup");
return 1;
}
}

/**
Expand All @@ -327,7 +338,7 @@ private Integer canonizeFolder(AnyFolder folder,XslFile xslFilterFile, boolean c
* @throws ConfiguratorException
*/
private Integer compare(String canonPath) throws IOException, ConfiguratorException {
String refPath = StringUtils.replace(canonPath,"tst-canon","ref-canon");
String refPath = StringUtils.replacePattern(canonPath,"(\\\\)tst(\\\\)","$1ref$2");
AnyFile refFile = new AnyFile(refPath);
AnyFile tstFile = new AnyFile(canonPath);
if (tstFile.length() == 0) {
Expand All @@ -341,4 +352,13 @@ private Integer compare(String canonPath) throws IOException, ConfiguratorExcept
} else
return 0;
}

private void canonicalize(XmlFile xmlFile) throws Exception {
if (xmlFile.isWellFormed()) {
XmlFile tempFile = new XmlFile(File.createTempFile("canonicalize.", "xml"));
xmlFile.canonicalize(tempFile, "http://www.w3.org/2001/10/xml-exc-c14n#");
FileUtils.copyFile(tempFile, xmlFile);
tempFile.delete();
}
}
}
Loading

0 comments on commit a576168

Please sign in to comment.