Browse files

exclude diffs from generation task

  • Loading branch information...
1 parent 94af0c3 commit d1189ed897dc75588a1050696bb44f43802aeaeb @inspirer inspirer committed Jan 17, 2011
View
3 core/kernel/source/jetbrains/mps/project/ProjectTester.java
@@ -46,7 +46,6 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -228,7 +227,7 @@ public void run() {
);
if (myIsRunnable) {
- diffReports.addAll(DiffReporter.createDiffReports(generationHandler));
+ diffReports.addAll(DiffReporter.createDiffReports(generationHandler, null));
}
List<SModel> outputModels = new ArrayList<SModel>();
outputModels.addAll(generationHandler.getOutputModels());
View
27 core/kernel/source/jetbrains/mps/project/tester/DiffReporter.java
@@ -21,10 +21,7 @@
import jetbrains.mps.util.NameUtil;
import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class DiffReporter {
@@ -52,7 +49,7 @@ private static void addDiffReport(TestComparator comparator, List<String> report
}
}
- public static List<String> createDiffReports(TesterGenerationHandler genHandler) {
+ public static List<String> createDiffReports(TesterGenerationHandler genHandler, Set<File> excludedFromDiffFiles) {
List<String> result = new ArrayList<String>();
for (SModelReference outputModel : genHandler.getOutputModelRefs()) {
List<String> files = new ArrayList<String>();
@@ -67,8 +64,17 @@ private static void addDiffReport(TestComparator comparator, List<String> report
continue;
}
+ final String filePath = getFilePath(genHandler, outputModel, outputFileName);
+ if(excludedFromDiffFiles != null) {
+ final File expectedFile = new File(filePath);
+ if(excludedFromDiffFiles.contains(expectedFile)) {
+ files.remove(outputFileName);
+ continue;
+ }
+ }
+
String newContent = genHandler.getSourceByNode(outputRoot, outputModel);
- if (addDiffReport(genHandler, outputModel, outputRoot, outputFileName, newContent, result)) {
+ if (addDiffReport(filePath, outputRoot, newContent, result)) {
files.remove(outputFileName);
}
}
@@ -81,7 +87,7 @@ private static void addDiffReport(TestComparator comparator, List<String> report
String newContent = sources.get(fileName);
if (newContent != null) {
- addDiffReport(genHandler, outputModel, fileName, fileName, newContent, result);
+ addDiffReport(getFilePath(genHandler, outputModel, fileName), fileName, newContent, result);
} else {
String title = getDiffReportTitle((SNode) null, fileName, false, true);
File file = new File(genHandler.getOutputDir(outputModel) + File.separator + fileName);
@@ -96,9 +102,8 @@ private static void addDiffReport(TestComparator comparator, List<String> report
return result;
}
- private static boolean addDiffReport(TesterGenerationHandler genHandler, SModelReference outputModel, String outputName, String outputFileName, String newContent, List<String> result) {
+ private static boolean addDiffReport(String filePath, String outputName, String newContent, List<String> result) {
boolean found = false;
- final String filePath = genHandler.getOutputDir(outputModel) + File.separator + outputFileName;
final File testFile = new File(filePath);
String oldContent = null;
if (testFile.exists() && testFile.canRead()) {
@@ -112,4 +117,8 @@ private static boolean addDiffReport(TesterGenerationHandler genHandler, SModelR
addDiffReport(new TestComparator(oldTest, newTest), result, title);
return found;
}
+
+ private static String getFilePath(TesterGenerationHandler genHandler, SModelReference outputModel, String outputFileName) {
+ return genHandler.getOutputDir(outputModel) + File.separator + outputFileName;
+ }
}
View
43 platform/buildlanguage/ant/sources/jetbrains/mps/build/ant/ExcludeNested.java
@@ -0,0 +1,43 @@
+package jetbrains.mps.build.ant;
+
+import jetbrains.mps.vfs.MPSExtentions;
+import org.apache.tools.ant.types.DataType;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.resources.FileResource;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Evgeny Gryaznov, 1/17/11
+ */
+public class ExcludeNested extends DataType {
+
+ private List<FileSet> excluded = new ArrayList<FileSet>();
+
+ public List<File> getExcludedFromDiffFiles() {
+ List<File> result = new ArrayList<File>();
+ for(FileSet inner : excluded) {
+ Iterator it = inner.iterator();
+ while (it.hasNext()) {
+ FileResource next = (FileResource) it.next();
+ File file = next.getFile();
+ if(file.exists()) {
+ result.add(file);
+ }
+ }
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ public void addFile(FileSet inner) {
+ excluded.add(inner);
+ }
+
+ public void addFiles(FileSet inner) {
+ excluded.add(inner);
+ }
+}
View
31 platform/buildlanguage/ant/sources/jetbrains/mps/build/ant/MpsLoadTask.java
@@ -1,24 +1,25 @@
package jetbrains.mps.build.ant;
-import org.apache.tools.ant.types.EnumeratedAttribute;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.util.JavaEnvUtils;
-import java.io.*;
-import java.util.*;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URLClassLoader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
-
-import jetbrains.mps.build.ant.ProjectNested;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
public abstract class MpsLoadTask extends org.apache.tools.ant.Task {
private File myMpsHome;
@@ -71,6 +72,12 @@ public void addConfiguredProject(ProjectNested projectInner) {
}
}
+ public void addConfiguredExclude(ExcludeNested excludeInner) {
+ for (File file : excludeInner.getExcludedFromDiffFiles()) {
+ myWhatToDo.excludeFileFromDiff(file);
+ }
+ }
+
public void addConfiguredLibrary(LibraryDataType libraryInner) {
if (libraryInner.getName() == null) {
log("Library missing required attribute name.", org.apache.tools.ant.Project.MSG_ERR);
@@ -204,7 +211,7 @@ private void processNonZeroExitCode(int i) {
private void dumpPropertiesToWhatToDo() {
Hashtable properties = getProject().getProperties();
for (Object key : properties.keySet()) {
- myWhatToDo.putProperty((String)key, (String)properties.get(key));
+ myWhatToDo.putProperty((String) key, (String) properties.get(key));
}
}
View
23 platform/buildlanguage/ant/sources/jetbrains/mps/build/ant/WhatToDo.java
@@ -28,12 +28,14 @@
public class WhatToDo {
private final Set<File> myModels = new LinkedHashSet<File>();
private final Set<File> myModules = new LinkedHashSet<File>();
+ private final Set<File> myExcludedFromDiff = new LinkedHashSet<File>();
private final Map<File, List<String>> myMPSProjects = new LinkedHashMap<File, List<String>>();
private boolean myFailOnError = false;
private final Map<String, File> myLibraries = new LinkedHashMap<String, File>();
private final Set<String> myCompiledLibraries = new LinkedHashSet<String>();
private final Map<String, String> myMacro = new LinkedHashMap<String, String>();
private int myLogLevel = org.apache.tools.ant.Project.MSG_INFO;
+ private static final String EXCLUDE_FROM_DIFF_FILE = "EXCLUDE_FROM_DIFF_FILE";
private static final String MODEL_FILE = "MODEL_FILE";
private static final String MODULE_FILE = "MODULE_FILE";
private static final String MPS_PROJECT = "MPS_PROJECT";
@@ -54,6 +56,11 @@ public void addModelFile(File file) {
myModels.add(file);
}
+ public void excludeFileFromDiff(File file) {
+ assert file.exists() && !file.isDirectory();
+ myExcludedFromDiff.add(file);
+ }
+
public void addProjectFile(File projectFile) {
assert projectFile.exists() && projectFile.isFile();
if (!myMPSProjects.containsKey(projectFile)) {
@@ -79,6 +86,14 @@ public void updateModels(Set<File> models) {
myModels.addAll(models);
}
+ public Set<File> getExcludedFromDiffFiles() {
+ return Collections.unmodifiableSet(myExcludedFromDiff);
+ }
+
+ public void updateExcludedFromDiffFiles(Set<File> excluded) {
+ myExcludedFromDiff.addAll(excluded);
+ }
+
public Set<File> getModules() {
return Collections.unmodifiableSet(myModules);
}
@@ -186,6 +201,12 @@ public String toString() {
sb.append(f.getAbsolutePath());
sb.append(" ");
}
+ for (File f : myExcludedFromDiff) {
+ sb.append(EXCLUDE_FROM_DIFF_FILE);
+ sb.append("=");
+ sb.append(f.getAbsolutePath());
+ sb.append(" ");
+ }
for (File f : myModules) {
sb.append(MODULE_FILE);
sb.append("=");
@@ -289,6 +310,8 @@ public static WhatToDo fromCommandLine(String... args) {
String[] propertyValuePair = s.split("=");
if (propertyValuePair[0].equals(MODEL_FILE)) {
whatToDo.addModelFile(new File(propertyValuePair[1]));
+ } else if (propertyValuePair[0].equals(EXCLUDE_FROM_DIFF_FILE)) {
+ whatToDo.excludeFileFromDiff(new File(propertyValuePair[1]));
} else if (propertyValuePair[0].equals(MODULE_FILE)) {
whatToDo.addModuleFile(new File(propertyValuePair[1]));
} else if (propertyValuePair[0].equals(MPS_LIBRARY)) {
View
2 ...rm/buildlanguage/ant/sources/jetbrains/mps/build/ant/generation/TestGenerationWorker.java
@@ -246,7 +246,7 @@ protected void generateModulesCycle(GeneratorManager gm, Cycle cycle) {
Boolean.parseBoolean(myWhatToDo.getProperty(TestGenerationOnTeamcity.SHOW_DIFF))) {
diffReports = ModelAccess.instance().runReadAction(new Computable<List<String>>() {
public List<String> compute() {
- return DiffReporter.createDiffReports(myGenerationHandler);
+ return DiffReporter.createDiffReports(myGenerationHandler, myWhatToDo.getExcludedFromDiffFiles());
}
});
} else {

0 comments on commit d1189ed

Please sign in to comment.