Example #1
0
  public static void enable(
      final BuildSettings settings, final PluginBuildSettings pluginSettings, boolean interactive) {
    final UaaService uaaService = UaaServiceFactory.getUaaService();

    final UaaClient.Privacy.PrivacyLevel privacyLevel = uaaService.getPrivacyLevel();
    if (!uaaService.isUaaTermsOfUseAccepted() && interactive) {
      // prompt for UAA choice
      if (privacyLevel.equals(UaaClient.Privacy.PrivacyLevel.UNDECIDED_TOU)) {
        while (true) {
          System.out.print(MESSAGE);
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          try {
            String selection = br.readLine().trim();
            if ("y".equalsIgnoreCase(selection)) {
              uaaService.setPrivacyLevel(UaaClient.Privacy.PrivacyLevel.ENABLE_UAA);
              break;
            } else if ("n".equalsIgnoreCase(selection)) {
              uaaService.setPrivacyLevel(UaaClient.Privacy.PrivacyLevel.DECLINE_TOU);
              break;
            }
          } catch (IOException e) {
            break;
          }
        }
      }
    } else if (isUaaAccepted(privacyLevel)) {
      Runnable r =
          new Runnable() {
            public void run() {
              final UaaClient.Product product =
                  VersionHelper.getProduct("Grails", settings.getGrailsVersion());
              uaaService.registerProductUsage(product);

              final ChainResolver chainResolver =
                  settings.getDependencyManager().getChainResolver();
              GrailsRepoResolver centralRepo = findCentralRepoResolver(chainResolver);
              if (centralRepo != null) {

                final GPathResult pluginList =
                    centralRepo.getPluginList(
                        new File(
                            settings.getGrailsWorkDir()
                                + "/plugin-list-"
                                + centralRepo.getName()
                                + ".xml"));

                final GrailsPluginInfo[] pluginInfos = pluginSettings.getPluginInfos();
                for (GrailsPluginInfo pluginInfo : pluginInfos) {
                  boolean registerUsage = false;

                  if (settings.getDefaultPluginSet().contains(pluginInfo.getName())) {
                    registerUsage = true;
                  } else {
                    final Object plugin =
                        UaaIntegrationSupport.findPlugin(pluginList, pluginInfo.getName());
                    if (plugin != null) {
                      registerUsage = true;
                    }
                  }
                  if (registerUsage) {
                    uaaService.registerFeatureUsage(
                        product,
                        VersionHelper.getFeatureUse(pluginInfo.getName(), pluginInfo.getVersion()));
                  }
                }
              }
            }
          };

      ConcurrentTaskScheduler scheduler = new ConcurrentTaskScheduler();

      scheduler.schedule(r, new Date(System.currentTimeMillis() + ONE_MINUTE));
    }
  }
Example #2
0
 private static boolean isUaaAccepted(UaaClient.Privacy.PrivacyLevel privacyLevel) {
   return privacyLevel.equals(UaaClient.Privacy.PrivacyLevel.ENABLE_UAA)
       || privacyLevel.equals(UaaClient.Privacy.PrivacyLevel.ENABLE_UAA);
 }