Search in sources :

Example 1 with MethodCallDependencyCheckInvoker

use of com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker 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 MethodCallDependencyCheckInvoker

use of com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker in project methods-distance by sevntu-checkstyle.

the class Main method main.

public static void main(String... args) throws CheckstyleException {
    final CliArguments arguments = new CliArguments(args);
    final Map<String, String> attributes = Collections.singletonMap("screenLinesCount", "50");
    final DependencyInformationSerializer serializer = new DependencyInformationSerializer(arguments);
    final MethodCallDependencyCheckInvoker invoker = new MethodCallDependencyCheckInvoker(attributes, serializer);
    invoker.invoke(arguments.getFiles());
}
Also used : MethodCallDependencyCheckInvoker(com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker)

Example 3 with MethodCallDependencyCheckInvoker

use of com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker in project methods-distance by sevntu-checkstyle.

the class ReorderCli method main.

public static void main(String... args) throws CheckstyleException {
    final Map<String, String> attributes = Collections.singletonMap("screenLinesCount", "50");
    final DependencyInformationSerializer serializer = new DependencyInformationSerializer();
    final MethodCallDependencyCheckInvoker runner = new MethodCallDependencyCheckInvoker(attributes, serializer);
    final List<File> files = Collections.singletonList(new File(args[0]));
    runner.invoke(files);
}
Also used : MethodCallDependencyCheckInvoker(com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker) File(java.io.File)

Example 4 with MethodCallDependencyCheckInvoker

use of com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker 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

MethodCallDependencyCheckInvoker (com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker)4 Dependencies (com.github.sevntu.checkstyle.domain.Dependencies)2 DependencyInformationConsumer (com.github.sevntu.checkstyle.module.DependencyInformationConsumer)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 DependencyInfoGraphSerializer (com.github.sevntu.checkstyle.dot.DependencyInfoGraphSerializer)1 DependencyInfoMatrixSerializer (com.github.sevntu.checkstyle.dsm.DependencyInfoMatrixSerializer)1 FileUtils (com.github.sevntu.checkstyle.utils.FileUtils)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1