diff --git a/.gitignore b/.gitignore index 6df73d2f..bb7106a6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ gradle-app.setting /.gradletasknamecache _support/ /out/ +.intellijPlatform/ diff --git a/build.gradle b/build.gradle deleted file mode 100644 index d9e081cd..00000000 --- a/build.gradle +++ /dev/null @@ -1,114 +0,0 @@ -plugins { - id 'java' - id 'jacoco' - id 'idea' - id 'org.jetbrains.intellij' version '1.17.2' - id 'com.dorongold.task-tree' version '2.1.1' - id 'org.infernus.idea.checkstyle.build' -} - - -repositories { - mavenCentral() -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Project Metadata -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -version = '5.92.0' - -intellij { - version = 'IC-2023.1.5' - pluginName = 'CheckStyle-IDEA' - updateSinceUntilBuild = false - instrumentCode = false - plugins = ['java'] -} - -verifyPlugin { - dependsOn(copyClassesToSandbox) - dependsOn(copyCheckstyleArtifactsToSandbox) -} - -publishPlugin { - token.set(System.getenv("JETBRAINS_PLUGIN_REPO_TOKEN")) -} - -// workaround for Checkstyle#14123 -configurations.configureEach { - resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") { - select("com.google.guava:guava:0") - } -} - - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Compilation -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - options.compilerArgs << '-Xlint:deprecation' - options.release.set(17) - - if (it.name == 'compileCsaccessJava' || it.name == 'compileCsaccessTestJava') { - options.compilerArgs << '-Xlint:unchecked' - } -} - -test { - forkEvery = 1 -} - -tasks.named("classpathIndexCleanup") { - dependsOn(tasks.named("processCsaccessResources")) - dependsOn(tasks.named("processCsaccessTestResources")) - dependsOn(tasks.named("compileCsaccessJava")) - dependsOn(tasks.named("compileCsaccessTestJava")) -} - - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Dependencies -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -dependencies { - implementation group: 'commons-io', name: 'commons-io', version: '2.15.1' - implementation group: 'commons-codec', name: 'commons-codec', version: '1.16.0' - - csaccessCompileOnly ("com.puppycrawl.tools:checkstyle:${supportedCsVersions.getBaseVersion()}") { - exclude group: 'commons-logging', module: 'commons-logging' - } - - testImplementation group: 'junit', name: 'junit', version: '4.13.2' - testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.5.0' -} - - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// IntelliJ IDEA Config -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -idea.module { - downloadJavadoc = true - downloadSources = true - excludeDirs += file('.idea') - excludeDirs += file('_support') - - // TODO We should also tell IntelliJ automatically that csaccessTest contains test code. - // The following lines should really do it, but currently don't, which seems like a Gradle bug to me: - //def SourceSet catSourceSet = sourceSets.getByName(CustomSourceSetCreator.CSACCESSTEST_SOURCESET_NAME); - //testSourceDirs += catSourceSet.getJava().getSrcDirs(); - //testSourceDirs += catSourceSet.getResources().getSrcDirs(); - //scopes.TEST.plus += [configurations.getByName(catSourceSet.getRuntimeConfigurationName())]; -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..b7be8691 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,112 @@ +import org.infernus.idea.checkstyle.build.CheckstyleVersions +import org.jetbrains.intellij.platform.gradle.TestFrameworkType +import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask + +plugins { + id("java") + id("jacoco") + id("idea") + id("org.jetbrains.intellij.platform") version "2.0.0" + id("com.dorongold.task-tree") version "2.1.1" + id("org.infernus.idea.checkstyle.build") +} + +version = "5.92.0" + +repositories { + mavenCentral() + + intellijPlatform { + defaultRepositories() + } +} + +intellijPlatform { + pluginConfiguration { + id = "CheckStyle-IDEA" + name = "CheckStyle-IDEA" + version = project.version.toString() + + ideaVersion { + sinceBuild = "231.9392.1" + untilBuild = provider { null } + } + } + + publishing { + token.set(System.getenv("JETBRAINS_PLUGIN_REPO_TOKEN")) + } +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + +} + +tasks { + withType { + dependsOn(copyClassesToSandbox, copyCheckstyleArtifactsToSandbox) + } + + withType { + setForkEvery(1) + } + + withType { + options.encoding = "UTF-8" + options.compilerArgs.addAll(listOf("-Xlint:deprecation")) + options.release.set(17) + + if (name == "compileCsaccessJava" || name == "compileCsaccessTestJava") { + options.compilerArgs.addAll(listOf("-Xlint:unchecked")) + } + } +} + +// workaround for Checkstyle#14123 +configurations.configureEach { + resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") { + select("com.google.guava:guava:0") + } +} + +dependencies { + intellijPlatform { + intellijIdeaCommunity("2023.1.5") + + bundledPlugin("com.intellij.java") + + instrumentationTools() + testFramework(TestFrameworkType.Platform) + } + + implementation("commons-io:commons-io:2.15.1") + implementation("commons-codec:commons-codec:1.16.0") + + val checkStyleBaseVersion = (project.extra["supportedCsVersions"] as CheckstyleVersions).baseVersion + csaccessCompileOnly("com.puppycrawl.tools:checkstyle:${checkStyleBaseVersion}") { + exclude(group = "commons-logging", module = "commons-logging") + } + + testImplementation("junit:junit:4.13.2") + testImplementation("org.hamcrest:hamcrest:2.2") + testImplementation("org.mockito:mockito-core:5.5.0") +} + +idea.module { + isDownloadJavadoc = true + isDownloadSources = true + + excludeDirs.addAll(listOf(file(".idea"), file("_support"))) + + // TODO We should also tell IntelliJ automatically that csaccessTest contains test code. + // The following lines should really do it, but currently don't, which seems like a Gradle bug to me: + //val SourceSet catSourceSet = sourceSets.getByName(CustomSourceSetCreator.CSACCESSTEST_SOURCESET_NAME) + //testSourceDirs.addAll(catSourceSet.getJava().getSrcDirs()) + //testSourceDirs.addAll(catSourceSet.getResources().getSrcDirs()) + //scopes.TEST.plus.addAll(listOf(configurations.getByName(catSourceSet.getRuntimeConfigurationName()))) +} diff --git a/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CsaccessTestTask.java b/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CsaccessTestTask.java index 48cf5877..11c39c4f 100644 --- a/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CsaccessTestTask.java +++ b/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CsaccessTestTask.java @@ -33,17 +33,17 @@ public class CsaccessTestTask extends Test { private Property dryRun; public CsaccessTestTask() { - super(); - final Project project = getProject(); final JavaPluginExtension jpc = project.getExtensions().getByType(JavaPluginExtension.class); - final SourceSet csaccessTestSourceSet = jpc.getSourceSets().getByName(CustomSourceSetCreator - .CSACCESSTEST_SOURCESET_NAME); + final SourceSet csaccessTestSourceSet = jpc.getSourceSets().getByName( + CustomSourceSetCreator.CSACCESSTEST_SOURCESET_NAME); dependsOn(project.getTasks().getByName(csaccessTestSourceSet.getClassesTaskName())); GradlePluginMain.configureTestTask(this); setTestClassesDirs(csaccessTestSourceSet.getOutput().getClassesDirs()); + setClasspath(csaccessTestSourceSet.getRuntimeClasspath() + .plus(csaccessTestSourceSet.getCompileClasspath())); } public static String getTaskName(final String pCheckstyleVersion) { diff --git a/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CustomSourceSetCreator.java b/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CustomSourceSetCreator.java index a27458de..6e025e16 100644 --- a/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CustomSourceSetCreator.java +++ b/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/CustomSourceSetCreator.java @@ -1,9 +1,5 @@ package org.infernus.idea.checkstyle.build; -import java.io.File; -import java.math.BigDecimal; -import java.util.stream.Collectors; - import org.gradle.api.Project; import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.file.FileCollection; @@ -20,12 +16,16 @@ import org.gradle.testing.jacoco.tasks.JacocoReportBase; import org.gradle.testing.jacoco.tasks.rules.JacocoViolationRule; +import java.io.File; +import java.math.BigDecimal; +import java.util.stream.Collectors; + public class CustomSourceSetCreator { static final String CSACCESS_SOURCESET_NAME = "csaccess"; public static final String CSACCESSTEST_SOURCESET_NAME = "csaccessTest"; - private static final double MINIMUM_CSACCESS_COVERAGE = 0.70d; + private static final double MINIMUM_CSACCESS_COVERAGE = 0.60d; private final Project project; @@ -45,15 +45,18 @@ private String getJacocoVerificationTaskName() { return sourceSets.getByName(CSACCESS_SOURCESET_NAME).getTaskName("jacoco", "CoverageVerification"); } - public void establishCsAccessSourceSet() { final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets"); final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); // Create the 'csaccess' source set final SourceSet csaccessSourceSet = sourceSets.create(CSACCESS_SOURCESET_NAME); - csaccessSourceSet.setCompileClasspath(csaccessSourceSet.getCompileClasspath().plus(mainSourceSet.getOutput())); - csaccessSourceSet.setRuntimeClasspath(csaccessSourceSet.getRuntimeClasspath().plus(mainSourceSet.getOutput())); + csaccessSourceSet.setCompileClasspath(csaccessSourceSet.getCompileClasspath() + .plus(mainSourceSet.getOutput()) + .plus(mainSourceSet.getCompileClasspath())); + csaccessSourceSet.setRuntimeClasspath(csaccessSourceSet.getRuntimeClasspath() + .plus(mainSourceSet.getOutput()) + .plus(mainSourceSet.getRuntimeClasspath())); // Derive all its configurations from 'main', so 'csaccess' code can see 'main' code final ConfigurationContainer configurations = project.getConfigurations(); @@ -79,7 +82,6 @@ public void establishCsAccessSourceSet() { .dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName())); } - public void establishCsAccessTestSourceSet() { final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets"); final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); @@ -88,10 +90,14 @@ public void establishCsAccessTestSourceSet() { // Create the 'csaccessTest' source set final SourceSet csaccessTestSourceSet = sourceSets.create(CSACCESSTEST_SOURCESET_NAME); - csaccessTestSourceSet.setCompileClasspath(csaccessTestSourceSet.getCompileClasspath(). - plus(mainSourceSet.getOutput()).plus(csaccessSourceSet.getOutput())); - csaccessTestSourceSet.setRuntimeClasspath(csaccessTestSourceSet.getRuntimeClasspath(). - plus(mainSourceSet.getOutput()).plus(csaccessSourceSet.getOutput())); + csaccessTestSourceSet.setCompileClasspath(csaccessTestSourceSet.getCompileClasspath() + .plus(mainSourceSet.getOutput()) + .plus(mainSourceSet.getCompileClasspath()) + .plus(csaccessSourceSet.getOutput())); + csaccessTestSourceSet.setRuntimeClasspath(csaccessTestSourceSet.getRuntimeClasspath() + .plus(mainSourceSet.getOutput()) + .plus(mainSourceSet.getRuntimeClasspath()) + .plus(csaccessSourceSet.getOutput())); // Derive all its configurations from 'test' and 'csaccess' final ConfigurationContainer configurations = project.getConfigurations(); diff --git a/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/GradlePluginMain.java b/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/GradlePluginMain.java index 93b10348..967802da 100644 --- a/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/GradlePluginMain.java +++ b/buildSrc/src/main/java/org/infernus/idea/checkstyle/build/GradlePluginMain.java @@ -19,6 +19,7 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent; import org.gradle.api.tasks.testing.logging.TestLoggingContainer; import org.gradle.language.base.plugins.LifecycleBasePlugin; +import org.jetbrains.annotations.NotNull; /** * The main plugin class. The action starts here. @@ -135,7 +136,7 @@ private void createCopyCheckstyleArtifactsToSandboxTask(final Project project, f final GatherCheckstyleArtifactsTask gatherTask = (GatherCheckstyleArtifactsTask) tasks.getByName(GatherCheckstyleArtifactsTask.NAME); - copyTask.dependsOn(gatherTask, "prepareTestingSandbox"); + copyTask.dependsOn(gatherTask, "prepareTestSandbox"); if (test) { tasks.getByName(JavaPlugin.TEST_TASK_NAME).dependsOn(copyTask); tasks.getByName(CsaccessTestTask.NAME).dependsOn(copyTask); @@ -145,8 +146,7 @@ private void createCopyCheckstyleArtifactsToSandboxTask(final Project project, f } copyTask.from(gatherTask.getBundledJarsDir()); - copyTask.into(new File(project.getLayout().getBuildDirectory().getAsFile().get(), "idea-sandbox/plugins" + (test ? "-test" : "") - + "/CheckStyle-IDEA/" + CSLIB_TARGET_SUBFOLDER)); + copyTask.into(new File(project.getLayout().getBuildDirectory().getAsFile().get(), pluginSandboxDir(test, CSLIB_TARGET_SUBFOLDER))); }); } @@ -164,21 +164,21 @@ private void forEachXTest(final TaskContainer tasks, final Consumer taskCo * copying it to the sandbox. Test code from csaccessTest sourceset not affected. * * @param pProject the Gradle project - * @param pIsTest {@code true} if the target is the test sandbox, {@code false} for the main sandbox + * @param test {@code true} if the target is the test sandbox, {@code false} for the main sandbox */ - private void createCopyClassesToSandboxTask(final Project pProject, final boolean pIsTest) { + private void createCopyClassesToSandboxTask(final Project pProject, final boolean test) { final TaskContainer tasks = pProject.getTasks(); - final String taskName = pIsTest ? "copyClassesToTestSandbox" : "copyClassesToSandbox"; + final String taskName = test ? "copyClassesToTestSandbox" : "copyClassesToSandbox"; final TaskProvider taskProvider = tasks.register(taskName, Copy.class); taskProvider.configure((Copy copyTask) -> { copyTask.setGroup("intellij"); copyTask.setDescription("Copy classes from '" + CustomSourceSetCreator.CSACCESS_SOURCESET_NAME - + "' sourceset into the prepared " + (pIsTest ? "test " : "") + "sandbox"); + + "' sourceset into the prepared " + (test ? "test " : "") + "sandbox"); final JavaPluginExtension jpc = pProject.getExtensions().getByType(JavaPluginExtension.class); SourceSet csaccessSourceSet = jpc.getSourceSets().getByName(CustomSourceSetCreator.CSACCESS_SOURCESET_NAME); copyTask.dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName())); - if (pIsTest) { + if (test) { tasks.getByName(JavaPlugin.TEST_TASK_NAME).dependsOn(copyTask); tasks.getByName(CsaccessTestTask.NAME).dependsOn(copyTask); forEachXTest(tasks, xTask -> xTask.dependsOn(copyTask)); @@ -188,11 +188,16 @@ private void createCopyClassesToSandboxTask(final Project pProject, final boolea final String targetSubfolder = "checkstyle/classes"; copyTask.from(csaccessSourceSet.getOutput()); - copyTask.into(new File(pProject.getLayout().getBuildDirectory().getAsFile().get(), "idea-sandbox/plugins" + (pIsTest ? "-test" : "") - + "/CheckStyle-IDEA/" + targetSubfolder)); + copyTask.into(new File(pProject.getLayout().getBuildDirectory().getAsFile().get(), pluginSandboxDir(test, targetSubfolder))); }); } + // TODO this will break when we change the base IDEA version; it should use SandboxAware or similar: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-task-awares.html#SandboxAware + private @NotNull String pluginSandboxDir(final boolean test, final String subDirectory) { + return "idea-sandbox/IC-2023.1.5/plugins" + + (test ? "-test" : "") + + "/CheckStyle-IDEA/" + subDirectory; + } /** * Defer some of the wiring until after the intellij plugin's tasks have been created. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd491..e6441136 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23a..09523c0e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 7f594621..00000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'checkstyle-idea' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..5a5d5c7b --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "checkstyle-idea" diff --git a/src/main/java/org/infernus/idea/checkstyle/importer/CheckStyleCodeStyleImporter.java b/src/main/java/org/infernus/idea/checkstyle/importer/CheckStyleCodeStyleImporter.java index 190d542b..8a1d847a 100644 --- a/src/main/java/org/infernus/idea/checkstyle/importer/CheckStyleCodeStyleImporter.java +++ b/src/main/java/org/infernus/idea/checkstyle/importer/CheckStyleCodeStyleImporter.java @@ -34,7 +34,7 @@ public CheckStyleCodeStyleImporter() { @NotNull @Override - public String @NotNull [] getSourceExtensions() { + public String[] getSourceExtensions() { return new String[]{"xml"}; } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 221191b9..5605819f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,7 +1,5 @@ - CheckStyle-IDEA - CheckStyle-IDEA org.infernus.idea.checkstyle.CheckStyleBundle ]]> - 5.92.0 - Jamie Shiell - com.intellij.modules.java -