Skip to content

Commit

Permalink
Fixed gshakhn#33 "NPE during initial configuration"
Browse files Browse the repository at this point in the history
* prevented potential NPE
* added dialog box for sonar connection errors

Issues: gshakhn#33
  • Loading branch information
aheusingfeld committed Apr 21, 2013
1 parent a73c638 commit 1224654
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 43 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.min.version>1.6</jdk.min.version>

<ij.plugin>true</ij.plugin>

This comment has been minimized.

Copy link
@gshakhn

gshakhn Apr 24, 2013

What does this do? My google-fu is failing.

This comment has been minimized.

Copy link
@aheusingfeld

aheusingfeld Apr 24, 2013

Author Owner

See here http://plugins.jetbrains.com/plugin?pr=idea&pluginId=7127! I added it because IntelliJ always deleted the .iml file and re-created it with type=MAVEN_MODULE

<idea.version>12.0.4</idea.version>
<idea.build>123.169</idea.build>
<sonar.version>3.4.1</sonar.version>
<sonar.language>java</sonar.language>
</properties>

<dependencies>
Expand Down
35 changes: 35 additions & 0 deletions sonar-intellij-plugin.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="PLUGIN_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.intellij:openapi:12.0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.intellij:util:12.0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.intellij:extensions:12.0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.intellij:annotations:12.0.4" level="project" />
<orderEntry type="library" name="Maven: com.intellij:forms_rt:12.0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.4" level="project" />
<orderEntry type="library" name="Maven: org.swinglabs:swingx-core:1.6.2-2" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.sonar:sonar-ws-client:3.4.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.2.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.2.2" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.intellij:idea:12.0.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.intellij:trove4j:12.0.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.intellij:picocontainer:12.0.4" level="project" />
</component>
</module>

Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void setToolWindowModel(ToolWindowModel model) {

@Override
public Sonar getSonar() {
Sonar sonarConn = SonarUtils.getSonar(state.host, state.user, state.password, state.useProxy);
return sonarConn;
return SonarUtils.getSonar(state.host, state.user, state.password, state.useProxy);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
import java.awt.event.ActionListener;
import java.util.List;


This comment has been minimized.

Copy link
@gshakhn

gshakhn Apr 24, 2013

Did you mean to add so many blank lines?

This comment has been minimized.

Copy link
@aheusingfeld

aheusingfeld Apr 24, 2013

Author Owner

Thanks for pointing this out -> removed with second commit










public class SonarProjectConfiguration extends BaseConfigurable implements RefreshProjectListListener
{
private JLabel lblHost;
Expand Down Expand Up @@ -52,14 +62,6 @@ public SonarProjectConfiguration(Project project)
this.modules = ModuleManager.getInstance(this.project).getModules();
sonarProjectComponent = project.getComponent(SonarProjectComponent.class);

testButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{

}
});
testButton.addActionListener(new ActionListener()
{
@Override
Expand Down Expand Up @@ -129,43 +131,36 @@ private void startRefreshProjects()
lblRefreshingProjects.setBusy(true);
applyToAllModulesButton.setEnabled(false);
applyToNotConfiguredButton.setEnabled(false);
testButton.setEnabled(false);
txtHost.setEnabled(false);
txtUser.setEnabled(false);
txtPassword.setEnabled(false);
useProxyBox.setEnabled(false);

Sonar sonarConn = SonarUtils.getSonar(txtHost.getText(), txtUser.getText(), new String(txtPassword.getPassword()),
final Sonar sonarConn = SonarUtils.getSonar(txtHost.getText(), txtUser.getText(), new String(txtPassword.getPassword()),
useProxyBox.isSelected());
RefreshProjectListWorker refreshProjectListWorker = new RefreshProjectListWorker(sonarConn);
final RefreshProjectListWorker refreshProjectListWorker = new RefreshProjectListWorker(sonarConn);
refreshProjectListWorker.addListener(this);
refreshProjectListWorker.execute();
}

@Override
public void doneRefreshProjects(List<SonarProject> newProjectList)
public void doneRefreshProjects(final List<SonarProject> newProjectList)
{
if (newProjectList == null)
{
applyToAllModulesButton.setEnabled(false);
applyToNotConfiguredButton.setEnabled(false);
lblRefreshingProjects.setBusy(false);
txtHost.setEnabled(true);
txtUser.setEnabled(true);
txtPassword.setEnabled(true);
useProxyBox.setEnabled(true);
}
else
boolean modified = newProjectList != null;
applyToAllModulesButton.setEnabled(modified);
applyToNotConfiguredButton.setEnabled(modified);
if (modified)
{
projectList = newProjectList;
applyToAllModulesButton.setEnabled(true);
applyToNotConfiguredButton.setEnabled(true);
lblRefreshingProjects.setBusy(false);
txtHost.setEnabled(true);
txtUser.setEnabled(true);
txtPassword.setEnabled(true);
useProxyBox.setEnabled(true);
setModified(true);
}
txtHost.setEnabled(true);
txtUser.setEnabled(true);
txtPassword.setEnabled(true);
useProxyBox.setEnabled(true);
testButton.setEnabled(true);
lblRefreshingProjects.setBusy(false);
}

public void updateModules(final boolean emptyOnly)
Expand Down Expand Up @@ -229,11 +224,14 @@ public JComponent createComponent()
@Override
public void apply() throws ConfigurationException
{
sonarProjectComponent.getState().host = txtHost.getText();
sonarProjectComponent.getState().user = txtUser.getText();
sonarProjectComponent.getState().password = new String(txtPassword.getPassword());
sonarProjectComponent.getState().useProxy = useProxyBox.isSelected();
sonarProjectComponent.getState().configured = true;
if (sonarProjectComponent != null && sonarProjectComponent.getState() != null)
{
sonarProjectComponent.getState().host = txtHost.getText();
sonarProjectComponent.getState().user = txtUser.getText();
sonarProjectComponent.getState().password = new String(txtPassword.getPassword());
sonarProjectComponent.getState().useProxy = useProxyBox.isSelected();
sonarProjectComponent.getState().configured = true;
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.sonar.ide.intellij.worker;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.ui.Messages;
import org.sonar.ide.intellij.listener.RefreshProjectListListener;
import org.sonar.ide.intellij.model.SonarProject;
import org.sonar.wsclient.Sonar;
Expand All @@ -15,6 +17,7 @@

public class RefreshProjectListWorker extends SwingWorker<List<SonarProject>, Void> {

private static final Logger LOG = Logger.getInstance("#org.sonar.ide.intellij.worker.RefreshProjectListWorker");
private Sonar sonar;
private List<RefreshProjectListListener> listeners = new ArrayList<RefreshProjectListListener>();

Expand All @@ -28,21 +31,34 @@ public void addListener(RefreshProjectListListener listener) {

@Override
protected List<SonarProject> doInBackground() throws Exception {
ResourceQuery query = new ResourceQuery();
final ResourceQuery query = new ResourceQuery();
query.setQualifiers("TRK,BRC");
query.setDepth(1);
query.setTimeoutMilliseconds(15000);

List<Resource> resources;
try {
resources = this.sonar.findAll(query);
} catch (Exception e) {
} catch (final Exception e) {
LOG.warn("Error occurred querrying Sonar " + query.getUrl(), e);
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
Throwable rootCause = e;
while (rootCause.getCause() != null) {
rootCause = e.getCause();
}
Messages.showErrorDialog("Connection to Sonar could not be established! " + rootCause.getLocalizedMessage(), "Sonar Connection Failed");
}
});
return null;
}

List<SonarProject> projects = new ArrayList<SonarProject>();
final List<SonarProject> projects = new ArrayList<SonarProject>();

for (Resource resource : resources) {
SonarProject project = new SonarProject(resource);
final SonarProject project = new SonarProject(resource);
projects.add(project);
}

Expand All @@ -64,9 +80,9 @@ protected void done() {
listener.doneRefreshProjects(projects);
}
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Refreshing of project was interrupted!", e);
} catch (ExecutionException e) {
e.printStackTrace();
LOG.error("Refreshing of project could not be successfully executed!", e);
}
}
}

0 comments on commit 1224654

Please sign in to comment.