(PUP-2568) Downcase class name before validating

Previously the check for a valid name was done against the raw input,
however it later downcased the name and used that form. This order
caused Class['A'] to be an error, which isn't desired (at least not
until PUP-1810 is taken care of). By just changing the order of
operations capital letters are once again allowed.
(PUP-2581) Make illegal names interchangeable to legal variable work

In interpolation when using expression mode ${} and having an illegal
name (e.g. _x) that resulted in a syntax error as the _x got translated
to a STRING token (a bare word not being a name). The interpolation
logic could then not transform it into a (valid) variable expression
(i.e. $_x).

The change is to let the lexer emit a WORD token for the illegal NAME.
The interpolation then changes that to a VARIBLE if it is the only
expression. If the WORD token escapes into the grammar, it is equivalent
to having used a quoted string in the source text.

Note that WORD only accepts unqualified input, anything with a : that is
not a valid NAME is still flagged as an error. Thus _x::y, x::_y are
both illegal NAME.
(PUP-2519) Create the default directory environment

Directory environments are not guaranteed to exist; Puppet provides a
fallback staticly loaded environment for the default production
environment if it does not exist, but we would prefer to set up a real
directory environment if possible to provide a better experience for new
installations.

This commit adjusts the Puppet::Settings catalog to create the default directory
environment in the first `environmentpath` directory if that directory
exists.

Now that the production directory environment is created implicitly by
the Puppet settings catalog when we have an environmentpath, the
can_enumerate_environments test needs to expect that the production
environment will be there along with the two we have explicitly created.
(PUP-2519) Ignore module directories if env does not exist

Puppet::Util::Autoload will attempt to look up module directories in the
given or configured environment, but there is no guarantee that the
environment exists when using directory environments, and Autoload's
module_directories method fails if a nil environment is being handled.

Given that puppet applications now directly set the current environment
during their initialization and we have adjusted other points in puppet
that used to lookup the configured environment to instead use the
current environment, module_directories now skips and returns an empty
array if no environment is found during bootstrapping.
(PUP-2519) Create fallback environment only for default production

The goal here was to only produce a fallback environment for the default
'production' environment which would only be found if the production
directory environment did not exist.  All other cases would raise an
error during application start up if the environment did not exist.
Except for applications in agent mode which currently need the concept of
the environment they will be requesting, but should not have to create
or verify the existence of a locally matching environment in their
environmentpath.

A few other changes are made to further narrow the scope of code making
open requests for the configured environment:

* indirection request - looks up current environment now, relying on
  this having been set by whatever application is making the request.
* puppet apply - instead of creating a new loader with a single static
  environment, it overrides current_environment instead.
* puppet util commandline - does not attempt to look for additional
  plugins if there is no environment to search in.  It relies on
  application to raise an error instead, if necessary.
(PUP-2159) Serialize node.environment as environment_name

Puppet::Node used to implicitly lookup and set an environment instance
when deserializing it's environment attribute String.  On an agent run,
with directory environments set, this was likely to produce a node with
a nil environment.

Henrik Lindberg and I changed node to deserialize the environment to an
environment_name attribute, separating the process of deserialization
from lookup and assignment of an actual environment.  The configurer can
then check to see whether the node already has an environment, and if
not, if it has an environment_name, it can create a remote environment
instance for the node so the agent can proceed without needing a
directory environment to exist.
(PUP-2519) Set environment for request or fail explicitly

The Indirector::Request#environment= setter would fall back to looking
up an environment from the environment loaders if given something that
was not an actual environment instance. If directory environments have
been set, this can return nil, and while a Request#environment will fall
back to the current_environment, there was no warning that you have
attempted to set an environment and been ignored.

To make this clearer, the setter will now first attempt to use the
current_environment if it matches the given environment name, and will
explicitly raise an EnvironmentNotFound error if no matching environment
is found. The use of the current_environment with a matching name is
preferred over looking up a configured environment because there may be
no directory environment to load.
(PUP-2519) Test agent with directory environments enabled
(maint) Add environment review tests

PUP-2214 and PUP-2519 have resolved the remaining issues related to
non-existent directory environments and directory environment
configuration which were causing the directory environment acceptance
test to fail.  I'm including these three tests now as a baseline for
static, dynamic and directory environment behavior.
Merge pull request #2646 from jpartlow/issue/master/pup-2519-settings-create-environment-dir

Issue/master/pup 2519 settings create environment dir
(PUP-2519) Use File::PATH_SEPARATOR for environmentpath spec

One of the new specs testing the creation of production directory
environment in the settings catalog was using a ':' instead of
File::PATH_SEPARATOR and therefor failing on Windows.  This commit
changes it to use File::PATH_SEPARATOR.
(maint) Reorder code to increase clarity

There were a lot of unless cases that made it hard for me to track down
the path of what was actually accepted. This inverts the branches so
that the if statements lay out what is required for the good case and
the else clauses express the various failures.

In addition there were a few error scenarios where reordering was
possible and reduced the amount of work that needed to be done before
the error was detected.
(PUP-2568) Remove unnecessary calls

There are several calls that can be removed from various paths. Downcase
isn't needed for the PResourceType's type_name, since that is already
downcased (removes a string copy). The other change is that the NAME
pattern can handle leading :: and so that only needs to be stripped off
if it is a valid name (removes a string copy).
Merge branch 'pr/2656' into stable

* pr/2656:
  (PUP-2568) Remove unnecessary calls
  (maint) Reorder code to increase clarity
  (PUP-2568) Downcase class name before validating

Closes GH-2656
Merge pull request #2661 from hlindberg/pup-2581_interpolating-expression-of-bad-name

(PUP-2581) Make illegal names interchangeable to legal variable in interpolation
Merge remote-tracking branch 'upstream/stable'

* upstream/stable:
  (PUP-2568) Remove unnecessary calls
  (maint) Reorder code to increase clarity
  (PUP-2581) Make illegal names interchangeable to legal variable work
  (PUP-2568) Downcase class name before validating

Conflicts:
	lib/puppet/pops/parser/eparser.rb

Rebuilt eparser.
Merge remote-tracking branch 'upstream/master' into puppet-4

* upstream/master:
  (PUP-2568) Remove unnecessary calls
  (maint) Reorder code to increase clarity
  (PUP-2519) Use File::PATH_SEPARATOR for environmentpath spec
  (maint) Add environment review tests
  (PUP-2519) Test agent with directory environments enabled
  (PUP-2519) Set environment for request or fail explicitly
  (PUP-2159) Serialize node.environment as environment_name
  (PUP-2519) Create fallback environment only for default production
  (PUP-2519) Ignore module directories if env does not exist
  (PUP-2519) Create the default directory environment
  (PUP-2581) Make illegal names interchangeable to legal variable work
  (PUP-2568) Downcase class name before validating