blob: ac434473df0f111a3a92b2982c62df135ecb8ccb [file] [log] [blame]
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:pub_semver/pub_semver.dart';
import '../package_name.dart';
import '../pubspec.dart';
import '../source.dart';
import '../system_cache.dart';
/// A [Null Object] that represents a source not recognized by pub.
/// It provides some default behavior so that pub can work with sources it
/// doesn't recognize.
/// [null object]:
class UnknownSource extends Source {
final String name;
BoundSource bind(SystemCache systemCache) =>
_BoundUnknownSource(this, systemCache);
/// Two unknown sources are the same if their names are the same.
bool operator ==(other) => other is UnknownSource && == name;
int get hashCode => name.hashCode;
bool descriptionsEqual(description1, description2) =>
description1 == description2;
int hashDescription(description) => description.hashCode;
PackageRef parseRef(String name, description, {String containingPath}) =>
PackageRef(name, this, description);
PackageId parseId(String name, Version version, description,
{String containingPath}) =>
PackageId(name, this, version, description);
class _BoundUnknownSource extends BoundSource {
final UnknownSource source;
final SystemCache systemCache;
_BoundUnknownSource(this.source, this.systemCache);
Future<List<PackageId>> doGetVersions(PackageRef ref) =>
throw UnsupportedError(
"Cannot get package versions from unknown source '${}'.");
Future<Pubspec> doDescribe(PackageId id) => throw UnsupportedError(
"Cannot describe a package from unknown source '${}'.");
Future get(PackageId id, String symlink) =>
throw UnsupportedError("Cannot get an unknown source '${}'.");
/// Returns the directory where this package can be found locally.
String getDirectory(PackageId id) => throw UnsupportedError(
"Cannot find a package from an unknown source '${}'.");