Verified Commit 9a21f60f authored by Hendrik Rombach's avatar Hendrik Rombach
Browse files

Merge branch '32210' into 3.0

parents cc193f90 3e1027ff
PLUGIN_NAME="NetiGoogleSdk"
#EXCLUDES=( "exclude dir" "exclude file" )
#PLUGINS_BUILD=( "npm-install" "npm-build" )
#PLUGINS_DIST=( "detect-license-check" )
#NPM_INSTALL=( "npm app dir" )
#NPM_BUILD=( "npm app dir" )
\ No newline at end of file
......@@ -21,4 +21,8 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties
/vendor
\ No newline at end of file
/vendor
/.build/plugins/
/.build/tmp/
/.build/update/
build:
nodes:
analysis:
dependencies:
before:
- git clone ssh://git@gitlab.netinventors.de:2202/shopware/plugins/NetiFoundation.git
environment:
php:
version: 5.6.16
filter:
dependency_paths:
- "NetiFoundation/*"
checks:
php:
code_rating: true
duplication: true
\ No newline at end of file
......@@ -12,8 +12,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
class NetiGoogleSdk extends Plugin
{
const MINIMUM_SDK_VERSION = "2.0.0";
const BREAKING_SDK_VERSION = "2.1.0";
public const MINIMUM_SDK_VERSION = '2.0.0';
public const BREAKING_SDK_VERSION = '2.1.0';
public function build(ContainerBuilder $container)
{
......
......@@ -39,9 +39,10 @@ class GoogleSdkFactory
* @param string|null $cacheKey
*
* @return \Google_Client
* @throws \NetiGoogleSdk\Exceptions\GoogleSdkFactoryException
*
* @throws GoogleSdkFactoryException
*/
public function getClient($applicationName, $developerKey, array $config = [], $cacheKey = null)
public function getClient($applicationName, $developerKey, array $config = [], $cacheKey = null): \Google_Client
{
$this->loadLibrary();
......@@ -50,7 +51,7 @@ class GoogleSdkFactory
'developer_key' => $developerKey,
];
$cacheKey = (null === $cacheKey) ? $developerKey : $cacheKey;
$cacheKey = $cacheKey ?? $developerKey;
$client = self::$clients[$cacheKey];
......@@ -63,21 +64,20 @@ class GoogleSdkFactory
/**
* @return bool
*
* @throws GoogleSdkFactoryException
*/
private function loadLibrary()
private function loadLibrary(): bool
{
if (!class_exists('Google_Client')) {
require_once $this->vendorPath . '/autoload.php';
} else {
if (!$this->assertCompatible()) {
throw new GoogleSdkFactoryException(
sprintf(
'Loaded Google Client version "%s" is incompatible with required version "%s".',
\Google_Client::LIBVER, NetiGoogleSdk::MINIMUM_SDK_VERSION
)
);
}
} elseif (!$this->assertCompatible()) {
throw new GoogleSdkFactoryException(
sprintf(
'Loaded Google Client version "%s" is incompatible with required version "%s".',
\Google_Client::LIBVER, NetiGoogleSdk::MINIMUM_SDK_VERSION
)
);
}
return true;
......@@ -86,7 +86,7 @@ class GoogleSdkFactory
/**
* @return bool
*/
private function assertCompatible()
private function assertCompatible(): bool
{
return (
version_compare(\Google_Client::LIBVER, NetiGoogleSdk::MINIMUM_SDK_VERSION, '>=') &&
......
#!/bin/bash
WORKING_DIR=$(dirname $0)
PLUGIN_NAME=$(basename ${WORKING_DIR})
VERSION=$(php -r "echo preg_replace('/.*<version>([^<]+)<\/version>.*/ims', '\\1', file_get_contents('${WORKING_DIR}/plugin.xml'), 1);")
TEMP_DIR='/tmp/ShopwarePlugins/'${PLUGIN_NAME}
SCRIPT_VERSION='3.1.0'
CURRENT_DIR=$(pwd)
EXCLUDES="sftp-config.json nbproject .idea composer.json composer.lock"
WORKING_DIR=$(cd $(dirname $0) && pwd)
BUILD_DIR="${WORKING_DIR}/.build"
PLUGIN_DIR="${BUILD_DIR}/plugins"
TEMP_DIR="${BUILD_DIR}/tmp"
UPDATE=1
PLUGIN_NAME=""
PLUGINS_BUILD=()
PLUGINS_DIST=()
TARGET_DIR=${CURRENT_DIR}
usage() {
echo "Usage: $0 [-h] [-n] [-t <string>]" 1>&2;
exit 1;
}
while getopts "hnt:" opt; do
case "${opt}" in
h)
usage
;;
n)
UPDATE=0
;;
t)
TARGET_DIR=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# Remove existing package file
if [ -f "${CURRENT_DIR}/${PLUGIN_NAME}-${VERSION}.zip" ]; then
rm "${CURRENT_DIR}/${PLUGIN_NAME}-${VERSION}.zip"
if [[ "/" != "${TARGET_DIR:0:1}" ]]; then
TARGET_DIR="${WORKING_DIR}/${TARGET_DIR}"
fi
# Create temporary build folder
mkdir -p ${TEMP_DIR}
if [[ ! -d $TARGET_DIR ]]; then
echo "ERROR: Target dir doesn't exist"
exit 2
fi
if [[ ! -w $TARGET_DIR ]]; then
echo "ERROR: Can't write to target dir"
exit 2
fi
# Copy all files from source folder to temporary folder
cp -Rp ${WORKING_DIR}/* ${TEMP_DIR}
TARGET_DIR=$(cd "${TARGET_DIR}" && pwd)
# Remove build.sh from temporary folder
rm "${TEMP_DIR}/build.sh"
cleanup() {
echo "INFO: Cleanup ${1}"
rm -Rf ${1}
}
# Remove excludes from temporary folder
for i in ${EXCLUDES}; do
if [ -e "${TEMP_DIR}/$i" ]; then
rm -R "${TEMP_DIR}/$i"
selfUpdate() {
echo "INFO: Run self update process"
UPDATE_DIR="${BUILD_DIR}/update"
git clone --quiet ssh://git@gitlab.netinventors.de:2202/shopware/build-script.git ${UPDATE_DIR}
cp -Rp ${UPDATE_DIR}/.build/plugins ${WORKING_DIR}/.build
cp -p ${UPDATE_DIR}/build.sh ${WORKING_DIR}
cleanup ${UPDATE_DIR}
}
runPlugins() {
if [[ -z ${@} ]]; then
return 0
fi
done
# Step into the temporary build folder
cd ${TEMP_DIR}
for PLUGIN in "${@}"; do
EXECUTABLE="${PLUGIN_DIR}/${PLUGIN}.sh"
if [[ -r "${EXECUTABLE}" ]]; then
echo "INFO: Run plugin ${PLUGIN}"
source "${EXECUTABLE}"
__FN="__$(sed -r 's/(\-)([a-z])/\U\2/g' <<< "${PLUGIN}")"
${__FN}
__RETURN=$?
if [[ 2 -eq ${__RETURN} ]]; then
echo "ERROR: A plugin stops the build process"
cleanup ${TEMP_DIR}
exit 2
fi
else
echo "WARNING: Plugin executable ${EXECUTABLE} not found"
fi
done
}
build() {
mkdir -p ${BUILD_DIR}
if [[ 1 -eq ${UPDATE} ]]; then
selfUpdate
bash -c "$0 -n -t \"${TARGET_DIR}\""
exit $?
fi
echo "INFO: Start build script version ${SCRIPT_VERSION}"
if [[ ! -r "${BUILD_DIR}/build.cfg" ]]; then
echo "ERROR: Unable to load build configuration file ${BUILD_DIR}/build.cfg"
exit 2
fi
# Load build configuration file
source "${BUILD_DIR}/build.cfg"
if [[ -z "${PLUGIN_NAME}" ]]; then
echo 'ERROR: Unable to resolve plugin name'
exit 2
fi
if [[ ! -r "${WORKING_DIR}/plugin.xml" ]]; then
echo "ERROR: Plugin describing file ${WORKING_DIR}/plugin.xml not found"
exit 2
fi
DIST_DIR="${BUILD_DIR}/tmp/${PLUGIN_NAME}"
VERSION=$(php -r "echo preg_replace('/.*<version>([^<]+)<\/version>.*/ims', '\\1', file_get_contents('${WORKING_DIR}/plugin.xml'), 1);")
EXCLUDES=( ".build" ".idea" "build.sh" ".git" ".gitignore" "${EXCLUDES[@]}" )
ZIP_FILE="${TARGET_DIR}/${PLUGIN_NAME}-${VERSION}.zip"
if [[ -z "$VERSION" ]]; then
echo 'ERROR: Unable to resolve plugin version from plugin.xml'
exit 2
fi
# Remove existing package file
if [[ -w "${ZIP_FILE}" ]]; then
rm "${ZIP_FILE}"
fi
if [[ -f "${ZIP_FILE}" ]]; then
echo "ERROR: Cannot override existing build file ${ZIP_FILE}"
exit 2
fi
RSYNC_EXCLUDES=( --exclude="${PLUGIN_NAME}-*.zip" )
cd ${WORKING_DIR}
runPlugins "${PLUGINS_BUILD[@]}"
for EXCLUDE in "${EXCLUDES[@]}"; do
RSYNC_EXCLUDES+=( --exclude="${EXCLUDE}" )
done
# Remove old temp dir
if [[ -d ${TEMP_DIR} ]]; then
rm -Rf ${TEMP_DIR}
fi
# Create temporary build folder
mkdir -p ${DIST_DIR}
# Copy all files from source folder to temporary folder
rsync -avzq "${RSYNC_EXCLUDES[@]}" . ${DIST_DIR}
# Step into the temporary build folder
cd ${DIST_DIR}
runPlugins "${PLUGINS_DIST[@]}"
# Replace __SECRET__ in plugin bootstrap to detect manipulations
SECRET=$(head -c 1000 /dev/urandom | tr -dc 'A-Za-z0-9%,!_;:#@' | fold -w 32 | head -n 1)
sed -i "s/__SECRET__/${SECRET}/g" "${PLUGIN_NAME}.php"
# Create md5.json file including the md5 checksum of every file in the package and the plugin __SECRET__
echo "<?php return [" > md5checksum.php
for FILE in $(find -type f -printf '%P\n'); do
echo "'${FILE}' => '$(md5sum ${FILE} | awk '{ print $1 }')'," >> md5checksum.php
done;
echo "'__SECRET__' => '${SECRET}'," >> md5checksum.php
echo "];" >> md5checksum.php
cd ${TEMP_DIR}
# Move one level up in folder structure
cd ..
# Zip temporary folder contents to package file in plugin folder
zip -qr "${ZIP_FILE}" $(basename ${DIST_DIR})
# Zip temporary folder contents to package file in plugin folder
zip -qr "${CURRENT_DIR}/${PLUGIN_NAME}-${VERSION}.zip" $(basename ${TEMP_DIR})
echo "INFO: Created build package is located in ${ZIP_FILE}"
# Step back into the current plugin folder
cd ${CURRENT_DIR}
cleanup ${TEMP_DIR}
echo "Package wurde erstellt unter ${CURRENT_DIR}/${PLUGIN_NAME}-${VERSION}.zip"
cd ${CURRENT_DIR}
}
# Remove temporary build folder
rm -R $(dirname ${TEMP_DIR})
build
......@@ -5,9 +5,6 @@
"require": {
"google/apiclient": "^2.0"
},
"require-dev": {
"shopware/shopware": "^5.2.6"
},
"config": {
"prepend-autoloader": false
},
......
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/5.5/engine/Shopware/Components/Plugin/schema/plugin.xsd">
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/5.6/engine/Shopware/Components/Plugin/schema/plugin.xsd">
<label lang="de">Google SDK</label>
<label lang="en">Google SDK</label>
<version>2.0.0</version>
<version>3.0.0</version>
<link>http://www.netinventors.de</link>
<author>Net Inventors GmbH</author>
<compatibility minVersion="5.5.0"/>
<compatibility minVersion="5.6.0" />
<changelog version="3.0.0">
<changes lang="de"><![CDATA[
[#32210] Release für SW 5.6
]]></changes>
<changes lang="en"><![CDATA[
[#32210] Release for SW 5.6
]]></changes>
</changelog>
<changelog version="2.0.0">
<changes lang="de">Release für SW 5.5</changes>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment