|
| 1 | +package eu.maveniverse.maven.njord.plugin3; |
| 2 | + |
| 3 | +import eu.maveniverse.maven.njord.shared.impl.repository.ArtifactStoreDeployer; |
| 4 | +import eu.maveniverse.maven.njord.shared.store.ArtifactStore; |
| 5 | +import eu.maveniverse.maven.njord.shared.store.ArtifactStoreManager; |
| 6 | +import java.io.IOException; |
| 7 | +import java.util.Optional; |
| 8 | +import org.apache.maven.plugins.annotations.Mojo; |
| 9 | +import org.apache.maven.plugins.annotations.Parameter; |
| 10 | +import org.eclipse.aether.repository.RemoteRepository; |
| 11 | + |
| 12 | +/** |
| 13 | + * Redeploys {@code from} store onto {@code to} store, eventually dropping {@code from} store. |
| 14 | + */ |
| 15 | +@Mojo(name = "redeploy", threadSafe = true, requiresProject = false) |
| 16 | +public class RedeployMojo extends NjordMojoSupport { |
| 17 | + @Parameter(required = true, property = "from") |
| 18 | + private String from; |
| 19 | + |
| 20 | + @Parameter(required = true, property = "to") |
| 21 | + private String to; |
| 22 | + |
| 23 | + @Parameter(required = true, property = "drop", defaultValue = "true") |
| 24 | + private boolean drop; |
| 25 | + |
| 26 | + @Override |
| 27 | + protected void doExecute(ArtifactStoreManager artifactStoreManager) throws IOException { |
| 28 | + Optional<ArtifactStore> fromOptional = artifactStoreManager.selectArtifactStore(from); |
| 29 | + Optional<ArtifactStore> toOptional = artifactStoreManager.selectArtifactStore(to); |
| 30 | + if (fromOptional.isEmpty()) { |
| 31 | + logger.warn("ArtifactStore with given name not found: {}", from); |
| 32 | + return; |
| 33 | + } |
| 34 | + if (toOptional.isEmpty()) { |
| 35 | + logger.warn("ArtifactStore with given name not found: {}", to); |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + logger.info("Redeploying {} -> {}", fromOptional.orElseThrow(), toOptional.orElseThrow()); |
| 40 | + toOptional.orElseThrow().close(); |
| 41 | + try (ArtifactStore from = fromOptional.orElseThrow()) { |
| 42 | + new ArtifactStoreDeployer( |
| 43 | + repositorySystem, |
| 44 | + mavenSession.getRepositorySession(), |
| 45 | + new RemoteRepository.Builder(to, "default", "njord:store:" + to).build()) |
| 46 | + .deploy(from); |
| 47 | + if (drop) { |
| 48 | + logger.info("Dropping {}", from); |
| 49 | + artifactStoreManager.dropArtifactStore(from); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments