From 8f149346a66f873cc053be4d050ae18612a82f41 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 10 Feb 2016 14:09:13 +0100 Subject: [PATCH] Add a REPL for Smack (smack-repl) --- repl | 30 ++++++++++++++++ settings.gradle | 3 +- smack-repl/build.gradle | 18 ++++++++++ smack-repl/scala.repl | 6 ++++ .../igniterealtime/smack/repl/SmackRepl.java | 34 +++++++++++++++++++ .../smack/repl/package-info.java | 21 ++++++++++++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100755 repl create mode 100644 smack-repl/build.gradle create mode 100644 smack-repl/scala.repl create mode 100644 smack-repl/src/main/java/org/igniterealtime/smack/repl/SmackRepl.java create mode 100644 smack-repl/src/main/java/org/igniterealtime/smack/repl/package-info.java diff --git a/repl b/repl new file mode 100755 index 000000000..20ffd4b66 --- /dev/null +++ b/repl @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -e +set -u +set -o pipefail + +while getopts d OPTION "$@"; do + case $OPTION in + d) + set -x + ;; + esac +done + +echo "Compiling and computing classpath (May take a while)" +# Sadly even with the --quiet option Gradle (or some component of) +# will print the number of warnings/errors to stdout if there are +# any. So the result could look like +# 52 warnings\n1 warning\n12 warnings\n +# /smack/smack-repl/build/classes/main:/smack/smack-repl/build/ +# resources/main:/smack/smack-tcp/build/libs/smack-tcp-4.2.0-alpha4-SNAPSHOT.jar +# So perform a "tail -n1" on the output of gradle +declare -r GRADLE_CLASSPATH="$(gradle :smack-repl:printClasspath --quiet |\ + tail -n1)" +echo "Finished, starting REPL" + +java \ + -Dscala.usejavacp=true \ + -classpath "${GRADLE_CLASSPATH}" \ + scala.tools.nsc.MainGenericRunner \ + -i smack-repl/scala.repl diff --git a/settings.gradle b/settings.gradle index 5759f000e..9d5284329 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,4 +22,5 @@ include 'smack-core', 'smack-android', 'smack-android-extensions', 'smack-java7', - 'smack-integration-test' + 'smack-integration-test', + 'smack-repl' diff --git a/smack-repl/build.gradle b/smack-repl/build.gradle new file mode 100644 index 000000000..4e9cb35fe --- /dev/null +++ b/smack-repl/build.gradle @@ -0,0 +1,18 @@ +ext { + scalaVersion = '2.11.7' +} + +dependencies { + compile project(':smack-tcp') + compile project(':smack-bosh') + compile project(':smack-java7') + compile project(':smack-resolver-minidns') + compile project(':smack-extensions') + compile project(':smack-experimental') + compile project(':smack-legacy') + compile "org.scala-lang:scala-compiler:${scalaVersion}" +} + +task printClasspath(dependsOn: assemble) << { + println sourceSets.main.runtimeClasspath.asPath +} diff --git a/smack-repl/scala.repl b/smack-repl/scala.repl new file mode 100644 index 000000000..0fcca635c --- /dev/null +++ b/smack-repl/scala.repl @@ -0,0 +1,6 @@ +org.igniterealtime.smack.repl.SmackRepl.init() + +import org.jivesoftware.smack._ +import org.jivesoftware.smack.util.TLSUtils +import org.jivesoftware.smack.tcp._ +import org.jxmpp.jid.impl.JidCreate diff --git a/smack-repl/src/main/java/org/igniterealtime/smack/repl/SmackRepl.java b/smack-repl/src/main/java/org/igniterealtime/smack/repl/SmackRepl.java new file mode 100644 index 000000000..841e7fb1f --- /dev/null +++ b/smack-repl/src/main/java/org/igniterealtime/smack/repl/SmackRepl.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2016 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.igniterealtime.smack.repl; + +import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.util.dns.javax.JavaxResolver; + +public class SmackRepl { + + public static void init() { + SmackConfiguration.getVersion(); + // smack-repl also pulls in smack-resolver-minidns which has higher precedence the smack-resolver-javax but + // won't work on Java SE platforms. Therefore explicitly setup JavaxResolver. + JavaxResolver.setup(); + // CHECKSTYLE:OFF + System.out.println("Smack REPL"); + // CHECKSTYLE:ON + } + +} diff --git a/smack-repl/src/main/java/org/igniterealtime/smack/repl/package-info.java b/smack-repl/src/main/java/org/igniterealtime/smack/repl/package-info.java new file mode 100644 index 000000000..36c6a20a6 --- /dev/null +++ b/smack-repl/src/main/java/org/igniterealtime/smack/repl/package-info.java @@ -0,0 +1,21 @@ +/** + * + * Copyright 2016 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A REPL (Read Eval Print Loop) for Smack. + */ +package org.igniterealtime.smack.repl;