Search in sources :

Example 1 with ChangeProperty

use of de.dagere.peass.analysis.properties.ChangeProperty 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 ChangeProperty

use of de.dagere.peass.analysis.properties.ChangeProperty 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 ChangeProperty

use of de.dagere.peass.analysis.properties.ChangeProperty in project peass by DaGeRe.

the class ReadProperties method detectVersionProperty.

private int detectVersionProperty(final File projectFolder, final File viewFolder, final BufferedWriter csvWriter, final VersionChangeProperties versionProperties, final Entry<String, Changes> versionChanges, final String predecessor, final ExecutionData data) throws IOException, JsonGenerationException, JsonMappingException {
    final File methodFolder = new File(out.getParentFile(), "methods");
    methodFolder.mkdirs();
    final String version = versionChanges.getKey();
    final ChangeProperties changeProperties = new ChangeProperties();
    changeProperties.setCommitText(GitUtils.getCommitText(projectFolder, version));
    changeProperties.setCommitter(GitUtils.getCommitter(projectFolder, version));
    versionProperties.getVersions().put(version, changeProperties);
    int count = 0;
    for (final Entry<String, List<Change>> changes : versionChanges.getValue().getTestcaseChanges().entrySet()) {
        final String testclazz = changes.getKey();
        String module = null;
        for (TestCase test : data.getVersions().get(versionChanges.getKey()).getTests()) {
            if (test.getClazz().equals(testclazz)) {
                module = test.getModule();
            }
        }
        final List<ChangeProperty> properties = new LinkedList<>();
        changeProperties.getProperties().put(testclazz, properties);
        for (final Change testcaseChange : changes.getValue()) {
            ExecutionConfig config = new ExecutionConfig();
            config.setVersion(version);
            config.setVersionOld(predecessor);
            ChangedEntity entity = new ChangedEntity(testclazz, module);
            final PropertyReadHelper reader = new PropertyReadHelper(config, entity, testcaseChange, projectFolder, viewFolder, methodFolder, null);
            final ChangeProperty currentProperty = reader.read();
            // if (currentProperty != null) {
            properties.add(currentProperty);
            Constants.OBJECTMAPPER.writeValue(out, versionProperties);
            writeCSVLine(csvWriter, currentProperty, projectFolder.getName());
            // }
            count++;
        }
    }
    return count;
}
Also used : PropertyReadHelper(de.dagere.peass.analysis.properties.PropertyReadHelper) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) Change(de.dagere.peass.analysis.changes.Change) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) LinkedList(java.util.LinkedList) TestCase(de.dagere.peass.dependency.analysis.data.TestCase) 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)

Example 4 with ChangeProperty

use of de.dagere.peass.analysis.properties.ChangeProperty in project peass by DaGeRe.

the class ReadProperties method readVersionProperties.

public static VersionChangeProperties readVersionProperties(final ProjectChanges knowledge, final File versionFile) {
    final VersionChangeProperties versionProperties = new VersionChangeProperties();
    try {
        final VersionChangeProperties allProperties = Constants.OBJECTMAPPER.readValue(versionFile, VersionChangeProperties.class);
        for (final Entry<String, Changes> versionChanges : knowledge.getVersionChanges().entrySet()) {
            final String version = versionChanges.getKey();
            final ChangeProperties allProps = allProperties.getVersions().get(version);
            if (allProps != null) {
                final ChangeProperties changeProperties = new ChangeProperties();
                changeProperties.setCommitText(allProps.getCommitText());
                changeProperties.setCommitter(allProps.getCommitText());
                versionProperties.getVersions().put(version, changeProperties);
                for (final Entry<String, List<Change>> changes : versionChanges.getValue().getTestcaseChanges().entrySet()) {
                    final String testclazz = changes.getKey();
                    final List<ChangeProperty> properties = new LinkedList<>();
                    final List<ChangeProperty> oldTestcaseProperties = allProps.getProperties().get(changes.getKey());
                    if (oldTestcaseProperties != null) {
                        changeProperties.getProperties().put(testclazz, properties);
                        for (final Change change : changes.getValue()) {
                            for (final ChangeProperty prop : oldTestcaseProperties) {
                                if (prop.getMethod().equals(change.getMethod())) {
                                    properties.add(prop);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return versionProperties;
}
Also used : ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) Changes(de.dagere.peass.analysis.changes.Changes) 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) Change(de.dagere.peass.analysis.changes.Change) IOException(java.io.IOException) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList)

Example 5 with ChangeProperty

use of de.dagere.peass.analysis.properties.ChangeProperty in project peass by DaGeRe.

the class CreateOverviewStatistics method main.

public static void main(final String[] args) throws JAXBException, JsonParseException, JsonMappingException, IOException {
    File dependencyFolder;
    final File repos;
    if (System.getenv(Constants.PEASS_REPOS) != null) {
        final String repofolder = System.getenv(Constants.PEASS_REPOS);
        repos = new File(repofolder);
        dependencyFolder = new File(repos, "dependencies-final");
    } else {
        throw new RuntimeException("Please define environment variable " + Constants.PEASS_REPOS);
    }
    final File propertyFolder = new File(repos, "properties/properties");
    final File changeFolder = new File(repos, "measurementdata/results");
    final File projectsFolder = new File("../../projekte");
    final DescriptiveStatistics[] stats = new DescriptiveStatistics[9];
    for (int i = 0; i < 9; i++) {
        stats[i] = new DescriptiveStatistics();
    }
    // "commons-imaging", "commons-io", "commons-numbers", "commons-pool", "commons-text", "httpcomponents-core", "k-9" }) {
    for (final String project : new String[] { "commons-csv", "commons-dbcp", "commons-fileupload", "commons-jcs", "commons-imaging", "commons-io", "commons-numbers", "commons-pool", "commons-text" }) {
        System.out.print(project + " & ");
        final int versions = GitUtils.getVersions(new File(projectsFolder, project));
        System.out.print(versions + " & ");
        stats[0].addValue(versions);
        final File executionFile = new File(dependencyFolder, ResultsFolders.TRACE_SELECTION_PREFIX + project + ".json");
        if (executionFile.exists()) {
            final ExecutionData changedTests = Constants.OBJECTMAPPER.readValue(executionFile, ExecutionData.class);
            System.out.print(changedTests.getVersions().size() + " & ");
            stats[1].addValue(changedTests.getVersions().size());
            int tests = 0;
            for (final TestSet testSet : changedTests.getVersions().values()) {
                tests += testSet.getTests().size();
            }
            System.out.print(tests + " & ");
            stats[2].addValue(tests);
            int changes = 0;
            int sourceChanges = 0;
            int sourceTests = 0;
            final File potentialChangeFolder = new File(changeFolder, project);
            if (potentialChangeFolder.exists()) {
                final File changefile = new File(potentialChangeFolder, project + ".json");
                final ProjectChanges measuredChanges = Constants.OBJECTMAPPER.readValue(changefile, ProjectChanges.class);
                changes = measuredChanges.getChangeCount();
                final File changefileOnlysource = new File(propertyFolder, project + "/" + project + ".json");
                if (changefileOnlysource.exists()) {
                    final VersionChangeProperties measuredChangesOnlysource = Constants.OBJECTMAPPER.readValue(changefileOnlysource, VersionChangeProperties.class);
                    for (final ChangeProperties changesAll : measuredChangesOnlysource.getVersions().values()) {
                        for (final List<ChangeProperty> method : changesAll.getProperties().values()) {
                            for (final ChangeProperty nowMetho : method) {
                                if (nowMetho.isAffectsSource()) {
                                    sourceChanges++;
                                }
                            }
                        }
                    }
                // sourceChanges = measuredChangesOnlysource.getChangeCount();
                }
            }
            final File allTestProps = new File(propertyFolder, project + "/" + project + "_all.json");
            if (allTestProps.exists()) {
                final VersionChangeProperties properties = Constants.OBJECTMAPPER.readValue(allTestProps, VersionChangeProperties.class);
                sourceTests = properties.getSourceChanges();
            }
            // System.out.print(sourceTests + " & ");
            // stats[3].addValue(sourceTests);
            System.out.print(changes + " & ");
            stats[4].addValue(changes);
            System.out.print(sourceChanges + " & ");
            stats[5].addValue(sourceChanges);
            final File changeTestProperties = new File(propertyFolder, project + File.separator + project + ".json");
            if (changeTestProperties.exists()) {
                final VersionChangeProperties versionProperties = Constants.OBJECTMAPPER.readValue(changeTestProperties, VersionChangeProperties.class);
                final ProjectStatistics projectStatistics = new ProjectStatistics();
                versionProperties.executeProcessor(projectStatistics);
                System.out.print(new DecimalFormat("##.##").format(projectStatistics.affectedLines.getMean()) + " & ");
                stats[6].addValue(projectStatistics.affectedLines.getMean());
                System.out.print(new DecimalFormat("##.##").format(projectStatistics.calls.getMean()) + " & ");
                stats[7].addValue(projectStatistics.calls.getMean());
                final double durationMeanChange = projectStatistics.changes.getMean();
                System.out.print(new DecimalFormat("##.##").format(durationMeanChange) + " \\% ");
                stats[8].addValue(durationMeanChange);
            }
        }
        System.out.print(" \\\\");
        System.out.println();
    }
    System.out.println("\\hline");
    System.out.print(" & ");
    for (int i = 0; i < 9; i++) {
        System.out.print(new DecimalFormat("##.##").format(stats[i].getMean()) + " & ");
    }
    System.out.println();
    for (int i = 0; i < 9; i++) {
        System.out.print(stats[i].getSum() + " & ");
    }
    System.out.println();
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) DecimalFormat(java.text.DecimalFormat) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) ExecutionData(de.dagere.peass.dependency.persistence.ExecutionData) ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) File(java.io.File) TestSet(de.dagere.peass.dependency.analysis.data.TestSet)

Aggregations

ChangeProperty (de.dagere.peass.analysis.properties.ChangeProperty)10 File (java.io.File)6 ChangeProperties (de.dagere.peass.analysis.properties.ChangeProperties)5 VersionChangeProperties (de.dagere.peass.analysis.properties.VersionChangeProperties)5 List (java.util.List)5 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)4 LinkedList (java.util.LinkedList)4 Change (de.dagere.peass.analysis.changes.Change)3 GuessDecider (de.dagere.peass.analysis.guessing.GuessDecider)3 Test (org.junit.Test)3 ProjectChanges (de.dagere.peass.analysis.changes.ProjectChanges)2 TestcaseClass (de.dagere.peass.analysis.groups.TestcaseClass)2 VersionClass (de.dagere.peass.analysis.groups.VersionClass)2 PropertyReadHelper (de.dagere.peass.analysis.properties.PropertyReadHelper)2 ExecutionConfig (de.dagere.peass.config.ExecutionConfig)2 RepoFolders (de.dagere.peass.analysis.all.RepoFolders)1 Changes (de.dagere.peass.analysis.changes.Changes)1 Classification (de.dagere.peass.analysis.groups.Classification)1 Guess (de.dagere.peass.analysis.guessing.Guess)1 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)1