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

want to avoid useless imports #104

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 @@ -13,6 +13,7 @@
import org.fugerit.java.daogen.base.config.DaogenCatalogField;
import org.fugerit.java.daogen.base.config.DaogenCatalogRelation;
import org.fugerit.java.daogen.base.config.DaogenClassConfigHelper;
import org.fugerit.java.daogen.base.gen.util.HelperUtils;

public class HelperGenerator extends DaogenBasicGenerator {

Expand Down Expand Up @@ -41,12 +42,8 @@ public void init( DaogenCatalogConfig daogenConfig, DaogenCatalogEntity entity )
} else {
throw new ConfigException( "Invalid "+DaogenCatalogConstants.GEN_PROP_DAO_HELPER_NG_MODE+" parameter : "+daoHelperNgMode );
}
this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+this.getEntityModelName() );
this.setImplementsInterface( this.getEntityModelName() );
for ( DaogenCatalogRelation relation : this.getCurrentEntity().getRelations() ) {
DaogenCatalogEntity entityTo = this.getDaogenConfig().getListMap( relation.getTo() );
this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+DaogenCatalogConstants.modelName( entityTo ) );
}
HelperUtils.checkImportModel( this.getDaogenConfig(), this );
}

private void generateRelations() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.fugerit.java.daogen.base.gen.util;

import org.fugerit.java.daogen.base.config.DaogenCatalogConfig;
import org.fugerit.java.daogen.base.config.DaogenCatalogConstants;
import org.fugerit.java.daogen.base.config.DaogenCatalogEntity;
import org.fugerit.java.daogen.base.config.DaogenCatalogRelation;
import org.fugerit.java.daogen.base.gen.DaogenBasicGenerator;

public class HelperUtils {

private HelperUtils() {}

public static void checkImportModel(DaogenCatalogConfig daogenConfig, DaogenBasicGenerator gen ) {
if ( !daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL ).equals( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_HELPER ) ) ) {
gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+gen.getEntityModelName() );
for ( DaogenCatalogRelation relation : gen.getCurrentEntity().getRelations() ) {
DaogenCatalogEntity entityTo = gen.getDaogenConfig().getListMap( relation.getTo() );
gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+DaogenCatalogConstants.modelName( entityTo ) );
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ public static void init(DaogenCatalogConfig daogenConfig, DaogenCatalogEntity en
} else {
throw new ConfigException( "Invalid "+DaogenCatalogConstants.GEN_PROP_DAO_WRAPPER_NG_MODE+" parameter : "+daoWrapperNgMode );
}
gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+gen.getEntityModelName() );
gen.setImplementsInterface( gen.getEntityModelName() );
for ( DaogenCatalogRelation relation : gen.getCurrentEntity().getRelations() ) {
DaogenCatalogEntity entityTo = gen.getDaogenConfig().getListMap( relation.getTo() );
gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+DaogenCatalogConstants.modelName( entityTo ) );
}
HelperUtils.checkImportModel( daogenConfig, gen );
}

public static void generateRelations(DaogenBasicGenerator gen ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private int testDaoGenerationWorker( File baseDir, Properties overrideProperties
}

@Test
public void testDaoGenerationJdk17SpringBoot() throws IOException, ConfigException {
public void testDaoGenerationJdk17SpringBoot() {
File file = new File( "target/daogen-run-jdk17-sprint-boot" );
Properties overrideProperties = new Properties();
overrideProperties.setProperty(
Expand All @@ -58,7 +58,7 @@ public void testDaoGenerationJdk17SpringBoot() throws IOException, ConfigExcepti
}

@Test
public void testDaoGenerationClassicalEntity() throws IOException, ConfigException {
public void testDaoGenerationClassicalEntity() {
File file = new File( "target/daogen-run-classical-entity" );
Properties overrideProperties = new Properties();
overrideProperties.setProperty(
Expand All @@ -82,7 +82,19 @@ public void testDaoGenerationClassicalEntity() throws IOException, ConfigExcepti
}

@Test
public void testDaoGenerationFailHelperNg() throws IOException, ConfigException {
public void testDaoModelAndHelperInTheSameFolder() {
File file = new File( "target/daogen-run-model-helper-coexists" );
Properties overrideProperties = new Properties();
overrideProperties.setProperty(
DaogenCatalogConstants.GEN_PROP_PACKAGE_HELPER ,
"org.fugerit.java.daogen.sample.def.model");
int result = this.testDaoGenerationWorker(file, overrideProperties);
Assert.assertTrue( file.exists() );
Assert.assertEquals( Result.RESULT_CODE_OK, result );
}

@Test
public void testDaoGenerationFailHelperNg() {
File file = new File( "target/daogen-run-fail-helper-ng" );
Properties overrideProperties = new Properties();
overrideProperties.setProperty(
Expand All @@ -92,7 +104,7 @@ public void testDaoGenerationFailHelperNg() throws IOException, ConfigException
}

@Test
public void testDaoGenerationFailWrapperNg() throws IOException, ConfigException {
public void testDaoGenerationFailWrapperNg() {
File file = new File( "target/daogen-run-fail-wrapper-ng" );
Properties overrideProperties = new Properties();
overrideProperties.setProperty(
Expand All @@ -102,7 +114,7 @@ public void testDaoGenerationFailWrapperNg() throws IOException, ConfigException
}

@Test
public void testDaoGenerationFailFinderNg() throws IOException, ConfigException {
public void testDaoGenerationFailFinderNg() {
File file = new File( "target/daogen-run-fail-finder-ng" );
Properties overrideProperties = new Properties();
overrideProperties.setProperty(
Expand All @@ -112,7 +124,7 @@ public void testDaoGenerationFailFinderNg() throws IOException, ConfigException
}

@Test
public void testDaoGenerationDefault() throws IOException, ConfigException {
public void testDaoGenerationDefault() throws IOException, ConfigException {
File file = new File( "target/daogen-run" );
try ( FileInputStream fis = new FileInputStream( new File( "src/test/resources/sample/daogenruntest-sample-daogen-config.xml" ) ) ) {
log.info( "DAOGEN start!" );
Expand Down
Loading