Search in sources :

Example 1 with ExecutionConfig

use of de.dagere.peass.config.ExecutionConfig 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 2 with ExecutionConfig

use of de.dagere.peass.config.ExecutionConfig 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)

Example 3 with ExecutionConfig

use of de.dagere.peass.config.ExecutionConfig in project peass by DaGeRe.

the class PropertyChangeGuesser method getGuesses.

public Set<String> getGuesses(final PeassFolders folders, final Entry<ChangedEntity, ClazzChangeData> changedEntity) throws FileNotFoundException {
    final Set<String> guessedTypes = new HashSet<>();
    // TODO Here, a real config should be passed; since this is rarely used, we go with the default folders
    ClazzFileFinder finder = new ClazzFileFinder(new ExecutionConfig());
    final File file = finder.getSourceFile(folders.getProjectFolder(), changedEntity.getKey());
    final File fileOld = finder.getSourceFile(folders.getOldSources(), changedEntity.getKey());
    if (file != null && fileOld != null && file.exists() && fileOld.exists()) {
        final CompilationUnit clazzUnit = JavaParserProvider.parse(file);
        final CompilationUnit clazzUnitOld = JavaParserProvider.parse(fileOld);
        for (Map.Entry<String, Set<String>> changedClazz : changedEntity.getValue().getChangedMethods().entrySet()) {
            // If only method change..
            if (changedClazz.getValue() != null) {
                for (String method : changedClazz.getValue()) {
                    final String source = FileComparisonUtil.getMethodSource(changedEntity.getKey(), method, clazzUnit);
                    final String sourceOld = FileComparisonUtil.getMethodSource(changedEntity.getKey(), method, clazzUnitOld);
                    final Patch<String> changedLinesMethod = DiffUtils.diff(Arrays.asList(sourceOld.split("\n")), Arrays.asList(source.split("\n")));
                    for (final Delta<String> delta : changedLinesMethod.getDeltas()) {
                        getDeltaGuess(guessedTypes, (delta.getOriginal().getLines()));
                        getDeltaGuess(guessedTypes, (delta.getRevised().getLines()));
                    }
                }
            }
        }
    }
    return guessedTypes;
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Set(java.util.Set) HashSet(java.util.HashSet) ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) File(java.io.File) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with ExecutionConfig

use of de.dagere.peass.config.ExecutionConfig in project peass by DaGeRe.

the class TestClazzFileFinder method testClasses.

@Test
public void testClasses() {
    ExecutionConfig config = new ExecutionConfig();
    config.getClazzFolders().add("src/main/java");
    config.getClazzFolders().add("src/java");
    List<String> clazzes = new ClazzFileFinder(config).getClasses(SOURCE);
    System.out.println(clazzes);
    MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe1"));
    MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2"));
    MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.Second"));
    MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2$Inner"));
    MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2$Inner$InnerInner"));
    MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2$InnerEnum"));
}
Also used : ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) Test(org.junit.jupiter.api.Test)

Example 5 with ExecutionConfig

use of de.dagere.peass.config.ExecutionConfig in project peass by DaGeRe.

the class TestPeassFilter method testExecution.

@Test
public void testExecution() throws ViewNotFoundException, IOException, XmlPullParserException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Assume.assumeFalse(EnvironmentVariables.isWindows());
    PeassFolders folders = new PeassFolders(CURRENT);
    final KiekerResultManager manager = new KiekerResultManager(folders, new ExecutionConfig(5), new KiekerConfig(true), new EnvironmentVariables());
    final TestSet testset = new TestSet();
    final TestCase testcase = new TestCase("defaultpackage.TestMe", "testMe", "");
    testset.addTest(testcase);
    final ModuleClassMapping mapping = new ModuleClassMapping(manager.getExecutor());
    final List<TraceElement> referenceTrace = regenerateTrace(manager, testset, testcase, mapping, 0);
    for (int i = 1; i <= 3; i++) {
        final List<TraceElement> compareTrace = regenerateTrace(manager, testset, testcase, mapping, i);
        checkRegeneratedTrace(referenceTrace, compareTrace);
    }
}
Also used : EnvironmentVariables(de.dagere.peass.execution.utils.EnvironmentVariables) TestCase(de.dagere.peass.dependency.analysis.data.TestCase) ModuleClassMapping(de.dagere.peass.dependency.analysis.ModuleClassMapping) TraceElement(de.dagere.peass.dependency.analysis.data.TraceElement) KiekerResultManager(de.dagere.peass.dependency.KiekerResultManager) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) KiekerConfig(de.dagere.peass.config.KiekerConfig) PeassFolders(de.dagere.peass.folders.PeassFolders) TestSet(de.dagere.peass.dependency.analysis.data.TestSet) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionConfig (de.dagere.peass.config.ExecutionConfig)72 Test (org.junit.jupiter.api.Test)48 File (java.io.File)39 PeassFolders (de.dagere.peass.folders.PeassFolders)28 KiekerConfig (de.dagere.peass.config.KiekerConfig)21 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)21 EnvironmentVariables (de.dagere.peass.execution.utils.EnvironmentVariables)20 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)14 StaticTestSelection (de.dagere.peass.dependency.persistence.StaticTestSelection)14 FakeFileIterator (de.dagere.peass.dependencytests.helper.FakeFileIterator)13 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)12 ProjectModules (de.dagere.peass.execution.utils.ProjectModules)12 DependencyReader (de.dagere.peass.dependency.reader.DependencyReader)11 VersionIteratorGit (de.dagere.peass.vcs.VersionIteratorGit)11 GitUtils (de.dagere.peass.vcs.GitUtils)10 ResultsFolders (de.dagere.peass.folders.ResultsFolders)8 ModuleClassMapping (de.dagere.peass.dependency.analysis.ModuleClassMapping)7 VersionIterator (de.dagere.peass.vcs.VersionIterator)7 HashSet (java.util.HashSet)7 ChangeManager (de.dagere.peass.dependency.ChangeManager)6