use of de.dagere.peass.analysis.properties.VersionChangeProperties in project peass by DaGeRe.
the class ClassifyByRules method classifyProject.
private void classifyProject(final Set<String> allFeatures, final String project) throws IOException, JsonParseException, JsonMappingException {
final RepoFolders repos = new RepoFolders();
final File learnFile = new File(repos.getClassificationFolder(), project + ".json");
final File learnPropertyFile = repos.getProjectPropertyFile(project);
final Classification learn = Constants.OBJECTMAPPER.readValue(learnFile, Classification.class);
final VersionChangeProperties changes = Constants.OBJECTMAPPER.readValue(learnPropertyFile, VersionChangeProperties.class);
final File methodFileFolder = new File(learnPropertyFile.getParentFile(), "methods");
try (BufferedWriter csvWriter = new BufferedWriter(new FileWriter(new File(project + ".csv")))) {
for (final Entry<String, ChangeProperties> version : changes.getVersions().entrySet()) {
final File versionFolder = new File(methodFileFolder, version.getKey());
for (final Entry<String, List<ChangeProperty>> testcase : version.getValue().getProperties().entrySet()) {
for (final ChangeProperty property : testcase.getValue()) {
final VersionClass versionClass = learn.getVersions().get(version.getKey());
final ChangedEntity entity = new ChangedEntity(testcase.getKey(), "", property.getMethod());
final TestcaseClass testcaseClass = versionClass.getTestcases().get(entity);
final GuessDecider guesser = new GuessDecider(versionFolder);
final Set<String> types = testcaseClass.getTypes();
writeFeatures(allFeatures, csvWriter, property, guesser);
writeType(csvWriter, types);
csvWriter.write("\n");
csvWriter.flush();
}
}
}
}
}
use of de.dagere.peass.analysis.properties.VersionChangeProperties in project peass by DaGeRe.
the class ClassifyByRules method getAllWords.
private void getAllWords(final Classification learn, final VersionChangeProperties changes, final File methodFileFolder, final Set<String> allFeatures) throws IOException {
for (final Entry<String, ChangeProperties> version : changes.getVersions().entrySet()) {
final File versionFolder = new File(methodFileFolder, version.getKey());
for (final Entry<String, List<ChangeProperty>> testcase : version.getValue().getProperties().entrySet()) {
for (final ChangeProperty property : testcase.getValue()) {
final GuessDecider guesser = new GuessDecider(versionFolder);
for (final String method : property.getAffectedMethods()) {
final Patch<String> diff = guesser.getDiff(method);
final List<String> features = getOriginalFeatures(diff);
final List<String> featuresRevised = getRevisedFeatures(diff);
allFeatures.addAll(features);
allFeatures.addAll(featuresRevised);
// indexBuilder.addDocument("doc_" + index++, features.toArray(new String[0]), categoryNames);
}
}
}
}
}
use of de.dagere.peass.analysis.properties.VersionChangeProperties in project peass by DaGeRe.
the class ClassifyByRules method getAllFeatures.
private Set<String> getAllFeatures() throws IOException, JsonParseException, JsonMappingException {
final Set<String> allFeatures = new HashSet<>();
for (final String project : new String[] { learnproject, classifyproject }) {
final RepoFolders repos = new RepoFolders();
final File learnFile = new File(repos.getClassificationFolder(), project + ".json");
final File learnPropertyFile = repos.getProjectPropertyFile(project);
final Classification learn = Constants.OBJECTMAPPER.readValue(learnFile, Classification.class);
final VersionChangeProperties changes = Constants.OBJECTMAPPER.readValue(learnPropertyFile, VersionChangeProperties.class);
final File methodFileFolder = new File(learnPropertyFile.getParentFile(), "methods");
getAllWords(learn, changes, methodFileFolder, allFeatures);
}
return allFeatures;
}
use of de.dagere.peass.analysis.properties.VersionChangeProperties in project peass by DaGeRe.
the class ExperimentSelector method selectForProject.
private void selectForProject(final File currentPropertyFile, final File currentChangeFile) throws IOException, JsonParseException, JsonMappingException, FileNotFoundException {
final RepoFolders repoFolders = new RepoFolders();
final VersionChangeProperties properties = Constants.OBJECTMAPPER.readValue(currentPropertyFile, VersionChangeProperties.class);
final ProjectChanges changes;
if (currentChangeFile != null && currentChangeFile.exists()) {
changes = Constants.OBJECTMAPPER.readValue(currentChangeFile, ProjectChanges.class);
} else {
changes = null;
}
final String projectName = currentChangeFile != null ? currentChangeFile.getName().replace(".json", "") : currentPropertyFile.getParentFile().getName();
final File fileSlurm = new File(repoFolders.getRCAScriptFolder(), "rca-slurm-" + projectName + ".sh");
final File fileJava = new File(repoFolders.getRCAScriptFolder(), "rca-java-" + projectName + ".sh");
final ExecutionData executionData = repoFolders.getExecutionData(projectName);
final RunCommandWriter writerSlurm = new RunCommandWriterSlurm(new PrintStream(fileSlurm), "cause1", executionData, RunCommandWriterSlurm.EXECUTE_RCA);
final RunCommandWriter writer = new RunCommandWriterRCA(new PrintStream(fileJava), "cause1", executionData);
properties.executeProcessor((version, testcase, change, changeProperties) -> {
all++;
});
if (changes != null) {
changes.executeProcessor((version, testcase, change) -> {
measurementAll++;
});
} else {
printOnlyChanged = false;
}
writeExecutions(properties, changes, writerSlurm, writer);
System.out.println("All: " + executionData.getAllExecutions());
System.out.println("All: " + all + " No testchange: " + noTestchange + " Measurement change: " + measurementChange + " All: " + measurementAll);
}
use of de.dagere.peass.analysis.properties.VersionChangeProperties in project peass by DaGeRe.
the class ReadProperties method readChangeProperties.
public void readChangeProperties(final File changefile, final File projectFolder, final File viewFolder, final ExecutionData changedTests) throws IOException, JsonParseException, JsonMappingException, JsonGenerationException {
final File resultCSV = new File(out.getParentFile(), projectFolder.getName() + ".csv");
try (BufferedWriter csvWriter = new BufferedWriter(new FileWriter(resultCSV))) {
writeCSVHeadline(csvWriter);
final VersionChangeProperties versionProperties = new VersionChangeProperties();
final ProjectChanges changes = Constants.OBJECTMAPPER.readValue(changefile, ProjectChanges.class);
int versionCount = 0, testcaseCount = 0;
for (final Entry<String, Changes> versionChanges : changes.getVersionChanges().entrySet()) {
final String version = versionChanges.getKey();
final TestSet tests = changedTests.getVersions().get(version);
//
final String predecessor = tests != null ? tests.getPredecessor() : version + "~1";
testcaseCount += detectVersionProperty(projectFolder, viewFolder, csvWriter, versionProperties, versionChanges, predecessor, changedTests);
if (tests == null) {
LOG.error("Version not contained in runfile: " + version);
}
versionCount++;
}
// writeOnlySource(versionProperties, ProjectChanges.getOldChanges());
System.out.println("Analyzed: " + testcaseCount + " testcases in " + versionCount + " versions");
}
}
Aggregations