mirror of
https://github.com/ethauvin/rife2.git
synced 2025-04-30 10:38:12 -07:00
WIP publish operation
This commit is contained in:
parent
d780cf3187
commit
41a048387c
4 changed files with 98 additions and 14 deletions
|
@ -41,6 +41,9 @@ java {
|
|||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri("https://maven.reposilite.com/releases")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -65,6 +68,7 @@ dependencies {
|
|||
testImplementation("org.apache.derby:derby:10.16.1.1")
|
||||
testImplementation("org.apache.derby:derbytools:10.16.1.1")
|
||||
testImplementation("com.oracle.database.jdbc:ojdbc11:21.9.0.0")
|
||||
testImplementation("com.reposilite:reposilite:3.4.0")
|
||||
}
|
||||
|
||||
configurations[JavaPlugin.API_CONFIGURATION_NAME].let { apiConfiguration ->
|
||||
|
|
|
@ -4,17 +4,33 @@
|
|||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import rife.engine.UrlBuilder;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* Contains the information required to locate a Maven-compatible repository.
|
||||
*
|
||||
* @param url the base URL of the repository
|
||||
* @param url the base URL of the repository
|
||||
* @param username the username to access the repository
|
||||
* @param password the password to access repository
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.5
|
||||
*/
|
||||
public record Repository(String url) {
|
||||
public record Repository(String url, String username, String password) {
|
||||
public static final Repository MAVEN_CENTRAL = new Repository("https://repo1.maven.org/maven2/");
|
||||
public static final Repository SONATYPE_SNAPSHOTS = new Repository("https://s01.oss.sonatype.org/content/repositories/snapshots/");
|
||||
|
||||
/**
|
||||
* Creates a new repository with only a URL.
|
||||
*
|
||||
* @param url the dependency to create the URL for
|
||||
* @since 1.5
|
||||
*/
|
||||
public Repository(String url) {
|
||||
this(url, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the artifact URL for a dependency if it would be located in this repository.
|
||||
*
|
||||
|
@ -23,11 +39,23 @@ public record Repository(String url) {
|
|||
* @since 1.5
|
||||
*/
|
||||
public String getArtifactUrl(Dependency dependency) {
|
||||
var group_path = dependency.groupId().replace(".", "/");
|
||||
return getArtifactUrl(dependency.groupId(), dependency.artifactId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the artifact URL for a dependency if it would be located in this repository.
|
||||
*
|
||||
* @param groupId the groupId dependency to create the URL for
|
||||
* @param artifactId the artifactId dependency to create the URL for
|
||||
* @return the constructed artifact URL
|
||||
* @since 1.5.7
|
||||
*/
|
||||
public String getArtifactUrl(String groupId, String artifactId) {
|
||||
var group_path = groupId.replace(".", "/");
|
||||
var result = new StringBuilder(url);
|
||||
if (!url.endsWith("/")) {
|
||||
result.append("/");
|
||||
}
|
||||
return result.append(group_path).append("/").append(dependency.artifactId()).append("/").toString();
|
||||
return result.append(group_path).append("/").append(artifactId).append("/").toString();
|
||||
}
|
||||
}
|
|
@ -6,9 +6,15 @@ package rife.bld.operations;
|
|||
|
||||
import rife.bld.Project;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.bld.publish.MetadataBuilder;
|
||||
import rife.bld.publish.PublishInfo;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -24,12 +30,34 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
private final PublishInfo info_ = new PublishInfo();
|
||||
private final List<File> artifacts_ = new ArrayList<>();
|
||||
|
||||
private static String basicAuthentication(String username, String password) {
|
||||
var valueToEncode = username + ":" + password;
|
||||
return "Basic " + StringUtils.encodeBase64(valueToEncode.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the publish operation.
|
||||
*
|
||||
* @since 1.5.7
|
||||
*/
|
||||
public void execute() {
|
||||
try {
|
||||
var client = HttpClient.newHttpClient();
|
||||
var builder = HttpRequest.newBuilder()
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(new MetadataBuilder().info(info()).build()))
|
||||
.uri(URI.create(repository().getArtifactUrl(info().groupId(), info().artifactId()) + "maven-metadata.xml"));
|
||||
if (repository().username() != null && repository().password() != null) {
|
||||
builder.header("Authorization", basicAuthentication(repository().username(), repository().password()));
|
||||
}
|
||||
var request = builder.build();
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (response.statusCode() != 200) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
package rife.bld.operations;
|
||||
|
||||
import com.reposilite.ReposiliteLauncherKt;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.WebProject;
|
||||
import rife.bld.dependencies.*;
|
||||
|
@ -47,18 +48,41 @@ public class TestPublishOperation {
|
|||
void testExecution()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var operation = new PublishOperation();
|
||||
operation.execute();
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
var repository = ReposiliteLauncherKt.createWithParameters(
|
||||
"-wd", tmp2.getAbsolutePath(),
|
||||
"-p", "8081",
|
||||
"--token", "manager:passwd");
|
||||
repository.launch();
|
||||
|
||||
static class TestProject extends WebProject {
|
||||
public TestProject(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
// wait for full startup
|
||||
Thread.sleep(4000);
|
||||
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation = new JarOperation()
|
||||
.fromProject(create_operation.project());
|
||||
jar_operation.execute();
|
||||
|
||||
var operation = new PublishOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.repository(new Repository("http://localhost:8081/releases", "manager", "passwd"));
|
||||
operation.execute();
|
||||
|
||||
repository.shutdown();
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp2);
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue