Package org.codehaus.plexus.compiler

Examples of org.codehaus.plexus.compiler.CompilerMessage


        List<CompilerMessage> messages = new ArrayList<CompilerMessage>( compilerErrors.size() );
        boolean success = true;
        for ( CompilerError compilerError : compilerErrors )
        {
            messages.add(
                new CompilerMessage( compilerError.getFile(), compilerError.getKind(), compilerError.getStartLine(),
                                     compilerError.getStartColumn(), compilerError.getEndLine(),
                                     compilerError.getEndColumn(), compilerError.getMessage() ) );
            if ( compilerError.isError() )
            {
                success = false;
View Full Code Here


        if ( messages.size() == 1 )
        {
            sb.append( LS );

            CompilerMessage compilerError = messages.get( 0 );

            sb.append( compilerError ).append( LS );
        }
       
        return sb.toString();
View Full Code Here

                }

                // TODO: there should be a better way to parse these
                if ( ( buffer.length() == 0 ) && line.startsWith( "error: " ) )
                {
                    errors.add( new CompilerMessage( line, true ) );
                }
                else if ( ( buffer.length() == 0 ) && isNote( line ) )
                {
                    // skip, JDK 1.5 telling us deprecated APIs are used but -Xlint:deprecation isn't set
                }
View Full Code Here

            if ( endcolumn == -1 )
            {
                endcolumn = context.length();
            }

            return new CompilerMessage( file, isError, line, startcolumn, line, endcolumn, message.trim() );
        }
        catch ( NoSuchElementException e )
        {
            return new CompilerMessage( "no more tokens - could not parse error message: " + error, isError );
        }
        catch ( NumberFormatException e )
        {
            return new CompilerMessage( "could not parse error message: " + error, isError );
        }
        catch ( Exception e )
        {
            return new CompilerMessage( "could not parse error message: " + error, isError );
        }
    }
View Full Code Here

        JavaCompiler compiler = getJavaCompiler( config );
        try
        {
            if ( compiler == null )
            {
                CompilerMessage message =
                                new CompilerMessage( "No compiler is provided in this environment. "
                                                     + "Perhaps you are running on a JRE rather than a JDK?",
                                                     CompilerMessage.Kind.ERROR );
                return new CompilerResult( false, Collections.singletonList( message ) );
            }
            final String sourceEncoding = config.getSourceEncoding();
            final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding );
            final DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
            final StandardJavaFileManager standardFileManager =
                compiler.getStandardFileManager( collector, null, sourceCharset );

            final Iterable<? extends JavaFileObject> fileObjects =
                standardFileManager.getJavaFileObjectsFromStrings( Arrays.asList( sourceFiles ) );
            final JavaCompiler.CompilationTask task =

                                         /*(Writer out,
                                         JavaFileManager fileManager,
                                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                                         Iterable<String> options,
                                         Iterable<String> classes,
                                         Iterable<? extends JavaFileObject> compilationUnits)*/


                compiler.getTask( null, standardFileManager, collector, Arrays.asList( args ), null, fileObjects );
            final Boolean result = task.call();
            final ArrayList<CompilerMessage> compilerMsgs = new ArrayList<CompilerMessage>();
            for ( Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics() )
            {
                CompilerMessage.Kind kind;
                switch ( diagnostic.getKind() )
                {
                    case ERROR:
                        kind = CompilerMessage.Kind.ERROR;
                        break;
                    case WARNING:
                        kind = CompilerMessage.Kind.WARNING;
                        break;
                    case MANDATORY_WARNING:
                        kind = CompilerMessage.Kind.MANDATORY_WARNING;
                        break;
                    case NOTE:
                        kind = CompilerMessage.Kind.NOTE;
                        break;
                    default:
                        kind = CompilerMessage.Kind.OTHER;
                        break;
                }
                String baseMessage = diagnostic.getMessage( null );
                if ( baseMessage == null )
                {
                    continue;
                }
                JavaFileObject source = diagnostic.getSource();
                String longFileName = source == null ? null : source.toUri().getPath();
                String shortFileName = source == null ? null : source.getName();
                String formattedMessage = baseMessage;
                int lineNumber = Math.max( 0, (int) diagnostic.getLineNumber() );
                int columnNumber = Math.max( 0, (int) diagnostic.getColumnNumber() );
                if ( source != null && lineNumber > 0 )
                {
                    // Some compilers like to copy the file name into the message, which makes it appear twice.
                    String possibleTrimming = longFileName + ":" + lineNumber + ": ";
                    if ( formattedMessage.startsWith( possibleTrimming ) )
                    {
                        formattedMessage = formattedMessage.substring( possibleTrimming.length() );
                    }
                    else
                    {
                        possibleTrimming = shortFileName + ":" + lineNumber + ": ";
                        if ( formattedMessage.startsWith( possibleTrimming ) )
                        {
                            formattedMessage = formattedMessage.substring( possibleTrimming.length() );
                        }
                    }
                }
                compilerMsgs.add(
                    new CompilerMessage( longFileName, kind, lineNumber, columnNumber, lineNumber, columnNumber,
                                       formattedMessage ) );
            }
            if ( result != Boolean.TRUE && compilerMsgs.isEmpty() )
            {
                compilerMsgs.add(
                    new CompilerMessage( "An unknown compilation problem occurred", CompilerMessage.Kind.ERROR ) );
            }
           
            return new CompilerResult( result, compilerMsgs);
        }
        catch ( Exception e )
View Full Code Here

                if ( line == null )
                {
                    // javac output not detected by other parsing
                    if ( buffer.length() > 0 && buffer.toString().startsWith( "javac:" ) )
                    {
                        errors.add( new CompilerMessage( buffer.toString(), CompilerMessage.Kind.ERROR ) );
                    }
                    return errors;
                }

                // TODO: there should be a better way to parse these
                if ( ( buffer.length() == 0 ) && line.startsWith( "error: " ) )
                {
                    errors.add( new CompilerMessage( line, true ) );
                }
                else if ( ( buffer.length() == 0 ) && isNote( line ) )
                {
                    // skip, JDK 1.5 telling us deprecated APIs are used but -Xlint:deprecation isn't set
                }
View Full Code Here

            if ( endcolumn == -1 )
            {
                endcolumn = context.length();
            }

            return new CompilerMessage( file, isError, line, startcolumn, line, endcolumn, message.trim() );
        }
        catch ( NoSuchElementException e )
        {
            return new CompilerMessage( "no more tokens - could not parse error message: " + error, isError );
        }
        catch ( NumberFormatException e )
        {
            return new CompilerMessage( "could not parse error message: " + error, isError );
        }
        catch ( Exception e )
        {
            return new CompilerMessage( "could not parse error message: " + error, isError );
        }
    }
View Full Code Here

        JavaCompiler compiler = getJavaCompiler( config );
        try
        {
            if ( compiler == null )
            {
                CompilerMessage message = new CompilerMessage( "No compiler is provided in this environment. "
                                                                   + "Perhaps you are running on a JRE rather than a JDK?",
                                                               CompilerMessage.Kind.ERROR );
                return new CompilerResult( false, Collections.singletonList( message ) );
            }
            final String sourceEncoding = config.getSourceEncoding();
            final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding );
            final DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
            final StandardJavaFileManager standardFileManager =
                compiler.getStandardFileManager( collector, null, sourceCharset );

            final Iterable<? extends JavaFileObject> fileObjects =
                standardFileManager.getJavaFileObjectsFromStrings( Arrays.asList( sourceFiles ) );

             /*(Writer out,
             JavaFileManager fileManager,
             DiagnosticListener<? super JavaFileObject> diagnosticListener,
             Iterable<String> options,
             Iterable<String> classes,
             Iterable<? extends JavaFileObject> compilationUnits)*/

            List<String> arguments = Arrays.asList( args );

            final JavaCompiler.CompilationTask task =
                compiler.getTask( null, standardFileManager, collector, arguments, null, fileObjects );
            final Boolean result = task.call();
            final ArrayList<CompilerMessage> compilerMsgs = new ArrayList<CompilerMessage>();
            for ( Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics() )
            {
                CompilerMessage.Kind kind = convertKind(diagnostic);
                String baseMessage = diagnostic.getMessage( null );
                if ( baseMessage == null )
                {
                    continue;
                }
                JavaFileObject source = diagnostic.getSource();
                String longFileName = source == null ? null : source.toUri().getPath();
                String shortFileName = source == null ? null : source.getName();
                String formattedMessage = baseMessage;
                int lineNumber = Math.max( 0, (int) diagnostic.getLineNumber() );
                int columnNumber = Math.max( 0, (int) diagnostic.getColumnNumber() );
                if ( source != null && lineNumber > 0 )
                {
                    // Some compilers like to copy the file name into the message, which makes it appear twice.
                    String possibleTrimming = longFileName + ":" + lineNumber + ": ";
                    if ( formattedMessage.startsWith( possibleTrimming ) )
                    {
                        formattedMessage = formattedMessage.substring( possibleTrimming.length() );
                    }
                    else
                    {
                        possibleTrimming = shortFileName + ":" + lineNumber + ": ";
                        if ( formattedMessage.startsWith( possibleTrimming ) )
                        {
                            formattedMessage = formattedMessage.substring( possibleTrimming.length() );
                        }
                    }
                }
                compilerMsgs.add(
                    new CompilerMessage( longFileName, kind, lineNumber, columnNumber, lineNumber, columnNumber,
                                         formattedMessage ) );
            }
            if ( result != Boolean.TRUE && compilerMsgs.isEmpty() )
            {
                compilerMsgs.add(
                    new CompilerMessage( "An unknown compilation problem occurred", CompilerMessage.Kind.ERROR ) );
            }

            return new CompilerResult( result, compilerMsgs );
        }
        catch ( Exception e )
View Full Code Here

                if ( line == null )
                {
                    // javac output not detected by other parsing
                    if ( buffer.length() > 0 && buffer.toString().startsWith( "javac:" ) )
                    {
                        errors.add( new CompilerMessage( buffer.toString(), CompilerMessage.Kind.ERROR ) );
                    }
                    return errors;
                }

                // TODO: there should be a better way to parse these
                if ( ( buffer.length() == 0 ) && line.startsWith( "error: " ) )
                {
                    errors.add( new CompilerMessage( line, true ) );
                }
                else if ( ( buffer.length() == 0 ) && isNote( line ) )
                {
                    // skip, JDK 1.5 telling us deprecated APIs are used but -Xlint:deprecation isn't set
                }
View Full Code Here

            if ( endcolumn == -1 )
            {
                endcolumn = context.length();
            }

            return new CompilerMessage( file, isError, line, startcolumn, line, endcolumn, message.trim() );
        }
        catch ( NoSuchElementException e )
        {
            return new CompilerMessage( "no more tokens - could not parse error message: " + error, isError );
        }
        catch ( NumberFormatException e )
        {
            return new CompilerMessage( "could not parse error message: " + error, isError );
        }
        catch ( Exception e )
        {
            return new CompilerMessage( "could not parse error message: " + error, isError );
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.compiler.CompilerMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.