private function copyReference($oldKey, $newKey)
    {
        $orig = $this->project->getReference($oldKey);
        if ($orig === null) {
            $this->log(
                "No object referenced by " . $oldKey . ". Can't copy to "
                . $newKey,
                Project::MSG_WARN
            );

            return;
        }

        $copy = clone $orig;

        if ($copy instanceof ProjectComponent) {
            $copy->setProject($this->newProject);
        } elseif (in_array('setProject', get_class_methods(get_class($copy)))) {
            $copy->setProject($this->newProject);
        } elseif ($copy instanceof Project) {
            // don't copy the old "Project" itself
        } else {
            $msg = "Error setting new project instance for "
                . "reference with id " . $oldKey;
            throw new BuildException($msg);
        }

        $this->newProject->addReference($newKey, $copy);
    }