Search in sources :

Example 1 with DependencyInformationConsumer

use of com.github.sevntu.checkstyle.module.DependencyInformationConsumer in project methods-distance by sevntu-checkstyle.

the class MainServlet method processDsm.

private void processDsm(URL sourceUrl, HttpServletResponse resp) throws CheckstyleException, IOException {
    class DsmDependencyInformationConsumer implements DependencyInformationConsumer {

        private Configuration configuration;

        @Override
        public void setConfiguration(Configuration configuration) {
            this.configuration = configuration;
        }

        @Override
        public void accept(String filePath, Dependencies dependencies) {
            try {
                final String javaSource = FileUtils.getFileContents(filePath);
                final MethodOrder methodOrder = new MethodOrder(dependencies);
                final String html = DependencyInfoMatrixSerializer.serialize(methodOrder, javaSource, configuration);
                resp.setContentType("text/html");
                resp.getWriter().append(html);
            } catch (final IOException | CheckstyleException ex) {
                throw new ResponseGenerationException(ex);
            }
        }
    }
    final Map<String, String> config = getCheckConfiguration();
    final DsmDependencyInformationConsumer consumer = new DsmDependencyInformationConsumer();
    final MethodCallDependencyCheckInvoker invoker = new MethodCallDependencyCheckInvoker(config, consumer);
    consumer.setConfiguration(invoker.getConfiguration());
    invoker.invoke(Collections.singletonList(downloadSource(sourceUrl)));
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) MethodCallDependencyCheckInvoker(com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker) Dependencies(com.github.sevntu.checkstyle.domain.Dependencies) MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) IOException(java.io.IOException) DependencyInformationConsumer(com.github.sevntu.checkstyle.module.DependencyInformationConsumer)

Example 2 with DependencyInformationConsumer

use of com.github.sevntu.checkstyle.module.DependencyInformationConsumer in project methods-distance by sevntu-checkstyle.

the class ReportCli method main.

public static void main(String... args) throws CheckstyleException {
    final DependencyInformationConsumer consumer = new ViolationReporterDependencyInformationConsumer();
    final ModuleFactory moduleFactory = new DependencyInformationConsumerInjector(consumer);
    final DefaultConfiguration moduleConfig = new DefaultConfiguration(MethodCallDependencyCheckstyleModule.class.getCanonicalName());
    moduleConfig.addAttribute("screenLinesCount", "50");
    final TreeWalker tw = new TreeWalker();
    tw.setModuleFactory(moduleFactory);
    tw.finishLocalSetup();
    tw.setupChild(moduleConfig);
    final AuditListener listener = new DefaultLogger(System.out, false);
    final Checker checker = new Checker();
    checker.setModuleFactory(moduleFactory);
    checker.addFileSetCheck(tw);
    checker.addListener(listener);
    final List<File> files = Collections.singletonList(new File(args[0]));
    checker.process(files);
}
Also used : ModuleFactory(com.puppycrawl.tools.checkstyle.ModuleFactory) Checker(com.puppycrawl.tools.checkstyle.Checker) ViolationReporterDependencyInformationConsumer(com.github.sevntu.checkstyle.module.ViolationReporterDependencyInformationConsumer) DependencyInformationConsumerInjector(com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector) TreeWalker(com.puppycrawl.tools.checkstyle.TreeWalker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) MethodCallDependencyCheckstyleModule(com.github.sevntu.checkstyle.module.MethodCallDependencyCheckstyleModule) AuditListener(com.puppycrawl.tools.checkstyle.api.AuditListener) ViolationReporterDependencyInformationConsumer(com.github.sevntu.checkstyle.module.ViolationReporterDependencyInformationConsumer) DependencyInformationConsumer(com.github.sevntu.checkstyle.module.DependencyInformationConsumer) DefaultLogger(com.puppycrawl.tools.checkstyle.DefaultLogger) File(java.io.File)

Example 3 with DependencyInformationConsumer

use of com.github.sevntu.checkstyle.module.DependencyInformationConsumer in project methods-distance by sevntu-checkstyle.

the class MainServlet method processDot.

private void processDot(URL sourceUrl, HttpServletResponse resp) throws CheckstyleException, IOException {
    final DependencyInformationConsumer consumer = (filePath, dependencies) -> {
        try {
            final String dot = DependencyInfoGraphSerializer.serializeInfo(dependencies);
            resp.setContentType("text/vnd.graphviz");
            resp.getWriter().append(dot);
        } catch (final IOException ex) {
            throw new ResponseGenerationException(ex);
        }
    };
    final Map<String, String> config = getCheckConfiguration();
    final MethodCallDependencyCheckInvoker invoker = new MethodCallDependencyCheckInvoker(config, consumer);
    invoker.invoke(Collections.singletonList(downloadSource(sourceUrl)));
}
Also used : OutputStream(java.io.OutputStream) HttpServlet(javax.servlet.http.HttpServlet) MalformedURLException(java.net.MalformedURLException) ServletException(javax.servlet.ServletException) URL(java.net.URL) HttpServletResponse(javax.servlet.http.HttpServletResponse) DependencyInfoGraphSerializer(com.github.sevntu.checkstyle.dot.DependencyInfoGraphSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils(com.github.sevntu.checkstyle.utils.FileUtils) File(java.io.File) MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) DependencyInfoMatrixSerializer(com.github.sevntu.checkstyle.dsm.DependencyInfoMatrixSerializer) HttpServletRequest(javax.servlet.http.HttpServletRequest) MethodCallDependencyCheckInvoker(com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) DependencyInformationConsumer(com.github.sevntu.checkstyle.module.DependencyInformationConsumer) URLConnection(java.net.URLConnection) Map(java.util.Map) Dependencies(com.github.sevntu.checkstyle.domain.Dependencies) Collections(java.util.Collections) InputStream(java.io.InputStream) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) MethodCallDependencyCheckInvoker(com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker) IOException(java.io.IOException) DependencyInformationConsumer(com.github.sevntu.checkstyle.module.DependencyInformationConsumer)

Aggregations

DependencyInformationConsumer (com.github.sevntu.checkstyle.module.DependencyInformationConsumer)3 MethodCallDependencyCheckInvoker (com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker)2 Dependencies (com.github.sevntu.checkstyle.domain.Dependencies)2 MethodOrder (com.github.sevntu.checkstyle.ordering.MethodOrder)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)2 File (java.io.File)2 IOException (java.io.IOException)2 DependencyInformationConsumerInjector (com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector)1 DependencyInfoGraphSerializer (com.github.sevntu.checkstyle.dot.DependencyInfoGraphSerializer)1 DependencyInfoMatrixSerializer (com.github.sevntu.checkstyle.dsm.DependencyInfoMatrixSerializer)1 MethodCallDependencyCheckstyleModule (com.github.sevntu.checkstyle.module.MethodCallDependencyCheckstyleModule)1 ViolationReporterDependencyInformationConsumer (com.github.sevntu.checkstyle.module.ViolationReporterDependencyInformationConsumer)1 FileUtils (com.github.sevntu.checkstyle.utils.FileUtils)1 Checker (com.puppycrawl.tools.checkstyle.Checker)1 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)1 DefaultLogger (com.puppycrawl.tools.checkstyle.DefaultLogger)1 ModuleFactory (com.puppycrawl.tools.checkstyle.ModuleFactory)1 TreeWalker (com.puppycrawl.tools.checkstyle.TreeWalker)1 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)1