Skip to content

Commit

Permalink
HAWKULAR-24: added custom rules for license checking
Browse files Browse the repository at this point in the history
Adding TSLint license checker
  • Loading branch information
Viliam Rockai committed Feb 19, 2015
1 parent b884354 commit 697f385
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 194 deletions.
198 changes: 14 additions & 184 deletions dist/hawkular-ui-service.js
Original file line number Diff line number Diff line change
@@ -1,187 +1,25 @@
/// <reference path="../../lib/hawtio-core-dts/angular.d.ts" />
/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// 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.
var hawkularRest;
(function (hawkularRest) {
hawkularRest._module = angular.module('hawkular.services', ['ngResource']);
})(hawkularRest || (hawkularRest = {}));

/**
* @ngdoc provider
* @name hawkular.rest.HawkularAlert
* @description
* # HawkularAlert
* Provider in the hawkular.rest.
*/
var hawkularRest;
(function (hawkularRest) {
hawkularRest._module.provider('HawkularAlert', function () {
// time (in ms) the notifications are shown
this.host = 'localhost';
this.port = 8080;
this.setHost = function (host) {
this.host = host;
return this;
};
this.setPort = function (port) {
this.port = port;
return this;
};
this.$get = ['$resource', function ($resource) {
var prefix = 'http://' + this.host + ':' + this.port;
var factory = {};
factory.Alert = $resource(prefix + '/hawkular/alerts', {}, {
reload: {
method: 'GET',
url: prefix + '/hawkular/alerts/reload'
}
});
factory.Trigger = $resource(prefix + '/hawkular/alerts/triggers/:triggerId', {
triggerId: '@triggerId'
}, {
save: {
method: 'POST',
url: prefix + '/hawkular/alerts/triggers/'
},
put: {
method: 'PUT'
},
conditions: {
method: 'GET',
url: prefix + '/hawkular/alerts/triggers/:triggerId/conditions',
isArray: true,
params: {
triggerId: '@triggerId'
}
}
});
factory.Dampening = $resource(prefix + '/hawkular/alerts/trigger/dampening/:triggerId', {
triggerId: '@triggerId'
}, {
save: {
method: 'POST',
url: prefix + '/hawkular/alerts/trigger/dampening/'
},
put: {
method: 'PUT'
}
});
factory.AvailabilityCondition = $resource(prefix + '/hawkular/alerts/conditions/availability/:conditionId', {
conditionId: '@conditionId'
}, {
put: {
method: 'PUT'
},
trigger: {
method: 'GET',
url: prefix + '/hawkular/alerts/conditions/availability/trigger/:triggerId',
isArray: true,
params: {
triggerId: '@triggerId'
}
}
});
factory.CompareCondition = $resource(prefix + '/hawkular/alerts/conditions/compare/:conditionId', {
conditionId: '@conditionId'
}, {
put: {
method: 'PUT'
},
trigger: {
method: 'GET',
url: prefix + '/hawkular/alerts/conditions/compare/trigger/:triggerId',
isArray: true,
params: {
triggerId: '@triggerId'
}
}
});
factory.StringCondition = $resource(prefix + '/hawkular/alerts/conditions/string/:conditionId', {
conditionId: '@conditionId'
}, {
put: {
method: 'PUT'
},
trigger: {
method: 'GET',
url: prefix + '/hawkular/alerts/conditions/string/trigger/:triggerId',
isArray: true,
params: {
triggerId: '@triggerId'
}
}
});
factory.ThresholdCondition = $resource(prefix + '/hawkular/alerts/conditions/threshold/:conditionId', {
conditionId: '@conditionId'
}, {
put: {
method: 'PUT'
},
trigger: {
method: 'GET',
url: prefix + '/hawkular/alerts/conditions/threshold/trigger/:triggerId',
isArray: true,
params: {
triggerId: '@triggerId'
}
}
});
factory.ThresholdRangeCondition = $resource(prefix + '/hawkular/alerts/conditions/range/:conditionId', {
conditionId: '@conditionId'
}, {
put: {
method: 'PUT'
},
trigger: {
method: 'GET',
url: prefix + '/hawkular/alerts/conditions/range/trigger/:triggerId',
isArray: true,
params: {
triggerId: '@triggerId'
}
}
});
factory.NotifierType = $resource(prefix + '/hawkular/alerts/notifierType/:notifierType', {
notifierType: '@notifierType'
}, {
get: {
method: 'GET',
isArray: true
}
});
factory.Notifier = $resource(prefix + '/hawkular/alerts/notifiers/:notifierId', {
notifierId: '@notifierId'
}, {
put: {
method: 'PUT',
url: prefix + '/hawkular/alerts/notifiers/:notifierId',
params: {
notifierId: '@notifierId'
}
},
notifierType: {
method: 'GET',
isArray: true,
url: prefix + '/hawkular/alerts/notifiers/type/:notifierType',
params: {
notifierType: '@notifierType'
}
}
});
return factory;
}];
});
})(hawkularRest || (hawkularRest = {}));

/**
* @ngdoc provider
* @name hawkular.rest.HawkularInventory
* @description
* # HawkularInventory
* Provider in the hawkular.rest.
*/
var hawkularRest;
(function (hawkularRest) {
hawkularRest._module.provider('HawkularInventory', function () {
// time (in ms) the notifications are shown
this.host = 'localhost';
this.port = 8080;
this.setHost = function (host) {
Expand Down Expand Up @@ -213,17 +51,9 @@ var hawkularRest;
});
})(hawkularRest || (hawkularRest = {}));

/**
* @ngdoc provider
* @name hawkular.rest.HawkularMetric
* @description
* # HawkularRest
* Provider in the hawkular.rest.
*/
var hawkularRest;
(function (hawkularRest) {
hawkularRest._module.provider('HawkularMetric', function () {
// time (in ms) the notifications are shown
this.host = 'localhost';
this.port = 8080;
this.setHost = function (host) {
Expand Down
1 change: 1 addition & 0 deletions dist/hawkular-ui-service.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions gulp/scripts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var gulp = require('gulp'),
tslint = require('gulp-tslint');
tslintRules = require('../tslint.json');

var paths = gulp.paths;

Expand All @@ -11,18 +11,29 @@ var $ = require('gulp-load-plugins')({

gulp.task('tslint', function () {
gulp.src([paths.src + '/hawkRest.ts', paths.src + '/hawkRest-*.ts'])
.pipe(tslint())
.pipe(tslint.report('verbose'));
.pipe($.tslint({
rulesDirectory: './tslint-rules/'
}))
.pipe($.tslint.report('verbose'));
});

gulp.task('scripts', function () {

var license = tslintRules.rules['license-header'][1];

return gulp.src([paths.src + '/hawkRest.ts', paths.src + '/hawkRest-*.ts'])
.pipe($.typescript())
.pipe($.typescript({
removeComments: true
}))
.on('error', function handleError(err) {
console.error(err.toString());
this.emit('end');
})
.pipe($.concat('hawkular-ui-service.js'))
.pipe($.header(license))
.pipe(gulp.dest(paths.dist + '/'))
.pipe($.concat('hawkular-ui-service.min.js'))
.pipe($.uglify())
.pipe(gulp.dest(paths.dist + '/'));
});

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"chalk": "~0.5.1",
"del": "~0.1.3",
"gulp": "~3.8.10",
"gulp-autoprefixer": "~2.0.0",
"gulp-angular-templatecache": "~1.4.2",
"del": "~0.1.3",
"gulp-autoprefixer": "~2.0.0",
"gulp-concat": "2.4.2",
"gulp-load-plugins": "~0.7.1",
"gulp-header": "1.2.2",
"gulp-karma": "~0.0.4",
"gulp-load-plugins": "~0.7.1",
"gulp-tslint": "1.4.3",
"gulp-typescript": "~2.3.0",
"gulp-tslint": "1.4.2",
"wiredep": "~2.2.0",
"gulp-uglify": "1.1.0",
"karma-jasmine": "~0.3.1",
"karma-phantomjs-launcher": "~0.1.4",
"require-dir": "~0.1.0",
"chalk": "~0.5.1"
"wiredep": "~2.2.0"
},
"engines": {
"node": ">=0.10.0"
Expand Down
15 changes: 15 additions & 0 deletions src/rest/hawkRest-inventory-provider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// 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.

/**
* @ngdoc provider
* @name hawkular.rest.HawkularInventory
Expand Down
15 changes: 15 additions & 0 deletions src/rest/hawkRest-metric-factory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// 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.

/**
* @ngdoc provider
* @name hawkular.rest.HawkularMetric
Expand Down
15 changes: 15 additions & 0 deletions src/rest/hawkRest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// 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.

/// <reference path="../../lib/hawtio-core-dts/angular.d.ts" />

module hawkularRest {
Expand Down
28 changes: 28 additions & 0 deletions tslint-rules/licenseHeaderRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Rule() {
Lint.Rules.AbstractRule.apply(this, arguments);
}

Rule.prototype = Object.create(Lint.Rules.AbstractRule.prototype);
Rule.prototype.apply = function(sourceFile) {
return this.applyWithWalker(new LicenseHeaderWalker(sourceFile, this.getOptions()));
};

function LicenseHeaderWalker() {
Lint.RuleWalker.apply(this, arguments);
}

LicenseHeaderWalker.prototype = Object.create(Lint.RuleWalker.prototype);
LicenseHeaderWalker.prototype.visitSourceFile = function (node) {
// create a failure at the current position
var sourceText = this.getSourceFile().text;

var licenceHeader = this.getOptions()[0];

if ( sourceText.indexOf(licenceHeader) !== 0 ){
this.addFailure(this.createFailure(0, 0, "Missing or incorrect project license header."));
}

Lint.RuleWalker.prototype.visitSourceFile.call(this, node);
};

exports.Rule = Rule;
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"check-operator",
"check-separator",
"_check-type"
],
"license-header": [ true,
"/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates\n/// and other contributors as indicated by the @author tags.\n///\n/// Licensed under the Apache License, Version 2.0 (the \"License\");\n/// you may not use this file except in compliance with the License.\n/// You may obtain a copy of the License at\n///\n/// http://www.apache.org/licenses/LICENSE-2.0\n///\n/// Unless required by applicable law or agreed to in writing, software\n/// distributed under the License is distributed on an \"AS IS\" BASIS,\n/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n/// See the License for the specific language governing permissions and\n/// limitations under the License.\n"
]
}
}

0 comments on commit 697f385

Please sign in to comment.