-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish model coverage report tool for MD/CSM
the project is published under Apache 2.0 license terms
- Loading branch information
1 parent
e7c44ad
commit e10daf1
Showing
11 changed files
with
817 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
tools/io.incquery.cameo.model-coverage-report/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: io.incquery.cameo.model-coverage-report | ||
Bundle-SymbolicName: io.incquery.cameo.model-coverage-report;singleton:=true | ||
Bundle-Version: 0.1.0.qualifier | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
Automatic-Module-Name: io.incquery.cameo.model-coverage-report | ||
Export-Package: . |
32 changes: 32 additions & 0 deletions
32
...eport/src/main/dist/template/data/resourcemanager/MDR_Example_Plugin_18351_descriptor.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<resourceDescriptor critical="false" | ||
date="${build.timestamp}" | ||
description="Model coverage reporting plugin" | ||
id="17151" | ||
mdVersionMax="higher" | ||
mdVersionMin="19.0 beta" | ||
name="Model coverage reporting plugin" | ||
product="" | ||
type="Plugin"> | ||
<version human="${human.version}" resource="${internal.version}" internal="${internal.version}"/> | ||
<provider name="IncQuery Labs cPlc."/> | ||
<edition>Reader</edition> | ||
<edition>Community</edition> | ||
<edition>Standard</edition> | ||
<edition>Professional Java</edition> | ||
<edition>Professional C++</edition> | ||
<edition>Professional C#</edition> | ||
<edition>Professional ArcStyler</edition> | ||
<edition>Professional EFFS ArcStyler</edition> | ||
<edition>OptimalJ</edition> | ||
<edition>Professional</edition> | ||
<edition>Architect</edition> | ||
<edition>Enterprise</edition> | ||
|
||
<requiredResource id="1440" name="SysML"/> | ||
|
||
<installation> | ||
<!-- START AUTO-GENERATED --> | ||
<!-- END AUTO-GENERATED --> | ||
</installation> | ||
</resourceDescriptor> |
20 changes: 20 additions & 0 deletions
20
...o.incquery.cameo.model-coverage-report/src/main/dist/template/plugins/${group}/plugin.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<plugin | ||
id="io.incquery.cameo.model-coverage-report" | ||
name="IncQuery Labs' Model Coverage Report Plugin" | ||
internalVersion="${internal.version}" | ||
version="${human.version}" | ||
provider-name="IncQuery Labs cPlc." | ||
class-lookup="LocalFirst" | ||
ownClassloader="true" | ||
class="io.incquery.cameo.modelcoveragereport.ModelCoverageReportPlugin"> | ||
|
||
<requires> | ||
<required-plugin id="com.nomagic.magicdraw.plugins.impl.sysml" name="SysML"/> | ||
</requires> | ||
|
||
<runtime> | ||
<!-- START AUTO-GENERATED --> | ||
<!-- END AUTO-GENERATED --> | ||
</runtime> | ||
|
||
</plugin> |
58 changes: 58 additions & 0 deletions
58
...rage-report/src/main/java/io/incquery/cameo/modelcoveragereport/MainMenuConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* | ||
* Copyright (c) 2002 NoMagic, Inc. All Rights Reserved. | ||
*/ | ||
|
||
package io.incquery.cameo.modelcoveragereport; | ||
|
||
import com.nomagic.actions.AMConfigurator; | ||
import com.nomagic.actions.ActionsCategory; | ||
import com.nomagic.actions.ActionsManager; | ||
import com.nomagic.actions.NMAction; | ||
import com.nomagic.magicdraw.actions.MDActionsCategory; | ||
|
||
public class MainMenuConfigurator implements AMConfigurator { | ||
|
||
String REPORTING = "Report"; | ||
|
||
/** | ||
* Action will be added to manager. | ||
*/ | ||
private NMAction[] actions; | ||
|
||
/** | ||
* Creates configurator. | ||
* | ||
* @param action | ||
* action to be added to main menu. | ||
*/ | ||
public MainMenuConfigurator(NMAction... actions) { | ||
this.actions = actions; | ||
} | ||
|
||
/** | ||
* @see com.nomagic.actions.AMConfigurator#configure(ActionsManager) Methods | ||
* adds action to given manager Examples category. | ||
*/ | ||
@Override | ||
public void configure(ActionsManager manager) { | ||
// searching for Examples action category | ||
ActionsCategory category = (ActionsCategory) manager.getActionFor(REPORTING); | ||
|
||
if (category == null) { | ||
// creating new category | ||
category = new MDActionsCategory(REPORTING, REPORTING); | ||
category.setNested(true); | ||
manager.addCategory(category); | ||
} | ||
for (NMAction action : actions) { | ||
category.addAction(action); | ||
} | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return AMConfigurator.MEDIUM_PRIORITY; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...report/src/main/java/io/incquery/cameo/modelcoveragereport/ModelCoverageReportPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.incquery.cameo.modelcoveragereport; | ||
|
||
import io.incquery.cameo.modelcoveragereport.actions.MetaModelCoverageAction; | ||
import com.nomagic.magicdraw.actions.ActionsConfiguratorsManager; | ||
import com.nomagic.magicdraw.plugins.Plugin; | ||
|
||
public class ModelCoverageReportPlugin extends Plugin { | ||
|
||
@Override | ||
public boolean close() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
|
||
ActionsConfiguratorsManager manager = ActionsConfiguratorsManager.getInstance(); | ||
manager.addMainMenuConfigurator(new MainMenuConfigurator(new MetaModelCoverageAction())); | ||
manager.addContainmentBrowserContextConfigurator(new ProfileCoverageActionConfigurator()); | ||
|
||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return true; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...rc/main/java/io/incquery/cameo/modelcoveragereport/ProfileCoverageActionConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.incquery.cameo.modelcoveragereport; | ||
|
||
import java.util.Arrays; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import io.incquery.cameo.modelcoveragereport.actions.ProfileCoverageAction; | ||
import com.nomagic.actions.AMConfigurator; | ||
import com.nomagic.actions.ActionsCategory; | ||
import com.nomagic.actions.ActionsManager; | ||
import com.nomagic.magicdraw.actions.ActionsStateUpdater; | ||
import com.nomagic.magicdraw.actions.BrowserContextAMConfigurator; | ||
import com.nomagic.magicdraw.actions.MDActionsCategory; | ||
import com.nomagic.magicdraw.ui.browser.Node; | ||
import com.nomagic.magicdraw.ui.browser.Tree; | ||
import com.nomagic.uml2.ext.magicdraw.mdprofiles.Profile; | ||
|
||
public class ProfileCoverageActionConfigurator implements BrowserContextAMConfigurator { | ||
|
||
@Override | ||
public void configure(ActionsManager manager, Tree tree) { | ||
ActionsCategory cat = manager.getCategory("REPORT"); | ||
if(cat == null) { | ||
cat = new MDActionsCategory("REPORT", "Generate Report..."); | ||
manager.addCategory(cat); | ||
} | ||
Set<Profile> selectedObjects = Arrays.stream(tree.getSelectedNodes()).map(Node::getUserObject) | ||
.filter(Profile.class::isInstance).map(Profile.class::cast).collect(Collectors.toSet()); | ||
if(!selectedObjects.isEmpty()) { | ||
cat.addAction(new ProfileCoverageAction(selectedObjects.iterator().next())); | ||
ActionsStateUpdater.updateActionsState(); | ||
} | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return AMConfigurator.MEDIUM_PRIORITY; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...ort/src/main/java/io/incquery/cameo/modelcoveragereport/actions/CoverageReportAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package io.incquery.cameo.modelcoveragereport.actions; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.nomagic.magicdraw.actions.MDAction; | ||
import com.nomagic.magicdraw.core.Application; | ||
import com.nomagic.magicdraw.core.GUILog; | ||
import com.nomagic.magicdraw.core.Project; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.swing.*; | ||
import java.awt.event.ActionEvent; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.sql.Timestamp; | ||
import java.text.SimpleDateFormat; | ||
|
||
public abstract class CoverageReportAction extends MDAction { | ||
private static final long serialVersionUID = 1L; | ||
protected static final String TEMPLATE__CAT_ID = "%S_COVERAGE_REPORT_GENERATOR"; | ||
protected static final String TEMPLATE__CAT_NAME = "Generate %s Coverage Report"; | ||
protected final String type; | ||
private static File baseDir = null; | ||
|
||
@Override | ||
public final void actionPerformed(@CheckForNull ActionEvent actionEvent) { | ||
// select output directory | ||
JFileChooser outputDirectorySelector = new JFileChooser(); | ||
outputDirectorySelector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | ||
outputDirectorySelector.setDialogTitle("Output Directory Selector"); | ||
outputDirectorySelector.setCurrentDirectory(baseDir); | ||
if(outputDirectorySelector.showOpenDialog(Application.getInstance().getMainFrame()) == JFileChooser.APPROVE_OPTION) { | ||
baseDir = outputDirectorySelector.getSelectedFile(); | ||
} else { | ||
return; | ||
} | ||
|
||
// execute the report generation | ||
Result result = actionPerformed(); | ||
|
||
// user feedback | ||
GUILog log = Application.getInstance().getGUILog(); | ||
if(result.succeeded) { | ||
log.log(result.message); | ||
} else if(result.error != null) { | ||
log.showError(result.message, result.error); | ||
} else { | ||
log.showError(result.message); | ||
} | ||
} | ||
|
||
protected File getBaseDir() { | ||
return baseDir; | ||
} | ||
|
||
public abstract Result actionPerformed(); | ||
|
||
protected CoverageReportAction(String type) { | ||
super(String.format(TEMPLATE__CAT_ID, type), String.format(TEMPLATE__CAT_NAME, type), null, null); | ||
this.type = type.toLowerCase(); | ||
} | ||
protected final void serializeToJson(Object coverageDTO, File outputDir) { | ||
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); | ||
File outputFile = new File(outputDir, String.format("%sCoverageInfo.json", type)); | ||
try (FileWriter writer = new FileWriter(outputFile)) { | ||
gson.toJson(coverageDTO, writer); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
protected final File setupDestinationDirectory(Project project) { | ||
Timestamp timestamp = new Timestamp(System.currentTimeMillis()); | ||
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss"); | ||
String projectName = project.getName(); | ||
|
||
return new File(Paths.get( | ||
getBaseDir() != null | ||
? getBaseDir().getAbsolutePath() | ||
: "./ModelCoverageInfo", | ||
projectName, | ||
simpleDate.format(timestamp)).toString()); | ||
} | ||
|
||
protected static final class Result { | ||
public final boolean succeeded; | ||
public final String message; | ||
public final Throwable error; | ||
|
||
private static final String OUTPUT_TEMPLATE = "Report files were successfully generated into the following directory: %s"; | ||
|
||
public Result(File outputDir) { | ||
this.succeeded = true; | ||
this.message = String.format(OUTPUT_TEMPLATE, outputDir.toString()); | ||
this.error = null; | ||
} | ||
public Result(String message, Throwable error) { | ||
this.succeeded = true; | ||
this.message = message; | ||
this.error = error; | ||
} | ||
} | ||
} |
Oops, something went wrong.