package com.boissinot.jenkins.csvexporter.service.extractor.maven.pom.aspect;

import com.boissinot.jenkins.csvexporter.domain.jenkins.job.ConfigJob;
import com.boissinot.jenkins.csvexporter.service.extractor.maven.pom.RemotePOMURLStrategy;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author Gregory Boissinot
 */
@Component
@Aspect
public class PomExtractionLogger {

    private Logger logger = LoggerFactory.getLogger(PomExtractionLogger.class);

    @Pointcut("within(com.boissinot.jenkins.csvexporter.service.extractor.maven.pom.DeveloperInfoRetriever) && args(configJob, objects)")
    private void getDevelopersPointcut(ConfigJob configJob, Object... objects) {
    }

    @Before(value = "getDevelopersPointcut(configJob, objects)")
    private void logGetDevelopers(ConfigJob configJob, Object... objects) {
        if (logger.isDebugEnabled()) {
            String jobName = configJob.getName();
            logger.debug(String.format("Extracting POM URL for %s job.", jobName));
        }
    }

    @Pointcut("bean(svnRemotePOMURLStrategy) && args(configJob, objects) && target(remoteStrategy)")
    private void svnGetRemotePomURLPointcut(ConfigJob configJob, RemotePOMURLStrategy remoteStrategy, Object... objects) {
    }

    @Pointcut("bean(gitRemotePOMURLStrategy) && args(configJob, objects) && target(remoteStrategy)")
    private void gitGetRemotePomURLPointcut(ConfigJob configJob, RemotePOMURLStrategy remoteStrategy, Object... objects) {
    }

    @Pointcut("bean(cvsRemotePOMURLStrategy) && args(configJob, objects) && target(remoteStrategy)")
    private void cvsGetRemotePomURLPointcut(ConfigJob configJob, RemotePOMURLStrategy remoteStrategy, Object... objects) {
    }

    @AfterReturning(value = "svnGetRemotePomURLPointcut(configJob, remoteStrategy,objects) || gitGetRemotePomURLPointcut(configJob, remoteStrategy, objects) || cvsGetRemotePomURLPointcut(configJob, remoteStrategy, objects)", returning = "pomRemoteURL")
    private void svnLogGetRemotePomURLPointcut(ConfigJob configJob, RemotePOMURLStrategy remoteStrategy, String pomRemoteURL, Object... objects) {
        if (logger.isDebugEnabled()) {
            String jobName = configJob.getName();
            String beanName = remoteStrategy.getBeanName();
            logger.debug(String.format("Using Spring bean %s.", beanName));
            logger.debug(String.format("Extracted POM content for '%s' job.", jobName));
            if (pomRemoteURL == null) {
                logger.debug(String.format("Can't compute the remote %s POM URL", remoteStrategy.getType()));
                return;
            }
            logger.debug(String.format("The remote POM URL(%s URL) is '%s'.", remoteStrategy.getType(), pomRemoteURL));
        }
    }

}

@@ -234,16 +234,51 @@
 rategy;%0A
+import org.aspectj.lang.JoinPoint;%0A
 import o
@@ -1307,498 +1307,128 @@
 ut(%22
-bean(svnRemotePOMURLStrategy) && args(configJob, objects) && target(remoteStrategy)%22)%0A    private void svnGetRemotePomURLPointcut(ConfigJob configJob, RemotePOMURLStrategy remoteStrategy, Object... objects) %7B%0A    %7D%0A%0A    @Pointcut(%22bean(gitRemotePOMURLStrategy) && args(configJob, objects) && target(remoteStrategy)%22)%0A    private void gitGetRemotePomURLPointcut(ConfigJob configJob, RemotePOMURLStrategy remoteStrategy, Object... objects) %7B%0A    %7D%0A%0A    @Pointcut(%22bean(cvs
+execution(String com.boissinot.jenkins.csvexporter.service.extractor.maven.pom.RemotePOMURLStrategy.get
 RemoteP
-OMURLStrategy
+omURL(*,*)
 ) &&
@@ -1456,34 +1456,8 @@
 cts)
- && target(remoteStrategy)
 %22)%0A 
@@ -1472,23 +1472,17 @@
 te void 
-cvsGetR
+r
 emotePom
@@ -1517,45 +1517,8 @@
 Job,
- RemotePOMURLStrategy remoteStrategy,
  Obj
@@ -1575,191 +1575,38 @@
  = %22
-svnGetRemotePomURLPointcut(configJob, remoteStrategy,objects) %7C%7C gitGetRemotePomURLPointcut(configJob, remoteStrategy, objects) %7C%7C cvsGetRemotePomURLPointcut(configJob, remoteStrategy
+remotePomURLPointcut(configJob
 , ob
@@ -1663,12 +1663,9 @@
 oid 
-svnL
+l
 ogGe
@@ -1690,64 +1690,49 @@
 cut(
-ConfigJob configJob, RemotePOMURLStrategy remoteStrategy
+JoinPoint jointPoint, ConfigJob configJob
 , St
@@ -1852,32 +1852,129 @@
 gJob.getName();%0A
+            RemotePOMURLStrategy remoteStrategy = (RemotePOMURLStrategy) jointPoint.getTarget();%0A
             Stri

Enhance Pointcut