From 9bcc8ea07dea571b3d57a8b55f945a16800af1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Spo=CC=88nemann?= Date: Wed, 8 Jun 2016 16:02:01 +0200 Subject: [PATCH] Added src-gen, xtend-gen etc. to generated list of removal paths --- .../xtext/splitting/GenerateRemovals.java | 42 +++++++++++++++++-- .../xtext/splitting/ValidateSplitting.java | 4 +- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/splitting/src/org/eclipse/xtext/splitting/GenerateRemovals.java b/splitting/src/org/eclipse/xtext/splitting/GenerateRemovals.java index 1b6c7267a..ab4651dfb 100644 --- a/splitting/src/org/eclipse/xtext/splitting/GenerateRemovals.java +++ b/splitting/src/org/eclipse/xtext/splitting/GenerateRemovals.java @@ -10,12 +10,20 @@ package org.eclipse.xtext.splitting; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; -import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; -import java.util.List; +import java.util.LinkedHashSet; import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class GenerateRemovals { + + public static final Set GEN_DIRS = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList( + "src-gen", "xtend-gen", "xtext-gen", "emf-gen" + ))); public static void main(String[] args) { if (args.length != 2) { @@ -23,9 +31,9 @@ public class GenerateRemovals { } String outputDir = args[1]; try { - final Map> removalPaths = new HashMap<>(); + final Map> removalPaths = new HashMap<>(); for (String targetRepo : ValidateSplitting.REPOSITORIES) { - removalPaths.put(targetRepo, new ArrayList<>()); + removalPaths.put(targetRepo, new LinkedHashSet<>()); } // Gather paths to be removed from the history for each target repository @@ -52,6 +60,32 @@ public class GenerateRemovals { } } + // Add directories with generated code to the removal list + final Pattern segmentPattern = Pattern.compile("/"); + try (BufferedReader reader = new BufferedReader(new FileReader(outputDir + "/" + FindProjects.ALL_FILES))) { + String line; + while ((line = reader.readLine()) != null) { + String file = line.replaceAll("\"|\\\\.", ""); + for (String genDir : GEN_DIRS) { + int genDirIndex = file.indexOf(genDir); + if (genDirIndex > 0) { + for (String targetRepo : ValidateSplitting.REPOSITORIES) { + Set repoRemovals = removalPaths.get(targetRepo); + Matcher matcher = segmentPattern.matcher(file); + boolean foundRemoval = false; + int genDirEndIndex = genDirIndex + genDir.length(); + while (!foundRemoval && matcher.find() && matcher.start() <= genDirEndIndex) { + if (repoRemovals.contains(file.substring(0, matcher.start()))) + foundRemoval = true; + } + if (!foundRemoval) + repoRemovals.add(file.substring(0, genDirEndIndex)); + } + } + } + } + } + // Write a removal list for each target repository for (String targetRepo : ValidateSplitting.REPOSITORIES) { try (FileWriter writer = new FileWriter(outputDir + "/removals-" + targetRepo + ".txt")) { diff --git a/splitting/src/org/eclipse/xtext/splitting/ValidateSplitting.java b/splitting/src/org/eclipse/xtext/splitting/ValidateSplitting.java index 0d66adf76..ab6e66c2d 100644 --- a/splitting/src/org/eclipse/xtext/splitting/ValidateSplitting.java +++ b/splitting/src/org/eclipse/xtext/splitting/ValidateSplitting.java @@ -67,10 +67,8 @@ public class ValidateSplitting { if (!specifiedPaths.contains(file)) { Matcher matcher = segmentPattern.matcher(file); boolean foundSplitting = false; - int lastMatch = -1; while (!foundSplitting && matcher.find()) { - lastMatch = matcher.start(); - if (specifiedPaths.contains(file.substring(0, lastMatch))) + if (specifiedPaths.contains(file.substring(0, matcher.start()))) foundSplitting = true; } if (!foundSplitting)