Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ workflows:
jobs:
- validate-with-maven-script:
name: "releasenotes-builder"
image-name: &custom_img "amitkumardeoghoria/jdk-17-groovy-git-mvn:v1.0"
image-name: &custom_img "amitkumardeoghoria/jdk-21-groovy5-git-mvn-ant-jq:latest"
command: "./.ci/validation.sh releasenotes-builder"
- validate-with-maven-script:
name: "patch-diff-report-tool"
Expand Down
61 changes: 39 additions & 22 deletions checkstyle-tester/diff.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@Grab('info.picocli:picocli:4.7.5')
import groovy.cli.picocli.CliBuilder
import static java.lang.System.err
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING

import java.nio.file.Files
import java.nio.file.Paths
import java.util.regex.Pattern

static void main(String[] args) {
void main(String[] args) {
def cliOptions = getCliOptions(args)
if (cliOptions != null) {
if (areValidCliOptions(cliOptions)) {
Expand Down Expand Up @@ -50,32 +52,36 @@ static void main(String[] args) {

def getCliOptions(args) {
def cliOptionsDescLineLength = 120
def cli = new CliBuilder(usage:'groovy diff.groovy [options]', header: 'options:', width: cliOptionsDescLineLength)
def cli = new CliBuilder(
usageMessage: 'groovy diff.groovy [options]',
headerHeading: 'Options:\n',
width: cliOptionsDescLineLength
)
cli.with {
r(longOpt: 'localGitRepo', args: 1, required: true, argName: 'path',
r(longOpt: 'localGitRepo', arity: "1", required: true, argName: 'path',
'Path to local git repository (required)')
b(longOpt: 'baseBranch', args: 1, required: false, argName: 'branch_name',
b(longOpt: 'baseBranch', arity: "1", required: false, argName: 'branch_name',
'Base branch name. Default is master (optional, default is master)')
p(longOpt: 'patchBranch', args: 1, required: true, argName: 'branch_name',
p(longOpt: 'patchBranch', arity: "1", required: true, argName: 'branch_name',
'Name of the patch branch in local git repository (required)')
bc(longOpt: 'baseConfig', args: 1, required: false, argName: 'path', 'Path to the base ' \
bc(longOpt: 'baseConfig', arity: "1", required: false, argName: 'path', 'Path to the base ' \
+ 'checkstyle config file (optional, if absent then the tool will use only ' \
+ 'patchBranch in case the tool mode is \'single\', otherwise baseBranch ' \
+ 'will be set to \'master\')')
pc(longOpt: 'patchConfig', args: 1, required: false, argName: 'path',
pc(longOpt: 'patchConfig', arity: "1", required: false, argName: 'path',
'Path to the patch checkstyle config file (required if baseConfig is specified)')
c(longOpt: 'config', args: 1, required: false, argName: 'path', 'Path to the checkstyle ' \
c(longOpt: 'config', arity: "1", required: false, argName: 'path', 'Path to the checkstyle ' \
+ 'config file (required if baseConfig and patchConfig are not secified)')
g(longOpt: 'allowExcludes', required: false, 'Whether to allow excludes specified in the list of ' \
+ 'projects (optional, default is false)')
h(longOpt: 'useShallowClone', 'Enable shallow cloning')
l(longOpt: 'listOfProjects', args: 1, required: true, argName: 'path',
l(longOpt: 'listOfProjects', arity: "1", required: true, argName: 'path',
'Path to file which contains projects to test on (required)')
s(longOpt: 'shortFilePaths', required: false, 'Whether to save report file paths' \
+ ' as a shorter version to prevent long paths. (optional, default is false)')
m(longOpt: 'mode', args: 1, required: false, argName: 'mode', 'The mode of the tool:' \
m(longOpt: 'mode', arity: "1", required: false, argName: 'mode', 'The mode of the tool:' \
+ ' \'diff\' or \'single\'. (optional, default is \'diff\')')
xm(longOpt: 'extraMvnRegressionOptions', args: 1, required: false, 'Extra arguments to pass to Maven' \
xm(longOpt: 'extraMvnRegressionOptions', arity: "1", required: false, 'Extra arguments to pass to Maven' \
+ 'for Checkstyle Regression run (optional, ex: -Dmaven.prop=true)')
}
return cli.parse(args)
Expand Down Expand Up @@ -703,27 +709,38 @@ def runMavenExecution(srcDir, excludes, checkstyleConfig,
}

def postProcessCheckstyleReport(targetDir, repoName, repoPath) {
new AntBuilder().replace(
file: getOsSpecificPath("$targetDir", "checkstyle-result.xml"),
token: new File(getOsSpecificPath("src", "main", "java", "$repoName")).absolutePath,
value: getOsSpecificPath("$repoPath")
)
def reportFile = Paths.get("$targetDir", "checkstyle-result.xml").toFile()
def oldPath = new File(getOsSpecificPath("src", "main", "java", "$repoName")).absolutePath
def newContent = reportFile.text.replace(oldPath, getOsSpecificPath("$repoPath"))
reportFile.text = newContent
}

def copyDir(source, destination) {
new AntBuilder().copy(todir: destination) {
fileset(dir: source)
def sourcePath = Paths.get(source)
def destPath = Paths.get(destination)
Files.walk(sourcePath).forEach { src ->
def target = destPath.resolve(sourcePath.relativize(src))
if (Files.isDirectory(src)) {
Files.createDirectories(target)
} else {
Files.copy(src, target, REPLACE_EXISTING)
}
}
}

def moveDir(source, destination) {
new AntBuilder().move(todir: destination) {
fileset(dir: source)
}
def sourcePath = Paths.get(source)
def destPath = Paths.get(destination)
Files.move(sourcePath, destPath, REPLACE_EXISTING)
}

def deleteDir(dir) {
new AntBuilder().delete(dir: dir, failonerror: false)
def path = Paths.get(dir)
if (Files.exists(path)) {
Files.walk(path)
.sorted(Comparator.reverseOrder())
.forEach { Files.delete(it) }
}
}

def executeCmd(cmd, dir = new File("").absoluteFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN curl -s "https://get.sdkman.io" | bash
# Install Java 21, Groovy, Maven via SDKMAN
RUN bash -c "source $SDKMAN_DIR/bin/sdkman-init.sh && \
sdk install java 21.0.4-tem && \
sdk install groovy 3.0.21 && \
sdk install groovy 5.0.0 && \
sdk install maven 3.9.11"

# Update PATH and setup environment
Expand All @@ -24,6 +24,4 @@ ENV PATH=$GROOVY_HOME/bin:$SDKMAN_DIR/candidates/maven/current/bin:$JAVA_HOME/bi
RUN bash -c "source $SDKMAN_DIR/bin/sdkman-init.sh && \
java -version && \
groovy --version && \
mvn -version && \
groovy -e 'new CliBuilder(); println \"CliBuilder OK\"' && \
groovy -e 'new AntBuilder(); println \"AntBuilder OK\"'"
mvn -version"
77 changes: 47 additions & 30 deletions patch-diff-report-tool/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.checkstyle</groupId>
<artifactId>patch-diff-report-tool</artifactId>
Expand All @@ -9,8 +9,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle.version>11.1.0</checkstyle.version>
<checkstyle.configLocation>https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle-checks.xml</checkstyle.configLocation>
<checkstyle.version>11.0.1</checkstyle.version>
<checkstyle.configLocation>
https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle-checks.xml
</checkstyle.configLocation>
<maven.plugin.antrun.version>3.1.0</maven.plugin.antrun.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Expand All @@ -24,6 +26,21 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-ant</artifactId>
<version>4.0.23</version> <!-- match your Groovy version -->
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-cli-picocli</artifactId>
<version>3.0.9</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-jxr</artifactId>
Expand Down Expand Up @@ -81,33 +98,33 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven.plugin.antrun.version}</version>
<executions>
<execution>
<id>ant-phase-verify</id>
<phase>verify</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="mvn.project.build.directory" value="${project.build.directory}" />
<property name="checkstyle.configLocation" value="${checkstyle.configLocation}" />
<property name="mvn.java.version" value="${maven.compiler.source}"/>
<ant antfile="config/ant-phase-verify.xml" />
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven.plugin.antrun.version}</version>
<executions>
<execution>
<id>ant-phase-verify</id>
<phase>verify</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="mvn.project.build.directory" value="${project.build.directory}"/>
<property name="checkstyle.configLocation" value="${checkstyle.configLocation}"/>
<property name="mvn.java.version" value="${maven.compiler.source}"/>
<ant antfile="config/ant-phase-verify.xml"/>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down