Closed a99cl208 closed 1 year ago
Hi, this would require refactoring the validator core code so it could be called without a UI. I think it could be done, but as I am already busy with a million other things is not a priority.
do you see any existing way to address this use case?
Yes: write a jArchi script to validate your model following the rules you think are important in your context. This script could output whatever information you want. Then run it it through command line.
You can run the jArchi script through command line?! If so you made my day, and I would ask how?
--script.runScript <script file>
See https://github.com/archimatetool/archi/wiki/Archi-Command-Line-Interface
Thanks, JB. As always, I forget about using jArchi. "Coders blinkers". ;-)
Ah ah no way. Take my virtual beer as a present 🍺 I guess you can close the ticket therefore.
If anyone has the same requirement, here is the jArchi script i've done:
/*
* Validate model.
*/
console.log("Start validing model...");
const File = Java.type("java.io.File");
const VALIDATION_FOLDER = "validation";
const VALIDATION_FILENAME = "validation_result.csv";
const ARCHI_FOLDER = "Archi";
const ARCHI_PLUGINS_FOLDER = "plugins";
const HAMMER_FILE_PREFIX = "com.archimatetool.hammer";
let modelPath = model.getPath();
console.log("Model path is '" + modelPath + "'");
let modelFile = new File(modelPath);
let gitFolder = modelFile.getParentFile().getParentFile();
let archiFolder = new File(gitFolder, ARCHI_FOLDER);
if (!archiFolder.exists())
{
archiFolder = new File("C:\\Program Files\\Archi");
if (!archiFolder.exists())
{
console.log("Archi folder not found");
exit();
}
}
console.log("Archi folder path is '" + archiFolder.getPath() + "'");
let resultsFile = new File(new File(gitFolder, VALIDATION_FOLDER), VALIDATION_FILENAME);
let pluginsFolder = new File(archiFolder, ARCHI_PLUGINS_FOLDER);
let hammerFile = pluginsFolder.list().filter(x => x.startsWith(HAMMER_FILE_PREFIX));
let hammerFilePath = new File(pluginsFolder, hammerFile[0]).getPath();
console.log("Hammer JAR file path is '" + hammerFilePath + "'");
Java.addToClasspath(hammerFilePath);
const Validator = Java.type("com.archimatetool.hammer.validation.Validator");
const IEditorModelManager = Java.type("com.archimatetool.editor.model.IEditorModelManager");
const ArchiHammerPlugin = Java.type("com.archimatetool.hammer.ArchiHammerPlugin");
const IPreferenceStore = Java.type("org.eclipse.jface.preference.IPreferenceStore");
var ArchiHammerPluginExt = Java.extend(ArchiHammerPlugin);
var IPreferenceStoreExt = Java.extend(IPreferenceStore);
var preferenceStore = new IPreferenceStoreExt({
getBoolean: function() { return true; } // Will set all preferences to true.
});
var plugin = new ArchiHammerPluginExt({
getPreferenceStore: function() { return preferenceStore; }
});
let preferences = ArchiHammerPlugin.INSTANCE = plugin;
let archiModel = IEditorModelManager.INSTANCE.openModel(modelFile);
let val = new Validator(archiModel);
let issuesCategories = val.validate();
let results = '"Category","Description","Object"\r\n'
for (let i = 0; i < issuesCategories.size(); i++) {
category = issuesCategories.get(i);
let categoryName = category.getName();
let issues = category.getIssues();
console.log(issues.size() + " " + categoryName + " found.");
for (let j = 0; j < issues.size(); j++) {
let issue = issues.get(j);
let line = '"' + categoryName + '","' + issue.getDescription() + '","' + issue.getObject().getName() + '"';
results += line + "\n";
}
}
console.log("Writing validation results to '" + resultsFile.getPath() + "'")
$.fs.writeFile(resultsFile.getPath(), results);
console.log("Done.");
Works perfectly (on Windows). Thanks again for support.
@a99cl208 Thanks for sharing! Perhaps you could create a gist so that folks can find it?
See also - https://github.com/archimatetool/archi-scripting-plugin/wiki/Community-shared-scripts
Hello,
I would like to discuss a use case which I am trying to address:
Therefore I would like to suggest if it would be possible to add support for command line for validation. A simple idea would be to use --validate option, and the command line will call the Validator from hammer library and put the outcome in a txt / csv / xml (does not really matter) file that could be processed by the caller afterwards.
Questions here would be: do you see any existing way to address this use case? If no what do you think of the idea / proposed solution?
Regards.