/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.rio.bdo;
import static br.com.objectos.rio.RioVersion.VERSION;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import br.com.objectos.way.base.io.Directory;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Throwables;
/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
@Parameters
class BdoInstallOptions {
@Parameter(names = { "--version" })
String version = VERSION.get();
@Parameter(names = { "--engine", "-e" })
String engine = "mysql";
@Parameter(names = { "--name", "-n" })
String name = "default";
@Parameter(names = { "--port", "-p" })
int port = 3306;
@Parameter(names = { "--dest", "-d" })
String dest = "/";
@Parameter(names = { "--install", "-i" })
boolean install = false;
@Parameter(names = { "--start", "-s" })
boolean start = false;
@Parameter(names = "--server")
String server = "rio.objectos.com.br";
public Directory installVar(BdoDirs dirs) {
String child = String.format("%s-%s", engine, name);
Directory bdoVar = dirs.bdoVar();
return bdoVar.dirAt(child);
}
public URL getDataUrl() {
String name = String.format("http://%s/bdo/%s-%s.tar.bz2", server, engine, version);
return newUrl(name);
}
public File getDataFile(BdoDirs dirs) {
Directory bdoVar = dirs.bdoVar();
String name = String.format("%s-%s.tar.bz2", engine, version);
return bdoVar.fileAt(name);
}
public Directory getDataDir(BdoDirs dirs) {
Directory installVar = installVar(dirs);
String dir = String.format("var/lib/%s/%s-%s", engine, engine, name);
return installVar.dirAt(dir);
}
public File getMoveFile(BdoDirs dirs) {
Directory bdoVar = dirs.bdoVar();
String child = String.format("%s-%s-move.tar", engine, name);
return bdoVar.fileAt(child);
}
public Directory getDest() {
return Directory.at(dest);
}
public String getScriptName() {
return String.format("%s-%s", engine, name);
}
private URL newUrl(String url) {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw Throwables.propagate(e);
}
}
}