[SCM] jenkins packaging branch, master, updated. debian/1.480.3+dfsg-1-1-g2b27844
James Page
james.page at ubuntu.com
Thu Jul 4 10:21:00 UTC 2013
The following commit has been merged in the master branch:
commit 2b27844e2d953daaf9681836da83f07f2667a0d8
Author: James Page <james.page at ubuntu.com>
Date: Thu Jul 4 11:20:52 2013 +0100
Re-add missing files from upstream tarball
diff --git a/core/src/main/java/jenkins/util/MarkFindingOutputStream.java b/core/src/main/java/jenkins/util/MarkFindingOutputStream.java
new file mode 100644
index 0000000..6fa4365
--- /dev/null
+++ b/core/src/main/java/jenkins/util/MarkFindingOutputStream.java
@@ -0,0 +1,118 @@
+package jenkins.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Filtering {@link OutputStream} that looks for {@link #MARK} in the output stream and notifies the callback.
+ *
+ * The mark itself will be removed from the stream.
+ *
+ * @author Kohsuke Kawaguchi
+ * @since 1.458
+ */
+public abstract class MarkFindingOutputStream extends OutputStream {
+ private final OutputStream base;
+
+ public MarkFindingOutputStream(OutputStream base) {
+ this.base = base;
+ }
+
+ /**
+ * Position in {@link #MARK} if we are currently suspecting a match.
+ */
+ private int match = 0;
+
+ public synchronized void write(int b) throws IOException {
+ if (MBYTES[match] == b) {// another byte matched. Good. Keep going...
+ match++;
+ if (match == MBYTES.length) {
+ // don't send MARK to the output, but instead notify the callback
+ onMarkFound();
+ match = 0;
+ }
+ } else {
+ if (match > 0) {
+ // only matched partially. send the partial match that we held off down the pipe
+ base.write(MBYTES, 0, match);
+ match = 0;
+
+ // this might match the first byte in MARK, so retry.
+ write(b);
+ } else {
+ base.write(b);
+ }
+ }
+ }
+
+ public void write(byte b[], int off, int len) throws IOException {
+ final int start = off;
+ final int end = off + len;
+ for (int i=off; i<end; ) {
+ if (MBYTES[match] == b[i]) {// another byte matched. Good. Keep going...
+ match++;
+ i++;
+ if (match == MBYTES.length) {
+ base.write(b,off,i-off-MBYTES.length); // flush the portion up to MARK
+ // don't send MARK to the output, but instead notify the callback
+ onMarkFound();
+ match = 0;
+ off = i;
+ len = end-i;
+ }
+ } else {
+ if (match > 0) {
+ // only matched partially.
+ // if a part of the partial match spans into the previous write, we need to fake that write.
+ int extra = match-(i-start);
+ if (extra>0) {
+ base.write(MBYTES,0,extra);
+ }
+ match = 0;
+
+ // this b[i] might be a fast byte in MARK, so we'll retry
+ } else {
+ // irrelevant byte.
+ i++;
+ }
+ }
+
+ }
+
+ // if we are partially matching, can't send that portion yet.
+ if (len-match>0)
+ base.write(b, off, len-match);
+ }
+
+ public void flush() throws IOException {
+ flushPartialMatch();
+ base.flush();
+ }
+
+ public void close() throws IOException {
+ flushPartialMatch();
+ base.close();
+ }
+
+ private void flushPartialMatch() throws IOException {
+ if (match>0) {
+ base.write(MBYTES,0,match);
+ match = 0;
+ }
+ }
+
+ protected abstract void onMarkFound();
+
+ // having a new line in the end makes it work better with line-buffering transformation
+ public static final String MARK = "[Jenkins:SYNC-MARK]\n";
+ private static final byte[] MBYTES = toUTF8(MARK);
+
+ private static byte[] toUTF8(String s) {
+ try {
+ return s.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
+ }
+}
diff --git a/core/src/main/java/jenkins/util/ServerTcpPort.java b/core/src/main/java/jenkins/util/ServerTcpPort.java
new file mode 100644
index 0000000..8460a32
--- /dev/null
+++ b/core/src/main/java/jenkins/util/ServerTcpPort.java
@@ -0,0 +1,35 @@
+package jenkins.util;
+
+import net.sf.json.JSONObject;
+import org.kohsuke.stapler.DataBoundConstructor;
+
+/**
+ * Used in conjunction with /lib/form/serverTcpPort tag to parse the submitted JSON back into a port number.
+ *
+ * @author Kohsuke Kawaguchi
+ * @since 1.445
+ */
+public class ServerTcpPort {
+ private int value;
+ private String type;
+
+ @DataBoundConstructor
+ public ServerTcpPort(int value, String type) {
+ this.value = value;
+ this.type = type;
+ }
+
+ public ServerTcpPort(JSONObject o) {
+ type = o.getString("type");
+ value = o.optInt("value");
+ }
+
+ /**
+ * Parses the value back into the port number
+ */
+ public int getPort() {
+ if (type.equals("fixed")) return value;
+ if (type.equals("random")) return 0;
+ return -1;
+ }
+}
--
jenkins packaging
More information about the pkg-java-commits
mailing list