Hello community,

 

in the context of the upgrade to Eclipse Mars release moves the question “How do we know when an update is available?” in the foucus. Sure, on the one hand you can use Check for Updates item from Help menu in Eclipse, but for an administrator is it rather unusual to start an development environment like Eclipse. On the other hand you can use a script to check the availability of an update. Here is an example in PowerShell 5 which checks the artifacts and content XML files from tools.hana.ondemand.com. If differences are found between the previous and current download it opens a messagebox or alternatively it sends an e-mail. You can execute this script automatically e.g. at fixed time a day and if an update is available it informs you, otherwise nothing happens.

I think it is not difficult to transpose this script in other script languages.

#-Begin-----------------------------------------------------------------
#-
#- PowerShell script to check the availabilty of SAP Development Tools
#- for Eclipse updates based on the changes of artifacts.xml and
#- content.xml from https://tools.hana.ondemand.com
#-
#- Language: PowerShell 5
#- Author:   Stefan Schnell
#-
#-----------------------------------------------------------------------

  #-Sub EclUpdateAvailable----------------------------------------------
  #-
  #- Parameter $EclRel is the Eclipse releae, e.g. like mars or neon
  #-
  #---------------------------------------------------------------------
    Function EclUpdateAvailable($EclRel) {

      #-Set Date and Time variable for Timestamp------------------------
        $date = Get-Date -Format "yyyMMdd"
        $time = Get-Date -Format "HHmmss"
        $stamp = "_" + $date + "_" + $time

      #-Get the last files----------------------------------------------
        $artifactsLastFile = dir artifacts*.xml | Sort -Descending | `
          Select -First 1
        $contentLastFile = dir content*.xml | Sort -Descending | `
          Select -First 1

      #-Download artifacts.jar, expand and rename artifacts.xml---------
        $url = "https://tools.hana.ondemand.com/" + $EclRel + `
          "/artifacts.jar"
        $artifacts_zip = $PSScriptRoot + "\artifacts" + $stamp + ".zip"
        Invoke-WebRequest -Uri $url -OutFile $artifacts_zip
        Expand-Archive -Path $artifacts_zip `
          -DestinationPath $PSScriptRoot -Force
        Remove-Item $artifacts_zip
        $artifacts_xml = $PSScriptRoot + "\artifacts.xml"
        $artifacts_new = $PSScriptRoot + "\artifacts" + $stamp + ".xml"
        Rename-Item -Path $artifacts_xml -NewName $artifacts_new

      #-Download content.jar, expand and rename content.xml-------------
        $url = "https://tools.hana.ondemand.com/" + $EclRel + `
          "/content.jar"
        $content_zip = $PSScriptRoot + "\content" + $stamp + ".zip"
        Invoke-WebRequest -Uri $url -OutFile $content_zip
        Expand-Archive -Path $content_zip `
          -DestinationPath $PSScriptRoot -Force
        Remove-Item $content_zip
        $content_xml = $PSScriptRoot + "\content.xml"
        $content_new = $PSScriptRoot + "\content" + $stamp + ".xml"
        Rename-Item -Path $content_xml -NewName $content_new

      #-Compare artifacts.xml-------------------------------------------
        $artiRes = $false
        If ($artifactsLastFile) {
          If (((Get-FileHash $artifactsLastFile).hash) -ne `
            ((Get-FileHash $artifacts_new).hash)) {
            $artiRes = $true
          }
        }

      #-Compare content.xml---------------------------------------------
        $contRes = $false
        If ($contentLastFile) {
          If (((Get-FileHash $contentLastFile).hash) -ne `
            ((Get-FileHash $content_new).hash)) {
            $contRes = $true
          }
        }

      #-If artifacts.xml or content.xml have changed--------------------
        If ($artiRes -or $contRes) {
          #-Show messagebox---------------------------------------------
            $rc = [System.Windows.Forms.MessageBox]::Show( `
              "An SAP Development Tools for Eclipse update is available", `
              "Important hint", 0)
          #-Send email--------------------------------------------------
#            $outlook = New-Object -ComObject Outlook.Application
#            $mail = $outlook.CreateItem(0)
#            $mail.To = "stefan.schnell@mycompany.com"
#            $mail.Subject = "SAP Development Tools for Eclipse"
#            $mail.Body = "An SAP Development Tools for Eclipse " + `
#              "update is available"
#            $mail.Send()
        }

    }

  #-Sub Main------------------------------------------------------------
    Function Main() {
      EclUpdateAvailable "mars"
    }

  #-Main----------------------------------------------------------------
    If ($PSVersionTable.PSVersion.Major -ge 5) {
      Main
    }

#-End-------------------------------------------------------------------

 

Enjoy it.

 

Cheers

Stefan

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Łukasz Pęgiel

    Hello Stefan,

    nice one, but there is automatic check of updates in Eclipse and it does not require admin rights to do it as it’s only simple download and extract of packages. So what for to play with PowerShell ?

    /wp-content/uploads/2016/08/2016_08_03_10h27_57_1007952.png

    Cheers

    Łukasz

    (0) 
      1. Łukasz Pęgiel

        That’s what I thought. Funny fact is that I often do same stuff, means I don’t know about built-in feature / class / FM so I create the feature by myself. Then once I’ve done it someone tells me that it was really good, unnecessary work 🙂

        Cheers

        (0) 

Leave a Reply