Search in sources :

Example 1 with Change

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

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

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

the class GetChangeClasses method main.

public static void main(final String[] args) throws JsonParseException, JsonMappingException, IOException {
    final File f = new File("results/merged.json");
    final ProjectChanges knowledge = Constants.OBJECTMAPPER.readValue(f, ProjectChanges.class);
    final Map<String, DescriptiveStatistics> clazzes = new HashMap<>();
    for (final Changes changes : knowledge.getVersionChanges().values()) {
        for (final List<Change> change : changes.getTestcaseChanges().values()) {
            for (final Change c : change) {
            // if (c.getCorrectness() != null && c.getCorrectness().equals("CORRECT")) {
            // for (String type : c.getType()) {
            // if (type.equals("FUNCTION") || type.equals("BUGFIX") || type.equals("FEATURE")) {
            // type = "FUNCTIONALITY";
            // }
            // if (type.equals("JUNIT")) {
            // type = "LIB";
            // }
            // DescriptiveStatistics clazz = clazzes.get(type);
            // if (clazz == null) {
            // clazz = new DescriptiveStatistics();
            // clazzes.put(type, clazz);
            // }
            // clazz.addValue(c.getChangePercent());
            // }
            // 
            // }
            }
        }
    }
    for (final Map.Entry<String, DescriptiveStatistics> clazz : clazzes.entrySet()) {
        System.out.println(clazz.getKey() + " " + clazz.getValue().getMean());
    }
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) HashMap(java.util.HashMap) Change(de.dagere.peass.analysis.changes.Change) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Change

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

the class TestPropertyReadHelper method testNullVersion.

@Test
public void testNullVersion() throws IOException {
    Change changeMock = Mockito.mock(Change.class);
    Mockito.when(changeMock.getMethod()).thenReturn("myTestMethod");
    ExecutionConfig config = new ExecutionConfig();
    config.setVersion("000001");
    File projectFolder = new File("target/current");
    Files.touch(new File(projectFolder, "pom.xml"));
    PropertyReadHelper helper = new PropertyReadHelper(config, new ChangedEntity("Test"), changeMock, projectFolder, null, null, null);
    ChangeProperty emptyProperty = helper.read();
    MatcherAssert.assertThat(emptyProperty, IsNull.notNullValue());
    Assert.assertEquals("myTestMethod", emptyProperty.getMethod());
}
Also used : PropertyReadHelper(de.dagere.peass.analysis.properties.PropertyReadHelper) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) Change(de.dagere.peass.analysis.changes.Change) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with Change

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

the class TestChangeReader method testBasicUsage.

@Test
public void testBasicUsage() throws JAXBException, JsonProcessingException {
    ChangeReader reader = new ChangeReader("android-example-correct", new ExecutionData());
    ProjectChanges changes = reader.readFile(TestAnalyseFullData.REGULAR_DATA_FOLDER.getParentFile());
    System.out.println(Constants.OBJECTMAPPER.writeValueAsString(changes));
    List<Change> methodChanges = changes.getVersionChanges().get("946e4318267b56838aa35da0a2a4e5c0528bfe04").getTestcaseChanges().get("com.example.android_example.ExampleUnitTest");
    Assert.assertEquals(1, methodChanges.size());
    Assert.assertEquals("test_TestMe", methodChanges.get(0).getMethod());
    Assert.assertEquals(15087.66, methodChanges.get(0).getOldTime(), 0.1);
}
Also used : ProjectChanges(de.dagere.peass.analysis.changes.ProjectChanges) ChangeReader(de.dagere.peass.analysis.changes.ChangeReader) Change(de.dagere.peass.analysis.changes.Change) ExecutionData(de.dagere.peass.dependency.persistence.ExecutionData) Test(org.junit.jupiter.api.Test)

Aggregations

Change (de.dagere.peass.analysis.changes.Change)17 ProjectChanges (de.dagere.peass.analysis.changes.ProjectChanges)9 File (java.io.File)9 List (java.util.List)6 Changes (de.dagere.peass.analysis.changes.Changes)5 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)5 ExecutionConfig (de.dagere.peass.config.ExecutionConfig)4 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)4 ChangeProperty (de.dagere.peass.analysis.properties.ChangeProperty)3 LinkedList (java.util.LinkedList)3 Test (org.junit.jupiter.api.Test)3 ChangeReader (de.dagere.peass.analysis.changes.ChangeReader)2 ChangeProperties (de.dagere.peass.analysis.properties.ChangeProperties)2 PropertyReadHelper (de.dagere.peass.analysis.properties.PropertyReadHelper)2 VersionChangeProperties (de.dagere.peass.analysis.properties.VersionChangeProperties)2 ExecutionData (de.dagere.peass.dependency.persistence.ExecutionData)2 IOException (java.io.IOException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1