MCPcopy Create free account
hub / github.com/diffplug/goomph / MavenRepoBuilder

Class MavenRepoBuilder

src/main/java/com/diffplug/gradle/p2/MavenRepoBuilder.java:38–168  ·  view source on GitHub ↗

Builds a maven repo out of a p2 repository.

Source from the content-addressed store, hash-verified

36
37/** Builds a maven repo out of a p2 repository. */
38class MavenRepoBuilder implements AutoCloseable {
39 final File root;
40 final Multimap<Coordinate, Artifact> artifactMap = HashMultimap.create();
41
42 MavenRepoBuilder(File root) throws Exception {
43 this.root = Objects.requireNonNull(root);
44 }
45
46 /**
47 * Installs the given OSGi jar into the given group.
48 *
49 * Parses the name from Bundle-SymbolicName, the version
50 * from Bundle-Version, and the source for Eclipse-SourceBundle.
51 */
52 public void install(String group, File osgiJar) throws Exception {
53 ParsedJar parsed = ParsedJar.parse(osgiJar);
54 artifactMap.put(new Coordinate(group, parsed.getSymbolicName()),
55 new Artifact(Version.parseVersion(parsed.getVersion()), parsed.isSource(), osgiJar));
56 }
57
58 @Override
59 public void close() throws Exception {
60 for (Coordinate coord : artifactMap.keySet()) {
61 File groupFolder = new File(root, coord.group);
62 File artifactFolder = new File(groupFolder, coord.artifactId);
63 FileMisc.mkdirs(artifactFolder);
64 Collection<Artifact> values = artifactMap.get(coord);
65 install(artifactFolder, coord, values);
66 }
67 }
68
69 private void install(File artifactFolder, Coordinate coord, Collection<Artifact> artifacts) throws IOException {
70 List<Version> allVersions = artifacts.stream()
71 .map(artifact -> artifact.version)
72 .distinct().sorted().collect(Collectors.toList());
73 // create the metadata
74 Node metadata = new Node(null, "metadata");
75 new Node(metadata, "groupId").setValue(coord.group);
76 new Node(metadata, "artifactId").setValue(coord.artifactId);
77 // the last one
78 new Node(metadata, "version").setValue(allVersions.get(allVersions.size() - 1));
79 Node versioning = new Node(metadata, "versioning");
80 Node versions = new Node(versioning, "versions");
81 for (Version version : allVersions) {
82 new Node(versions, "version").setValue(version.toString());
83 }
84 new Node(versioning, "lastUpdated").setValue(System.currentTimeMillis());
85 // create the metadata file
86 String mavenMetadataContent = FileMisc.toUnixNewline(XmlUtil.serialize(metadata));
87 File mavenMetadata = new File(artifactFolder, "maven-metadata.xml");
88 Files.write(mavenMetadata.toPath(), mavenMetadataContent.getBytes(StandardCharsets.UTF_8));
89 // write out the artifacts
90 for (Artifact artifact : artifacts) {
91 StringBuilder builder = new StringBuilder();
92 builder.append(coord.artifactId);
93 builder.append('-');
94 builder.append(artifact.version.toString());
95 if (artifact.isSources) {

Callers

nothing calls this directly

Calls 1

createMethod · 0.45

Tested by

no test coverage detected