Skip to content

Commit

Permalink
✨ customize terminal logger #144
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Oct 19, 2023
1 parent ace5569 commit b2e7675
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Contract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.fessional.meepo.Meepo;
Expand Down Expand Up @@ -87,28 +88,33 @@ public static class Builder {
private String pkg;
private final Map<String, Boolean> flt = new HashMap<>();

@Contract("_->this")
public Builder targetDirectory(File src) {
this.src = src;
return this;
}

@Contract("_->this")
public Builder targetDirectory(String src) {
this.src = new File(src);
return this;
}

@Contract("_->this")
public Builder targetPackage(String pkg) {
this.pkg = pkg;
return this;
}

@Contract("_->this")
public Builder excludeType(String... typ) {
for (String s : typ) {
this.flt.put(s, Boolean.FALSE);
}
return this;
}

@Contract("_->this")
public Builder includeType(String... typ) {
for (String s : typ) {
this.flt.put(s, Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pro.fessional.wings.faceless.jooqgen;

import lombok.val;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jooq.Converter;
import org.jooq.codegen.GenerationTool;
import org.jooq.meta.TableDefinition;
Expand Down Expand Up @@ -90,18 +92,22 @@ public class WingsCodeGenerator {
}


@NotNull
public static Builder builder() {
return builder(config());
}

@NotNull
public static Builder builder(Configuration conf) {
return new Builder(conf == null ? config() : conf);
}

@NotNull
public static Configuration config() {
return config(WingsCodeGenerator.class.getResourceAsStream(JOOQ_XML));
}

@NotNull
public static Configuration config(InputStream ins) {
Objects.requireNonNull(ins);
try (ins) {
Expand Down Expand Up @@ -197,16 +203,19 @@ public Builder(Configuration conf) {
/**
* Whether to generate incrementally. That is, not to delete files that do not exist in this time.
*/
@Contract("_->this")
public Builder incremental(boolean t) {
incr = t;
return this;
}

@Contract("_->this")
public Builder setGlobalSuffix(String suffix) {
this.suffix = suffix;
return this;
}

@Contract("_->this")
public Builder setLiveDataByMax(boolean asMax) {
WingsCodeGenConf.setLiveDataByMax(asMax);
return this;
Expand All @@ -223,23 +232,27 @@ public Configuration configuration() {
return conf;
}

@Contract("_->this")
public Builder springRepository(boolean b) {
this.conf.getGenerator().getGenerate().withSpringAnnotations(b);
return this;
}

@Contract("->this")
public Builder h2() {
jdbcDriver("org.h2.Driver");
databaseName("org.jooq.meta.h2.H2Database");
databaseSchema("PUBLIC");
return this;
}

@Contract("_->this")
public Builder jdbcDriver(String str) {
this.conf.getJdbc().setDriver(str);
return this;
}

@Contract("_->this")
public Builder jdbcUrl(String str) {
this.conf.getJdbc().setUrl(str);
if (str.contains(":h2:")) {
Expand All @@ -258,26 +271,31 @@ public Builder jdbcUrl(String str) {
return this;
}

@Contract("_->this")
public Builder jdbcUser(String str) {
this.conf.getJdbc().setUser(str);
return this;
}

@Contract("_->this")
public Builder jdbcPassword(String str) {
this.conf.getJdbc().setPassword(str);
return this;
}

@Contract("_->this")
public Builder targetPackage(String str) {
this.conf.getGenerator().getTarget().setPackageName(str);
return this;
}

@Contract("_->this")
public Builder targetDirectory(String str) {
this.conf.getGenerator().getTarget().setDirectory(str);
return this;
}

@Contract("_->this")
public Builder databaseSchema(String str) {
this.conf.getGenerator().getDatabase().setInputSchema(str);
return this;
Expand Down Expand Up @@ -317,6 +335,7 @@ public Builder databaseSchema(String str) {
* @param str AbstractDatabase
* @return Builder
*/
@Contract("_->this")
public Builder databaseName(String str) {
this.conf.getGenerator().getDatabase().setName(str);
return this;
Expand Down Expand Up @@ -349,6 +368,7 @@ public Builder databaseIncludes(String... reg) {
/**
* append or replace configuration/generator/database/includes
*/
@Contract("_,_->this")
public Builder databaseIncludes(boolean append, String... reg) {
final String join = String.join("|", reg);
final Database db = this.conf.getGenerator().getDatabase();
Expand All @@ -374,13 +394,15 @@ public Builder databaseIncludes(boolean append, String... reg) {
* @return Builder
* @see Pattern#COMMENTS
*/
@Contract("_->this")
public Builder databaseExcludes(String... reg) {
return databaseExcludes(false, reg);
}

/**
* append or replace configuration/generator/database/excludes
*/
@Contract("_,_->this")
public Builder databaseExcludes(boolean append, String... reg) {
final String join = String.join("|", reg);
final Database db = this.conf.getGenerator().getDatabase();
Expand Down Expand Up @@ -415,6 +437,7 @@ public Builder databaseExcludes(boolean append, String... reg) {
* @param str sql
* @return Builder
*/
@Contract("_->this")
public Builder databaseVersionProvider(String str) {
this.conf.getGenerator().getDatabase().setSchemaVersionProvider(str);
return this;
Expand All @@ -425,24 +448,28 @@ public Builder databaseVersionProvider(String str) {
*
* @return Builder
*/
@Contract("->this")
public Builder forceRegenerate() {
this.conf.getGenerator().getDatabase().setSchemaVersionProvider(Null.Str);
return this;
}

@Contract("_,_->this")
public Builder forcedType(String name, String type) {
ForcedType ft = new ForcedType();
ft.setName(name);
ft.setIncludeTypes(type);
return forcedType(ft);
}

@Contract("_->this")
public Builder forcedType(ForcedType... ft) {
final List<ForcedType> fts = this.conf.getGenerator().getDatabase().getForcedTypes();
fts.addAll(Arrays.asList(ft));
return this;
}

@Contract("_,_,_->this")
public Builder forcedType(Class<?> userType, Class<? extends Converter<?, ?>> converter, String... reg) {
ForcedType ft = new ForcedType()
.withUserType(userType.getName())
Expand All @@ -459,23 +486,28 @@ public Builder forcedType(Class<?> userType, Class<? extends Converter<?, ?>> co
* @param sortImport Replacing fully qualified references with import is only valid for wingsGenerator.
* @return this
*/
@Contract("_,_->this")
public Builder forcedType(ForcedType ft, String sortImport) {
WingsCodeGenConf.shortImport4Table(sortImport);
return forcedType(ft);
}

@Contract("_,_->this")
public <E extends Enum<E> & CodeEnum> Builder forcedStrCodeEnum(Class<E> en, String... reg) {
return forcedJooqEnum(en, JooqCodeEnumConverter.class, reg);
}

@Contract("_,_->this")
public <E extends Enum<E> & ConstantEnum> Builder forcedIntConsEnum(Class<E> en, String... reg) {
return forcedJooqEnum(en, JooqConsEnumConverter.class, reg);
}

@Contract("_->this")
public Builder forcedLocale(String... reg) {
return forcedType(Locale.class, JooqLocaleConverter.class, reg);
}

@Contract("_->this")
public Builder forcedZoneId(String... reg) {
final String zid = ZoneId.class.getName();
final String exp = String.join("|", reg);
Expand All @@ -492,12 +524,14 @@ public Builder forcedZoneId(String... reg) {
return forcedType(ft1, ft2);
}

@Contract("_->this")
public Builder funSeqName(Function<TableDefinition, String> fn) {
WingsJooqGenHelper.funSeqName.set(fn);
return this;
}

//
@Contract("_,_,_->this")
private <E extends Enum<E>> Builder forcedJooqEnum(Class<E> userType, Class<?> converter, String... reg) {
final String cv = converter.getName();
ForcedType ft = new ForcedType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ public Helper exclude(String info, Predicate<Long> exc) {
return this;
}

@NotNull
public SortedMap<Long, RevisionSql> scan() {

TreeMap<Long, RevisionSql> result = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pro.fessional.wings.faceless.database;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.MetaDataAccessException;
Expand Down Expand Up @@ -30,23 +31,27 @@ public DataSource getCurrent() {
return current;
}

@Contract("_->this")
public DataSourceContext setCurrent(DataSource current) {
this.current = current;
return this;
}

@Contract("->this")
public DataSourceContext clearBackend() {
backendMap.clear();
return this;
}

@Contract("_,_->this")
public DataSourceContext addBackend(String name, DataSource ds) {
if (name != null && ds != null) {
backendMap.put(name, ds);
}
return this;
}

@Contract("_->this")
public DataSourceContext addBackend(Map<String, DataSource> map) {
if (map != null) {
backendMap.putAll(map);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pro.fessional.wings.slardar.spring.conf;

import org.jetbrains.annotations.Contract;
import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsAwareConfigurer;
Expand All @@ -21,31 +22,37 @@ public class WingsBindAuthnConfigurer<U extends UserDetailsService> extends User
private WingsAuthCheckService wingsAuthCheckService;
private boolean wingsBindAuthnProvider = true;

@Contract("_->this")
public WingsBindAuthnConfigurer<U> userDetailsService(U userDetailsService) {
this.userDetailsService = userDetailsService;
return this;
}

@Contract("_->this")
public WingsBindAuthnConfigurer<U> withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor) {
addObjectPostProcessor(objectPostProcessor);
return this;
}

@Contract("_->this")
public WingsBindAuthnConfigurer<U> passwordEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
return this;
}

@Contract("_->this")
public WingsBindAuthnConfigurer<U> userDetailsPasswordManager(UserDetailsPasswordService passwordManager) {
this.userDetailsPasswordService = passwordManager;
return this;
}

@Contract("_->this")
public WingsBindAuthnConfigurer<U> wingsBindAuthnProvider(boolean bool) {
this.wingsBindAuthnProvider = bool;
return this;
}

@Contract("_->this")
public WingsBindAuthnConfigurer<U> wingsAuthCheckService(WingsAuthCheckService wingsAuthCheckService) {
this.wingsAuthCheckService = wingsAuthCheckService;
return this;
Expand Down
Loading

0 comments on commit b2e7675

Please sign in to comment.