Skip to content

Commit 5277177

Browse files
Remove the circular dependency between diktat-rules and diktat-ruleset
### What's done: * Now it's possible to run `mvn clean install` w/o skipping tests. * Reverted ad66a04 (was useless in the 1st place). * Reverted ad66a04 (no longer necessary). * Partially reverted 54c8cce (no longer necessary). * See #1478.
1 parent 4a3e5e1 commit 5277177

File tree

7 files changed

+105
-46
lines changed

7 files changed

+105
-46
lines changed

.github/workflows/build_and_test.yml

+3-17
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ jobs:
2424
restore-keys: |
2525
maven-build-
2626
- name: Maven Install
27-
run: mvn -B clean install -DskipTests
28-
- name: Maven run test
29-
run: mvn verify
27+
run: mvn -B clean install
3028
- name: Code coverage report
3129
uses: codecov/codecov-action@v3
3230
with:
@@ -152,25 +150,13 @@ jobs:
152150
- name: Maven Install
153151
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
154152
run: |
155-
mvn -B -T1C clean install -DskipTests
156-
shell: bash
157-
158-
- name: Maven run test
159-
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
160-
run: |
161-
mvn verify
153+
mvn -B -T1C clean install
162154
shell: bash
163155

164156
- name: Maven Install on windows
165157
if: runner.os == 'Windows'
166158
run: |
167-
mvn -B -T1C clean install -DskipTests
168-
shell: cmd
169-
170-
- name: Maven run test
171-
if: runner.os == 'Windows'
172-
run: |
173-
mvn verify
159+
mvn -B -T1C clean install
174160
shell: cmd
175161

176162
# This step needs a Git repository, so it's impossible to extract it

.github/workflows/metrics_for_master.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ jobs:
2828
key: maven-build-${{ hashFiles('**/pom.xml') }}
2929
restore-keys: |
3030
maven-build-
31-
- name: Maven Install
32-
# we need to run `install` goal here so that gradle will be able to resolve dependencies and run tests on diktat-gradle-plugin
33-
run: mvn -B install -DskipPluginMarker -DskipTests
3431
- name: Run tests
35-
run: mvn verify
32+
# we need to run `install` goal here so that gradle will be able to resolve dependencies and run tests on diktat-gradle-plugin
33+
run: mvn -B install -DskipPluginMarker
3634
- name: Generate code coverage report
3735
uses: codecov/codecov-action@v3
3836
with:

.github/workflows/release.yml

+4-10
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,10 @@ jobs:
4949
{ "id": "gpg.passphrase", "passphrase": "${{ secrets.DIKTAT_GPG_PASS }}" },
5050
{ "id": "kotlin-maven-plugin-tools", "username": "${{github.actor}}", "password": "${{ secrets.GITHUB_TOKEN }}" }
5151
]
52-
# Runs tests, incl. smoke tests (using a fat JAR built from the
53-
# "diktat-ruleset" module). The fat JAR is also used later during the
54-
# "upload-release-asset" step (see below).
55-
- name: Run tests
56-
run: mvn -B clean install
57-
# "diktat-ruleset" is a module that creates a fat JAR, which is,
58-
# obviously, never released. Since we *do need* this fat JAR in order to
59-
# run smoke tests, we *skip tests entirely* in this step.
60-
- name: Deploy artifacts (skipping the clean, test, and verify phases)
61-
run: mvn -B deploy -Prelease --projects "!diktat-ruleset" -DskipTests=true
52+
- name: Deploy artifacts
53+
run: mvn -B clean deploy -Prelease --projects '!diktat-ruleset'
54+
- name: Build diktat.jar
55+
run: mvn -B package --projects diktat-ruleset
6256
- name: Create Github Release
6357
id: create_release
6458
uses: actions/create-release@v1

.gitignore

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
target
2-
.gradle
3-
build
1+
target/
2+
.gradle/
3+
build/
44
!ktlint/src/main/resources/config/.idea
5-
/.idea
5+
/.idea/
66
*.iml
7-
out
7+
out/
88
.DS_Store
9+
10+
# Vim swap files
11+
*.swp

diktat-rules/pom.xml

+67
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,73 @@
161161
</arguments>
162162
</configuration>
163163
</plugin>
164+
165+
<plugin>
166+
<groupId>org.apache.maven.plugins</groupId>
167+
<artifactId>maven-jar-plugin</artifactId>
168+
<executions>
169+
<!-- Don't produce the JAR during the `package` phase. -->
170+
<execution>
171+
<id>default-jar</id>
172+
<phase>none</phase>
173+
</execution>
174+
<!-- Instead, create it immediately before the `test` phase
175+
so that the shade plug-in may use it. -->
176+
<execution>
177+
<id>fat-jar-for-smoke-tests</id>
178+
<phase>process-test-classes</phase>
179+
<goals>
180+
<goal>jar</goal>
181+
</goals>
182+
</execution>
183+
</executions>
184+
</plugin>
185+
186+
<!-- Create a fat JAR to be used in smoke tests, removing the
187+
circular dependency between `diktat-rules` and `diktat-ruleset`. -->
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-shade-plugin</artifactId>
191+
<version>3.3.0</version>
192+
<configuration>
193+
<!-- Suppress the generation of `dependency-reduced-pom.xml`,
194+
because it will also get installed under `~/.m2`,
195+
resulting in the `diktat-maven-plugin` build failure
196+
(the plug-in depends on `diktat-rules`). -->
197+
<createDependencyReducedPom>false</createDependencyReducedPom>
198+
<!-- Should be `false`: otherwise, the generated JAR, even
199+
with a custom classifier, will still be installed/deployed. -->
200+
<shadedArtifactAttached>false</shadedArtifactAttached>
201+
<!-- Necessary: otherwise, the artifact produced by the JAR
202+
plug-in will be overwritten by the fat JAR. -->
203+
<finalName>${project.name}-${project.version}-fat-jar-for-smoke-tests</finalName>
204+
<artifactSet>
205+
<excludes>
206+
<exclude>com.squareup:kotlinpoet</exclude>
207+
<exclude>net.java.dev.jna:jna</exclude>
208+
<exclude>org.jetbrains.intellij.deps:trove4j</exclude>
209+
<exclude>org.jetbrains.kotlin:kotlin-compiler-embeddable</exclude>
210+
<exclude>org.jetbrains.kotlin:kotlin-daemon-embeddable</exclude>
211+
<exclude>org.jetbrains.kotlin:kotlin-reflect</exclude>
212+
<exclude>org.jetbrains.kotlin:kotlin-script-runtime</exclude>
213+
<exclude>org.jetbrains.kotlin:kotlin-stdlib-common</exclude>
214+
<exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk7</exclude>
215+
<exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk8</exclude>
216+
<exclude>org.jetbrains.kotlin:kotlin-stdlib</exclude>
217+
<exclude>org.jetbrains:annotations</exclude>
218+
</excludes>
219+
</artifactSet>
220+
</configuration>
221+
<executions>
222+
<execution>
223+
<id>fat-jar-for-smoke-tests</id>
224+
<phase>process-test-classes</phase>
225+
<goals>
226+
<goal>shade</goal>
227+
</goals>
228+
</execution>
229+
</executions>
230+
</plugin>
164231
</plugins>
165232
</build>
166233

diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.cqfn.diktat.util.prependPath
88
import org.cqfn.diktat.util.retry
99

1010
import mu.KotlinLogging
11+
import org.assertj.core.api.Assertions.assertThat
1112
import org.assertj.core.api.Assertions.fail
1213
import org.assertj.core.api.SoftAssertions.assertSoftly
1314
import org.junit.jupiter.api.AfterAll
@@ -101,6 +102,10 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
101102
companion object {
102103
private const val KTLINT_VERSION = "0.46.1"
103104

105+
private const val BUILD_DIRECTORY = "target"
106+
107+
private const val FAT_JAR_GLOB = "diktat-rules-*-fat-jar-for-smoke-tests.jar"
108+
104109
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
105110
private val logger = KotlinLogging.loggerWithKtlintConfig { }
106111
private val baseDirectory = Path("src/test/resources/test/smoke").absolute()
@@ -164,22 +169,28 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
164169
"The base directory for the smoke test is $baseDirectory."
165170
}
166171

167-
val diktatDir: String =
168-
Path("../diktat-ruleset/target")
169-
.takeIf { it.exists() }
170-
?.listDirectoryEntries()
171-
?.single { it.name.contains("diktat") }
172-
?.pathString ?: ""
172+
/*
173+
* The fat JAR should reside in the same directory as `ktlint` and
174+
* `save*` and be named `diktat.jar`
175+
* (see `diktat-rules/src/test/resources/test/smoke/save.toml`).
176+
*/
177+
val diktatFrom = Path(BUILD_DIRECTORY)
178+
.takeIf(Path::exists)
179+
?.listDirectoryEntries(FAT_JAR_GLOB)
180+
?.singleOrNull()
181+
assertThat(diktatFrom)
182+
.describedAs(diktatFrom?.toString() ?: "$BUILD_DIRECTORY/$FAT_JAR_GLOB")
183+
.isNotNull
184+
.isRegularFile
173185

174-
val diktatFrom = Path(diktatDir)
175186
val diktat = baseDirectory / "diktat.jar"
176187
val save = baseDirectory / getSaveForCurrentOs()
177188
val ktlint = baseDirectory / "ktlint"
178189

179190
downloadFile(URL("https://github.com/saveourtool/save-cli/releases/download/v$SAVE_VERSION/${getSaveForCurrentOs()}"), save)
180191
downloadFile(URL("https://github.com/pinterest/ktlint/releases/download/$KTLINT_VERSION/ktlint"), ktlint)
181192

182-
diktatFrom.copyTo(diktat)
193+
diktatFrom?.copyTo(diktat)
183194
}
184195

185196
@AfterAll

diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ open class FixTestBase(
6969
val systemName = System.getProperty("os.name")
7070
val result = when {
7171
systemName.startsWith("Linux", ignoreCase = true) || systemName.startsWith("Mac", ignoreCase = true) ->
72-
ProcessBuilder("sh", "-c", "chmod 777 $savePath ; ./$savePath src/test/resources/test/smoke/src/main/kotlin $testPath --log all")
73-
else -> ProcessBuilder(savePath, "src/test/resources/test/smoke/src/main/kotlin", testPath)
72+
ProcessBuilder("sh", "-c", "chmod 777 $savePath ; ./$savePath $filesDir/src/main/kotlin $testPath --log all")
73+
else -> ProcessBuilder(savePath, "$filesDir/src/main/kotlin", testPath)
7474
}
7575
return result
7676
}

0 commit comments

Comments
 (0)