Skip to content

Commit

Permalink
Merge branch 'update-forms' into update-forms-2
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jan 9, 2022
2 parents c5d84ef + 7f63f70 commit a9a6b62
Show file tree
Hide file tree
Showing 1,362 changed files with 13,676 additions and 11,369 deletions.
4 changes: 2 additions & 2 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<properties>
<asm.version>9.2</asm.version>
<slf4jVersion>1.7.32</slf4jVersion>
<stapler.version>1627.v5c244c19f85f</stapler.version>
<stapler.version>1638.v229a_24fa_b_17c</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand Down Expand Up @@ -221,7 +221,7 @@ THE SOFTWARE.
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.1.14</version>
<version>3.1.15</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
Expand Down
8 changes: 8 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
<pattern>net</pattern>
<shadedPattern>io.jenkins.cli.shaded.net</shadedPattern>
</relocation>
<relocation>
<pattern>com</pattern>
<shadedPattern>io.jenkins.cli.shaded.com</shadedPattern>
</relocation>
<relocation>
<pattern>jakarta</pattern>
<shadedPattern>io.jenkins.cli.shaded.jakarta</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
Expand Down
38 changes: 22 additions & 16 deletions cli/src/main/java/hudson/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.cli;

import static java.util.logging.Level.FINE;
Expand Down Expand Up @@ -80,9 +81,10 @@ private CLI() {}
* @throws NotTalkingToJenkinsException when connection is not made to Jenkins service.
*/
/*package*/ static void verifyJenkinsConnection(URLConnection c) throws IOException {
if (c.getHeaderField("X-Hudson")==null && c.getHeaderField("X-Jenkins")==null)
if (c.getHeaderField("X-Hudson") == null && c.getHeaderField("X-Jenkins") == null)
throw new NotTalkingToJenkinsException(c);
}

/*package*/ static final class NotTalkingToJenkinsException extends IOException {
NotTalkingToJenkinsException(String s) {
super(s);
Expand All @@ -106,14 +108,15 @@ public static void main(final String[] _args) throws Exception {
}
}

private enum Mode {HTTP, SSH, WEB_SOCKET}
private enum Mode { HTTP, SSH, WEB_SOCKET }

public static int _main(String[] _args) throws Exception {
List<String> args = Arrays.asList(_args);
PrivateKeyProvider provider = new PrivateKeyProvider();

String url = System.getenv("JENKINS_URL");

if (url==null)
if (url == null)
url = System.getenv("HUDSON_URL");

boolean noKeyAuth = false;
Expand All @@ -130,10 +133,10 @@ public static int _main(String[] _args) throws Exception {

boolean strictHostKey = false;

while(!args.isEmpty()) {
while (!args.isEmpty()) {
String head = args.get(0);
if (head.equals("-version")) {
System.out.println("Version: "+computeVersion());
System.out.println("Version: " + computeVersion());
return 0;
}
if (head.equals("-http")) {
Expand Down Expand Up @@ -167,9 +170,9 @@ public static int _main(String[] _args) throws Exception {
printUsage("-remoting mode is no longer supported");
return -1;
}
if(head.equals("-s") && args.size()>=2) {
if (head.equals("-s") && args.size() >= 2) {
url = args.get(1);
args = args.subList(2,args.size());
args = args.subList(2, args.size());
continue;
}
if (head.equals("-noCertificateCheck")) {
Expand All @@ -185,15 +188,15 @@ public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
args = args.subList(1,args.size());
args = args.subList(1, args.size());
continue;
}
if (head.equals("-noKeyAuth")) {
noKeyAuth = true;
args = args.subList(1,args.size());
args = args.subList(1, args.size());
continue;
}
if(head.equals("-i") && args.size()>=2) {
if (head.equals("-i") && args.size() >= 2) {
File f = getFileFromArguments(args);
if (!f.exists()) {
printUsage(Messages.CLI_NoSuchFileExists(f));
Expand All @@ -202,7 +205,7 @@ public boolean verify(String s, SSLSession sslSession) {

provider.readFrom(f);

args = args.subList(2,args.size());
args = args.subList(2, args.size());
continue;
}
if (head.equals("-strictHostKey")) {
Expand Down Expand Up @@ -239,7 +242,7 @@ public boolean verify(String s, SSLSession sslSession) {
break;
}

if(url==null) {
if (url == null) {
printUsage(Messages.CLI_NoURL());
return -1;
}
Expand All @@ -263,7 +266,7 @@ public boolean verify(String s, SSLSession sslSession) {
url += '/';
}

if(args.isEmpty())
if (args.isEmpty())
args = Collections.singletonList("help"); // default to help

if (mode == null) {
Expand Down Expand Up @@ -338,6 +341,7 @@ class CLIEndpoint extends Endpoint {
@Override
public void onOpen(Session session, EndpointConfig config) {}
}

class Authenticator extends ClientEndpointConfig.Configurator {
@Override
public void beforeRequest(Map<String, List<String>> headers) {
Expand All @@ -346,6 +350,7 @@ public void beforeRequest(Map<String, List<String>> headers) {
}
}
}

ClientManager client = ClientManager.createClient(JdkClientContainer.class.getName()); // ~ ContainerProvider.getWebSocketContainer()
client.getProperties().put(ClientProperties.REDIRECT_ENABLED, true); // https://tyrus-project.github.io/documentation/1.13.1/index/tyrus-proprietary-config.html#d0e1775
Session session = client.connectToServer(new CLIEndpoint(), ClientEndpointConfig.Builder.create().configurator(new Authenticator()).build(), URI.create(url.replaceFirst("^http", "ws") + "cli/ws"));
Expand All @@ -354,6 +359,7 @@ public void beforeRequest(Map<String, List<String>> headers) {
public void send(byte[] data) throws IOException {
session.getBasicRemote().sendBinary(ByteBuffer.wrap(data));
}

@Override
public void close() throws IOException {
session.close();
Expand Down Expand Up @@ -479,7 +485,7 @@ private static String computeVersion() {
Properties props = new Properties();
try {
InputStream is = CLI.class.getResourceAsStream("/jenkins/cli/jenkins-cli-version.properties");
if(is!=null) {
if (is != null) {
try {
props.load(is);
} finally {
Expand All @@ -489,7 +495,7 @@ private static String computeVersion() {
} catch (IOException e) {
e.printStackTrace(); // if the version properties is missing, that's OK.
}
return props.getProperty("version","?");
return props.getProperty("version", "?");
}

/**
Expand Down Expand Up @@ -520,7 +526,7 @@ static String usage() {
}

private static void printUsage(String msg) {
if(msg!=null) System.out.println(msg);
if (msg != null) System.out.println(msg);
System.err.println(usage());
}

Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/hudson/cli/CLIConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* Fluent-API to instantiate {@link CLI}.
*
*
* @author Kohsuke Kawaguchi
*/
public class CLIConnectionFactory {
Expand All @@ -26,7 +26,7 @@ public CLIConnectionFactory authorization(String value) {
* Currently unused.
*/
public CLIConnectionFactory basicAuth(String username, String password) {
return basicAuth(username+':'+password);
return basicAuth(username + ':' + password);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public String toString() {
buf.append(super.toString()).append("\n");
buf.append("Read back: ").append(HexDump.toHex(readBack)).append('\n');
buf.append("Read ahead: ").append(HexDump.toHex(readAhead));
if (diagnoseFailure!=null) {
if (diagnoseFailure != null) {
StringWriter w = new StringWriter();
PrintWriter p = new PrintWriter(w);
diagnoseFailure.printStackTrace(p);
p.flush();

buf.append("\nDiagnosis problem:\n ");
buf.append(w.toString().trim().replace("\n","\n "));
buf.append(w.toString().trim().replace("\n", "\n "));
}
return buf.toString();
}
Expand Down
18 changes: 9 additions & 9 deletions cli/src/main/java/hudson/cli/FlightRecorderInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public DiagnosedStreamCorruptionException analyzeCrash(Exception problem, String
final ByteArrayOutputStream readAhead = new ByteArrayOutputStream();
final IOException[] error = new IOException[1];

Thread diagnosisThread = new Thread(diagnosisName+" stream corruption diagnosis thread") {
Thread diagnosisThread = new Thread(diagnosisName + " stream corruption diagnosis thread") {
@Override
public void run() {
int b;
try {
// not all InputStream will look for the thread interrupt flag, so check that explicitly to be defensive
while (!Thread.interrupted() && (b=source.read())!=-1) {
while (!Thread.interrupted() && (b = source.read()) != -1) {
readAhead.write(b);
}
} catch (IOException e) {
Expand All @@ -81,23 +81,23 @@ public void run() {
if (diagnosisThread.isAlive())
diagnosisThread.interrupt(); // if it's not dead, kill

return new DiagnosedStreamCorruptionException(problem,diagnosisProblem,getRecord(),readAhead.toByteArray());
return new DiagnosedStreamCorruptionException(problem, diagnosisProblem, getRecord(), readAhead.toByteArray());

}

@Override
public int read() throws IOException {
int i = source.read();
if (i>=0)
if (i >= 0)
recorder.write(i);
return i;
}

@Override
public int read(@NonNull byte[] b, int off, int len) throws IOException {
len = source.read(b, off, len);
if (len>0)
recorder.write(b,off,len);
if (len > 0)
recorder.write(b, off, len);
return len;
}

Expand All @@ -106,8 +106,8 @@ public int read(@NonNull byte[] b, int off, int len) throws IOException {
*/
@Override
public long skip(long n) throws IOException {
byte[] buf = new byte[(int)Math.min(n,64*1024)];
return read(buf,0,buf.length);
byte[] buf = new byte[(int) Math.min(n, 64 * 1024)];
return read(buf, 0, buf.length);
}

@Override
Expand Down Expand Up @@ -157,7 +157,7 @@ public synchronized byte[] toByteArray() {
System.arraycopy(data, 0, ret, capacity - pos, pos);
return ret;
}

/** @author @roadrunner2 */
@Override public synchronized void write(@NonNull byte[] buf, int off, int len) {
// no point in trying to copy more than capacity; this also simplifies logic below
Expand Down
12 changes: 6 additions & 6 deletions cli/src/main/java/hudson/cli/FullDuplexHttpStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class FullDuplexHttpStream {
private final URL base;

private final OutputStream output;
private final InputStream input;

Expand Down Expand Up @@ -65,7 +65,7 @@ public FullDuplexHttpStream(URL base, String relativeTarget, String authorizatio
con.setDoOutput(true); // request POST to avoid caching
con.setRequestMethod("POST");
con.addRequestProperty("Session", uuid.toString());
con.addRequestProperty("Side","download");
con.addRequestProperty("Side", "download");
if (authorization != null) {
con.addRequestProperty("Authorization", authorization);
}
Expand All @@ -83,11 +83,11 @@ public FullDuplexHttpStream(URL base, String relativeTarget, String authorizatio
con.setDoOutput(true); // request POST
con.setRequestMethod("POST");
con.setChunkedStreamingMode(0);
con.setRequestProperty("Content-type","application/octet-stream");
con.setRequestProperty("Content-type", "application/octet-stream");
con.addRequestProperty("Session", uuid.toString());
con.addRequestProperty("Side","upload");
con.addRequestProperty("Side", "upload");
if (authorization != null) {
con.addRequestProperty ("Authorization", authorization);
con.addRequestProperty("Authorization", authorization);
}
output = con.getOutputStream();
LOGGER.fine("established upload side");
Expand Down Expand Up @@ -118,5 +118,5 @@ private URL tryToResolveRedirects(URL base, String authorization) {

static final int BLOCK_SIZE = 1024;
static final Logger LOGGER = Logger.getLogger(FullDuplexHttpStream.class.getName());

}
13 changes: 7 additions & 6 deletions cli/src/main/java/hudson/cli/HexDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class HexDump {
private static final String CODE = "0123456789abcdef";

public static String toHex(byte[] buf) {
return toHex(buf,0,buf.length);
return toHex(buf, 0, buf.length);
}

public static String toHex(byte[] buf, int start, int len) {
StringBuilder r = new StringBuilder(len*2);
StringBuilder r = new StringBuilder(len * 2);
boolean inText = false;
for (int i=0; i<len; i++) {
byte b = buf[start+i];
for (int i = 0; i < len; i++) {
byte b = buf[start + i];
if (b >= 0x20 && b <= 0x7e) {
if (!inText) {
inText = true;
Expand All @@ -28,8 +29,8 @@ public static String toHex(byte[] buf, int start, int len) {
inText = false;
}
r.append("0x");
r.append(CODE.charAt((b>>4)&15));
r.append(CODE.charAt(b&15));
r.append(CODE.charAt((b >> 4) & 15));
r.append(CODE.charAt(b & 15));
if (i < len - 1) {
if (b == 10) {
r.append('\n');
Expand Down
2 changes: 2 additions & 0 deletions cli/src/main/java/hudson/cli/PlainCLIProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ protected final OutputStream stream(final Op op) {
public void write(int b) throws IOException {
send(op, new byte[] {(byte) b});
}

@Override
public void write(@NonNull byte[] b, int off, int len) throws IOException {
send(op, b, off, len);
}

@Override
public void write(@NonNull byte[] b) throws IOException {
send(op, b);
Expand Down
Loading

0 comments on commit a9a6b62

Please sign in to comment.