Generator { public Path generateProject() throws Exception { Path workingDirPath = this.workingDir.toPath(); Files.createDirectories(workingDirPath); Path javaTemplateDir = workingDirPath.resolve("../java"); Files.createDirectories(javaTemplateDir); String s = this.getClass().getResource("").getPath(); if (s.contains("jar!")) { Generator.LOGGER.trace("we work on a jar file"); Generator.LOGGER.trace("Location of the current class: {}", s); int excl = s.lastIndexOf("!"); s = s.substring(0, excl); s = s.substring("file:".length()); try (JarFile jf = new JarFile(s);) { Enumeration<JarEntry> entries = jf.entries(); while (entries.hasMoreElements()) { JarEntry je = entries.nextElement(); String name = je.getName(); if (name.startsWith(Generator.TEMPLATE_PROJECT_FOLDER + "/") && (name.length() > (Generator.TEMPLATE_PROJECT_FOLDER.length() + 1))) { name = name.substring(Generator.TEMPLATE_PROJECT_FOLDER.length() + 1); if (je.isDirectory()) { Path dir = workingDirPath.resolve(name); Files.createDirectory(dir); } else { Path file = workingDirPath.resolve(name); try (InputStream is = jf.getInputStream(je);) { Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING); } } } else if (name.startsWith(Generator.TEMPLATE_JAVA_FOLDER + "/") && (name.length() > (Generator.TEMPLATE_JAVA_FOLDER.length() + 1))) { if (!je.isDirectory()) { File f = new File(name); Path file = javaTemplateDir.resolve(f.getName()); try (InputStream is = jf.getInputStream(je);) { Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING); } } } } } } else { File templateProjectDir = new File(this.getClass().getResource("/" + Generator.TEMPLATE_PROJECT_FOLDER).getFile()); FileUtils.copyDirectory(templateProjectDir, this.workingDir); File javaTemplatesDir = new File(this.getClass().getResource("/" + Generator.TEMPLATE_JAVA_FOLDER).getFile()); FileUtils.copyDirectory(javaTemplatesDir, javaTemplateDir.toFile()); } String[] splitPkg = this.javaPackage.split("\\."); StringBuilder javaFolderString = new StringBuilder(this.workingDir.getAbsolutePath() + File.separator + "src" + File.separator + "main" + File.separator + "java"); for (String value : splitPkg) { javaFolderString.append(File.separator).append(value); } Path templateJavaService = javaTemplateDir.resolve(Generator.TEMPLATE_JAVA_TEMPLATE_SERVICE); File javaService = new File(javaFolderString + File.separator + this.name + ".java"); Files.createDirectories(javaService.toPath().getParent()); Files.copy(templateJavaService, javaService.toPath(), StandardCopyOption.REPLACE_EXISTING); this.generateJavaFile(javaService); this.updateFilesRecursively(this.workingDir); return this.workingDir.toPath(); } Generator(TInterface tInterface, String packageAndNamespace, URL iaArtifactTemplateUploadUrl, String name, File workingDir); Path generateProject(); File generateAndZipProject();  }
@Test public void testMultipleOpsWithInOutParams() throws Exception { TInterface i = new TInterface(); i.setName("http: TOperation op; TOperation.InputParameters input; TOperation.OutputParameters output; TParameter param; op = new TOperation(); op.setName("install"); i.getOperation().add(op); input = new TOperation.InputParameters(); param = new TParameter(); param.setName("VMIP"); param.setType("xs:string"); input.getInputParameter().add(param); param = new TParameter(); param.setName("DBMSUsername"); param.setType("xs:string"); input.getInputParameter().add(param); op.setInputParameters(input); output = new TOperation.OutputParameters(); param = new TParameter(); param.setName("Output"); param.setType("xs:string"); output.getOutputParameter().add(param); op.setOutputParameters(output); op = new TOperation(); op.setName("uninstall"); i.getOperation().add(op); input = new TOperation.InputParameters(); param = new TParameter(); param.setName("SomeLongParameterName"); param.setType("xs:string"); input.getInputParameter().add(param); param = new TParameter(); param.setName("Port"); param.setType("xs:string"); input.getInputParameter().add(param); op.setInputParameters(input); op.setOutputParameters(output); Generator gen = new Generator(i, "org.opentosca.ia.test", new URL("http: gen.generateProject(); }
@Test public void testOneOpNoParams() throws Exception { TInterface i = new TInterface(); i.setName("http: TOperation op = new TOperation(); op.setName("install"); i.getOperation().add(op); Generator gen = new Generator(i, "org.opentosca.ia.test", new URL("http: gen.generateProject(); }