/** Validates the model and adds error messages to the ExecutionResult */ private void validateModel(ExecutionResult result) { result.append("-> Validating the project..."); ModelUtility modelUtility = new ModelUtility(); modelUtility.validate(this.getProject(), result); if (result.isOk()) { result.append("-> Validation is OK"); } else { result.append("-> *** ERROR: The project validation FAILED! See messages above. ***"); result.append("-> *** You need to fix the issues before code can be generated. ***"); } }
public void generateObjC(ExecutionResult result) throws Exception { this.validateModel(result); if (!result.isOk()) { return; } this.getIo().deleteDirectory(this.getOutputDirectory()); result.append("-> Generating Objective-C classes..."); try { ObjcGenerator generator = new ObjcGenerator(); generator.generateAll(this.getProject(), this.getOutputDirectory()); result.append("-> *** Code generation OK ***"); } catch (Exception e) { throw new RuntimeException(e); } }
public void generateSwift(ExecutionResult result) throws Exception { this.validateModel(result); if (!result.isOk()) { return; } this.getIo().deleteDirectory(this.getOutputDirectory()); result.append("-> Generating Swift classes..."); try { SwiftGenerator generator = new SwiftGenerator(); generator.generateAll(this.getProject(), this.getOutputDirectory()); result.append("-> *** Code generation OK ***"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
public void run(String[] args, ExecutionResult result) throws Exception { if (args != null && args.length == 1) { String value = args[0].trim().toLowerCase(); if (value.equals("help") || value.equals("?")) { result.append("Usage: " + COMMAND_HELP); result.setOk(false); return; } } if (args == null || args.length != 3) { result.append("Usage: " + COMMAND_HELP); result.setOk(false); return; } String option = args[0]; String projectFile = args[1]; String outputDirectory = args[2]; this.run(option, projectFile, outputDirectory, result); }
public void run(String option, String projectFile, String outputDirectory, ExecutionResult result) throws Exception { if (option == null || (!option.equals(GENERATE_JAVA) && !option.equals(GENERATE_OBJC) && !option.equals(GENERATE_SWIFT))) { result.append("-> Invalid option! The command line is:"); result.append(COMMAND_HELP); result.setOk(false); return; } if (projectFile == null || !this.getIo().existsFile(projectFile)) { result.append("-> The project file doesn't exists: " + projectFile); result.setOk(false); return; } if (outputDirectory == null || !this.getIo().existsFile(outputDirectory)) { result.append("-> The output directory doesn't exists: " + outputDirectory); result.setOk(false); return; } ModelUtility modelUtility = new ModelUtility(); Project newProject = modelUtility.openProject(projectFile); this.setProject(newProject); this.setOutputDirectory(outputDirectory); if (option.equals(GENERATE_JAVA)) { this.generateJava(result); return; } if (option.equals(GENERATE_OBJC)) { this.generateObjC(result); return; } if (option.equals(GENERATE_SWIFT)) { this.generateSwift(result); return; } }