Package br.com.objectos.rio.kdo.eclipse

Source Code of br.com.objectos.rio.kdo.eclipse.EclipsePrepare

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

import java.io.File;

import br.com.objectos.rio.AbstractRioCommand;
import br.com.objectos.rio.HttpServer;
import br.com.objectos.rio.kdo.KdoDirs;
import br.com.objectos.way.base.io.Directory;

import com.google.inject.Inject;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
class EclipsePrepare
    extends AbstractRioCommand<EclipsePrepareOptions>
    implements EclipsePrepareCommand {

  private final KdoDirs dirs;

  @Inject
  public EclipsePrepare(KdoDirs dirs) {
    this.dirs = dirs;
  }

  @Override
  protected String getCommandName() {
    return "kdo eclipse prepare";
  }

  @Override
  protected EclipsePrepareOptions newOptions() {
    return new EclipsePrepareOptions();
  }

  @Override
  protected void executeCommand(EclipsePrepareOptions options) {
    options.all();

    HttpServer server = options.fileServer();
    Directory eclipseVar = dirs.eclipseVar();
    File eclipseTar = eclipseVar.fileAt("eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz");
    Directory eclipseDir = eclipseVar.dirAt("eclipse");

    infoAction("dirs");
    info("Preparing directories.");

    eclipseDir.deleteContents();

    if (options.download) {
      download(server, eclipseVar);
    }

    if (options.extract) {
      extract(eclipseTar, eclipseVar);
    }

    if (options.plugins) {
      plugins(eclipseDir);
    }

    if (options.objectos) {
      objectos(eclipseDir);
    }
  }

  private void download(HttpServer server, Directory eclipseVar) {
    infoAction("download");
    info("Downloading and staging required files.");

    download(server).to(eclipseVar)
        .map(
            "kdo/eclipse/eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz",
            "eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz")
        .exec();
  }

  private void extract(File eclipseTar, Directory eclipseVar) {
    infoAction("extract");
    info("Unpacking to %s", eclipseVar.getAbsolutePath());

    untar(eclipseTar)
        .gunzip()
        .toDir(eclipseVar);
  }

  private void plugins(Directory pluginsDir) {
    infoAction("plugins");
    info("Installing aditional plugins.");

    P2Director.at(pluginsDir)
        .repository("http://beust.com/eclipse")
        .repository("http://download.eclipse.org/releases/kepler")
        .repository("http://download.eclipse.org/webtools/repository/kepler")
        .repository("http://www.normalesup.org/~simonet/soft/ow/update")
        .installIU("org.testng.eclipse.feature.group/6.8.6.20130914_0724")
        .installIU("net.vtst.ow.eclipse.less.feature.feature.group/1.0.18")
        .execute();
  }

  private void objectos(Directory eclipseDir) {
    infoAction("objectos");
    info("Applying objectos settings.");

    resourcesAt("/kdo/eclipse/prepare")
        .add("configuration/config.ini")
        .add("icon.png")
        .copyTo(eclipseDir);
  }

}
TOP

Related Classes of br.com.objectos.rio.kdo.eclipse.EclipsePrepare

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.