Commit c44033c3 authored by Ossama Othman's avatar Ossama Othman Committed by Erich Keane

Clean up some SonarQube warnings (trailing whitespace, etc).

Clean up trailing whitespace and removed Windows line endings from
most text files to address SonarQube warnings.  As a side effect of
this clean-up, several files that should not have been executable had
their executable permission bit removed.

Change-Id: Ie388df6e383219cdebfb56ba8fa86cacf2ca3e46
Signed-off-by: default avatarOssama Othman <ossama.othman@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1980Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarJon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent b56811eb
Build Instructions for Android-API:
1.Verify that you have the latest JDK (you might need to set the JDK_HOME variable)
2.Clone the latest iotivity codebase.
3.set environment variables:
a.platform=android
b.If running in windows, change the following line in the build.gradle file (<iotivity>/android/android_api/base/build.gradle):
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
to
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
4.Build scons for android and your targeted architecture (This will also build Android API):
a.scons TARGET_OS=android TARGET_ARCH=<target arch> TARGET_TRANSPORT=IP RELEASE=1
where <target arch> can be armeabi, armeabi-v7a, x86.
Note: To build in debug mode, use RELEASE=0.
Note: The minimum SDK version supported is 21.
Note: Only TARGET_TRANSPORT currently supported is IP
b.If the project is setup correctly, you should see a BUILD SUCCESSFUL message on the terminal
c.You should see the .aar files generated inside of '<iotivity>/android/android_api/base/build/outputs/aar' directory. The .aar files contain jni directory and also a .jar file
TO RUN UNIT TESTS IN ANDROID-API
5.The '<iotivity>/android/android_api/base/src/androidTest/...' directory contains tests which can be used to get an idea about the Android API usage.
TO USE THE .AAR FILE IN <iotivity>/android/examples project
6. Verify that 7 different *.so files exist inside <iotivity>/android/android-api/base/libs/<TARGET_ARCH> directory. (They should already be present in the *.aar file.)
7. Import Project 'Examples' into android-studio.
8.To add an .aar file to the 'Examples' project,
a.Right click on Examples->New->Module->Import .JAR or .AAR Package
b.Select the .aar file from the location in step 6e above
c.Right click on Examples->Open Module Settings
d.Select each sample app module under 'Modules'->Dependencies->Add->Module Dependency
e.The .aar file selected in step 10b above should be present. Select it.
f.Repeat steps d and e for each sample app module.
TO USE THE .AAR FILE IN A DIFFERENT PROJECT
9. Verify that 7 different *.so files exist inside <iotivity base>/android/android-api/base/libs/<TARGET_ARCH> directory.
10. Import the .aar file in your project to use it
Build Instructions for Android-API:
1.Verify that you have the latest JDK (you might need to set the JDK_HOME variable)
2.Clone the latest iotivity codebase.
3.set environment variables:
a.platform=android
b.If running in windows, change the following line in the build.gradle file (<iotivity>/android/android_api/base/build.gradle):
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
to
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
4.Build scons for android and your targeted architecture (This will also build Android API):
a.scons TARGET_OS=android TARGET_ARCH=<target arch> TARGET_TRANSPORT=IP RELEASE=1
where <target arch> can be armeabi, armeabi-v7a, x86.
Note: To build in debug mode, use RELEASE=0.
Note: The minimum SDK version supported is 21.
Note: Only TARGET_TRANSPORT currently supported is IP
b.If the project is setup correctly, you should see a BUILD SUCCESSFUL message on the terminal
c.You should see the .aar files generated inside of '<iotivity>/android/android_api/base/build/outputs/aar' directory. The .aar files contain jni directory and also a .jar file
TO RUN UNIT TESTS IN ANDROID-API
5.The '<iotivity>/android/android_api/base/src/androidTest/...' directory contains tests which can be used to get an idea about the Android API usage.
TO USE THE .AAR FILE IN <iotivity>/android/examples project
6. Verify that 7 different *.so files exist inside <iotivity>/android/android-api/base/libs/<TARGET_ARCH> directory. (They should already be present in the *.aar file.)
7. Import Project 'Examples' into android-studio.
8.To add an .aar file to the 'Examples' project,
a.Right click on Examples->New->Module->Import .JAR or .AAR Package
b.Select the .aar file from the location in step 6e above
c.Right click on Examples->Open Module Settings
d.Select each sample app module under 'Modules'->Dependencies->Add->Module Dependency
e.The .aar file selected in step 10b above should be present. Select it.
f.Repeat steps d and e for each sample app module.
TO USE THE .AAR FILE IN A DIFFERENT PROJECT
9. Verify that 7 different *.so files exist inside <iotivity base>/android/android-api/base/libs/<TARGET_ARCH> directory.
10. Import the .aar file in your project to use it
import os
import platform
Import('env')
android_home = env.get('ANDROID_HOME')
ANDROID_TARGET_ARCH = env.get('TARGET_ARCH')
if env.get('RELEASE'):
ANDROID_RELEASE="release"
else:
ANDROID_RELEASE="debug"
os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
print '''
***************************************** Info ********************************
* Either 'Android API 21' is not installed or 'Android SDK Build Tools *
* 20.0.0' is not installed. The Android SDK Manager will now open. Please *
* be sure to deselect all options, then select the following 2 packages: *
* 1. Under "Tools" select "Android SDK Build-tools" Revision 20. *
* 2. Under "Android 5.0.1 (API 21)" select "SDK Platform" *
* 3. Continue by selecting "Install 2 Packages" *
* *
* NOTE: If you have an http proxy, please press ctrl+c now and edit/create *
* the following file in your $HOME directory as follows: *
* *
* Edit/Create file: "$HOME/.android/androidtool.cfg" *
* *
* http.proxyPort=<YOUR_PORT_NUMBER> *
* sdkman.monitor.density=108 *
* http.proxyHost=<YOUR_HTTP_PROXY_ADDRESS> *
* sdkman.show.update.only=true *
* sdkman.ask.adb.restart=false *
* sdkman.force.http=true *
* sdkman.show.updateonly=true *
* *
*******************************************************************************
...Opening Android SDK Manager now. Once you are finished, the build will continue.
'''
os.system(android_home + '/tools/android')
jdk_env = Environment(ENV=os.environ)
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE))
jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
import os
import platform
Import('env')
android_home = env.get('ANDROID_HOME')
ANDROID_TARGET_ARCH = env.get('TARGET_ARCH')
if env.get('RELEASE'):
ANDROID_RELEASE="release"
else:
ANDROID_RELEASE="debug"
os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
print '''
***************************************** Info ********************************
* Either 'Android API 21' is not installed or 'Android SDK Build Tools *
* 20.0.0' is not installed. The Android SDK Manager will now open. Please *
* be sure to deselect all options, then select the following 2 packages: *
* 1. Under "Tools" select "Android SDK Build-tools" Revision 20. *
* 2. Under "Android 5.0.1 (API 21)" select "SDK Platform" *
* 3. Continue by selecting "Install 2 Packages" *
* *
* NOTE: If you have an http proxy, please press ctrl+c now and edit/create *
* the following file in your $HOME directory as follows: *
* *
* Edit/Create file: "$HOME/.android/androidtool.cfg" *
* *
* http.proxyPort=<YOUR_PORT_NUMBER> *
* sdkman.monitor.density=108 *
* http.proxyHost=<YOUR_HTTP_PROXY_ADDRESS> *
* sdkman.show.update.only=true *
* sdkman.ask.adb.restart=false *
* sdkman.force.http=true *
* sdkman.show.updateonly=true *
* *
*******************************************************************************
...Opening Android SDK Manager now. Once you are finished, the build will continue.
'''
os.system(android_home + '/tools/android')
jdk_env = Environment(ENV=os.environ)
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE))
jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
/*
* //******************************************************************
* //
* // Copyright 2015 Intel Corporation.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
* //
* // 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.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
#include "JniEntityHandler.h"
#include "JniOcResourceRequest.h"
#include "JniOcResourceResponse.h"
#include "JniUtils.h"
JniEntityHandler::JniEntityHandler(JNIEnv *env, jobject entityHandler)
{
m_jListener = env->NewGlobalRef(entityHandler);
}
JniEntityHandler::~JniEntityHandler()
{
LOGD("~JniEntityHandler");
if (m_jListener)
{
jint ret;
JNIEnv *env = GetJNIEnv(ret);
if (NULL == env) return;
env->DeleteGlobalRef(m_jListener);
if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
}
}
OCEntityHandlerResult JniEntityHandler::handleEntity(const std::shared_ptr<OCResourceRequest> request)
{
LOGD("JniEntityHandler_handleEntity");
jint envRet;
JNIEnv *env = GetJNIEnv(envRet);
if (NULL == env) return OC_EH_ERROR;
JniOcResourceRequest* jniResReq = new JniOcResourceRequest(request);
jlong reqHandle = reinterpret_cast<jlong>(jniResReq);
jobject jResourceRequest = env->NewObject(g_cls_OcResourceRequest, g_mid_OcResourceRequest_N_ctor,
reqHandle);
if (!jResourceRequest)
{
LOGE("Failed to create OcResourceRequest");
delete jniResReq;
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jclass clsL = env->GetObjectClass(m_jListener);
if (!clsL)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jmethodID midL = env->GetMethodID(clsL, "handleEntity",
"(Lorg/iotivity/base/OcResourceRequest;)Lorg/iotivity/base/EntityHandlerResult;");
if (!midL)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jobject entityHandlerResult = env->CallObjectMethod(m_jListener, midL, jResourceRequest);
if (env->ExceptionCheck())
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
if (!entityHandlerResult)
{
ThrowOcException(JNI_INVALID_VALUE, "EntityHandlerResult cannot be null");
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jclass clsResult = env->GetObjectClass(entityHandlerResult);
if (!clsResult)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jmethodID getValue_ID = env->GetMethodID(clsResult, "getValue", "()I");
if (!getValue_ID)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jint jResult = env->CallIntMethod(entityHandlerResult, getValue_ID);
if (env->ExceptionCheck())
{
LOGE("Java exception is thrown");
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return JniUtils::getOCEntityHandlerResult(env, static_cast<int>(jResult));
/*
* //******************************************************************
* //
* // Copyright 2015 Intel Corporation.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
* //
* // 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.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
#include "JniEntityHandler.h"
#include "JniOcResourceRequest.h"
#include "JniOcResourceResponse.h"
#include "JniUtils.h"
JniEntityHandler::JniEntityHandler(JNIEnv *env, jobject entityHandler)
{
m_jListener = env->NewGlobalRef(entityHandler);
}
JniEntityHandler::~JniEntityHandler()
{
LOGD("~JniEntityHandler");
if (m_jListener)
{
jint ret;
JNIEnv *env = GetJNIEnv(ret);
if (NULL == env) return;
env->DeleteGlobalRef(m_jListener);
if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
}
}
OCEntityHandlerResult JniEntityHandler::handleEntity(const std::shared_ptr<OCResourceRequest> request)
{
LOGD("JniEntityHandler_handleEntity");
jint envRet;
JNIEnv *env = GetJNIEnv(envRet);
if (NULL == env) return OC_EH_ERROR;
JniOcResourceRequest* jniResReq = new JniOcResourceRequest(request);
jlong reqHandle = reinterpret_cast<jlong>(jniResReq);
jobject jResourceRequest = env->NewObject(g_cls_OcResourceRequest, g_mid_OcResourceRequest_N_ctor,
reqHandle);
if (!jResourceRequest)
{
LOGE("Failed to create OcResourceRequest");
delete jniResReq;
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jclass clsL = env->GetObjectClass(m_jListener);
if (!clsL)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jmethodID midL = env->GetMethodID(clsL, "handleEntity",
"(Lorg/iotivity/base/OcResourceRequest;)Lorg/iotivity/base/EntityHandlerResult;");
if (!midL)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jobject entityHandlerResult = env->CallObjectMethod(m_jListener, midL, jResourceRequest);
if (env->ExceptionCheck())
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
if (!entityHandlerResult)
{
ThrowOcException(JNI_INVALID_VALUE, "EntityHandlerResult cannot be null");
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jclass clsResult = env->GetObjectClass(entityHandlerResult);
if (!clsResult)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jmethodID getValue_ID = env->GetMethodID(clsResult, "getValue", "()I");
if (!getValue_ID)
{
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
jint jResult = env->CallIntMethod(entityHandlerResult, getValue_ID);
if (env->ExceptionCheck())
{
LOGE("Java exception is thrown");
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return OC_EH_ERROR;
}
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
return JniUtils::getOCEntityHandlerResult(env, static_cast<int>(jResult));
}
\ No newline at end of file
/*
* //******************************************************************
* //
* // Copyright 2015 Intel Corporation.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
* //
* // 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.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
#include "JniOcStack.h"
#ifndef _Included_org_iotivity_base_JniEntityHandler
#define _Included_org_iotivity_base_JniEntityHandler
class JniEntityHandler
{
public:
JniEntityHandler(JNIEnv *env, jobject listener);
~JniEntityHandler();
OCEntityHandlerResult handleEntity(const std::shared_ptr<OC::OCResourceRequest> request);
private:
jobject m_jListener;
};
/*
* //******************************************************************
* //
* // Copyright 2015 Intel Corporation.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
* //
* // 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.
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
#include "JniOcStack.h"
#ifndef _Included_org_iotivity_base_JniEntityHandler
#define _Included_org_iotivity_base_JniEntityHandler
class JniEntityHandler
{
public:
JniEntityHandler(JNIEnv *env, jobject listener);
~JniEntityHandler();
OCEntityHandlerResult handleEntity(const std::shared_ptr<OC::OCResourceRequest> request);
private:
jobject m_jListener;
};
#endif
\ No newline at end of file
///*
//* //******************************************************************
//* //
//* // Copyright 2015 Intel Corporation.
//* //
//* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//* //
//* // 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.
//* //
//* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//*/
//
//#include "JniListenerManager.h"
//
//#include "JniOnGetListener.h"
//
//template<class T>
//T* JniListenerManager<T>::addListener(JNIEnv* env, jobject jListener)
//{
// T *onEventListener = NULL;
//
// m_mapMutex.lock();
//
// for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
// {
// if (env->IsSameObject(jListener, it->first))
// {
// auto refPair = it->second;
// onEventListener = refPair.first;
// refPair.second++;
// it->second = refPair;
// m_listenerMap.insert(*it);
// LOGD("OnEventListener: ref. count is incremented");
// break;
// }
// }
//
// if (!onEventListener)
// {
// onEventListener = new T(env, jListener, this);
// jobject jgListener = env->NewGlobalRef(jListener);
//
// m_listenerMap.insert(std::pair<jobject, std::pair<T*, int>>(jgListener, std::pair<T*, int>(onEventListener, 1)));