diff --git a/app/build.gradle b/app/build.gradle index 4d2b480..5e1c51b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,13 +31,15 @@ android { productFlavors { } packagingOptions { - exclude 'META-INF/proguard/androidx-annotations.pro' + resources { + excludes += ['META-INF/proguard/androidx-annotations.pro'] + } } + namespace 'com.ublox.BLE' } dependencies { implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation project(':meshprovision') implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:support-v13:28.0.0' testImplementation 'junit:junit:4.12' diff --git a/app/src/androidTest/java/com/ublox/BLE/TestAboutActivity.java b/app/src/androidTest/java/com/ublox/BLE/TestAboutActivity.java index 49ae7f9..3dc38dd 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestAboutActivity.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestAboutActivity.java @@ -10,7 +10,7 @@ import org.hamcrest.Matcher; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import static android.app.Activity.RESULT_OK; diff --git a/app/src/androidTest/java/com/ublox/BLE/TestChatFragment.java b/app/src/androidTest/java/com/ublox/BLE/TestChatFragment.java index 7a50d41..2b8baba 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestChatFragment.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestChatFragment.java @@ -5,9 +5,9 @@ import com.ublox.BLE.activities.MainActivity; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; @@ -29,13 +29,13 @@ public class TestChatFragment { @Rule public ActivityTestRule act = new MainWithBluetoothTestRule(); - @Before + @BeforeEach public void setup() { waitFor(500); onView(withText("CHAT")).perform(click()); } - @Test + @org.junit.jupiter.api.Test public void sendMessage_connected() { typeMessage("Hello World!"); onView(allOf(withId(R.id.tvMessage), withText("Hello World!"))).check(matches(isDisplayed())); @@ -48,7 +48,7 @@ public void sendMessage_notConnected() { onToast(act.getActivity(), "You need to be connected to a device in order to do this"); } - @Test + @org.junit.jupiter.api.Test public void sendMessage_withCr() { onView(withId(R.id.swSendWithCR)).perform(click()); typeMessage("Hello World!"); diff --git a/app/src/androidTest/java/com/ublox/BLE/TestDatapump.java b/app/src/androidTest/java/com/ublox/BLE/TestDatapump.java index 703d727..7bb05fb 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestDatapump.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestDatapump.java @@ -5,9 +5,9 @@ import com.ublox.BLE.activities.MainActivity; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; @@ -24,7 +24,7 @@ public class TestDatapump { @Rule public ActivityTestRule activityTestRule = new MainWithBluetoothTestRule(); - @Before + @BeforeEach public void setup() { waitFor(500); onView(withText("TEST")).perform(click()); diff --git a/app/src/androidTest/java/com/ublox/BLE/TestDevicesActivity.java b/app/src/androidTest/java/com/ublox/BLE/TestDevicesActivity.java index 1cf03bb..66f13f9 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestDevicesActivity.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestDevicesActivity.java @@ -12,9 +12,9 @@ import com.ublox.BLE.bluetooth.BluetoothPeripheral; import com.ublox.BLE.utils.GattAttributes; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import java.lang.reflect.Field; @@ -46,7 +46,7 @@ public class TestDevicesActivity { @Rule public GrantPermissionRule permissionRule = GrantPermissionRule.grant(Manifest.permission.ACCESS_COARSE_LOCATION); - @Before + @BeforeEach public void setup() { mockScanner = mock(BluetoothCentral.class); @@ -57,19 +57,19 @@ public void setup() { } } - @Test + @org.junit.jupiter.api.Test public void openAboutPage() { onView(withId(R.id.menu_about)).perform(click()); onView(withId(R.id.bVisit)).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void startCallsScan() { onView(withId(R.id.menu_scan)).perform(click()); verify(mockScanner, atLeastOnce()).scan(any()); } - @Test + @org.junit.jupiter.api.Test public void whenScanStartedDisplayStop() { when(mockScanner.getState()).thenReturn(BluetoothCentral.State.SCANNING); act.getActivity().centralChangedState(mockScanner); @@ -77,7 +77,7 @@ public void whenScanStartedDisplayStop() { onView(withId(R.id.menu_stop)).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void stopCallsStopOnScan() { when(mockScanner.getState()).thenReturn(BluetoothCentral.State.SCANNING); act.getActivity().centralChangedState(mockScanner); @@ -85,7 +85,7 @@ public void stopCallsStopOnScan() { verify(mockScanner, atLeastOnce()).stop(); } - @Test + @org.junit.jupiter.api.Test public void whenStoppedDisplayScanAgain() { when(mockScanner.getState()).thenReturn( BluetoothCentral.State.SCANNING, @@ -99,7 +99,7 @@ public void whenStoppedDisplayScanAgain() { onView(withId(R.id.menu_scan)).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void displayScannedPeripherals() { listMockedPeripherals(); @@ -109,7 +109,7 @@ public void displayScannedPeripherals() { onData(withDevice("00:00:00:00:00:01")).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void filterWithSps() { listMockedPeripherals(); onView(withId(R.id.checkBoxSps)).perform(click()); @@ -118,7 +118,7 @@ public void filterWithSps() { onData(withDevice("00:00:00:00:00:01")).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void filterDevicesAreSavedAnyway() { onView(withId(R.id.checkBoxSps)).perform(click()); listMockedPeripherals(); @@ -130,7 +130,7 @@ public void filterDevicesAreSavedAnyway() { onData(withDevice("00:00:00:00:00:01")).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void filterOnName() { listMockedPeripherals(); @@ -150,7 +150,7 @@ public void filterNameAlsoWorksOnAddress() { onData(withDevice("00:00:00:00:00:02")).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void filterCombineNameAndSps() { listMockedPeripherals(); @@ -161,7 +161,7 @@ public void filterCombineNameAndSps() { } - @Test() + @org.junit.jupiter.api.Test() public void connect() { listMockedPeripherals(); try { diff --git a/app/src/androidTest/java/com/ublox/BLE/TestMainActivity.java b/app/src/androidTest/java/com/ublox/BLE/TestMainActivity.java index b00382f..4901884 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestMainActivity.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestMainActivity.java @@ -5,9 +5,9 @@ import com.ublox.BLE.activities.MainActivity; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; @@ -25,7 +25,7 @@ public class TestMainActivity { @Rule public ActivityTestRule act = new MainWithBluetoothTestRule(); - @Before + @BeforeEach public void setup() { waitFor(500); } @@ -46,7 +46,7 @@ public void disconnectFromDevice() { onView(withId(R.id.menu_connect)).check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void reconnectToDevice() { onView(withId(R.id.menu_disconnect)).perform(click()); onView(withId(R.id.menu_connect)).perform(click()); diff --git a/app/src/androidTest/java/com/ublox/BLE/TestOverviewFragment.java b/app/src/androidTest/java/com/ublox/BLE/TestOverviewFragment.java index 8509e7b..540561d 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestOverviewFragment.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestOverviewFragment.java @@ -6,7 +6,7 @@ import com.ublox.BLE.activities.MainActivity; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; diff --git a/app/src/androidTest/java/com/ublox/BLE/TestServicesFragment.java b/app/src/androidTest/java/com/ublox/BLE/TestServicesFragment.java index 472093e..acfbf59 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestServicesFragment.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestServicesFragment.java @@ -5,9 +5,9 @@ import com.ublox.BLE.activities.MainActivity; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onData; @@ -26,7 +26,7 @@ public class TestServicesFragment { @Rule public ActivityTestRule act = new MainWithBluetoothTestRule(); - @Before + @BeforeEach public void setup() { waitFor(500); onView(withText("SERVICES")).perform(click()); diff --git a/app/src/androidTest/java/com/ublox/BLE/TestTestFragment.java b/app/src/androidTest/java/com/ublox/BLE/TestTestFragment.java index d28fb74..d7c84c4 100644 --- a/app/src/androidTest/java/com/ublox/BLE/TestTestFragment.java +++ b/app/src/androidTest/java/com/ublox/BLE/TestTestFragment.java @@ -5,10 +5,10 @@ import com.ublox.BLE.activities.MainActivity; -import org.junit.Before; -import org.junit.Ignore; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; @@ -32,19 +32,19 @@ public class TestTestFragment { @Rule public ActivityTestRule act = new MainWithBluetoothTestRule(); - @Before + @BeforeEach public void setup() { waitFor(500); onView(withText("TEST")).perform(click()); } - @Test + @org.junit.jupiter.api.Test public void requestMTU_empty() { onView(withId(R.id.bMtu)).perform(click(), click()); onToast(act.getActivity(), "You must enter a number").check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void requestMTU_tooSmall() { enterMTU("0"); onView(withId(R.id.tvMtuSize)).check(matches(not(withText("0")))); @@ -56,81 +56,81 @@ public void requestMTU_min() { onView(withId(R.id.tvMtuSize)).check(matches(withText("23"))); } - @Test + @org.junit.jupiter.api.Test public void requestMTU_max() { enterMTU("247"); onView(withId(R.id.tvMtuSize)).check(matches(withText("247"))); } - @Test + @org.junit.jupiter.api.Test public void requestMTU_tooLarge() { enterMTU("300"); onView(withId(R.id.tvMtuSize)).check(matches(withText("247"))); } - @Test + @org.junit.jupiter.api.Test public void toggleCredits() { onView(withId(R.id.swCredits)).perform(click()); onView(withId(R.id.swCredits)).check(matches(isChecked())); } - @Ignore("Datapumping seems to lock ui here, might be badly mocked") - @Test + @Disabled("Datapumping seems to lock ui here, might be badly mocked") + @org.junit.jupiter.api.Test public void toggleCredits_ongoing() { onView(withId(R.id.swTxTest)).perform(click()); onView(withId(R.id.swCredits)).perform(click()); onView(withId(R.id.swCredits)).check(matches(isNotChecked())); } - @Test + @org.junit.jupiter.api.Test public void sendOnePacket() { onView(withText("packet")).perform(click()); onView(withId(R.id.swTxTest)).perform(click()); onView(withId(R.id.tvTxCounter)).check(matches(withText("20 B"))); } - @Ignore("Datapumping seems to lock ui here, might be badly mocked") - @Test + @Disabled("Datapumping seems to lock ui here, might be badly mocked") + @org.junit.jupiter.api.Test public void sendContinuous() { onView(withId(R.id.continuous)).perform(click()); onView(withId(R.id.swTxTest)).perform(click()); onView(withId(R.id.tvTxCounter)).check(matches(not(withText("0 B")))); } - @Test + @org.junit.jupiter.api.Test public void clearRx() { onView(withId(R.id.bRxReset)).perform(click()); onView(withId(R.id.tvRxAvg)).check(matches(withText("0.00 kbps"))); } - @Test + @org.junit.jupiter.api.Test public void setPacketEmpty() { onView(withId(R.id.etPacketSize)).perform(click(), clearText(), closeSoftKeyboard()); onToast(act.getActivity(), "The packet length number too big or not valid!").check(matches(isDisplayed())); } - @Test + @org.junit.jupiter.api.Test public void toggleCredits_disconnectedNoChange() { onView(withId(R.id.menu_disconnect)).perform(click()); onView(withId(R.id.swCredits)).perform(click()); onView(withId(R.id.swCredits)).check(matches(isNotChecked())); } - @Test + @org.junit.jupiter.api.Test public void requestMTU_disconnectedNoChange() { onView(withId(R.id.menu_disconnect)).perform(click()); enterMTU("247"); onView(withId(R.id.tvMtuSize)).check(matches(not(withText("247")))); } - @Test + @org.junit.jupiter.api.Test public void startTxTest_disconnectedNoChange() { onView(withId(R.id.menu_disconnect)).perform(click()); onView(withId(R.id.swTxTest)).perform(click()); onView(withId(R.id.tvTxCounter)).check(matches(withText("0 B"))); } - @Test + @org.junit.jupiter.api.Test public void sendSinglePacketLargerThanMtuDisplaysCorrectly() { onView(withText("packet")).perform(click()); onView(withId(R.id.etPacketSize)).perform(click(), clearText(), typeText("32"), closeSoftKeyboard()); diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 35c4146..faecf6d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + @@ -47,9 +46,6 @@ android:name=".activities.RemoteActivity" android:label="" android:screenOrientation="portrait" /> - \ No newline at end of file diff --git a/app/src/main/java/com/ublox/BLE/activities/DevicesActivity.java b/app/src/main/java/com/ublox/BLE/activities/DevicesActivity.java index e9d53cb..44519c3 100644 --- a/app/src/main/java/com/ublox/BLE/activities/DevicesActivity.java +++ b/app/src/main/java/com/ublox/BLE/activities/DevicesActivity.java @@ -34,11 +34,9 @@ import com.ublox.BLE.bluetooth.BluetoothDevice; import com.ublox.BLE.bluetooth.BluetoothPeripheral; import com.ublox.BLE.bluetooth.BluetoothScanner; -import com.ublox.BLE.fragments.KeyEntryFragment; import com.ublox.BLE.utils.GattAttributes; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.UUID; @@ -50,7 +48,7 @@ import static android.bluetooth.BluetoothDevice.BOND_BONDING; import static android.bluetooth.BluetoothDevice.BOND_NONE; import static android.content.pm.PackageManager.PERMISSION_GRANTED; -import static no.nordicsemi.android.meshprovisioner.utils.SecureUtils.calculateK3; + public class DevicesActivity extends Activity implements AdapterView.OnItemClickListener, BluetoothCentral.Delegate { /* @@ -72,7 +70,6 @@ public class DevicesActivity extends Activity implements AdapterView.OnItemClick private LeDeviceListAdapter mLeDeviceListAdapter; private BluetoothAdapter mBluetoothAdapter; private BluetoothCentral scanner; - private byte[] currentNetworkId = calculateK3(DEFAULT_NET_KEY); private byte[] currentNetKey = DEFAULT_NET_KEY; private byte[] currentAppKey = DEFAULT_APP_KEY; @@ -175,7 +172,6 @@ public boolean onOptionsItemSelected(MenuItem item) { startActivity(aboutIntent); break; case R.id.menu_mesh_keys: - showMeshDialog(null); break; } return true; @@ -237,44 +233,6 @@ private void scanLeDevice(final boolean enable) { invalidateOptionsMenu(); } - private void showMeshDialog(BluetoothPeripheral andJoin) { - if (!DEFINE_MESH_ACTIVE) return; - - boolean doJoin = andJoin != null; - boolean doSkipDialog = doJoin && hasMatchingKey(andJoin); - - if (doSkipDialog) { - joinMesh(andJoin); - return; - } - - String acceptText = doJoin ? "Join" : "Set"; - KeyEntryFragment dialog = new KeyEntryFragment(); - dialog.setDefaultKeys(DEFAULT_NET_KEY, DEFAULT_APP_KEY); - dialog.setAcceptKeys(acceptText, (netKey, appKey) -> { - currentNetKey = netKey; - currentAppKey = appKey; - currentNetworkId = calculateK3(netKey); - - if (!doJoin) return; - joinMesh(andJoin); - }); - dialog.show(getFragmentManager(), "KeyEntry"); - } - - private boolean hasMatchingKey(BluetoothPeripheral peripheral) { - byte[] serviceData = peripheral.serviceDataFor(MESH_SERVICE); - return serviceData.length > 8 && serviceData[0] == 0 && Arrays.equals(currentNetworkId, Arrays.copyOfRange(serviceData, 1, serviceData.length)); - } - - private void joinMesh(BluetoothPeripheral peripheral) { - Intent intent = new Intent(this, MeshActivity.class); - intent.putExtra(EXTRA_DEVICE, peripheral); - intent.putExtra(EXTRA_NET_KEY, currentNetKey); - intent.putExtra(EXTRA_APP_KEY, currentAppKey); - startActivity(intent); - } - @TargetApi(23) private void verifyPermissionAndScan() { String[] request = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S @@ -318,6 +276,16 @@ public void onRequestPermissionsResult (int requestCode, String[] permissions, i if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && requestCode == BLUETOOTH_ENABLE_REQUEST) { if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return; + } startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } else { Toast.makeText(this, R.string.enable_permission_toast, Toast.LENGTH_LONG).show(); @@ -342,7 +310,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ContextCompat.checkSelfPermission(this, BLUETOOTH_CONNECT) == PERMISSION_GRANTED) { if (DEFINE_MESH_ACTIVE && device.advertisedService(MESH_SERVICE)) { - showMeshDialog(device); + } else { Intent intent = new Intent(this, MainActivity.class); intent.putExtra(EXTRA_DEVICE, ((BluetoothDevice) device).toUbloxDevice()); diff --git a/app/src/main/res/layout/fragment_mesh_list.xml b/app/src/main/res/layout/fragment_mesh_list.xml index a0bedc9..8d17666 100644 --- a/app/src/main/res/layout/fragment_mesh_list.xml +++ b/app/src/main/res/layout/fragment_mesh_list.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - tools:context=".fragments.MeshListFragment"> + android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/fragment_mesh_node_details.xml b/app/src/main/res/layout/fragment_mesh_node_details.xml index 6b9f197..de854d4 100644 --- a/app/src/main/res/layout/fragment_mesh_node_details.xml +++ b/app/src/main/res/layout/fragment_mesh_node_details.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - tools:context=".activities.MeshActivity"> + android:layout_height="match_parent"> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,92 +133,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f955316..9b42019 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,94 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index 3660389..9d495b3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1 @@ -include ':app' -include ':meshprovision' -project(':meshprovision').projectDir = file('Android-nRF-Mesh-Library/android-nrf-mesh-library/meshprovisioner') \ No newline at end of file +include ':app' \ No newline at end of file