Skip to content

Commit

Permalink
First pass at per-project room configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
thickpaddy committed Feb 1, 2011
1 parent 706dacd commit 426afe9
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.*~
*.swp
.project
target
6 changes: 5 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ When the build has completed, you'll have a .hpi file available which needs to b

rm -rf /var/lib/hudson/plugins/campfire*

Then use the advanced tab of the plugin manager to upload the hpi file. Finally, restart hudson (note: not reload configuration, restart the hudson daemon).
Then either use the advanced tab of the plugin manager to upload the hpi file or just copy it to the plugins directory, e.g.

cp campfire.hpi /var/lib/hudson/plugins/

Finally, restart hudson (note: not reload configuration, restart the hudson daemon).

### Troubleshooting

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/hudson/plugins/campfire/CampfireNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ public class CampfireNotifier extends Notifier {
private String hudsonUrl;
private boolean smartNotify;

/**
* Descriptor should be singleton. (Won't this just set a class constant to an instance (but not the only possible instance) of DescriptorImpl?)
*/
// getter for project configuration..
// Configured room name should be null unless different from descriptor/global room name
public String getConfiguredRoomName() {
if ( DESCRIPTOR.getRoom().equals(room.getName()) ) {
return null;
} else {
return room.getName();
}
}

@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

Expand Down Expand Up @@ -119,12 +126,12 @@ private void initialize() throws IOException {
initialize(DESCRIPTOR.getSubdomain(), DESCRIPTOR.getToken(), DESCRIPTOR.getRoom(), DESCRIPTOR.getHudsonUrl(), DESCRIPTOR.getSsl(), DESCRIPTOR.getSmartNotify());
}

private void initialize(String subdomain, String token, String room, String hudsonUrl, boolean ssl, boolean smartNotify) throws IOException {
private void initialize(String subdomain, String token, String roomName, String hudsonUrl, boolean ssl, boolean smartNotify) throws IOException {
campfire = new Campfire(subdomain, token, ssl);
try {
this.room = campfire.findRoomByName(room);
this.room = campfire.findRoomByName(roomName);
if ( this.room == null ) {
throw new IOException("Room '" + room + "' not found");
throw new IOException("Room '" + roomName + "' not found");
}
} catch (IOException e) {
throw new IOException("Cannot join room: " + e.getMessage());
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/campfire/DescriptorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
*/
@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
String projectRoom = req.getParameter("roomName");
if ( projectRoom == null || projectRoom.trim().length() == 0 ) {
projectRoom = room;
}
try {
return new CampfireNotifier(subdomain, token, room, hudsonUrl, ssl, smartNotify);
return new CampfireNotifier(subdomain, token, projectRoom, hudsonUrl, ssl, smartNotify);
} catch (Exception e) {
throw new FormException("Failed to initialize campfire notifier - check your global campfire notifier configuration settings", e, "");
throw new FormException("Failed to initialize campfire notifier - check your campfire notifier configuration settings", e, "");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
This jelly script is used for per-project configuration.
See global.jelly for a general discussion about jelly script.
-->
<!--<f:entry title="Hostname" description="Hostname of the Campfire server">-->
<!--http://<f:textbox name="subdomain" value="${descriptor.getSubdomain()}" />.campfirenow.com-->
<!--</f:entry>-->
<!--<f:entry title="Token" description="The authentication token of the bot">-->
<!--<f:password name="token" value="${descriptor.getToken()}" />-->
<!--</f:entry>-->
<!--<f:entry title="Room" description="Room the bot should join">-->
<!--<f:textbox name="room" value="${descriptor.getRoom()}" />-->
<!--</f:entry>-->
<!--<f:entry title="SSL" description="Use SSL?">-->
<!--<f:textbox name="ssl" value="${descriptor.getSsl()}" />-->
<!--</f:entry>-->
</j:jelly>
<f:entry title="Project Room (if different from ${descriptor.getRoom()})" help="${rootURL}/plugin/campfire/help-projectConfig-room.html">
<f:textbox name="roomName" value="${instance.getConfiguredRoomName()}"/>
</f:entry>
</j:jelly>
7 changes: 4 additions & 3 deletions src/main/webapp/help-globalConfig-room.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div>
<p>Enter the name of the room to which notifications should be sent. Note that this is the name of the
room, not the id number, e.g. "Dev Team".</p>
</div>
<p>Enter the name of the room to which notifications should be sent. Note that this is the name of the
room, not the id number, e.g. "Dev Team". You can customize the room name per-project, but should always
enter a default here.</p>
</div>
4 changes: 4 additions & 0 deletions src/main/webapp/help-projectConfig-room.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<p>Enter the name of the room to which notifications should be sent. Note that this is the name of the
room, not the id number, e.g. "Dev Team".</p>
</div>
6 changes: 3 additions & 3 deletions src/main/webapp/help.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
This causes Hudson to broadcast build failures and recoveries
on a Campfire chat server.
</div>
Send build notifications to a Campfire chat room.<br />
The campfire notifier is configured globally, but you can customize the room name per-project.
</div>

0 comments on commit 426afe9

Please sign in to comment.