Search in sources :

Example 1 with StringBuildingOutputProcessor

use of org.jetbrains.android.util.StringBuildingOutputProcessor in project android by JetBrains.

the class AndroidMavenExecutor method generateResources.

public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
    final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
    final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
    result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
    try {
        JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {

            @Nullable
            @Override
            public JavaParameters compute() {
                try {
                    return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
                } catch (ExecutionException e) {
                    LOG.info(e);
                    result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
                    return null;
                }
            }
        });
        if (javaParams == null) {
            return result;
        }
        GeneralCommandLine commandLine = javaParams.toCommandLine();
        final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
        boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
        String message = processor.getMessage();
        if (!success) {
            LOG.info(message);
            String lcmessage = message.toLowerCase();
            int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
            if (buildErrorIndex >= 0) {
                result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
            }
        }
    } catch (ExecutionException e) {
        LOG.info(e);
        result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
    }
    return result;
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) HashMap(com.intellij.util.containers.HashMap) StringBuildingOutputProcessor(org.jetbrains.android.util.StringBuildingOutputProcessor) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 CompilerMessageCategory (com.intellij.openapi.compiler.CompilerMessageCategory)1 HashMap (com.intellij.util.containers.HashMap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringBuildingOutputProcessor (org.jetbrains.android.util.StringBuildingOutputProcessor)1 Nullable (org.jetbrains.annotations.Nullable)1 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)1 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)1