1 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
2 #*************************************************************************
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 # Copyright 2000, 2010 Oracle and/or its affiliates.
8 # OpenOffice.org - a multi-platform office productivity suite
10 # This file is part of OpenOffice.org.
12 # OpenOffice.org is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License version 3
14 # only, as published by the Free Software Foundation.
16 # OpenOffice.org is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Lesser General Public License version 3 for more details
20 # (a copy is included in the LICENSE file that accompanied this code).
22 # You should have received a copy of the GNU Lesser General Public License
23 # version 3 along with OpenOffice.org. If not, see
24 # <http://www.openoffice.org/license.html>
25 # for a copy of the LGPLv3 License.
27 #*************************************************************************
29 #*************************************************************************
31 # RepositoryHelper - Perl for working with repositories
35 #*************************************************************************
37 package RepositoryHelper
;
45 #use File::Temp qw(tmpnam);
55 my $class = ref($proto) || $proto;
56 my $initial_directory = shift;
57 if ($initial_directory) {
58 $initial_directory = Cwd
::realpath
($initial_directory);
60 if ( defined $ENV{PWD
} ) {
61 $initial_directory = $ENV{PWD
};
62 } elsif (defined $ENV{_cwd
}) {
63 $initial_directory = $ENV{_cwd
};
65 $initial_directory = cwd
();
69 $self->{INITIAL_DIRECTORY
} = $initial_directory;
70 $self->{REPOSITORY_ROOT
} = undef;
71 if (! search_via_build_lst
($self))
73 croak
('Cannot determine source directory/repository for ' . $self->{INITIAL_DIRECTORY
});
80 sub get_repository_root
83 return $self->{REPOSITORY_ROOT
};
86 sub get_initial_directory
89 return $self->{INITIAL_DIRECTORY
};
92 sub search_via_build_lst
{
94 my $previous_dir = '';
95 my $rep_root_candidate = $self->{INITIAL_DIRECTORY
};
98 if ($rep_root_candidate eq '/') {
99 $test_file = '/prj/build.lst';
101 $test_file = $rep_root_candidate . '/prj/build.lst';
104 $self->{REPOSITORY_ROOT
} = File
::Basename
::dirname
($rep_root_candidate);
107 $previous_dir = $rep_root_candidate;
108 $rep_root_candidate = File
::Basename
::dirname
($rep_root_candidate);
109 return 0 if ((!$rep_root_candidate) || ($rep_root_candidate eq $previous_dir));
111 while (chdir "$rep_root_candidate");
116 1; # needed by use or require
122 RepositoryHelper - Perl module for working with repositories
126 # example that will analyze sources and return the source root directory
128 use RepositoryHelper;
130 # Create a new instance:
131 $a = RepositoryHelper->new();
133 # Get repositories for the actual workspace:
134 $a->get_repository_root();
139 RepositoryHelper is a perlPerl module for working with repositories
144 RepositoryHelper::new()
146 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.
148 RepositoryHelper::get_repository_root()
150 Returns the repository root, retrieved by educated guess...
152 RepositoryHelper::get_initial_directory()
154 Returns full path to the initialistion directory.
158 RepositoryHelper::new()
159 RepositoryHelper::get_repository_root()
160 RepositoryHelper::get_initial_directory()
164 Vladimir Glazunov, vg@openoffice.org