NpmCpeMemoryIndex.java

  1. /*
  2.  * This file is part of dependency-check-core.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  * Copyright (c) 2020 Jeremy Long. All Rights Reserved.
  17.  */
  18. package org.owasp.dependencycheck.data.cpe;

  19. import javax.annotation.concurrent.ThreadSafe;

  20. /**
  21.  * <p>
  22.  * An in memory Lucene index that contains the vendor/product combinations from
  23.  * the CPE (application) identifiers within the NVD CVE data. The intent of the
  24.  * index is to hold only products in the NVD associated with NPM/node.js.</p>
  25.  *
  26.  * This is the last remaining singleton in dependency-check-core; The use of
  27.  * this singleton - while it may not technically be thread-safe (one database
  28.  * used to build this index may not have the same entries as another) the risk
  29.  * of this is currently believed to be small. As this memory index consumes a
  30.  * large amount of memory we will remain using the singleton pattern for now.
  31.  *
  32.  * @author Jeremy Long
  33.  */
  34. @ThreadSafe
  35. public final class NpmCpeMemoryIndex extends AbstractMemoryIndex {

  36.     /**
  37.      * Singleton instance.
  38.      */
  39.     private static final NpmCpeMemoryIndex INSTANCE = new NpmCpeMemoryIndex();

  40.     /**
  41.      * private constructor for singleton.
  42.      */
  43.     private NpmCpeMemoryIndex() {
  44.     }

  45.     /**
  46.      * Gets the singleton instance of the NpmCpeMemoryIndex.
  47.      *
  48.      * @return the instance of the NpmCpeMemoryIndex
  49.      */
  50.     @Override
  51.     protected AbstractMemoryIndex instance() {
  52.         return INSTANCE;
  53.     }

  54.     /**
  55.      * Gets the singleton instance of the CpeMemoryIndex.
  56.      *
  57.      * @return the instance of the CpeMemoryIndex
  58.      */
  59.     public static NpmCpeMemoryIndex getInstance() {
  60.         return INSTANCE;
  61.     }
  62. }