From 1e9162f460c193e395b9c5398402b10c8a76449d Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Wed, 11 Oct 2023 12:18:15 +0200 Subject: [PATCH] Apply code formatter (.settings seem to have been lost temporarily) * Keep YELLOW rating for all files Issue-Ref: 4310 Issue-Url: https://git.fortiss.org/af3/af3/-/issues/4310 Signed-off-by: Simon Barner <barner@fortiss.org> --- .../tooling/ext/quality/ui/view/fx/.ratings | 2 +- .../ui/view/fx/ModelQualityFXController.java | 7 +- .../org/fortiss/tooling/ext/quality/.ratings | 2 +- .../ext/quality/GraphMetricsProvider.java | 6 +- .../tooling/ext/quality/service/.ratings | 2 +- .../quality/service/ModelQualityService.java | 11 +-- .../tooling/ext/quality/storage/.ratings | 4 +- .../ext/quality/storage/CSVFileWriter.java | 79 ++++++++++--------- .../storage/ModelQualityStorageManager.java | 6 +- 9 files changed, 63 insertions(+), 56 deletions(-) diff --git a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings index f2581491b..99d0ae977 100644 --- a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings +++ b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/.ratings @@ -1,3 +1,3 @@ IModelQualityViewPart.java 708f8089645df12098ea67190805cce343045d2e YELLOW -ModelQualityFXController.java e39386b6d4a3f51e71be89d1f1f633342ece79ea YELLOW +ModelQualityFXController.java 24b571533dfa46cb33e5aef49ac91a48a92c9708 YELLOW ModelQualityFXViewPart.java 179abf18d6e3b6c844076620f53b43ac8a42c217 YELLOW diff --git a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java index e39386b6d..24b571533 100644 --- a/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java +++ b/org.fortiss.tooling.ext.quality.ui/src/org/fortiss/tooling/ext/quality/ui/view/fx/ModelQualityFXController.java @@ -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()) { diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings index 4ab24eee1..8f7af8e81 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/.ratings @@ -1,5 +1,5 @@ AF3QualityActivator.java 353c3d99f423997e4e99a896b3c095fd77d81431 YELLOW -GraphMetricsProvider.java b00a3b47acfcb6df3ab948f1258ff256ab07728c YELLOW +GraphMetricsProvider.java 021a9a7de4fb080fe3a7f4f1fe1843564080cdb4 YELLOW HierarchicElementProvider.java 14d99b4d76ec28191ecd0f2654f43b92c36f1302 YELLOW IMetricProvider.java 99fc8993b0e65b2f8757978eeb0481d912f5608c YELLOW IMetricUpdateListener.java c24dc7c0f282623bbf1eefac1fbbb6752c97ddf0 YELLOW diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java index b00a3b47a..021a9a7de 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/GraphMetricsProvider.java @@ -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()) { diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings index 6d7c1b24c..c939dee61 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/.ratings @@ -1,2 +1,2 @@ IModelQualityService.java b530e32826340efaa3872e110d71e1c3a720dc07 YELLOW -ModelQualityService.java e7623bd438d8c0152a00481662fb32954d143c57 YELLOW +ModelQualityService.java a996770744711fb101f174b3421b4984ecdf60d8 YELLOW diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java index e7623bd43..a99677074 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/ModelQualityService.java @@ -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 diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/.ratings b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/.ratings index 1f9621e24..abec1e37a 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/.ratings +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/.ratings @@ -1,2 +1,2 @@ -CSVFileWriter.java 6ee652cdd7a270ad22a29e30d19e6f7f2a41f611 YELLOW -ModelQualityStorageManager.java 50f1fa35b82bc42b564d75fb9510a989b129533f YELLOW +CSVFileWriter.java dc1f73b071a2acd8fffed383c3528c55b34768f0 YELLOW +ModelQualityStorageManager.java 66569ed1d4c3fd12b8f80e526aad70a981622d25 YELLOW diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/CSVFileWriter.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/CSVFileWriter.java index 6ee652cdd..dc1f73b07 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/CSVFileWriter.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/CSVFileWriter.java @@ -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(); + } } diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/ModelQualityStorageManager.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/ModelQualityStorageManager.java index 50f1fa35b..66569ed1d 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/ModelQualityStorageManager.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/storage/ModelQualityStorageManager.java @@ -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"; } -- GitLab