]> source.dussan.org Git - sonarqube.git/commitdiff
Improve plugin samples
authorsimonbrandhof <simon.brandhof@gmail.com>
Wed, 4 May 2011 15:52:38 +0000 (17:52 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Wed, 4 May 2011 15:52:55 +0000 (17:52 +0200)
20 files changed:
samples/assembly.xml [new file with mode: 0644]
samples/gwt-plugin/pom.xml [new file with mode: 0644]
samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/GwtPlugin.java [new file with mode: 0644]
samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/SamplePage.java [new file with mode: 0644]
samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/client/I18nConstants.java [new file with mode: 0644]
samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/client/SamplePagePanel.java [new file with mode: 0644]
samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/viewer/SampleViewer.java [new file with mode: 0644]
samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/viewer/client/SampleViewerPanel.java [new file with mode: 0644]
samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/SamplePage.gwt.xml [new file with mode: 0644]
samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/client/I18nConstants_fr.properties [new file with mode: 0644]
samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/public/test.html [new file with mode: 0644]
samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/viewer/SampleViewer.gwt.xml [new file with mode: 0644]
samples/pom.xml [new file with mode: 0644]
samples/standard-plugin/pom.xml [new file with mode: 0644]
samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleFooter.java [new file with mode: 0644]
samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleMetrics.java [new file with mode: 0644]
samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SamplePlugin.java [new file with mode: 0644]
samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleRubyWidget.java [new file with mode: 0644]
samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleSensor.java [new file with mode: 0644]
samples/standard-plugin/src/main/resources/sample_ruby_widget.html.erb [new file with mode: 0644]

diff --git a/samples/assembly.xml b/samples/assembly.xml
new file mode 100644 (file)
index 0000000..014a7dc
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+  <id>distribution</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <includeBaseDirectory>true</includeBaseDirectory>
+
+  <fileSets>
+    <fileSet>
+      <directory>standard-plugin</directory>
+      <outputDirectory>standard-plugin</outputDirectory>
+      <includes>
+        <include>src/**/*</include>
+        <include>pom.xml</include>
+      </includes>
+    </fileSet>
+    <fileSet>
+      <directory>gwt-plugin</directory>
+      <outputDirectory>gwt-plugin</outputDirectory>
+      <includes>
+        <include>src/**/*</include>
+        <include>pom.xml</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+</assembly>
diff --git a/samples/gwt-plugin/pom.xml b/samples/gwt-plugin/pom.xml
new file mode 100644 (file)
index 0000000..975327b
--- /dev/null
@@ -0,0 +1,102 @@
+<?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>com.mycompany.sonar</groupId>
+  <artifactId>sonar-gwt-plugin</artifactId>
+  <packaging>sonar-plugin</packaging>
+  <version>2.8-SNAPSHOT</version>
+  <name>Sonar :: Samples :: GWT plugin</name>
+  <description>Description of plugin with GWT extensions</description>
+
+  <properties>
+    <!-- To be replaced with the minimum required version of Sonar -->
+    <sonar.buildVersion>${project.version}</sonar.buildVersion>
+  </properties>
+
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.sonar</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+      <version>${sonar.buildVersion}</version>
+    </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.0</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>
diff --git a/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/GwtPlugin.java b/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/GwtPlugin.java
new file mode 100644 (file)
index 0000000..40d78ca
--- /dev/null
@@ -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();
+  }
+}
\ No newline at end of file
diff --git a/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/SamplePage.java b/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/SamplePage.java
new file mode 100644 (file)
index 0000000..dc2dd74
--- /dev/null
@@ -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";
+  }
+}
diff --git a/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/client/I18nConstants.java b/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/client/I18nConstants.java
new file mode 100644 (file)
index 0000000..4dde01e
--- /dev/null
@@ -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();
+}
diff --git a/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/client/SamplePagePanel.java b/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/page/client/SamplePagePanel.java
new file mode 100644 (file)
index 0000000..c0d16ed
--- /dev/null
@@ -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;
+  }
+}
diff --git a/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/viewer/SampleViewer.java b/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/viewer/SampleViewer.java
new file mode 100644 (file)
index 0000000..53ca2a4
--- /dev/null
@@ -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";
+  }
+}
\ No newline at end of file
diff --git a/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/viewer/client/SampleViewerPanel.java b/samples/gwt-plugin/src/main/java/com/mycompany/sonar/gwt/viewer/client/SampleViewerPanel.java
new file mode 100644 (file)
index 0000000..a1188d0
--- /dev/null
@@ -0,0 +1,14 @@
+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.services.Resource;
+
+public class SampleViewerPanel extends Page {
+
+  @Override
+  protected Widget doOnResourceLoad(Resource resource) {
+    return new Label("This is a sample");
+  }
+}
\ No newline at end of file
diff --git a/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/SamplePage.gwt.xml b/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/SamplePage.gwt.xml
new file mode 100644 (file)
index 0000000..8f95c2e
--- /dev/null
@@ -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>
diff --git a/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/client/I18nConstants_fr.properties b/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/client/I18nConstants_fr.properties
new file mode 100644 (file)
index 0000000..aa92d17
--- /dev/null
@@ -0,0 +1,2 @@
+# This file must use UTF-8 encoding
+sample=Ceci est un exemple
\ No newline at end of file
diff --git a/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/public/test.html b/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/page/public/test.html
new file mode 100644 (file)
index 0000000..04371e3
--- /dev/null
@@ -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>
\ No newline at end of file
diff --git a/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/viewer/SampleViewer.gwt.xml b/samples/gwt-plugin/src/main/resources/com/mycompany/sonar/gwt/viewer/SampleViewer.gwt.xml
new file mode 100644 (file)
index 0000000..af900e8
--- /dev/null
@@ -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>
diff --git a/samples/pom.xml b/samples/pom.xml
new file mode 100644 (file)
index 0000000..34f0baa
--- /dev/null
@@ -0,0 +1,59 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.codehaus.sonar</groupId>
+    <artifactId>sonar</artifactId>
+    <version>2.8-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
+  <groupId>org.codehaus.sonar.samples</groupId>
+  <artifactId>sonar-samples</artifactId>
+  <packaging>pom</packaging>
+  <name>Sonar :: Samples</name>
+
+  <modules>
+    <module>standard-plugin</module>
+    <module>gwt-plugin</module>
+  </modules>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+            <configuration>
+              <appendAssemblyId>false</appendAssemblyId>
+              <finalName>sonar-samples-${project.version}</finalName>
+              <descriptors>
+                <descriptor>assembly.xml</descriptor>
+              </descriptors>
+              <archiverConfig>
+                <!-- Workaround for http://jira.codehaus.org/browse/MASSEMBLY-422 -->
+                <!-- 420(dec) = 644(oct) -->
+                <fileMode>420</fileMode>
+                <!-- 493(dec) = 755(oct) -->
+                <directoryMode>493</directoryMode>
+                <defaultDirectoryMode>493</defaultDirectoryMode>
+              </archiverConfig>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+    </plugins>
+  </build>
+</project>
\ No newline at end of file
diff --git a/samples/standard-plugin/pom.xml b/samples/standard-plugin/pom.xml
new file mode 100644 (file)
index 0000000..a075f68
--- /dev/null
@@ -0,0 +1,57 @@
+<?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>com.mycompany.sonar</groupId>
+  <artifactId>sonar-standard-plugin</artifactId>
+  <packaging>sonar-plugin</packaging>
+  <version>2.8-SNAPSHOT</version>
+  <name>Sonar :: Samples :: Standard plugin</name>
+  <description>Description of standard plugin</description>
+
+  <properties>
+    <!-- To be replaced with the minimum required version of Sonar -->
+    <sonar.buildVersion>${project.version}</sonar.buildVersion>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.sonar</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+      <version>${sonar.buildVersion}</version>
+    </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.0</version>
+        <extensions>true</extensions>
+        <configuration>
+          <pluginClass>com.mycompany.sonar.standard.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>
diff --git a/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleFooter.java b/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleFooter.java
new file mode 100644 (file)
index 0000000..ab72e40
--- /dev/null
@@ -0,0 +1,9 @@
+package com.mycompany.sonar.standard;
+
+import org.sonar.api.web.Footer;
+
+public final class SampleFooter implements Footer {
+  public String getHtml() {
+    return "<p>Sample footer - <em>This is static HTML</em></p>";
+  }
+}
diff --git a/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleMetrics.java b/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleMetrics.java
new file mode 100644 (file)
index 0000000..6d493bc
--- /dev/null
@@ -0,0 +1,31 @@
+package com.mycompany.sonar.standard;
+
+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);
+  }
+}
diff --git a/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SamplePlugin.java b/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SamplePlugin.java
new file mode 100644 (file)
index 0000000..e6ca0cc
--- /dev/null
@@ -0,0 +1,21 @@
+package com.mycompany.sonar.standard;
+
+import org.sonar.api.SonarPlugin;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This class is the entry point for all extensions
+ */
+public final class SamplePlugin extends SonarPlugin {
+
+  // This is where you're going to declare all your Sonar extensions
+  public List getExtensions() {
+    return Arrays.asList(
+        SampleMetrics.class, SampleSensor.class, SampleRubyWidget.class,
+
+        // UI
+        SampleFooter.class);
+  }
+}
\ No newline at end of file
diff --git a/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleRubyWidget.java b/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleRubyWidget.java
new file mode 100644 (file)
index 0000000..7a97194
--- /dev/null
@@ -0,0 +1,38 @@
+package com.mycompany.sonar.standard;
+
+import org.sonar.api.web.*;
+
+@UserRole(UserRole.USER)
+@Description("Show how to use Ruby Widget API")
+@WidgetProperties({
+  @WidgetProperty(key="param1",
+    description="This is a mandatory parameter",
+    optional=false
+  ),
+  @WidgetProperty(key="max",
+    description="max threshold",
+    type=WidgetPropertyType.INTEGER,
+    defaultValue="80"
+  ),
+  @WidgetProperty(key="param2",
+    description="This is an optional parameter"
+  ),
+  @WidgetProperty(key="floatprop",
+    description="test description"
+  )
+})
+public class SampleRubyWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+
+  public String getId() {
+    return "sample";
+  }
+
+  public String getTitle() {
+    return "Sample";
+  }
+
+  @Override
+  protected String getTemplatePath() {
+    return "/sample_ruby_widget.html.erb";
+  }
+}
\ No newline at end of file
diff --git a/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleSensor.java b/samples/standard-plugin/src/main/java/com/mycompany/sonar/standard/SampleSensor.java
new file mode 100644 (file)
index 0000000..f37749e
--- /dev/null
@@ -0,0 +1,30 @@
+package com.mycompany.sonar.standard;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.resources.Project;
+
+public class SampleSensor implements Sensor {
+
+  public boolean shouldExecuteOnProject(Project project) {
+    // this sensor is executed on any type of project
+    return true;
+  }
+
+  public void analyse(Project project, SensorContext sensorContext) {
+    saveLabelMeasure(sensorContext);
+    saveNumericMeasure(sensorContext);
+  }
+
+  private void saveNumericMeasure(SensorContext context) {
+    // Sonar API includes many libraries like commons-lang and google-collections
+    context.saveMeasure(SampleMetrics.RANDOM, RandomUtils.nextDouble());
+  }
+
+  private void saveLabelMeasure(SensorContext context) {
+    Measure measure = new Measure(SampleMetrics.MESSAGE, "Hello World!");
+    context.saveMeasure(measure);
+  }
+}
diff --git a/samples/standard-plugin/src/main/resources/sample_ruby_widget.html.erb b/samples/standard-plugin/src/main/resources/sample_ruby_widget.html.erb
new file mode 100644 (file)
index 0000000..c2602c4
--- /dev/null
@@ -0,0 +1,40 @@
+<div class="dashbox">
+  <h3><span title="<%= metric('random').description -%>"></span></h3>
+  <p>
+    <span class="big">
+      <%= format_measure('random') -%> <%= trend_icon(measure('random')) %>
+    </span>
+  </p>
+  <p><%= format_measure('message') -%></p>
+  <p>
+    <%= format_measure('ncloc', :suffix => ' lines', :url => url_for_drilldown('ncloc')) -%>
+  </p>
+</div>
+<div class="dashbox">
+       <h3>Help</h3>
+         <p>
+      Read configuration : <%= configuration('sonar.jdbc.username') -%>
+    </p>
+
+       <p>
+           Sample of Jfree Eastwood chart : <br/>
+               <%= gchart('cht=bhs&chco=FF0000,00FF00,0000FF&chs=200x125&chd=s:FOE,THE,Bar&chxt=x,y&chxl=1:|Dec|Nov|Oct|0:||20K||60K||100K|') -%>
+         </p>
+       <p>
+               Widget properties:
+               <table>
+                 <tr>
+                   <td>max:</td>
+                   <td><%= widget_properties['max'] -%></td>   
+                 </tr> 
+               <tr>
+                   <td>param1:</td>
+                   <td><%= widget_properties['param1'] -%></td>        
+                 </tr>
+               <tr>
+                   <td>param2:</td>
+                   <td><%= widget_properties['param2'] -%></td>        
+                 </tr>
+               </table>
+       </p>
+</div>