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

[Simplify] Clean-up and add missing entry point values #39

Merged
merged 1 commit into from
Apr 23, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ class AssertJGenerationTask extends SourceTask {
}
}

if (!inputClassesToFile.empty) {
if (!inputClassesToFile.isEmpty()) {
// only generate the entry points if there are classes that have changed (or exist..)
for (assertionsEntryPointType in assertJOptions.entryPoints) {
for (assertionsEntryPointType in assertJOptions.entryPoints.entryPoints) {
File assertionsEntryPointFile = generator.generateAssertionsEntryPointClassFor(
classDescriptions,
assertionsEntryPointType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017. assertj-generator-gradle-plugin contributors.
* Copyright 2023. assertj-generator-gradle-plugin contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -12,7 +12,7 @@
*/
package org.assertj.generator.gradle.tasks.config

import com.google.common.collect.Iterators

import groovy.transform.EqualsAndHashCode
import org.assertj.assertions.generator.AssertionsEntryPointType

Expand All @@ -23,11 +23,13 @@ import java.util.stream.Collectors
* way when configuring.
*/
@EqualsAndHashCode
class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>, Serializable {
class EntryPointGeneratorOptions {

private final Set<AssertionsEntryPointType> _entryPoints = EnumSet.of(AssertionsEntryPointType.STANDARD)

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

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

@Override
Iterator<AssertionsEntryPointType> iterator() {
Iterators.unmodifiableIterator(entryPoints.iterator())
}

private void forEnum(boolean value, AssertionsEntryPointType e) {
if (value) {
entryPoints.add(e)
_entryPoints.add(e)
} else {
entryPoints.remove(e)
_entryPoints.remove(e)
}
}

void only(AssertionsEntryPointType... rest) {
entryPoints.clear()
_entryPoints.clear()

entryPoints.addAll(rest.toList())
_entryPoints.addAll(rest.toList())
}

void only(String... rest) {
Set<AssertionsEntryPointType> asEnums = Arrays.stream(rest)
def asEnums = Arrays.stream(rest)
.map { it.toUpperCase() }
.map { AssertionsEntryPointType.valueOf(it) }
.collect(Collectors.toSet())

only(asEnums.toArray(new AssertionsEntryPointType[0]))
only(asEnums as AssertionsEntryPointType[])
}

/**
* Generate Assertions entry point class.
* @see AssertionsEntryPointType#STANDARD
*/
boolean getStandard() {
entryPoints.contains(AssertionsEntryPointType.STANDARD)
Expand All @@ -76,7 +73,7 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
}

/**
* Generate generating BDD Assertions entry point class.
* @see AssertionsEntryPointType#BDD
*/
boolean getBdd() {
entryPoints.contains(AssertionsEntryPointType.BDD)
Expand All @@ -87,7 +84,29 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
}

/**
* Generate generating JUnit Soft Assertions entry point class.
* @see AssertionsEntryPointType#SOFT
*/
boolean getSoft() {
entryPoints.contains(AssertionsEntryPointType.SOFT)
}

void setSoft(boolean value) {
forEnum(value, AssertionsEntryPointType.SOFT)
}

/**
* @see AssertionsEntryPointType#BDD_SOFT
*/
boolean getBddSoft() {
entryPoints.contains(AssertionsEntryPointType.BDD_SOFT)
}

void setBddSoft(boolean value) {
forEnum(value, AssertionsEntryPointType.BDD_SOFT)
}

/**
* @see AssertionsEntryPointType#JUNIT_SOFT
*/
boolean getJunitSoft() {
entryPoints.contains(AssertionsEntryPointType.JUNIT_SOFT)
Expand All @@ -98,25 +117,35 @@ class EntryPointGeneratorOptions implements Iterable<AssertionsEntryPointType>,
}

/**
* Generate generating Soft Assertions entry point class.
* @see AssertionsEntryPointType#JUNIT_BDD_SOFT
*/
boolean getSoft() {
entryPoints.contains(AssertionsEntryPointType.SOFT)
boolean getJunitBddSoft() {
entryPoints.contains(AssertionsEntryPointType.JUNIT_BDD_SOFT)
}

void setSoft(boolean value) {
forEnum(value, AssertionsEntryPointType.SOFT)
void setJunitBddSoft(boolean value) {
forEnum(value, AssertionsEntryPointType.JUNIT_BDD_SOFT)
}

/**
* @see AssertionsEntryPointType#AUTO_CLOSEABLE_SOFT
*/
boolean getAutoCloseableSoft() {
entryPoints.contains(AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT)
}

private void writeObject(ObjectOutputStream s) throws IOException {
s.writeObject(entryPoints)
s.writeObject(classPackage)
void setAutoCloseableSoft(boolean value) {
forEnum(value, AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT)
}

private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
Set<AssertionsEntryPointType> typesFromStream = (Set<AssertionsEntryPointType>) s.readObject()
this.entryPoints = typesFromStream
/**
* @see AssertionsEntryPointType#AUTO_CLOSEABLE_BDD_SOFT
*/
boolean getAutoCloseableBddSoft() {
entryPoints.contains(AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT)
}

classPackage = (String) s.readObject()
void setAutoCloseableBddSoft(boolean value) {
forEnum(value, AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT)
}
}