Skip to content

Commit

Permalink
[FIXED JENKINS-10090] new option to specify IRC server encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzi committed Jun 26, 2011
1 parent 6a1869b commit 6efc31a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
42 changes: 32 additions & 10 deletions src/main/java/hudson/plugins/ircbot/IrcPublisher.java
Expand Up @@ -4,13 +4,8 @@
package hudson.plugins.ircbot;

import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixRun;
import hudson.matrix.MatrixBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.User;
import hudson.plugins.im.GroupChatIMMessageTarget;
import hudson.plugins.im.IMConnection;
Expand All @@ -29,10 +24,11 @@
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.SortedMap;
import java.util.logging.Logger;

import net.sf.json.JSONObject;
Expand All @@ -42,7 +38,7 @@
/**
* Publishes build results to IRC channels.
*
* @author bruyeron
* @author bruyeron (original author)
* @author $Author: kutzi $ (last change)
* @version $Id: IrcPublisher.java 39408 2011-05-01 10:52:54Z kutzi $
*/
Expand Down Expand Up @@ -130,7 +126,7 @@ protected Object readResolve() {
this.channels = null;

if (getNotificationStrategy() == null) {
// set to the fixed strategy in ircbot <= 1.7
// set to the only available strategy in ircbot <= 1.7
setNotificationStrategy(NotificationStrategy.STATECHANGE_ONLY);
}
return this;
Expand All @@ -143,6 +139,21 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>

public static final String PARAMETERNAME_USE_NOTICE = PREFIX + "useNotice";
public static final String PARAMETERNAME_NICKSERV_PASSWORD = PREFIX + "nickServPassword";

public static final String[] CHARSETS;

static {
SortedMap<String, Charset> availableCharsets = Charset.availableCharsets();
String[] cs = new String[availableCharsets.size()];
cs[0] = "UTF-8";
int i = 1;
for (String csName : availableCharsets.keySet()) {
if (!"UTF-8".equals(csName)) {
cs[i++] = csName;
}
}
CHARSETS = cs;
}

boolean enabled = false;

Expand Down Expand Up @@ -172,6 +183,8 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>
private String hudsonPassword;

private boolean useNotice;

private String charset;

DescriptorImpl() {
super(IrcPublisher.class);
Expand Down Expand Up @@ -240,6 +253,8 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc

this.useNotice = "on".equals(req.getParameter(PARAMETERNAME_USE_NOTICE));

this.charset = req.getParameter("charset");

// try to establish the connection
try {
IRCConnectionProvider.setDesc(this);
Expand Down Expand Up @@ -335,8 +350,7 @@ public Publisher newInstance(StaplerRequest req, JSONObject formData) throws For
}

@Override
@SuppressWarnings("unchecked")
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
public boolean isApplicable(@SuppressWarnings("rawtypes") Class<? extends AbstractProject> jobType) {
return true;
}

Expand Down Expand Up @@ -445,6 +459,10 @@ public boolean isUseNotice() {
return this.useNotice;
}

public String getCharset() {
return this.charset;
}

/**
* Deserialize old descriptors.
*/
Expand All @@ -461,6 +479,10 @@ private Object readResolve() {
}
}

if (this.charset == null) {
this.charset = "UTF-8";
}

return this;
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java
Expand Up @@ -75,9 +75,10 @@ public boolean connect() {
try {
this.pircConnection = new PircConnection(this.descriptor.getNick(), this.descriptor.isUseNotice());

// always use UTF-8; don't depend on the JVM's default encoding
this.pircConnection.setEncoding("UTF-8");

this.pircConnection.setEncoding(this.descriptor.getCharset());

LOGGER.info(String.format("Connecting to %s:%s as %s using charset %s",
this.descriptor.getHost(), this.descriptor.getPort(), this.descriptor.getNick(), this.descriptor.getCharset()));
this.pircConnection.connect(this.descriptor.getHost(), this.descriptor.getPort(), this.descriptor.getPassword());
LOGGER.info("connected to IRC");
this.pircConnection.addJoinListener(this);
Expand Down
Expand Up @@ -53,6 +53,13 @@

<super:global-jenkinsLogin />

<f:entry title="Notification charset" description="The character set to use for notifications">
<select name="charset">
<j:forEach var="cs" items="${descriptor.CHARSETS}">
<f:option selected="${instance.charset.toString()==cs}">${cs}</f:option>
</j:forEach>
</select>
</f:entry>
<f:entry title="Use /notice command" description="Use /notice command instead of /msg (default in ircbot &lt;= 2.0)">
<f:checkbox name="${descriptor.PARAMETERNAME_USE_NOTICE}" checked="${descriptor.useNotice}"/>
</f:entry>
Expand Down

0 comments on commit 6efc31a

Please sign in to comment.