All files / src/background zcl_abapgit_background.clas.abap

100% Statements 167/167
100% Branches 0/0
100% Functions 0/0
100% Lines 167/167

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 1681x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_background DEFINITION
  PUBLIC
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    TYPES: BEGIN OF ty_method,
             class       TYPE seoclsname,
             description TYPE string,
           END OF ty_method.
 
    TYPES: ty_methods TYPE SORTED TABLE OF ty_method WITH UNIQUE KEY class.
 
    CLASS-METHODS run
      RAISING
        zcx_abapgit_exception .
 
    CLASS-METHODS list_methods
      RETURNING VALUE(rt_methods) TYPE ty_methods.
 
    CLASS-METHODS enqueue
      RAISING
        zcx_abapgit_exception.
 
    CLASS-METHODS dequeue.
  PROTECTED SECTION.
  PRIVATE SECTION.
    CONSTANTS c_enq_type TYPE c LENGTH 12 VALUE 'BACKGROUND'.
ENDCLASS.
 
 
 
CLASS zcl_abapgit_background IMPLEMENTATION.
 
 
  METHOD dequeue.
    CALL FUNCTION 'DEQUEUE_EZABAPGIT'
      EXPORTING
        type = c_enq_type.
  ENDMETHOD.
 
 
  METHOD enqueue.
    CALL FUNCTION 'ENQUEUE_EZABAPGIT'
      EXPORTING
        mode_zabapgit  = 'E'
        type           = c_enq_type
        _scope         = '3'
      EXCEPTIONS
        foreign_lock   = 1
        system_failure = 2
        OTHERS         = 3.
 
    IF sy-subrc <> 0.
      zcx_abapgit_exception=>raise_t100( ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD list_methods.
 
    DATA: ls_method       LIKE LINE OF rt_methods,
          ls_key          TYPE seoclskey,
          lt_implementing TYPE seor_implementing_keys,
          ls_implementing LIKE LINE OF lt_implementing.
 
    FIELD-SYMBOLS: <ls_method> LIKE LINE OF rt_methods.
 
 
* in order to handle local classes in the compiled report
    ls_method-class = 'ZCL_ABAPGIT_BACKGROUND_PULL'.
    INSERT ls_method INTO TABLE rt_methods.
    ls_method-class = 'ZCL_ABAPGIT_BACKGROUND_PUSH_AU'.
    INSERT ls_method INTO TABLE rt_methods.
    ls_method-class = 'ZCL_ABAPGIT_BACKGROUND_PUSH_FI'.
    INSERT ls_method INTO TABLE rt_methods.
 
    ls_key-clsname = 'ZIF_ABAPGIT_BACKGROUND'.
 
    CALL FUNCTION 'SEO_INTERFACE_IMPLEM_GET_ALL'
      EXPORTING
        intkey       = ls_key
      IMPORTING
        impkeys      = lt_implementing
      EXCEPTIONS
        not_existing = 1
        OTHERS       = 2 ##FM_SUBRC_OK.
    LOOP AT lt_implementing INTO ls_implementing.
      ls_method-class = ls_implementing-clsname.
      INSERT ls_method INTO TABLE rt_methods.
    ENDLOOP.
 
    LOOP AT rt_methods ASSIGNING <ls_method>.
      CALL METHOD (<ls_method>-class)=>zif_abapgit_background~get_description
        RECEIVING
          rv_description = <ls_method>-description.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD run.
 
    DATA: lo_per        TYPE REF TO zcl_abapgit_persist_background,
          lo_repo       TYPE REF TO zcl_abapgit_repo_online,
          lt_list       TYPE zcl_abapgit_persist_background=>ty_background_keys,
          li_background TYPE REF TO zif_abapgit_background,
          li_log        TYPE REF TO zif_abapgit_log,
          lx_error      TYPE REF TO zcx_abapgit_exception,
          lv_repo_name  TYPE string.
 
    FIELD-SYMBOLS: <ls_list> LIKE LINE OF lt_list.
 
    TRY.
        enqueue( ).
      CATCH zcx_abapgit_exception.
        WRITE: / 'Another instance of the program is already running'.
        RETURN.
    ENDTRY.
 
    CREATE OBJECT lo_per.
    lt_list = lo_per->list( ).
 
    WRITE: / 'Background mode'.
 
    LOOP AT lt_list ASSIGNING <ls_list>.
      CREATE OBJECT li_log TYPE zcl_abapgit_log.
 
      TRY.
          lo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( <ls_list>-key ).
          lv_repo_name = lo_repo->get_name( ).
          WRITE: / <ls_list>-method, lv_repo_name.
 
          zcl_abapgit_login_manager=>set(
            iv_uri      = lo_repo->get_url( )
            iv_username = <ls_list>-username
            iv_password = <ls_list>-password ).
 
          CREATE OBJECT li_background TYPE (<ls_list>-method).
 
          li_background->run(
            io_repo     = lo_repo
            ii_log      = li_log
            it_settings = <ls_list>-settings ).
 
          " Decrease memory usage for repository already processed (but keep log)
          lo_repo->refresh(
            iv_drop_cache = abap_true
            iv_drop_log   = abap_false ).
        CATCH zcx_abapgit_exception INTO lx_error.
          li_log->add_exception( lx_error ).
      ENDTRY.
 
      " Clear auth buffer to allow different user/password per repository in background mode
      zcl_abapgit_login_manager=>clear( ).
 
      zcl_abapgit_log_viewer=>write_log( li_log ).
    ENDLOOP.
 
    IF lines( lt_list ) = 0.
      WRITE: / 'Nothing configured'.
    ENDIF.
 
    dequeue( ).
 
  ENDMETHOD.
ENDCLASS.