Skip to content

Commit a3e2d84

Browse files
authored
[Simplify] Clean-up and add missing entry point values (#39)
This has some small clean-ups before running Konvert on the EntryPointOptions type. Extracted from #29
1 parent cd3dab6 commit a3e2d84

File tree

2 files changed

+63
-34
lines changed

2 files changed

+63
-34
lines changed

src/main/groovy/org/assertj/generator/gradle/tasks/AssertJGenerationTask.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ class AssertJGenerationTask extends SourceTask {
173173
}
174174
}
175175

176-
if (!inputClassesToFile.empty) {
176+
if (!inputClassesToFile.isEmpty()) {
177177
// only generate the entry points if there are classes that have changed (or exist..)
178-
for (assertionsEntryPointType in assertJOptions.entryPoints) {
178+
for (assertionsEntryPointType in assertJOptions.entryPoints.entryPoints) {
179179
File assertionsEntryPointFile = generator.generateAssertionsEntryPointClassFor(
180180
classDescriptions,
181181
assertionsEntryPointType,
Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017. assertj-generator-gradle-plugin contributors.
2+
* Copyright 2023. assertj-generator-gradle-plugin contributors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -12,7 +12,7 @@
1212
*/
1313
package org.assertj.generator.gradle.tasks.config
1414

15-
import com.google.common.collect.Iterators
15+
1616
import groovy.transform.EqualsAndHashCode
1717
import org.assertj.assertions.generator.AssertionsEntryPointType
1818

@@ -23,11 +23,13 @@ import java.util.stream.Collectors
2323
* way when configuring.
2424
*/
2525
@EqualsAndHashCode
26-
class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>, Serializable {
26+
class EntryPointGeneratorOptions {
27+
28+
private final Set<AssertionsEntryPointType> _entryPoints = EnumSet.of(AssertionsEntryPointType.STANDARD)
2729

28-
// Ideally, this should be final, however due to the way ObjectInputStream works we have to make it
29-
// non-final and reassign it. The default initialization is never called :(
30-
private Set<AssertionsEntryPointType> entryPoints = EnumSet.of(AssertionsEntryPointType.STANDARD)
30+
Set<AssertionsEntryPointType> getEntryPoints() {
31+
_entryPoints.asImmutable()
32+
}
3133

3234
/**
3335
* An optional package name for the Assertions entry point class. If omitted, the package will be determined
@@ -36,36 +38,31 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
3638
*/
3739
String classPackage
3840

39-
@Override
40-
Iterator<AssertionsEntryPointType> iterator() {
41-
Iterators.unmodifiableIterator(entryPoints.iterator())
42-
}
43-
4441
private void forEnum(boolean value, AssertionsEntryPointType e) {
4542
if (value) {
46-
entryPoints.add(e)
43+
_entryPoints.add(e)
4744
} else {
48-
entryPoints.remove(e)
45+
_entryPoints.remove(e)
4946
}
5047
}
5148

5249
void only(AssertionsEntryPointType... rest) {
53-
entryPoints.clear()
50+
_entryPoints.clear()
5451

55-
entryPoints.addAll(rest.toList())
52+
_entryPoints.addAll(rest.toList())
5653
}
5754

5855
void only(String... rest) {
59-
Set<AssertionsEntryPointType> asEnums = Arrays.stream(rest)
56+
def asEnums = Arrays.stream(rest)
6057
.map { it.toUpperCase() }
6158
.map { AssertionsEntryPointType.valueOf(it) }
6259
.collect(Collectors.toSet())
6360

64-
only(asEnums.toArray(new AssertionsEntryPointType[0]))
61+
only(asEnums as AssertionsEntryPointType[])
6562
}
6663

6764
/**
68-
* Generate Assertions entry point class.
65+
* @see AssertionsEntryPointType#STANDARD
6966
*/
7067
boolean getStandard() {
7168
entryPoints.contains(AssertionsEntryPointType.STANDARD)
@@ -76,7 +73,7 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
7673
}
7774

7875
/**
79-
* Generate generating BDD Assertions entry point class.
76+
* @see AssertionsEntryPointType#BDD
8077
*/
8178
boolean getBdd() {
8279
entryPoints.contains(AssertionsEntryPointType.BDD)
@@ -87,7 +84,29 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
8784
}
8885

8986
/**
90-
* Generate generating JUnit Soft Assertions entry point class.
87+
* @see AssertionsEntryPointType#SOFT
88+
*/
89+
boolean getSoft() {
90+
entryPoints.contains(AssertionsEntryPointType.SOFT)
91+
}
92+
93+
void setSoft(boolean value) {
94+
forEnum(value, AssertionsEntryPointType.SOFT)
95+
}
96+
97+
/**
98+
* @see AssertionsEntryPointType#BDD_SOFT
99+
*/
100+
boolean getBddSoft() {
101+
entryPoints.contains(AssertionsEntryPointType.BDD_SOFT)
102+
}
103+
104+
void setBddSoft(boolean value) {
105+
forEnum(value, AssertionsEntryPointType.BDD_SOFT)
106+
}
107+
108+
/**
109+
* @see AssertionsEntryPointType#JUNIT_SOFT
91110
*/
92111
boolean getJunitSoft() {
93112
entryPoints.contains(AssertionsEntryPointType.JUNIT_SOFT)
@@ -98,25 +117,35 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
98117
}
99118

100119
/**
101-
* Generate generating Soft Assertions entry point class.
120+
* @see AssertionsEntryPointType#JUNIT_BDD_SOFT
102121
*/
103-
boolean getSoft() {
104-
entryPoints.contains(AssertionsEntryPointType.SOFT)
122+
boolean getJunitBddSoft() {
123+
entryPoints.contains(AssertionsEntryPointType.JUNIT_BDD_SOFT)
105124
}
106125

107-
void setSoft(boolean value) {
108-
forEnum(value, AssertionsEntryPointType.SOFT)
126+
void setJunitBddSoft(boolean value) {
127+
forEnum(value, AssertionsEntryPointType.JUNIT_BDD_SOFT)
128+
}
129+
130+
/**
131+
* @see AssertionsEntryPointType#AUTO_CLOSEABLE_SOFT
132+
*/
133+
boolean getAutoCloseableSoft() {
134+
entryPoints.contains(AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT)
109135
}
110136

111-
private void writeObject(ObjectOutputStream s) throws IOException {
112-
s.writeObject(entryPoints)
113-
s.writeObject(classPackage)
137+
void setAutoCloseableSoft(boolean value) {
138+
forEnum(value, AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT)
114139
}
115140

116-
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
117-
Set<AssertionsEntryPointType> typesFromStream = (Set<AssertionsEntryPointType>) s.readObject()
118-
this.entryPoints = typesFromStream
141+
/**
142+
* @see AssertionsEntryPointType#AUTO_CLOSEABLE_BDD_SOFT
143+
*/
144+
boolean getAutoCloseableBddSoft() {
145+
entryPoints.contains(AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT)
146+
}
119147

120-
classPackage = (String) s.readObject()
148+
void setAutoCloseableBddSoft(boolean value) {
149+
forEnum(value, AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT)
121150
}
122151
}

0 commit comments

Comments
 (0)