Search in sources :

Example 6 with ClazzFileFinder

use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.

the class TestExecutor method loadClasses.

public void loadClasses() {
    existingClasses = new LinkedList<>();
    for (final File module : getModules().getModules()) {
        ExecutionConfig executionConfig = testTransformer.getConfig().getExecutionConfig();
        ClazzFileFinder finder = new ClazzFileFinder(executionConfig);
        final List<String> currentClasses = finder.getClasses(module);
        existingClasses.addAll(currentClasses);
    }
}
Also used : ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) File(java.io.File)

Example 7 with ClazzFileFinder

use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.

the class JmhTestTransformer method getTestMethodNames.

@Override
public List<TestCase> getTestMethodNames(final File module, final TestCase clazzname) {
    final List<TestCase> methods = new LinkedList<>();
    ClazzFileFinder finder = new ClazzFileFinder(measurementConfig.getExecutionConfig());
    final File clazzFile = finder.getClazzFile(module, clazzname);
    try {
        // File might be removed or moved
        if (clazzFile != null) {
            LOG.debug("Parsing {} - {}", clazzFile, clazzname);
            final CompilationUnit unit = JavaParserProvider.parse(clazzFile);
            List<ClassOrInterfaceDeclaration> clazzDeclarations = ClazzFinder.getClazzDeclarations(unit);
            for (ClassOrInterfaceDeclaration clazz : clazzDeclarations) {
                String parsedClassName = getFullName(clazz);
                LOG.trace("Clazz: {} - {}", parsedClassName, clazzname.getShortClazz());
                if (parsedClassName.equals(clazzname.getShortClazz())) {
                    List<String> benchmarkMethods = JUnitParseUtil.getAnnotatedMethods(clazz, "org.openjdk.jmh.annotations.Benchmark", "Benchmark");
                    for (String benchmarkMethod : benchmarkMethods) {
                        TestCase foundBenchmark = new TestCase(clazzname.getClazz(), benchmarkMethod, clazzname.getModule());
                        methods.add(foundBenchmark);
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }
    return methods;
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) TestCase(de.dagere.peass.dependency.analysis.data.TestCase) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) LinkedList(java.util.LinkedList)

Example 8 with ClazzFileFinder

use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.

the class JmhTestTransformer method findModuleTests.

public TestSet findModuleTests(final ModuleClassMapping mapping, final List<String> includedModules, final File module) throws FileNotFoundException {
    TestSet moduleTests = new TestSet();
    ClazzFileFinder finder = new ClazzFileFinder(measurementConfig.getExecutionConfig());
    for (final String clazz : finder.getClasses(module)) {
        String currentModule = ModuleClassMapping.getModuleName(projectFolder, module);
        final List<TestCase> testMethodNames = getTestMethodNames(module, new TestCase(clazz, null, currentModule));
        for (TestCase test : testMethodNames) {
            if (includedModules == null || includedModules.contains(test.getModule())) {
                addTestIfIncluded(moduleTests, test);
            }
        }
    }
    return moduleTests;
}
Also used : TestCase(de.dagere.peass.dependency.analysis.data.TestCase) ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) TestSet(de.dagere.peass.dependency.analysis.data.TestSet)

Example 9 with ClazzFileFinder

use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.

the class FileComparisonUtil method getMethodSource.

public static String getMethodSource(final File projectFolder, final ChangedEntity entity, final String method, final ExecutionConfig config) throws FileNotFoundException {
    ClazzFileFinder finder = new ClazzFileFinder(config);
    final File file = finder.getSourceFile(projectFolder, entity);
    if (file != null) {
        LOG.debug("Found:  {} {}", file, file.exists());
        final CompilationUnit cu = JavaParserProvider.parse(file);
        return getMethodSource(entity, method, cu);
    } else {
        return "";
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) File(java.io.File)

Example 10 with ClazzFileFinder

use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.

the class JUnitTestShortener method shortenTest.

private void shortenTest() {
    if (!lastShortenedMap.isEmpty()) {
        throw new RuntimeException("Only use TestShortener once!");
    }
    ClazzFileFinder finder = new ClazzFileFinder(transformer.getConfig().getExecutionConfig());
    final File calleeClazzFile = finder.getClazzFile(module, callee);
    if (calleeClazzFile != null) {
        try {
            shortenTestClazz(callee, calleeClazzFile);
            for (final File superclass : superclasses) {
                if (!lastShortenedMap.containsValue(superclass)) {
                    // A rather dirty hack..
                    final ChangedEntity callee = new ChangedEntity(superclass.getName().replaceAll(".java", ""), this.callee.getModule());
                    LOG.debug("Shortening: " + callee);
                    shortenTestClazz(callee, superclass);
                }
            }
        } catch (final IOException e1) {
            e1.printStackTrace();
        }
    } else {
        throw new RuntimeException("Could not find " + callee.getModule() + " " + callee.getClazz() + " java file in " + module + " - maybe package missing?");
    }
}
Also used : ClazzFileFinder(de.dagere.peass.dependency.ClazzFileFinder) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) IOException(java.io.IOException) File(java.io.File)

Aggregations

ClazzFileFinder (de.dagere.peass.dependency.ClazzFileFinder)11 File (java.io.File)8 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4 ExecutionConfig (de.dagere.peass.config.ExecutionConfig)4 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)2 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)2 LinkedList (java.util.LinkedList)2 Test (org.junit.jupiter.api.Test)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1