}
catch (CmdLineParser.OptionException e)
{
System.err.println("Error parsing command " + e.getMessage());
printUsage();
throw new PackageManagerException(e.getMessage());
}
// get package manager home
String packageManagerHome = (String) cmdLineParser.getOptionValue(packageManagerHomeCmdOption);
if (packageManagerHome == null)
{
throw new PackageManagerException("Package manager home has not been set");
}
File pmHome = new File(packageManagerHome);
if (!pmHome.exists())
{
throw new PackageManagerException("Package manager home " + pmHome + " does not exist!");
}
logger.info("Using Package Manager Home: " + packageManagerHome);
PackageManagerEnvironment env = new PackageManagerEnvironment(packageManagerHome);
// Run the setup script
String schemaSetupScript = (String) cmdLineParser.getOptionValue(schemaFileCmdOption);
if (schemaSetupScript != null)
{
File schemaFile = new File(schemaSetupScript);
if (!schemaFile.exists())
{
throw new PackageManagerException(
"Could not setup the database for package manager, because of non-existent schema file "
+ schemaSetupScript);
}
Connection conn = null;
// We use Derby Embedded which is file based (so point to the DB home).
// TODO: This should ideally be handled by the PackageDatabaseManager,
// or some central place which is aware of the DB type. Let's just
// do this here for now.
File dbHome = env.getDataDir();
// set the Derby system home property to point to the package manager db
System.setProperty("derby.system.home", dbHome.getAbsolutePath());
logger.info("Package manager DB home set to " + System.getProperty("derby.system.home"));
try
{
conn = DriverManager.getConnection("jdbc:derby:pmdb;create=true");
DBUtil.runSql(conn, schemaFile);
logger.info("Successfully setup the package manager database");
}
catch (SQLException sqle)
{
throw new PackageManagerException("Could not setup package manager database: ", sqle);
}
catch (IOException ioe)
{
throw new PackageManagerException("Could not setup package manager database: ", ioe);
}
finally
{
if (conn != null)
{