Debian Codegraph @

maven-packager-utils/src/main/java/org/debian/maven/packager/util/GetPackageResult.java

raw
1 /*
2 * Copyright 2012 Ludovic Claude.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.debian.maven.packager.util;
18
19 import java.util.Set;
20 import java.util.TreeSet;
21
22 /**
23 * Parses the output of the <tt>dpkg --search</tt> and <tt>apt-file find</tt>
24 * commands and extracts the name of the packages matching the search criteria.
25 * <p>
26 * The format expected is:
27 * <pre>
28 * &lt;pkg>: &lt;file>
29 * </pre>
30 */
31 public class GetPackageResult implements OutputHandler {
32
33 private final Set<String> result = new TreeSet<String>();
34
35 public void newLine(String line) {
36 // Clean up lines of the form <pkg>: <file>
37 int colon = line.indexOf(':');
38 if (colon > 0 && line.indexOf(' ') > colon) {
39 String candidatePkg = line.substring(0, colon);
40 // Ignore lines such as 'dpkg : xxx'
41 if (candidatePkg.equals(candidatePkg.trim()) && !candidatePkg.startsWith("dpkg")) {
42 System.out.println("Found " + candidatePkg);
43 result.add(candidatePkg);
44 }
45 }
46 }
47
48 public void failure() {
49 }
50
51 public Set<String> getResult() {
52 return result;
53 }
54
55 }