1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Defines member function for a generic application implementation base
16 : // class (empty implementation).
17 :
18 : #include "syzygy/application/application.h"
19 :
20 : #include "base/files/file_enumerator.h"
21 : #include "base/files/file_path.h"
22 : #include "base/files/file_util.h"
23 :
24 : namespace application {
25 :
26 : AppImplBase::AppImplBase(const base::StringPiece& name)
27 E : : in_(stdin), out_(stdout), err_(stderr) {
28 E : name_.assign(name.begin(), name.end());
29 E : }
30 :
31 E : bool AppImplBase::ParseCommandLine(const base::CommandLine* command_line) {
32 E : return true;
33 E : }
34 :
35 E : bool AppImplBase::SetUp() {
36 E : return true;
37 E : }
38 :
39 E : int AppImplBase::Run() {
40 E : return 0;
41 E : }
42 :
43 E : void AppImplBase::TearDown() {
44 E : }
45 :
46 E : base::FilePath AppImplBase::AbsolutePath(const base::FilePath& path) {
47 E : if (path.empty())
48 E : return base::FilePath();
49 :
50 E : base::FilePath temp(base::MakeAbsoluteFilePath(path));
51 E : if (temp.empty())
52 i : return path;
53 i : else
54 E : return temp;
55 E : }
56 :
57 : bool AppImplBase::AppendMatchingPaths(const base::FilePath& pattern,
58 E : std::vector<base::FilePath>* matches) {
59 E : DCHECK(matches != NULL);
60 E : bool found_a_match = false;
61 :
62 : // Whether the pattern is an existing file or not, we expand it as a glob.
63 : // If it's a file, it'll match itself and nothing else.
64 : base::FileEnumerator files(AbsolutePath(pattern.DirName()),
65 : false,
66 : base::FileEnumerator::FILES,
67 E : pattern.BaseName().value());
68 E : while (true) {
69 E : base::FilePath file = files.Next();
70 E : if (file.empty())
71 E : break;
72 :
73 E : DCHECK(file.IsAbsolute());
74 :
75 E : found_a_match = true;
76 E : matches->push_back(file);
77 E : }
78 :
79 E : return found_a_match;
80 E : }
81 :
82 : } // namespace application
|