# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
                        unicode_literals, with_statement)

import sys

from colors import cyan, green, red, yellow

from pants.base.config import Config
from pants.option import custom_types
from pants.option.errors import ParseError


migrations = {
  ('backends', 'packages'): ('DEFAULT', 'backend_packages'),
  ('backends', 'plugins'): ('DEFAULT', 'plugins'),
  ('DEFAULT', 'bootstrap_buildfiles'): ('goals', 'bootstrap_buildfiles'),

  ('jvm', 'missing_deps_target_whitelist'): ('compile.java', 'missing_deps_whitelist'),

  ('java-compile', 'partition_size_hint'): ('compile.java', 'partition_size_hint'),
  ('java-compile', 'javac_args'): ('compile.java', 'args'),
  ('java-compile', 'jvm_args'): ('compile.java', 'jvm_options'),
  ('java-compile', 'confs'): ('compile.java', 'confs'),
  ('java-compile', 'locally_changed_targets_heuristic_limit'): ('compile.java',
                                                                'changed_targets_heuristic_limit'),
  ('java-compile', 'warning_args'): ('compile.java', 'warning_args'),
  ('java-compile', 'no_warning_args'): ('compile.java', 'no_warning_args'),
  ('java-compile', 'use_nailgun'): ('compile.java', 'use_nailgun'),

  ('scala-compile', 'partition_size_hint'): ('compile.scala', 'partition_size_hint'),
  ('scala-compile', 'jvm_args'): ('compile.scala', 'jvm_options'),
  ('scala-compile', 'confs'): ('compile.scala', 'confs'),
  ('scala-compile', 'locally_changed_targets_heuristic_limit'): ('compile.scala',
                                                                 'changed_targets_heuristic_limit'),
  ('scala-compile', 'warning_args'): ('compile.scala', 'warning_args'),
  ('scala-compile', 'no_warning_args'): ('compile.scala', 'no_warning_args'),
  ('scala-compile', 'runtime-deps'): ('compile.scala', 'runtime-deps'),
  ('scala-compile', 'use_nailgun'): ('compile.scala', 'use_nailgun'),
  ('scala-compile', 'args'): ('compile.scala', 'args'),

  ('javadoc-gen', 'include_codegen'): ('gen.javadoc', 'include_codegen'),
  ('scaladoc-gen', 'include_codegen'): ('gen.scaladoc', 'include_codegen'),

  ('nailgun', 'autokill'): ('DEFAULT', 'kill_nailguns'),

  ('jvm-run', 'jvm_args'): ('run.jvm', 'jvm_options'),
  ('benchmark-run', 'jvm_args'): ('bench', 'jvm_options'),
  ('specs-run', 'jvm_args'): ('test.specs', 'jvm_options'),
  ('junit-run', 'jvm_args'): ('test.junit', 'jvm_options'),
  ('scala-repl', 'jvm_args'): ('repl.scala', 'jvm_options'),
  ('ivy-resolve', 'jvm_args'): ('resolve.ivy', 'jvm_options'),

  ('jvm-run', 'confs'): ('run.jvm', 'confs'),
  ('benchmark-run', 'confs'): ('bench', 'confs'),
  ('specs-run', 'confs'): ('test.specs', 'confs'),
  ('junit-run', 'confs'): ('test.junit', 'confs'),
  ('scala-repl', 'confs'): ('repl.scala', 'confs'),
  ('ivy-resolve', 'confs'): ('resolve.ivy', 'confs'),

  ('scala-repl', 'args'): ('repl.scala', 'args'),

  ('checkstyle', 'bootstrap-tools'): ('compile.checkstyle', 'bootstrap_tools'),
  ('checkstyle', 'configuration'): ('compile.checkstyle', 'configuration'),
  ('checkstyle', 'properties'): ('compile.checkstyle', 'properties'),

  ('scalastyle', 'config'): ('compile.scalastyle', 'config'),
  ('scalastyle', 'excludes'): ('compile.scalastyle', 'excludes'),

  # These must now be defined for each JvmTask subtask, so we temporarily put them
  # in the DEFAULT section as a convenience.
  # These will soon move into a subsystem, which will fix this.
  ('jvm', 'debug_config'): ('DEFAULT', 'debug_config'),
  ('jvm', 'debug_port'): ('DEFAULT', 'debug_port'),

  ('scala-compile', 'scalac-plugins'): ('compile.scala', 'plugins'),
  ('scala-compile', 'scalac-plugin-args'): ('compile.scala', 'plugin_args'),

  ('markdown-to-html', 'extensions'): ('markdown', 'extensions'),
  ('markdown-to-html', 'code-style'): ('markdown', 'code_style'),

  # Note: This assumes that ConfluencePublish is registered as the only task in a
  #       goal called 'confluence'.  Adjust if this is not the case in your pants.ini.
  ('confluence-publish', 'url'): ('confluence', 'url'),

  # JVM tool migrations.
  ('antlr-gen', 'javadeps'): ('gen.antlr', 'antlr3'),
  ('antlr4-gen', 'javadeps'): ('gen.antlr', 'antlr4'),
  ('scrooge-gen', 'bootstrap-tools'): ('gen.scrooge', 'scrooge'),
  ('thrift-linter', 'bootstrap-tools'): ('thrift-linter', 'scrooge_linter'),
  ('wire-gen', 'bootstrap-tools'): ('gen.wire', 'wire_compiler'),
  ('benchmark-run', 'bootstrap-tools'): ('bench', 'benchmark_tool'),
  ('benchmark-run', 'agent-bootstrap-tools'): ('bench', 'benchmark_agent'),
  ('compile.checkstyle', 'bootstrap-tools'): ('compile.checkstyle', 'checkstyle'),
  ('ivy-resolve', 'bootstrap-tools'): ('resolve.ivy', 'xalan'),
  ('jar-tool', 'bootstrap-tools'): ('DEFAULT', 'jar-tool'),
  ('junit-run', 'junit-bootstrap-tools'): ('test.junit', 'junit'),
  ('junit-run', 'emma-bootstrap-tools'): ('test.junit', 'emma'),
  ('junit-run', 'cobertura-bootstrap-tools'): ('test.junit', 'cobertura'),
  ('java-compile', 'jmake-bootstrap-tools'): ('compile.java', 'jmake'),
  ('java-compile', 'compiler-bootstrap-tools'): ('compile.java', 'java_compiler'),
  # Note: compile-bootstrap-tools is not a typo.
  ('scala-compile', 'compile-bootstrap-tools'): ('compile.scala', 'scalac'),
  ('scala-compile', 'zinc-bootstrap-tools'): ('compile.scala', 'zinc'),
  ('scala-compile', 'scalac-plugin-bootstrap-tools'): ('compile.scala', 'plugin_jars'),
  ('scala-repl', 'bootstrap-tools'): ('repl.scala', 'scala_repl'),
  ('specs-run', 'bootstrap-tools'): ('test.specs', 'specs'),

  # Artifact cache spec migration.
  ('dx-tool', 'read_artifact_caches'): ('dex', 'read_artifact_caches'),
  ('thrift-gen', 'read_artifact_caches'): ('gen.thrift', 'read_artifact_caches'),
  ('ivy-resolve', 'read_artifact_caches'): ('resolve.ivy', 'read_artifact_caches'),
  ('java-compile', 'read_artifact_caches'): ('compile.java', 'read_artifact_caches'),
  ('scala-compile', 'read_artifact_caches'): ('compile.scala', 'read_artifact_caches'),

  ('dx-tool', 'write_artifact_caches'): ('dex', 'write_artifact_caches'),
  ('thrift-gen', 'write_artifact_caches'): ('gen.thrift', 'write_artifact_caches'),
  ('ivy-resolve', 'write_artifact_caches'): ('resolve.ivy', 'write_artifact_caches'),
  ('java-compile', 'write_artifact_caches'): ('compile.java', 'write_artifact_caches'),
  ('scala-compile', 'write_artifact_caches'): ('compile.scala', 'write_artifact_caches'),

  ('protobuf-gen', 'version'): ('gen.protoc', 'version'),
  ('protobuf-gen', 'supportdir'): ('gen.protoc', 'supportdir'),
  ('protobuf-gen', 'plugins'): ('gen.protoc', 'plugins'),
  ('protobuf-gen', 'javadeps'): ('gen.protoc', 'javadeps'),
  ('protobuf-gen', 'pythondeps'): ('gen.protoc', 'pythondeps'),

  ('thrift-gen', 'strict'): ('gen.thrift', 'strict'),
  ('thrift-gen', 'supportdir'): ('gen.thrift', 'supportdir'),
  ('thrift-gen', 'version'): ('gen.thrift', 'version'),
  ('thrift-gen', 'java'): ('gen.thrift', 'java'),
  ('thrift-gen', 'python'): ('gen.thrift', 'python'),

  ('backend', 'python-path'): ('DEFAULT', 'pythonpath'),

  ('python-ipython', 'entry-point'): ('repl.py', 'ipython_entry_point'),
  ('python-ipython', 'requirements'): ('repl.py', 'ipython_requirements'),

  ('jar-publish', 'restrict_push_branches'): ('publish.jar', 'restrict_push_branches'),
  ('jar-publish', 'ivy_jvmargs'): ('publish.jar', 'jvm_options'),
  ('jar-publish', 'repos'): ('publish.jar', 'repos'),
  ('jar-publish', 'publish_extras'): ('publish.jar', 'publish_extras'),

  ('publish', 'individual_plugins'): ('publish.jar', 'individual_plugins'),