Package br.com.objectos.rio.bdo.install

Source Code of br.com.objectos.rio.bdo.install.BdoInstallOptions

/*
* 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.install;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import br.com.objectos.rio.bdo.BdoDirs;
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 {

  String version = "0.1.0";

  @Parameter(names = { "--engine", "-e" })
  String engine = "mysql";

  @Parameter(names = { "--name", "-n" })
  String name = "default";

  @Parameter(names = { "--port", "-p" })
  int port = 3306;

  @Parameter(names = { "--prepare-only" })
  boolean prepareOnly = 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 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);
    }
  }

}
TOP

Related Classes of br.com.objectos.rio.bdo.install.BdoInstallOptions

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.