Skip to content

Commit

Permalink
OneBranch Builds Legacy-SDK (#1407)
Browse files Browse the repository at this point in the history
* add pipeline config
add install java scripts

* added missing version/environment sections
fixed exit command option
added tag for buddy builds

* fix unclosed file handle in build task

* moves scripts to ./.scripts
added versioning script

* Try different download method
fix gradlew.bat paths
fix exit code in restore.cmd

* put all commands in scripts
rename scripts to match taskname

* update directory in scripts

* add dir check

* try pushd/popd

* print pwd

* use path in call cmd and project-dir for gradle

* try cd again

* try pushd a different way

* more variables; directory check

* attempt setting rootProject.name

* added template for gradle tasks from a pipeline
added conditional to check for sdk-version file
updated other scripts to use template format

* add resolveDependencies task
try splitting restore commands

* added gradle proxy script
deleted other gradle cmds
added arguments to yml
moved restore tasks back to windows.yml

* remove unneeded package-info

* skipWinNative for for now.
add installJava7 script

* fix filename/dirname parsing

* enable native build
stub windows sdk installer script

* update resolveDependencies task to use all configurations

* only set tools directories if they are changed

* added some additonal logging during native build configuration

* add script to install windows 8.1 sdk

* move function definitions above calls

* Fix Download-File function

* typo

* reorder restore commands

* add arguments to windows sdk installer

* fix options for win sdk installer
set env var with win sdk installation directory

* set logs dir for installer script

* fix syntax error in yml

* upgrade gradle to 5.6.4

* upgrade spotbugs
suppress java 11 try-with-resources bug

* clean up build logging

* added comment about installer options for win sdk

* disable spotbugsTest

* update spotbugs to only use main configuration

* add buildfile for :test superproject so its subprojects can be built independently

* updated commands to build whole project
split assemble, checks and unit tests into separate tasks
stubbed in collectd restore command

* add default signing profile

* upgrade gradle to latest version

* fix typo

* add signing for dlls

* fix tests paths.
split results into their respective projects.

* fix path to script

* use all_* wildcards in build def names.
add missing "sign_inline" option to dlls.

* enable policheck for windows buddy builds

* fix filename

* updated signing exclusions.
trying different pattern for DLL signing.

* move test commands to test stage

* update artifact publish options to try to remove duplicate artifacts.

* fix version section for buddy builds

* updated native build to always output both release and debug DLLs.
simplify some configuration.

* publish DLLs to their own artifact output location

* revert some version properties.
supply version.name to buddy build.

* add capture of native logs

* fix native build condition

* move version sections to buddy/official

* move build phase to buddy/official definitions.
add default options to gradle.cmd

* add option to prevent building over prebuilt DLLs.
fix artifact excludes for perfcounter dlls.

* include --info in default gradle options

* fix prebuilt condition to disable tasks and still consume built dlls

* save dependency lockfiles

* update testresults patterns

* set warning mode in default gradle options

* add smoketest configuration

* remove reference to DOCKER_CLI_EXE; not used

* change root path for winsdk install logs

* remove dump of installed software after each installation.

* remove use of reserved var name in ps script

* remove check for module; fail if not found

* list  disk/installed programs info at end of restore

* add step to find docker exe

* remove unused functions

* resolve powershell warnings

* move find docker to top

* move versioning section to windows build definition

* add collectd build definition and scripts

* add artifacts clause to collectd build def

* update source_mode in windows build

* add runtime section to collectd build def

* add missing name field

* export collectd_home var

* fix image name

* update packages first

* rework collectd script;
simplifying and fixing directory issues

* fix directory on build script

* use specific paths for gradlew

* fix stderr redirect

* fix condition for directory check

* typo

* resolve collectd dependencies in restore phase

* set java7 env var

* set env vars in build script

* removed files related to official build

* ignore static analysis for now

* remove unused build definition

* remove unneeded step

* remove unused script

* suppress spotbugs seeing fixed bug

* upgrade xstream. regenerate lockfiles.

* split collectd build into buddy/official
(remove snapshot tag from official)

* split build into official/buddy;
isRelease=true on official

* Update lockfiles

* Use Java 8

* Delete unused scripts

* Use java 8 JDK instead of JRE

* Fix build failure on OneBranch

* Remove JAVA_JRE_7

* Add back JAVA_JRE_7

* Upgrade gradle to 6.8.3

* Fix listTestApps

* Add release scripts

* Done release pipeline testing, revert version back

* Copy more files required by Maven

* Invoke gradle task prepare

* Skip code signing

* Test legacy-sdk release pipeline

* Need to copy 36 files to maven

* Comment out collectd for now since thers is no bits generated

* Add collectd-api.jar to source

* Remove exception

* Enable collectd

* Done testing and revert version

* Re-trigger build to fix the linked required pipeline

* Get rid of the old legacy-sdk pipeline

* Some cleanup

* Fix spotbugs

* remove duplicate

Co-authored-by: Trask Stalnaker <[email protected]>

* delete duplicate

Co-authored-by: Trask Stalnaker <[email protected]>

* Simplification

Co-authored-by: Trask Stalnaker <[email protected]>

* Remove an .idea file

* Delete signing on the buddy build

* Fix VerifyJava7

* Update xmlpull path

Co-authored-by: Trask Stalnaker <[email protected]>

Co-authored-by: Helen Yang <[email protected]>
Co-authored-by: Trask Stalnaker <[email protected]>
Co-authored-by: Helen Y <[email protected]>
  • Loading branch information
4 people authored Mar 26, 2021
1 parent 130683b commit 8f54627
Show file tree
Hide file tree
Showing 56 changed files with 2,836 additions and 269 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ gradle-app.setting
.idea/tasks.xml
.idea/dictionaries

# Ignore iml
.idea/ApplicationInsights-Java.iml

# Sensitive or high-churn files:
.idea/dataSources.ids
Expand Down
3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions .pipelines/pipeline.user.windows.buddy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version:
major: 0
minor: 0
tag: 'SNAPSHOT'
name: 'ApplicationInsights-Java'
system: 'custom'
build:
commands:
- !!buildcommand
name: 'Assemble Perf Counters DLL'
command: '.scripts/gradle.cmd'
arguments: ':core:windowsSharedLibrary'
artifacts:
- from: 'core/build/libs/windows/shared'
include:
- '**/*'
exclude:
- '**/*.pdb'
logs:
- to: 'PerfCounters DLL Build Logs'
from: 'core/build/tmp'
include:
- '*WindowsCpp/*'
- !!buildcommand
name: 'Assemble ApplicationInsights-Java JARs'
command: '.scripts/gradle.cmd'
arguments: 'assemble prepare -Pcore.native.artifacts.prebuilt=true'
artifacts:
- to: 'Artifacts'
include:
- '**/build/libs/*.jar'
- '**/build/libs/*-sources.jar'
- '**/build/libs/*-javadoc.jar'
- '**/build/libs/*.pom'
exclude:
- 'logging/common/**/*'
- 'ApplicationInsightsInternalLogger/**/*'
- 'buildSrc/**/*'
44 changes: 44 additions & 0 deletions .pipelines/pipeline.user.windows.official.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version:
major: 0
minor: 0
name: 'ApplicationInsights-Java'
system: 'custom'
static_analysis_options:
policheck_options:
disable_tool_scan: false
fail_on_error: true
build:
commands:
- !!buildcommand
name: 'Assemble Perf Counters DLL'
command: '.scripts/gradle.cmd'
arguments: ':core:windowsSharedLibrary'
artifacts:
- from: 'core/build/libs/windows/shared'
include:
- '**/*'
exclude:
- '**/*.pdb'
signing_options:
profile: external_distribution
sign_inline: true
logs:
- to: 'PerfCounters DLL Build Logs'
from: 'core/build/tmp'
include:
- '*WindowsCpp/*'
- !!buildcommand
name: 'Assemble ApplicationInsights-Java JARs'
command: '.scripts/gradle.cmd'
arguments: 'assemble prepare -Pcore.native.artifacts.prebuilt=true -DisRelease=true'
artifacts:
- to: 'Artifacts'
include:
- '**/build/libs/*.jar'
- '**/build/libs/*-sources.jar'
- '**/build/libs/*-javadoc.jar'
- '**/build/libs/*.pom'
exclude:
- 'logging/common/**/*'
- 'ApplicationInsightsInternalLogger/**/*'
- 'buildSrc/**/*'
69 changes: 69 additions & 0 deletions .pipelines/pipeline.user.windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
environment:
host:
os: 'windows'
flavor: 'server'
version: '2019'
runtime:
provider: 'appcontainer'
image: 'cdpxwin1809.azurecr.io/global/vse2019:latest'
source_mode: 'link'
versioning:
commands:
- !!defaultcommand
name: 'Generate Version'
command: '.scripts/version.cmd'
static_analysis_options:
policheck_options:
disable_tool_scan: false
fail_on_error: true
signing_options:
profile: 'none'
restore:
commands:
- !!defaultcommand
name: 'Install Windows 8.1 SDK'
command: '.scripts/installWindows81SDK.cmd'
logs:
- from: 'WinSdkInstall'
to: 'WinSdkInstall'
include:
- '**/*.log'
- !!defaultcommand
name: 'Install Java 7 JRE'
command: '.scripts/installJava7jre.cmd'
- !!defaultcommand
name: 'Install Java 8 JDK'
command: '.scripts/installJava8jdk.cmd'
- !!defaultcommand
name: 'Clean and Resolve Dependencies'
command: '.scripts/gradle.cmd'
arguments: 'clean resolveDependencies --refresh-dependencies'
- !!defaultcommand
name: 'List Installation Information'
command: '.scripts/dumpInstallationInfo.cmd'
test:
commands:
# - !!defaultcommand
# name: 'Gradle Static Analysis'
# command: '.scripts/gradle.cmd'
# arguments: 'check -x test'
# logs:
# - to: 'Checks Reports'
# include:
# - '**/build/reports/**/*'
# exclude:
# - '**/build/reports/tests/**/*'
- !!testcommand
name: 'ApplicationInsights-Java Unit Tests'
command: '.scripts/gradle.cmd'
arguments: 'test'
fail_on_stderr: false
testresults:
- title: ':Unit Test Results'
type: 'junit'
include:
- '**/build/test-results/test/**/*'
logs:
- to: 'Test Logs'
include:
- '**/build/reports/tests/**/*'
4 changes: 4 additions & 0 deletions .pipelines/pipeline.user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
artifact_publish_options:
publish_to_legacy_artifacts: false
publish_to_pipeline_artifacts: true
publish_to_cloudvault_artifacts: false
89 changes: 89 additions & 0 deletions .scripts/copyBitsToAzureBlob.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
param (
[Parameter(Mandatory=$true, HelpMessage="azuresdkpartnerdrops service principal key")]
[ValidateNotNullOrEmpty()]
[string]$ServicePrincipalKey,

[Parameter(Mandatory=$true, HelpMessage="azuresdkpartnerdrops Service principal client ID")]
[ValidateNotNullOrEmpty()]
[string]$ServicePrincipleClientId,

[Parameter(Mandatory=$true, HelpMessage="Agent Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$AgentJarPath,

[Parameter(Mandatory=$true, HelpMessage="Collectd Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$CollectdJarPath,

[Parameter(Mandatory=$true, HelpMessage="Core Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$CoreJarPath,

[Parameter(Mandatory=$true, HelpMessage="Logging-log4j1_2 Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$Log4j1_2JarPath,

[Parameter(Mandatory=$true, HelpMessage="Logging-log4j2 Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$Log4j2JarPath,

[Parameter(Mandatory=$true, HelpMessage="Logging-logback Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$LogbackJarPath,

[Parameter(Mandatory=$true, HelpMessage="Spring Boot Starter Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$SpringBootStarterJarPath,

[Parameter(Mandatory=$true, HelpMessage="Web Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$WebJarPath,

[Parameter(Mandatory=$true, HelpMessage="Web Auto Jar Path")]
[ValidateNotNullOrEmpty()]
[string]$WebAutoJarPath,

[Parameter(Mandatory=$true, HelpMessage="applicationinsights-java version")]
[ValidateNotNullOrEmpty()]
[string]$SDKVersionNumber
)

$Env:AZCOPY_SPA_CLIENT_SECRET=$ServicePrincipalKey
azcopy login --service-principal --application-id $ServicePrincipleClientId
azcopy copy "$AgentJarPath/applicationinsights-agent-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$AgentJarPath/applicationinsights-agent-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$AgentJarPath/applicationinsights-agent-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$AgentJarPath/applicationinsights-agent-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CollectdJarPath/applicationinsights-collectd-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CollectdJarPath/applicationinsights-collectd-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CollectdJarPath/applicationinsights-collectd-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CollectdJarPath/applicationinsights-collectd-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CoreJarPath/applicationinsights-core-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CoreJarPath/applicationinsights-core-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CoreJarPath/applicationinsights-core-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$CoreJarPath/applicationinsights-core-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j1_2JarPath/applicationinsights-logging-log4j1_2-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j1_2JarPath/applicationinsights-logging-log4j1_2-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j1_2JarPath/applicationinsights-logging-log4j1_2-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j1_2JarPath/applicationinsights-logging-log4j1_2-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j2JarPath/applicationinsights-logging-log4j2-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j2JarPath/applicationinsights-logging-log4j2-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j2JarPath/applicationinsights-logging-log4j2-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$Log4j2JarPath/applicationinsights-logging-log4j2-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$LogbackJarPath/applicationinsights-logging-logback-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$LogbackJarPath/applicationinsights-logging-logback-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$LogbackJarPath/applicationinsights-logging-logback-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$LogbackJarPath/applicationinsights-logging-logback-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$SpringBootStarterJarPath/applicationinsights-spring-boot-starter-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$SpringBootStarterJarPath/applicationinsights-spring-boot-starter-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$SpringBootStarterJarPath/applicationinsights-spring-boot-starter-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$SpringBootStarterJarPath/applicationinsights-spring-boot-starter-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebJarPath/applicationinsights-web-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebJarPath/applicationinsights-web-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebJarPath/applicationinsights-web-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebJarPath/applicationinsights-web-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebAutoJarPath/applicationinsights-web-auto-$SDKVersionNumber.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebAutoJarPath/applicationinsights-web-auto-$SDKVersionNumber-javadoc.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebAutoJarPath/applicationinsights-web-auto-$SDKVersionNumber-sources.jar" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
azcopy copy "$WebAutoJarPath/applicationinsights-web-auto-$SDKVersionNumber.pom" "https://azuresdkpartnerdrops.blob.core.windows.net/drops/applicationinsights-sdk/java/$SDKVersionNumber/"
Remove-Item Env:AZCOPY_SPA_CLIENT_SECRET
5 changes: 5 additions & 0 deletions .scripts/dumpInstallationInfo.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off

echo "Listing installed software..."
powershell -NoProfile -ExecutionPolicy Unrestricted -File "%~dp0List-Programs.ps1" || exit /B 1
echo "Finished listing installed software."
15 changes: 15 additions & 0 deletions .scripts/generateVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To generate a custom version with "M.m.p.yyyymmdd<build_count_of_day>"
$path = "core\build\src\generated\main\resources\sdk-version.properties"
if (-Not (Test-Path -Path $path -PathType Leaf)) {
Write-Error -Message "'$path' does not exist" -Category ObjectNotFound
exit 2
}
$versionProps = ConvertFrom-StringData (Get-Content $path -Raw)
Write-Host "Read from sdk-version.properties: " $versionProps.version
$matchObj = ($versionProps.version | Select-String -Pattern "^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<tag>.*))?")
$major, $minor, $patch, $tag = $matchObj.Matches[0].Groups['major', 'minor','patch','tag'].Value
$date = Get-Date -UFormat "%Y%m%d"
$revision = "$date$env:CDP_DEFINITION_BUILD_COUNT_DAY"
$buildNumber = "$major.$minor.$patch.$revision"
[Environment]::SetEnvironmentVariable("CustomBuildNumber", $buildNumber, "User") # This will allow you to use it from env var in later steps of the same phase
Write-Host "##vso[build.updatebuildnumber]${buildNumber}"
20 changes: 20 additions & 0 deletions .scripts/gradle.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off
setlocal

pushd %~dp0
set SCRIPT_ROOT=%CD%
popd

pushd %~dp0..
set PROJECT_ROOT=%CD%

set DEFAULT_OPTIONS=--info --stacktrace -DisBuildServer=true --warning-mode=all
set GRADLE_CMD=gradlew.bat %DEFAULT_OPTIONS% %*
echo Running '%GRADLE_CMD%' in '%PROJECT_ROOT%'
call %GRADLE_CMD%
if errorlevel 1 (
echo Error running '%GRADLE_CMD%' in '%PROJECT_ROOT%'
exit /b 1
)
popd
endlocal
74 changes: 74 additions & 0 deletions .scripts/install-azcopy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
param (
[Parameter(Mandatory=$true, HelpMessage="Url to download. Must point to a zip file. Assumes filename is last path element. Assumes zip contains top level directory with same name as zip file.")]
[ValidateNotNullOrEmpty()]
[string]$Url,

[Parameter(Mandatory=$true, HelpMessage="Destination directory to unzip downloaded file.")]
[ValidateNotNullOrEmpty()]
[System.IO.FileInfo]$Destination,

[Parameter(HelpMessage="When used, adds bin directory to PATH.")]
[switch]$UpdatePath = $false,

[Parameter(HelpMessage="When used, downloads directory will be cleaned and temp directories cleaned.")]
[switch]$CleanOnFinish = $false,

[Parameter(Mandatory=$false, HelpMessage="7Zip location. Should point to 7z.exe.")]
[ValidateNotNullOrEmpty()]
[System.IO.FileInfo]$PathTo7Zip,

[Parameter(Mandatory=$false, HelpMessage="Skips download step.")]
[switch]$SkipDownload = $false,

[Parameter(Mandatory=$false, HelpMessage="Skips unzip.")]
[switch]$SkipUnzip = $false
)

$fileName, $dirName = ($Url | Select-String -Pattern ".+/(?<filename>(?<dirname>[^/]+)\..+)$").Matches[0].Groups['filename', 'dirname'].Value
$Source = [System.IO.Path]::Combine("C:\Downloads", $fileName)

$ErrorActionPreference = "Stop"
Import-Module "$PSScriptRoot\win-installer-helper.psm1" -DisableNameChecking

Start-Setup

$PathNodes=@()
try
{
if (-not $SkipDownload) {
Write-Host "Downloading '$fileName' from '$Url' to '$Source'"
Get-File -Url $url -FileName $fileName
Write-Host "Download finished: $Source"
}
else
{
Write-Host "Skipping download."
if (-not (Test-Path $Source)) {
Write-Error "$Source does not exist"
exit
}
}

if (-not $SkipUnzip)
{
Write-Host "Unzipping $Source to $Destination"
Expand-Archive -LiteralPath $Source -Destination $Destination -Force
Write-Host "Finished unzipping to $Destination"
}
}
finally
{
if (!$PathNodes -eq "")
{
Write-Host "Appending to PATH: '$PathNodes'"
Update-Path -PathNodes $PathNodes
}
if ($CleanOnFinish)
{
Stop-Setup
}
else
{
Stop-Setup -PreserveTemp -PreserveDownloads
}
}
Loading

0 comments on commit 8f54627

Please sign in to comment.