Skip to content
Snippets Groups Projects
Commit 1e9162f4 authored by Simon Barner's avatar Simon Barner
Browse files

Apply code formatter (.settings seem to have been lost temporarily)

* Keep YELLOW rating for all files

Issue-Ref: 4310
Issue-Url: af3#4310



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 7f923aa8
No related branches found
No related tags found
1 merge request!210Setting up Metric extraction plugin for AF3 : Issue 4310
Showing
with 63 additions and 56 deletions
IModelQualityViewPart.java 708f8089645df12098ea67190805cce343045d2e YELLOW
ModelQualityFXController.java e39386b6d4a3f51e71be89d1f1f633342ece79ea YELLOW
ModelQualityFXController.java 24b571533dfa46cb33e5aef49ac91a48a92c9708 YELLOW
ModelQualityFXViewPart.java 179abf18d6e3b6c844076620f53b43ac8a42c217 YELLOW
......@@ -30,7 +30,6 @@ import java.text.DecimalFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -59,7 +58,6 @@ import org.fortiss.tooling.spiderchart.style.DataSeriesStyle;
import org.fortiss.tooling.spiderchart.style.LegendStyle;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.chart.BarChart;
......@@ -146,7 +144,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
public void initialize() {
childMetricChoiceBox.getItems().addAll(MetricKey.values());
}
/** {@inheritDoc} */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
......@@ -192,6 +190,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
public void onChoiceBoxChange() {
updateCharts("Invalid selection or metrics not available");
}
/**
* Is triggered when the child metric choice box changes.
*/
......@@ -221,7 +220,7 @@ public class ModelQualityFXController extends CompositeFXControllerBase<SplitPan
if(node != null) {
//updateChoiceBoxes(node);
// updateChoiceBoxes(node);
if(!node.getChildren().isEmpty()) {
......
AF3QualityActivator.java 353c3d99f423997e4e99a896b3c095fd77d81431 YELLOW
GraphMetricsProvider.java b00a3b47acfcb6df3ab948f1258ff256ab07728c YELLOW
GraphMetricsProvider.java 021a9a7de4fb080fe3a7f4f1fe1843564080cdb4 YELLOW
HierarchicElementProvider.java 14d99b4d76ec28191ecd0f2654f43b92c36f1302 YELLOW
IMetricProvider.java 99fc8993b0e65b2f8757978eeb0481d912f5608c YELLOW
IMetricUpdateListener.java c24dc7c0f282623bbf1eefac1fbbb6752c97ddf0 YELLOW
......@@ -265,10 +265,10 @@ public class GraphMetricsProvider {
saveMetric(scopeElement, manager, recursively, betweenness);
}
}
/** Saving the metrics for each contained element of an {@link IHierarchicElement}. */
private static void saveMetric(IHierarchicElement scopeElement, MetricDataManager manager, boolean recursively,
Map<IHierarchicElement, Double> betweenness) {
private static void saveMetric(IHierarchicElement scopeElement, MetricDataManager manager,
boolean recursively, Map<IHierarchicElement, Double> betweenness) {
MetricKey key = recursively ? MetricKey.BETWEENESS_CENTRALITY_RECURSIVELY
: MetricKey.BETWEENESS_CENTRALITY;
for(IHierarchicElement child : scopeElement.getContainedElements()) {
......
IModelQualityService.java b530e32826340efaa3872e110d71e1c3a720dc07 YELLOW
ModelQualityService.java e7623bd438d8c0152a00481662fb32954d143c57 YELLOW
ModelQualityService.java a996770744711fb101f174b3421b4984ecdf60d8 YELLOW
......@@ -113,9 +113,9 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
}
try {
performMetricCollection(toBeProcessed);
} catch (NoSuchAlgorithmException e) {
} catch(NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
}
} while(true);
......@@ -164,10 +164,11 @@ public class ModelQualityService extends EObjectAwareServiceBase<IMetricProvider
*
* @param topLevelElement
* the {@link ITopLevelElement} on which the analysis should be performed
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws IOException
* @throws NoSuchAlgorithmException
*/
private void performMetricCollection(ITopLevelElement topLevelElement) throws NoSuchAlgorithmException, IOException {
private void performMetricCollection(ITopLevelElement topLevelElement)
throws NoSuchAlgorithmException, IOException {
// Sort root elements, as some metrics are saved into trees from other root elements
// To avoid these problems, the elements have to be processed in a certain order
......
CSVFileWriter.java 6ee652cdd7a270ad22a29e30d19e6f7f2a41f611 YELLOW
ModelQualityStorageManager.java 50f1fa35b82bc42b564d75fb9510a989b129533f YELLOW
CSVFileWriter.java dc1f73b071a2acd8fffed383c3528c55b34768f0 YELLOW
ModelQualityStorageManager.java 66569ed1d4c3fd12b8f80e526aad70a981622d25 YELLOW
......@@ -59,11 +59,12 @@ public class CSVFileWriter {
*
* @param map
* to convert into csv
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws IOException
* @throws NoSuchAlgorithmException
*
*/
public static void metricExtractionToCSV(Map<IProjectRootElement, DataRootElement> map) throws NoSuchAlgorithmException, IOException {
public static void metricExtractionToCSV(Map<IProjectRootElement, DataRootElement> map)
throws NoSuchAlgorithmException, IOException {
// check if there is any data to export
if(map == null || map.isEmpty()) {
......@@ -79,15 +80,17 @@ public class CSVFileWriter {
Collection<DataRootElement> values = map.values();
DataRootElement firstValue = values.toArray(new DataRootElement[0])[0];
String projectName = firstValue.getTopLevelElement().getSaveableName();
Path path = new File(ModelQualityStorageManager.MODEL_QUALITY_PROJECT_DIR,
projectName.replace(ModelQualityStorageManager.AF3_PRJ_SUFFIX,ModelQualityStorageManager.CSV)).toPath();
Path af3File = new File(ModelQualityStorageManager.MODEL_PROJECT_DIR,firstValue.getTopLevelElement().getSaveableName()).toPath();
String projectHash = computeGitHash(af3File);
Path path = new File(ModelQualityStorageManager.MODEL_QUALITY_PROJECT_DIR, projectName
.replace(ModelQualityStorageManager.AF3_PRJ_SUFFIX, ModelQualityStorageManager.CSV))
.toPath();
Path af3File = new File(ModelQualityStorageManager.MODEL_PROJECT_DIR,
firstValue.getTopLevelElement().getSaveableName()).toPath();
String projectHash = computeGitHash(af3File);
List<String> allKeys = new ArrayList<>();
boolean createNewIndex = true;
if(Files.exists(path)) {
// Read first line and try to extract the keys from the already existing file
try(BufferedReader reader = new BufferedReader(new FileReader(path.toFile()))) {
......@@ -100,7 +103,7 @@ public class CSVFileWriter {
e.printStackTrace();
}
}
writeMetricsToFile(map, allKeys, path, createNewIndex, projectName,projectHash);
writeMetricsToFile(map, allKeys, path, createNewIndex, projectName, projectHash);
}
/**
......@@ -115,14 +118,14 @@ public class CSVFileWriter {
* @param createNewIndex
* if a index should be written before writing any values
* @param projectName
* the name of the base fileProject for this map currently in the focus
* the name of the base fileProject for this map currently in the focus
* @param projectHash
* the af3 file hash value saved for version identification
* the af3 file hash value saved for version identification
*/
private static void writeMetricsToFile(Map<IProjectRootElement, DataRootElement> map,
List<String> allKeys, Path path, boolean createNewIndex, String projectName, String projectHash) {
List<String> allKeys, Path path, boolean createNewIndex, String projectName,
String projectHash) {
try(var writer = new BufferedWriter(new FileWriter(path.toFile(), true))) {
if(createNewIndex) {
// Create new index and write it into the first line of the file
......@@ -162,8 +165,8 @@ public class CSVFileWriter {
.map(id -> id.toString()).reduce((a, b) -> a + " " + b).orElse("");
// These 6 data entries are just concatenated in front
var startStream = Stream.of(formattedDateTime, projectName, projectHash, rootName,
node.getName(), children_ids);
var startStream = Stream.of(formattedDateTime, projectName, projectHash,
rootName, node.getName(), children_ids);
// Collect all values from provider in the correct order and combine
var values = Stream.concat(startStream, valueKeys.stream()
.map(String::toUpperCase).map(MetricKey::valueOf).map(k -> {
......@@ -186,25 +189,29 @@ public class CSVFileWriter {
e.printStackTrace();
}
}
/** Function to generate the hash for a fileProject to later on identify the versions with the saved metrics. */
private static String computeGitHash(Path filePath) throws NoSuchAlgorithmException, IOException {
String fileAsString = new String(Files.readAllBytes(Paths.get(filePath.toString())));
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] hash = digest.digest(fileAsString.getBytes(StandardCharsets.UTF_8));
return bytesToHex(hash);
/**
* Function to generate the hash for a fileProject to later on identify the versions with the
* saved metrics.
*/
private static String computeGitHash(Path filePath)
throws NoSuchAlgorithmException, IOException {
String fileAsString = new String(Files.readAllBytes(Paths.get(filePath.toString())));
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] hash = digest.digest(fileAsString.getBytes(StandardCharsets.UTF_8));
return bytesToHex(hash);
}
/** Switching from bytes to Hex notation. */
private static String bytesToHex(byte[] hash) {
StringBuilder hexString = new StringBuilder(2 * hash.length);
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
StringBuilder hexString = new StringBuilder(2 * hash.length);
for(byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if(hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}
......@@ -30,7 +30,7 @@ public class ModelQualityStorageManager {
/** The name of the general quality plugin directory. */
public static final String AF3_QUALITY_DIRECTORY_NAME = "AF3-Model-Quality-Directory";
/** The name of the general project directory. */
public static final String AF3_PROJECT_DIRECTORY_NAME = "AF3-Project-Directory";
......@@ -40,14 +40,14 @@ public class ModelQualityStorageManager {
/** {@link File} representing the directory where all data is saved. */
public static final File MODEL_QUALITY_PROJECT_DIR =
new File(WORKSPACE_ROOT.getLocation() + File.separator + AF3_QUALITY_DIRECTORY_NAME);
/** {@link File} representing the directory where all data is saved. */
public static final File MODEL_PROJECT_DIR =
new File(WORKSPACE_ROOT.getLocation() + File.separator + AF3_PROJECT_DIRECTORY_NAME);
/** Defines the suffix of AF3 project files. */
public static final String AF3_PRJ_SUFFIX = "af3_23";
/** Suffix of the file in which the data is written. */
public static final String CSV = "csv";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment