Browse files

PLF-4450 : Use a groovy script to manage PLF Extensions

  • Loading branch information...
1 parent 3875722 commit 65bed087e39f6c5f2d19b11bc22cb7e11e32d111 Arnaud Héritier committed Apr 10, 2013
View
1 .gitignore
@@ -39,3 +39,4 @@ pom.xml.versionsBackup
# Exclude JEnv Config File
.java-version
+dependency-reduced-pom.xml
View
2 plf-shared-assemblies/src/main/resources/assemblies/plf-copy-libraries-component.xml
@@ -93,6 +93,8 @@
<exclude>rome:modules:*</exclude>
<!-- this is a build resource -->
<exclude>org.exoplatform.resources:exo-lgpl-license-resource-bundle:*</exclude>
+ <!-- The extensions manager is a special jar deployed in the bin directory -->
+ <exclude>org.exoplatform.platform.distributions:plf-shared-tomcat-extensions-manager:*</exclude>
</excludes>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
<useProjectArtifact>false</useProjectArtifact>
View
11 ...lies/src/main/resources/assemblies/plf-standalone-default-tomcat-distribution-content.xml
@@ -175,6 +175,17 @@
</unpackOptions>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
+ <!-- eXo Platform Extensions Manager -->
+ <dependencySet>
+ <outputDirectory>/bin</outputDirectory>
+ <includes>
+ <!-- This artifact isn't by default in tomcat -->
+ <include>org.exoplatform.platform.distributions:plf-shared-tomcat-extensions-manager:jar</include>
+ </includes>
+ <scope>provided</scope>
+ <outputFileNameMapping>plf-tomcat-extensions-manager.jar</outputFileNameMapping>
+ <useProjectArtifact>false</useProjectArtifact>
+ </dependencySet>
<!-- We only authorize this additional tomcat artifact for now -->
<dependencySet>
<outputDirectory>/lib</outputDirectory>
View
120 plf-shared-tomcat-extensions-manager/pom.xml
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2003-2013 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>plf-public-distributions</artifactId>
+ <groupId>org.exoplatform.platform.distributions</groupId>
+ <version>4.0.0-plf-relooking-SNAPSHOT</version>
+ </parent>
+ <artifactId>plf-shared-tomcat-extensions-manager</artifactId>
+ <packaging>jar</packaging>
+ <name>eXo Platform Public Distributions - Shared Tomcat Extensions Manager</name>
+ <description>Command line utility to manage Platform extensions in a standalone Apache Tomcat based distribution.</description>
+ <properties>
+ <groovy-eclipse-compiler.version>2.7.0-01</groovy-eclipse-compiler.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>2.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-ant</artifactId>
+ <version>2.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!-- Required to not break gmaven usage for -Pfix-headers by example-->
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <configuration>
+ <providerSelection>2.0</providerSelection>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-eclipse-compiler</artifactId>
+ <version>${groovy-eclipse-compiler.version}</version>
+ </dependency>
+ </dependencies>
+ <configuration>
+ <compilerId>groovy-eclipse-compiler</compilerId>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-eclipse-compiler</artifactId>
+ <version>${groovy-eclipse-compiler.version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <manifestEntries>
+ <Main-Class>org.exoplatform.platform.distributions.ExtensionsManager</Main-Class>
+ <Date>${maven.build.timestamp}</Date>
+ <Implementation-URL>${project.url}</Implementation-URL>
+ <SCM-URL>${project.scm.connection}</SCM-URL>
+ <SCM-Revision>${buildNumber}</SCM-Revision>
+ <Specification-Title>${exo.product.name}</Specification-Title>
+ <Specification-Version>${parsedVersion.majorVersion}.0</Specification-Version>
+ <Specification-Vendor>${project.organization.name}</Specification-Vendor>
+ <Implementation-Title>${project.name}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
+ </manifestEntries>
+ </transformer>
+ </transformers>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
165 ...s-manager/src/main/groovy/org/exoplatform/platform/distributions/ExtensionsManager.groovy
@@ -0,0 +1,165 @@
+package org.exoplatform.platform.distributions
+/**
+ * Copyright (C) 2003-2013 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import groovy.io.FileType
+
+
+/**
+ * Command line utility to manage Platform extensions in a standalone Apache Tomcat based distribution.
+ */
+
+ant = new AntBuilder()
+
+// Computes the script extension from the OS
+scriptExtension = "sh"
+if (System.properties['os.name'].toLowerCase().contains('windows')) {
+ scriptExtension = "bat"
+}
+
+if (!System.getProperty("platform.home")) {
+ println 'error: Erroneous setup, system property platform.home not defined.'
+ System.exit 1
+}
+
+platformHome = new File(System.getProperty("platform.home"))
+
+if (!platformHome.isDirectory()) {
+ println "error: Erroneous setup, platform home directory (${platformHome}) is invalid."
+ System.exit 1
+}
+
+extensionsDirectory = new File(platformHome, "extensions")
+
+if (!extensionsDirectory.isDirectory()) {
+ println "error: Erroneous setup, extensions directory (${extensionsDirectory}) is invalid."
+ System.exit 1
+}
+
+def cli = new CliBuilder(
+ posix: false,
+ stopAtNonOption: true,
+ usage: "extension.${scriptExtension} [options]\n",
+ header: "eXo Platform Extensions Manager\n\nOptions :\n",
+ footer: '\nUse the extension "all" to install or uninstall all available extensions')
+// Create the list of options.
+cli.with {
+ h longOpt: 'help', 'Show usage information'
+ l longOpt: 'list', 'List all available extensions'
+ i longOpt: 'install', args: 1, argName: 'extension', 'Install an extension'
+ u longOpt: 'uninstall', args: 1, argName: 'extension', 'Uninstall an extension'
+}
+
+options = cli.parse(args)
+
+// Erroneous command line
+if (!options) {
+ System.exit 1
+}
+
+// Show usage text when -h or --help option is used.
+if (options.h) {
+ cli.usage()
+ System.exit 0
+}
+
+// Validate parameters constraints (only one)
+if ([options.l, options.i, options.u].findAll { it }.size() != 1) {
+ println 'error: Invalid command line parameters. You must use one and only one of these options --list, --install <extension> or --uninstall <extension>'
+ cli.usage()
+ System.exit 1
+}
+
+// Unknown parameter(s)
+if (options.arguments()) {
+ println "error: Invalid command line parameters. Unknown parameter(s) : ${options.arguments()}"
+ cli.usage()
+ System.exit 1
+}
+
+def listExtensions() {
+ println ""
+ println "Available extensions:"
+ extensionsDirectory.eachFile() { file -> println " ${file.name}" }
+ println ""
+ println "To install an extension use: "
+ println " extension.${scriptExtension} --install <extension>"
+ println ""
+ println "To install all avalaible extensions use: "
+ println " extension.${scriptExtension} --install all"
+}
+
+def installExtension(String extensionName) {
+ def extensionDirectory = new File(extensionsDirectory, extensionName);
+ if (!extensionDirectory.isDirectory()) {
+ println "error: Extension \"${extensionName}\" doesn't exist."
+ listExtensions()
+ System.exit 1
+ }
+ println "Installing ${extensionName} extension ..."
+ ant.copy(todir: "${platformHome}",
+ preservelastmodified: true,
+ verbose: true) {
+ fileset(dir: "${extensionDirectory}") {
+ include(name: "**/*.jar")
+ include(name: "**/*.war")
+ }
+ }
+ println "Done."
+}
+
+def uninstallExtension(String extensionName) {
+ def extensionDirectory = new File(extensionsDirectory, extensionName);
+ if (!extensionDirectory.isDirectory()) {
+ println "error: Extension \"${extensionName}\" doesn't exist."
+ listExtensions()
+ System.exit 1
+ }
+ println "Uninstalling ${extensionName} extension ..."
+ extensionDirectory.eachFileRecurse(FileType.FILES) { file ->
+ ant.delete(
+ file: new File(platformHome, extensionDirectory.toURI().relativize(file.toURI()).getPath()),
+ verbose: true)
+ }
+ println "Done."
+}
+
+// ListExtensions
+if (options.l) {
+ listExtensions()
+ System.exit 0
+}
+
+// InstallExtensions
+if (options.i) {
+ if ("all".equalsIgnoreCase(options.i))
+ extensionsDirectory.eachFile() { file -> installExtension file.name }
+ else
+ installExtension(options.i)
+ System.exit 0
+}
+
+// UninstallExtension
+if (options.u) {
+ if ("all".equalsIgnoreCase(options.u))
+ extensionsDirectory.eachFile() { file -> uninstallExtension file.name }
+ else
+ uninstallExtension(options.u)
+ System.exit 0
+}
View
5 plf-shared-tomcat-resources/pom.xml
@@ -71,6 +71,11 @@
<artifactId>plf-shared-tomcat-extension-crsh</artifactId>
<type>zip</type>
</dependency>
+ <!-- Extensions Manager for Tomcat distribution -->
+ <dependency>
+ <groupId>org.exoplatform.platform.distributions</groupId>
+ <artifactId>plf-shared-tomcat-extensions-manager</artifactId>
+ </dependency>
<!-- GateIn Container Integration Servlet -->
<dependency>
<groupId>org.exoplatform.platform.distributions</groupId>
View
181 plf-shared-tomcat-resources/src/main/resources/extension.sh
@@ -1,4 +1,4 @@
-#!/bin/bash -ue
+#!/bin/bash
#
# Copyright (C) 2003-2013 eXo Platform SAS.
#
@@ -23,10 +23,20 @@ echo " # eXo Platform v. ${project.version} "
echo " # Extensions Manager "
echo " # ============================ "
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false
+darwin=false
+os400=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+Darwin*) darwin=true;;
+OS400*) os400=true;;
+esac
+
# resolve links - $0 may be a softlink
PRG="$0"
-while [ -h "$PRG" ] ; do
+while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
@@ -35,159 +45,28 @@ while [ -h "$PRG" ] ; do
PRG=`dirname "$PRG"`/"$link"
fi
done
-
-PRGDIR=`dirname "$PRG"`
-
-usage(){
- echo "Usage: "`basename "$PRG"`" [action] [options]"
- echo ""
- echo " Manages eXo Platform extensions"
- echo ""
- echo "actions:"
- echo ""
- echo " list Lists all available extensions"
- echo " install all Installs all available extensions"
- echo " install <ext> Installs the extension named <ext>"
- echo " uninstall all Uninstalls all available extensions"
- echo " uninstall <ext> Uninstalls the extension named <ext>"
- echo ""
- echo "options:"
- echo ""
- echo " -h, --help This help message"
- exit 1
-}
-
-list_extensions(){
- echo "Available extensions:"
- for _dir in `ls -1 ${PRGDIR}/extensions`; do
- echo " $_dir"
- done
- echo ""
- echo "To install an extension use: "
- echo " "`basename "$PRG"`" install <ext>"
- echo ""
- echo "To install all avalaible extensions use: "
- echo " "`basename "$PRG"`" install all"
-}
-
-copy_extension(){
- local _extension=$1
- echo "Installing extension \"$_extension\" ..."
- if [ -d ${PRGDIR}/extensions/$_extension/lib/ ]; then
- for _lib in `ls -1 ${PRGDIR}/extensions/$_extension/lib/*.jar`; do
- echo -n "* Installing library "`basename $_lib`" ... "
- if [ ! -f "${PRGDIR}/lib/"`basename $_lib` ]; then
- cp $_lib ${PRGDIR}/lib
- echo "OK."
- else
- echo "SKIPPED. "`basename $_lib`" already installed."
- fi
- done
- fi
- if [ -d ${PRGDIR}/extensions/$_extension/webapps/ ]; then
- for _war in `ls -1 ${PRGDIR}/extensions/$_extension/webapps/*.war`; do
- echo -n "* Installing webapp "`basename $_war`" ... "
- if [ ! -f "${PRGDIR}/webapps/"`basename $_war` ]; then
- cp $_war ${PRGDIR}/webapps
- echo "OK."
- else
- echo "SKIPPED. "`basename $_war`" already installed."
- fi
- done
- fi
- echo "Done"
-}
-
-install_extension(){
- local _extension=$1
- if [ "$_extension" == "all" ]; then
- for _dir in `ls -1 ${PRGDIR}/extensions`; do
- copy_extension $_dir
- done
- elif [ -d ${PRGDIR}/extensions/$_extension ]; then
- copy_extension $_extension
- else
- echo "[ERROR] Extension \"$_extension\" doesn't exist !"
- echo ""
- list_extensions
- exit 1;
- fi
-}
-delete_extension(){
- local _extension=$1
- echo "Uninstalling extension \"$_extension\" ..."
- for _war in `ls -1 ${PRGDIR}/extensions/$_extension/webapps/*.war`; do
- local _file="${PRGDIR}/webapps/"`basename $_war`
- echo -n "* Deleting webapp "`basename $_war`" ... "
- if [ -f $_file ]; then
- rm $_file
- echo "OK."
- else
- echo "SKIPPED. "`basename $_war`" not installed."
- fi
- done
- echo "Done"
-}
+# Get standard environment variables
+PRGDIR=`dirname "$PRG"`
+# Only set CATALINA_HOME if not already set
+[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR" >/dev/null; pwd`
-uninstall_extension(){
- local _extension=$1
- if [ "$_extension" == "all" ]; then
- for _dir in `ls -1 ${PRGDIR}/extensions`; do
- delete_extension $_dir
- done
- elif [ -d ${PRGDIR}/extensions/$_extension ]; then
- delete_extension $_extension
+# Get standard Java environment variables
+if $os400; then
+ # -r will Only work on the os400 if the files are:
+ # 1. owned by the user
+ # 2. owned by the PRIMARY group of the user
+ # this will not work if the user belongs in secondary groups
+ . "$CATALINA_HOME"/bin/setclasspath.sh
+else
+ if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
+ . "$CATALINA_HOME"/bin/setclasspath.sh
else
- echo "[ERROR] Extension \"$_extension\" doesn't exist !"
- echo ""
- list_extensions
- exit 1;
+ echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
+ echo "This file is needed to run this program"
+ exit 1
fi
-}
-
-# no action ? provide help
-if [ $# -lt 1 ]; then
- echo "[ERROR] No action defined !"
- echo ""
- usage
- exit 1;
fi
-# Action to do
-ACTION=$1
-shift
-
-case "${ACTION}" in
- list)
- list_extensions
- exit 0
- ;;
- install)
- if [ $# -lt 1 ]; then
- echo "[ERROR] Missing extension name argument !"
- echo ""
- usage
- exit 1;
- fi
- install_extension $1
- ;;
- uninstall)
- if [ $# -lt 1 ]; then
- echo "[ERROR] Missing extension name argument !"
- echo ""
- usage
- exit 1;
- fi
- uninstall_extension $1
- ;;
- *)
- echo "[ERROR] Invalid action \"${ACTION}\""
- echo ""
- usage
- exit 1
- ;;
-esac
-
-exit 0
+eval exec \"$_RUNJAVA\" -Dplatform.home=\"$CATALINA_HOME\" -jar \"$CATALINA_HOME/bin/plf-tomcat-extensions-manager.jar\" "$@"
View
11 pom.xml
@@ -24,7 +24,7 @@
<parent>
<artifactId>maven-parent-pom</artifactId>
<groupId>org.exoplatform</groupId>
- <version>9</version>
+ <version>10-SNAPSHOT</version>
<relativePath />
</parent>
<groupId>org.exoplatform.platform.distributions</groupId>
@@ -35,9 +35,10 @@
<modules>
<module>plf-community-tomcat-standalone</module>
<module>plf-shared-assemblies</module>
- <module>plf-shared-tomcat-extension-crsh</module>
<module>plf-shared-dependencies</module>
<module>plf-shared-root-webapp</module>
+ <module>plf-shared-tomcat-extension-crsh</module>
+ <module>plf-shared-tomcat-extensions-manager</module>
<module>plf-shared-tomcat-integration-webapp</module>
<module>plf-shared-tomcat-pc-creator-listener</module>
<module>plf-shared-tomcat-resources</module>
@@ -168,6 +169,12 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
+ <!-- Extensions Manager for Tomcat distribution -->
+ <dependency>
+ <groupId>org.exoplatform.platform.distributions</groupId>
+ <artifactId>plf-shared-tomcat-extensions-manager</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.exoplatform.platform.distributions</groupId>
<artifactId>plf-shared-tomcat-integration-webapp</artifactId>

0 comments on commit 65bed08

Please sign in to comment.