From f2895176536177193f8882ba51d3815729d160a9 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 23 Dec 2010 14:07:09 +0100 Subject: [PATCH] added a simple hello world plugin sample --- samples/pom.xml | 1 + samples/scm-sample-hello/pom.xml | 37 ++++++++ .../main/java/sample/hello/HelloResource.java | 90 +++++++++++++++++++ .../main/resources/META-INF/scm/plugin.xml | 63 +++++++++++++ .../resources/sample/hello/sample.hello.js | 67 ++++++++++++++ scm-webapp/pom.xml | 6 ++ 6 files changed, 264 insertions(+) create mode 100644 samples/scm-sample-hello/pom.xml create mode 100644 samples/scm-sample-hello/src/main/java/sample/hello/HelloResource.java create mode 100644 samples/scm-sample-hello/src/main/resources/META-INF/scm/plugin.xml create mode 100644 samples/scm-sample-hello/src/main/resources/sample/hello/sample.hello.js diff --git a/samples/pom.xml b/samples/pom.xml index e2366da882..00b485fafa 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -16,6 +16,7 @@ scm-samples + scm-sample-hello scm-sample-auth diff --git a/samples/scm-sample-hello/pom.xml b/samples/scm-sample-hello/pom.xml new file mode 100644 index 0000000000..a8399eb61d --- /dev/null +++ b/samples/scm-sample-hello/pom.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + + + scm-samples + sonia.scm.samples + 1.0-M5-SNAPSHOT + + + sonia.scm.sample + scm-sample-hello + 1.0-M5-SNAPSHOT + scm-sample-hello + A simple hello world plugin + https://bitbucket.org/sdorra/scm-manager + + + + + javax.servlet + servlet-api + ${servlet.version} + provided + + + + sonia.scm + scm-core + 1.0-M5-SNAPSHOT + + + + + diff --git a/samples/scm-sample-hello/src/main/java/sample/hello/HelloResource.java b/samples/scm-sample-hello/src/main/java/sample/hello/HelloResource.java new file mode 100644 index 0000000000..a83024f4bd --- /dev/null +++ b/samples/scm-sample-hello/src/main/java/sample/hello/HelloResource.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sample.hello; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.Inject; +import com.google.inject.Provider; + +import sonia.scm.security.SecurityContext; + +//~--- JDK imports ------------------------------------------------------------ + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * + * @author Sebastian Sdorra + */ +@Path("sample/hello") +public class HelloResource +{ + + /** + * Constructs ... + * + * + * @param securityContextProvider + */ + @Inject + public HelloResource(Provider securityContextProvider) + { + message = "Hello " + + securityContextProvider.get().getUser().getDisplayName(); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getHelloMessage() + { + return message; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private String message; +} diff --git a/samples/scm-sample-hello/src/main/resources/META-INF/scm/plugin.xml b/samples/scm-sample-hello/src/main/resources/META-INF/scm/plugin.xml new file mode 100644 index 0000000000..ccbf405403 --- /dev/null +++ b/samples/scm-sample-hello/src/main/resources/META-INF/scm/plugin.xml @@ -0,0 +1,63 @@ + + + + + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.name} + ${project.description} + Sebastian Sdorra + ${project.url} + + + + sample.hello + + + + + + + diff --git a/samples/scm-sample-hello/src/main/resources/sample/hello/sample.hello.js b/samples/scm-sample-hello/src/main/resources/sample/hello/sample.hello.js new file mode 100644 index 0000000000..4b34a6ca17 --- /dev/null +++ b/samples/scm-sample-hello/src/main/resources/sample/hello/sample.hello.js @@ -0,0 +1,67 @@ +/* * + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + +function sayHello(){ + Ext.Ajax.request({ + url: restUrl + 'sample/hello', + method: 'GET', + disableCaching: true, + success: function(response){ + var msg = response.responseText; + Ext.MessageBox.show({ + title: 'Hello Message', + msg: msg, + buttons: Ext.MessageBox.OK, + icon: Ext.MessageBox.INFO + }); + }, + failure: function(){ + Ext.MessageBox.show({ + title: 'Error', + msg: 'Could not display the hello message', + buttons: Ext.MessageBox.OK, + icon: Ext.MessageBox.ERROR + }); + } + }); +} + +loginCallbacks.push(function(){ + var navPanel = Ext.getCmp('navigationPanel'); + var count = navPanel.count() - 1; + navPanel.insertSection(count, { + title: 'Hello World', + items: [{ + label: 'Say Hello', + fn: sayHello + }] + }); +}); \ No newline at end of file diff --git a/scm-webapp/pom.xml b/scm-webapp/pom.xml index 516b05986c..9cc63955e5 100644 --- a/scm-webapp/pom.xml +++ b/scm-webapp/pom.xml @@ -247,6 +247,12 @@ scm-sample-auth 1.0-M5-SNAPSHOT + + + sonia.scm.sample + scm-sample-hello + 1.0-M5-SNAPSHOT + sonia.scm.plugins