Permalink
Browse files

Merge pull request #3 from jsl/more_project_overrides

Allow build-level overrides for Campfire subdomain and token
  • Loading branch information...
2 parents a429d5f + b415472 commit c8443530a0382aa44cf11443465c0fe843b53549 @mmrwoods mmrwoods committed Apr 26, 2012
View
@@ -24,6 +24,7 @@ Other features have since been added including...
* Play sounds on build success and failure, added by Henry Poydar.
* Build notifications now include commit info.
* Room to which notifications are sent can be customised per-project.
+* Subdomain and API token can be customized per-project.
Note: The plugin code is a bit of a mess, partly just because I don't have a
lot of Java experience, but also because I simply haven't got the time to tidy
@@ -51,6 +51,14 @@ protected String getHost() {
return this.subdomain + ".campfirenow.com";
}
+ public String getSubdomain() {
+ return this.subdomain;
+ }
+
+ public String getToken() {
+ return this.token;
+ }
+
protected String getProtocol() {
if (this.ssl) { return "https://"; }
return "http://";
@@ -19,14 +19,14 @@
public class CampfireNotifier extends Notifier {
- private transient Campfire campfire;
+ private Campfire campfire;
private Room room;
private String hudsonUrl;
private boolean smartNotify;
private boolean sound;
- // getter for project configuration..
- // Configured room name should be null unless different from descriptor/global room name
+ // getters for project configuration..
+ // Configured room name / subdomain / token should be null unless different from descriptor/global values
public String getConfiguredRoomName() {
if ( DESCRIPTOR.getRoom().equals(room.getName()) ) {
return null;
@@ -35,6 +35,22 @@ public String getConfiguredRoomName() {
}
}
+ public String getConfiguredSubdomain() {
+ if ( DESCRIPTOR.getSubdomain().equals(campfire.getSubdomain()) ) {
+ return null;
+ } else {
+ return campfire.getSubdomain();
+ }
+ }
+
+ public String getConfiguredToken() {
+ if ( DESCRIPTOR.getToken().equals(campfire.getToken()) ) {
+ return null;
+ } else {
+ return campfire.getToken();
+ }
+ }
+
@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
@@ -48,7 +48,7 @@ public String getHudsonUrl() {
public boolean getSsl() {
return ssl;
}
-
+
public boolean getSmartNotify() {
return smartNotify;
}
@@ -66,12 +66,20 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
*/
@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
- String projectRoom = req.getParameter("roomName");
+ String projectSubdomain = req.getParameter("campfireSubdomain");
+ String projectToken = req.getParameter("campfireToken");
+ String projectRoom = req.getParameter("campfireRoom");
if ( projectRoom == null || projectRoom.trim().length() == 0 ) {
projectRoom = room;
}
+ if ( projectToken == null || projectToken.trim().length() == 0 ) {
+ projectToken = token;
+ }
+ if ( projectSubdomain == null || projectSubdomain.trim().length() == 0 ) {
+ projectSubdomain = subdomain;
+ }
try {
- return new CampfireNotifier(subdomain, token, projectRoom, hudsonUrl, ssl, smartNotify, sound);
+ return new CampfireNotifier(projectSubdomain, projectToken, projectRoom, hudsonUrl, ssl, smartNotify, sound);
} catch (Exception e) {
String message = "Failed to initialize campfire notifier - check your campfire notifier configuration settings: " + e.getMessage();
LOGGER.log(Level.WARNING, message, e);
@@ -6,7 +6,7 @@
import java.util.Date;
public class Room {
- private transient Campfire campfire;
+ private Campfire campfire;
private String name;
private String id;
@@ -3,7 +3,13 @@
This jelly script is used for per-project configuration.
See global.jelly for a general discussion about jelly script.
-->
+ <f:entry title="Project Subdomain" description="Optional. Use to send notifications to a subdomain other than the default (${descriptor.getSubdomain()})" help="${rootURL}/plugin/campfire/help-projectConfig-subdomain.html">
+ <f:textbox name="campfireSubdomain" value="${instance.getConfiguredSubdomain()}"/>
+ </f:entry>
+ <f:entry title="Project API Token" description="Optional. Use to send notifications to an API token other than the default (${descriptor.getToken()})" help="${rootURL}/plugin/campfire/help-projectConfig-token.html">
+ <f:textbox name="campfireToken" value="${instance.getConfiguredToken()}"/>
+ </f:entry>
<f:entry title="Project Room Name" description="Optional. Use to send notifications to a room other than the default (${descriptor.getRoom()})" help="${rootURL}/plugin/campfire/help-projectConfig-room.html">
- <f:textbox name="roomName" value="${instance.getConfiguredRoomName()}"/>
+ <f:textbox name="campfireRoom" value="${instance.getConfiguredRoomName()}"/>
</f:entry>
</j:jelly>
@@ -12,10 +12,10 @@
so it should be straightforward to find them.
-->
<f:section title="Global Campfire Notifier Settings">
- <f:entry title="Subdomain" help="${rootURL}/plugin/campfire/help-globalConfig-subdomain.html">
+ <f:entry title="Default Subdomain" help="${rootURL}/plugin/campfire/help-globalConfig-subdomain.html">
<f:textbox name="campfireSubdomain" value="${descriptor.getSubdomain()}" />
</f:entry>
- <f:entry title="API Token" help="${rootURL}/plugin/campfire/help-globalConfig-token.html">
+ <f:entry title="Default API Token" help="${rootURL}/plugin/campfire/help-globalConfig-token.html">
<f:textbox name="campfireToken" value="${descriptor.getToken()}" />
</f:entry>
<f:entry title="Default Room Name" help="${rootURL}/plugin/campfire/help-globalConfig-room.html">
@@ -0,0 +1,3 @@
+<div>
+ <p>The subdomain for your Campfire account , if different from the default subdomain configuration in the global campfire notifier settings.
+</div>
@@ -0,0 +1,3 @@
+<div>
+ <p>The API authentication token that should be used to send notifications for this project, if different from the default token configuration in the global campfire notifier settings.</p>
+</div>

0 comments on commit c844353

Please sign in to comment.