@Override
  public void apply(Settings settings) {
    File rootDir = settings.getRootDir();

    Path rootDirPath = rootDir.toPath();

    String projectPathPrefix =
        GradleUtil.getProperty(settings, PROJECT_PATH_PREFIX_PROPERTY_NAME, "");

    if (Validator.isNotNull(projectPathPrefix)) {
      if (projectPathPrefix.charAt(0) != ':') {
        projectPathPrefix = ":" + projectPathPrefix;
      }

      if (projectPathPrefix.charAt(projectPathPrefix.length() - 1) == ':') {

        projectPathPrefix = projectPathPrefix.substring(0, projectPathPrefix.length() - 1);
      }
    }

    try {
      _includeProjects(settings, rootDirPath, rootDirPath, projectPathPrefix);
    } catch (IOException ioe) {
      throw new UncheckedIOException(ioe);
    }
  }
  protected WorkspaceExtension addWorkspaceExtension(Settings settings) {
    ExtensionAware extensionAware = (ExtensionAware) settings.getGradle();

    ExtensionContainer extensionContainer = extensionAware.getExtensions();

    return extensionContainer.create(EXTENSION_NAME, WorkspaceExtension.class, settings);
  }
  private void _includeProject(
      Settings settings,
      Path projectDirPath,
      Path projectPathRootDirPath,
      String projectPathPrefix) {

    Path relativePath = projectPathRootDirPath.relativize(projectDirPath);

    String projectPath = relativePath.toString();

    projectPath = projectPathPrefix + ":" + projectPath.replace(File.separatorChar, ':');

    settings.include(new String[] {projectPath});

    ProjectDescriptor projectDescriptor = settings.findProject(projectPath);

    projectDescriptor.setProjectDir(projectDirPath.toFile());
  }
  @Override
  public void apply(Settings settings) {
    Gradle gradle = settings.getGradle();

    final WorkspaceExtension workspaceExtension = addWorkspaceExtension(settings);

    for (ProjectConfigurator projectConfigurator : workspaceExtension.getProjectConfigurators()) {

      for (File rootDir : projectConfigurator.getDefaultRootDirs()) {
        for (File projectDir : projectConfigurator.getProjectDirs(rootDir)) {

          String projectPath = GradleUtil.getProjectPath(projectDir, settings.getRootDir());

          settings.include(new String[] {projectPath});

          _projectConfiguratorsMap.put(projectPath, projectConfigurator);
        }
      }
    }

    gradle.beforeProject(
        new Closure<Void>(null) {

          @SuppressWarnings("unused")
          public void doCall(Project project) {
            Plugin<Project> plugin = null;

            if (project.getParent() == null) {
              plugin = workspaceExtension.getRootProjectConfigurator();
            } else {
              plugin = _projectConfiguratorsMap.get(project.getPath());
            }

            if (plugin != null) {
              plugin.apply(project);
            }
          }
        });
  }