Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions data7/src/main/java/data7/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public Exporter(ResourcesPath path) {
* @throws IOException
*/
public void saveDataset(Data7 data7) throws IOException {
Utils.checkFolderDestination(path.getBinaryPath());
FileOutputStream fos = new FileOutputStream(path.getBinaryPath() + data7.getProject().getName() + "-data7.obj", false);
Utils.checkFolderDestination(path.getBinaryPath().toString());
FileOutputStream fos = new FileOutputStream(path.getBinaryPath().resolve(data7.getProject().getName() + "-data7.obj").toString(), false);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(data7);
oos.close();
Expand All @@ -77,7 +77,7 @@ public void saveDataset(Data7 data7) throws IOException {
*/
public void exportDatasetToXML(Data7 data7) {
VulnerabilitySet dataset = data7.getVulnerabilitySet();
Utils.checkFolderDestination(path.getXmlPath());
Utils.checkFolderDestination(path.getXmlPath().toString());
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Expand Down Expand Up @@ -182,7 +182,7 @@ public void exportDatasetToXML(Data7 data7) {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(path.getXmlPath() + data7.getProject().getName() + "-data7.xml");
StreamResult result = new StreamResult(path.getXmlPath().resolve(data7.getProject().getName() + "-data7.xml").toString());

transformer.setOutputProperty(OutputKeys.VERSION, "1.0");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
Expand Down Expand Up @@ -210,7 +210,7 @@ public void exportDatasetToXML(Data7 data7) {
* @throws IOException
*/
public void saveCWEList(List<CWE> cweList) throws IOException {
FileOutputStream fos = new FileOutputStream(path.getBinaryPath() + CWE_OBJ, false);
FileOutputStream fos = new FileOutputStream(path.getBinaryPath().resolve(CWE_OBJ).toString(), false);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(cweList);
oos.close();
Expand All @@ -225,7 +225,7 @@ public void saveCWEList(List<CWE> cweList) throws IOException {
* @throws ClassNotFoundException
*/
public List<CWE> loadCWEMist() throws IOException, ClassNotFoundException {
File file = new File(path.getBinaryPath() + CWE_OBJ);
File file = path.getBinaryPath().resolve(CWE_OBJ).toFile();
if (file.exists()) {
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream read = new ObjectInputStream(fileIn);
Expand Down
34 changes: 18 additions & 16 deletions data7/src/main/java/data7/ResourcesPath.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
package data7;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ResourcesPath {

private final String savingPath;
private final String binaryPath;
private final String gitPath;
private final String xmlPath;
private final String cvePath;
private final Path savingPath;
private final Path binaryPath;
private final Path gitPath;
private final Path xmlPath;
private final Path cvePath;

public ResourcesPath(String path) {
File f = new File(path);
savingPath = Paths.get(path);
File f = savingPath.toFile();
if (f.exists() && f.isDirectory()) {
savingPath = path;
binaryPath = savingPath + "binary/";
gitPath = savingPath + "git/";
xmlPath = savingPath + "xml/";
cvePath = savingPath + "cve/";
binaryPath = savingPath.resolve("binary");
gitPath = savingPath.resolve("git");
xmlPath = savingPath.resolve("xml");
cvePath = savingPath.resolve("cve");
} else throw new RuntimeException("Path is incorrect or inexisting");
}

public String getSavingPath() {
public Path getSavingPath() {
return savingPath;
}

public String getBinaryPath() {
public Path getBinaryPath() {
return binaryPath;
}

public String getGitPath() {
public Path getGitPath() {
return gitPath;
}

public String getXmlPath() {
public Path getXmlPath() {
return xmlPath;
}

public String getCvePath() {
public Path getCvePath() {
return cvePath;
}
}
23 changes: 12 additions & 11 deletions data7/src/main/java/data7/importer/Data7Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.time.Year;
import java.util.*;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Data7 updateOrCreateDataset() throws ParseException, IOException, ClassNo
//clone the git
Map<String, GitActions> git = new HashMap<>();
data7.getProject().getSubProjects().forEach((component, metainf) -> {
git.put(component, new GitActions(metainf.getOnlineRepository(), path.getGitPath() + component));
git.put(component, new GitActions(metainf.getOnlineRepository(), path.getGitPath().resolve(component).toString()));
});

//Source To proceed with
Expand Down Expand Up @@ -185,8 +186,8 @@ private List<String> dowloadRecentXML(long lastUpdated, long currentTime) throws
* @throws ParseException
*/
private boolean checkMetaIfNewerThan(String year, long lastUpdate) throws IOException, ParseException {
Misc.downloadFromURL(CVE_URL + year + META, path.getCvePath());
File meta = new File(path.getCvePath() + FILE_START + year + META);
Misc.downloadFromURL(CVE_URL + year + META, path.getCvePath().toString());
File meta = path.getCvePath().resolve(FILE_START + year + META).toFile();
BufferedReader brTest = new BufferedReader(new FileReader(meta));
String date = brTest.readLine();
date = date.replace("lastModifiedDate:", "");
Expand All @@ -202,13 +203,13 @@ private boolean checkMetaIfNewerThan(String year, long lastUpdate) throws IOExce
* @throws IOException
*/
private String downloadCVEXML(String year) throws IOException {
checkFolderDestination(path.getCvePath());
Misc.downloadFromURL(CVE_URL + year + XML, path.getCvePath());
String fpath = path.getCvePath() + FILE_START + year + XML;
File zip = new File(fpath);
Misc.unzipping(fpath, path.getCvePath());
Files.delete(zip.toPath());
return fpath.replace(".zip", "");
checkFolderDestination(path.getCvePath().toString());
Misc.downloadFromURL(CVE_URL + year + XML, path.getCvePath().toString());
Path fpath = path.getCvePath().resolve(FILE_START + year + XML);
File zip = fpath.toFile();
Misc.unzipping(fpath.toString(), path.getCvePath().toString());
Files.delete(fpath);
return fpath.toString().replace(".zip", "");
}

/**
Expand Down Expand Up @@ -259,7 +260,7 @@ private List<CVE> listOfNewCVE(List<String> pathOfXMLFiles) {
* @throws ClassNotFoundException
*/
public Data7 loadDataset() throws IOException, ClassNotFoundException {
File file = new File(path.getBinaryPath() + project + "-data7.obj");
File file = path.getBinaryPath().resolve(project + "-data7.obj").toFile();
if (file.exists()) {
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream read = new ObjectInputStream(fileIn);
Expand Down
8 changes: 4 additions & 4 deletions data7/src/main/java/data7/importer/cwe/CWEImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -43,8 +43,8 @@ public CWEImporter(ResourcesPath path){


public List<CWE> retrieveCWEOnline() throws IOException {
Misc.downloadFromURL(Resources.CWE_URL, path.getCvePath());
Misc.unzipping(path.getCvePath() + CWE_XML_FILE + ".zip", path.getCvePath());
Misc.downloadFromURL(Resources.CWE_URL, path.getCvePath().toString());
Misc.unzipping(path.getCvePath().resolve(CWE_XML_FILE + ".zip").toString(), path.getCvePath().toString());
List<CWE> cweList = CWEParser.parse(path);
new Exporter(path).saveCWEList(cweList);
return cweList;
Expand Down