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

LibComp 4 issues PR #38

Merged
merged 9 commits into from
Nov 2, 2020
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
Binary file removed Library_Comparison-1.0.11.zip
Binary file not shown.
Binary file added Library_Comparison-1.0.13.zip
Binary file not shown.
8 changes: 0 additions & 8 deletions PluginCode/.idea/modules.xml

This file was deleted.

10 changes: 5 additions & 5 deletions PluginCode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ plugins {
id 'org.jetbrains.intellij' version '0.4.10'
}


group 'my_Plugin'
version '1.0.11'
group 'library.comparison'
version '1.0.13'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}



dependencies {
compile group: 'org.json', name: 'json', version: '20180813'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
plugins 'java'
version '2020.1.1'
updateSinceUntilBuild false
}

patchPluginXml {
changeNotes """
Add change notes here.<br>
Expand Down
1 change: 1 addition & 0 deletions PluginCode/src/main/java/PostStartupActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void runActivity(@NotNull Project project) {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {


ReplacementAction actionPerformed = new ReplacementAction();
try {
actionPerformed.detectAllOpenEditors();
Expand Down
193 changes: 177 additions & 16 deletions PluginCode/src/main/java/smr/cs/ualberta/libcomp/DatabaseAccess.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package smr.cs.ualberta.libcomp;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.wm.WindowManager;
import com.jcraft.jsch.Session;
import org.apache.commons.io.FileUtils;
import java.awt.*;
Expand All @@ -23,6 +26,8 @@
import smr.cs.ualberta.libcomp.data.ReplacementFeedback;
import smr.cs.ualberta.libcomp.data.Library;
import smr.cs.ualberta.libcomp.data.User;

import javax.swing.*;
import java.io.File;

import static java.net.HttpURLConnection.HTTP_CREATED;
Expand All @@ -37,6 +42,11 @@ public class DatabaseAccess {
private int userid = 0;
private String filePath = PathManager.getPluginsPath()+"\\Library_Comparison\\lib";
private String feedbackUrllink = "https://smr.cs.ualberta.ca/comparelibraries/api/pluginfeedback/";
private String linkURL = "https://smr.cs.ualberta.ca/comparelibraries/api/metrics/?format=json&latestdate=";
private String librariesURL = "https://smr.cs.ualberta.ca/comparelibraries/api/libraries/?format=json";
private String chartsURL = "https://smr.cs.ualberta.ca/comparelibraries/api/charts/?format=json";
private String metricsURL = "https://smr.cs.ualberta.ca/comparelibraries/api/metrics/?format=json&latestdate=";
private String updateUrllink = "https://smr.cs.ualberta.ca/comparelibraries/api/pluginusers/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@relhajj these are still hard-coded domains, not in a config file. Given time, we can ignore it but this isn't what we agreed on in Issue #36


public ArrayList<String> selectJsonAllLibraries(String librarySelected) throws IOException
{
Expand All @@ -63,24 +73,21 @@ public ArrayList<String> selectJsonAllLibraries(String librarySelected) throws I
domain_name = jsonObj.getString("domain_name");
if (jsonObj.has("package"))
Package = jsonObj.getString("package");


boolean isFound1 = Package.toLowerCase().contains(librarySelected.toLowerCase());
boolean isFound2 = librarySelected.toLowerCase().contains(Package.toLowerCase());
if (isFound1 || isFound2) {
domainLibraries.add(Long.toString(library_id));
domainLibraries.add(Long.toString(domain_id));
domainLibraries.add(domain_name);
}

}
}
return domainLibraries;
}

public String getLatestMetricDate() throws IOException {
String cloudVer = "";
String linkURL = "https://smr.cs.ualberta.ca/comparelibraries/api/metrics/?format=json&latestdate=";
String linkURL = this.linkURL;

HttpURLConnection connection = (HttpURLConnection) new URL(linkURL).openConnection();
connection.setRequestMethod("GET");
Expand Down Expand Up @@ -127,6 +134,9 @@ public String checkLocalDate() throws IOException {
public void getJson(String linkURL, String filePath, String suffix) throws IOException {

File jsonFile = new File(filePath);
// to be removed later
// JOptionPane.showMessageDialog(null, jsonFile);

FileOutputStream fOuts = new FileOutputStream(jsonFile);
jsonFile.createNewFile();

Expand Down Expand Up @@ -155,15 +165,15 @@ public void getJson(String linkURL, String filePath, String suffix) throws IOExc

public void getDataRestApi() throws IOException {
String suffixLocal = this.filePath + "\\";
String url = "https://smr.cs.ualberta.ca/comparelibraries/api/libraries/?format=json";
String url = this.librariesURL;
String filePath = suffixLocal + "allLibraries.json";
getJson(url, filePath, "{\"Libraries\":");

url = "https://smr.cs.ualberta.ca/comparelibraries/api/charts/?format=json";
url = this.chartsURL;
filePath = suffixLocal + "allCharts.json";
getJson(url, filePath, "{\"Charts\":");

url = "https://smr.cs.ualberta.ca/comparelibraries/api/metrics/?format=json&latestdate=";
url = this.metricsURL ;
filePath = suffixLocal + "Version.json";
getJson(url, filePath, "{\"version\":");
}
Expand Down Expand Up @@ -415,8 +425,10 @@ public boolean sendFeedback(String jsonBodyStr, String tokenValue) throws IOExce

public void sendUser(String username, String jsonString) throws IOException {

String updateUrllink = "https://smr.cs.ualberta.ca/comparelibraries/api/pluginusers/" + username + "/";
String InsertUrllink = "https://smr.cs.ualberta.ca/comparelibraries/api/pluginusers/";
String updateUrllink = this.updateUrllink + username + "/";
String InsertUrllink = this.updateUrllink;


String tokenValue = getUserToken();

if (tokenValue.equals("NoToken")) {
Expand Down Expand Up @@ -548,7 +560,7 @@ public void sendFeedbackToCloud() throws IOException {
}
}

public String readMavenVersion(String urlStr) throws IOException {
public String readMavenVersion(String urlStr, int typeofMaven) throws IOException {
String returnValue = "// " + urlStr;
urlStr = urlStr + "/latest";
try {
Expand All @@ -559,9 +571,24 @@ public String readMavenVersion(String urlStr) throws IOException {
String inputLine;
int location = -1;
while (((inputLine = in.readLine()) != null) && (location == -1)) {
location = inputLine.indexOf("gradle-div");
if (location != -1) {
returnValue = " " + in.readLine() + "\n" + " " + in.readLine();
if (typeofMaven == 1)
{
location = inputLine.indexOf("gradle-div");
if (location != -1) {
returnValue = " " + in.readLine() + "\n" + " " + in.readLine();
}
}
if (typeofMaven == 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does typeOfMaven mean.. what is 1 vs 2? Can you perhaps create an enumeration for this for better readability like MVN_DEP_TYPE = {GRADLE, MAVEN} or something like that ?

{
location = inputLine.indexOf("maven-div");
if (location != -1) {
returnValue = "\t\t" + in.readLine() + "\n" + "\t\t" + in.readLine() + "\n" + "\t\t" + in.readLine() + "\n" + "\t\t" + in.readLine() + "\n" + "\t\t" + in.readLine() + "\n" + "\t\t" + in.readLine() + "\n" + "\t\t" + in.readLine();
returnValue = returnValue.replaceAll("&lt;","<");
returnValue = returnValue.replaceAll("&gt;",">");
returnValue = returnValue.replaceAll("&#32;&#32;&#32;&#32;","\t");


}
}
}
in.close();
Expand Down Expand Up @@ -646,9 +673,6 @@ public ArrayList <Library> getMetricsData(int metricDomain, int metricLibraryID
libraryDataPoint.setPackage(jsonObj.getString("package")); // Change tag to package
if (jsonObj.has("maven_url"))
libraryDataPoint.setMavenlink(jsonObj.getString("maven_url")); // Change tag to maven
// will be removed later
// libraryDataPoint.setMavenlink("https://mvnrepository.com/artifact/junit/junit");

if (jsonObj.has("popularity"))
libraryDataPoint.setPopularity(jsonObj.getDouble("popularity"));
if (jsonObj.has("release_frequency"))
Expand Down Expand Up @@ -728,5 +752,142 @@ public Image readCharts(int metric_DomainID, int metric_line) throws IOException
}
return img;
}



public void EnabledDomain(int domain, String project_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function name is unclear.. is it enableDomain.. is it isEnabledDomain? Don't think it's the latter since it doesn't return a bool but please use function names that indicate the action being taken or the check being performed etc

if (isEnabled(domain, project_name))
{ setdisabled(domain, project_name);}
else
{ setEnabled(domain, project_name);}

}

private void setdisabled(int domain, String project_name) {

String filePath = this.filePath +"\\"+ project_name +"domains.json";
File myFile = new File(filePath);
JSONObject Mainobj = null; // = new JSONObject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please start variable names with a small letter mainObj .. probably mainJSONObj?

if (myFile.exists()) {
String content = null;
try {
content = FileUtils.readFileToString(myFile, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
JSONObject objM = new JSONObject(content);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you try to use more descriptive variable names? what does objM mean?

JSONArray jsonarr = objM.getJSONArray("Domains");
int location = domainExist(domain, jsonarr);
jsonarr.remove(location);
Mainobj = new JSONObject();
Mainobj.put("Domains", jsonarr);
}
FileOutputStream fOuts = null;
try {
fOuts = new FileOutputStream(myFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String result = Mainobj.toString();
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOuts);
try {
myOutWriter.append(result);
myOutWriter.close();
} catch (IOException e) {
e.printStackTrace();
}


}

private void setEnabled(int domain, String project_name) {

String filePath = this.filePath +"\\"+ project_name +"domains.json";
File myFile = new File(filePath);
JSONObject Mainobj = null; // = new JSONObject();
if (myFile.exists()) {
String content = null;
try {
content = FileUtils.readFileToString(myFile, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
JSONObject objM = new JSONObject(content);
JSONArray jsonarr = objM.getJSONArray("Domains");
jsonarr.put(domain);
Mainobj = new JSONObject();
Mainobj.put("Domains", jsonarr);
} else
{
Mainobj = new JSONObject();
JSONArray array = new JSONArray();
array.put(domain);
Mainobj.put("Domains", array);
}

FileOutputStream fOuts = null;
try {
fOuts = new FileOutputStream(myFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String result = Mainobj.toString();
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOuts);
try {
myOutWriter.append(result);
} catch (IOException e) {
e.printStackTrace();
}
try {
myOutWriter.close();
} catch (IOException e) {
e.printStackTrace();
}


}


private int domainExist(int domain, JSONArray arr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again the function name does not indicate the action/check being performed

{
Boolean found = false;
int index = 0;
while (!found && index < arr.length() )
{
if (arr.getInt(index) == domain)
{
found = true;
} else {++index;}
}
if (!found) index = -1;
return index;
}

public boolean isEnabled(int domain, String project_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is what enabled?

boolean disabled = false;
String filePath = this.filePath +"\\"+ project_name +"domains.json";

File myFile = new File(filePath);
JSONObject Mainobj = null; // = new JSONObject();
if (myFile.exists()) {
String content = null;
try {
content = FileUtils.readFileToString(myFile, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
JSONObject objM = new JSONObject(content);
JSONArray arr = objM.getJSONArray("Domains");
int location = domainExist(domain, arr);
if (location > -1)
{ disabled = true; }
} else
{ disabled = false; }

return disabled;
}



}

Loading