Skip to content

Commit

Permalink
exclude diffs from generation task
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Gryaznov authored and Evgeny Gryaznov committed Jan 17, 2011
1 parent 94af0c3 commit d1189ed
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 24 deletions.
3 changes: 1 addition & 2 deletions core/kernel/source/jetbrains/mps/project/ProjectTester.java
Expand Up @@ -46,7 +46,6 @@
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
Expand Down Expand Up @@ -228,7 +227,7 @@ public void run() {
); );


if (myIsRunnable) { if (myIsRunnable) {
diffReports.addAll(DiffReporter.createDiffReports(generationHandler)); diffReports.addAll(DiffReporter.createDiffReports(generationHandler, null));
} }
List<SModel> outputModels = new ArrayList<SModel>(); List<SModel> outputModels = new ArrayList<SModel>();
outputModels.addAll(generationHandler.getOutputModels()); outputModels.addAll(generationHandler.getOutputModels());
Expand Down
27 changes: 18 additions & 9 deletions core/kernel/source/jetbrains/mps/project/tester/DiffReporter.java
Expand Up @@ -21,10 +21,7 @@
import jetbrains.mps.util.NameUtil; import jetbrains.mps.util.NameUtil;


import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


public class DiffReporter { public class DiffReporter {


Expand Down Expand Up @@ -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>(); List<String> result = new ArrayList<String>();
for (SModelReference outputModel : genHandler.getOutputModelRefs()) { for (SModelReference outputModel : genHandler.getOutputModelRefs()) {
List<String> files = new ArrayList<String>(); List<String> files = new ArrayList<String>();
Expand All @@ -67,8 +64,17 @@ public static List<String> createDiffReports(TesterGenerationHandler genHandler)
continue; 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); String newContent = genHandler.getSourceByNode(outputRoot, outputModel);
if (addDiffReport(genHandler, outputModel, outputRoot, outputFileName, newContent, result)) { if (addDiffReport(filePath, outputRoot, newContent, result)) {
files.remove(outputFileName); files.remove(outputFileName);
} }
} }
Expand All @@ -81,7 +87,7 @@ public static List<String> createDiffReports(TesterGenerationHandler genHandler)
String newContent = sources.get(fileName); String newContent = sources.get(fileName);


if (newContent != null) { if (newContent != null) {
addDiffReport(genHandler, outputModel, fileName, fileName, newContent, result); addDiffReport(getFilePath(genHandler, outputModel, fileName), fileName, newContent, result);
} else { } else {
String title = getDiffReportTitle((SNode) null, fileName, false, true); String title = getDiffReportTitle((SNode) null, fileName, false, true);
File file = new File(genHandler.getOutputDir(outputModel) + File.separator + fileName); File file = new File(genHandler.getOutputDir(outputModel) + File.separator + fileName);
Expand All @@ -96,9 +102,8 @@ public static List<String> createDiffReports(TesterGenerationHandler genHandler)
return result; 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; boolean found = false;
final String filePath = genHandler.getOutputDir(outputModel) + File.separator + outputFileName;
final File testFile = new File(filePath); final File testFile = new File(filePath);
String oldContent = null; String oldContent = null;
if (testFile.exists() && testFile.canRead()) { if (testFile.exists() && testFile.canRead()) {
Expand All @@ -112,4 +117,8 @@ private static boolean addDiffReport(TesterGenerationHandler genHandler, SModelR
addDiffReport(new TestComparator(oldTest, newTest), result, title); addDiffReport(new TestComparator(oldTest, newTest), result, title);
return found; return found;
} }

private static String getFilePath(TesterGenerationHandler genHandler, SModelReference outputModel, String outputFileName) {
return genHandler.getOutputDir(outputModel) + File.separator + outputFileName;
}
} }
@@ -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);
}
}
@@ -1,24 +1,25 @@
package jetbrains.mps.build.ant; 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.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.taskdefs.Execute; 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 org.apache.tools.ant.util.JavaEnvUtils;


import java.io.*; import java.io.File;
import java.util.*; import java.io.FileNotFoundException;
import java.net.URL; import java.io.IOException;
import java.net.MalformedURLException; import java.io.InputStream;
import java.net.URLClassLoader;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;
import jetbrains.mps.build.ant.ProjectNested; 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 { public abstract class MpsLoadTask extends org.apache.tools.ant.Task {
private File myMpsHome; private File myMpsHome;
Expand Down Expand Up @@ -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) { public void addConfiguredLibrary(LibraryDataType libraryInner) {
if (libraryInner.getName() == null) { if (libraryInner.getName() == null) {
log("Library missing required attribute name.", org.apache.tools.ant.Project.MSG_ERR); log("Library missing required attribute name.", org.apache.tools.ant.Project.MSG_ERR);
Expand Down Expand Up @@ -204,7 +211,7 @@ private void processNonZeroExitCode(int i) {
private void dumpPropertiesToWhatToDo() { private void dumpPropertiesToWhatToDo() {
Hashtable properties = getProject().getProperties(); Hashtable properties = getProject().getProperties();
for (Object key : properties.keySet()) { for (Object key : properties.keySet()) {
myWhatToDo.putProperty((String)key, (String)properties.get(key)); myWhatToDo.putProperty((String) key, (String) properties.get(key));
} }
} }


Expand Down
Expand Up @@ -28,12 +28,14 @@
public class WhatToDo { public class WhatToDo {
private final Set<File> myModels = new LinkedHashSet<File>(); private final Set<File> myModels = new LinkedHashSet<File>();
private final Set<File> myModules = 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 final Map<File, List<String>> myMPSProjects = new LinkedHashMap<File, List<String>>();
private boolean myFailOnError = false; private boolean myFailOnError = false;
private final Map<String, File> myLibraries = new LinkedHashMap<String, File>(); private final Map<String, File> myLibraries = new LinkedHashMap<String, File>();
private final Set<String> myCompiledLibraries = new LinkedHashSet<String>(); private final Set<String> myCompiledLibraries = new LinkedHashSet<String>();
private final Map<String, String> myMacro = new LinkedHashMap<String, String>(); private final Map<String, String> myMacro = new LinkedHashMap<String, String>();
private int myLogLevel = org.apache.tools.ant.Project.MSG_INFO; 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 MODEL_FILE = "MODEL_FILE";
private static final String MODULE_FILE = "MODULE_FILE"; private static final String MODULE_FILE = "MODULE_FILE";
private static final String MPS_PROJECT = "MPS_PROJECT"; private static final String MPS_PROJECT = "MPS_PROJECT";
Expand All @@ -54,6 +56,11 @@ public void addModelFile(File file) {
myModels.add(file); myModels.add(file);
} }


public void excludeFileFromDiff(File file) {
assert file.exists() && !file.isDirectory();
myExcludedFromDiff.add(file);
}

public void addProjectFile(File projectFile) { public void addProjectFile(File projectFile) {
assert projectFile.exists() && projectFile.isFile(); assert projectFile.exists() && projectFile.isFile();
if (!myMPSProjects.containsKey(projectFile)) { if (!myMPSProjects.containsKey(projectFile)) {
Expand All @@ -79,6 +86,14 @@ public void updateModels(Set<File> models) {
myModels.addAll(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() { public Set<File> getModules() {
return Collections.unmodifiableSet(myModules); return Collections.unmodifiableSet(myModules);
} }
Expand Down Expand Up @@ -186,6 +201,12 @@ public String toString() {
sb.append(f.getAbsolutePath()); sb.append(f.getAbsolutePath());
sb.append(" "); sb.append(" ");
} }
for (File f : myExcludedFromDiff) {
sb.append(EXCLUDE_FROM_DIFF_FILE);
sb.append("=");
sb.append(f.getAbsolutePath());
sb.append(" ");
}
for (File f : myModules) { for (File f : myModules) {
sb.append(MODULE_FILE); sb.append(MODULE_FILE);
sb.append("="); sb.append("=");
Expand Down Expand Up @@ -289,6 +310,8 @@ public static WhatToDo fromCommandLine(String... args) {
String[] propertyValuePair = s.split("="); String[] propertyValuePair = s.split("=");
if (propertyValuePair[0].equals(MODEL_FILE)) { if (propertyValuePair[0].equals(MODEL_FILE)) {
whatToDo.addModelFile(new File(propertyValuePair[1])); 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)) { } else if (propertyValuePair[0].equals(MODULE_FILE)) {
whatToDo.addModuleFile(new File(propertyValuePair[1])); whatToDo.addModuleFile(new File(propertyValuePair[1]));
} else if (propertyValuePair[0].equals(MPS_LIBRARY)) { } else if (propertyValuePair[0].equals(MPS_LIBRARY)) {
Expand Down
Expand Up @@ -246,7 +246,7 @@ protected void generateModulesCycle(GeneratorManager gm, Cycle cycle) {
Boolean.parseBoolean(myWhatToDo.getProperty(TestGenerationOnTeamcity.SHOW_DIFF))) { Boolean.parseBoolean(myWhatToDo.getProperty(TestGenerationOnTeamcity.SHOW_DIFF))) {
diffReports = ModelAccess.instance().runReadAction(new Computable<List<String>>() { diffReports = ModelAccess.instance().runReadAction(new Computable<List<String>>() {
public List<String> compute() { public List<String> compute() {
return DiffReporter.createDiffReports(myGenerationHandler); return DiffReporter.createDiffReports(myGenerationHandler, myWhatToDo.getExcludedFromDiffFiles());
} }
}); });
} else { } else {
Expand Down

0 comments on commit d1189ed

Please sign in to comment.