From ad413221cc46e2bc0b86e621e1ba4a039d5665f0 Mon Sep 17 00:00:00 2001 From: Brian Fitzpatrick Date: Fri, 26 Oct 2018 10:34:07 -0600 Subject: [PATCH] adding wsdl2rest support to camel-project generator #11 -- initial cut with fat jar and running the wsdl2rest tool with inputs -- updating to support full paths and a logging.props file -- Updating version for when we include wsdl2rest functionality -- also updating the travis file to build the wsdl2rest jar -- additional work on test and wsdl2rest call -- additional fixes -- Setting jar to specific version vs asterisk and returning to broken test -- updates to make wsdl2rest run in a promise #11 -- Increasing the mocha timeout in the travis configuration #11 -- addressing some review feedback -- updating tests to run with npm test call -- reset readme.md Signed-off-by: Brian Fitzpatrick --- .gitignore | 1 + .travis.yml | 2 +- README.md | 29 ++-- app/index.js | 101 ++++++++++- app/wsdl2rest/config/logging.properties | 38 ++++ app/wsdl2rest/pom.xml | 149 ++++++++++++++++ package-lock.json | 7 +- package.json | 5 + test/address.wsdl | 219 ++++++++++++++++++++++++ test/app.js | 34 ++++ 10 files changed, 570 insertions(+), 15 deletions(-) create mode 100644 app/wsdl2rest/config/logging.properties create mode 100644 app/wsdl2rest/pom.xml create mode 100644 test/address.wsdl diff --git a/.gitignore b/.gitignore index fc13c92..0ec17d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules/ /coverage/ /.nyc_output/ +/app/wsdl2rest/target/ log-camel-lsp.out diff --git a/.travis.yml b/.travis.yml index bedaa33..28550a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ before_install: - 'export PATH=./node_modules/.bin:$PATH' - 'npm install -g typescript' - 'npm install -g mocha' + - 'mvn install -f ./app/wsdl2rest/pom.xml' install: - 'npm install --ignore-scripts' - 'npm install' @@ -13,7 +14,6 @@ install: - 'rm -f ./node_modules/.bin/which' script: - 'npm test --silent' - - 'mocha' after_success: - if [[ $TRAVIS_PULL_REQUEST == "false" && $TRAVIS_BRANCH == "master" ]]; then sonar-scanner; diff --git a/README.md b/README.md index 5b8dcb4..f6716f3 100644 --- a/README.md +++ b/README.md @@ -77,30 +77,31 @@ The generator is located in the npm repository (https://www.npmjs.com/package/ge \____| \__,_| |_| |_| |_| \___| |_| ----------------------------------------------- Camel Project Generator + Version: 0.1.2 ----------------------------------------------- ? Your Camel project name (myproject) -? Your Camel version 2.18.1 -? DSL type (blueprint or spring) blueprint +? Your Camel version 2.18.2 +? Camel DSL type (blueprint, spring, or java) blueprint ? Package name: com.myproject camel project name myproject -camel version 2.18.1 +camel version 2.18.2 camel DSL blueprint package name com.myproject Creating folders Copying files -Copying dot files create pom.xml create README.md create src\main\resources\OSGI-INF\blueprint\blueprint.xml + create src\main\resources\OSGI-INF\log4j2.properties > ``` ### Notes on input fields * 'Camel project name' defaults to the name of the directory in which you start the generator. -* 'Camel version' defaults to 2.18.1 but if you provide a different version, that version then becomes the default for the next time the generator is run. -* 'DSL type' defaults to 'spring' but if you change it to a valid DSL type such as 'blueprint', 'spring', or 'java', that becomes the default for the next time the generator is run. If you enter an invalid value, the generator will present an error ">> Camel DSL must be either 'spring', 'blueprint', or 'java'.". +* 'Camel version' defaults to 2.22.1 but if you provide a different version, that version then becomes the default for the next time the generator is run. +* 'Camel DSL type' defaults to 'spring' but if you change it to a valid DSL type such as 'blueprint', 'spring', or 'java', that becomes the default for the next time the generator is run. If you enter an invalid value, the generator will present an error ">> Camel DSL must be either 'spring', 'blueprint', or 'java'.". * 'Package name' defaults to 'com.' + the name of the directory (i.e. 'com.myproject'). This default does not change if you provide a different value. ## Development Notes @@ -122,6 +123,14 @@ Then create a directory you wish to create a Camel project in and run the genera > yo camel-project ``` +## Running the Generator from the Command Line (*NEW*) +With version 0.1.2 we have added command-line capabilities for providing argument values for the prompted information. Without prompting, this allows us to use the generator as part of a larger script to help prep a new project in a more automated fashion. + +This allows us to do things like the following and avoid having to go through the prompts: +``` +> yo camel-project appname=MyApp camelVersion=2.19.1 camelDSL=spring package=com.myapp +``` + ### Running the Mocha tests First you must install mocha with npm. ``` @@ -132,14 +141,10 @@ Then, in the main generator-camel-project directory: > mocha ``` -## Known issues +## Running the Generated Templates -Generated templates for spring and Java DSLs can be run with: +Generated templates for spring, blueprint, and Java DSLs can be run with: ``` > mvn install > mvn camel:run ``` - -Unfortunately, the blueprint version does not run successfully. Working on finding a solution. -Created https://github.com/camel-tooling/generator-camel-project/issues/1 - diff --git a/app/index.js b/app/index.js index b940b5b..e259a03 100644 --- a/app/index.js +++ b/app/index.js @@ -19,9 +19,13 @@ var yeoman = require('yeoman-generator'); var glob = require('glob'); var path = require('path'); var mkdirp = require('mkdirp'); +var fileUrl = require('file-url'); +var exec = require('child_process').exec; +var fs = require('fs'); + const utils = require('./util'); -const defaultCamelVersion = "2.22.1"; +const defaultCamelVersion = "2.22.2"; const defaultCamelDSL = "spring"; const defaultPackagePrefix = "com."; @@ -55,6 +59,8 @@ module.exports = class extends yeoman { this.argument('camelVersion', { type: String, required: false }); this.argument('camelDSL', { type: String, required: false }); this.argument('package', { type: String, required: false }); + + this.option('wsdl2rest'); } prompting() { @@ -69,6 +75,8 @@ module.exports = class extends yeoman { showPrompts = false; } + let showWsdl2Rest = this.options.wsdl2rest; + if (showPrompts) { consoleHeader(); } @@ -109,12 +117,34 @@ module.exports = class extends yeoman { validate : utils.validatePackage }, prompts); + if (showWsdl2Rest) { + var defaultOutput = 'src//main//java'; + utils.addPrompt({ + type: 'input', + name: 'wsdl', + message: 'URL to the input WSDL', + store: true + }, prompts); + utils.addPrompt({ + type: 'input', + name: 'outdirectory', + message: 'Name of the output directory for generated artifacts', + default: defaultOutput, + store: true + }, prompts); + + } + if (showPrompts) { return this.prompt(prompts).then(function (props) { this.appname = props.name; this.camelVersion = props.camelVersion; this.camelDSL = props.camelDSL; this.package = props.package; + if (showWsdl2Rest) { + this.outdirectory = props.outdirectory; + this.wsdl = props.wsdl; + } }.bind(this)); } else { this.appname = defaultProject; @@ -126,6 +156,8 @@ module.exports = class extends yeoman { //writing logic here writing() { + let showWsdl2Rest = this.options.wsdl2rest; + var packageFolder = this.package.replace(/\./g, '/'); var src = 'src/main/java'; var myTemplatePath = path.join(this.templatePath(), this.camelDSL); @@ -153,5 +185,72 @@ module.exports = class extends yeoman { { userProps: userProps } ); } + + if (showWsdl2Rest) { + return wsdl2restGenerate(this.wsdl, this.outdirectory, this.camelDSL); + } } }; + +function wsdl2restGenerate(wsdlUrl, outputDirectory, dsl) { + if (dsl.indexOf('java') > 0) { + console.log(`Generating Rest DSL from SOAP for a Camel Java DSL is currently unsupported.`); + } + + var wsdl2restdir = path.join(__dirname, 'wsdl2rest'); + var targetDir = path.join(wsdl2restdir, 'target'); + var jar = path.join(targetDir, 'wsdl2rest-impl-fatjar-0.1.3-SNAPSHOT.jar'); + var outPath = path.join(process.cwd(), outputDirectory); + var wsdlFileUrl; + if (!wsdlUrl.startsWith('file:')) { + wsdlFileUrl = fileUrl(wsdlUrl); + } else { + wsdlFileUrl = wsdlUrl; + } + + if (!fs.existsSync(outPath)){ + console.log(`Creating wsdl2rest java output directory`); + fs.mkdirSync(outPath); + } + + var blueprintPath; + var springPath; + var isBlueprint = dsl.includes('blueprint') > 0; + if (isBlueprint) { + blueprintPath = path.join(process.cwd(), "src/main/resources/OSGI-INF/blueprint/blueprint-rest.xml"); + } else { + springPath = path.join(process.cwd(), "src/main/resources/META-INF/spring/camel-context-rest.xml"); + }; + + // build the java command with classpath, class name, and the passed parameters + var cmdString = 'java '; + cmdString = cmdString + '-jar ' + jar; + cmdString = cmdString + ' --wsdl ' + wsdlFileUrl; + cmdString = cmdString + ' --out ' + outPath; + + if (isBlueprint) { + cmdString = cmdString + ' --blueprint-context ' + blueprintPath; + } else { + cmdString = cmdString + ' --camel-context ' + springPath; + } + console.log('calling: ' + cmdString); + return new Promise((resolve, reject) => { + const wsdl2rest = exec(cmdString); + wsdl2rest.stdout.on('data', function (data) { + console.log(`stdout: ${data}`); + }); + wsdl2rest.stderr.on('data', function (data) { + console.log(`stderr: ${data}`); + }); + wsdl2rest.on('close', function (code) { + if (code === 0) { + console.log(`wsdl2rest generated artifacts successfully`); + resolve() + } else { + reject() + console.log(`stderr: ${code}`); + console.log(`wsdl2rest did not generate artifacts successfully - please check the log file for details`); + } + }); + }) +} diff --git a/app/wsdl2rest/config/logging.properties b/app/wsdl2rest/config/logging.properties new file mode 100644 index 0000000..9e3b759 --- /dev/null +++ b/app/wsdl2rest/config/logging.properties @@ -0,0 +1,38 @@ +### +# #%L +# Fuse wsdl2rest :: Distro :: Standalone +# %% +# Copyright (C) 2015 Private +# %% +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# #L% +### + +# Root logger option +log4j.rootLogger=DEBUG, file, console + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.file=wsdl2rest.log +log4j.appender.file.append=true +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n +log4j.appender.file.threshold=DEBUG + +# Direct log messages to console +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%m%n +log4j.appender.console.threshold=INFO + diff --git a/app/wsdl2rest/pom.xml b/app/wsdl2rest/pom.xml new file mode 100644 index 0000000..d2da10e --- /dev/null +++ b/app/wsdl2rest/pom.xml @@ -0,0 +1,149 @@ + + 4.0.0 + + wsdl2rest-impl-fatjar + Wsdl2Rest Fat Jar + 0.1.3-SNAPSHOT + org.github.camel.tooling.wsdl2rest + + + + 0.8.0.fuse-720034 + UTF-8 + + + + + org.jboss.fuse.wsdl2rest + wsdl2rest-impl + ${version.wsdl2rest} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.0.RELEASE + + + + repackage + + + + + org.jboss.fuse.wsdl2rest.impl.Main + + + + + + + + fuse-public-repository + FuseSource Community Release Repository + https://repo.fusesource.com/nexus/content/groups/public + + false + + + true + never + + + + red-hat-ga-repository + Red Hat GA Repository + https://maven.repository.redhat.com/ga + + true + never + + + false + + + + + true + never + + + false + + red-hat-ea-repository + Red Hat EA Repository + https://maven.repository.redhat.com/earlyaccess/all + + + + + true + never + + + false + + jboss-ea-repository + Red Hat JBoss Early Access Repository + http://repository.jboss.org/nexus/content/groups/ea + + + + + + fuse-public-repository + FuseSource Community Release Repository + https://repo.fusesource.com/nexus/content/groups/public + + false + + + true + never + + + + red-hat-ga-repository + Red Hat GA Repository + https://maven.repository.redhat.com/ga + + true + never + + + false + + + + + true + never + + + false + + red-hat-ea-repository + Red Hat EA Repository + https://maven.repository.redhat.com/earlyaccess/all + + + + + true + never + + + false + + jboss-ea-repository + Red Hat JBoss Early Access Repository + http://repository.jboss.org/nexus/content/groups/ea + + + + diff --git a/package-lock.json b/package-lock.json index 4d9017a..b285903 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "generator-camel-project", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -682,6 +682,11 @@ "escape-string-regexp": "^1.0.5" } }, + "file-url": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/file-url/-/file-url-2.0.2.tgz", + "integrity": "sha1-6VF4TXkJUSfTcTApqwY/QIGMoq4=" + }, "fill-range": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", diff --git a/package.json b/package.json index 9352e4a..6fce5b8 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "author": "Brian Fitzpatrick", "license": "Apache-2.0", "dependencies": { + "file-url": "^2.0.2", "fs-extra": "^7.0.0", "glob": "^7.1.2", "mkdirp": "^0.5.1", @@ -28,5 +29,9 @@ }, "devDependencies": { "mocha": "^5.2.0" + }, + "scripts": { + "unit": "mocha --timeout=5000 test/", + "test": "npm run unit" } } diff --git a/test/address.wsdl b/test/address.wsdl new file mode 100644 index 0000000..aad51f5 --- /dev/null +++ b/test/address.wsdl @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/app.js b/test/app.js index 1a8428a..8565444 100644 --- a/test/app.js +++ b/test/app.js @@ -169,3 +169,37 @@ describe('generator-camel:app', function () { }); }); }); + +describe('generator-camel:wsdl2rest', function () { + describe('Should properly scaffold with config for Spring and wsdl2rest', function () { + it('Should create the basic structure two ways', function () { + basicProps.name = 'MyAppMock'; + basicProps.package = 'com.generator.mock'; + basicProps.camelVersion = '2.18.2'; + basicProps.camelDSL = 'spring'; + var wsdlPath = path.join(__dirname, '../test/address.wsdl'); + basicProps.wsdl = wsdlPath; + basicProps.outdirectory = 'src/main/java'; + return helpers.run(path.join(__dirname, '../app')) + .inTmpDir(function (dir) { + var done = this.async(); // `this` is the RunContext object. + fs.copy(path.join(__dirname, '../templates'), dir, done); + basicProps.outdirectory = path.join(dir, 'src/main/java'); + }) + .withOptions({ wsdl2rest: true }) + .withPrompts({ name: basicProps.name }) + .withPrompts({ camelVersion: basicProps.camelVersion }) + .withPrompts({ camelDSL: basicProps.camelDSL }) + .withPrompts({ package: basicProps.package }) + .withPrompts({ wsdl: basicProps.wsdl }) + .withPrompts({ outdirectory: basicProps.outdirectory }) + .toPromise() + .then(() => { + assert.file('pom.xml'); + assert.file('README.md'); + assert.file('src/main/resources/META-INF/spring/camel-context.xml'); + assert.file('src/main/resources/META-INF/spring/camel-context-rest.xml') + }); + }); + }); +});