diff --git a/Library_Comparison-1.0.11.zip b/Library_Comparison-1.0.11.zip deleted file mode 100644 index f44b92e..0000000 Binary files a/Library_Comparison-1.0.11.zip and /dev/null differ diff --git a/Library_Comparison-1.0.13.zip b/Library_Comparison-1.0.13.zip new file mode 100644 index 0000000..ff28af2 Binary files /dev/null and b/Library_Comparison-1.0.13.zip differ diff --git a/PluginCode/.idea/modules.xml b/PluginCode/.idea/modules.xml deleted file mode 100644 index 7da28ed..0000000 --- a/PluginCode/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/PluginCode/build.gradle b/PluginCode/build.gradle index 4addd27..fb66ab8 100644 --- a/PluginCode/build.gradle +++ b/PluginCode/build.gradle @@ -3,9 +3,8 @@ 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 @@ -13,8 +12,6 @@ repositories { mavenCentral() } - - dependencies { compile group: 'org.json', name: 'json', version: '20180813' } @@ -22,7 +19,10 @@ dependencies { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { plugins 'java' + version '2020.1.1' + updateSinceUntilBuild false } + patchPluginXml { changeNotes """ Add change notes here.
diff --git a/PluginCode/src/main/java/PostStartupActivity.java b/PluginCode/src/main/java/PostStartupActivity.java index df78a9e..b36f710 100644 --- a/PluginCode/src/main/java/PostStartupActivity.java +++ b/PluginCode/src/main/java/PostStartupActivity.java @@ -33,6 +33,7 @@ public void runActivity(@NotNull Project project) { @Override public void selectionChanged(@NotNull FileEditorManagerEvent event) { + ReplacementAction actionPerformed = new ReplacementAction(); try { actionPerformed.detectAllOpenEditors(); diff --git a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/DatabaseAccess.java b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/DatabaseAccess.java index fe6aba9..f886fd9 100644 --- a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/DatabaseAccess.java +++ b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/DatabaseAccess.java @@ -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.*; @@ -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; @@ -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/"; public ArrayList selectJsonAllLibraries(String librarySelected) throws IOException { @@ -63,8 +73,6 @@ public ArrayList 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) { @@ -72,7 +80,6 @@ public ArrayList selectJsonAllLibraries(String librarySelected) throws I domainLibraries.add(Long.toString(domain_id)); domainLibraries.add(domain_name); } - } } return domainLibraries; @@ -80,7 +87,7 @@ public ArrayList selectJsonAllLibraries(String librarySelected) throws I 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"); @@ -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(); @@ -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\":"); } @@ -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")) { @@ -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 { @@ -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) + { + 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("<","<"); + returnValue = returnValue.replaceAll(">",">"); + returnValue = returnValue.replaceAll(" ","\t"); + + + } } } in.close(); @@ -646,9 +673,6 @@ public ArrayList 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")) @@ -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) { + 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(); + 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"); + 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) + { + 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) { + 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; + } + + + } diff --git a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/EnableDomainAction.java b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/EnableDomainAction.java new file mode 100644 index 0000000..60844f0 --- /dev/null +++ b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/EnableDomainAction.java @@ -0,0 +1,317 @@ +package smr.cs.ualberta.libcomp.action; + +import com.android.aapt.Resources; +import com.intellij.lang.ASTNode; +import com.intellij.lang.FileASTNode; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.markup.MarkupModel; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.TextEditor; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.WindowManager; +import com.intellij.xdebugger.ui.DebuggerColors; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.editor.*; +import com.intellij.psi.*; +import com.intellij.psi.PsiImportList; +import com.intellij.psi.PsiFile; +import org.apache.commons.lang.StringUtils; +import org.jetbrains.annotations.NotNull; +import smr.cs.ualberta.libcomp.*; +import smr.cs.ualberta.libcomp.data.DependencyStatement; +import smr.cs.ualberta.libcomp.data.ReplacementFeedback; +import smr.cs.ualberta.libcomp.data.ImportStatement; +import smr.cs.ualberta.libcomp.data.User; +import smr.cs.ualberta.libcomp.dialog.ReplacementDialog; + +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; + +/** + * The ActionReplacement class is the main action for the plugin + * This is triggered by the replacement button on the main plugin dialog + */ + +public class EnableDomainAction extends AnAction { + + public int ExludedDomains; + + public EnableDomainAction() { + ExludedDomains = 2; + } + + @Override + public void actionPerformed(@NotNull final AnActionEvent event) { + ExludedDomains = 3; + + Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); + PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); + final Project project = event.getRequiredData(CommonDataKeys.PROJECT); + + if (psiFile != null) { + FileType fileType = psiFile.getFileType(); + + if (fileType.getDefaultExtension().equalsIgnoreCase("java")) { + detectImports(psiFile, editor, project); + } + + if (fileType.getDefaultExtension().equalsIgnoreCase("groovy")) + { + try { + detectDependancy(editor, psiFile , project); + } catch (IOException e) { + e.printStackTrace(); + } + event.getPresentation().setEnabledAndVisible(true); + } + + if (fileType.getDefaultExtension().equalsIgnoreCase("xml")) + { + try { + detectMaven(editor, psiFile , project); + } catch (IOException e) { + e.printStackTrace(); + } + event.getPresentation().setEnabledAndVisible(true); + } + + event.getPresentation().setVisible(true); + event.getPresentation().setEnabled(true); + } + } // end of actionPErformed + + + public int detectDependenciesPSI(FileASTNode psinode) + { + int location = -1; + ASTNode child = psinode.getFirstChildNode(); + String name = child.getText(); + boolean found = name.contains("dependencies"); + boolean over = false; + while ((!found) && (!over)) + { + child = child.getTreeNext(); + if (child != null) + { + name = child.getText(); + found = name.contains("dependencies"); + } + else over = true; + } + if (found) + { + location = child.getStartOffset(); + } + return location; + } + + public int detectMavenPSI(final Document document) + { + int location = -1; + int i = 0; + + int startOffset = document.getLineStartOffset(i); + int endOffset = document.getLineEndOffset(i); + String name = document.getText(new TextRange(startOffset, endOffset)).trim(); + boolean found = name.contains("dependencies"); + boolean over = false; + while ((!found) && (!over)) + { + ++i; + startOffset = document.getLineStartOffset(i); + endOffset = document.getLineEndOffset(i); + name = document.getText(new TextRange(startOffset, endOffset)).trim(); + found = name.contains("dependencies"); + over = name.contains(""); + } + if (found) + { + location = i; + } + return location; + } + + public void detectMaven(@NotNull final Editor editor, @NotNull final PsiFile psiFile, @NotNull final Project project ) throws IOException { + + final MarkupModel editorModel = editor.getMarkupModel(); + final Document document = editor.getDocument(); + String project_name = project.getName(); + + TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); + TextAttributes softerAttributes = attributes.clone(); + boolean dependenciesExists = false; + int i = 0; + int loc = detectMavenPSI(document); // Parse PSI to detect the PSI dependencies node + if (loc != -1) // dependencies exists + { + dependenciesExists = true; + i = document.getLineNumber(loc); // line number of the dependencies PSI node + } + + Caret primaryCaret = editor.getCaretModel().getPrimaryCaret(); + int mouseClickLocation = primaryCaret.getOffset(); + int clickedLineNumber = document.getLineNumber(mouseClickLocation); + + + String lineText = null; + String selectedTerm; + + while (dependenciesExists) + { + int startOffset = document.getLineStartOffset(i); + int endOffset = document.getLineEndOffset(i); + + lineText = null; + String[] valuesInQuotes = new String[0]; + valuesInQuotes = null; + lineText = document.getText(new TextRange(startOffset, endOffset)).trim(); + if ((lineText != null) && (lineText.length()>2)) + {valuesInQuotes = StringUtils.substringsBetween(lineText, "", "");} + + + if (i == clickedLineNumber) { + if (valuesInQuotes != null) { + selectedTerm = valuesInQuotes[0]; + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ArrayList choicesArray = dataAccessObject.selectJsonAllLibraries(selectedTerm); + if (choicesArray.size() > 0) { + int domain = Integer.parseInt(choicesArray.get(1)); + dataAccessObject.EnabledDomain (domain, project_name); + ReplacementAction actionPerformed = new ReplacementAction(); + try { + actionPerformed.detectAllOpenEditors(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + ++i; + boolean isContainsEnd = lineText.contains(""); + if (isContainsEnd) { + dependenciesExists = false; + } + } + } + + + + public void detectDependancy(@NotNull final Editor editor, @NotNull final PsiFile psiFile, @NotNull final Project project ) throws IOException { + + final MarkupModel editorModel = editor.getMarkupModel(); + final Document document = editor.getDocument(); + String project_name = project.getName(); + + TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); + TextAttributes softerAttributes = attributes.clone(); + boolean dependenciesExists = false; + int i = 0; + int loc = detectDependenciesPSI(psiFile.getNode()); // Parse PSI to detect the PSI dependencies node + if (loc != -1) // dependencies exists + { + dependenciesExists = true; + i = document.getLineNumber(loc); // line number of the dependencies PSI node + } + + Caret primaryCaret = editor.getCaretModel().getPrimaryCaret(); + int mouseClickLocation = primaryCaret.getOffset(); + int clickedLineNumber = document.getLineNumber(mouseClickLocation); + + + String lineText = null; + String selectedTerm; +// editorModel.removeAllHighlighters(); + + while (dependenciesExists) + { + int startOffset = document.getLineStartOffset(i); + int endOffset = document.getLineEndOffset(i); + lineText = document.getText(new TextRange(startOffset, endOffset)).trim(); + String[] valuesInQuotes = StringUtils.substringsBetween(lineText, "\'", "\'"); + if (i == clickedLineNumber) { + if (valuesInQuotes != null) { + selectedTerm = valuesInQuotes[0]; + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ArrayList choicesArray = dataAccessObject.selectJsonAllLibraries(selectedTerm); + if (choicesArray.size() > 0) { + int domain = Integer.parseInt(choicesArray.get(1)); + dataAccessObject.EnabledDomain (domain, project_name); + ReplacementAction actionPerformed = new ReplacementAction(); + try { + actionPerformed.detectAllOpenEditors(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + ++i; + boolean isContainsEnd = lineText.contains("}"); + if (isContainsEnd) { + dependenciesExists = false; + } + } + } + + + public void detectImports(@NotNull final PsiFile psiFile, @NotNull final Editor editor, @NotNull final Project project ) { + + try { + final Document document = editor.getDocument(); + PsiJavaFile javaFile = (PsiJavaFile)psiFile; + PsiImportList importList = javaFile.getImportList(); + String project_name = project.getName(); + + if (importList == null) { return; } + int importLineNumber; + Caret primaryCaret = editor.getCaretModel().getPrimaryCaret(); + int mouseClickLocation = primaryCaret.getOffset(); + int clickedLineNumber = document.getLineNumber(mouseClickLocation); + + for (PsiImportStatementBase importStatementObject : importList.getAllImportStatements()) { + String TermSelected = importStatementObject.getImportReference().getReferenceName(); + int locationLastWord = importStatementObject.getImportReference().getTextOffset(); + importLineNumber = document.getLineNumber(locationLastWord); + if (importLineNumber == clickedLineNumber) + { + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ArrayList choicesArray = dataAccessObject.selectJsonAllLibraries(TermSelected); + if (choicesArray.size()>0){ + int domain = Integer.parseInt(choicesArray.get(1)); + dataAccessObject.EnabledDomain (domain, project_name); + ReplacementAction actionPerformed = new ReplacementAction(); + try { + actionPerformed.detectAllOpenEditors(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + } + catch(Exception e) { + e.printStackTrace(); + } + } + + + + + + +} // end of class + diff --git a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/ReplacementAction.java b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/ReplacementAction.java index 054e05b..ed59fd4 100644 --- a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/ReplacementAction.java +++ b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/action/ReplacementAction.java @@ -49,13 +49,18 @@ public class ReplacementAction extends AnAction { public ArrayList ImportListObjects; public ArrayList DependListObjects; + public ArrayList MavenListObjects; private int to_library; private String full_lib_list; private String libraryName; private boolean sendToCloud = false ; + + public ReplacementAction() { ImportListObjects = new ArrayList<>(); DependListObjects = new ArrayList<>(); + MavenListObjects = new ArrayList<>(); + } /** @@ -68,6 +73,7 @@ public void actionPerformed(@NotNull final AnActionEvent event) { PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); if (psiFile != null) { FileType fileType = psiFile.getFileType(); + if (fileType.getDefaultExtension().equalsIgnoreCase("java")) { try { replaceRequestedImport(event); @@ -77,11 +83,21 @@ public void actionPerformed(@NotNull final AnActionEvent event) { } } - else { + + if (fileType.getDefaultExtension().equalsIgnoreCase("xml")) { + try { + replaceRequestedMaven(event); + detectMavenOnAction(event); + } catch (ParseException e) { + e.printStackTrace(); + } + + } + + if (fileType.getDefaultExtension().equalsIgnoreCase("groovy")) { try { replaceRequestedDependency(event); detectDependencyOnAction(event); - // from here } catch (ParseException | IOException e) { e.printStackTrace(); } @@ -108,7 +124,9 @@ public Project getActiveProject() public void detectAllOpenEditors() throws IOException { Project proj= getActiveProject(); - + String project_name = "none"; + if (proj == null) { return;} + project_name = proj.getName(); FileEditorManager manager = FileEditorManager.getInstance(proj); VirtualFile[] filesAll = manager.getOpenFiles(); FileEditor[] editorFileAll = manager.getAllEditors(); @@ -121,12 +139,13 @@ public void detectAllOpenEditors() throws IOException { if (psiFile != null) { FileType fileType = psiFile.getFileType(); - if (fileType.getDefaultExtension().equalsIgnoreCase("java")) { - detectImports(psiFile, editor); - } - else { - detectDependancy(editor, psiFile); - } + + if (fileType.getDefaultExtension().equalsIgnoreCase("java")) + {detectImports(psiFile, editor, project_name); } + if (fileType.getDefaultExtension().equalsIgnoreCase("xml")) + {detectMaven(editor, psiFile, project_name);} + if (fileType.getDefaultExtension().equalsIgnoreCase("groovy")) + {detectDependancy(editor, psiFile, project_name);} } indexOpenEditors = indexOpenEditors + 1; } @@ -152,20 +171,12 @@ public int detectDependenciesPSI(FileASTNode psinode) if (found) { location = child.getStartOffset(); - } - return location; - } - public String parsePackage(String term) - { - String returnTerml = ""; - // returnTerml = term.substring(term.lastIndexOf(".") + 1); - return returnTerml; - } - public void detectDependancy(@NotNull final Editor editor, @NotNull final PsiFile psiFile ) throws IOException { + + public void detectDependancy(@NotNull final Editor editor, @NotNull final PsiFile psiFile, @NotNull final String project_name ) throws IOException { final MarkupModel editorModel = editor.getMarkupModel(); final Document document = editor.getDocument(); @@ -179,8 +190,6 @@ public void detectDependancy(@NotNull final Editor editor, @NotNull final PsiFil dependenciesExists = true; i = document.getLineNumber(loc); // line number of the dependencies PSI node } - - String lineText; String selectedTerm; DependListObjects.clear(); @@ -190,9 +199,18 @@ public void detectDependancy(@NotNull final Editor editor, @NotNull final PsiFil { int startOffset = document.getLineStartOffset(i); int endOffset = document.getLineEndOffset(i); + lineText = null; + String[] valuesInQuotes = new String[0]; + valuesInQuotes = null; + lineText = document.getText(new TextRange(startOffset, endOffset)).trim(); - String[] valuesInQuotes = StringUtils.substringsBetween(lineText, "\'", "\'"); - if (valuesInQuotes != null) { + + if ((lineText != null) && (lineText.length()>2)) + {valuesInQuotes = StringUtils.substringsBetween(lineText, "\'", "\'");} + + + + if (valuesInQuotes != null) { selectedTerm = valuesInQuotes[0]; DatabaseAccess dataAccessObject = new DatabaseAccess(); @@ -205,27 +223,158 @@ public void detectDependancy(@NotNull final Editor editor, @NotNull final PsiFil depObj.setDomainName(choicesArray.get(2)); depObj.setFromlocation(startOffset); depObj.setTolocation(endOffset); + + if (dataAccessObject.isEnabled(Integer.parseInt(choicesArray.get(1)), project_name)) { + depObj.setEnableddomain(false); + } + else { + depObj.setEnableddomain(true); + } + DependListObjects.add(depObj); + + if (depObj.getEnableddomain()) { + editorModel.addLineHighlighter(i, + DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes); + + } + + + } + } + ++i; + boolean isContainsEnd = lineText.contains("}"); + if (isContainsEnd) { + dependenciesExists = false; + } + } + } + + + public int detectMavenPSI(final Document document) + { + int location = -1; + int i = 0; + + int startOffset = document.getLineStartOffset(i); + int endOffset = document.getLineEndOffset(i); + String name = document.getText(new TextRange(startOffset, endOffset)).trim(); + boolean found = name.contains("dependencies"); + boolean over = false; + while ((!found) && (!over)) + { + ++i; + startOffset = document.getLineStartOffset(i); + endOffset = document.getLineEndOffset(i); + name = document.getText(new TextRange(startOffset, endOffset)).trim(); + found = name.contains("dependencies"); + over = name.contains(""); + } + if (found) + { + location = i; + } + return location; + } + + public void detectMaven(@NotNull final Editor editor, @NotNull final PsiFile psiFile, @NotNull final String project_name ) throws IOException { + + final MarkupModel editorModel = editor.getMarkupModel(); + final Document document = editor.getDocument(); + String lineText; + String selectedTerm; + + TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); + TextAttributes softerAttributes = attributes.clone(); + boolean dependenciesExists = false; + int i = 0; + int loc = detectMavenPSI(document); // Parse PSI to detect the PSI dependencies node + if (loc != -1) // dependencies exists + { + dependenciesExists = true; + i = loc; // line number of the dependencies PSI node + } + MavenListObjects.clear(); + editorModel.removeAllHighlighters(); + + while (dependenciesExists) + { + int startOffset = document.getLineStartOffset(i); + int endOffset = document.getLineEndOffset(i); + lineText = null; + String[] valuesInQuotes = new String[0]; + valuesInQuotes = null; + lineText = document.getText(new TextRange(startOffset, endOffset)).trim(); + if ((lineText != null) && (lineText.length()>2)) + {valuesInQuotes = StringUtils.substringsBetween(lineText, "", "");} + + if (valuesInQuotes != null) { + selectedTerm = valuesInQuotes[0]; + + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ArrayList choicesArray = dataAccessObject.selectJsonAllLibraries(selectedTerm); + if (choicesArray.size() > 0) { + DependencyStatement depObj = new DependencyStatement(); + depObj.setImportLocation(i); + depObj.setImportLib(Integer.parseInt(choicesArray.get(0))); + depObj.setImportDomain(Integer.parseInt(choicesArray.get(1))); + depObj.setDomainName(choicesArray.get(2)); + depObj.setFromlocation(startOffset); + depObj.setTolocation(endOffset); + + if (dataAccessObject.isEnabled(Integer.parseInt(choicesArray.get(1)), project_name)) { + depObj.setEnableddomain(false); + } + else { + depObj.setEnableddomain(true); + } + + MavenListObjects.add(depObj); + + + if (depObj.getEnableddomain()) { editorModel.addLineHighlighter(i, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes); + } + + } + } ++i; - boolean isContainsEnd = lineText.contains("}"); + boolean isContainsEnd = lineText.contains(""); if (isContainsEnd) { dependenciesExists = false; } } } + public void detectMavenOnAction(@NotNull final AnActionEvent event) { + + Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); + PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); + final Project project = event.getRequiredData(CommonDataKeys.PROJECT); + String project_name = project.getName(); + + try { + detectMaven(editor, psiFile, project_name); + } + catch(Exception e) { + e.printStackTrace(); + } + + } + public void detectDependencyOnAction(@NotNull final AnActionEvent event) throws IOException { Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); + final Project project = event.getRequiredData(CommonDataKeys.PROJECT); + String project_name = project.getName(); try { - detectDependancy(editor, psiFile); + detectDependancy(editor, psiFile, project_name); } catch(Exception e) { e.printStackTrace(); @@ -261,10 +410,12 @@ public void update(@NotNull final AnActionEvent event) { e.printStackTrace(); } } - else { + if (fileType.getDefaultExtension().equalsIgnoreCase("xml")) { + detectMavenOnAction(event); + } + if (fileType.getDefaultExtension().equalsIgnoreCase("groovy")) { try { detectDependencyOnAction(event); - event.getPresentation().setEnabledAndVisible(true); } catch (IOException e) { @@ -410,17 +561,162 @@ public void windowClosing(WindowEvent e) { } } - public void replaceRequestedDependency(@NotNull final AnActionEvent event) throws ParseException { + public void replaceRequestedMaven(@NotNull final AnActionEvent event) throws ParseException { final Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); final Project project = event.getRequiredData(CommonDataKeys.PROJECT); final Document document = editor.getDocument(); PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); - final MarkupModel editorModel = editor.getMarkupModel(); + String project_name = project.getName(); + String class_name = "Maven File"; + + Date action_date = new Date(); + int from_library; + + User userRecord = new User(); + DatabaseAccess dataAccessObject = new DatabaseAccess(); + userRecord = dataAccessObject.readUserProfile(); + sendToCloud = (Integer.parseInt(userRecord.getSendAllCloud())==1); + + //Work off of the primary caret to get the selection info + Caret primaryCaret = editor.getCaretModel().getPrimaryCaret(); + + //Get the location of the mouse click, get the caret offset, then from the offset get the line number + int mouseClickLocation = primaryCaret.getOffset(); + int clickedLineNumber = document.getLineNumber(mouseClickLocation); + + //Check if the user clicked on a line that is potentially replaceable (i.e. import statement is in database) + int currentLine = 0; + int locationStartOfImport; + int locationEndOfImport; + + while (currentLine < MavenListObjects.size()) { + if (MavenListObjects.get(currentLine).getImportLocation() == clickedLineNumber) { + from_library = MavenListObjects.get(currentLine).getImportLib(); + locationStartOfImport = MavenListObjects.get(currentLine).getFromlocation(); + locationEndOfImport = MavenListObjects.get(currentLine).getTolocation(); + int finalFrom_library = from_library; + + ReplacementDialog replacementDialog =new ReplacementDialog(MavenListObjects.get(currentLine).getDomainName(), MavenListObjects.get(currentLine).getImportDomain(),MavenListObjects.get(currentLine).getImportLib()); + + // int finalLocationStartOfImport = locationStartOfImport; + int finalLocationStartOfImport = document.getLineStartOffset(clickedLineNumber - 1); + int finalLocationEndOfImport = locationEndOfImport; + finalLocationEndOfImport = document.getLineEndOffset(clickedLineNumber + 4); + String finalClass_name = class_name; + int finalLocationEndOfImport1 = finalLocationEndOfImport; + int finalLocationEndOfImport2 = finalLocationEndOfImport; + WindowAdapter adapter = new WindowAdapter() { + + @Override + public void windowLostFocus(WindowEvent e) { + String finalChoice = replacementDialog.getMavenReturned(); + + to_library = replacementDialog.getto_library(); + full_lib_list = replacementDialog.getSelectionLibrary(); + libraryName = replacementDialog.getLibraryname(); + + if (finalChoice.equals("None") == false) { + try { + finalChoice = dataAccessObject.readMavenVersion(finalChoice,2); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + + String finalChoice1 = finalChoice; + WriteCommandAction.runWriteCommandAction(project, () -> + document.replaceString(finalLocationStartOfImport, finalLocationEndOfImport1, finalChoice1)); + + try { + detectMaven(editor, psiFile, project_name); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + + + } + + try { + + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ReplacementFeedback replacementFeedbackPoint = new ReplacementFeedback(0, action_date, clickedLineNumber, project_name, finalClass_name, full_lib_list, finalFrom_library, to_library); + dataAccessObject.updateFeedback(sendToCloud, replacementFeedbackPoint); + + } + catch (IOException ioException) { + ioException.printStackTrace(); + } + } + + @Override + public void windowClosing(WindowEvent e) { + String finalChoice = replacementDialog.getMavenReturned(); + to_library = replacementDialog.getto_library(); + full_lib_list = replacementDialog.getSelectionLibrary(); + libraryName = replacementDialog.getLibraryname(); + + if (finalChoice.equals("None") == false) { + + try { + finalChoice = dataAccessObject.readMavenVersion(finalChoice, 2); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + + String finalChoice1 = finalChoice; + + WriteCommandAction.runWriteCommandAction(project, () -> + document.replaceString(finalLocationStartOfImport, finalLocationEndOfImport2, finalChoice1)); + + try { + detectMaven(editor, psiFile, project_name); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + + + try { + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ReplacementFeedback replacementFeedbackPoint = new ReplacementFeedback(0, action_date, clickedLineNumber, project_name, finalClass_name, full_lib_list, finalFrom_library, to_library); + dataAccessObject.updateFeedback(sendToCloud, replacementFeedbackPoint); + + } + catch (IOException ioException) { + ioException.printStackTrace(); + } + } + try { + + DatabaseAccess dataAccessObject = new DatabaseAccess(); + ReplacementFeedback replacementFeedbackPoint = new ReplacementFeedback(0, action_date, clickedLineNumber, project_name, finalClass_name, full_lib_list, finalFrom_library, to_library); + dataAccessObject.updateFeedback(sendToCloud, replacementFeedbackPoint); + + } + catch (IOException ioException) { + ioException.printStackTrace(); + } + } + }; + replacementDialog.addWindowListener(adapter); + replacementDialog.addWindowFocusListener(adapter); + replacementDialog.setVisible(true); + } + currentLine = currentLine + 1; + } + } + + + + public void replaceRequestedDependency(@NotNull final AnActionEvent event) throws ParseException { + + final Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); + final Project project = event.getRequiredData(CommonDataKeys.PROJECT); + final Document document = editor.getDocument(); + PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); String project_name = project.getName(); - String class_name = ""; + String class_name = "groovy Class"; Date action_date = new Date(); int from_library; @@ -469,7 +765,7 @@ public void windowLostFocus(WindowEvent e) { if (finalChoice.equals("None") == false) { try { - finalChoice = dataAccessObject.readMavenVersion(finalChoice); + finalChoice = dataAccessObject.readMavenVersion(finalChoice, 1); } catch (IOException ioException) { ioException.printStackTrace(); } @@ -479,7 +775,7 @@ public void windowLostFocus(WindowEvent e) { document.replaceString(finalLocationStartOfImport, finalLocationEndOfImport1, finalChoice1)); try { - detectDependancy(editor, psiFile); + detectDependancy(editor, psiFile, project_name); } catch (IOException ioException) { ioException.printStackTrace(); } @@ -509,7 +805,7 @@ public void windowClosing(WindowEvent e) { if (finalChoice.equals("None") == false) { try { - finalChoice = dataAccessObject.readMavenVersion(finalChoice); + finalChoice = dataAccessObject.readMavenVersion(finalChoice, 1); } catch (IOException ioException) { ioException.printStackTrace(); } @@ -520,7 +816,7 @@ public void windowClosing(WindowEvent e) { document.replaceString(finalLocationStartOfImport, finalLocationEndOfImport2, finalChoice1)); try { - detectDependancy(editor, psiFile); + detectDependancy(editor, psiFile, project_name); } catch (IOException ioException) { ioException.printStackTrace(); } @@ -556,13 +852,21 @@ public void windowClosing(WindowEvent e) { } } + public Boolean domainsEnabled (int domain) + { + Boolean enabledDomain = false; + + if (domain < 2) { enabledDomain = true; } + + return enabledDomain; + } /** * The detectImportStatementMethod will got through the current open file and test the import statements to see if they are in the database * The trigger for this to occur is a right click anywhere in the editor, I have yet to figure out how to have it work onLoad * Right now, the library being queried is the "last word" of the import statement * ex. for my.import.statement.rehab, the term queried against in the database is "rehab" */ - public void detectImports(@NotNull final PsiFile psiFile, @NotNull final Editor editor ) { + public void detectImports(@NotNull final PsiFile psiFile, @NotNull final Editor editor, @NotNull final String project_name ) { try { final MarkupModel editorModel = editor.getMarkupModel(); @@ -603,11 +907,18 @@ public void detectImports(@NotNull final PsiFile psiFile, @NotNull final Editor impObj.setImportLib(Integer.parseInt(choicesArray.get(0))); impObj.setImportDomain(Integer.parseInt(choicesArray.get(1))); impObj.setDomainName(choicesArray.get(2)); + if (dataAccessObject.isEnabled(Integer.parseInt(choicesArray.get(1)), project_name)) { + impObj.setEnableddomain(false); + } + else { + impObj.setEnableddomain(true); + } ImportListObjects.add(impObj); - //highlight the line - editorModel.addLineHighlighter(importLineNumber, - DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1,softerAttributes); + if (impObj.getEnableddomain()) { + editorModel.addLineHighlighter(importLineNumber, + DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1,softerAttributes); + } } } } @@ -620,9 +931,11 @@ public void detectImportOnAction(@NotNull final AnActionEvent event) throws IOEx PsiFile psiFile = event.getRequiredData(CommonDataKeys.PSI_FILE); Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); + final Project project = event.getRequiredData(CommonDataKeys.PROJECT); + String project_name = project.getName(); try { - detectImports(psiFile, editor); + detectImports(psiFile, editor, project_name); } catch(Exception e) { e.printStackTrace(); diff --git a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/DependencyStatement.java b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/DependencyStatement.java index e2d4354..7a140ab 100644 --- a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/DependencyStatement.java +++ b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/DependencyStatement.java @@ -9,7 +9,9 @@ public DependencyStatement() {} public Integer fromlocation; public Integer tolocation; private String domainName; + private Boolean Enableddomain; + public Boolean getEnableddomain() { return Enableddomain;} public Integer getImportLocation() { return importLocation; } public Integer getImportDomain() { return importDomain; } public Integer getImportLib() { return importLib; } @@ -23,5 +25,5 @@ public DependencyStatement() {} public void setFromlocation(Integer fromlocation) { this.fromlocation = fromlocation; } public void setTolocation(Integer tolocation) { this.tolocation = tolocation; } public void setDomainName(String domainName) { this.domainName = domainName; } - + public void setEnableddomain(Boolean enableddomain) { Enableddomain = enableddomain; } } diff --git a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/ImportStatement.java b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/ImportStatement.java index 710668f..da591fc 100644 --- a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/ImportStatement.java +++ b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/data/ImportStatement.java @@ -13,6 +13,8 @@ public class ImportStatement { public Integer importDomain; public Integer importLib; private String domainName; + private Boolean Enableddomain; + public ImportStatement() { } @@ -21,11 +23,13 @@ public ImportStatement() { public Integer getImportDomain() { return importDomain; } public Integer getImportLib() { return importLib; } public String getDomainName() { return domainName; } + public Boolean getEnableddomain() { return Enableddomain; } + public void setDomainName(String domainName) { this.domainName = "Libraries from the " + domainName + " domain"; } public void setImportListBase(PsiImportStatementBase importListBase) { this.importListBase = importListBase; } public void setImportLocation(Integer importLocation) {this.importLocation = importLocation; } public void setImportDomain(Integer importDomain) {this.importDomain = importDomain; } public void setImportLib(Integer importLib) { this.importLib = importLib; } - + public void setEnableddomain(Boolean enableddomain) { Enableddomain = enableddomain; } } diff --git a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/dialog/ReplacementDialog.java b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/dialog/ReplacementDialog.java index 7255ade..19e9adb 100644 --- a/PluginCode/src/main/java/smr/cs/ualberta/libcomp/dialog/ReplacementDialog.java +++ b/PluginCode/src/main/java/smr/cs/ualberta/libcomp/dialog/ReplacementDialog.java @@ -57,6 +57,7 @@ public class ReplacementDialog extends JFrame { private DecimalFormat percentf; private DecimalFormat changef; private DecimalFormat scoref; + private String NoData = "No Data"; private Color colorBackGround = new Color(210, 210, 210); private Color colorForGround = new Color(255, 255, 255); private Color colorForGroundDis = new Color(0, 0, 0); @@ -70,7 +71,7 @@ public class ReplacementDialog extends JFrame { "Column 2 Sort Descending", "Column 3 Sort Ascending", "The header row shows your current library, click on an alternative library to replace", - "Number of times the library is imported per 1000 repositories", //popularity + "Number of times the library package is imported in the 1000 top starred repositories on GitHub", //popularity "Average time in days between two consecutive releases of a library", //release frequency "Average time in days to close issues in the issue tracking system of a library", //issue closing time "Average time in days to get the first response on issues in the issue tracking system of a library", //issue response time @@ -166,19 +167,15 @@ public ReplacementDialog(String domainName, int domainId, int libID) throws Head dataDate = new LocalDate[2][columnLength]; // only two date Format dataString = new String[1][columnLength]; // only one String format - current = 0; df = new DecimalFormat("#"); - intf = new DecimalFormat("# Repos"); + intf = new DecimalFormat("#'/1000' Repos"); // "#/1000 Repos" daysf = new DecimalFormat("# Days"); reposf = new DecimalFormat("# Repos"); percentf = new DecimalFormat("0.00 %"); - changef = new DecimalFormat("# Changes"); + changef = new DecimalFormat("# Breaking Changes"); scoref = new DecimalFormat("0.00/5 "); - // datef = new DateFormat("yyy-MM-DD"); - - data[indexPopularity][offsetBtnCols - 1] = "Popularity (Repos)"; data[indexRelease][offsetBtnCols - 1] = "Release Frequency (Days)"; data[indexIssueClosing][offsetBtnCols - 1] = "Issue Closing Time (Days)"; @@ -192,7 +189,6 @@ public ReplacementDialog(String domainName, int domainId, int libID) throws Head data[rowLength][offsetBtnCols - 1] = "Last Modification Date"; data[rowLength + 1][offsetBtnCols - 1] = "License"; - while (current < columnLength - offsetBtnCols) { dataDouble[indexPopularity][current + offsetBtnCols] = (libraryList.get(current).getPopularity()); @@ -208,14 +204,51 @@ public ReplacementDialog(String domainName, int domainId, int libID) throws Head dataDate[indexModification][current + offsetBtnCols] = (libraryList.get(current).getLast_modification_date()); dataString[indexLicense][current + offsetBtnCols] = (libraryList.get(current).getLicense()); - data[indexPopularity][current + offsetBtnCols] = intf.format(libraryList.get(current).getPopularity()); - data[indexRelease][current + offsetBtnCols] = daysf.format(libraryList.get(current).getRelease_frequency()); - data[indexIssueClosing][current + offsetBtnCols] = daysf.format(libraryList.get(current).getIssue_closing_time()); - data[indexIssueResponse][current + offsetBtnCols] = daysf.format(libraryList.get(current).getIssue_response_time()); - data[indexBackwardCompatibility][current + offsetBtnCols] = changef.format(libraryList.get(current).getBackwards_compatibility()); - data[indexSecurity][current + offsetBtnCols] = percentf.format(libraryList.get(current).getSecurity()); - data[indexPerformance][current + offsetBtnCols] = percentf.format(libraryList.get(current).getPerformance()); - data[indexScore][current + offsetBtnCols] = scoref.format(libraryList.get(current).getOverall_score()); + if (libraryList.get(current).getPopularity() > 0) + data[indexPopularity][current + offsetBtnCols] = intf.format(libraryList.get(current).getPopularity()); + else + data[indexPopularity][current + offsetBtnCols] = NoData; + + if (libraryList.get(current).getRelease_frequency() > 0) + data[indexRelease][current + offsetBtnCols] = daysf.format(libraryList.get(current).getRelease_frequency()); + else + data[indexRelease][current + offsetBtnCols] = NoData; + + + if (libraryList.get(current).getIssue_closing_time() > 0) + data[indexIssueClosing][current + offsetBtnCols] = daysf.format(libraryList.get(current).getIssue_closing_time()); + else + data[indexIssueClosing][current + offsetBtnCols] = NoData; + + if (libraryList.get(current).getIssue_response_time() > 0) + data[indexIssueResponse][current + offsetBtnCols] = daysf.format(libraryList.get(current).getIssue_response_time()); + else + data[indexIssueResponse][current + offsetBtnCols] = NoData; + + + if (libraryList.get(current).getBackwards_compatibility() > 0) + data[indexBackwardCompatibility][current + offsetBtnCols] = changef.format(libraryList.get(current).getBackwards_compatibility()); + else + data[indexBackwardCompatibility][current + offsetBtnCols] = NoData; + + + if (libraryList.get(current).getSecurity() > 0) + data[indexSecurity][current + offsetBtnCols] = percentf.format(libraryList.get(current).getSecurity()); + else + data[indexSecurity][current + offsetBtnCols] = NoData; + + + if (libraryList.get(current).getPerformance() > 0) + data[indexPerformance][current + offsetBtnCols] = percentf.format(libraryList.get(current).getPerformance()); + else + data[indexPerformance][current + offsetBtnCols] = NoData; + + + if (libraryList.get(current).getOverall_score() > 0) + data[indexScore][current + offsetBtnCols] = scoref.format(libraryList.get(current).getOverall_score()); + else + data[indexScore][current + offsetBtnCols] = NoData; + if (libraryList.get(current).getLast_discussed_so().getYear() == 1900) data[7][current + offsetBtnCols] = "Never"; @@ -224,8 +257,6 @@ public ReplacementDialog(String domainName, int domainId, int libID) throws Head data[8][current + offsetBtnCols] = libraryList.get(current).getLast_modification_date(); - - data[9][current + offsetBtnCols] = libraryList.get(current).getLicense(); if (full_lib_list.length() < 1) @@ -243,8 +274,6 @@ public ReplacementDialog(String domainName, int domainId, int libID) throws Head public boolean isCellEditable(int row, int column) { return column < 0; } - - //Implement table cell tool tips. public String getToolTipText(MouseEvent e) { String tip = null; @@ -396,7 +425,7 @@ public void mouseClicked(MouseEvent e) { table.addColumnSelectionInterval(selectedLibrary, selectedLibrary); bConfirm.setEnabled(true); bConfirm.setBackground(cololrSelectColumn); - String message = "Replace " + libraryList.get(0).getPackage() + " Package with " + libraryList.get(columnM - offsetBtnCols).getPackage(); + String message = "Replace " + libraryList.get(currentLibrary - offsetBtnCols).getPackage() + " Package with " + libraryList.get(columnM - offsetBtnCols).getPackage(); bConfirm.setText(message); } @@ -543,28 +572,52 @@ else if (i == selectedLibrary) switch (rowIndex) { case 0: // indPopularity - table.getModel().setValueAt(intf.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(intf.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 1: // indRelease - table.getModel().setValueAt(daysf.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(daysf.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 2: //indIssueClosing - table.getModel().setValueAt(daysf.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(daysf.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 3: // indIssueResponse - table.getModel().setValueAt(daysf.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(daysf.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 4: //indBackward - table.getModel().setValueAt(changef.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(changef.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 5: // indSecurity - table.getModel().setValueAt(percentf.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(percentf.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 6: // indPerformance - table.getModel().setValueAt(percentf.format(dataDouble[rowIndex][i]), rowIndex, i); + if (dataDouble[rowIndex][i] >0) + table.getModel().setValueAt(percentf.format(dataDouble[rowIndex][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 10: // indOverScore - table.getModel().setValueAt(scoref.format(dataDouble[rowIndex-3][i]), rowIndex, i); + if (dataDouble[rowIndex-3][i] >0) + table.getModel().setValueAt(scoref.format(dataDouble[rowIndex-3][i]), rowIndex, i); + else + table.getModel().setValueAt(NoData, rowIndex, i); break; case 7: // Date String setValue; @@ -755,8 +808,6 @@ public Chart(String title, Image img) throws HeadlessException { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLocationRelativeTo(null); bConfirm.setEnabled(true); - - bConfirm.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { diff --git a/PluginCode/src/main/resources/META-INF/plugin.xml b/PluginCode/src/main/resources/META-INF/plugin.xml index cfc111b..8db8119 100644 --- a/PluginCode/src/main/resources/META-INF/plugin.xml +++ b/PluginCode/src/main/resources/META-INF/plugin.xml @@ -1,11 +1,10 @@ - my_Plugin.LibraryCompare - LibraryComparison + library.comparison + LibComp Rehab El-hajj The LibComp plugin is a tool to aid developers in Java library comparison. LibComp detects Java libraries and highlights them, the user is then able to click on these libraries and view other suggestions with relevant metric data and charts. All suggestions are Java libraries within the same domain as the original package. If the user chooses, they also have the option to replace a library package with one of the provided suggestions. This tool detects import statements in Java files and dependencies in the build.gradle file. - 1.0.11 - + 1.0.13 @@ -22,6 +21,16 @@ + + + + + - - + + + + +