javaobjective-ciosxcodebash

Error with bash script "exit code 126"


I want integrate CPD (Copy-Paste-Detection) to my iOS project. I read about it here and here.

To automatically determine CopyPaste in the code I'm using bash script:

echo "Checking files in ${SOURCE_ROOT}"
JARS_DIR=${PROJECT_DIR}/CPD
FULL_PATH_TO_CPD_XML_OUTPUT=${PROJECT_DIR}/cpd-output.xml

# Running CPD
java -classpath "${JARS_DIR}/ObjCLanguage-0.0.5-SNAPSHOT.jar:${JARS_DIR}/pmd.jar" net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files "${SOURCE_ROOT}" -v --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > "${FULL_PATH_TO_CPD_XML_OUTPUT}"

# Running self :)
${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

That code create cpd-output.xml file. But take me an error at compile time "Command /bin/sh failed with exit code 126". Here is log copy http://pastebin.com/359k1Wni I took the code from this example project Error is going then I comment this string:

${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

I tried to find what ever information about this error, but found only a few of these problems without answers. I'm not know anything about bash scripting. I will be happy with any advice. Thank you for your attention.

P.S. Author of following the script written:

In order to integrate XCode and the CPD, we will add to the Build Phases target with the project, Run Script phase, conventionally consisting of several parts: Actually calling cpd Parsing cpd-output.xml Output in the "right format"


Solution

  • The problem was in the wrong script. I give a revised script, which logs have been added:

    echo "Checking files in ${SOURCE_ROOT}"
    CPD_DIR=${PROJECT_DIR}/CPD
    JARS_DIR=${PROJECT_DIR}/CPD
    FULL_PATH_TO_CPD_XML_OUTPUT=${PROJECT_DIR}/cpd-output.xml
    OBJC_JAR_LIBRARY=${JARS_DIR}/ObjCLanguage-0.0.5-SNAPSHOT.jar
    
    echo [DEBUG] CPD_DIR = ${CPD_DIR}
    echo [DEBUG] JARS_DIR = ${JARS_DIR}
    echo [DEBUG] FULL_PATH_TO_CPD_XML_OUTPUT = ${FULL_PATH_TO_CPD_XML_OUTPUT}
    echo [DEBUG] OBJC_JAR_LIBRARY = ${OBJC_JAR_LIBRARY}
    echo [DEBUG] SOURCE_ROOT = ${SOURCE_ROOT}
    
    # Running CPD
    java -classpath "${OBJC_JAR_LIBRARY}:${JARS_DIR}/pmd.jar" net.sourceforge.pmd.cpd.CPD --minimum-tokens 200 --files "${SOURCE_ROOT}" -v --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > "${FULL_PATH_TO_CPD_XML_OUTPUT}"
    
    CPD_EXECUTABLE="${CPD_DIR}/CPDObjective-C"
    if [ ! -f "${CPD_EXECUTABLE}" ];
    then
    echo "CPD executable file is not found: " ${CPD_EXECUTABLE}
    fi
    echo "Running ${CPD_EXECUTABLE} -cpd-xml ${FULL_PATH_TO_CPD_XML_OUTPUT}"
    "${CPD_EXECUTABLE}" -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"
    

    Here is source code of sample Copy-Paste-Detect