Skip to content

Commit

Permalink
GH-341 Bump CDN to 1.6.0 (Resolve #341)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Feb 6, 2021
1 parent 305dbc5 commit d876f1c
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 35 deletions.
19 changes: 18 additions & 1 deletion reposilite-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>net.dzikoysk</groupId>
<artifactId>cdn</artifactId>
<version>1.5.3</version>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
Expand Down Expand Up @@ -134,6 +134,23 @@
<version>2.11.0</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-tinylog</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<version>2.2.1</version>
</dependency>

<!-- Tests -->
<dependency>
<groupId>com.google.http-client</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Configuration load(String customConfigurationFile, String workingD

verifyBasePath(configuration);
verifyProxied(configuration);
FileUtils.overrideFile(configurationFile, cdn.compose(configuration));
FileUtils.overrideFile(configurationFile, cdn.render(configuration));
loadProperties(configuration);

return configuration;
Expand All @@ -73,7 +73,7 @@ private static Configuration createConfiguration(File configurationFile) throws
Reposilite.getLogger().info("Legacy configuration file has been found");

Configuration configuration = CDN.configure()
.enableIndentationFormatting()
.enableYamlLikeFormatting()
.build()
.parse(Configuration.class, FileUtils.getContentOfFile(legacyConfiguration));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.panda_lang.reposilite.console;

import org.panda_lang.reposilite.ReposiliteConstants;
import org.panda_lang.utilities.commons.text.ContentJoiner;
import org.panda_lang.utilities.commons.text.Joiner;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.ArgSpec;
Expand Down Expand Up @@ -67,8 +67,8 @@ public boolean execute(List<String> response) {
CommandSpec specification = command.getCommandSpec();

response.add(" " + command.getCommandName()
+ " " + ContentJoiner.on(" ").join(specification.args(), ArgSpec::paramLabel)
+ " - " + ContentJoiner.on(". ").join(specification.usageMessage().description()));
+ " " + Joiner.on(" ").join(specification.args(), ArgSpec::paramLabel)
+ " - " + Joiner.on(". ").join(specification.usageMessage().description()));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.panda_lang.reposilite.utils.FilesUtils;
import org.panda_lang.utilities.commons.StringUtils;
import org.panda_lang.utilities.commons.function.Lazy;
import org.panda_lang.utilities.commons.text.MessageFormatter;
import org.panda_lang.utilities.commons.text.Formatter;

import java.util.function.Supplier;

Expand All @@ -43,7 +43,7 @@ public String getApp() {
}

public static FrontendService load(Configuration configuration) {
MessageFormatter formatter = new MessageFormatter()
Formatter formatter = new Formatter()
.register("{{REPOSILITE.BASE_PATH}}", configuration.basePath)
.register("{{REPOSILITE.VUE_BASE_PATH}}", configuration.basePath.equals("/") ? "" : configuration.basePath)
.register("{{REPOSILITE.TITLE}}", configuration.title.replace("'", "\\'"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package org.panda_lang.reposilite.metadata;

import org.panda_lang.panda.Panda;
import org.panda_lang.reposilite.utils.FilesUtils;
import org.panda_lang.utilities.commons.StringUtils;
import org.panda_lang.utilities.commons.collection.Pair;
import org.panda_lang.utilities.commons.function.PandaStream;
import org.panda_lang.utilities.commons.text.ContentJoiner;
import org.panda_lang.utilities.commons.text.Joiner;

import java.io.File;
import java.time.Instant;
Expand Down Expand Up @@ -122,7 +121,7 @@ protected static String toUpdateTime(File file) {
}

public static String toGroup(String[] elements) {
return ContentJoiner.on(".")
return Joiner.on(".")
.join(Arrays.copyOfRange(elements, 0, elements.length))
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.panda_lang.reposilite.repository;

import org.panda_lang.reposilite.metadata.MetadataUtils;
import org.panda_lang.utilities.commons.text.ContentJoiner;
import org.panda_lang.utilities.commons.text.Joiner;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -58,7 +58,7 @@ public boolean isHidden() {
}

public File getFile(String... path) {
return new File(directory, ContentJoiner.on(File.separator).join(path).toString());
return new File(directory, Joiner.on(File.separator).join(path).toString());
}

public String getUri() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ abstract class ReposiliteIntegrationTestSpecification extends ReposiliteTestSpec
properties.forEach({ property, value -> System.setProperty(property, value) })

try {
return ReposiliteLauncher.create(ArrayUtils.mergeArrays(args, ArrayUtils.of(
return ReposiliteLauncher.create(ArrayUtils.merge(args, ArrayUtils.of(
"--working-directory=" + workingDirectory.getAbsolutePath(),
"--test-env"
))).orElseThrow({ new RuntimeException("Invalid test parameters") })
}
finally {
System.clearProperty("reposilite.port");
System.clearProperty("reposilite.port")
properties.forEach({ key, value -> System.clearProperty(key) })
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import net.dzikoysk.cdn.CDN
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.panda_lang.utilities.commons.FileUtils
import org.panda_lang.utilities.commons.text.ContentJoiner
import org.panda_lang.utilities.commons.text.Joiner

import static org.junit.jupiter.api.Assertions.*

Expand Down Expand Up @@ -63,7 +63,7 @@ class ConfigurationLoaderTest {
@Test
void 'should load custom config' () {
def customConfig = new File(workingDirectory, "random.cdn")
FileUtils.overrideFile(customConfig, CDN.defaultInstance().compose(new Configuration()))
FileUtils.overrideFile(customConfig, CDN.defaultInstance().render(new Configuration()))
FileUtils.overrideFile(customConfig, FileUtils.getContentOfFile(customConfig).replace("port: 80", "port: 7"))

def configuration = ConfigurationLoader.tryLoad(customConfig.getAbsolutePath(), workingDirectory.getAbsolutePath())
Expand All @@ -73,7 +73,7 @@ class ConfigurationLoaderTest {
@Test
void 'should not load other file types' () {
def customConfig = new File(workingDirectory, "random.properties")
FileUtils.overrideFile(customConfig, CDN.defaultInstance().compose(new Configuration()))
FileUtils.overrideFile(customConfig, CDN.defaultInstance().render(new Configuration()))
assertThrows RuntimeException.class, { ConfigurationLoader.load(customConfig.getAbsolutePath(), workingDirectory.getAbsolutePath()) }
}

Expand All @@ -92,7 +92,7 @@ class ConfigurationLoaderTest {
@Test
void 'should verify proxied' () {
def config = new File(workingDirectory, "config.cdn")
FileUtils.overrideFile(config, ContentJoiner.on("\n").join(
FileUtils.overrideFile(config, Joiner.on("\n").join(
"proxied {",
" https://without.slash",
" https://with.slash/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test
import org.panda_lang.reposilite.ReposiliteConstants
import org.panda_lang.reposilite.ReposiliteWriter
import org.panda_lang.reposilite.error.FailureService
import org.panda_lang.utilities.commons.text.ContentJoiner
import org.panda_lang.utilities.commons.text.Joiner

import static org.junit.jupiter.api.Assertions.assertTrue

Expand All @@ -32,7 +32,7 @@ class ConsoleThreadTest {
void 'should print version message' () {
executeInput("version")

assertTrue ContentJoiner.on('')
assertTrue Joiner.on('')
.join(ReposiliteWriter.getCache())
.toString()
.contains(ReposiliteConstants.VERSION)
Expand All @@ -42,7 +42,7 @@ class ConsoleThreadTest {
void 'should print docker info' () {
executeInput('')

assertTrue ContentJoiner.on('')
assertTrue Joiner.on('')
.join(ReposiliteWriter.getCache())
.toString()
.contains("Docker")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import groovy.transform.CompileStatic
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.panda_lang.utilities.commons.text.ContentJoiner
import org.panda_lang.utilities.commons.text.Joiner

import static org.junit.jupiter.api.Assertions.assertEquals

Expand Down Expand Up @@ -50,7 +50,7 @@ class ArtifactTest {

@Test
void 'should return artifact file' () {
def fileName = ContentJoiner.on(File.separator)
def fileName = Joiner.on(File.separator)
.join(ARTIFACT.getRepository().getName(), ARTIFACT.getGroup(), ARTIFACT.getArtifact(), ARTIFACT.getVersion())
.toString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DeployEndpointTest extends ReposiliteIntegrationTestSpecification {
def response = put(uri, username, password, content)
assertEquals status, response.getStatusLine().getStatusCode()

def result = IOUtils.convertStreamToString(response.getEntity().getContent()).getValue()
def result = IOUtils.convertStreamToString(response.getEntity().getContent()).get()
assertNotNull result
assertTrue result.contains(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class LookupApiEndpointTest extends ReposiliteIntegrationTestSpecification {
def repositories = shouldReturn200AndJsonResponse('/api')
assertNotNull repositories.get('files')

def files = repositories.getSection('files')
def files = repositories.getSection('files').get()
assertEquals 2, files.size()
assertEquals 'releases', files.getSection(0).getString('name').get()
assertEquals 'snapshots', files.getSection(1).getString('name').get()
assertEquals 'releases', files.getSection(0).get().getString('name', null)
assertEquals 'snapshots', files.getSection(1).get().getString('name', null)
}

@Test
Expand All @@ -52,11 +52,11 @@ class LookupApiEndpointTest extends ReposiliteIntegrationTestSpecification {
assertEquals HttpStatus.SC_OK, response.getStatusCode()

def repositories = CDN.defaultInstance().parseJson(response.parseAsString())
def files = repositories.getSection('files')
def files = repositories.getSection('files').get()
assertEquals 3, files.size()
assertEquals 'releases', files.getSection(0).getString('name').get()
assertEquals 'snapshots', files.getSection(1).getString('name').get()
assertEquals 'private', files.getSection(2).getString('name').get()
assertEquals 'releases', files.getSection(0).get().getString('name').get()
assertEquals 'snapshots', files.getSection(1).get().getString('name').get()
assertEquals 'private', files.getSection(2).get().getString('name').get()
}

@Test
Expand All @@ -83,8 +83,8 @@ class LookupApiEndpointTest extends ReposiliteIntegrationTestSpecification {
@Test
void 'should return 200 and directory dto' () {
def result = shouldReturn200AndJsonResponse('/api/org/panda-lang/reposilite-test')
def files = result.getSection('files')
assertEquals '1.0.1-SNAPSHOT', files.getSection(0).getString('name').get()
def files = result.getSection('files').get()
assertEquals '1.0.1-SNAPSHOT', files.getSection(0).get().getString('name').get()
}

private static Configuration shouldReturn200AndJsonResponse(String uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class ProxyServiceTest extends ReposiliteIntegrationTestSpecification {

def proxiedConfigurationFile = new File(PROXIED_WORKING_DIRECTORY.getAbsolutePath() + '/' + ReposiliteConstants.CONFIGURATION_FILE_NAME)
proxiedConfigurationFile.getParentFile().mkdirs()
FileUtils.overrideFile(proxiedConfigurationFile, CDN.defaultInstance().compose(proxiedConfiguration))
FileUtils.overrideFile(proxiedConfigurationFile, CDN.defaultInstance().render(proxiedConfiguration))

def proxiedReposilite = ReposiliteLauncher.create(null, PROXIED_WORKING_DIRECTORY.getAbsolutePath(), false, true)

Expand Down

0 comments on commit d876f1c

Please sign in to comment.