
com.liferay.source.formatter.check.CopyrightCheck 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.source.formatter.check;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.tools.GitUtil;
import com.liferay.source.formatter.SourceFormatterArgs;
import com.liferay.source.formatter.processor.SourceProcessor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Hugo Huijser
*/
public class CopyrightCheck extends BaseFileCheck {
@Override
public boolean isLiferaySourceCheck() {
return true;
}
@Override
protected String doProcess(
String fileName, String absolutePath, String content)
throws Exception {
SourceProcessor sourceProcessor = getSourceProcessor();
SourceFormatterArgs sourceFormatterArgs =
sourceProcessor.getSourceFormatterArgs();
String gitWorkingBranchName =
sourceFormatterArgs.getGitWorkingBranchName();
if (gitWorkingBranchName.matches("release-\\d{4}\\.q[1-4]")) {
return content;
}
if (!fileName.endsWith(".tpl") && !fileName.endsWith(".vm")) {
content = _fixCopyright(
fileName, absolutePath, content, sourceFormatterArgs);
}
return content;
}
private String _fixCopyright(
String fileName, String absolutePath, String content,
SourceFormatterArgs sourceFormatterArgs)
throws Exception {
int x = content.indexOf("/**\n * SPDX-FileCopyrightText: (c) ");
if (x == -1) {
addMessage(fileName, "Missing copyright");
return content;
}
String s = content.substring(x + 35, content.indexOf("\n", x + 35));
if (!s.matches("\\d{4} Liferay, Inc\\. https://liferay\\.com")) {
addMessage(fileName, "Missing copyright");
return content;
}
if (!content.startsWith("/**\n * SPDX-FileCopyrightText: (c) ") &&
!content.startsWith("<%--\n/**\n * SPDX-FileCopyrightText: (c) ") &&
!content.startsWith(
_XML_DECLARATION +
"
© 2015 - 2025 Weber Informatics LLC | Privacy Policy