IDE: package editor: add dependency: check for cycle

git-svn-id: trunk@34540 -
This commit is contained in:
mattias 2012-01-02 17:06:11 +00:00
parent eb06e0d323
commit 51a5483ed9
3 changed files with 33 additions and 5 deletions

View File

@ -3392,7 +3392,14 @@ resourcestring
lisProjAddThePackageNameIsInvalidPlaseChooseAnExistingPackag = 'The package '
+'name %s%s%s is invalid.%sPlase choose an existing package.';
lisProjAddDependencyAlreadyExists = 'Dependency already exists';
lisUnableToAddTheDependencyBecauseThePackageHasAlread2 = 'Unable to add the '
+'dependency %s, because the package %s has already a dependency to %s';
lisVersionMismatch = 'Version mismatch';
lisUnableToAddTheDependencyBecauseThePackageHasAlread = 'Unable to add the '
+'dependency %s, because the package %s has already a dependency %s';
lisCycleDetected = 'Cycle detected';
lisUnableToAddTheDependencyBecauseThisWouldCreateACyc = 'Unable to add the '
+'dependency %s, because this would create a cycle. Dependency %s';
lisProjAddTheProjectHasAlreadyADependency = 'The project has already a '
+'dependency for the package %s%s%s.';
lisProjAddPackageNotFound = 'Package not found';

View File

@ -422,7 +422,6 @@ begin
RequiredPackage:=PackageGraph.FindPackageWithName(NewPkgName,nil);
if RequiredPackage<>nil then begin
// check if there is a dependency, that requires another version
ConflictDependency:=PackageGraph.FindConflictRecursively(
LazPackage.FirstRequiredDependency,RequiredPackage);
@ -430,7 +429,22 @@ begin
DebugLn(['CheckAddingDependency ',LazPackage.Name,' requiring ',RequiredPackage.IDAsString,' conflicts with ',ConflictDependency.AsString]);
if not Quiet then
IDEMessageDialog(lisVersionMismatch,
'Unable to add the dependency '+RequiredPackage.IDAsString+', because the package '+LazPackage.Name+' has already a dependency '+ConflictDependency.AsString,
Format(lisUnableToAddTheDependencyBecauseThePackageHasAlread, [
RequiredPackage.IDAsString, LazPackage.Name, ConflictDependency.
AsString]),
mtError,[mbCancel]);
exit(mrCancel);
end;
// check if there is a cycle
ConflictDependency:=PackageGraph.FindDependencyRecursively(
RequiredPackage.FirstRequiredDependency,LazPackage.Name);
if ConflictDependency<>nil then begin
DebugLn(['CheckAddingDependency ',LazPackage.Name,' requiring ',RequiredPackage.IDAsString,' conflicts with ',ConflictDependency.AsString]);
if not Quiet then
IDEMessageDialog(lisCycleDetected,
Format(lisUnableToAddTheDependencyBecauseThisWouldCreateACyc, [
RequiredPackage.IDAsString, ConflictDependency.AsString(true)]),
mtError,[mbCancel]);
exit(mrCancel);
end;
@ -444,7 +458,8 @@ begin
DebugLn(['CheckAddingDependency ',LazPackage.Name,' requiring ',NewPkgName,', but is already provided by ',ProvidingAPackage.IDAsString]);
if WarnIfAlreadyThere then
IDEMessageDialog(lisProjAddDependencyAlreadyExists,
'Unable to add the dependency '+RequiredPackage.IDAsString+', because the package '+LazPackage.Name+' has already a dependency to '+ProvidingAPackage.Name,
Format(lisUnableToAddTheDependencyBecauseThePackageHasAlread2, [
RequiredPackage.IDAsString, LazPackage.Name, ProvidingAPackage.Name]),
mtError,[mbCancel]);
exit(mrIgnore);
end;

View File

@ -293,7 +293,7 @@ type
procedure ConsistencyCheck;
function IsCompatible(Pkg: TLazPackageID): boolean;
procedure MakeCompatible(const PkgName: string; const Version: TPkgVersion);
function AsString: string;
function AsString(WithOwner: boolean = false): string;
function NextUsedByDependency: TPkgDependency;
function PrevUsedByDependency: TPkgDependency;
function NextRequiresDependency: TPkgDependency;
@ -1955,13 +1955,19 @@ begin
if MaxVersion.Compare(Version)<0 then MaxVersion.Assign(Version);
end;
function TPkgDependency.AsString: string;
function TPkgDependency.AsString(WithOwner: boolean): string;
begin
if Self=nil then
exit('(nil)');
Result:=FPackageName;
if pdfMinVersion in FFlags then
Result:=Result+' (>='+MinVersion.AsString+')';
if pdfMaxVersion in FFlags then
Result:=Result+' (<='+MaxVersion.AsString+')';
if WithOwner then begin
if Owner is TLazPackage then
Result:=TLazPackage(Owner).Name+' uses '+Result;
end;
end;
function TPkgDependency.NextUsedByDependency: TPkgDependency;