001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo.tools.ant;
012:
013: import org.apache.tools.ant.Task;
014: import org.apache.tools.ant.BuildException;
015:
016: import java.io.InputStream;
017: import java.io.IOException;
018: import java.util.Properties;
019:
020: import com.versant.core.common.BindingSupportImpl;
021:
022: /**
023: * Ant wrapper for the CopyDatabaseBean.
024: * @see CopyDatabaseBean
025: * @keep-all
026: */
027: public class CopyDatabaseTask extends Task {
028:
029: private String config = "versant.properties";
030: private CopyDatabaseBean cbean = new CopyDatabaseBean();
031:
032: public void execute() throws BuildException {
033: if (config == null) {
034: throw new BuildException("project attribute is required "
035: + "(name of .jdogenie project on the classpath)");
036: }
037: try {
038: cbean.setSrcProps(loadProperties(config));
039: cbean.copyDatabase();
040: } catch (Throwable t) {
041: t.printStackTrace(System.out);
042: throw new BuildException(t);
043: }
044: }
045:
046: private Properties loadProperties(String filename)
047: throws IOException {
048: ClassLoader cl = getClass().getClassLoader();
049: InputStream in = null;
050: try {
051: if (filename.startsWith("/"))
052: filename = filename.substring(1);
053: in = cl.getResourceAsStream(filename);
054: if (in == null) {
055: throw BindingSupportImpl.getInstance().runtime(
056: "Resource not found: " + filename);
057: }
058: Properties p = new Properties();
059: p.load(in);
060: return p;
061: } finally {
062: if (in != null)
063: in.close();
064: }
065: }
066:
067: public void setConfig(String config) {
068: this .config = config;
069: }
070:
071: public void setProject(String config) {
072: setConfig(config);
073: }
074:
075: public void setDatastore(String datastore) {
076: cbean.setDatastore(datastore);
077: }
078:
079: public void setDb(String db) {
080: cbean.setDb(db);
081: }
082:
083: public void setUrl(String url) {
084: cbean.setUrl(url);
085: }
086:
087: public void setDriver(String driver) {
088: cbean.setDriver(driver);
089: }
090:
091: public void setUser(String user) {
092: cbean.setUser(user);
093: }
094:
095: public void setPassword(String password) {
096: cbean.setPassword(password);
097: }
098:
099: public void setProperties(String properties) {
100: cbean.setProperties(properties);
101: }
102:
103: public void setDropTables(boolean dropTables) {
104: cbean.setDropTables(dropTables);
105: }
106:
107: public void setCreateTables(boolean createTables) {
108: cbean.setCreateTables(createTables);
109: }
110:
111: public void setRowsPerTransaction(int rowsPerTransaction) {
112: cbean.setRowsPerTransaction(rowsPerTransaction);
113: }
114:
115: public void setLogEvents(String logEvents) {
116: cbean.setLogEvents(logEvents);
117: }
118:
119: }
|