1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.jar.identification.exposers;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 import org.apache.maven.shared.jar.JarAnalyzer;
28 import org.apache.maven.shared.jar.identification.JarIdentification;
29 import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
30 import org.codehaus.plexus.util.FileUtils;
31
32
33
34
35
36 @Singleton
37 @Named("filename")
38 public class FilenameExposer implements JarIdentificationExposer {
39 private static final Pattern VERSION_PATTERN = Pattern.compile("-\\d");
40
41 @Override
42 public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
43 String filename = FileUtils.removeExtension(jarAnalyzer.getFile().getName());
44 Matcher mat = VERSION_PATTERN.matcher(filename);
45 if (mat.find()) {
46 String prefix = filename.substring(0, mat.start());
47 identification.addArtifactId(prefix);
48 identification.addName(prefix);
49 identification.addVersion(filename.substring(mat.end() - 1));
50 } else {
51 identification.addArtifactId(filename);
52 identification.addName(filename);
53 }
54 }
55 }