Search in sources :

Example 1 with ProjectChanges

use of de.dagere.peass.analysis.changes.ProjectChanges 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 2 with ProjectChanges

use of de.dagere.peass.analysis.changes.ProjectChanges 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)

Example 3 with ProjectChanges

use of de.dagere.peass.analysis.changes.ProjectChanges 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 4 with ProjectChanges

use of de.dagere.peass.analysis.changes.ProjectChanges 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)

Example 5 with ProjectChanges

use of de.dagere.peass.analysis.changes.ProjectChanges in project peass by DaGeRe.

the class CreateClassificationData method main.

public static void main(final String[] args) throws JsonParseException, JsonMappingException, IOException {
    RepoFolders folders = new RepoFolders();
    String project = args[0];
    File goalFile = new File(folders.getClassificationFolder(), project + ".json");
    File propertyFile = folders.getProjectPropertyFile(project);
    if (propertyFile.exists()) {
        final VersionChangeProperties properties = Constants.OBJECTMAPPER.readValue(propertyFile, VersionChangeProperties.class);
        createClassificationData(properties, goalFile, project);
    } else {
        File changeFile = new File(folders.getResultsFolder(), project + File.separator + project + ".json");
        if (!changeFile.exists()) {
            changeFile = new File(folders.getResultsFolder(), project + ".json");
        }
        if (changeFile.exists()) {
            final ProjectChanges changes = Constants.OBJECTMAPPER.readValue(changeFile, ProjectChanges.class);
            createClassificationData(changes, goalFile, project);
        } else {
            LOG.error("Can not write classification data, both change file and property file are not defined!");
        }
    }
}
Also used : ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) File(java.io.File) RepoFolders(de.dagere.peass.analysis.all.RepoFolders)

Aggregations

ProjectChanges (de.dagere.peass.analysis.changes.ProjectChanges)15 File (java.io.File)10 VersionChangeProperties (de.dagere.peass.analysis.properties.VersionChangeProperties)6 Change (de.dagere.peass.analysis.changes.Change)5 ExecutionData (de.dagere.peass.dependency.persistence.ExecutionData)4 LinkedList (java.util.LinkedList)4 RepoFolders (de.dagere.peass.analysis.all.RepoFolders)3 ChangeReader (de.dagere.peass.analysis.changes.ChangeReader)3 Changes (de.dagere.peass.analysis.changes.Changes)3 ChangeProperties (de.dagere.peass.analysis.properties.ChangeProperties)2 ChangeProperty (de.dagere.peass.analysis.properties.ChangeProperty)2 StatisticsConfig (de.dagere.peass.config.StatisticsConfig)2 ModuleClassMapping (de.dagere.peass.dependency.analysis.ModuleClassMapping)2 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)2 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)2 GitCommit (de.dagere.peass.vcs.GitCommit)2 IOException (java.io.IOException)2 ZipFile (net.lingala.zip4j.ZipFile)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2