Skip to content

Commit

Permalink
Merge pull request #3 from froque/project_injection
Browse files Browse the repository at this point in the history
Use injection for maven project instead of reading from pom.xml
  • Loading branch information
jonathanlermitage authored Nov 11, 2020
2 parents 71fb61d + afa64f3 commit 3d45c06
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/main/java/biz/lermitage/oga/CheckMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugin.MojoExecutionException
import org.apache.maven.plugins.annotations.Mojo
import org.apache.maven.plugins.annotations.Parameter
import org.apache.maven.project.MavenProject
import org.codehaus.plexus.util.xml.pull.XmlPullParserException
import java.io.File
import java.io.FileReader
import java.io.IOException
import java.net.URL


/**
* Goal which checks that no dependency uses a deprecated groupId.
*
Expand All @@ -27,6 +29,9 @@ class CheckMojo : AbstractMojo() {
@Parameter(name = "ogDefinitionsUrl")
private val ogDefinitionsUrl: String? = null

@Parameter(property = "project", readonly = true)
var project: MavenProject? = null

/**
* Execute goal.
*/
Expand All @@ -38,8 +43,7 @@ class CheckMojo : AbstractMojo() {
val definitions = URL(ogDefinitionsUrl ?: DEFINITIONS_URL).let { IOTools.readDefinitionsFromUrl(it) }
log.debug("Loaded definitions file version: ${definitions.version}, ${definitions.date}")

val model = readModel(File("pom.xml"))
val dependencies = listDependencies(model)//.filter { dep -> !definitions.whitelist!!.contains("${dep.groupId}:${dep.artifactId}") }
val dependencies = project?.dependencies!!.filterNotNull()
val deprecatedDependencies: HashSet<String> = HashSet()
log.info("Checking dependencies...")

Expand Down Expand Up @@ -87,22 +91,6 @@ class CheckMojo : AbstractMojo() {
}
}

@Throws(IOException::class, XmlPullParserException::class)
private fun readModel(pomFile: File?): Model {
// parse pom.xml, see https://stackoverflow.com/questions/4838591/is-there-a-library-for-reading-maven2-3-pom-xml-files
return MavenXpp3Reader().read(FileReader(pomFile!!))
}

private fun listDependencies(model: Model): List<Dependency> {
log.debug("Listing dependencies:")
val dependencies = model.dependencies
dependencies.sortWith(Comparator { o1, o2 -> ("${o1.groupId}:${o1.artifactId}").compareTo("${o2.groupId}:${o2.artifactId}") })
for (dep in dependencies) {
log.debug(" ${dep.groupId}:${dep.artifactId}")
}
return dependencies
}

/*private fun isDeprecatedOnMavencentral(groupId: String, artifactId: String): Boolean {
return try {
val url = "https://mvnrepository.com/artifact/$groupId/$artifactId"
Expand Down

0 comments on commit 3d45c06

Please sign in to comment.