<commit_before>version: 2.1

executors:
  build-executor:
    docker:
      - image: cimg/openjdk:8.0-browsers

parameters:
  cache_version:
    description: the current version of the cache
    type: string
    default: v4

orbs:
  branch-management: opennms/branch-management@2.3.0

commands:
  cached_checkout:
    description: Restore and Update Source Cache
    steps:
      - restore_cache:
          keys:
            - source-<< pipeline.parameters.cache_version >>-{{ .Branch }}-{{ .Revision }}
            - source-<< pipeline.parameters.cache_version >>-{{ .Branch }}-
            - source-<< pipeline.parameters.cache_version >>-

      - checkout

      # Save source cache
      - save_cache:
          key: source-<< pipeline.parameters.cache_version >>-{{ .Branch }}-{{ .Revision }}
          paths:
            - ".git"

  generate_megapom:
    steps:
      - run:
          name: create checksum file
          command: find * -name pom.xml | sort -u | xargs cat > /tmp/megapom.xml

  fetch_maven_cache:
    description: Download Update Maven Dependencies
    steps:
      - generate_megapom

      - restore_cache:
          keys:
          - maven-<< pipeline.parameters.cache_version >>-dependencies-{{ checksum "/tmp/megapom.xml" }}
          # fallback to using the latest cache if no exact match is found
          - maven-<< pipeline.parameters.cache_version >>-dependencies-

      - run:
          name: Clean Old Maven Repository Entries
          command: |
            if [ -d ~/.m2/repository ]; then
              # clean out anything older than 14 days
              find ~/.m2/repository -type f -ctime +14 -exec rm -rf {} \; 2>/dev/null || :
              find ~/.m2/repository -depth -type d -print | while read -r DIR; do
                rmdir "$DIR" 2>/dev/null || :
              done
            fi

      - run:
          name: Collect Maven Dependencies
          command: |
             mvn dependency:resolve || true
             mvn dependency:resolve-plugins || true
             mvn dependency:go-offline || true

  store_maven_cache:
    description: Save Maven Dependencies
    steps:
      - generate_megapom

      - run:
          name: Remove Build Artifacts from Maven Cache
          command: |
            if [ -d ~/.m2/repository ]; then
              rm -rf ~/.m2/repository/org/opennms/newts
            fi

      - save_cache:
          paths:
            - ~/.m2
          key: << pipeline.parameters.cache_version >>-dependencies-{{ checksum "/tmp/megapom.xml" }}

jobs:
  build:
    executor: build-executor
    resource_class: xlarge

    environment:
      MAVEN_OPTS: -Xmx4096m -XX:+UseParallelGC

    steps:
      - cached_checkout
      - fetch_maven_cache
      - run:
          name: Run the build
          no_output_timeout: 20m
          command: mvn -DskipTests=true install
      - store_maven_cache

      - run:
          name: Run the tests
          no_output_timeout: 20m
          command: mvn -DskipITs=false verify

      - run:
          name: Save test results
          command: |
            mkdir -p ~/junit/
            find . -type f -regex ".*/target/failsafe-reports/.*xml" -exec cp {} ~/junit/ \;
            find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \;
          when: always

      - store_test_results:
          path: ~/junit

      - store_artifacts:
          path: assembly/target/newts*

      - persist_to_workspace:
          root: .
          paths:
            - ./

  deploy:
    executor: build-executor

    steps:
      - attach_workspace:
          at: .

      - fetch_maven_cache

      - run:
          name: Deploy the artifacts
          command: |
            mvn -s .circleci.settings.xml -DskipTests deploy

workflows:
  build-deploy:
    jobs:
      - build:
          filters:
            branches:
              only: /.*/
      - deploy:
          requires:
            - build
          filters:
            branches:
              only:
               - /^release-.*/
               - master
<commit_msg>add some maven opts to improve memory usage and GC for tests<commit_after>version: 2.1

executors:
  build-executor:
    docker:
      - image: cimg/openjdk:8.0-browsers

parameters:
  cache_version:
    description: the current version of the cache
    type: string
    default: v4

orbs:
  branch-management: opennms/branch-management@2.3.0

commands:
  cached_checkout:
    description: Restore and Update Source Cache
    steps:
      - restore_cache:
          keys:
            - source-<< pipeline.parameters.cache_version >>-{{ .Branch }}-{{ .Revision }}
            - source-<< pipeline.parameters.cache_version >>-{{ .Branch }}-
            - source-<< pipeline.parameters.cache_version >>-

      - checkout

      # Save source cache
      - save_cache:
          key: source-<< pipeline.parameters.cache_version >>-{{ .Branch }}-{{ .Revision }}
          paths:
            - ".git"

  generate_megapom:
    steps:
      - run:
          name: create checksum file
          command: find * -name pom.xml | sort -u | xargs cat > /tmp/megapom.xml

  fetch_maven_cache:
    description: Download Update Maven Dependencies
    steps:
      - generate_megapom

      - restore_cache:
          keys:
          - maven-<< pipeline.parameters.cache_version >>-dependencies-{{ checksum "/tmp/megapom.xml" }}
          # fallback to using the latest cache if no exact match is found
          - maven-<< pipeline.parameters.cache_version >>-dependencies-

      - run:
          name: Clean Old Maven Repository Entries
          command: |
            if [ -d ~/.m2/repository ]; then
              # clean out anything older than 14 days
              find ~/.m2/repository -type f -ctime +14 -exec rm -rf {} \; 2>/dev/null || :
              find ~/.m2/repository -depth -type d -print | while read -r DIR; do
                rmdir "$DIR" 2>/dev/null || :
              done
            fi

      - run:
          name: Collect Maven Dependencies
          command: |
             mvn dependency:resolve || true
             mvn dependency:resolve-plugins || true
             mvn dependency:go-offline || true

  store_maven_cache:
    description: Save Maven Dependencies
    steps:
      - generate_megapom

      - run:
          name: Remove Build Artifacts from Maven Cache
          command: |
            if [ -d ~/.m2/repository ]; then
              rm -rf ~/.m2/repository/org/opennms/newts
            fi

      - save_cache:
          paths:
            - ~/.m2
          key: << pipeline.parameters.cache_version >>-dependencies-{{ checksum "/tmp/megapom.xml" }}

jobs:
  build:
    executor: build-executor
    resource_class: xlarge

    environment:
      MAVEN_OPTS: -Xmx4096m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-UseGCOverheadLimit

    steps:
      - cached_checkout
      - fetch_maven_cache
      - run:
          name: Run the build
          no_output_timeout: 20m
          command: mvn -DskipTests=true install
      - store_maven_cache

      - run:
          name: Run the tests
          no_output_timeout: 20m
          command: mvn -DskipITs=false verify

      - run:
          name: Save test results
          command: |
            mkdir -p ~/junit/
            find . -type f -regex ".*/target/failsafe-reports/.*xml" -exec cp {} ~/junit/ \;
            find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \;
          when: always

      - store_test_results:
          path: ~/junit

      - store_artifacts:
          path: assembly/target/newts*

      - persist_to_workspace:
          root: .
          paths:
            - ./

  deploy:
    executor: build-executor

    steps:
      - attach_workspace:
          at: .

      - fetch_maven_cache

      - run:
          name: Deploy the artifacts
          command: |
            mvn -s .circleci.settings.xml -DskipTests deploy

workflows:
  build-deploy:
    jobs:
      - build:
          filters:
            branches:
              only: /.*/
      - deploy:
          requires:
            - build
          filters:
            branches:
              only:
               - /^release-.*/
               - master

{'fraction_non_alphanumeric': 0.10449927431059507, 'fraction_numerical': 0.006894049346879536, 'mean_word_length': 1.554525795489651, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1833931', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2393, 'n_words': 611}