use of com.puppycrawl.tools.checkstyle.api.CheckstyleException 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)));
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project methods-distance by sevntu-checkstyle.
the class MainServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String requestPath = req.getPathInfo();
final String sourceUrl = req.getParameter("source_url");
try {
final URL url = new URL(sourceUrl);
switch(requestPath) {
case "/dsm":
processDsm(url, resp);
break;
case "/dot":
processDot(url, resp);
break;
default:
processNotFound(resp);
}
} catch (final MalformedURLException ex) {
resp.getWriter().print("Malformed url provided: " + sourceUrl);
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
} catch (final CheckstyleException ex) {
resp.getWriter().print("Checkstyle exception occurred: " + ex.getMessage());
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class AbstractGoogleModuleTestSupport method getModuleConfig.
/**
* Returns {@link Configuration} instance for the given module name.
* This implementation uses {@link #getModuleConfig(String)} method inside.
*
* @param moduleName module name.
* @param moduleId module id.
* @return {@link Configuration} instance for the given module name.
* @throws IllegalStateException if there is a problem retrieving the module or config.
*/
protected static Configuration getModuleConfig(String moduleName, String moduleId) {
final Configuration result;
final List<Configuration> configs = getModuleConfigs(moduleName);
if (configs.size() == 1) {
result = configs.get(0);
} else if (configs.isEmpty()) {
throw new IllegalStateException("no instances of the Module was found: " + moduleName);
} else if (moduleId == null) {
throw new IllegalStateException("multiple instances of the same Module are detected");
} else {
result = configs.stream().filter(conf -> {
try {
return conf.getProperty("id").equals(moduleId);
} catch (CheckstyleException ex) {
throw new IllegalStateException("problem to get ID attribute from " + conf, ex);
}
}).findFirst().orElseThrow(() -> new IllegalStateException("problem with module config"));
}
return result;
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class JavadocPropertiesGenerator method writePropertiesFile.
/**
* Creates the .properties file from a .java file.
*
* @param options the user-specified options
* @throws CheckstyleException if a javadoc comment can not be parsed
*/
private static void writePropertiesFile(CliOptions options) throws CheckstyleException {
try (PrintWriter writer = new PrintWriter(options.outputFile, StandardCharsets.UTF_8)) {
final DetailAST top = JavaParser.parseFile(options.inputFile, JavaParser.Options.WITH_COMMENTS).getFirstChild();
final DetailAST objBlock = getClassBody(top);
if (objBlock != null) {
iteratePublicStaticIntFields(objBlock, writer::println);
}
} catch (IOException ex) {
throw new CheckstyleException("Failed to write javadoc properties of '" + options.inputFile + "' to '" + options.outputFile + "'", ex);
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class ConfigurationLoader method loadConfiguration.
/**
* Returns the module configurations from a specified input source.
* Note that if the source does wrap an open byte or character
* stream, clients are required to close that stream by themselves
*
* @param configSource the input stream to the Checkstyle configuration
* @param overridePropsResolver overriding properties
* @param ignoredModulesOptions {@code OMIT} if modules with severity
* 'ignore' should be omitted, {@code EXECUTE} otherwise
* @param threadModeSettings the thread mode configuration
* @return the check configurations
* @throws CheckstyleException if an error occurs
* @noinspection WeakerAccess
*/
public static Configuration loadConfiguration(InputSource configSource, PropertyResolver overridePropsResolver, IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings) throws CheckstyleException {
try {
final boolean omitIgnoreModules = ignoredModulesOptions == IgnoredModulesOptions.OMIT;
final ConfigurationLoader loader = new ConfigurationLoader(overridePropsResolver, omitIgnoreModules, threadModeSettings);
loader.parseInputSource(configSource);
return loader.configuration;
} catch (final SAXParseException ex) {
final String message = String.format(Locale.ROOT, SAX_PARSE_EXCEPTION_FORMAT, UNABLE_TO_PARSE_EXCEPTION_PREFIX, ex.getMessage(), ex.getLineNumber(), ex.getColumnNumber());
throw new CheckstyleException(message, ex);
} catch (final ParserConfigurationException | IOException | SAXException ex) {
throw new CheckstyleException(UNABLE_TO_PARSE_EXCEPTION_PREFIX, ex);
}
}
Aggregations