[jboss-cvs] JBossAS SVN: r95700 - in projects/ejb3/trunk/package-manager/src: main/java/org/jboss/ejb3/packagemanager/impl and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 28 14:14:06 EDT 2009
Author: jaikiran
Date: 2009-10-28 14:14:06 -0400 (Wed, 28 Oct 2009)
New Revision: 95700
Modified:
projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/db/DefaultDatabaseManager.java
projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/impl/DefaultPackageManagerImpl.java
projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/main/Main.java
projects/ejb3/trunk/package-manager/src/test/java/org/jboss/ejb3/packagemanager/test/commandline/unit/CommandLineTestCase.java
Log:
EJBTHREE-1942 Minor changes to implementation and a few more tests added. Docs to be updated next
Modified: projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/db/DefaultDatabaseManager.java
===================================================================
--- projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/db/DefaultDatabaseManager.java 2009-10-28 18:06:43 UTC (rev 95699)
+++ projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/db/DefaultDatabaseManager.java 2009-10-28 18:14:06 UTC (rev 95700)
@@ -302,7 +302,6 @@
try
{
installedPackage = em.merge(installedPackage);
- logger.info("Deleting installed package = " + installedPackage.getId());
em.remove(installedPackage);
tx.commit();
logger.info("Deleted installed package = " + installedPackage.getId());
Modified: projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/impl/DefaultPackageManagerImpl.java
===================================================================
--- projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/impl/DefaultPackageManagerImpl.java 2009-10-28 18:06:43 UTC (rev 95699)
+++ projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/impl/DefaultPackageManagerImpl.java 2009-10-28 18:14:06 UTC (rev 95700)
@@ -201,8 +201,8 @@
}
// post-installation step
this.postInstallPackage(pkgContext);
+ this.pkgDatabaseManager.installPackage(pkgContext);
logger.info("Installed " + pkgContext);
- this.pkgDatabaseManager.installPackage(pkgContext);
}
/**
@@ -212,6 +212,7 @@
public void removePackage(String packageName) throws PackageNotInstalledException, PackageManagerException
{
this.removePackage(packageName, false);
+ logger.info("Uninstalled " + packageName);
}
Modified: projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/main/Main.java
===================================================================
--- projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/main/Main.java 2009-10-28 18:06:43 UTC (rev 95699)
+++ projects/ejb3/trunk/package-manager/src/main/java/org/jboss/ejb3/packagemanager/main/Main.java 2009-10-28 18:14:06 UTC (rev 95700)
@@ -30,7 +30,9 @@
/**
* Main
- *
+ *
+ * TODO: This needs a lot of rework - currently WIP.
+ *
* @author Jaikiran Pai
* @version $Revision: $
*/
@@ -45,55 +47,62 @@
* TODO: The command line arguments, haven't yet been finalized
*
* @param args
+ * @throws PackageManagerException
*/
- public static void main(String[] args)
+ public static void main(String[] args) throws PackageManagerException
{
- Getopt getOpt = new Getopt("packagemanager", args, "i:u:e:s:p:");
- int opt;
- String packageFilePath = null;
+
+ Getopt arguments = new Getopt("packagemanager", args, "i:u:r:s:p:");
+ int argument;
String jbossHome = null;
- String packageNameToUninstall = null;
String pmHome = System.getProperty("java.io.tmpdir");
- while ((opt = getOpt.getopt()) != -1)
+ // TODO: Better handling of commands/options
+ while ((argument = arguments.getopt()) != -1)
{
- switch (opt)
+ switch (argument)
{
- case 'i' :
- packageFilePath = getOpt.getOptarg();
- break;
- case 'u' :
- packageFilePath = getOpt.getOptarg();
- break;
- case 'e' :
- packageNameToUninstall = getOpt.getOptarg();
- break;
case 's' :
- jbossHome = getOpt.getOptarg();
+ jbossHome = arguments.getOptarg();
break;
case 'p' :
- pmHome = getOpt.getOptarg();
+ pmHome = arguments.getOptarg();
break;
- default :
- throw new Error("Unhandled code " + opt);
}
}
- if (jbossHome == null || packageFilePath == null)
+
+ if (jbossHome == null)
{
- throw new Error("JBoss home or package file not specified");
+ throw new Error("JBoss Server Home not specified");
}
PackageManagerEnvironment env = new PackageManagerEnvironment(pmHome);
PackageManager pm = new DefaultPackageManagerImpl(env, jbossHome);
-
- // install the package
- try
+
+ Getopt commands = new Getopt("packagemanager", args, "i:u:r:s:p:");
+ int command;
+ String packageToOperateOn = null;
+ // TODO: Better handling of commands/options
+ while ((command = commands.getopt()) != -1)
{
- pm.installPackage(packageFilePath);
+ switch (command)
+ {
+ case 'i' :
+ packageToOperateOn = commands.getOptarg();
+ pm.installPackage(packageToOperateOn);
+ break;
+ case 'u' :
+ packageToOperateOn = commands.getOptarg();
+ pm.updatePackage(packageToOperateOn);
+ break;
+ case 'r' :
+ packageToOperateOn = commands.getOptarg();
+ pm.removePackage(packageToOperateOn);
+ break;
+ }
}
- catch (PackageManagerException ie)
- {
- throw new RuntimeException(ie);
- }
+
}
+
+
}
Modified: projects/ejb3/trunk/package-manager/src/test/java/org/jboss/ejb3/packagemanager/test/commandline/unit/CommandLineTestCase.java
===================================================================
--- projects/ejb3/trunk/package-manager/src/test/java/org/jboss/ejb3/packagemanager/test/commandline/unit/CommandLineTestCase.java 2009-10-28 18:06:43 UTC (rev 95699)
+++ projects/ejb3/trunk/package-manager/src/test/java/org/jboss/ejb3/packagemanager/test/commandline/unit/CommandLineTestCase.java 2009-10-28 18:14:06 UTC (rev 95700)
@@ -25,10 +25,12 @@
import org.jboss.ejb3.packagemanager.PackageManager;
import org.jboss.ejb3.packagemanager.PackageManagerEnvironment;
+import org.jboss.ejb3.packagemanager.exception.PackageNotInstalledException;
import org.jboss.ejb3.packagemanager.impl.DefaultPackageManagerImpl;
import org.jboss.ejb3.packagemanager.main.Main;
import org.jboss.ejb3.packagemanager.test.common.PackageManagerTestCase;
import org.jboss.logging.Logger;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -72,7 +74,7 @@
}
/**
- * Test that the command line variant of the package manager works as expected.
+ * Test that the install operation from the command line works as expected.
*
* TODO: Note that the params passed through the command line are still work-in-progress
* and they might change in future. This test case then needs to change appropriately.
@@ -80,7 +82,7 @@
* @throws Exception
*/
@Test
- public void testMainMethodOfDefaultPackageManager() throws Exception
+ public void testInstall() throws Exception
{
File commandLineTestPackage = this.createSimplePackage("command-line-test-package.jar");
@@ -95,4 +97,80 @@
this.assertFileExistenceUnderJBossHome(this.jbossHome, "common/lib/dummy.jar");
}
+
+ /**
+ * Test that the uninstall operation from the command line works as expected.
+ *
+ * TODO: Note that the params passed through the command line are still work-in-progress
+ * and they might change in future. This test case then needs to change appropriately.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testUnInstallOfNonExistentPackage() throws Exception
+ {
+ // test that non-existent package uninstallation is not allowed
+
+ String commandLineArgs[] = new String[]
+ {"-r", "blahblahblah", "-p", this.pkgMgrHome.getAbsolutePath(), "-s", this.jbossHome.getAbsolutePath()};
+ File commandLineTestPackage = this.createSimplePackage("command-line-test-package.jar");
+
+ // run the package manager
+ try
+ {
+ Main.main(commandLineArgs);
+ Assert
+ .fail("Uninstallation of non-existent package did not throw any errors. Expected package manager to throw error");
+ }
+ catch (PackageNotInstalledException pnie)
+ {
+ // expected
+ }
+
+ }
+
+ /**
+ * Test that the uninstall operation from the command line works as expected.
+ *
+ * TODO: Note that the params passed through the command line are still work-in-progress
+ * and they might change in future. This test case then needs to change appropriately.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testUnInstall() throws Exception
+ {
+ // first install and then uninstall
+ File packageWithScripts = this.createPackageWithPreInstallScript("commandline-uninstall-test-package.jar");
+ // test that non-existent package uninstallation is not allowed
+
+ String commandLineArgs[] = new String[]
+ {"-i", packageWithScripts.toURI().toURL().toExternalForm(), "-p", this.pkgMgrHome.getAbsolutePath(), "-s",
+ this.jbossHome.getAbsolutePath()};
+
+ // run the package manager
+ Main.main(commandLineArgs);
+
+ // do a simple test that the package was installed
+ this.assertFileExistenceUnderJBossHome(this.jbossHome, "server/default/deploy/dummy.jar");
+
+ // now uninstall
+ commandLineArgs = new String[]
+ {"-r", "common-package-with-pre-install", "-p", this.pkgMgrHome.getAbsolutePath(), "-s",
+ this.jbossHome.getAbsolutePath()};
+
+ // run the package manager
+ Main.main(commandLineArgs);
+
+ // now test that the files were uninstalled
+ this.assertFileAbsenceUnderJBossHome(jbossHome, "server/default/deploy/dummy.jar");
+
+ // Remember that the JBOSS_HOME/bin/test.txt file was created
+ // by an script and was NOT included as an installation file (i.e. through
+ // "file" element in the package.xml). Such files are NOT tracked/controlled
+ // by the package manager and hence will not be touched on uninstallation
+ // (unless ofcourse, the post/pre uninstall scripts take care of these files)
+ this.assertFileExistenceUnderJBossHome(jbossHome, "bin/test.txt");
+
+ }
}
More information about the jboss-cvs-commits
mailing list