Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes & info msgs #13

Merged
merged 5 commits into from
Dec 31, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ jshell.history
/nbproject/
/target-old/
nbactions.xml
nb-configuration.xml
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A command line tool to scan the dependencies of a project and detect their Licenses. I wrote this while building an SCA Tool.

The tool scans the metadata file (e.g. pom.xml for maven based projects and package.json for npm) and creates a dependency tree detecting the direct as well as transitive dependencies. The license (if found) is analyzed and matched with the licenses in the SPDX License Database using methods of NLP. The motivation for the algorithm of license detection is taken from [Link](https://github.com/go-enry/go-license-detector).
The tool scans the metadata file (e.g. pom.xml for maven based projects and package.json for npm) and creates a dependency tree resolving the direct as well as transitive dependencies. The license (if found) is analyzed and matched with the licenses in the SPDX License Database using methods of NLP. The motivation for the algorithm of license detection is taken from [Link](https://github.com/go-enry/go-license-detector).

![SAMPLE_IMAGE](./images/npm-scan-result.jpg)

Expand All @@ -17,6 +17,7 @@ The tool scans the metadata file (e.g. pom.xml for maven based projects and pack
- [X] License Detection through License files
- [ ] License Detection through README files (If no License file is found in the package)
- [X] Supports scanning remote public repo
- [X] Supports scanning packages (zip/jar/tgz)
- [ ] Export report as XML/JSON

### Supported package/project managers
Expand All @@ -36,7 +37,7 @@ The tool scans the metadata file (e.g. pom.xml for maven based projects and pack

## Build

Build the jar package using Maven
Build the jar package with Maven
```
mvn -DskipTests package
```
Expand All @@ -48,9 +49,9 @@ To scan a local project
java -jar <path-to-jar> scan -src <project-path>
```

To scan a remote repository
To scan a remote repository/package
```
java -jar <path-to-jar> monitor -src <repo-url>
java -jar <path-to-jar> monitor -src <url>
```

## CONTRIBUTING
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.phsyberdome</groupId>
<artifactId>phsyberdome-sca-cli</artifactId>
<version>1.0</version>
<version>1.0.1-beta</version>
<packaging>jar</packaging>
<build>
<plugins>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/phsyberdome/drona/CLIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ public static void printDivider(Color color) {
}

public static void printLine(String data, Color color) {
updateCurrentLine("", color);
System.out.println(ansi().fg(color).a(data).reset());
}

public static void print(String data, Color color) {
updateCurrentLine("", color);
System.out.print(ansi().fg(color).a(data).reset());
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/phsyberdome/drona/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.Ansi.Color;

/**
*
Expand Down Expand Up @@ -95,7 +97,8 @@ private void readConfigFile(String filename) {
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "UNABLE TO READ CONFIG FILE", ex);
}
}else {
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "No config file found!");
CLIHelper.printLine("No config file found!",Color.CYAN);
CLIHelper.printDivider(Color.YELLOW);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/phsyberdome/drona/Drona.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ private static void monitor(String url) {
CLIHelper.printLine("INVALID URL TO SCAN!", Color.RED);
return;
}
CLIHelper.updateCurrentLine("Downloading repository/package...", Color.YELLOW);
Path targetPath = FileUtil.getFilePathFromURL(url, Configuration.getConfiguration().getCloneLocation().toString());
if(targetPath==null){
return;
}
CLIHelper.updateCurrentLine("", Color.BLUE);
CLIHelper.printLine("Downloaded repository/package", Color.BLUE);
scan(targetPath.toString(), null);
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/phsyberdome/drona/Plugins/JavaMavenPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void readModules() {
File file = FileUtil.searchFile(Configuration.getConfiguration().getBasePath().toFile(), "(.*\\.(pom|POM))|(pom\\.(xml|XML))");
if(file == null) {
CLIHelper.updateCurrentLine("pom file not found in project",Ansi.Color.RED);

return;
}
Path path = file.toPath();
Expand All @@ -73,6 +73,11 @@ public void readModules() {
CLIHelper.updateCurrentLine("Couldn't read pom file",Ansi.Color.RED);
return;
}
String rootArtifactId = PomReader.extractAttributeFromNode(doc.getDocumentElement(), "artifactId");
String rootGroupId = PomReader.extractAttributeFromNode(doc.getDocumentElement(), "groupId");
String rootVersion = PomReader.extractAttributeFromNode(doc.getDocumentElement(), "version");
Module root = new Module(rootArtifactId,rootVersion);

NodeList list = doc.getElementsByTagName("dependency");

for(int i=0;i<list.getLength();i++){
Expand Down Expand Up @@ -105,9 +110,10 @@ public void readModules() {
}else{
CLIHelper.updateCurrentLine("Cannot proceed! REASON: Couldnt get version for "+m.getName(),Ansi.Color.CYAN);
}
modules.add(m);
root.addToDependencies(m);
}
}
modules.add(root);
}else{
CLIHelper.updateCurrentLine("pom file not found at " + path.toAbsolutePath().toString(),Ansi.Color.RED);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/phsyberdome/drona/Utils/JSONHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.phsyberdome.drona.Models.Pair;
import java.util.ArrayList;
Expand All @@ -24,7 +25,7 @@ public static String convertToJson(Object object) {
ObjectMapper objectMapper = new ObjectMapper();
String json;
try {
json = objectMapper.writeValueAsString(object);
json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
}catch(JsonProcessingException e) {
Logger.getLogger(JSONHelper.class.getCanonicalName()).log(Level.WARNING, e.getLocalizedMessage());
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/phsyberdome/drona/Utils/PomReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static String buildUrlForPomFile(String groupId,String artifactId,String
repoUrlString += ("/" + artifactId + "-" + version + ".pom");
return repoUrlString;
}


public static String extractAttributeFromNode(Element element, String attrib){
NodeList n = element.getElementsByTagName(attrib);
Expand Down