aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_tag.cc
blob: 62525d6579e7a7e279c8fbb89bafd1ce23ad0cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007, 2008, 2010, 2011 Ciaran McCreesh
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <paludis/dep_tag.hh>
#include <paludis/dep_spec.hh>
#include <paludis/dep_label.hh>
#include <paludis/spec_tree.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/singleton-impl.hh>
#include <paludis/util/set-impl.hh>
#include <paludis/util/mutex.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/accept_visitor.hh>
#include <algorithm>
#include <sstream>

using namespace paludis;

namespace
{
    std::shared_ptr<DepTagCategory>
    make_glsa_dep_tag()
    {
        return std::make_shared<DepTagCategory>(
                true,
                "glsa",
                "Security advisories",
                "Your system is potentially affected by these security issues:",
                "Please read the advisories carefully and take appropriate action.");
    }

    std::shared_ptr<DepTagCategory>
    make_general_set_dep_tag()
    {
        return std::make_shared<DepTagCategory>(
                true,
                "general",
                "General sets",
                "",
                "");
    }

    std::shared_ptr<DepTagCategory>
    make_dependency_set_dep_tag()
    {
        return std::make_shared<DepTagCategory>(
                false,
                "dependency",
                "Dependencies",
                "",
                "");
    }

    std::shared_ptr<DepTagCategory>
    make_target_dep_tag()
    {
        return std::make_shared<DepTagCategory>(
                false,
                "target",
                "Targets",
                "",
                "");
    }
}

DepTagCategory::DepTagCategory(
        bool vis,
        const std::string & our_id,
        const std::string & t, const std::string & pre,
        const std::string & post) :
    _visible(vis),
    _id(our_id),
    _title(t),
    _pre_text(pre),
    _post_text(post)
{
}

bool
DepTagCategory::visible() const
{
    return _visible;
}

std::string
DepTagCategory::id() const
{
    return _id;
}

std::string
DepTagCategory::title() const
{
    return _title;
}

std::string
DepTagCategory::pre_text() const
{
    return _pre_text;
}

std::string
DepTagCategory::post_text() const
{
    return _post_text;
}

DepTag::DepTag()
{
}

DepTag::~DepTag()
{
}

namespace
{
    struct DepTagComparator
    {
        std::string value;

        void visit(const GLSADepTag & t)
        {
            value = t.short_text();
        }

        void visit(const GeneralSetDepTag & t)
        {
            value = t.short_text();
        }

        void visit(const DependencyDepTag & t)
        {
            value = stringify(*t.package_id()) + "," + stringify(*t.dependency()) + ",";
        }

        void visit(const TargetDepTag & t)
        {
            value = t.short_text();
        }
    };
}

bool
DepTag::operator== (const DepTag & other) const
{
    DepTagComparator c1, c2;
    accept(c1);
    other.accept(c2);
    return c1.value == c2.value;
}

bool
DepTag::operator< (const DepTag & other) const
{
    DepTagComparator c1, c2;
    accept(c1);
    other.accept(c2);
    return c1.value < c2.value;
}

GLSADepTag::GLSADepTag(const std::string & id, const std::string & our_glsa_title, const FSPath & our_glsa_file) :
    _id(id),
    _glsa_title(our_glsa_title),
    _glsa_file(our_glsa_file)
{
}

GLSADepTag::~GLSADepTag()
{
}

std::string
GLSADepTag::short_text() const
{
    return "GLSA-" + _id;
}

std::string
GLSADepTag::category() const
{
    return "glsa";
}

const FSPath
GLSADepTag::glsa_file() const
{
    return _glsa_file;
}

std::string
GLSADepTag::glsa_title() const
{
    return _glsa_title;
}

namespace paludis
{
    template <>
    struct Imp<GeneralSetDepTag>
    {
        const SetName id;
        const std::string source;

        Imp(const SetName & n, const std::string s) :
            id(n),
            source(s)
        {
        }
    };
}

GeneralSetDepTag::GeneralSetDepTag(const SetName & id, const std::string & r) :
    _imp(id, r)
{
}

GeneralSetDepTag::~GeneralSetDepTag()
{
}

std::string
GeneralSetDepTag::short_text() const
{
    return stringify(_imp->id);
}

std::string
GeneralSetDepTag::category() const
{
    return "general";
}

std::string
GeneralSetDepTag::source() const
{
    return _imp->source;
}

namespace paludis
{
    template <>
    struct Imp<DependencyDepTag>
    {
        mutable Mutex mutex;
        mutable std::string str;

        std::shared_ptr<const PackageID> id;
        const std::shared_ptr<PackageDepSpec> spec;

        Imp(const std::shared_ptr<const PackageID> & i, const PackageDepSpec & d) :
            id(i),
            spec(std::static_pointer_cast<PackageDepSpec>(d.clone()))
        {
            spec->set_tag(std::shared_ptr<const DepTag>());
        }
    };
}

DependencyDepTag::DependencyDepTag(const std::shared_ptr<const PackageID> & i, const PackageDepSpec & d) :
    _imp(i, d)
{
}

DependencyDepTag::~DependencyDepTag()
{
}

std::string
DependencyDepTag::short_text() const
{
    return stringify(*_imp->id);
}

std::string
DependencyDepTag::category() const
{
    return "dependency";
}

const std::shared_ptr<const PackageID>
DependencyDepTag::package_id() const
{
    return _imp->id;
}

const std::shared_ptr<const PackageDepSpec>
DependencyDepTag::dependency() const
{
    return _imp->spec;
}

TargetDepTag::TargetDepTag()
{
}

TargetDepTag::~TargetDepTag()
{
}

std::string
TargetDepTag::short_text() const
{
    return "target";
}

std::string
TargetDepTag::category() const
{
    return "target";
}

DepTagCategoryFactory::DepTagCategoryFactory()
{
}

const std::shared_ptr<DepTagCategory>
DepTagCategoryFactory::create(const std::string & s) const
{
    if (s == "glsa")
        return make_glsa_dep_tag();
    if (s == "general")
        return make_general_set_dep_tag();
    if (s == "dependency")
        return make_dependency_set_dep_tag();
    if (s == "target")
        return make_target_dep_tag();
    throw ConfigurationError("No dep tag category named '" + s + "'");
}

bool
DepTagEntryComparator::operator() (const DepTagEntry & l, const DepTagEntry & r) const
{
    return *l.tag() < *r.tag();
}

template class Singleton<DepTagCategoryFactory>;

template class Set<DepTagEntry, DepTagEntryComparator>;
template class WrappedForwardIterator<Set<DepTagEntry, DepTagEntryComparator>::ConstIteratorTag, const DepTagEntry>;
template class WrappedOutputIterator<Set<DepTagEntry, DepTagEntryComparator>::InserterTag, DepTagEntry>;

template class Pimp<GeneralSetDepTag>;
template class Pimp<DependencyDepTag>;