Permalink
Browse files

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

  • Loading branch information...
1 parent 3875722 commit 02e46f35ade3c64c7ae0f84704dcad9f8669b663 Arnaud Héritier committed Apr 10, 2013
View
@@ -39,3 +39,4 @@ pom.xml.versionsBackup
# Exclude JEnv Config File
.java-version
+dependency-reduced-pom.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>
@@ -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>
@@ -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>
@@ -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("catalina.home")) {
+ println 'error: Erroneous setup, system property catalina.home not defined.'
+ System.exit 1
+}
+
+catalinaHome = new File(System.getProperty("catalina.home"))
+
+if (!catalinaHome.isDirectory()) {
+ println "error: Erroneous setup, platform home directory (${catalinaHome}) is invalid."
+ System.exit 1
+}
+
+extensionsDirectory = new File(catalinaHome, "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: "${catalinaHome}",
+ 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(catalinaHome, 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
+}
@@ -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>
Oops, something went wrong.

0 comments on commit 02e46f3

Please sign in to comment.