Skip to content

Commit

Permalink
Switch to OSGi annotations and bnd-maven-plugin (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert authored Mar 18, 2024
1 parent dc4987c commit df24a3a
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# #%L
# wcm.io
# %%
# Copyright (C) 2021 wcm.io
# %%
# 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.
# #L%

# Builds the application, deploys it to local author, and then deploys it to local publish as well (without building it again)
# Deployment to author and publish runs in parallel

# Display a pause message (only when the script was executed via double-click on windows)
pause_message() {
if [ "$DISPLAY_PAUSE_MESSAGE_WRAPPER" = true ]; then
echo ""
read -n1 -r -p "Press any key to continue..."
fi
}

if [[ $0 == *":\\"* ]]; then
DISPLAY_PAUSE_MESSAGE_WRAPPER=true
fi

# Build application
./build-deploy.sh build --maven.profiles=fast "$@"
if [ "$?" -ne "0" ]; then
pause_message
exit $?
fi

# Deploy to author (in parallel)
./build-deploy.sh deploy --maven.profiles=fast --conga.node=aem-author "$@" &

# Deploy to publish (in parallel)
./build-deploy.sh deploy --maven.profiles=fast,publish --conga.node=aem-publish "$@" &

wait
pause_message
8 changes: 4 additions & 4 deletions examples/aem-caravan-jaxrs-sample/build-deploy-publish.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
#!/bin/bash
# #%L
# wcm.io
# %%
# Copyright (C) 2017 wcm.io
# Copyright (C) 2017 - 2021 wcm.io
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,11 +19,11 @@

# Call with "help" parameter to display syntax information

SLING_URL="http://localhost:4503"
MAVEN_PROFILES="fast,publish"
CONGA_NODE="aem-publish"

if [[ $0 == *":\\"* ]]; then
DISPLAY_PAUSE_MESSAGE=true
fi

./build-deploy.sh --sling.url=${SLING_URL} --conga.node=${CONGA_NODE} --display.pause.message=${DISPLAY_PAUSE_MESSAGE} "$@"
./build-deploy.sh --maven.profiles=${MAVEN_PROFILES} --conga.node=${CONGA_NODE} --display.pause.message=${DISPLAY_PAUSE_MESSAGE} "$@"
126 changes: 75 additions & 51 deletions examples/aem-caravan-jaxrs-sample/build-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
#!/bin/bash
# #%L
# wcm.io
# %%
# Copyright (C) 2017 wcm.io
# Copyright (C) 2017 - 2022 wcm.io
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,11 @@
# Call with "help" parameter to display syntax information

# defaults
SLING_URL="http://localhost:4502"
SLING_USER="admin"
SLING_PASSWORD="admin"
CONGA_ENVIRONMENT="development"
MAVEN_PROFILES="fast"
SLING_URL=""
SLING_USER=""
SLING_PASSWORD=""
CONGA_ENVIRONMENT="local"
CONGA_NODE="aem-author"
JVM_ARGS=""

Expand All @@ -36,19 +37,18 @@ DEPLOY=false
HELP=false
DEFAULT_COMMANDS=true

####

help_message_exit() {
echo ""
echo " Syntax <parameters> <commands>"
echo ""
echo " Parameters:"
echo " --sling.url=${SLING_URL}"
echo " --sling.user=${SLING_USER}"
echo " --sling.password=${SLING_PASSWORD}"
echo " --conga.environment=${CONGA_ENVIRONMENT}"
echo " --conga.node=${CONGA_NODE}"
echo " --jvm.args=${JVM_ARGS}"
echo " --maven.profiles=${MAVEN_PROFILES} or -P${MAVEN_PROFILES}"
echo " --sling.url=${SLING_URL} or -Dsling.url=${SLING_URL}"
echo " --sling.user=${SLING_USER} or -Dsling.user=${SLING_USER}"
echo " --sling.password=${SLING_PASSWORD} or -Dsling.password=${SLING_PASSWORD}"
echo " --conga.environment=${CONGA_ENVIRONMENT} or -Dconga.environment=${CONGA_ENVIRONMENT}"
echo " --conga.node=${CONGA_NODE} or -Dconga.node=${CONGA_NODE}"
echo " --jvm.args=${JVM_ARGS} or -Djvm.args=${JVM_ARGS}"
echo ""
echo " Commands:"
echo " build - Clean and install maven project"
Expand All @@ -64,6 +64,10 @@ parse_parameters() {
for i in "$@"
do
case $i in
--maven\.profiles=*|-P*)
MAVEN_PROFILES="${i#*=}"
shift # past argument=value
;;
--sling\.url=*|-Dsling\.url=*)
SLING_URL="${i#*=}"
shift # past argument=value
Expand Down Expand Up @@ -119,83 +123,102 @@ parse_parameters() {
}

welcome_message() {
echo -e "********************************************************************\e[96m"
echo "********************************************************************"
if ([ "$BUILD" = true ] && [ "$DEPLOY" = true ]) || [ "$HELP" = true ]; then
echo " ___ _ _ ___ _ ___ _ ___ ___ ___ _ _____ __"
echo " | _ ) | | |_ _| | | \ _| |_ | \| __| _ \ | / _ \ \ / /"
echo " | _ \ |_| || || |__| |) | |_ _| | |) | _|| _/ |_| (_) \ V /"
echo " |___/\___/|___|____|___/ |_| |___/|___|_| |____\___/ |_|"
echo -e "\e[96m ___ _ _ ___ _ ___ _ ___ ___ ___ _ _____ __\e[0m"
echo -e "\e[96m | _ ) | | |_ _| | | \ _| |_ | \| __| _ \ | / _ \ \ / /\e[0m"
echo -e "\e[96m | _ \ |_| || || |__| |) | |_ _| | |) | _|| _/ |_| (_) \ V /\e[0m"
echo -e "\e[96m |___/\___/|___|____|___/ |_| |___/|___|_| |____\___/ |_|\e[0m"
elif [ "$BUILD" = true ]; then
echo " ___ _ _ ___ _ ___ "
echo " | _ ) | | |_ _| | | \\"
echo " | _ \ |_| || || |__| |) |"
echo " |___/\___/|___|____|___/"
echo -e "\e[96m ___ _ _ ___ _ ___ \e[0m"
echo -e "\e[96m | _ ) | | |_ _| | | \\ \e[0m"
echo -e "\e[96m | _ \ |_| || || |__| |) |\e[0m"
echo -e "\e[96m |___/\___/|___|____|___/\e[0m"
elif [ "$DEPLOY" = true ]; then
echo " ___ ___ ___ _ _____ __"
echo " | \| __| _ \ | / _ \ \ / /"
echo " | |) | _|| _/ |_| (_) \ V /"
echo " |___/|___|_| |____\___/ |_|"
echo -e "\e[96m ___ ___ ___ _ _____ __\e[0m"
echo -e "\e[96m | \| __| _ \ | / _ \ \ / /\e[0m"
echo -e "\e[96m | |) | _|| _/ |_| (_) \ V /\e[0m"
echo -e "\e[96m |___/|___|_| |____\___/ |_|\e[0m"
fi
echo -e "\e[0m"
echo -e " Destination: \e[1m${SLING_URL}\e[0m (\e[1m${CONGA_NODE}\e[0m)"
echo ""
echo -e " Destination: \e[1m${CONGA_NODE}\e[0m (${MAVEN_PROFILES})"
echo ""
echo "********************************************************************"
}

completion_message() {
ELAPSED_TIME=$(($SECONDS - $START_TIME))
TOTAL_TIME="($(($ELAPSED_TIME/60)):$(printf "%02d" $(($ELAPSED_TIME%60))) min)"

echo ""
if [ "$BUILD" = true ] && [ "$DEPLOY" = true ]; then
echo -e "*** \e[1mBuild+Deploy complete\e[0m ***"
echo -e "*** \e[1mBuild+Deploy complete\e[0m $TOTAL_TIME ***"
elif [ "$BUILD" = true ]; then
echo -e "*** \e[1mBuild complete\e[0m ***"
echo -e "*** \e[1mBuild complete\e[0m $TOTAL_TIME ***"
elif [ "$DEPLOY" = true ]; then
echo -e "*** \e[1mDeploy complete\e[0m ***"
echo -e "*** \e[1mDeploy complete\e[0m $TOTAL_TIME ***"
fi
echo ""

pause_message
}

####

execute_build() {
echo ""
echo -e "*** \e[1mBuild application\e[0m ***"
echo ""

mvn ${JVM_ARGS} \
-Dconga.environments=${CONGA_ENVIRONMENT} \
-Pfast clean install eclipse:eclipse

MAVEN_ARGS=""
if [ -n "$JVM_ARGS" ]; then
MAVEN_ARGS+="${JVM_ARGS} "
fi
if [ -n "${MAVEN_PROFILES}" ]; then
MAVEN_ARGS+="--activate-profiles ${MAVEN_PROFILES} "
fi
if [ -n "${CONGA_ENVIRONMENT}" ]; then
MAVEN_ARGS+="-Dconga.environments=${CONGA_ENVIRONMENT} "
fi

mvn $MAVEN_ARGS clean install eclipse:eclipse

if [ "$?" -ne "0" ]; then
exit_with_error "*** BUILD FAILED ***"
fi
}

####

execute_deploy() {
echo ""
echo -e "*** \e[1mDeploy to AEM\e[0m ***"
echo ""

mvn -f config-definition \
${JVM_ARGS} \
-Dconga.environments=${CONGA_ENVIRONMENT} \
-Dconga.nodeDirectory=target/configuration/${CONGA_ENVIRONMENT}/${CONGA_NODE} \
-Dsling.url=${SLING_URL} \
-Dsling.user=${SLING_USER} \
-Dsling.password=${SLING_PASSWORD} \
conga-aem:package-install
MAVEN_ARGS=""
if [ -n "$JVM_ARGS" ]; then
MAVEN_ARGS+="${JVM_ARGS} "
fi
if [ -n "${MAVEN_PROFILES}" ]; then
MAVEN_ARGS+="--activate-profiles=${MAVEN_PROFILES} "
fi
if [ -n "${CONGA_ENVIRONMENT}" ] && [ -n "${CONGA_NODE}" ]; then
MAVEN_ARGS+="-Dconga.environments=${CONGA_ENVIRONMENT} -Dconga.nodeDirectory=target/configuration/${CONGA_ENVIRONMENT}/${CONGA_NODE} "
fi
if [ -n "${SLING_URL}" ]; then
MAVEN_ARGS+="-Dsling.url=${SLING_URL} "
fi
if [ -n "${SLING_USER}" ]; then
MAVEN_ARGS+="-Dsling.user=${SLING_USER} "
fi
if [ -n "${SLING_PASSWORD}" ]; then
MAVEN_ARGS+="-Dsling.password=${SLING_PASSWORD} "
fi

mvn $MAVEN_ARGS -f config-definition conga-aem:package-install

if [ "$?" -ne "0" ]; then
exit_with_error "*** DEPLOY FAILED ***"
fi

}

####

# Display a pause message (only when the script was executed via double-click on windows)
pause_message() {
if [ "$DISPLAY_PAUSE_MESSAGE" = true ]; then
Expand All @@ -212,7 +235,8 @@ exit_with_error() {
exit 1
}

####

START_TIME=$SECONDS

parse_parameters "$@"
welcome_message
Expand Down
3 changes: 0 additions & 3 deletions examples/aem-caravan-jaxrs-sample/config-definition/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@
<goals>
<goal>generate</goal>
</goals>
<configuration>
<environmentDir>${basedir}/src/main/dev-environments</environmentDir>
</configuration>
</execution>

</executions>
Expand Down
4 changes: 2 additions & 2 deletions examples/aem-caravan-jaxrs-sample/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.12.0</version>
<version>5.11.0</version>
</dependency>

</dependencies>
Expand Down
21 changes: 15 additions & 6 deletions integration-test/sample-service-1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<groupId>io.wcm.caravan</groupId>
<artifactId>io.wcm.caravan.jaxrs.integration-test.sample-service-1</artifactId>
<version>1-SNAPSHOT</version>
<packaging>bundle</packaging>
<packaging>jar</packaging>

<name>JAX-RS Integration Test Sample Service 1</name>

Expand All @@ -51,12 +51,21 @@
<plugins>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<configuration>
<instructions>
<Caravan-JaxRs-ApplicationPath>/caravan/jaxrs/test/sampleservice1</Caravan-JaxRs-ApplicationPath>
</instructions>
<bnd>
Caravan-JaxRs-ApplicationPath: /caravan/jaxrs/test/sampleservice1
</bnd>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ServiceScope;

import io.wcm.caravan.jaxrs.publisher.ApplicationPath;
import io.wcm.caravan.jaxrs.publisher.JaxRsComponent;

/**
* Sample JAX-RS Service that is registered to all JAX-RS appliations in the OSGi container.
*/
@Component
@Service(value = JaxRsComponent.class, serviceFactory = true)
@Property(name = JaxRsComponent.PROPERTY_GLOBAL_COMPONENT, value = "true")
@Component(
service = JaxRsComponent.class,
scope = ServiceScope.BUNDLE,
property = JaxRsComponent.PROPERTY_GLOBAL_COMPONENT + "=true")
@Path("/globalServiceId")
public class JaxRsGlobalService implements JaxRsComponent {

Expand Down
Loading

0 comments on commit df24a3a

Please sign in to comment.