Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for unreleased dependencies #6989

Merged
merged 2 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions eng/versioning/pom_file_version_scanner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ $DependencyTypeForError = "$($DependencyTypeCurrent)|$($DependencyTypeDependency
$UpdateTagFormat = "{x-version-update;<groupId>:<artifactId>;$($DependencyTypeForError)}"
$StartTime = $(get-date)

function Write-Error-With-Color([string]$msg)
{
Write-Host "$($msg)" -ForegroundColor Red
}

# The expected format for a depenency, as found in the eng\versioning\version_*.txt files, is as follows:
# groupId:artifactId;dependency-version;current-version
class Dependency {
Expand All @@ -49,15 +54,18 @@ class Dependency {
[string]$inputString
){
$split = $inputString.Split(";")
if ($split.Count -ne 3)
if (($split.Count -ne 3) -and ($split.Count -ne 2))
{
# throw and let the caller handle the error since it'll have access to the
# filename of the file with the malformed line for reporting
throw
}
$this.id = $split[0]
$this.depVer = $split[1]
$this.curVer = $split[2]
if ($split.Count -eq 3)
{
$this.curVer = $split[2]
}
}
}

Expand Down Expand Up @@ -188,6 +196,11 @@ function Test-Dependency-Tag-And-Version {
}
elseif ($depType -eq $DependencyTypeCurrent)
{
# Verify that none of the 'current' dependencies are using a groupId that starts with 'unreleased_'
if ($depKey.StartsWith('unreleased_'))
{
return "Error: $($versionUpdateString) is using an unreleased_ dependency and trying to set current value. Only dependency versions can be set with an unreleased dependency."
}
if ($versionString -ne $libHash[$depKey].curVer)
{
return "Error: $($depKey)'s <version> is '$($versionString)' but the current version is listed as $($libHash[$depKey].curVer)"
Expand Down Expand Up @@ -239,11 +252,11 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
return
}
}
Write-Output "processing pomFile=$($pomFile)"
Write-Host "processing pomFile=$($pomFile)"
$dependencyManagement = $xmlPomFile.GetElementsByTagName("dependencyManagement")[0]
if ($dependencyManagement)
{
Write-Output "Error: <dependencyManagement> is not allowed. Every dependency must have its own version and version update tag"
Write-Error-With-Color "Error: <dependencyManagement> is not allowed. Every dependency must have its own version and version update tag"
}

# Ensure that the project has a version tag with the exception of projects under the eng directory which
Expand All @@ -266,7 +279,7 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
{
$script:FoundError = $true
# every project string needs to have an update tag and projects version tags are always 'current'
Write-Output "Error: project/version update tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
Write-Error-With-Color "Error: project/version update tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
}
else
{
Expand All @@ -275,7 +288,7 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($retVal)
{
$script:FoundError = $true
Write-Output "$($retVal)"
Write-Host "$($retVal)"
}
}
}
Expand All @@ -284,15 +297,15 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
$script:FoundError = $true
# <!-- {x-version-update;<groupId>:<artifactId>;current} -->
# every project string needs to have an update tag and projects version tags are always 'current'
Write-Output "Error: Missing project/version update tag. The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
Write-Error-With-Color "Error: Missing project/version update tag. The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
}

}
else
{
# output an error for missing version element
$script:FoundError = $true
Write-Output "Error: Could not find project/version node for $($pomFile)"
Write-Error-With-Color "Error: Could not find project/version node for $($pomFile)"
}
}

Expand All @@ -310,7 +323,7 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($versionNode.NextSibling.Value.Trim() -ne "{x-version-update;$($groupId):$($artifactId);current}")
{
$script:FoundError = $true
Write-Output "Error: project/parent/version update tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
Write-Error-With-Color "Error: project/parent/version update tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
}
else
{
Expand All @@ -319,22 +332,22 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($retVal)
{
$script:FoundError = $true
Write-Output "$($retVal)"
Write-Host "$($retVal)"
}
}
}
else
{
$script:FoundError = $true
# every project string needs to have an update tag and projects version tags are always 'current'
Write-Output "Error: Missing project/parent/version update tag. The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
Write-Error-With-Color "Error: Missing project/parent/version update tag. The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current} -->"
}
}
else
{
# output an error for missing version element
$script:FoundError = $true
Write-Output "Error: Could not find project/parent/version node for $($pomFile)"
Write-Error-With-Color "Error: Could not find project/parent/version node for $($pomFile)"
}
}

Expand All @@ -348,7 +361,7 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if (!$versionNode)
{
$script:FoundError = $true
Write-Output "Error: dependency is missing version element for groupId=$($groupId), artifactId=$($artifactId) should be <version></version> <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
Write-Error-With-Color "Error: dependency is missing version element for groupId=$($groupId), artifactId=$($artifactId) should be <version></version> <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
continue
}
if ($versionNode.NextSibling -and $versionNode.NextSibling.NodeType -eq "Comment")
Expand All @@ -358,7 +371,7 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($versionNode.NextSibling.Value.Trim() -notmatch "{x-version-update;(\w+)?$($groupId):$($artifactId);\w+}")
{
$script:FoundError = $true
Write-Output "Error: dependency version update tag for groupId=$($groupId), artifactId=$($artifactId) should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
Write-Error-With-Color "Error: dependency version update tag for groupId=$($groupId), artifactId=$($artifactId) should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
}
else
{
Expand All @@ -367,14 +380,14 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($retVal)
{
$script:FoundError = $true
Write-Output "$($retVal)"
Write-Error-With-Color $retVal
}
}
}
else
{
$script:FoundError = $true
Write-Output "Error: Missing dependency version update tag for groupId=$($groupId), artifactId=$($artifactId). The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
Write-Error-With-Color "Error: Missing dependency version update tag for groupId=$($groupId), artifactId=$($artifactId). The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
}
}
# Verify every plugin has a group, artifact and version
Expand All @@ -388,14 +401,14 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if (!$groupId)
{
$script:FoundError = $true
Write-Output "Error: plugin $($artifactId) is missing its groupId tag"
Write-Error-With-Color "Error: plugin $($artifactId) is missing its groupId tag"
continue
}
$versionNode = $pluginNode.GetElementsByTagName("version")[0]
if (!$versionNode)
{
$script:FoundError = $true
Write-Output "Error: plugin is missing version element for groupId=$($groupId), artifactId=$($artifactId) should be <version></version> <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
Write-Error-With-Color "Error: plugin is missing version element for groupId=$($groupId), artifactId=$($artifactId) should be <version></version> <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
continue
}
if ($versionNode.NextSibling -and $versionNode.NextSibling.NodeType -eq "Comment")
Expand All @@ -405,7 +418,7 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($versionNode.NextSibling.Value.Trim() -notmatch "{x-version-update;(\w+)?$($groupId):$($artifactId);\w+}")
{
$script:FoundError = $true
Write-Output "Error: plugin version update tag for groupId=$($groupId), artifactId=$($artifactId) should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
Write-Error-With-Color "Error: plugin version update tag for groupId=$($groupId), artifactId=$($artifactId) should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
}
else
{
Expand All @@ -414,25 +427,25 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
if ($retVal)
{
$script:FoundError = $true
Write-Output "$($retVal)"
Write-Host "$($retVal)"
}
}
}
else
{
$script:FoundError = $true
Write-Output "Error: Missing plugin version update tag for groupId=$($groupId), artifactId=$($artifactId). The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
Write-Error-With-Color "Error: Missing plugin version update tag for groupId=$($groupId), artifactId=$($artifactId). The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
}
}
}
$ElapsedTime = $(get-date) - $StartTime
$TotalRunTime = "{0:HH:mm:ss}" -f ([datetime]$ElapsedTime.Ticks)
Write-Output "Total run time=$($TotalRunTime)"
Write-Host "Total run time=$($TotalRunTime)"

if ($script:FoundError)
{
Write-Output "There were errors encountered during execution. Please fix any errors and run the script again."
Write-Output "This script can be run locally from the root of the repo. .\eng\pom_file_version_scanner.ps1"
Write-Host "There were errors encountered during execution. Please fix any errors and run the script again."
Write-Host "This script can be run locally from the root of the repo. .\eng\pom_file_version_scanner.ps1"
exit(1)
}

Loading