All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.gradle.plugins.soy.task.ReplaceSoyTranslationTask Maven / Gradle / Ivy

/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.gradle.plugins.soy.task;

import com.liferay.portal.tools.soy.builder.commands.ReplaceSoyTranslationCommand;

import groovy.lang.Closure;

import java.io.File;
import java.io.IOException;

import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.SourceTask;
import org.gradle.api.tasks.TaskAction;

/**
 * @author     Andrea Di Giorgi
 * @deprecated As of Judson (7.1.x), with no direct replacement
 */
@CacheableTask
@Deprecated
public class ReplaceSoyTranslationTask extends SourceTask {

	@Input
	@Optional
	public Closure getReplacementClosure() {
		return _replacementClosure;
	}

	@TaskAction
	public void replaceSoyTranslation() throws IOException {
		for (File file : getSource()) {
			_replaceSoyTranslationCommand.execute(file.toPath());
		}
	}

	public void setReplacementClosure(Closure replacementClosure) {
		_replacementClosure = replacementClosure;
	}

	private Closure _replacementClosure;

	private final ReplaceSoyTranslationCommand _replaceSoyTranslationCommand =
		new ReplaceSoyTranslationCommand() {

			@Override
			protected String getReplacement(
				String variableName, String languageKey,
				String argumentsObject) {

				Closure closure = getReplacementClosure();

				if (closure != null) {
					return closure.call(
						variableName, languageKey, argumentsObject);
				}

				return super.getReplacement(
					variableName, languageKey, argumentsObject);
			}

		};

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy