All files / src/repo zcl_abapgit_dot_abapgit.clas.abap

96.32% Statements 419/435
75% Branches 12/16
50% Functions 5/10
96.32% Lines 419/435

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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 4361x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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x 20x 20x 1x 1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x 41x 41x 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_dot_abapgit DEFINITION
  PUBLIC
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    CLASS-METHODS build_default
      RETURNING
        VALUE(ro_dot_abapgit) TYPE REF TO zcl_abapgit_dot_abapgit .
    CLASS-METHODS deserialize
      IMPORTING
        !iv_xstr              TYPE xstring
      RETURNING
        VALUE(ro_dot_abapgit) TYPE REF TO zcl_abapgit_dot_abapgit
      RAISING
        zcx_abapgit_exception .
    METHODS constructor
      IMPORTING
        !is_data TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit .
    METHODS serialize
      RETURNING
        VALUE(rv_xstr) TYPE xstring
      RAISING
        zcx_abapgit_exception .
    METHODS to_file
      RETURNING
        VALUE(rs_file) TYPE zif_abapgit_git_definitions=>ty_file
      RAISING
        zcx_abapgit_exception .
    METHODS get_data
      RETURNING
        VALUE(rs_data) TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit .
    METHODS add_ignore
      IMPORTING
        !iv_path     TYPE string
        !iv_filename TYPE string .
    METHODS is_ignored
      IMPORTING
        !iv_path          TYPE string
        !iv_filename      TYPE string
      RETURNING
        VALUE(rv_ignored) TYPE abap_bool .
    METHODS remove_ignore
      IMPORTING
        !iv_path     TYPE string
        !iv_filename TYPE string .
    METHODS get_starting_folder
      RETURNING
        VALUE(rv_path) TYPE string .
    METHODS get_folder_logic
      RETURNING
        VALUE(rv_logic) TYPE string .
    METHODS set_folder_logic
      IMPORTING
        !iv_logic TYPE string .
    METHODS set_starting_folder
      IMPORTING
        !iv_path TYPE string .
    METHODS get_main_language
      RETURNING
        VALUE(rv_language) TYPE spras .
    METHODS get_i18n_languages
      RETURNING
        VALUE(rt_languages) TYPE zif_abapgit_definitions=>ty_languages
      RAISING
        zcx_abapgit_exception .
    METHODS set_i18n_languages
      IMPORTING
        it_languages TYPE zif_abapgit_definitions=>ty_languages
      RAISING
        zcx_abapgit_exception .
    METHODS determine_i18n_parameters
      IMPORTING
        !iv_main_language_only TYPE abap_bool
      RETURNING
        VALUE(rs_i18n_params)  TYPE zif_abapgit_definitions=>ty_i18n_params
      RAISING
        zcx_abapgit_exception.
    METHODS get_signature
      RETURNING
        VALUE(rs_signature) TYPE zif_abapgit_git_definitions=>ty_file_signature
      RAISING
        zcx_abapgit_exception .
    METHODS use_lxe
      IMPORTING
        !iv_yes       TYPE abap_bool DEFAULT abap_undefined
      RETURNING
        VALUE(rv_yes) TYPE abap_bool .
    METHODS get_requirements
      RETURNING
        VALUE(rt_requirements) TYPE zif_abapgit_dot_abapgit=>ty_requirement_tt .
    METHODS set_requirements
      IMPORTING
        !it_requirements TYPE zif_abapgit_dot_abapgit=>ty_requirement_tt .
    METHODS get_name
      RETURNING
        VALUE(rv_name) TYPE string.
    METHODS set_name
      IMPORTING
        !iv_name TYPE csequence.
    METHODS get_version_constant
      RETURNING
        VALUE(rv_version_constant) TYPE string .
    METHODS set_version_constant
      IMPORTING
        !iv_version_constant TYPE csequence .
    METHODS get_abap_language_version
      RETURNING
        VALUE(rv_abap_language_version) TYPE string .
    METHODS set_abap_language_version
      IMPORTING
        !iv_abap_language_version TYPE string .
    METHODS get_original_system
      RETURNING
        VALUE(rv_original_system) TYPE string .
    METHODS set_original_system
      IMPORTING
        !iv_original_system TYPE csequence .
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    DATA ms_data TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit .
 
    CLASS-METHODS to_xml
      IMPORTING
        !is_data      TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit
      RETURNING
        VALUE(rv_xml) TYPE string
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS from_xml
      IMPORTING
        !iv_xml        TYPE string
      RETURNING
        VALUE(rs_data) TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit .
ENDCLASS.
 
 
 
CLASS zcl_abapgit_dot_abapgit IMPLEMENTATION.
 
 
  METHOD add_ignore.
 
    DATA: lv_name TYPE string.
 
    FIELD-SYMBOLS: <lv_ignore> LIKE LINE OF ms_data-ignore.
 
 
    lv_name = iv_path && iv_filename.
 
    READ TABLE ms_data-ignore FROM lv_name TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      RETURN.
    ENDIF.
 
    APPEND INITIAL LINE TO ms_data-ignore ASSIGNING <lv_ignore>.
    <lv_ignore> = lv_name.
 
  ENDMETHOD.
 
 
  METHOD build_default.
 
    DATA: ls_data TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit.
 
 
    ls_data-master_language = sy-langu.
    ls_data-starting_folder = '/src/'.
    ls_data-folder_logic    = zif_abapgit_dot_abapgit=>c_folder_logic-prefix.
 
    CREATE OBJECT ro_dot_abapgit
      EXPORTING
        is_data = ls_data.
 
  ENDMETHOD.
 
 
  METHOD constructor.
    ms_data = is_data.
  ENDMETHOD.
 
 
  METHOD deserialize.
 
    DATA: lv_xml  TYPE string,
          ls_data TYPE zif_abapgit_dot_abapgit=>ty_dot_abapgit.
 
 
    lv_xml = zcl_abapgit_convert=>xstring_to_string_utf8( iv_xstr ).
 
    ls_data = from_xml( lv_xml ).
 
    CREATE OBJECT ro_dot_abapgit
      EXPORTING
        is_data = ls_data.
 
  ENDMETHOD.
 
 
  METHOD determine_i18n_parameters.
 
    rs_i18n_params-main_language         = get_main_language( ).
    rs_i18n_params-use_lxe               = use_lxe( ).
    rs_i18n_params-main_language_only    = iv_main_language_only.
    rs_i18n_params-translation_languages = zcl_abapgit_lxe_texts=>get_translation_languages(
      iv_main_language  = get_main_language( )
      it_i18n_languages = get_i18n_languages( ) ).
 
  ENDMETHOD.
 
 
  METHOD from_xml.
 
    DATA: lv_xml TYPE string.
 
    lv_xml = iv_xml.
 
    CALL TRANSFORMATION id
      OPTIONS value_handling = 'accept_data_loss'
      SOURCE XML lv_xml
      RESULT data = rs_data.
 
* downward compatibility
    IF rs_data-folder_logic IS INITIAL.
      rs_data-folder_logic = zif_abapgit_dot_abapgit=>c_folder_logic-prefix.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD get_abap_language_version.
    rv_abap_language_version = ms_data-abap_language_version.
  ENDMETHOD.
 
 
  METHOD get_data.
    rs_data = ms_data.
  ENDMETHOD.
 
 
  METHOD get_folder_logic.
    rv_logic = ms_data-folder_logic.
  ENDMETHOD.
 
 
  METHOD get_i18n_languages.
    rt_languages = ms_data-i18n_languages.
  ENDMETHOD.
 
 
  METHOD get_main_language.
    rv_language = ms_data-master_language.
    IF rv_language IS INITIAL.
      rv_language = sy-langu.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD get_name.
    rv_name = ms_data-name.
  ENDMETHOD.
 
 
  METHOD get_original_system.
    rv_original_system = ms_data-original_system.
  ENDMETHOD.
 
 
  METHOD get_requirements.
    rt_requirements = ms_data-requirements.
  ENDMETHOD.
 
 
  METHOD get_signature.
 
    rs_signature-path     = zif_abapgit_definitions=>c_root_dir.
    rs_signature-filename = zif_abapgit_definitions=>c_dot_abapgit.
    rs_signature-sha1     = zcl_abapgit_hash=>sha1_blob( serialize( ) ).
 
  ENDMETHOD.
 
 
  METHOD get_starting_folder.
    rv_path = ms_data-starting_folder.
  ENDMETHOD.
 
 
  METHOD get_version_constant.
    rv_version_constant = ms_data-version_constant.
  ENDMETHOD.
 
 
  METHOD is_ignored.
 
    DATA: lv_name     TYPE string,
          lv_starting TYPE string,
          lv_dot      TYPE string,
          lv_ignore   TYPE string.
 
 
    lv_name = iv_path && iv_filename.
 
    CONCATENATE ms_data-starting_folder '*' INTO lv_starting.
 
    " Always allow .abapgit.xml and .apack-manifest.xml
    CONCATENATE '/' zif_abapgit_definitions=>c_dot_abapgit INTO lv_dot.
    IF lv_name = lv_dot.
      RETURN.
    ENDIF.
    CONCATENATE '/' zif_abapgit_apack_definitions=>c_dot_apack_manifest INTO lv_dot.
    IF lv_name = lv_dot.
      RETURN.
    ENDIF.
 
    " Ignore all files matching pattern in ignore list
    LOOP AT ms_data-ignore INTO lv_ignore.
      IF lv_name CP lv_ignore.
        rv_ignored = abap_true.
        RETURN.
      ENDIF.
    ENDLOOP.
 
    " Ignore all files outside of starting folder tree
    IF ms_data-starting_folder <> '/' AND NOT lv_name CP lv_starting.
      rv_ignored = abap_true.
    ENDIF.
 
    IF iv_path = zif_abapgit_data_config=>c_default_path.
      rv_ignored = abap_false.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD remove_ignore.
 
    DATA: lv_name TYPE string.
 
 
    lv_name = iv_path && iv_filename.
 
    DELETE TABLE ms_data-ignore FROM lv_name.
 
  ENDMETHOD.
 
 
  METHOD serialize.
 
    DATA lv_xml TYPE string.
 
    lv_xml = to_xml( ms_data ).
 
    rv_xstr = zcl_abapgit_convert=>string_to_xstring_utf8_bom( lv_xml ).
 
  ENDMETHOD.
 
 
  METHOD set_abap_language_version.
    ms_data-abap_language_version = iv_abap_language_version.
  ENDMETHOD.
 
 
  METHOD set_folder_logic.
    ms_data-folder_logic = iv_logic.
  ENDMETHOD.
 
 
  METHOD set_i18n_languages.
    ms_data-i18n_languages = it_languages.
  ENDMETHOD.
 
 
  METHOD set_name.
    ms_data-name = iv_name.
  ENDMETHOD.
 
 
  METHOD set_original_system.
    ms_data-original_system = iv_original_system.
  ENDMETHOD.
 
 
  METHOD set_requirements.
    ms_data-requirements = it_requirements.
  ENDMETHOD.
 
 
  METHOD set_starting_folder.
    ms_data-starting_folder = iv_path.
  ENDMETHOD.
 
 
  METHOD set_version_constant.
    ms_data-version_constant = iv_version_constant.
  ENDMETHOD.
 
 
  METHOD to_file.
    rs_file-path     = zif_abapgit_definitions=>c_root_dir.
    rs_file-filename = zif_abapgit_definitions=>c_dot_abapgit.
    rs_file-data     = serialize( ).
    rs_file-sha1     = zcl_abapgit_hash=>sha1_blob( rs_file-data ).
  ENDMETHOD.
 
 
  METHOD to_xml.
 
    CALL TRANSFORMATION id
      OPTIONS initial_components = 'suppress'
      SOURCE data = is_data
      RESULT XML rv_xml.
 
    rv_xml = zcl_abapgit_xml_pretty=>print( rv_xml ).
 
    REPLACE FIRST OCCURRENCE
      OF REGEX '<\?xml version="1\.0" encoding="[\w-]+"\?>'
      IN rv_xml
      WITH '<?xml version="1.0" encoding="utf-8"?>'.
    ASSERT sy-subrc = 0.
 
  ENDMETHOD.
 
 
  METHOD use_lxe.
 
    IF iv_yes <> abap_undefined.
      ms_data-use_lxe = iv_yes.
    ENDIF.
 
    rv_yes = ms_data-use_lxe.
 
  ENDMETHOD.
ENDCLASS.