Skip to content

Commit

Permalink
Add license header check/update tasks and updpdate existing headers (k…
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks authored Jun 16, 2017
1 parent d1c25be commit 4cc5be2
Show file tree
Hide file tree
Showing 1,064 changed files with 1,535 additions and 1,081 deletions.
70 changes: 69 additions & 1 deletion build/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
/**
* @fileoverview Gulp tasks for checking and validating the code or a commit.
*/
import fs from 'fs';
import gulp from 'gulp';
import gulpClangFormat from 'gulp-clang-format';
import gulpEslint from 'gulp-eslint';
import filter from 'gulp-filter';
import license from 'gulp-header-license';
import licenseCheck from 'gulp-license-check';
import gulpSassLint from 'gulp-sass-lint';
import beautify from 'js-beautify';
import path from 'path';
Expand All @@ -38,7 +42,7 @@ const htmlBeautify = beautify.html;
*
* This task should be used prior to publishing a change.
**/
gulp.task('check', ['lint', 'test', 'integration-test:prod']);
gulp.task('check', ['check-license-headers', 'lint', 'test', 'integration-test:prod']);

/**
* Checks the code quality (integration tests only) of Dashboard. In addition a local kubernetes
Expand Down Expand Up @@ -133,6 +137,70 @@ gulp.task('format-go', function(doneFn) {
doneFn);
});

/**
* Checks and prints all source files for presence of up-to-date license headers.
* License header templates are stored in 'license' directory.
*/
gulp.task('check-license-headers', () => {
const HEADER_NOT_PRESENT = 'Header not present';
const commonFilter = filter('**/*.{js,go}', {restore: true});
const htmlFilter = filter('**/*.html', {restore: true});

let hasErrors = false;
const handleLogEvent = (event) => {
if (!hasErrors && event.msg.startsWith(HEADER_NOT_PRESENT)) {
hasErrors = true;
}
};

const handleEndEvent = () => {
if (hasErrors) {
throw new Error('License headers need to be present in all files.');
}
};

return gulp.src([path.join(conf.paths.src, '**/*.{js,go,html}')], {base: conf.paths.base})
.pipe(commonFilter)
.pipe(licenseCheck(licenseConfig('license/header.txt')).on('log', handleLogEvent))
.pipe(commonFilter.restore)
.pipe(htmlFilter)
.pipe(licenseCheck(licenseConfig('license/header_html.txt')).on('log', handleLogEvent))
.pipe(htmlFilter.restore)
.on('end', handleEndEvent);
});

/**
* Returns config object for gulp-license-check plugin.
* @param {string} licenseFilePath
* @return {Object}
*/
function licenseConfig(licenseFilePath) {
return {
path: licenseFilePath,
blocking: false,
logInfo: false,
logError: true,
};
}

/**
* Updates license headers in all source files based on templates stored in 'license' directory.
*/
gulp.task('update-license-headers', () => {
const commonFilter = filter('**/*.{js,go}', {restore: true});
const htmlFilter = filter('**/*.html', {restore: true});
const matchRate = 0.9;

gulp.src([path.join(conf.paths.src, '**/*.{js,go,html}')], {base: conf.paths.base})
.pipe(commonFilter)
.pipe(license(fs.readFileSync('license/header.txt', 'utf8'), {}, matchRate))
.pipe(commonFilter.restore)
.pipe(htmlFilter)
.pipe(license(fs.readFileSync('license/header_html.txt', 'utf8'), {}, matchRate))
.pipe(htmlFilter.restore)
.pipe(gulp.dest(conf.paths.base));
});

/**
* Can be used as gulp pipe function to format HTML files.
*
Expand Down
13 changes: 13 additions & 0 deletions license/header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// 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.
15 changes: 15 additions & 0 deletions license/header_html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
Copyright 2017 The Kubernetes Dashboard Authors.

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.
-->
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
"gulp-concat": "~2.6.1",
"gulp-css-url-adjuster": "^0.2.3",
"gulp-eslint": "~3.0.1",
"gulp-filter": "^5.0.0",
"gulp-flatten": "~0.3.1",
"gulp-header-license": "^1.0.9",
"gulp-htmlmin": "~3.0.0",
"gulp-if": "~2.0.2",
"gulp-inject": "~4.2.0",
"gulp-license-check": "^1.2.1",
"gulp-minify-css": "~1.2.4",
"gulp-modify": "~0.1.1",
"gulp-protractor": "~4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/api/types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/api/types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/client/manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/client/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/client/verber.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions src/app/backend/client/verber_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// 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.

package client

import (
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/apihandler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions src/app/backend/handler/apihandler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// 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.

package handler

import (
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/confighandler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/filter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/gziphandler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/localehandler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions src/app/backend/handler/localehandler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// 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.

package handler

import (
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/metrics.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/integration/metric/heapster/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/cluster/cluster.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/condition.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/endpoint.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/event.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/namespace.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/namespace_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/pod.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/pod_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/podinfo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/podinfo_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/podmetrics.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/podmetrics_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/resourcechannels.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/service_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/resource/common/serviceport.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 4cc5be2

Please sign in to comment.