Commits

Samuel Le Berrigaud committed 132ab7d

Small refactorings…

  • Participants
  • Parent commits 862698c

Comments (0)

Files changed (4)

-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
-
     <parent>
         <groupId>com.atlassian.pom</groupId>
         <artifactId>atlassian-public-pom</artifactId>
-        <version>18</version>
+        <version>20</version>
     </parent>
 
     <groupId>com.atlassian.maven.plugins</groupId>
-    <artifactId>atlassian-maven-plugin</artifactId>
+    <artifactId>maven-dependency-tracker-plugin</artifactId>
     <version>1.0-SNAPSHOT</version>
     <packaging>maven-plugin</packaging>
-    <name>Atlassian Maven Plugin</name>
+    <name>Atlassian Maven Dependency Tracker Plugin</name>
 
     <scm>
         <connection>scm:svn:https://labs.atlassian.com/svn/MAP/trunk</connection>

File src/main/groovy/com/atlassian/maven/plugins/AbstractMapMojo.groovy

-package com.atlassian.maven.plugins
-
-import com.atlassian.maven.plugins.DependencyReportLine
-import org.apache.maven.project.MavenProject
-import org.codehaus.groovy.maven.mojo.GroovyMojo
-
-abstract class AbstractMapMojo extends GroovyMojo
-{
-    static final String UKNOWN_MD5 = '?'
-
-    /**
-     * The Maven Project
-     *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
-     */
-    MavenProject project
-
-    /**
-     *
-     * @parameter expression="${atlassian.dependency.report.file}" default-value="dependencies.txt"
-     * @required
-     * @readonly
-     */
-    String reportFileName = 'dependencies.txt'
-
-    SortedSet<DependencyReportLine> reportLines()
-    {
-        final SortedSet report = new TreeSet()
-        project.artifacts.each { report.add(DependencyReportLine.from(it, md5(it))) }
-        return report
-    }
-
-    String md5(artifact)
-    {
-        if (!artifact.file?.exists())
-        {
-            println "File for $artifact doesn't exists"
-            return UKNOWN_MD5
-        }
-        else
-        {
-            def checksumName = "${artifact.file.name}.md5"
-            ant.checksum(file: artifact.file, property: checksumName)
-            return ant.project.properties[checksumName]
-        }
-    }
-
-    void writeReportToFile(String fileName, Set report)
-    {
-        new File(fileName).withWriter {writer -> report.each { writer << "$it\n" } }
-    }
-}

File src/main/groovy/com/atlassian/maven/plugins/GenerateDependenciesReportMojo.groovy

 package com.atlassian.maven.plugins
 
-import com.atlassian.maven.plugins.AbstractMapMojo
-
 /**
  *
  * @requiresDependencyResolution test
  * @goal dependencies-report
  */
-class GenerateDependenciesReportMojo extends AbstractMapMojo
+class GenerateDependenciesReportMojo extends AbstractDependencyTrackerMojo
 {
     void execute()
     {

File src/main/groovy/com/atlassian/maven/plugins/ValidateDepdendenciesMojo.groovy

-package com.atlassian.maven.plugins
-
-import com.atlassian.maven.plugins.AbstractMapMojo
-import com.atlassian.maven.plugins.DependencyReportLine
-import org.apache.commons.collections.CollectionUtils
-import org.apache.maven.plugin.MojoFailureException
-
-/**
- * @requiresDependencyResolution test
- * @goal validate-dependencies
- * @phase validate
- */
-class ValidateDepdendenciesMojo extends AbstractMapMojo
-{
-    /**
-     *
-     * @parameter expression="${atlassian.dependency.skip}" default-value="false"
-     * @required
-     * @readonly
-     */
-    boolean skip = false
-
-    void execute()
-    {
-        if (skip)
-        {
-            log.info "Skipping dependency report validation"
-            return 
-        }
-
-        final File report = new File(reportFileName)
-        if (!report?.exists())
-        {
-            log.warn("$report.absolutePath doesn't exists, won't validate dependencies")
-            return
-        }
-
-        def fileReport = report.readLines().collect { DependencyReportLine.from(it) }
-        def runtimeReport = reportLines()
-
-        def newDependencies = CollectionUtils.subtract(runtimeReport, fileReport)
-        def removedDependencies = CollectionUtils.subtract(fileReport, runtimeReport)
-
-        if (!newDependencies && !removedDependencies)
-        {
-            log.debug "Calculated dependencies are the same as in the report"
-            return
-        }
-
-        log.error "The following dependencies are not present in the report:"
-        newDependencies.each { log.error "\t$it" }
-        log.error "The following dependencies are present in the report but no longer calculated:"
-        removedDependencies.each { log.error "\t$it" }
-
-        String fileName = "${reportFileName}.tmp"
-        writeReportToFile(fileName, runtimeReport);
-
-        throw new MojoFailureException("The dependency report and your resolved dependencies are not in sync. An updated report has been written to <${new File(fileName).absolutePath}>")
-    }
-}