Skip to content

Commit

Permalink
#40 conflict false negative
Browse files Browse the repository at this point in the history
  • Loading branch information
krasa committed Jun 6, 2019
1 parent 5fa1ade commit c911005
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 78 deletions.
6 changes: 4 additions & 2 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<id>MavenRunHelper</id>
<name>Maven Helper</name>
<version>4.4.183.4139.0</version>
<version>4.5.183.4139.0</version>

<vendor url="https://github.com/krasa/MavenHelper" email="[email protected]">Vojtech
Krasa
Expand Down Expand Up @@ -38,6 +38,8 @@
]]></description>

<change-notes><![CDATA[
<br>4.5
<br> - Fixed conflict false negative due to a <a href="https://youtrack.jetbrains.com/issue/IDEA-215596">bugged dependency resolution by IntelliJ</a>
<br>4.4
<br> - Goals rearranging fixed
<br>4.3
Expand Down Expand Up @@ -135,7 +137,7 @@
description="Run New Maven Goal..." icon="/krasa/mavenhelper/icons/runMaven.png">
<add-to-group group-id="RunMenu" anchor="first"/>
</action>
</actions>
</actions>



Expand Down
26 changes: 24 additions & 2 deletions src/krasa/mavenhelper/analyzer/GuiForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
Expand All @@ -42,7 +42,7 @@
</component>
<splitpane id="6c003" binding="splitPane">
<constraints>
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="400" height="400"/>
</grid>
</constraints>
Expand Down Expand Up @@ -224,6 +224,28 @@
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="a7c42" class="javax.swing.JEditorPane" binding="intellijBugLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<contentType value="text/html"/>
<editable value="false"/>
<foreground color="-65516"/>
<text value="&lt;html&gt;&#10; &lt;head&gt;&#10; &#10; &lt;/head&gt;&#10; &lt;body&gt;&#10; BUG&#10; &lt;/body&gt;&#10;&lt;/html&gt;&#10;"/>
</properties>
</component>
<component id="38953" class="javax.swing.JEditorPane" binding="falsePositive">
<constraints>
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<contentType value="text/html"/>
<editable value="false"/>
<foreground color="-65516"/>
<text value="&lt;html&gt;&#10; &lt;head&gt;&#10; &#10; &lt;/head&gt;&#10; &lt;body&gt;&#10; FALSE POSITIVE&#10; &lt;/body&gt;&#10;&lt;/html&gt;&#10;"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
61 changes: 53 additions & 8 deletions src/krasa/mavenhelper/analyzer/GuiForm.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package krasa.mavenhelper.analyzer;

import com.intellij.icons.AllIcons;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.CommonActionsManager;
import com.intellij.ide.DefaultTreeExpander;
import com.intellij.ide.util.PropertiesComponent;
Expand Down Expand Up @@ -97,6 +98,8 @@ public int compare(MavenArtifactNode o1, MavenArtifactNode o2) {
private JPanel buttonsPanel;
private JButton donate;
private JButton reimport;
protected JEditorPane intellijBugLabel;
protected JEditorPane falsePositive;
protected DefaultListModel listDataModel;
protected Map<String, List<MavenArtifactNode>> allArtifactsMap;
protected final DefaultTreeModel rightTreeModel;
Expand Down Expand Up @@ -125,6 +128,42 @@ public GuiForm(final Project project, VirtualFile file, final MavenProject maven
mavenProjectsManager = MavenProjectsManager.getInstance(project);
myProjectService = MyProjectService.getInstance(project);
this.mavenProject = mavenProject;

intellijBugLabel.setText("<html>\n" +
" <head>\n" +
"\n" +
" </head>\n" +
" <body>\n" +
" 1) An artifact is in conflict, its version is probably wrongly resolved due to a <a href=\"https://github.com/krasa/MavenHelper/issues/40\">bug in IntelliJ</a>." +
" </body>\n" +
"</html>\n");
intellijBugLabel.setBackground(rootPanel.getBackground());
intellijBugLabel.setForeground(SimpleTextAttributes.ERROR_ATTRIBUTES.getFgColor());
intellijBugLabel.setVisible(false);
intellijBugLabel.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
BrowserUtil.browse(e.getURL());
}
});


falsePositive.setText("<html>\n" +
" <head>\n" +
"\n" +
" </head>\n" +
" <body>\n" +
" 2) Probably a false positive, this should not happen, please report it at <a href=\"https://github.com/krasa/MavenHelper/issues/\">GitHub</a>." +
" </body>\n" +
"</html>\n");
falsePositive.setBackground(rootPanel.getBackground());
falsePositive.setForeground(SimpleTextAttributes.ERROR_ATTRIBUTES.getFgColor());
falsePositive.setVisible(false);
falsePositive.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
BrowserUtil.browse(e.getURL());
}
});

final ActionListener radioButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -193,6 +232,8 @@ public void actionPerformed(ActionEvent e) {
}
});
noConflictsWarningLabel.setText(WARNING);
noConflictsWarningLabel.setForeground(SimpleTextAttributes.ERROR_ATTRIBUTES.getFgColor());

leftPanelLayout = (CardLayout) leftPanelWrapper.getLayout();

rightTreeRoot = new DefaultMutableTreeNode();
Expand All @@ -201,7 +242,7 @@ public void actionPerformed(ActionEvent e) {
rightTree.setRootVisible(false);
rightTree.setShowsRootHandles(true);
rightTree.expandPath(new TreePath(rightTreeRoot.getPath()));
rightTree.setCellRenderer(new TreeRenderer(showGroupId));
rightTree.setCellRenderer(new TreeRenderer(showGroupId, this));
rightTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
rightTreePopupHandler = new RightTreePopupHandler(project, mavenProject, rightTree);
rightTree.addMouseListener(rightTreePopupHandler);
Expand All @@ -214,7 +255,7 @@ public void actionPerformed(ActionEvent e) {
leftTree.setRootVisible(false);
leftTree.setShowsRootHandles(true);
leftTree.expandPath(new TreePath(leftTreeRoot.getPath()));
leftTree.setCellRenderer(new TreeRenderer(showGroupId));
leftTree.setCellRenderer(new TreeRenderer(showGroupId, this));
leftTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
leftTreePopupHandler = new LeftTreePopupHandler(project, mavenProject, leftTree);
leftTree.addMouseListener(leftTreePopupHandler);
Expand Down Expand Up @@ -335,7 +376,7 @@ public void valueChanged(TreeSelectionEvent e) {
final String key = getArtifactKey(userObject.getArtifact());
List<MavenArtifactNode> mavenArtifactNodes = allArtifactsMap.get(key);
if (mavenArtifactNodes != null) {// can be null while refreshing
fillRightTree(mavenArtifactNodes, sortByVersion(mavenArtifactNodes));
fillRightTree(mavenArtifactNodes);
}
}
}
Expand All @@ -350,14 +391,14 @@ public void valueChanged(ListSelectionEvent e) {

final MyListNode myListNode = (MyListNode) leftPanelList.getSelectedValue();
List<MavenArtifactNode> artifacts = myListNode.value;
fillRightTree(artifacts, myListNode.getRightVersion());
fillRightTree(artifacts);
}
}

private void fillRightTree(List<MavenArtifactNode> mavenArtifactNodes, String rightVersion) {
private void fillRightTree(List<MavenArtifactNode> mavenArtifactNodes) {
rightTreeRoot.removeAllChildren();
for (MavenArtifactNode mavenArtifactNode : mavenArtifactNodes) {
MyTreeUserObject userObject = MyTreeUserObject.create(mavenArtifactNode, rightVersion);
MyTreeUserObject userObject = new MyTreeUserObject(mavenArtifactNode);
userObject.showOnlyVersion = true;
final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObject);
fillRightTree(mavenArtifactNode, newNode);
Expand All @@ -379,6 +420,8 @@ private void fillRightTree(MavenArtifactNode mavenArtifactNode, DefaultMutableTr
}

private void initializeModel() {
intellijBugLabel.setVisible(false);
falsePositive.setVisible(false);
rightTreePopupHandler.hidePopup();
leftTreePopupHandler.hidePopup();

Expand All @@ -398,6 +441,8 @@ private void initializeModel() {
}

private void updateLeftPanel() {
intellijBugLabel.setVisible(false);
falsePositive.setVisible(false);
listDataModel.clear();
leftTreeRoot.removeAllChildren();

Expand Down Expand Up @@ -458,7 +503,7 @@ public void run() {
}

leftPanelLayout.show(leftPanelWrapper, "list");
} else if (allDependenciesAsListRadioButton.isSelected()) {
} else if (allDependenciesAsListRadioButton.isSelected()) { //list
for (Map.Entry<String, List<MavenArtifactNode>> s : allArtifactsMap.entrySet()) {
if (contains(searchFieldText, s.getKey())) {
listDataModel.addElement(new MyListNode(s));
Expand Down Expand Up @@ -496,7 +541,7 @@ private boolean fillLeftTree(DefaultMutableTreeNode parent, List<MavenArtifactNo

for (MavenArtifactNode mavenArtifactNode : dependencyTree) {
boolean directMatch = false;
MyTreeUserObject treeUserObject = new MyTreeUserObject(mavenArtifactNode, SimpleTextAttributes.REGULAR_ATTRIBUTES);
MyTreeUserObject treeUserObject = new MyTreeUserObject(mavenArtifactNode);
if (search && contains(searchFieldText, mavenArtifactNode)) {
directMatch = true;
treeUserObject.highlight = true;
Expand Down
17 changes: 3 additions & 14 deletions src/krasa/mavenhelper/analyzer/MyListNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ public class MyListNode {

protected final String key;
protected final List<MavenArtifactNode> value;
protected String maxVersion;
protected String rightVersion;
protected boolean conflict;

public MyListNode(Map.Entry<String, List<MavenArtifactNode>> s) {
key = s.getKey();
value = s.getValue();
maxVersion = GuiForm.sortByVersion(value);
initRightVersion();
initConflict();
}
Expand All @@ -37,16 +35,11 @@ private void initRightVersion() {
}

private void initConflict() {
String lastVersion = null;
if (value != null && !value.isEmpty()) {
for (MavenArtifactNode mavenArtifactNode : value) {
if (mavenArtifactNode.getState() != MavenArtifactState.EXCLUDED) {
String version = mavenArtifactNode.getArtifact().getVersion();
if (lastVersion != null && !lastVersion.equals(version)) {
conflict = true;
break;
}
lastVersion = version;
if (Utils.isOmitted(mavenArtifactNode) || Utils.isConflictAlternativeMethod(mavenArtifactNode)) {
conflict = true;
break;
}
}
}
Expand All @@ -56,10 +49,6 @@ public boolean isConflict() {
return conflict;
}

public String getMaxVersion() {
return maxVersion;
}

public String getRightVersion() {
return rightVersion;
}
Expand Down
56 changes: 19 additions & 37 deletions src/krasa/mavenhelper/analyzer/MyTreeUserObject.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,38 @@
package krasa.mavenhelper.analyzer;

import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.model.MavenArtifact;
import org.jetbrains.idea.maven.model.MavenArtifactNode;
import org.jetbrains.idea.maven.model.MavenArtifactState;

/**
* @author Vojtech Krasa
*/
public class MyTreeUserObject {

private MavenArtifactNode mavenArtifactNode;
protected SimpleTextAttributes attributes;
private MavenArtifactNode mavenArtifactNode;

boolean showOnlyVersion = false;
boolean highlight;
boolean showOnlyVersion = false;
boolean highlight;

public MyTreeUserObject(MavenArtifactNode mavenArtifactNode) {
this.mavenArtifactNode = mavenArtifactNode;
this.attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
public MyTreeUserObject(MavenArtifactNode mavenArtifactNode) {
this.mavenArtifactNode = mavenArtifactNode;
}

public MyTreeUserObject(MavenArtifactNode mavenArtifactNode, final SimpleTextAttributes regularAttributes) {
this.mavenArtifactNode = mavenArtifactNode;
this.attributes = regularAttributes;
}

static MyTreeUserObject create(MavenArtifactNode mavenArtifactNode, @NotNull String rightVersion) {
SimpleTextAttributes attributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
if (mavenArtifactNode.getState() == MavenArtifactState.ADDED
|| (mavenArtifactNode.getRelatedArtifact() != null
&& mavenArtifactNode.getRelatedArtifact().getVersion().equals(mavenArtifactNode.getArtifact().getVersion()))) {
attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
return new MyTreeUserObject(mavenArtifactNode, attributes);
}

public MavenArtifact getArtifact() {
return mavenArtifactNode.getArtifact();
}
return mavenArtifactNode.getArtifact();
}

public MavenArtifactNode getMavenArtifactNode() {
return mavenArtifactNode;
}

public MavenArtifactNode getMavenArtifactNode() {
return mavenArtifactNode;
}
public boolean isHighlight() {
return highlight;
}

public boolean isHighlight() {
return highlight;
}
@Override
public String toString() {
return mavenArtifactNode.getArtifact().getArtifactId();
}

@Override
public String toString() {
return mavenArtifactNode.getArtifact().getArtifactId();
}
}
Loading

0 comments on commit c911005

Please sign in to comment.