Example usage for org.aspectj.bridge IMessage ERROR

List of usage examples for org.aspectj.bridge IMessage ERROR

Introduction

In this page you can find the example usage for org.aspectj.bridge IMessage ERROR.

Prototype

Kind ERROR

To view the source code for org.aspectj.bridge IMessage ERROR.

Click Source Link

Usage

From source file:AjcCompiler.java

License:Open Source License

/**
 * Do the AspectJ compiling.//from ww w  . j a v  a2s . com
 *
 * @throws Exception
 */
public void execute() throws Exception {
    assembleArguments();

    if (!forceAjcCompile && !hasSourcesToCompile()) {
        getLog().warning("No sources found skipping aspectJ compile");
        return;
    }

    if (!forceAjcCompile && !isBuildNeeded()) {
        getLog().info("No modifications found skipping aspectJ compile");
        return;
    }

    if (getLog().isLoggable(Level.INFO)) {
        String command = "Running : ajc";
        Iterator iter = ajcOptions.iterator();
        while (iter.hasNext()) {
            command += (" " + iter.next());
        }
        getLog().info(command);
    }
    try {
        getLog().fine(
                "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory());
        writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory());
        getLog().fine("Argumentsfile written : "
                + new File(getOutputDirectory(), argumentFileName).getAbsolutePath());
    } catch (IOException e) {
        throw new Exception("Could not write arguments file to the target area", e);
    }

    Main main = new Main();
    MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog());
    main.setHolder(mavenMessageHandler);

    synchronized (BIG_ASPECTJ_LOCK) {
        main.runMain((String[]) ajcOptions.toArray(new String[ajcOptions.size()]), false);
    }

    IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true);
    if (!proceedOnError && errors.length > 0)
        throw new Exception(Arrays.asList(errors).toString());
}

From source file:AjcCompiler.java

License:Open Source License

/**
 * Hook into the maven logger./* w ww  .  j  a  va 2 s.c  o m*/
 */
public boolean handleMessage(IMessage message) {
    if (message.getKind().equals(IMessage.WARNING) && !isIgnoring(IMessage.WARNING))
        log.warning(message.getMessage());
    else if (message.getKind().equals(IMessage.DEBUG) && !isIgnoring(IMessage.DEBUG))
        log.fine(message.getMessage());
    else if (message.getKind().equals(IMessage.ERROR) && !isIgnoring(IMessage.ERROR))
        log.severe(message.getMessage());
    else if (message.getKind().equals(IMessage.ABORT) && !isIgnoring(IMessage.ABORT))
        log.severe(message.getMessage());
    else if (message.getKind().equals(IMessage.FAIL) && !isIgnoring(IMessage.FAIL))
        log.severe(message.getMessage());
    else if (message.getKind().equals(IMessage.INFO) && !isIgnoring(IMessage.INFO))
        log.fine(message.getMessage());
    else if (message.getKind().equals(IMessage.WEAVEINFO) && !isIgnoring(IMessage.WEAVEINFO))
        log.info(message.getMessage());
    else if (message.getKind().equals(IMessage.TASKTAG) && !isIgnoring(IMessage.TASKTAG))
        log.fine(message.getMessage());
    return super.handleMessage(message);
}

From source file:de.zalando.mojo.aspectj.AbstractAjcCompiler.java

License:Open Source License

/**
 * Do the AspectJ compiling./*  ww  w.  j  av a 2  s . co m*/
 *
 * @throws MojoExecutionException
 */
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {

    if (isSkip()) {
        if (getLog().isInfoEnabled()) {
            getLog().info("Skipping execution because of 'skip' option");
        }
        return;
    }

    ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
    if (!"java".equalsIgnoreCase(artifactHandler.getLanguage())) {
        getLog().warn("Not executing aspectJ compiler as the project is not a Java classpath-capable package");
        return;
    }

    // MASPECT-110:
    //
    // Only add the aspectSourcePathDir and testAspectSourcePathDir to their respective
    // compileSourceRoots if they actually exist and are directories... to avoid crashing
    // downstream plugins requiring/assuming that all entries within the compileSourceRoots
    // and testCompileSourceRoots are directories.
    //
    final File aspectSourcePathDir = FileUtils.resolveFile(basedir, aspectDirectory);
    final File testAspectSourcePathDir = FileUtils.resolveFile(basedir, testAspectDirectory);

    final String aspectSourcePath = aspectSourcePathDir.getAbsolutePath();
    final String testAspectSourcePath = testAspectSourcePathDir.getAbsolutePath();

    if (aspectSourcePathDir.exists() && aspectSourcePathDir.isDirectory()
            && !project.getCompileSourceRoots().contains(aspectSourcePath)) {
        getLog().debug("Adding existing aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots.");
        project.getCompileSourceRoots().add(aspectSourcePath);
    } else {
        getLog().debug("Not adding non-existent or already added aspectSourcePathDir [" + aspectSourcePath
                + "] to compileSourceRoots.");
    }

    if (testAspectSourcePathDir.exists() && testAspectSourcePathDir.isDirectory()
            && !project.getTestCompileSourceRoots().contains(testAspectSourcePath)) {
        getLog().debug("Adding existing testAspectSourcePathDir [" + testAspectSourcePath
                + "] to testCompileSourceRoots.");
        project.getTestCompileSourceRoots().add(testAspectSourcePath);
    } else {
        getLog().debug("Not adding non-existent or already added testAspectSourcePathDir ["
                + testAspectSourcePath + "] to testCompileSourceRoots.");
    }

    assembleArguments();

    if (!forceAjcCompile && !hasSourcesToCompile()) {
        getLog().warn("No sources found skipping aspectJ compile");
        return;
    }

    if (!forceAjcCompile && !isBuildNeeded()) {
        getLog().info("No modifications found skipping aspectJ compile");
        return;
    }

    if (getLog().isDebugEnabled()) {
        StringBuilder command = new StringBuilder("Running : ajc");

        for (String arg : ajcOptions) {
            command.append(' ').append(arg);
        }
        getLog().debug(command);
    }
    try {
        getLog().debug(
                "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory());
        AjcHelper.writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory());
        getLog().debug("Arguments file written : "
                + new File(getOutputDirectory(), argumentFileName).getAbsolutePath());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not write arguments file to the target area", e);
    }

    final Main ajcMain = new Main();
    MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog());
    ajcMain.setHolder(mavenMessageHandler);

    synchronized (BIG_ASPECTJ_LOCK) {
        ajcMain.runMain((String[]) ajcOptions.toArray(new String[ajcOptions.size()]), false);
    }

    IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true);
    if (!proceedOnError && errors.length > 0) {
        throw CompilationFailedException.create(errors);
    }
}

From source file:de.zalando.mojo.aspectj.MavenMessageHandler.java

License:Open Source License

/**
 * Copies output from the supplied message onto the active Maven Log.
 * If the message type (i.e. {@code message.getKind()}) is listed in the showDetailsForMessageKindList List,
 * the message is prefixed with location details (Class, row/line number etc.) as well.
 * <p/>/*from   w  w w . j  av a 2  s . co m*/
 * {@inheritDoc}
 */
public boolean handleMessage(final IMessage message) {

    // Compose the message text
    final StringBuilder builder = new StringBuilder(message.getMessage());
    if (isMessageDetailDesired(message)) {

        //
        // The AJC details are typically delivered on the format [fileName]:[lineNumber]
        // (i.e. /src/main/java/Clazz.java:16).
        //
        // Mimic this, and include the context of the message as well,
        // including guarding against NPEs.
        //
        final ISourceLocation sourceLocation = message.getSourceLocation();
        final String sourceFile = sourceLocation == null || sourceLocation.getSourceFile() == null
                ? "<unknown source file>"
                : sourceLocation.getSourceFile().getAbsolutePath();
        final String context = sourceLocation == null || sourceLocation.getContext() == null ? ""
                : sourceLocation.getContext() + "\n";
        final String line = sourceLocation == null ? "<no line information>" : "" + sourceLocation.getLine();

        builder.append("\n\t").append(sourceFile).append(":").append(line).append("\n").append(context);
    }

    final String messageText = builder.toString();

    if (isNotIgnored(message, IMessage.DEBUG) || isNotIgnored(message, IMessage.INFO)
            || isNotIgnored(message, IMessage.TASKTAG)) {

        // The DEBUG, INFO, and TASKTAG ajc message kinds are considered Maven Debug messages.
        log.debug(messageText);

    } else if (isNotIgnored(message, IMessage.WEAVEINFO)) {

        // The WEAVEINFO ajc message kind is considered Maven Info messages.
        log.info(messageText);

    } else if (isNotIgnored(message, IMessage.WARNING)) {

        // The WARNING ajc message kind is considered Maven Warn messages.
        log.warn(messageText);

    } else if (isNotIgnored(message, IMessage.ERROR) || isNotIgnored(message, IMessage.ABORT)
            || isNotIgnored(message, IMessage.FAIL)) {

        // We map ERROR, ABORT, and FAIL ajc message kinds to Maven Error messages.
        log.error(messageText);
    }

    // Delegate to normal handling.
    return super.handleMessage(message);
}

From source file:org.caesarj.compiler.aspectj.CaesarSuperPointcut.java

License:Open Source License

/**
 * Resolve the bindings. If we are in a caesar scope, we try to 
 * resolve the pointcut in the super type. Otherwise, we just use
 * the regular resolving.//from  ww  w .  j a v  a2s  .  c o  m
 */
public void resolveBindings(IScope scope, Bindings bindings) {

    if (scope instanceof CaesarScope) {
        onType = ((CaesarScope) scope).getSuperRegisterType();
    }
    try {
        super.resolveBindings(scope, bindings);
    } catch (Exception e) {
        onType = null;
        scope.message(IMessage.ERROR, this, "Can't find referenced pointcut");
        return;
    }
}

From source file:org.codehaus.mojo.aspectj.AbstractAjcCompiler.java

License:Open Source License

/**
 * Do the AspectJ compiling./*from  www.  j  a v a  2  s  .c  o  m*/
 *
 * @throws MojoExecutionException
 */
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {

    if (isSkip()) {
        if (getLog().isInfoEnabled()) {
            getLog().info("Skipping execution because of 'skip' option");
        }
        return;
    }

    ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
    if (!"java".equalsIgnoreCase(artifactHandler.getLanguage())) {
        getLog().warn("Not executing aspectJ compiler as the project is not a Java classpath-capable package");
        return;
    }

    // MASPECT-110:
    //
    // Only add the aspectSourcePathDir and testAspectSourcePathDir to their respective
    // compileSourceRoots if they actually exist and are directories... to avoid crashing
    // downstream plugins requiring/assuming that all entries within the compileSourceRoots
    // and testCompileSourceRoots are directories.
    //
    final File aspectSourcePathDir = FileUtils.resolveFile(basedir, aspectDirectory);
    final File testAspectSourcePathDir = FileUtils.resolveFile(basedir, testAspectDirectory);

    final String aspectSourcePath = aspectSourcePathDir.getAbsolutePath();
    final String testAspectSourcePath = testAspectSourcePathDir.getAbsolutePath();

    if (aspectSourcePathDir.exists() && aspectSourcePathDir.isDirectory()
            && !project.getCompileSourceRoots().contains(aspectSourcePath)) {
        getLog().debug("Adding existing aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots.");
        project.getCompileSourceRoots().add(aspectSourcePath);
    } else {
        getLog().debug("Not adding non-existent or already added aspectSourcePathDir [" + aspectSourcePath
                + "] to compileSourceRoots.");
    }

    if (testAspectSourcePathDir.exists() && testAspectSourcePathDir.isDirectory()
            && !project.getTestCompileSourceRoots().contains(testAspectSourcePath)) {
        getLog().debug("Adding existing testAspectSourcePathDir [" + testAspectSourcePath
                + "] to testCompileSourceRoots.");
        project.getTestCompileSourceRoots().add(testAspectSourcePath);
    } else {
        getLog().debug("Not adding non-existent or already added testAspectSourcePathDir ["
                + testAspectSourcePath + "] to testCompileSourceRoots.");
    }

    assembleArguments();

    if (!forceAjcCompile && !hasSourcesToCompile()) {
        getLog().warn("No sources found skipping aspectJ compile");
        return;
    }

    if (!forceAjcCompile && !isBuildNeeded()) {
        getLog().info("No modifications found skipping aspectJ compile");
        return;
    }

    if (getLog().isDebugEnabled()) {
        StringBuilder command = new StringBuilder("Running : ajc");

        for (String arg : ajcOptions) {
            command.append(' ').append(arg);
        }
        getLog().debug(command);
    }
    try {
        getLog().debug(
                "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory());
        AjcHelper.writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory());
        getLog().debug("Arguments file written : "
                + new File(getOutputDirectory(), argumentFileName).getAbsolutePath());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not write arguments file to the target area", e);
    }

    final Main ajcMain = new Main();
    MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog());
    ajcMain.setHolder(mavenMessageHandler);

    synchronized (BIG_ASPECTJ_LOCK) {
        ajcMain.runMain(ajcOptions.toArray(new String[ajcOptions.size()]), false);
    }

    IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true);
    if (!proceedOnError && errors.length > 0) {
        throw CompilationFailedException.create(errors);
    }
}

From source file:org.eclipse.ajdt.core.ant.AjcTask.java

License:Open Source License

/**
 * Run the compile in the same VM by loading the compiler (Main), setting up any message holders, doing the compile, and
 * converting abort/failure and error messages to BuildException, as appropriate.
 * /*from w  w w  .j  a v a 2  s .co m*/
  * @return true on successful compilation
 * @throws BuildException if abort or failure messages or if errors and failonerror.
 * 
 */
protected boolean executeInSameVM(String[] args) {
    if (null != maxMem) {
        log("maxMem ignored unless forked: " + maxMem, Project.MSG_WARN);
    }
    IMessageHolder holder = messageHolder;
    int numPreviousErrors;
    if (null == holder) {
        MessageHandler mhandler = new MessageHandler(true);
        final IMessageHandler delegate;
        delegate = new AntMessageHandler(this.logger, this.verbose, false);
        mhandler.setInterceptor(delegate);
        holder = mhandler;
        numPreviousErrors = 0;
    } else {
        numPreviousErrors = holder.numMessages(IMessage.ERROR, true);
    }
    AjdtCommandForAnt command = new AjdtCommandForAnt();
    {
        Main newmain = new Main();
        newmain.setCommand(command);
        newmain.setHolder(holder);
        newmain.setCompletionRunner(new Runnable() {
            public void run() {
                doCompletionTasks();
            }
        });
        if (null != main) {
            MessageUtil.fail(holder, "still running prior main");
            return false;
        }
        main = newmain;
    }
    main.runMain(args, false);
    if (failonerror) {
        int errs = holder.numMessages(IMessage.ERROR, false);
        errs -= numPreviousErrors;
        if (0 < errs) {
            String m = errs + " errors";
            MessageUtil.print(System.err, holder, "", MessageUtil.MESSAGE_ALL, MessageUtil.PICK_ERROR, true);
            throw new BuildException(m);
        }
    }
    // Throw BuildException if there are any fail or abort
    // messages.
    // The BuildException message text has a list of class names
    // for the exceptions found in the messages, or the
    // number of fail/abort messages found if there were
    // no exceptions for any of the fail/abort messages.
    // The interceptor message handler should have already
    // printed the messages, including any stack traces.
    // HACK: this ignores the Usage message
    {
        IMessage[] fails = holder.getMessages(IMessage.FAIL, true);
        if (!LangUtil.isEmpty(fails)) {
            StringBuffer sb = new StringBuffer();
            String prefix = "fail due to ";
            int numThrown = 0;
            for (int i = 0; i < fails.length; i++) {
                String message = fails[i].getMessage();
                if (LangUtil.isEmpty(message)) {
                    message = "<no message>";
                } else if (-1 != message.indexOf(USAGE_SUBSTRING)) {
                    continue;
                }
                Throwable t = fails[i].getThrown();
                if (null != t) {
                    numThrown++;
                    sb.append(prefix);
                    sb.append(LangUtil.unqualifiedClassName(t.getClass()));
                    String thrownMessage = t.getMessage();
                    if (!LangUtil.isEmpty(thrownMessage)) {
                        sb.append(" \"" + thrownMessage + "\"");
                    }
                }
                sb.append("\"" + message + "\"");
                prefix = ", ";
            }
            if (0 < sb.length()) {
                sb.append(" (" + numThrown + " exceptions)");
                throw new BuildException(sb.toString());
            }
        }
    }
    return command.isFailed();
}

From source file:org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter.java

License:Open Source License

public boolean execute() throws BuildException {
    javac.log(//from  ww w.ja va2  s.  com
            "Note that you may see messages about skipping *.aj files above. "
                    + "These messages can be ignored as these files are handled directly by "
                    + "ajc.  Similarly, the messages below about skipping *.java files can be ignored.",
            Project.MSG_INFO);

    // javac task spits out messages that it 

    if (null == javac) {
        throw new IllegalStateException("null javac");
    }
    if (!((Boolean) inSelfCall.get()).booleanValue() && afterCleaningDirs()) {
        // if we are not re-calling ourself and we cleaned dirs,
        // then re-call javac to get the list of all source files.
        inSelfCall.set(Boolean.TRUE);
        javac.execute();
        // javac re-invokes us after recalculating file list
    } else {
        try {
            AjcTask ajc = new AjcTask();
            String err = ajc.setupAjc(javac);
            if (null != err) {
                throw new BuildException(err, javac.getLocation());
            }
            addAJFiles(ajc);
            IMessageHolder handler = new MessageHandler();
            ajc.setMessageHolder(handler);

            String logFile = null;
            String[] args = javac.getCurrentCompilerArgs();
            for (int i = 0; i < args.length; i++) {
                if (args[i].equals("-log") && args.length > i) {
                    logFile = args[i + 1];
                    ajc.setLog(new File(logFile));
                    break;
                }
            }

            ajc.execute();

            // if log file is used, this message handler will never show any errors
            IMessage[] messages = handler.getMessages(IMessage.ERROR, true);
            if (messages != IMessage.RA_IMessage && logFile != null) {
                // log messages
                String msg = "Compilation has errors or warnings. Log is available in " + logFile;
                javac.log(msg, Project.MSG_INFO);
                return false;
            } else {
                return ajc.wasCompilationSuccessful();
            }

        } finally {
            inSelfCall.set(Boolean.FALSE);
        }
    }
    return true;
}

From source file:org.eclipse.ajdt.internal.ui.ajde.UIMessageHandler.java

License:Open Source License

public List<ProblemTracker> getErrors() {
    List<ProblemTracker> errors = new ArrayList<ProblemTracker>();
    for (Iterator<ProblemTracker> iter = problems.iterator(); iter.hasNext();) {
        ProblemTracker prob = (ProblemTracker) iter.next();
        if (prob.kind.equals(IMessage.ERROR)) {
            errors.add(prob);//from   ww w.ja v  a2s  .  co  m
        }
    }
    return errors;
}

From source file:org.eclipse.ajdt.internal.ui.ajde.UIMessageHandler.java

License:Open Source License

/**
 * Sets the given marker to have hte appropriate severity, according to the
 * kind.//w  w w. j  a v  a2 s .c  o  m
 * 
 * @param marker
 *            the marker to set the message for
 * @param kind
 *            used to determine the appropriate severity
 * @throws CoreException
 */
private void setSeverity(IMarker marker, IMessage.Kind kind) throws CoreException {
    if (kind == IMessage.ERROR) {
        marker.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
    } else if (kind == IMessage.WARNING) {
        marker.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
    } else {
        marker.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
    }

}