Skip to content

Commit

Permalink
Add plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrandhof committed Sep 29, 2011
1 parent 84f5e90 commit ad10a91
Show file tree
Hide file tree
Showing 21 changed files with 538 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/sonar-checkstyle-extension-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>sonar-checkstyle-extension-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sonar-plugin</packaging>
<name>Examples :: Checkstyle Extension Plugin</name>
<name>Sonar Examples :: Checkstyle Extension Plugin</name>

<dependencies>
<dependency>
Expand Down
99 changes: 99 additions & 0 deletions plugins/sonar-gwt-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.sonar.examples</groupId>
<artifactId>sonar-gwt-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.1-SNAPSHOT</version>
<name>Sonar Examples :: GWT Plugin</name>

<properties>
<sonar.buildVersion>2.10</sonar.buildVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.buildVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-gwt-api</artifactId>
<version>${sonar.buildVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-incubator</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonar.buildVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.1</version>
<extensions>true</extensions>
<configuration>
<pluginClass>com.mycompany.sonar.gwt.GwtPlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<configuration>
<modules>
<module>com.mycompany.sonar.gwt.viewer.SampleViewer</module>
<module>com.mycompany.sonar.gwt.page.SamplePage</module>
</modules>
<webappDirectory>${project.build.directory}/classes</webappDirectory>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mycompany.sonar.gwt;

import com.mycompany.sonar.gwt.page.SamplePage;
import com.mycompany.sonar.gwt.viewer.SampleViewer;
import org.sonar.api.SonarPlugin;

import java.util.Arrays;
import java.util.List;

public final class GwtPlugin extends SonarPlugin {

public List getExtensions() {
return Arrays.asList(SampleViewer.class, SamplePage.class);
}

public String toString() {
return getKey();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mycompany.sonar.gwt.page;

import org.sonar.api.web.GwtPage;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE)
@UserRole(UserRole.USER)
public class SamplePage extends GwtPage {

public String getGwtId() {
return "com.mycompany.sonar.gwt.page.SamplePage";
}

public String getTitle() {
return "Sample";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mycompany.sonar.gwt.page.client;

import com.google.gwt.core.client.GWT;

public interface I18nConstants extends com.google.gwt.i18n.client.Constants {

static I18nConstants INSTANCE = GWT.create(I18nConstants.class);

@DefaultStringValue("This is a sample")
String sample();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mycompany.sonar.gwt.page.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.gwt.ui.Page;
import org.sonar.wsclient.services.Resource;

public class SamplePagePanel extends Page {

@Override
protected Widget doOnResourceLoad(Resource resource) {
VerticalPanel panel = new VerticalPanel();
panel.add(new Label(resource.getName(true)));
panel.add(new Label(I18nConstants.INSTANCE.sample()));
return panel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mycompany.sonar.gwt.viewer;

import org.sonar.api.web.GwtPage;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE_TAB)
@UserRole(UserRole.USER)
public class SampleViewer extends GwtPage {
public String getTitle() {
return "Sample";
}

public String getGwtId() {
return "com.mycompany.sonar.gwt.viewer.SampleViewer";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.mycompany.sonar.gwt.viewer.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.gwt.ui.Page;
import org.sonar.wsclient.gwt.AbstractCallback;
import org.sonar.wsclient.gwt.Sonar;
import org.sonar.wsclient.services.Measure;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

public class SampleViewerPanel extends Page {

private Label label;

@Override
protected Widget doOnResourceLoad(Resource resource) {
label = new Label("Loading value");
loadMeasureFromServer(resource);
return label;
}

// Ajax call to web service
private void loadMeasureFromServer(Resource resource) {
ResourceQuery query = ResourceQuery.createForResource(resource, "random");
Sonar.getInstance().find(query, new AbstractCallback<Resource>() {
@Override
protected void doOnResponse(Resource result) {
Measure measure = result.getMeasure("random");
if (measure==null || measure.getValue()==null) {
label.setText("No random value");
} else {
label.setText("Random value inserted during analysis: " + measure.getValue());
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<module>

<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.gwt.http.HTTP"/>
<inherits name="org.sonar.Sonar"/>

<entry-point class='com.mycompany.sonar.gwt.page.client.SamplePagePanel'/>

<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr"/>

</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file must use UTF-8 encoding
sample=Ceci est un exemple
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>GWT Smaple</title>
<link href="http://localhost:9000/dev/stylesheets/yui-2.6.0.css" media="all" rel="Stylesheet" type="text/css" />
<link href="http://localhost:9000/dev/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />
<script src="http://localhost:9000/dev/javascripts/application.js" type="text/javascript"></script>
<script src="http://localhost:9000/dev/javascripts/prototype.js" type="text/javascript"></script>
<script src="http://localhost:9000/dev/javascripts/scriptaculous.js" type="text/javascript"></script>
</head>

<body>
<script type="text/javascript">
var config = {
"sonar_url": "http://localhost:9000/dev",
"resource_key" : "org.codehaus.sonar:sonar",
};
</script>

<div class="error" id="error" style="display:none"><span id="errormsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$('error').hide();return false;">hide</a>]</div>
<div class="warning" id="warning" style="display:none"><span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$('warning').hide();return false;">hide</a>]</div>
<div class="notice" id="info" style="display:none"><span id="infomsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$('info').hide();return false;">hide</a>]</div>

<div id="gwtpage">
</div>

<script type="text/javascript" language="javascript" src="org.sonar.plugins.gwtsample.page.GwtSamplePage.nocache.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<module>

<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.gwt.http.HTTP"/>
<inherits name="org.sonar.Sonar"/>

<entry-point class='com.mycompany.sonar.gwt.viewer.client.SampleViewerPanel'/>

</module>
2 changes: 1 addition & 1 deletion plugins/sonar-pmd-extension-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>sonar-pmd-extension-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.1-SNAPSHOT</version>
<name>Examples :: PMD Extension Plugin</name>
<name>Sonar Examples :: PMD Extension Plugin</name>

<dependencies>
<dependency>
Expand Down
55 changes: 55 additions & 0 deletions plugins/sonar-reference-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.sonar.examples</groupId>
<artifactId>sonar-reference-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.1-SNAPSHOT</version>
<name>Sonar Examples :: Reference Plugin</name>

<properties>
<sonar.buildVersion>2.10</sonar.buildVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.buildVersion}</version>
<scope>provided</scope>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonar.buildVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.1</version>
<extensions>true</extensions>
<configuration>
<pluginClass>com.mycompany.sonar.reference.SamplePlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mycompany.sonar.reference;

import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;

import java.util.Arrays;
import java.util.List;

public final class SampleMetrics implements Metrics {

public static final Metric MESSAGE = new Metric.Builder("message_key", "Message", Metric.ValueType.STRING)
.setDescription("This is a metric to store a well known message")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(false)
.setDomain(CoreMetrics.DOMAIN_GENERAL)
.create();

public static final Metric RANDOM = new Metric.Builder("random", "Random", Metric.ValueType.FLOAT)
.setDescription("Random value")
.setDirection(Metric.DIRECTION_BETTER)
.setQualitative(false)
.setDomain(CoreMetrics.DOMAIN_GENERAL)
.create();

// getMetrics() method is defined in the Metrics interface and is used by
// Sonar to retrieve the list of new Metric
public List<Metric> getMetrics() {
return Arrays.asList(MESSAGE, RANDOM);
}
}
Loading

0 comments on commit ad10a91

Please sign in to comment.