Search in sources :

Example 1 with VersionChangeProperties

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();
                }
            }
        }
    }
}
Also used : VersionClass(de.dagere.peass.analysis.groups.VersionClass) FileWriter(java.io.FileWriter) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) BufferedWriter(java.io.BufferedWriter) Classification(de.dagere.peass.analysis.groups.Classification) ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File) GuessDecider(de.dagere.peass.analysis.guessing.GuessDecider) RepoFolders(de.dagere.peass.analysis.all.RepoFolders) TestcaseClass(de.dagere.peass.analysis.groups.TestcaseClass)

Example 2 with VersionChangeProperties

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);
                }
            }
        }
    }
}
Also used : ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList) List(java.util.List) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) File(java.io.File) GuessDecider(de.dagere.peass.analysis.guessing.GuessDecider)

Example 3 with VersionChangeProperties

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;
}
Also used : Classification(de.dagere.peass.analysis.groups.Classification) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) File(java.io.File) HashSet(java.util.HashSet) RepoFolders(de.dagere.peass.analysis.all.RepoFolders)

Example 4 with VersionChangeProperties

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);
}
Also used : PrintStream(java.io.PrintStream) ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) RunCommandWriterSlurm(de.dagere.peass.measurement.utils.RunCommandWriterSlurm) RunCommandWriterRCA(de.dagere.peass.measurement.utils.RunCommandWriterRCA) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) RunCommandWriter(de.dagere.peass.measurement.utils.RunCommandWriter) File(java.io.File) RepoFolders(de.dagere.peass.analysis.all.RepoFolders) ExecutionData(de.dagere.peass.dependency.persistence.ExecutionData)

Example 5 with VersionChangeProperties

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");
    }
}
Also used : ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) Changes(de.dagere.peass.analysis.changes.Changes) FileWriter(java.io.FileWriter) ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) File(java.io.File) BufferedWriter(java.io.BufferedWriter) TestSet(de.dagere.peass.dependency.analysis.data.TestSet)

Aggregations

VersionChangeProperties (de.dagere.peass.analysis.properties.VersionChangeProperties)11 File (java.io.File)10 ProjectChanges (de.dagere.peass.analysis.changes.ProjectChanges)6 ChangeProperties (de.dagere.peass.analysis.properties.ChangeProperties)6 RepoFolders (de.dagere.peass.analysis.all.RepoFolders)5 ChangeProperty (de.dagere.peass.analysis.properties.ChangeProperty)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Classification (de.dagere.peass.analysis.groups.Classification)3 Change (de.dagere.peass.analysis.changes.Change)2 Changes (de.dagere.peass.analysis.changes.Changes)2 GuessDecider (de.dagere.peass.analysis.guessing.GuessDecider)2 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)2 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)2 ExecutionData (de.dagere.peass.dependency.persistence.ExecutionData)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 ChangeReader (de.dagere.peass.analysis.changes.ChangeReader)1 TestcaseClass (de.dagere.peass.analysis.groups.TestcaseClass)1