Skip to content

Commit

Permalink
Add maven back & front build integration (#65)
Browse files Browse the repository at this point in the history
- Add frontend-maven-plugin
- Add url path mandatory parameter on both maven package
  and grunt build processes
- Add 'dist' directory (front build folder) to war file
  - This was accomplished by adding this folder to the maven package
    lifecycle
- Fix Spring filter to match API paths only (/api/v1/*)
  - Frontend filter will be done with frontend tools
- Update Gruntfile.js
  - Update jsrev task to load requirejs components (controllers,
    services and directives) based on the specified path where the app
    will be deployed (for example, '/' or '/grupo1')
  - Fix some Gruntfile issues
  - Requirejs module packager not updated. See Notes (2) for more information
- Update views paths on both routes.js and directives' templateUrl field
  - Update absolute paths ('/views/home.html') to relative paths
    ('views/home.html')
- Update karma configuration file
  - Genereate symlink inside app's folder pointing to bower_components
    folder when running `karma start`. See Notes (1) for more information
- Update README.md
- Fix logger
  - It was on DEBUG level. jpascale changed this and mmercado approved
    its PR. We have to be careful about this changes.
- Update WebConfig parameters for stage deploy
- Exclude dependency from main's pom
  - This dependency is excluded to avoid the following warning from the
    Tomcat server:
       INFO:validateJarFile(/home/matias/Programs/apache-tomcat-7.0.68/
       webapps/grupo1/WEB-INF/lib/javax.el-api-2.2.4.jar)- jar not loaded.
       See Servlet Spec 3.0, section 10.7.2.
       Offending class:javax/el/Expression.class

Notes:
(1) Genereate symlink inside app's folder pointing to bower_components
    folder when running `karma start`.

Why do we need this?
basePath is used as a starting path for all other paths inside this
config file.
For example, with the following config
  basePath: 'app', files: [{pattern: index.js}, {pattern: ../other.js}],
port: 9876
the files that will be match will be
  '<project_path>/app/index.html'
  '<project_path>/other.html'

However, the files will be served as:
   http://localhost:9876/base/index.js
   http://localhost:9876/absolute/absoultePathToProject/other.js

Due to we need to set basePath to 'app' to be able to test directives
with templateUrl,
and to avoid the case of the 'other.js' example of above with
bower_components, we need
to make reference to the bower_components folder somehow.
This 'somehow' was resolved to be a symlink.

(2) Requirejs module packager not updated

Test setting Gruntfile.js's requirejs:compile:options:modules also
with the following values:
  {name:'controllers/BodyCtrl'},
  {name: 'controllers/HomeCtrl'},
  {name: 'controllers/LoginCtrl'}
so as to compress all related files. However, this was causing some
.js files to be merged with all of this files (like angular.js)
and this increased each of these files sizes, doing the contrary
effect that it was being looked for (speed up loading time).

That's why it was decided to left the Gruntfile.js as it was.
  • Loading branch information
MatiasComercio committed Jan 30, 2017
1 parent a925c47 commit 9c9fd70
Show file tree
Hide file tree
Showing 25 changed files with 277 additions and 95 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ local.properties

# Front-End files
*~
node/
etc/
node_modules/
bower_components/
# symlink to bower_components on the projects folder
app/bower_components
dist/
.sass-cache/
.tmp/
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- pip install --user codecov
- gem install compass
install:
- npm install
- npm install -g bower
- bower install
script:
- npm test
- mvn clean package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=${SONAR_TOKEN}
- mvn clean package -DurlPath='' sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=${SONAR_TOKEN}
after_success:
- mvn clean test jacoco:report
- npm install -g codeclimate-test-reporter
Expand Down
52 changes: 39 additions & 13 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ module.exports = function (grunt) { // eslint-disable-line strict
cwd: '.',
src: 'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*',
dest: '<%= yeoman.dist %>'
},
{
expand: true,
cwd: '.',
src: 'bower_components/font-awesome/fonts/*',
dest: '<%= yeoman.dist %>'
}, {
expand: true,
cwd: '.',
Expand Down Expand Up @@ -375,11 +381,9 @@ module.exports = function (grunt) { // eslint-disable-line strict
removeCombined: true,
preserveLicenseComments: false,
findNestedDependencies: true,
dir: 'dist/scripts',
dir: '<%= yeoman.dist %>/scripts',
modules: [
{
name: 'build'
}
{name: 'build'}
],
optimize: 'uglify2',
paths: {
Expand All @@ -393,7 +397,6 @@ module.exports = function (grunt) { // eslint-disable-line strict
dist: {
options: {
baseRoot: '<%= yeoman.dist %>/scripts',
baseUrl: 'scripts',
outputFile: '<%= yeoman.dist %>/scripts/paths.js'
}
}
Expand Down Expand Up @@ -421,14 +424,14 @@ module.exports = function (grunt) { // eslint-disable-line strict
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
baseRoot: '',
baseUrl: ''
baseUrl: "<%= grunt.option('urlPath') %>/scripts/"
});

if (!options.outputFile) {
grunt.fail.warn('Option `outputFile` not specified.');
}

var templateString = 'var paths = <%= JSON.stringify(moduleMappings, null, 2) %>;';
var templateString = 'var paths = <%= JSON.stringify(moduleMappings, replacer, 2) %>;';

var assets = grunt.filerev.summary;
var path = require('path');
Expand All @@ -455,7 +458,17 @@ module.exports = function (grunt) { // eslint-disable-line strict

var data = {
baseUrl: options.baseUrl,
moduleMappings: mappings
moduleMappings: mappings,
replacer: function(key, value) {
if (typeof value !== 'string') {
return value;
}
if (value.startsWith('controllers') ||
value.startsWith('services') ||
value.startsWith('directives')) {
return options.baseUrl + value;
}
}
};

var outFile = options.outputFile;
Expand All @@ -469,18 +482,22 @@ module.exports = function (grunt) { // eslint-disable-line strict
}

var content = grunt.template.process(templateString, {data: data});
grunt.file.write(options.outputFile, content);
grunt.log.writeln('File "' + options.outputFile + '" created.');
grunt.file.write(outFile, content);
grunt.log.writeln('File "' + outFile + '" created.');
});

grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target) {
return grunt.task.run(['build:' + target, 'connect:dist:keepalive']);
return grunt.task.run([
'build:' + target,
'connect:' + target + ':keepalive'
]);
}

grunt.task.run([
'clean:server',
'wiredep:serve',
// commented as it introduce linter errors on files
// 'wiredep:serve',
'concurrent:server',
'autoprefixer',
'bower',
Expand All @@ -496,12 +513,21 @@ module.exports = function (grunt) { // eslint-disable-line strict
});

grunt.registerTask('build', 'Compiles app for production or release candidate', function () {
if (grunt.option('urlPath') === undefined) {
grunt.fail.warn("You have to specify your app's path. If '/', then specify ''\n" +
'Examples: \n' +
" `grunt build --urlPath=''` if deployng app to '/'\n" +
" `grunt build --urlPath='/grupo1'` if deployng app to '/grupo1'\n"
);
}

grunt.task.run([
'clean:dist',
// copy stylesheets, in: app/styles/ out: .tmp/styles
'copy:styles',
// Wires in bower dependencies where they belong in: <<>> out: <<>>
'wiredep:dist',
// commented as it may introduce linter errors on files
// 'wiredep:dist',
// In theory avoids problems related to name mangling by minifiers in: app/scripts out: .tmp/scripts
'ngAnnotate',
// Optimizer in: .tmp/scripts out: dist/scripts
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@


[![Build Status](https://travis-ci.org/MatiasComercio/paw.svg?branch=development)](https://travis-ci.org/MatiasComercio/paw) [![Code Climate](https://codeclimate.com/github/MatiasComercio/paw/badges/gpa.svg)](https://codeclimate.com/github/MatiasComercio/paw)
[![Test Coverage](https://codeclimate.com/github/MatiasComercio/paw/badges/coverage.svg)](https://codeclimate.com/github/MatiasComercio/paw/coverage)

[![alt text][2]][1]

[1]: https://sonarqube.com/dashboard?id=ar.edu.itba.paw%3Apaw
[2]: http://www.qatestingtools.com/sites/default/files/tools_shortcuts/sonarqube-150px.png (hover text)
[2]: http://www.qatestingtools.com/sites/default/files/tools_shortcuts/sonarqube-150px.png

![Quality Gate](https://sonarqube.com/api/badges/gate?key=ar.edu.itba.paw:paw) ![Coverage Gate](https://sonarqube.com/api/badges/measure?key=ar.edu.itba.paw:paw&metric=coverage&blinking=true) ![Code Smells Gate](https://sonarqube.com/api/badges/measure?key=ar.edu.itba.paw:paw&metric=code_smells&blinking=true) ![Bugs Gate](https://sonarqube.com/api/badges/measure?key=ar.edu.itba.paw:paw&metric=bugs&blinking=true) ![Vulnerabilities](https://sonarqube.com/api/badges/measure?key=ar.edu.itba.paw:paw&metric=vulnerabilities&blinking=true)

Expand Down
4 changes: 2 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<script src="bower_components/json3/lib/json3.js"></script>
<![endif]-->
<!-- endbuild -->
<script src='/scripts/paths.js'></script>
<script src='bower_components/requirejs/require.js' data-main='/scripts/build.js'></script>
<script type='application/javascript' src='scripts/paths.js'></script>
<script type='application/javascript' src='bower_components/requirejs/require.js' data-main='scripts/build.js'></script>
</body>
</html>
2 changes: 1 addition & 1 deletion app/scripts/directives/backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define(
function(navDataService, windowSize) {
return {
restrict: 'E',
templateUrl: '/views/directives/backdrop.html',
templateUrl: 'views/directives/backdrop.html',
scope: true,
bindToController: true,
link: function(scope, element, attributes) {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define(['paw', 'services/navDataService'], function(paw) {

return {
restrict: 'E',
templateUrl: '/views/directives/navbar.html',
templateUrl: 'views/directives/navbar.html',
controller: controller,
controllerAs: 'controller',
scope: {},
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ define(

return {
restrict: 'E',
templateUrl: '/views/directives/sidebar.html',
templateUrl: 'views/directives/sidebar.html',
controller: controller,
controllerAs: 'controller',
scope: {},
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/sidebarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define(['paw'], function(paw) {
controller: function() {},
controllerAs: 'controller',
transclude: true,
templateUrl: '/views/directives/sidebar_item.html',
templateUrl: 'views/directives/sidebar_item.html',
link: function(scope, element, attrs) {
scope.select = function() {
scope.opened = !scope.opened;
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/paw.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ define(['routes',
$translateProvider.preferredLanguage('preferredLanguage');
$translateProvider.useSanitizeValueStrategy('escape');

RestangularProvider.setBaseUrl('/api/v1/');
RestangularProvider.setBaseUrl('api/v1/');
}]);
return paw;
}
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ define([], function() {
defaultRoutePath: '/',
routes: {
'/': {
templateUrl: '/views/home.html',
templateUrl: 'views/home.html',
controller: 'HomeCtrl'
},
'/login': {
templateUrl: '/views/login.html',
templateUrl: 'views/login.html',
controller: 'LoginCtrl'
},
'/students': {
templateUrl: '/views/students/index.html',
templateUrl: 'views/students/index.html',
controller: 'StudentsIndexCtrl'
}
/* ===== yeoman hook ===== */
Expand Down
2 changes: 1 addition & 1 deletion app/specs/services/AuthenticatedRestangular.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define(['paw', 'spec-utils', 'api-responses', 'services/AuthenticatedRestangular
});

it("contains the token's header with the correct value", function () {
$httpBackend.expectGET('/api/v1/', apiResponsesService.header).respond('data');
$httpBackend.expectGET('api/v1/', apiResponsesService.header).respond('data');
AuthenticatedRestangularService.all('/').customGET().then(function() {});
$httpBackend.flush();
$rootScope.$apply();
Expand Down
2 changes: 1 addition & 1 deletion app/specs/services/Authentication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function() {
var token;
beforeEach(function() {
var user = {'dni': 12345678, 'password': 'pass'};
$httpBackend.expectPOST('/api/v1/login').respond(200, '', {'x-auth-token': expectedToken});
$httpBackend.expectPOST('api/v1/login').respond(200, '', {'x-auth-token': expectedToken});
AuthenticationService.login(user).then(function(apiToken) {
token = apiToken;
});
Expand Down
6 changes: 3 additions & 3 deletions app/specs/services/Courses.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(['paw', 'spec-utils', 'api-responses'], function() {
var courses;

beforeEach(function() {
$httpBackend.expectGET('/api/v1/courses').respond(JSON.stringify({courses: expectedCourses}));
$httpBackend.expectGET('api/v1/courses').respond(JSON.stringify({courses: expectedCourses}));
CoursesService.getList().then(function(apiCourses) {
courses = specUtilsService.sanitizeRestangularAll(apiCourses);
});
Expand All @@ -55,8 +55,8 @@ define(['paw', 'spec-utils', 'api-responses'], function() {

beforeEach(function() {
expectedCourseInfo = apiResponsesService.course;
$httpBackend.expectGET('/api/v1/courses').respond(JSON.stringify({courses: expectedCourses}));
$httpBackend.expectGET('/api/v1/courses/72.03').respond(JSON.stringify(expectedCourseInfo));
$httpBackend.expectGET('api/v1/courses').respond(JSON.stringify({courses: expectedCourses}));
$httpBackend.expectGET('api/v1/courses/72.03').respond(JSON.stringify(expectedCourseInfo));
CoursesService.getList().then(function(apiCourses) {
var course = apiCourses[0];
course.get().then(function(apiCourseInfo) {
Expand Down
6 changes: 3 additions & 3 deletions app/specs/services/Students.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define(['paw', 'spec-utils', 'api-responses'], function() {
var students;

beforeEach(function() {
$httpBackend.expectGET('/api/v1/students').respond(JSON.stringify({students: expectedStudents}));
$httpBackend.expectGET('api/v1/students').respond(JSON.stringify({students: expectedStudents}));
StudentsService.getList().then(function(apiStudents) {
students = specUtilsService.sanitizeRestangularAll(apiStudents);
});
Expand All @@ -63,8 +63,8 @@ define(['paw', 'spec-utils', 'api-responses'], function() {

beforeEach(function() {
expectedStudentInfo = apiResponsesService.student;
$httpBackend.expectGET('/api/v1/students').respond(JSON.stringify({students: expectedStudents}));
$httpBackend.expectGET('/api/v1/students/5').respond(JSON.stringify(expectedStudentInfo));
$httpBackend.expectGET('api/v1/students').respond(JSON.stringify({students: expectedStudents}));
$httpBackend.expectGET('api/v1/students/5').respond(JSON.stringify(expectedStudentInfo));
StudentsService.getList().then(function(apiStudents) {
var student = apiStudents[0];
student.get().then(function(apiStudentInfo) {
Expand Down
66 changes: 33 additions & 33 deletions app/specs/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Object.keys(window.__karma__.files).forEach(function (file) {

require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/app/scripts',
baseUrl: '/base/scripts',

// this is from where requirejs will search dependencies, prepending the baseUrl to
// the specified files
Expand All @@ -24,38 +24,38 @@ require.config({
'services/dependencyResolverFor': 'services/dependencyResolverFor',
'i18n/i18nLoader': 'i18n/i18nLoader',
'i18n/translations.es': 'i18n/translations.es',
affix: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix',
alert: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert',
angular: '../../bower_components/angular/angular',
'angular-route': '../../bower_components/angular-route/angular-route',
'angular-cookies': '../../bower_components/angular-cookies/angular-cookies',
'angular-translate': '../../bower_components/angular-translate/angular-translate',
'angular-mocks': '../../bower_components/angular-mocks/angular-mocks',
button: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button',
bootstrap: '../../bower_components/bootstrap/dist/js/bootstrap',
carousel: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel',
collapse: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/collapse',
dropdown: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/dropdown',
'es5-shim': '../../bower_components/es5-shim/es5-shim',
jquery: '../../bower_components/jquery/dist/jquery',
json3: '../../bower_components/json3/lib/json3',
modal: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal',
moment: '../../bower_components/moment/moment',
popover: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/popover',
requirejs: '../../bower_components/requirejs/require',
scrollspy: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy',
tab: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab',
tooltip: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip',
transition: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition',
'font-awesome': '../../bower_components/font-awesome',
'bootstrap-sass-official': '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap',
'angular-animate': '../../bower_components/angular-animate/angular-animate',
'angular-bootstrap': '../../bower_components/angular-bootstrap/ui-bootstrap-tpls',
'jquery-mousewheel': '../../bower_components/jquery-mousewheel/jquery.mousewheel',
'angular-material': '../../bower_components/angular-material/angular-material',
'angular-aria': '../../bower_components/angular-aria/angular-aria',
lodash: '../../bower_components/lodash/dist/lodash',
restangular: '../../bower_components/restangular/dist/restangular',
affix: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix',
alert: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert',
angular: '../bower_components/angular/angular',
'angular-route': '../bower_components/angular-route/angular-route',
'angular-cookies': '../bower_components/angular-cookies/angular-cookies',
'angular-translate': '../bower_components/angular-translate/angular-translate',
'angular-mocks': '../bower_components/angular-mocks/angular-mocks',
button: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button',
bootstrap: '../bower_components/bootstrap/dist/js/bootstrap',
carousel: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel',
collapse: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/collapse',
dropdown: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/dropdown',
'es5-shim': '../bower_components/es5-shim/es5-shim',
jquery: '../bower_components/jquery/dist/jquery',
json3: '../bower_components/json3/lib/json3',
modal: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal',
moment: '../bower_components/moment/moment',
popover: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/popover',
requirejs: '../bower_components/requirejs/require',
scrollspy: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy',
tab: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab',
tooltip: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip',
transition: '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition',
'font-awesome': '../bower_components/font-awesome',
'bootstrap-sass-official': '../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap',
'angular-animate': '../bower_components/angular-animate/angular-animate',
'angular-bootstrap': '../bower_components/angular-bootstrap/ui-bootstrap-tpls',
'jquery-mousewheel': '../bower_components/jquery-mousewheel/jquery.mousewheel',
'angular-material': '../bower_components/angular-material/angular-material',
'angular-aria': '../bower_components/angular-aria/angular-aria',
lodash: '../bower_components/lodash/dist/lodash',
restangular: '../bower_components/restangular/dist/restangular',

// all directives templates should go here and on shim section
'backdrop-template': '../views/directives/backdrop.html',
Expand Down
11 changes: 5 additions & 6 deletions app/styles/main.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
$icon-font-path: "../bower_components/bootstrap-sass-official/assets/fonts/bootstrap/";
$fa-font-path: "/bower_components/font-awesome/fonts";
$icon-font-path: '../bower_components/bootstrap-sass-official/assets/fonts/bootstrap/';
$fa-font-path: '../bower_components/font-awesome/fonts';
// bower:scss
@import 'bootstrap-sass-official/assets/stylesheets/_bootstrap.scss';
@import 'font-awesome/scss/font-awesome.scss';
@import 'bootstrap-sass-official/assets/stylesheets/bootstrap';
@import 'font-awesome/scss/font-awesome';
// endbower

@import 'modules/variables/importer';
@import 'modules/common';
@import 'modules/_tables';
@import 'modules/tables';
@import 'modules/filters';
@import 'directives/navbar';
@import 'directives/sidebar';
@import 'directives/backdrop';
@import 'partials/index';
@import 'partials/home';
@import 'partials/students/_index';
Loading

0 comments on commit 9c9fd70

Please sign in to comment.