Debian Codegraph @

maven-packager-utils/src/main/java/org/debian/maven/packager/util/GetPackageContainingPatternResult.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.HashMap;
20 import java.util.HashSet;
21 import java.util.Map;
22 import java.util.Set;
23
24 public class GetPackageContainingPatternResult implements OutputHandler {
25 private final String extension;
26 private final Map<String, String> result = new HashMap<String, String>();
27
28 public GetPackageContainingPatternResult(String extension) {
29 this.extension = extension;
30 }
31
32 public void newLine(String line) {
33 // Clean up lines of the form <pkg>: <file>
34 int colon = line.indexOf(':');
35 if (colon > 0 && line.indexOf(' ') > colon) {
36 String candidatePkg = line.substring(0, colon);
37 // Ignore lines such as 'dpkg : xxx'
38 if (candidatePkg.equals(candidatePkg.trim()) && !candidatePkg.startsWith("dpkg")) {
39 String match = matchFile(line.substring(colon + 1).trim(), candidatePkg);
40 if (match != null) {
41 result.put(match, candidatePkg);
42 }
43 }
44 }
45 }
46
47 protected String matchFile(String potentialMatch, String candidatePkg) {
48 if (potentialMatch.endsWith(extension)) {
49 System.out.println("Found " + potentialMatch + " in " + candidatePkg);
50 return potentialMatch;
51 } else {
52 return null;
53 }
54 }
55
56 public void failure() {
57 }
58
59 public Map<String, String> getPackagesAndFiles() {
60 return result;
61 }
62
63 public Set<String> getPackages() {
64 return new HashSet<String>(result.values());
65 }
66 }