1 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #*************************************************************************
22 # SourceConfig - Perl extension for parsing general info databases
26 #*************************************************************************
36 use File
::Temp
qw(tmpnam);
46 my $class = ref($proto) || $proto;
47 my $source_root = shift;
48 my @additional_repositories = @_;
51 $self->{USER_SOURCE_ROOT
} = undef;
52 if (defined $source_root) {
53 $source_root = Cwd
::realpath
($source_root);
54 $source_root =~ s/\\|\/$//;
55 $self->{USER_SOURCE_ROOT
} = $source_root;
56 $source_root .= '/..';
60 $source_root = $ENV{SRC_ROOT
};
62 $source_root = Cwd
::realpath
($source_root);
63 $self->{SOURCE_ROOT
} = $source_root;
66 $self->{REPOSITORIES
} = {};
67 $self->{MODULE_PATHS
} = {};
68 $self->{MODULE_REPOSITORY
} = {};
69 $self->{REAL_MODULES
} = {};
70 if (defined $self->{USER_SOURCE_ROOT
})
72 ${$self->{REPOSITORIES
}}{File
::Basename
::basename
($self->{USER_SOURCE_ROOT
})} = $self->{USER_SOURCE_ROOT
};
76 get_fallback_repository
($self);
78 foreach my $additional_repository (@additional_repositories)
80 ${$self->{REPOSITORIES
}}{File
::Basename
::basename
($additional_repository)} = $additional_repository;
83 get_module_paths
($self);
93 return sort keys %{$self->{REPOSITORIES
}};
96 sub get_module_repository
{
99 if (defined ${$self->{MODULE_REPOSITORY
}}{$module}) {
100 return ${$self->{MODULE_REPOSITORY
}}{$module};
102 Carp
::cluck
("No such module $module in active repositories!!\n");
107 sub get_module_path
{
110 if (defined ${$self->{MODULE_PATHS
}}{$module}) {
111 return ${$self->{MODULE_PATHS
}}{$module};
113 Carp
::cluck
("No path for module $module in active repositories!!\n");
122 return sort keys %{$self->{MODULE_PATHS
}};
125 sub get_active_modules
128 return sort keys %{$self->{REAL_MODULES
}};
135 return exists ($self->{REAL_MODULES
}{$module});
138 ##### private methods #####
140 sub get_repository_module_paths
{
142 my $repository = shift;
143 my $repository_path = ${$self->{REPOSITORIES
}}{$repository};
144 if (opendir DIRHANDLE
, $repository_path) {
145 foreach my $module (readdir(DIRHANDLE
)) {
146 next if (($module =~ /^\.+/) || (!-d
"$repository_path/$module"));
147 my $module_entry = $module;
148 if (($module !~ s/\.lnk$//) && ($module !~ s/\.link$//)) {
149 $self->{REAL_MODULES
}{$module}++;
151 my $possible_path = "$repository_path/$module_entry";
152 if (-d
$possible_path) {
153 if (defined ${$self->{MODULE_PATHS
}}{$module}) {
155 croak
("Ambiguous paths for module $module: $possible_path and " . ${$self->{MODULE_PATHS
}}{$module});
157 ${$self->{MODULE_PATHS
}}{$module} = $possible_path;
158 ${$self->{MODULE_REPOSITORY
}}{$module} = $repository;
163 croak
("Cannot read $repository_path repository content");
167 sub get_module_paths
{
169 foreach my $repository (keys %{$self->{REPOSITORIES
}}) {
170 get_repository_module_paths
($self, $repository);
172 croak
("No modules found!") if (!scalar keys %{$self->{MODULE_PATHS
}});
176 # Fallback - fallback repository is based on RepositoryHelper educated guess
178 sub get_fallback_repository
{
180 my $repository_root = RepositoryHelper
->new()->get_repository_root();
181 ${$self->{REPOSITORIES
}}{File
::Basename
::basename
($repository_root)} = $repository_root;
186 1; # needed by use or require