forked from bndtools/bnd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MavenCoordinatePlugin.java
83 lines (70 loc) · 2.35 KB
/
MavenCoordinatePlugin.java
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
package biz.aQute.bnd.reporter.plugins.entries.bundle;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import aQute.bnd.annotation.plugin.BndPlugin;
import aQute.bnd.osgi.Jar;
import aQute.bnd.service.Plugin;
import aQute.bnd.service.reporter.ReportEntryPlugin;
import aQute.service.reporter.Reporter;
import biz.aQute.bnd.reporter.generator.EntryNamesReference;
import biz.aQute.bnd.reporter.maven.dto.MavenCoordinatesDTO;
/**
* This plugin find and add the content of the pom.properties file to the
* report.
*/
@BndPlugin(name = "entry." + EntryNamesReference.MAVEN_COORDINATE)
public class MavenCoordinatePlugin implements ReportEntryPlugin<Jar>, Plugin {
private Reporter _reporter;
private final Map<String, String> _properties = new HashMap<>();
public MavenCoordinatePlugin() {
_properties.put(ReportEntryPlugin.ENTRY_NAME_PROPERTY, EntryNamesReference.MAVEN_COORDINATE);
_properties.put(ReportEntryPlugin.SOURCE_CLASS_PROPERTY, Jar.class.getCanonicalName());
}
@Override
public MavenCoordinatesDTO extract(final Jar jar, final Locale locale) {
Objects.requireNonNull(jar, "jar");
Objects.requireNonNull(locale, "locale");
MavenCoordinatesDTO dto = new MavenCoordinatesDTO();
jar.getResources()
.entrySet()
.stream()
.filter(e -> e.getKey()
.endsWith("pom.properties"))
.findAny()
.ifPresent(e -> {
final Properties p = new Properties();
try {
p.load(e.getValue()
.openInputStream());
dto.groupId = p.getProperty("groupId");
dto.artifactId = p.getProperty("artifactId");
dto.version = p.getProperty("version");
// dto.type = p.getProperty("type");//may interrest on
// .eas
dto.classifier = p.getProperty("classifier");
} catch (final Exception exception) {
_reporter.exception(exception, "Failed to read pom.properties file at %s", e.getKey());
}
});
if (dto.groupId == null && dto.artifactId == null) {
return null;
}
return dto;
}
@Override
public Map<String, String> getProperties() {
return Collections.unmodifiableMap(_properties);
}
@Override
public void setProperties(final Map<String, String> map) throws Exception {
_properties.putAll(map);
}
@Override
public void setReporter(final Reporter processor) {
_reporter = processor;
}
}