From 8cc2784c351934954e20f2274d0d5d09b12f90da Mon Sep 17 00:00:00 2001 From: junkerm Date: Fri, 5 Apr 2019 13:08:49 +0200 Subject: [PATCH] enable external documentation directory (#412) * enable external documentation directory --- bundles/specmate-ui-core/bnd.bnd | 13 +- .../ui/core/ResourceRegistration.java | 100 ++++++-- web/webpack/webpack.common.js | 241 +++++++++--------- 3 files changed, 201 insertions(+), 153 deletions(-) diff --git a/bundles/specmate-ui-core/bnd.bnd b/bundles/specmate-ui-core/bnd.bnd index b0d9e225a..2f63ae8e2 100644 --- a/bundles/specmate-ui-core/bnd.bnd +++ b/bundles/specmate-ui-core/bnd.bnd @@ -1,8 +1,9 @@ -Bundle-Version: 0.0.0.${tstamp} -Private-Package: com.specmate.ui.core --buildpath: \ +Bundle-Version: 0.0.0.${tstamp} +Private-Package: com.specmate.ui.core +-buildpath: \ org.eclipse.osgi,\ - org.eclipse.osgi.services -Include-Resource: webcontent=webcontent --dsannotations: \ + org.eclipse.osgi.services,\ + javax.servlet-api +Include-Resource: webcontent=webcontent +-dsannotations: \ * \ No newline at end of file diff --git a/bundles/specmate-ui-core/src/com/specmate/ui/core/ResourceRegistration.java b/bundles/specmate-ui-core/src/com/specmate/ui/core/ResourceRegistration.java index 6033248fd..2c8cd8033 100644 --- a/bundles/specmate-ui-core/src/com/specmate/ui/core/ResourceRegistration.java +++ b/bundles/specmate-ui-core/src/com/specmate/ui/core/ResourceRegistration.java @@ -1,27 +1,73 @@ -package com.specmate.ui.core; - -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.http.HttpService; -import org.osgi.service.http.NamespaceException; - -@Component(immediate=true) -public class ResourceRegistration { - - private HttpService httpService; - - @Activate - public void activate(){ - try { - httpService.registerResources("/", "/webcontent",null); - } catch (NamespaceException e) { - e.printStackTrace(); - } - } - - @Reference - public void setHttpService(HttpService http){ - this.httpService=http; - } -} +package com.specmate.ui.core; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpContext; +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; +import org.osgi.service.log.LogService; + +@Component(immediate = true) +public class ResourceRegistration { + + private HttpService httpService; + private LogService logService; + + @Activate + public void activate() { + try { + this.httpService.registerResources("/", "/webcontent", null); + registerDocFolder(); + } catch (NamespaceException e) { + this.logService.log(LogService.LOG_ERROR, "Could not register frontend with http service: ", e); + } + } + + private void registerDocFolder() throws NamespaceException { + File docFolder = new File("./doc"); + if (docFolder.exists() && docFolder.isDirectory()) { + this.httpService.registerResources("/doc", "/", new HttpContext() { + + @Override + public URL getResource(String name) { + try { + return new URL(docFolder.toURI().toURL(), name.substring(1)); + } catch (MalformedURLException e) { + return null; + } + } + + @Override + public String getMimeType(String name) { + return null; + } + + @Override + public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) + throws IOException { + return true; + } + }); + } + } + + @Reference + public void setHttpService(HttpService http) { + this.httpService = http; + } + + @Reference + public void setLogServicve(LogService logService) { + this.logService = logService; + } + +} diff --git a/web/webpack/webpack.common.js b/web/webpack/webpack.common.js index 7e0a4675a..d225c15ba 100644 --- a/web/webpack/webpack.common.js +++ b/web/webpack/webpack.common.js @@ -1,121 +1,122 @@ const SPECMATE_VERSION = '0.3.1-dev-1' - -const webpack = require('webpack'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const GitRevisionPlugin = require('git-revision-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const helpers = require('./helpers'); - - -const gitRevisionPlugin = new GitRevisionPlugin({ - commithashCommand: 'rev-parse --short HEAD' -}); - -module.exports = { - entry: { - 'polyfills': './src/polyfills.ts', - 'vendor': './src/vendor.ts', - 'specmate': './src/main.ts', - 'assets': './src/assets.ts', - }, - - resolve: { - extensions: ['.ts', '.js'] - }, - - module: { - rules: [{ - test: /\.ts$/, - loaders: [{ - loader: 'awesome-typescript-loader', - options: { configFileName: helpers.root('src', 'tsconfig.json') } - }, 'angular2-template-loader'] - }, - { - test: /\.(html|svg)$/, - loader: 'html-loader', - exclude: [helpers.root('node_modules', 'flag-icon-css'), helpers.root('node_modules', 'font-awesome')] - }, - { - test: /\.svg/, - loader: 'file-loader?name=img/[name]_[hash].[ext]', - include: [helpers.root('node_modules', 'flag-icon-css'), helpers.root('node_modules', 'font-awesome')] - }, - { - test: /\.(html|svg)$/, - loader: 'string-replace-loader', - query: { - search: '@@version', - replace: SPECMATE_VERSION - } - }, - { - test: /\.(png|jpe?g|gif|ico)$/, - loader: 'file-loader?name=img/[name]_[hash].[ext]' - }, - { - test: /\.css$/, - exclude: helpers.root('src', 'app'), - use: ['style-loader', 'css-loader'] - }, - { - test: /\.css$/, - include: helpers.root('src', 'app'), - loader: 'raw-loader' - }, - { - test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, - // We cannot use [hash] or anything similar here, since ng-split will not work then. - loader: 'file-loader?name=fonts/[name].[ext]' - }, - { - test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, - loader: "file-loader?name=fonts/[name].[ext]", - }, - { - test: /\.scss$/, - use: [{ - loader: "style-loader" - }, - { - loader: "postcss-loader", - options: { - sourceMap: true, - plugins: function() { - return [require("autoprefixer")]; - } - } - }, - { - loader: "sass-loader", - options: { - sourceMap: true - } - } - ] - } - ] - }, - - plugins: [ - new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, helpers.root('../src'), {}), - new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/, helpers.root('../src'), {}), - new webpack.optimize.CommonsChunkPlugin({ name: ['specmate', 'vendor', 'polyfills', 'assets'] }), - new HtmlWebpackPlugin({ - template: 'src/index.html', - favicon: 'src/assets/img/favicon.ico' - }), - - new webpack.ProvidePlugin({ - $: 'jquery', - jQuery: 'jquery', - 'window.jQuery': 'jquery' - }), - - new CopyWebpackPlugin([{ - from: helpers.root('src', 'assets', 'i18n'), - to: 'i18n', - copyUnmodified: true - }]) - ] -}; + + +const webpack = require('webpack'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const GitRevisionPlugin = require('git-revision-webpack-plugin'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const helpers = require('./helpers'); + + +const gitRevisionPlugin = new GitRevisionPlugin({ + commithashCommand: 'rev-parse --short HEAD' +}); + +module.exports = { + entry: { + 'polyfills': './src/polyfills.ts', + 'vendor': './src/vendor.ts', + 'specmate': './src/main.ts', + 'assets': './src/assets.ts', + }, + + resolve: { + extensions: ['.ts', '.js'] + }, + + module: { + rules: [{ + test: /\.ts$/, + loaders: [{ + loader: 'awesome-typescript-loader', + options: { configFileName: helpers.root('src', 'tsconfig.json') } + }, 'angular2-template-loader'] + }, + { + test: /\.(html|svg)$/, + loader: 'html-loader', + exclude: [helpers.root('node_modules', 'flag-icon-css'), helpers.root('node_modules', 'font-awesome')] + }, + { + test: /\.svg/, + loader: 'file-loader?name=img/[name]_[hash].[ext]', + include: [helpers.root('node_modules', 'flag-icon-css'), helpers.root('node_modules', 'font-awesome')] + }, + { + test: /\.(html|svg)$/, + loader: 'string-replace-loader', + query: { + search: '@@version', + replace: SPECMATE_VERSION + } + }, + { + test: /\.(png|jpe?g|gif|ico)$/, + loader: 'file-loader?name=img/[name]_[hash].[ext]' + }, + { + test: /\.css$/, + exclude: helpers.root('src', 'app'), + use: ['style-loader', 'css-loader'] + }, + { + test: /\.css$/, + include: helpers.root('src', 'app'), + loader: 'raw-loader' + }, + { + test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, + // We cannot use [hash] or anything similar here, since ng-split will not work then. + loader: 'file-loader?name=fonts/[name].[ext]' + }, + { + test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, + loader: "file-loader?name=fonts/[name].[ext]", + }, + { + test: /\.scss$/, + use: [{ + loader: "style-loader" + }, + { + loader: "postcss-loader", + options: { + sourceMap: true, + plugins: function() { + return [require("autoprefixer")]; + } + } + }, + { + loader: "sass-loader", + options: { + sourceMap: true + } + } + ] + } + ] + }, + + plugins: [ + new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, helpers.root('../src'), {}), + new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/, helpers.root('../src'), {}), + new webpack.optimize.CommonsChunkPlugin({ name: ['specmate', 'vendor', 'polyfills', 'assets'] }), + new HtmlWebpackPlugin({ + template: 'src/index.html', + favicon: 'src/assets/img/favicon.ico' + }), + + new webpack.ProvidePlugin({ + $: 'jquery', + jQuery: 'jquery', + 'window.jQuery': 'jquery' + }), + + new CopyWebpackPlugin([{ + from: helpers.root('src', 'assets', 'i18n'), + to: 'i18n', + copyUnmodified: true + }]) + ] +};