Search in sources :

Example 1 with SPackageGeneratorWrapper

use of org.bimserver.tools.generators.SPackageGeneratorWrapper 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();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(java.nio.file.Path) AdaptorGeneratorWrapper(org.bimserver.tools.generators.AdaptorGeneratorWrapper) DataObjectGeneratorWrapper(org.bimserver.tools.generators.DataObjectGeneratorWrapper) SPackageGeneratorWrapper(org.bimserver.tools.generators.SPackageGeneratorWrapper) MetaDataManager(org.bimserver.emf.MetaDataManager) IOException(java.io.IOException) EPackage(org.eclipse.emf.ecore.EPackage) SServiceGeneratorWrapper(org.bimserver.tools.generators.SServiceGeneratorWrapper) SConverterGeneratorWrapper(org.bimserver.tools.generators.SConverterGeneratorWrapper) AsyncServiceGeneratorWrapper(org.bimserver.tools.generators.AsyncServiceGeneratorWrapper) SourceCodeFetcher(org.bimserver.shared.meta.SourceCodeFetcher) File(java.io.File) ProtocolBuffersGenerator(org.bimserver.tools.generators.ProtocolBuffersGenerator) SService(org.bimserver.shared.meta.SService)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 LinkedHashSet (java.util.LinkedHashSet)1 MetaDataManager (org.bimserver.emf.MetaDataManager)1 SService (org.bimserver.shared.meta.SService)1 SourceCodeFetcher (org.bimserver.shared.meta.SourceCodeFetcher)1 AdaptorGeneratorWrapper (org.bimserver.tools.generators.AdaptorGeneratorWrapper)1 AsyncServiceGeneratorWrapper (org.bimserver.tools.generators.AsyncServiceGeneratorWrapper)1 DataObjectGeneratorWrapper (org.bimserver.tools.generators.DataObjectGeneratorWrapper)1 ProtocolBuffersGenerator (org.bimserver.tools.generators.ProtocolBuffersGenerator)1 SConverterGeneratorWrapper (org.bimserver.tools.generators.SConverterGeneratorWrapper)1 SPackageGeneratorWrapper (org.bimserver.tools.generators.SPackageGeneratorWrapper)1 SServiceGeneratorWrapper (org.bimserver.tools.generators.SServiceGeneratorWrapper)1 EPackage (org.eclipse.emf.ecore.EPackage)1