1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Add a REPL for Smack (smack-repl)

This commit is contained in:
Florian Schmaus 2016-02-10 14:09:13 +01:00
parent 529e1eb058
commit 8f149346a6
6 changed files with 111 additions and 1 deletions

30
repl Executable file
View file

@ -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

View file

@ -22,4 +22,5 @@ include 'smack-core',
'smack-android',
'smack-android-extensions',
'smack-java7',
'smack-integration-test'
'smack-integration-test',
'smack-repl'

18
smack-repl/build.gradle Normal file
View file

@ -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
}

6
smack-repl/scala.repl Normal file
View file

@ -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

View file

@ -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
}
}

View file

@ -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;