Skip to content

Commit 4cc135a

Browse files
authored
Merge pull request #275 from nexB/243-license-expression
Add support for License Expressions
2 parents 20e37e0 + a20437b commit 4cc135a

18 files changed

Lines changed: 13211 additions & 42 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ targeted platform.
9090

9191
## Testing
9292

93-
Test functionality using:
93+
Test ABCM functionality using:
9494

9595
```bash
9696
$ npm test
@@ -109,4 +109,4 @@ If you have a question, a suggestion or find a bug, enter an issue.
109109

110110
[![Gitter chat](https://badges.gitter.im/aboutcode-org/gitter.png)](https://gitter.im/aboutcode-org/discuss)
111111

112-
For questions and chats, you can join the Gitter channel at https://gitter.im/aboutcode-org/discuss
112+
For questions and chats, you can join the Gitter channel at https://gitter.im/aboutcode-org/discuss

assets/app/js/aboutCodeDB.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class AboutCodeDB {
298298
});
299299
return this.db.File.bulkCreate(files, options)
300300
.then(() => this.db.License.bulkCreate(this._addFileIds(files, 'licenses'), options))
301+
.then(() => this.db.LicenseExpression.bulkCreate(this._addFileIdsExpressions(files, 'license_expressions'), options))
301302
.then(() => this.db.Copyright.bulkCreate(this._addFileIds(files, 'copyrights'), options))
302303
.then(() => this.db.Package.bulkCreate(this._addFileIds(files, 'packages'), options))
303304
.then(() => this.db.Email.bulkCreate(this._addFileIds(files, 'emails'), options))
@@ -318,8 +319,19 @@ class AboutCodeDB {
318319
});
319320
});
320321
}
322+
323+
_addFileIdsExpressions(files, attribute) {
324+
return $.map(files, (file) => {
325+
return $.map(file[attribute] || [], (value) => {
326+
return {
327+
license_expression: value,
328+
fileId: file.id
329+
};
330+
});
331+
});
332+
}
321333
}
322334

323335
AboutCodeDB.MissingFileInfoError = class MissingFileInfoError extends Error {};
324336

325-
module.exports = AboutCodeDB;
337+
module.exports = AboutCodeDB;

assets/app/js/controllers/aboutCodeClueDataTable.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,13 @@ AboutCodeClueDataTable.COPYRIGHT_COLUMNS =
503503

504504
AboutCodeClueDataTable.LICENSE_COLUMNS =
505505
[
506+
{
507+
'data': 'license_expressions[<hr/>]',
508+
'title': 'License Expressions',
509+
'name': 'license_expressions',
510+
'bar_chart_class': 'bar-chart-licenses',
511+
'visible': false
512+
},
506513
{
507514
'data': 'license_key[<hr/>]',
508515
'title': 'License Key',

assets/app/js/controllers/aboutCodeComponentDataTable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class AboutCodeComponentDataTable extends Controller {
132132
name: 'owner'
133133
},
134134
{
135-
data: 'licenses[<hr/>].key',
136-
title: 'License',
135+
data: 'license_expression[<hr/>].license_expression',
136+
title: 'License Expression',
137137
name: 'license_expression'
138138
},
139139
{

assets/app/js/controllers/componentDialog.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ComponentDialog extends Controller {
2929
this.title = this.dialog.find('.modal-title');
3030
this.status = this.dialog.find('#component-status');
3131
this.name = this.dialog.find('#component-name');
32-
this.license = this.dialog.find('#component-license');
32+
this.license_expression = this.dialog.find('#component-license-expression');
3333
this.owner = this.dialog.find('#component-owner');
3434
this.copyright = this.dialog.find('#component-copyright');
3535
this.deployed = this.dialog.find('input[name=component-deployed]');
@@ -100,8 +100,8 @@ class ComponentDialog extends Controller {
100100
fileId: component.fileId,
101101
review_status: this.status.val(),
102102
name: this.name.val(),
103-
licenses: $.map(this.license.val() || [], (license) => {
104-
return { key: license };
103+
license_expression: $.map(this.license_expression.val() || [], (license_expression) => {
104+
return { license_expression: license_expression };
105105
}),
106106
copyrights: $.map(this.copyright.val() || [], (copyright) => {
107107
return { statements: copyright.split('\n') };
@@ -147,7 +147,7 @@ class ComponentDialog extends Controller {
147147
this._setupStatus(component),
148148
this._setupName(component),
149149
this._setupVersion(component),
150-
this._setupLicenses(component),
150+
this._setupLicenseExpression(component),
151151
this._setupCopyrights(component),
152152
this._setupOwners(component),
153153
this._setupLanguage(component),
@@ -190,18 +190,18 @@ class ComponentDialog extends Controller {
190190
.then((component) => component ? component : { path: path });
191191
}
192192

193-
_setupLicenses(component) {
194-
const saved = (component.licenses || []).map((license) => license.key);
195-
return this._licenseQuery(component.path, 'key')
196-
.then((license_keys) => license_keys.concat(saved))
197-
.then((license_keys) => {
198-
this.license.html('').select2({
199-
data: $.unique(license_keys),
193+
_setupLicenseExpression(component) {
194+
const saved = (component.license_expression || []).map((license_expression) => license_expression);
195+
return this._licenseExpressionQuery(component.path, 'license_expression')
196+
.then((license_expressions) => license_expressions.concat(saved))
197+
.then((license_expressions) => {
198+
this.license_expression.html('').select2({
199+
data: $.unique(license_expressions),
200200
multiple: true,
201-
placeholder: 'Enter license',
201+
placeholder: 'Enter Expression',
202202
tags: true
203203
}, true);
204-
this.license.val(saved);
204+
this.license_expression.val(saved);
205205
});
206206
}
207207

@@ -401,6 +401,10 @@ class ComponentDialog extends Controller {
401401
_licenseQuery(path, field) {
402402
return this.db().findAllUnique(path, field, this.db().db.License);
403403
}
404+
405+
_licenseExpressionQuery(path, field) {
406+
return this.db().findAllUnique(path, field, this.db().db.LicenseExpression);
407+
}
404408
}
405409

406-
module.exports = ComponentDialog;
410+
module.exports = ComponentDialog;

assets/app/js/controllers/dejacodeExportDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ class DejaCodeExportDialog extends Controller {
145145
}
146146
}
147147

148-
module.exports = DejaCodeExportDialog;
148+
module.exports = DejaCodeExportDialog;

assets/app/js/models/component.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function(sequelize, DataTypes) {
2424
review_status: DataTypes.STRING,
2525
name: DataTypes.STRING,
2626
version: DataTypes.STRING,
27-
licenses: jsonDataType('licenses'),
27+
license_expression: jsonDataType('license_expression'),
2828
copyrights: jsonDataType('copyrights'),
2929
owner: DataTypes.STRING,
3030
code_type: DataTypes.STRING,
@@ -41,16 +41,11 @@ module.exports = function(sequelize, DataTypes) {
4141
},
4242
{
4343
getterMethods: {
44-
license_expression: function() {
45-
return $.map(this.licenses, (license) => {
46-
return license.key;
47-
}).join(' AND ');
48-
},
4944
copyright: function() {
5045
return $.map(this.copyrights, (copyright) => {
5146
return copyright.statements.join(' ');
5247
}).join('\n');
5348
}
5449
}
5550
});
56-
};
51+
};

assets/app/js/models/database.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
const headerModel = require('./header');
1818
const fileModel = require('./file');
1919
const licenseModel = require('./license');
20+
const licenseExpressionModel = require('./licenseExpression');
2021
const copyrightModel = require('./copyright');
2122
const packageModel = require('./package');
2223
const emailModel = require('./email');
@@ -29,6 +30,7 @@ module.exports = function(sequelize, DataTypes) {
2930
this.Header = headerModel(sequelize, DataTypes);
3031
this.File = fileModel(sequelize, DataTypes);
3132
this.License = licenseModel(sequelize, DataTypes);
33+
this.LicenseExpression = licenseExpressionModel(sequelize, DataTypes);
3234
this.Copyright = copyrightModel(sequelize, DataTypes);
3335
this.Package = packageModel(sequelize, DataTypes);
3436
this.Email = emailModel(sequelize, DataTypes);
@@ -40,6 +42,7 @@ module.exports = function(sequelize, DataTypes) {
4042
// Define the relations
4143
this.Header.hasMany(this.File);
4244
this.File.hasMany(this.License);
45+
this.File.hasMany(this.LicenseExpression);
4346
this.File.hasMany(this.Copyright);
4447
this.File.hasMany(this.Package);
4548
this.File.hasMany(this.Email);
@@ -49,6 +52,7 @@ module.exports = function(sequelize, DataTypes) {
4952
// Include Array for queries
5053
this.fileIncludes = [
5154
{ model: this.License, separate: true },
55+
{ model: this.LicenseExpression, separate: true },
5256
{ model: this.Copyright, separate: true },
5357
{ model: this.Package, separate: true },
5458
{ model: this.Email, separate: true },

assets/app/js/models/flatFile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function(sequelize, DataTypes) {
3131
copyright_authors: jsonDataType('copyright_authors'),
3232
copyright_start_line: jsonDataType('copyright_start_line'),
3333
copyright_end_line: jsonDataType('copyright_end_line'),
34+
license_expressions: jsonDataType('license_expressions'),
3435
license_key: jsonDataType('license_key'),
3536
license_score: jsonDataType('license_score'),
3637
license_short_name: jsonDataType('license_short_name'),
@@ -177,6 +178,7 @@ module.exports = function(sequelize, DataTypes) {
177178
copyright_authors: getValues(file.copyrights, 'authors'),
178179
copyright_start_line: getValues(file.copyrights, 'start_line'),
179180
copyright_end_line: getValues(file.copyrights, 'end_line'),
181+
license_expressions: file.license_expressions,
180182
license_key: getValues(file.licenses, 'key'),
181183
license_score: getValues(file.licenses, 'score'),
182184
license_short_name: getValues(file.licenses, 'short_name'),
@@ -301,4 +303,4 @@ function getNestedValues(array, key, nestedKey) {
301303
return [nestedElem[nestedKey] ? nestedElem[nestedKey] : []];
302304
});
303305
});
304-
}
306+
}

assets/app/js/models/license.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ module.exports = function(sequelize, DataTypes) {
3737
{
3838
timestamps: false
3939
});
40-
};
40+
};

0 commit comments

Comments
 (0)