1414import java .io .FileReader ;
1515import java .io .IOException ;
1616import java .lang .reflect .Type ;
17+ import java .nio .file .Files ;
1718import java .util .Optional ;
1819
1920import org .slf4j .Logger ;
3435 */
3536public class DataRepositoryAotMetadataService {
3637
38+ private static final String MODULE_JSON_PROP = "module" ;
39+
40+ private static final String TYPE_JSON_PROP = "type" ;
41+
42+ private static final String NAME_JSON_PROP = "name" ;
43+
44+ private static final String METHODS = "methods" ;
45+
3746 private static final Logger log = LoggerFactory .getLogger (DataRepositoryAotMetadataService .class );
3847
3948 final private Gson gson = new GsonBuilder ().registerTypeAdapter (DataRepositoryAotMetadata .class , new JsonDeserializer <DataRepositoryAotMetadata >() {
@@ -42,17 +51,17 @@ public class DataRepositoryAotMetadataService {
4251 public DataRepositoryAotMetadata deserialize (JsonElement json , Type typeOfT ,
4352 JsonDeserializationContext context ) throws JsonParseException {
4453 JsonObject o = json .getAsJsonObject ();
45- JsonElement e = o .get ("module" );
54+ JsonElement e = o .get (MODULE_JSON_PROP );
4655 if (e .isJsonPrimitive ()) {
4756 String module = e .getAsString ();
48- String name = context .deserialize (o .get ("name" ), String .class );
49- String type = context .deserialize (o .get ("type" ), String .class );
57+ String name = context .deserialize (o .get (NAME_JSON_PROP ), String .class );
58+ String type = context .deserialize (o .get (TYPE_JSON_PROP ), String .class );
5059 DataRepositoryModule moduleType = DataRepositoryModule .valueOf (module .toUpperCase ());
5160 switch (moduleType ) {
5261 case MONGODB :
53- return new DataRepositoryAotMetadata (name , type , moduleType , context .deserialize (o .get ("methods" ), MongoAotMethodMetadata [].class ));
62+ return new DataRepositoryAotMetadata (name , type , moduleType , context .deserialize (o .get (METHODS ), MongoAotMethodMetadata [].class ));
5463 case JPA :
55- return new DataRepositoryAotMetadata (name , type , moduleType , context .deserialize (o .get ("methods" ), JpaAotMethodMetadata [].class ));
64+ return new DataRepositoryAotMetadata (name , type , moduleType , context .deserialize (o .get (METHODS ), JpaAotMethodMetadata [].class ));
5665 }
5766 }
5867 return null ;
@@ -62,11 +71,12 @@ public DataRepositoryAotMetadata deserialize(JsonElement json, Type typeOfT,
6271
6372 public DataRepositoryAotMetadata getRepositoryMetadata (IJavaProject project , String repositoryType ) {
6473 try {
65- String metadataFilePath = repositoryType .replace ('.' , File . separatorChar ) ;
74+ String metadataFilePath = repositoryType .replace ('.' , '/' ) + ".json" ;
6675
6776 Optional <File > metadataFile = IClasspathUtil .getOutputFolders (project .getClasspath ())
68- .map (outputFolder -> new File (outputFolder .getParentFile (), "spring-aot/main/resources/" + metadataFilePath + ".json" ))
69- .filter (file -> file .exists ())
77+ .map (outputFolder -> outputFolder .getParentFile ().toPath ().resolve ("spring-aot/main/resources/" ).resolve (metadataFilePath ))
78+ .filter (Files ::isRegularFile )
79+ .map (p -> p .toFile ())
7080 .findFirst ();
7181
7282 if (metadataFile .isPresent ()) {
0 commit comments