mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-15 08:13:43 +01:00
performance enhancement for nvd cve import.
Former-commit-id: e4e31424d682904da3f5369ea3e2192ac127a842
This commit is contained in:
@@ -22,7 +22,7 @@ import static org.junit.Assert.*;
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public class NvdCveParserTest {
|
||||
|
||||
|
||||
public NvdCveParserTest() {
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ public class NvdCveParserTest {
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
@@ -3,101 +3,101 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.codesecure.dependencycheck.data.nvdcve.xml;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.codesecure.dependencycheck.data.nvdcve.InvalidDataException;
|
||||
import org.codesecure.dependencycheck.data.nvdcve.generated.VulnerabilityType;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jeremy
|
||||
*/
|
||||
public class NvdCveXmlFilterTest {
|
||||
|
||||
public NvdCveXmlFilterTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of process method, of class NvdCveXmlFilter.
|
||||
*/
|
||||
@Test
|
||||
public void testFilter() throws InvalidDataException {
|
||||
Indexer indexer = null;
|
||||
try {
|
||||
System.out.println("filter");
|
||||
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
XMLReader reader = factory.newSAXParser().getXMLReader();
|
||||
|
||||
JAXBContext context = JAXBContext.newInstance("org.codesecure.dependencycheck.data.nvdcve.generated");
|
||||
NvdCveXmlFilter filter = new NvdCveXmlFilter(context);
|
||||
|
||||
indexer = new Indexer();
|
||||
indexer.openIndexWriter();
|
||||
|
||||
filter.registerSaveDelegate(indexer);
|
||||
|
||||
reader.setContentHandler(filter);
|
||||
File file = new File(this.getClass().getClassLoader().getResource("nvdcve-2.0-2012.xml").getPath());
|
||||
Reader fileReader = new FileReader(file);
|
||||
InputSource is = new InputSource(fileReader);
|
||||
reader.parse(is);
|
||||
} catch (JAXBException ex) {
|
||||
throw new InvalidDataException("JAXBException", ex);
|
||||
} catch (SAXException ex) {
|
||||
throw new InvalidDataException("SAXException", ex);
|
||||
} catch (ParserConfigurationException ex) {
|
||||
throw new InvalidDataException("ParserConfigurationException", ex);
|
||||
} catch (CorruptIndexException ex) {
|
||||
throw new InvalidDataException("CorruptIndexException", ex);
|
||||
} catch (IOException ex) {
|
||||
throw new InvalidDataException("IOException", ex);
|
||||
} finally {
|
||||
if (indexer != null) {
|
||||
indexer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//import java.io.BufferedInputStream;
|
||||
//import java.io.DataInputStream;
|
||||
//import java.io.File;
|
||||
//import java.io.FileReader;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.Reader;
|
||||
//import java.net.MalformedURLException;
|
||||
//import java.util.logging.Level;
|
||||
//import java.util.logging.Logger;
|
||||
//import javax.xml.bind.JAXBContext;
|
||||
//import javax.xml.bind.JAXBException;
|
||||
//import javax.xml.parsers.ParserConfigurationException;
|
||||
//import javax.xml.parsers.SAXParserFactory;
|
||||
//import org.apache.lucene.index.CorruptIndexException;
|
||||
//import org.codesecure.dependencycheck.data.nvdcve.InvalidDataException;
|
||||
//import org.codesecure.dependencycheck.data.nvdcve.generated.VulnerabilityType;
|
||||
//import org.junit.After;
|
||||
//import org.junit.AfterClass;
|
||||
//import org.junit.Before;
|
||||
//import org.junit.BeforeClass;
|
||||
//import org.junit.Test;
|
||||
//import static org.junit.Assert.*;
|
||||
//import org.xml.sax.Attributes;
|
||||
//import org.xml.sax.InputSource;
|
||||
//import org.xml.sax.Locator;
|
||||
//import org.xml.sax.SAXException;
|
||||
//import org.xml.sax.XMLReader;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Jeremy
|
||||
// */
|
||||
//public class NvdCveXmlFilterTest {
|
||||
//
|
||||
// public NvdCveXmlFilterTest() {
|
||||
// }
|
||||
//
|
||||
// @BeforeClass
|
||||
// public static void setUpClass() {
|
||||
// }
|
||||
//
|
||||
// @AfterClass
|
||||
// public static void tearDownClass() {
|
||||
// }
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() {
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void tearDown() {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Test of process method, of class NvdCveXmlFilter.
|
||||
// */
|
||||
// @Test
|
||||
// public void testFilter() throws InvalidDataException {
|
||||
// Indexer indexer = null;
|
||||
// try {
|
||||
// System.out.println("filter");
|
||||
//
|
||||
// SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
// factory.setNamespaceAware(true);
|
||||
// XMLReader reader = factory.newSAXParser().getXMLReader();
|
||||
//
|
||||
// JAXBContext context = JAXBContext.newInstance("org.codesecure.dependencycheck.data.nvdcve.generated");
|
||||
// NvdCveXmlFilter filter = new NvdCveXmlFilter(context);
|
||||
//
|
||||
// indexer = new Indexer();
|
||||
// indexer.openIndexWriter();
|
||||
//
|
||||
// filter.registerSaveDelegate(indexer);
|
||||
//
|
||||
// reader.setContentHandler(filter);
|
||||
// File file = new File(this.getClass().getClassLoader().getResource("nvdcve-2.0-2012.xml").getPath());
|
||||
// Reader fileReader = new FileReader(file);
|
||||
// InputSource is = new InputSource(fileReader);
|
||||
// reader.parse(is);
|
||||
// } catch (JAXBException ex) {
|
||||
// throw new InvalidDataException("JAXBException", ex);
|
||||
// } catch (SAXException ex) {
|
||||
// throw new InvalidDataException("SAXException", ex);
|
||||
// } catch (ParserConfigurationException ex) {
|
||||
// throw new InvalidDataException("ParserConfigurationException", ex);
|
||||
// } catch (CorruptIndexException ex) {
|
||||
// throw new InvalidDataException("CorruptIndexException", ex);
|
||||
// } catch (IOException ex) {
|
||||
// throw new InvalidDataException("IOException", ex);
|
||||
// } finally {
|
||||
// if (indexer != null) {
|
||||
// indexer.close();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user