protected Set<String> resolveTargetLanguages(BundleSet bundleSet) throws MojoFailureException { Set<String> targetLanguages = bundleSet.getTargetLanguages(); if (targetLanguages == null) { ServiceClient client = getServiceClient(); String srcLang = bundleSet.getSourceLanguage(); if (srcLang == null) { srcLang = "en"; } // targetLanguages is not specified. Default to all available languages. try { Map<String, Set<String>> activeMTLangs = client.getConfiguredMTLanguages(); targetLanguages = activeMTLangs.get(srcLang); } catch (ServiceException e) { targetLanguages = Collections.emptySet(); throw new MojoFailureException("Globalization Pipeline service error", e); } getLog() .info( "The configuration parameter 'targetLanguages' is not specified." + " Using currently active target languages: " + targetLanguages); } return Collections.unmodifiableSet(targetLanguages); }
/** * Returns GP ServiceClient instance used for this for this maven session. * * <p>This implementation resolves service credentials in the following order: * * <ol> * <li>A json file specified by user defined property 'gp.credentials.json'. This is typically * specified by a command line argument, e.g.<br> * <code>-D gp.credentials.json=/home/yoshito/gpcreds.json</code> * <li>A json file specified by <credentialsJson> in pom.xml * <li>A set of fields specified by <credentials> in pom.xml * </ol> * * @return An instance of ServiceClient. * @throws MojoFailureException on a failure. */ protected ServiceClient getServiceClient() throws MojoFailureException { if (gpClient == null) { synchronized (this) { Credentials creds = credentials; if (credentialsJson != null) { getLog().info("Reading GP service credentials from " + credentialsJson.getAbsolutePath()); try (InputStreamReader reader = new InputStreamReader(new FileInputStream(credentialsJson), StandardCharsets.UTF_8)) { Gson gson = new Gson(); creds = gson.fromJson(reader, Credentials.class); } catch (IOException e) { throw new MojoFailureException( "Error while reading the specified JSON credential file.", e); } catch (JsonSyntaxException e) { throw new MojoFailureException("Bad JSON credential format.", e); } } if (creds == null) { throw new MojoFailureException( "Globalization Pipeline service credentials are not specified."); } if (!creds.isValid()) { throw new MojoFailureException("Bad credentials: " + creds); } getLog().debug("Using GP service credentials " + creds); gpClient = ServiceClient.getInstance( ServiceAccount.getInstance( creds.getUrl(), creds.getInstanceId(), creds.getUserId(), creds.getPassword())); } } return gpClient; }