Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crd-generator): Add CRD-Generator Maven plugin #5979

Merged
merged 40 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f6040bd
feat(crd-generator): Add CRD-Generator Maven plugin
baloo42 Apr 25, 2024
4057f67
Add crd-generator-collector module
baloo42 May 3, 2024
d4b7f2a
Refactor crd-generator-maven-plugin to use collector module
baloo42 May 3, 2024
1dce59e
Adjusted log levels and allow to force create indices
baloo42 May 3, 2024
dbc1153
Enable parallel by default in crd-generator maven plugin
baloo42 May 3, 2024
f4a6028
Remove not necessary classes from base index
baloo42 May 3, 2024
d7be6a6
Cleanup
baloo42 May 3, 2024
ff1b97d
More cleanup
baloo42 May 3, 2024
a283857
Fix base index (must also include CustomResource)
baloo42 May 3, 2024
9ab5fac
Fix includes/excludes and some code smells
baloo42 May 4, 2024
9125a0a
Add CustomResourceCollector tests
baloo42 May 4, 2024
85fcc91
Cleanup, add tests and fix code smells
baloo42 May 7, 2024
f91de1c
Add tests for crd-generator-maven-plugin and fix code smells
baloo42 May 8, 2024
ef4fe25
Fix code smells
baloo42 May 8, 2024
9ed611c
Remove high level filtering and return an array of cr classes instead…
baloo42 May 8, 2024
b536658
Refactor Jandex utility methods to be more reusable
baloo42 May 9, 2024
b0eef86
Polish var names, add javadoc, improve error handling, refactor tests
baloo42 May 10, 2024
c47fe6d
Fix CrdGeneratorMojoTest
baloo42 May 12, 2024
c7d2ab9
Fix code smells
baloo42 May 12, 2024
9e85e4b
Try to fix tests
baloo42 May 12, 2024
e227f15
Use same jandex version for core module and maven plugin
baloo42 May 13, 2024
cc18c80
Add README for crd-generator maven plugin
baloo42 May 14, 2024
e1c768b
Fix README
baloo42 May 15, 2024
e8c881f
Add integration tests using maven-invoker plugin
baloo42 May 15, 2024
818d37f
Add more integration tests and verify content
baloo42 May 15, 2024
db4c6a2
Add integration tests for intermediate custom resource classes
baloo42 May 15, 2024
0fc55ed
Remove CrdGeneratorMojoTest - already covered by integration test
baloo42 May 15, 2024
fe68d5d
Fix ClasspathTypeTest
baloo42 May 15, 2024
0c6a349
Fix groovy files formatting
baloo42 May 16, 2024
25d34f0
Fix version after rebase
baloo42 May 30, 2024
b5ebcac
Reimplement integration tests to be OS independent
baloo42 May 30, 2024
82677b9
Add collection input methods to CRDGenerator
baloo42 May 31, 2024
f5dac69
Refactor CustomResourceCollector to use only a list as output
baloo42 May 31, 2024
9551136
Fix integration tests for Java 8
baloo42 Jul 2, 2024
bcf601d
Make file comparison in integration tests OS independent
baloo42 Jul 3, 2024
b1ce3de
Add groovy formatter settings to parent pom and remove crd-generator …
baloo42 Jul 3, 2024
02976f1
Make reset methods package-private
baloo42 Jul 3, 2024
f10f525
Add @SuppressWarnings("UnusedReturnValue") to get rid of all warnings
baloo42 Jul 3, 2024
b9a8534
Improve log message
baloo42 Jul 3, 2024
04228c9
Fix jandex version after rebase
baloo42 Aug 27, 2024
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
Prev Previous commit
Next Next commit
Add @SuppressWarnings("UnusedReturnValue") to get rid of all warnings
baloo42 authored and manusa committed Aug 30, 2024
commit f10f52568f7be554041fb55dde20d375583bbb3f
Original file line number Diff line number Diff line change
@@ -43,18 +43,21 @@ class CustomResourceClassLoader {

private ClassLoader cachedClassLoader;

@SuppressWarnings("UnusedReturnValue")
public CustomResourceClassLoader withParentClassLoader(ClassLoader parentClassLoader) {
this.parentClassLoader = parentClassLoader;
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceClassLoader withClasspathElement(String... classpathElements) {
if (classpathElements != null) {
withClasspathElements(Arrays.asList(classpathElements));
}
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceClassLoader withClasspathElements(Collection<String> classpathElements) {
if (classpathElements != null) {
classpathElements.stream()
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ public CustomResourceCollector withParentClassLoader(ClassLoader classLoader) {
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceCollector withClasspathElement(String... classpathElement) {
this.customResourceClassLoader.withClasspathElement(classpathElement);
return this;
@@ -79,13 +80,15 @@ public CustomResourceCollector withClasspathElements(Collection<String> classpat
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceCollector withCustomResourceClass(String... className) {
if (className != null) {
withCustomResourceClasses(Arrays.asList(className));
}
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceCollector withCustomResourceClasses(Collection<String> classNames) {
if (classNames != null) {
classNames.stream()
@@ -95,11 +98,13 @@ public CustomResourceCollector withCustomResourceClasses(Collection<String> clas
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceCollector withIndex(IndexView... index) {
jandexCustomResourceClassScanner.withIndex(index);
return this;
}

@SuppressWarnings("UnusedReturnValue")
public CustomResourceCollector withIndices(Collection<IndexView> indices) {
jandexCustomResourceClassScanner.withIndices(indices);
return this;
Original file line number Diff line number Diff line change
@@ -58,18 +58,21 @@ public class JandexCustomResourceClassScanner {
*/
private boolean forceIndex = false;

@SuppressWarnings("UnusedReturnValue")
public JandexCustomResourceClassScanner withForceIndex(boolean forceIndex) {
this.forceIndex = forceIndex;
return this;
}

@SuppressWarnings("UnusedReturnValue")
public JandexCustomResourceClassScanner withIndex(IndexView... index) {
if (index != null) {
withIndices(Arrays.asList(index));
}
return this;
}

@SuppressWarnings("UnusedReturnValue")
public JandexCustomResourceClassScanner withIndices(Collection<IndexView> indices) {
if (indices != null) {
indices.stream()
@@ -79,13 +82,15 @@ public JandexCustomResourceClassScanner withIndices(Collection<IndexView> indice
return this;
}

@SuppressWarnings("UnusedReturnValue")
public JandexCustomResourceClassScanner withFileToScan(File... files) {
if (files != null) {
withFilesToScan(Arrays.asList(files));
}
return this;
}

@SuppressWarnings("UnusedReturnValue")
public JandexCustomResourceClassScanner withFilesToScan(Collection<File> files) {
if (files != null) {
files.stream()
Original file line number Diff line number Diff line change
@@ -52,20 +52,23 @@ class JandexIndexer {
private long maxBytesReadFromJar = 100000000; // 100 MB
private long maxClassFileSize = 1000000; // 1 MB
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need limits?

Copy link
Member

@manusa manusa Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem reasonable limits.
We can keep it this way.
If users complain, then we can make this configurable in a future release (at the Mojo level).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's keep it.

Just as a note:
I'm a little bit unsure if those checks make sense overall...
I mean, if a project cannot trust it's dependencies, then the project has more problems than those from a zip bomb. But if we think towards the CRD-Generator CLI, it's some kind of own input validation and kind of useful.


@SuppressWarnings("UnusedReturnValue")
public JandexIndexer withMaxJarEntries(int maxJarEntries) {
if (maxJarEntries < 1)
throw new IllegalArgumentException("maxJarEntries must be greater than 0");
this.maxJarEntries = maxJarEntries;
return this;
}

@SuppressWarnings("UnusedReturnValue")
public JandexIndexer withMaxClassFileSize(int maxClassFileSize) {
if (maxClassFileSize < 10)
throw new IllegalArgumentException("maxClassFileSize must be greater than 10");
this.maxClassFileSize = maxClassFileSize;
return this;
}

@SuppressWarnings("UnusedReturnValue")
public JandexIndexer withMaxBytesReadFromJar(long maxBytesReadFromJar) {
if (maxBytesReadFromJar < 10)
throw new IllegalArgumentException("maxBytesReadFromJar must be greater than 10");
@@ -161,6 +164,7 @@ private long addToIndex(JarFile zip, JarEntry entry, Indexer indexer) {
}
}

@SuppressWarnings("UnusedReturnValue")
private long addToIndex(Path file, Indexer indexer) {
try (InputStream in = Files.newInputStream(file)) {
return addToIndex(in, indexer);