Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / modules / RepositoryHelper.pm
blob31bbf7462bfbddc99d839e818e8a5f05c2773f61
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
24 # usage: see below
26 #*************************************************************************
28 package RepositoryHelper;
30 use strict;
33 use Carp;
34 use Cwd qw (cwd);
35 use File::Basename;
36 #use File::Temp qw(tmpnam);
38 my $debug = 0;
40 ##### profiling #####
42 ##### ctor #####
44 sub new {
45 my $proto = shift;
46 my $class = ref($proto) || $proto;
47 my $initial_directory = shift;
48 if ($initial_directory) {
49 $initial_directory = Cwd::realpath($initial_directory);
50 } else {
51 if ( defined $ENV{PWD} ) {
52 $initial_directory = $ENV{PWD};
53 } elsif (defined $ENV{_cwd}) {
54 $initial_directory = $ENV{_cwd};
55 } else {
56 $initial_directory = cwd();
59 my $self = {};
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});
66 bless($self, $class);
67 return $self;
70 ##### methods #####
71 sub get_repository_root
73 my $self = shift;
74 return $self->{REPOSITORY_ROOT};
77 sub get_initial_directory
79 my $self = shift;
80 return $self->{INITIAL_DIRECTORY};
83 sub search_via_build_lst {
84 my $self = shift;
85 my $previous_dir = '';
86 my $rep_root_candidate = $self->{INITIAL_DIRECTORY};
87 do {
88 my $test_file;
89 if ($rep_root_candidate eq '/') {
90 $test_file = '/prj/build.lst';
91 } else {
92 $test_file = $rep_root_candidate . '/prj/build.lst';
94 if (-e $test_file) {
95 $self->{REPOSITORY_ROOT} = File::Basename::dirname($rep_root_candidate);
96 return 1;
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");
105 ##### finish #####
107 1; # needed by use or require
109 __END__
111 =head1 NAME
113 RepositoryHelper - Perl module for working with repositories
115 =head1 SYNOPSIS
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();
128 =head1 DESCRIPTION
130 RepositoryHelper is a perlPerl module for working with repositories
131 in the database.
133 Methods:
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.
147 =head2 EXPORT
149 RepositoryHelper::new()
150 RepositoryHelper::get_repository_root()
151 RepositoryHelper::get_initial_directory()
153 =head1 AUTHOR
155 Vladimir Glazunov, vg@openoffice.org
157 =head1 SEE ALSO
159 perl(1).
161 =cut