Content of file DebugProfilingAspect.java.html

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>DebugProfilingAspect.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">NorthernWind :: Frontend :: Media :: Spring MVC</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-frontend-media</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.aspect</a> &gt; <span class="el_source">DebugProfilingAspect.java</span></div><h1>DebugProfilingAspect.java</h1><pre class="source lang-java linenums"><span class="nc bnc" id="L1" title="All 4 branches missed.">/*</span>
 * #%L
 * *********************************************************************************************************************
 *
 * NorthernWind - lightweight CMS
 * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
 * %%
 * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
 * %%
 * *********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * *********************************************************************************************************************
 *
 *
 * *********************************************************************************************************************
 * #L%
 */
package it.tidalwave.northernwind.aspect;

import java.lang.annotation.Annotation;
import javax.annotation.Nonnull;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Configurable;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="nc" id="L43">@Configurable @Aspect @Slf4j</span>
<span class="nc bnc" id="L44" title="All 22 branches missed.">public class DebugProfilingAspect </span>
  {
//    @Around(&quot;execution(@it.tidalwave.northernwind.aspect.DebugProfiling * *(..))&quot;) FIXME: requires aspectj plugin 1.5
    @Around(&quot;execution(* it.tidalwave.northernwind.frontend.media.impl.EmbeddedMediaMetadataProvider.getMetadataString(..))&quot;)
    public Object advice (@Nonnull final ProceedingJoinPoint pjp)
      throws Throwable
      {
<span class="nc" id="L51">        log.debug(&quot;getMetadataString({})&quot;, pjp.getArgs());</span>
<span class="nc" id="L52">        final var time = System.currentTimeMillis();</span>
        
<span class="nc" id="L54">        final var result = pjp.proceed();</span>
        
<span class="nc bnc" id="L56" title="All 2 branches missed.">        if (log.isDebugEnabled())</span>
          {
<span class="nc" id="L58">            final var annotation = getAnnotation(pjp, DebugProfiling.class);</span>
<span class="nc" id="L59">            log.debug(&quot;&gt;&gt;&gt;&gt; {} in {} msec&quot;, annotation.message(), System.currentTimeMillis() - time);</span>
          }

<span class="nc" id="L62">        return result;</span>
      }
    
    // See http://stackoverflow.com/questions/2559255/spring-aop-how-to-get-the-annotations-of-the-adviced-method
    @Nonnull
    private static &lt;T extends Annotation&gt; T getAnnotation (@Nonnull final ProceedingJoinPoint pjp,
                                                           @Nonnull final Class&lt;T&gt; annotationClass)
      throws NoSuchMethodException
      {
<span class="nc" id="L71">        final var methodSignature = (MethodSignature)pjp.getSignature();</span>
<span class="nc" id="L72">        var method = methodSignature.getMethod();</span>
        
<span class="nc bnc" id="L74" title="All 2 branches missed.">        if (method.getDeclaringClass().isInterface()) // FIXME &amp;&amp; annotation inheritance -- FIXME also ancestor class</span>
also ancestor class
{ <span class="nc" id="L76"> final var methodName = pjp.getSignature().getName();</span> <span class="nc" id="L77"> method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes()); </span> } <span class="nc" id="L80"> return method.getAnnotation(annotationClass);</span> } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>