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 # RepositoryHelper - Perl for working with repositories
26 #*************************************************************************
28 package RepositoryHelper
;
36 #use File::Temp qw(tmpnam);
46 my $class = ref($proto) || $proto;
47 my $initial_directory = shift;
48 if ($initial_directory) {
49 $initial_directory = Cwd
::realpath
($initial_directory);
51 if ( defined $ENV{PWD
} ) {
52 $initial_directory = $ENV{PWD
};
53 } elsif (defined $ENV{_cwd
}) {
54 $initial_directory = $ENV{_cwd
};
56 $initial_directory = cwd
();
60 $self->{INITIAL_DIRECTORY
} = $initial_directory;
61 $self->{REPOSITORY_ROOT
} = undef;
62 if (! search_via_build_lst
($self))
64 croak
('Cannot determine source directory/repository for ' . $self->{INITIAL_DIRECTORY
});
71 sub get_repository_root
74 return $self->{REPOSITORY_ROOT
};
77 sub get_initial_directory
80 return $self->{INITIAL_DIRECTORY
};
83 sub search_via_build_lst
{
85 my $previous_dir = '';
86 my $rep_root_candidate = $self->{INITIAL_DIRECTORY
};
89 if ($rep_root_candidate eq '/') {
90 $test_file = '/prj/build.lst';
92 $test_file = $rep_root_candidate . '/prj/build.lst';
95 $self->{REPOSITORY_ROOT
} = File
::Basename
::dirname
($rep_root_candidate);
98 $previous_dir = $rep_root_candidate;
99 $rep_root_candidate = File
::Basename
::dirname
($rep_root_candidate);
100 return 0 if ((!$rep_root_candidate) || ($rep_root_candidate eq $previous_dir));
102 while (chdir "$rep_root_candidate");
107 1; # needed by use or require
113 RepositoryHelper - Perl module for working with repositories
117 # example that will analyze sources and return the source root directory
119 use RepositoryHelper;
121 # Create a new instance:
122 $a = RepositoryHelper->new();
124 # Get repositories for the actual workspace:
125 $a->get_repository_root();
130 RepositoryHelper is a perlPerl module for working with repositories
135 RepositoryHelper::new()
137 Creates a new instance of RepositoryHelper. Can be initialized by: some path which likely to belong to a repository, default - empty, the current dir will be taken.
139 RepositoryHelper::get_repository_root()
141 Returns the repository root, retrieved by educated guess...
143 RepositoryHelper::get_initial_directory()
145 Returns full path to the initialistion directory.
149 RepositoryHelper::new()
150 RepositoryHelper::get_repository_root()
151 RepositoryHelper::get_initial_directory()
155 Vladimir Glazunov, vg@openoffice.org