use of org.bimserver.tools.generators.SServiceGeneratorWrapper in project BIMserver by opensourceBIM.
the class CodeMigrator method start.
private void start() {
LOGGER.info("Starting code migrator...");
Migrator migrator = new Migrator(null);
int latestVersion = migrator.getLatestVersion();
LOGGER.info("Migrating to version " + latestVersion);
Schema schema = migrator.migrateSchemaTo(latestVersion);
schema.writeToEcore(new File("models/models.ecore"));
LOGGER.info("Model migrated to version " + latestVersion);
LOGGER.info("Generating ServiceInterface objects...");
Set<EPackage> ePackages = new LinkedHashSet<EPackage>();
Path home = Paths.get("cmhome");
if (!Files.exists(home)) {
try {
Files.createDirectories(home);
} catch (IOException e) {
e.printStackTrace();
}
}
Path tmp = home.resolve("tmp");
if (!Files.exists(tmp)) {
try {
Files.createDirectories(tmp);
} catch (IOException e) {
e.printStackTrace();
}
}
MetaDataManager metaDataManager = new MetaDataManager(tmp);
metaDataManager.init();
DataObjectGeneratorWrapper serviceGenerator = new DataObjectGeneratorWrapper(metaDataManager);
for (EPackage ePackage : schema.getEPackages()) {
if (!ePackage.getName().equals("ifc2x3tc1") && !ePackage.getName().equals("ifc4")) {
ePackages.add(ePackage);
}
}
serviceGenerator.generateDataObjects(ePackages);
LOGGER.info("ServiceInterface objects successfully generated");
SConverterGeneratorWrapper sConverterGenerator = new SConverterGeneratorWrapper(metaDataManager);
sConverterGenerator.generate(ePackages);
SServiceGeneratorWrapper serviceGeneratorWrapper = new SServiceGeneratorWrapper();
serviceGeneratorWrapper.generate(ServiceInterface.class, StorePackage.eINSTANCE);
LOGGER.info("Generating protocol buffers file and classes...");
protocolBuffersGenerator = new ProtocolBuffersGenerator();
for (Class<? extends PublicInterface> clazz : InterfaceList.getInterfaces()) {
SService service = new SService(servicesMap, new SourceCodeFetcher() {
@Override
public String get(Class<?> clazz) {
File javaFile = new File("../PluginBase/src/" + clazz.getName().replace(".", "/") + ".java");
try {
return FileUtils.readFileToString(javaFile);
} catch (IOException e) {
return null;
}
}
}, clazz);
servicesMap.add(service);
}
servicesMap.initialize();
for (SService service : servicesMap.list()) {
AdaptorGeneratorWrapper adaptorGeneratorWrapper = new AdaptorGeneratorWrapper();
adaptorGeneratorWrapper.generate(service.getInterfaceClass(), service);
AsyncServiceGeneratorWrapper asyncServiceGeneratorWrapper = new AsyncServiceGeneratorWrapper();
asyncServiceGeneratorWrapper.generate(service.getInterfaceClass(), service);
File protoFile = new File("../BimServerClientLib/src/org/bimserver/client/protocolbuffers/" + service.getInterfaceClass().getSimpleName() + ".proto");
File descFile = new File("../BimServerClientLib/src/org/bimserver/client/protocolbuffers/" + service.getInterfaceClass().getSimpleName() + ".desc");
protocolBuffersGenerator.generate(service.getInterfaceClass(), protoFile, descFile, this.knownServices.isEmpty(), service, knownShortNames);
this.knownServices.add(service);
this.knownShortNames.add(service.getInterfaceClass().getSimpleName());
}
SPackageGeneratorWrapper sPackageGeneratorWrapper = new SPackageGeneratorWrapper();
sPackageGeneratorWrapper.generate(ePackages);
LOGGER.info("Protocol buffers file and classes generated");
// RealtimeReflectorFactoryBuilder reflectorBuilder = new RealtimeReflectorFactoryBuilder(InterfaceList.createSServicesMap(), new File("../PluginBase/genclasses"));
// reflectorBuilder.newReflectorFactory();
LOGGER.info("");
LOGGER.info("Migration successfull");
try {
FileUtils.deleteDirectory(new File("cmhome"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations