Skip to content

Commit

Permalink
Merge pull request #41 from icapps/feature/#37-skip-license
Browse files Browse the repository at this point in the history
#37: added ignore option
  • Loading branch information
jorre127 authored Jan 22, 2025
2 parents b6198f5 + 54abd5a commit 8e03f0c
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## [2.1.0] - 2023-09-13
### Added
- Option to ignore certain packages
## [2.0.0] - 2022-06-05
### Breaking
- Updated to the dart 3.0.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ license_generator:
pub_dev_base_url: String #(optional) This will override the default pubdev base url for downloading the pubdev details (homepage/repository) -> Default: https://pub.dev
licenses: #(optional) This will accept key value pairs (String/String) -> (package name/raw license url)
#license_generator: https://raw.githubusercontent.com/icapps/flutter-icapps-license/master/LICENSE (example)
ignore_licenses: #(optional) This wil accept a list of package names (String)
- shared_preferences
extra_licenses: #(optional) this will allow you to add extra licenses that are not added in your pubspec.yaml
something_something: #the name of your package will be used if `name` is not specified
name: String #(optional) This will override your package name
Expand Down
23 changes: 20 additions & 3 deletions bin/src/model/pubspec.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:path/path.dart';
import 'package:yaml/yaml.dart';

import '../util/logger.dart';
import 'dto/dependency.dart';
import 'dto/extra_dependency.dart';
Expand All @@ -21,6 +22,7 @@ class Params {
static const yamlConfigPubDevBaseUrl = 'pub_dev_base_url';
static const yamlConfigLicensesList = 'licenses';
static const yamlConfigExtraLicensesList = 'extra_licenses';
static const yamlConfigIgnoreLicenses = 'ignore_licenses';

late PubspecLock pubspecLock;
String fileOutputPath = defaultFileOutputPath;
Expand Down Expand Up @@ -73,10 +75,20 @@ class Params {
icappsLicenseConfig[yamlConfigExtraLicensesList] as YamlMap?);
}

final ignoredPackages =
icappsLicenseConfig?[yamlConfigIgnoreLicenses] as YamlList?;
final packages = config['dependencies'] as YamlMap?;
final devPackages = config['dev_dependencies'] as YamlMap?;
_generateDependencies(packages: packages, isDevDependency: false);
_generateDependencies(packages: devPackages, isDevDependency: true);
_generateDependencies(
packages: packages,
isDevDependency: false,
ignoredPackages: ignoredPackages,
);
_generateDependencies(
packages: devPackages,
isDevDependency: true,
ignoredPackages: ignoredPackages,
);

final containsLicenseGenerator = devDependencies
.where((element) => element.name == yamlConfigLicense)
Expand All @@ -102,7 +114,9 @@ class Params {
}

void _generateDependencies(
{required YamlMap? packages, required bool isDevDependency}) {
{required YamlMap? packages,
required bool isDevDependency,
required YamlList? ignoredPackages}) {
final type = isDevDependency ? 'dev_dependencies' : 'dependencies';
if (packages != null) {
for (final package in packages.keys) {
Expand All @@ -111,6 +125,9 @@ class Params {
throw ArgumentError(
'package should be a String: the name of the package');
}
if (ignoredPackages?.contains(package) == true) {
continue;
}
final dynamic values = packages.value[package];
Dependency dependency;
if (values is String) {
Expand Down
33 changes: 0 additions & 33 deletions example/lib/util/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,39 +212,6 @@ SOFTWARE.''',
homepage: null,
repository: r'https://github.com/rrousselGit/provider',
),
const License(
name: r'shared_preferences',
license: r'''Copyright 2013 The Flutter Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
''',
version: r'^2.1.1',
homepage: null,
repository:
r'https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences',
),
];
}
}
30 changes: 15 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
fast_barcode_scanner:
dependency: "direct main"
description:
Expand Down Expand Up @@ -116,18 +116,10 @@ packages:
dependency: transitive
description:
name: intl
sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.18.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
version: "0.18.1"
license_generator:
dependency: "direct dev"
description:
Expand All @@ -147,10 +139,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -332,6 +324,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
win32:
dependency: transitive
description:
Expand All @@ -357,5 +357,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.0.0"
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ license_generator:
check_before_generate: true
licenses:
# license_generator: https://raw.githubusercontent.com/icapps/flutter-icapps-license/master/LICENSE
ignore_licenses:
- shared_preferences
extra_licenses:
something_something:
name: Something Something
Expand Down
90 changes: 86 additions & 4 deletions test/command/generate_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dart:io';

import 'package:path/path.dart';
import 'package:test/test.dart';

import '../../bin/src/command/generate_command.dart';
import '../../bin/src/model/dto/dependency.dart';
import '../../bin/src/model/dto/dependency_license_data.dart';
import '../../bin/src/model/dto/dependency_lock.dart';
import '../../bin/src/model/dto/extra_dependency.dart';
import '../../bin/src/model/pubspec.dart';
import '../../bin/src/command/generate_command.dart';
import '../../bin/src/repo/license_repository.dart';

void main() {
Expand Down Expand Up @@ -73,7 +74,88 @@ class LicenseUtil {
static List<License> getLicenses() {
return [
License(
const License(
name: r'license_generator',
license: r'''this is the license_generator license''',
version: r'1.0.0',
homepage: null,
repository: null,
),
];
}
}
""");
});

test('Test generate command with ignore', () async {
const yaml = r'''
name: test_example
dependencies:
shared_preferences: ^2.1.1
dev_dependencies:
license_generator: 1.0.0
license_generator:
ignore_licenses:
- shared_preferences
''';
const lock = r'''
packages:
license_generator:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "1.0.0"
shared_preferences:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "2.1.1"
''';
final params = Params(yaml, lock);
final repo = TestLicenseRepository({
'license_generator': const DependencyLicenseData(
license: 'this is the license_generator license'),
'shared_preferences': const DependencyLicenseData(
license: 'this is the shared_preference license'),
});
params.fileOutputPath = outputPath;
final generateCommand = GenerateCommand(repo);
await generateCommand.generateLicenses(params);
final data = File(outputPath).readAsStringSync();
expect(data, """import 'package:flutter/widgets.dart';
//============================================================//
//THIS FILE IS AUTO GENERATED. DO NOT EDIT//
//============================================================//
@immutable
class License {
final String name;
final String license;
final String? version;
final String? homepage;
final String? repository;
const License({
required this.name,
required this.license,
this.version,
this.homepage,
this.repository,
});
}
class LicenseUtil {
LicenseUtil._();
static List<License> getLicenses() {
return [
const License(
name: r'license_generator',
license: r'''this is the license_generator license''',
version: r'1.0.0',
Expand Down Expand Up @@ -141,7 +223,7 @@ class LicenseUtil {
static List<License> getLicenses() {
return [
License(
const License(
name: r'license_generator',
license: r'''this is the license_generator license''',
version: r'1.0.0',
Expand Down Expand Up @@ -218,7 +300,7 @@ class LicenseUtil {
static List<License> getLicenses() {
return [
License(
const License(
name: r'license_generator',
license: r'''this is the license_generator license''',
version: null,
Expand Down
6 changes: 4 additions & 2 deletions test/repo/license_repository_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ void main() {
),
throwsA(predicate((e) =>
e is FatalException &&
e.message == "Failed to get the license url for 'test_package'")),
e.message ==
".dart_tool/package_config.json is not up to date. Path: 'test/repo/test_data/no-local-license-file-dev/test_package-1.0.0' does not exist anymore.")),
);
});

Expand All @@ -290,7 +291,8 @@ void main() {
),
throwsA(predicate((e) =>
e is FatalException &&
e.message == "Failed to get the license url for 'test_package'")),
e.message ==
".dart_tool/package_config.json is not up to date. Path: 'test/repo/test_data/no-local-license-file-dev/test_package-1.0.0' does not exist anymore.")),
);
});

Expand Down

0 comments on commit 8e03f0c

Please sign in to comment.