Search in sources :

Example 1 with RepoFolders

use of de.dagere.peass.analysis.all.RepoFolders 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 RepoFolders

use of de.dagere.peass.analysis.all.RepoFolders 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 3 with RepoFolders

use of de.dagere.peass.analysis.all.RepoFolders in project peass by DaGeRe.

the class ExperimentSelector method call.

@Override
public Integer call() throws Exception {
    if (propertyFile == null) {
        final RepoFolders repoFolders = new RepoFolders();
        final File propertiesFolder = new File(repoFolders.getPropertiesFolder(), "properties");
        for (final File projectFile : propertiesFolder.listFiles()) {
            LOG.info("Searching in {}", projectFile);
            final File currentPropertyFile = projectFile.listFiles((FilenameFilter) new WildcardFileFilter("*.json"))[0];
            selectForProject(currentPropertyFile, null);
        }
    } else {
        selectForProject(propertyFile, changesFile);
    }
    return 0;
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) RepoFolders(de.dagere.peass.analysis.all.RepoFolders)

Example 4 with RepoFolders

use of de.dagere.peass.analysis.all.RepoFolders 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 RepoFolders

use of de.dagere.peass.analysis.all.RepoFolders in project peass by DaGeRe.

the class ReadProperties method call.

@Override
public Void call() throws Exception {
    final RepoFolders folders = new RepoFolders();
    final String projectName = projectFolder.getName();
    SelectedTests selectedTests = VersionSorter.getSelectedTests(staticSelectionFile, executionFile, folders.getDependencyFile(projectName));
    if (!projectFolder.exists()) {
        GitUtils.downloadProject(selectedTests.getUrl(), projectFolder);
    }
    System.out.println("Read all: " + ReadAllProperties.readAll);
    if (ReadAllProperties.readAll) {
        final ExecutionData changedTests = executionFile != null ? Constants.OBJECTMAPPER.readValue(executionFile, ExecutionData.class) : folders.getExecutionData(projectName);
        final File resultFile = new File("results" + File.separator + projectName + File.separator + "properties_alltests.json");
        out = resultFile;
        ResultsFolders resultsFolders = new ResultsFolders(out, projectName);
        final PropertyReader reader = new PropertyReader(resultsFolders, projectFolder, changedTests, new ExecutionConfig());
        reader.readAllTestsProperties();
    } else {
        final File changefile;
        if (this.changefile != null) {
            changefile = this.changefile;
        } else {
            changefile = folders.getChangeFile(projectName);
        }
        if (out == null) {
            out = folders.getProjectPropertyFile(projectName);
            if (!out.getParentFile().exists()) {
                out.getParentFile().mkdirs();
            }
        }
        if (!changefile.exists()) {
            LOG.error("Changefile {} needs to exist.", changefile);
            System.exit(1);
        }
        if (!viewfolder.exists()) {
            LOG.error("ViewFolder {} needs to exist.", viewfolder);
            System.exit(1);
        }
        StaticTestSelection dependencies = Constants.OBJECTMAPPER.readValue(staticSelectionFile, StaticTestSelection.class);
        readChangeProperties(changefile, projectFolder, viewfolder, new ExecutionData(dependencies));
    }
    return null;
}
Also used : SelectedTests(de.dagere.peass.dependency.persistence.SelectedTests) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) ResultsFolders(de.dagere.peass.folders.ResultsFolders) PropertyReader(de.dagere.peass.analysis.properties.PropertyReader) File(java.io.File) RepoFolders(de.dagere.peass.analysis.all.RepoFolders) ExecutionData(de.dagere.peass.dependency.persistence.ExecutionData) StaticTestSelection(de.dagere.peass.dependency.persistence.StaticTestSelection)

Aggregations

RepoFolders (de.dagere.peass.analysis.all.RepoFolders)13 File (java.io.File)13 VersionChangeProperties (de.dagere.peass.analysis.properties.VersionChangeProperties)5 ExecutionData (de.dagere.peass.dependency.persistence.ExecutionData)4 ProjectChanges (de.dagere.peass.analysis.changes.ProjectChanges)3 Classification (de.dagere.peass.analysis.groups.Classification)3 ChangeProperties (de.dagere.peass.analysis.properties.ChangeProperties)2 TestcaseClass (de.dagere.peass.analysis.groups.TestcaseClass)1 VersionClass (de.dagere.peass.analysis.groups.VersionClass)1 GuessDecider (de.dagere.peass.analysis.guessing.GuessDecider)1 ChangeProperty (de.dagere.peass.analysis.properties.ChangeProperty)1 PropertyReader (de.dagere.peass.analysis.properties.PropertyReader)1 ExecutionConfig (de.dagere.peass.config.ExecutionConfig)1 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)1 SelectedTests (de.dagere.peass.dependency.persistence.SelectedTests)1 StaticTestSelection (de.dagere.peass.dependency.persistence.StaticTestSelection)1 ResultsFolders (de.dagere.peass.folders.ResultsFolders)1 RunCommandWriter (de.dagere.peass.measurement.utils.RunCommandWriter)1 RunCommandWriterRCA (de.dagere.peass.measurement.utils.RunCommandWriterRCA)1 RunCommandWriterSlurm (de.dagere.peass.measurement.utils.RunCommandWriterSlurm)1