Search in sources :

Example 1 with Content

use of com.artipie.asto.Content in project maven-adapter by artipie.

the class CachedProxySlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom req = new RequestLineFrom(line);
    final Key key = new KeyFromPath(req.uri().getPath());
    return new AsyncResponse(new RepoHead(this.client).head(req.uri().getPath()).thenCompose(head -> this.cache.load(key, new Remote.WithErrorHandling(() -> {
        final CompletableFuture<Optional<? extends Content>> promise = new CompletableFuture<>();
        this.client.response(line, Headers.EMPTY, Content.EMPTY).send((rsstatus, rsheaders, rsbody) -> {
            final CompletableFuture<Void> term = new CompletableFuture<>();
            if (rsstatus.success()) {
                final Flowable<ByteBuffer> res = Flowable.fromPublisher(rsbody).doOnError(term::completeExceptionally).doOnTerminate(() -> term.complete(null));
                promise.complete(Optional.of(new Content.From(res)));
            } else {
                promise.complete(Optional.empty());
            }
            return term;
        });
        return promise;
    }), new CacheControl.All(StreamSupport.stream(head.orElse(Headers.EMPTY).spliterator(), false).map(Header::new).map(CachedProxySlice::checksumControl).collect(Collectors.toUnmodifiableList()))).handle((content, throwable) -> {
        final Response result;
        if (throwable == null && content.isPresent()) {
            result = new RsWithBody(StandardRs.OK, new Content.From(content.get()));
        } else {
            result = StandardRs.NOT_FOUND;
        }
        return result;
    })));
}
Also used : Header(com.artipie.http.headers.Header) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Hex(org.apache.commons.codec.binary.Hex) DigestVerification(com.artipie.asto.cache.DigestVerification) RsWithBody(com.artipie.http.rs.RsWithBody) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Flowable(io.reactivex.Flowable) Locale(java.util.Locale) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Remote(com.artipie.asto.cache.Remote) KeyFromPath(com.artipie.http.slice.KeyFromPath) Headers(com.artipie.http.Headers) DecoderException(org.apache.commons.codec.DecoderException) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Cache(com.artipie.asto.cache.Cache) Pattern(java.util.regex.Pattern) StandardRs(com.artipie.http.rs.StandardRs) CacheControl(com.artipie.asto.cache.CacheControl) Optional(java.util.Optional) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) ByteBuffer(java.nio.ByteBuffer) RsWithBody(com.artipie.http.rs.RsWithBody) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) CompletableFuture(java.util.concurrent.CompletableFuture) KeyFromPath(com.artipie.http.slice.KeyFromPath) Content(com.artipie.asto.Content) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 2 with Content

use of com.artipie.asto.Content in project maven-adapter by artipie.

the class AstoMavenTest method generatesMetadataForFirstArtifact.

@Test
void generatesMetadataForFirstArtifact() {
    final String version = "1.0";
    new TestResource("maven-metadata.xml.example").saveTo(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"));
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.LGR_UPLOAD, version), AstoMavenTest.LGR).toCompletableFuture().join();
    MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.LGR, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.test']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'logger']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions[count(//version) = 1]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
    MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.LGR_UPLOAD, version)).join().size(), new IsEqual<>(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataXml(com.artipie.maven.MetadataXml) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) AllOf(org.hamcrest.core.AllOf) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) ListOf(org.cactoos.list.ListOf) IsEqual(org.hamcrest.core.IsEqual) TestResource(com.artipie.asto.test.TestResource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Predicate(java.util.function.Predicate) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Matchers(org.hamcrest.Matchers) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) PublisherAs(com.artipie.asto.ext.PublisherAs) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) XML(com.jcabi.xml.XML) PublisherAs(com.artipie.asto.ext.PublisherAs) ListOf(org.cactoos.list.ListOf) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) XMLDocument(com.jcabi.xml.XMLDocument) Test(org.junit.jupiter.api.Test)

Example 3 with Content

use of com.artipie.asto.Content in project maven-adapter by artipie.

the class AstoMavenTest method generatesWithSnapshotMetadata.

@Test
void generatesWithSnapshotMetadata() throws Exception {
    final String snapshot = "1.0-SNAPSHOT";
    final Predicate<String> cond = item -> !item.contains(snapshot);
    this.addFilesToStorage(cond, AstoMavenTest.ASTO);
    this.addFilesToStorage(cond.negate(), AstoMavenTest.ASTO_UPLOAD);
    this.metadataAndVersions(snapshot, "0.20.2");
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.ASTO_UPLOAD, snapshot), AstoMavenTest.ASTO).toCompletableFuture().get();
    MatcherAssert.assertThat(new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.ASTO, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(// @checkstyle LineLengthCheck (20 lines)
    XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.artipie']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'asto']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '1.0-SNAPSHOT']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.15']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.11.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.18']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '1.0-SNAPSHOT']"), XhtmlMatchers.hasXPath("metadata/versioning/versions[count(//version) = 6]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
    MatcherAssert.assertThat("Artifacts were not moved to the correct location", this.storage.list(new Key.From(AstoMavenTest.ASTO, snapshot)).join().size(), new IsEqual<>(12));
    MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.ASTO_UPLOAD, snapshot)).join().size(), new IsEqual<>(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataXml(com.artipie.maven.MetadataXml) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) AllOf(org.hamcrest.core.AllOf) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) ListOf(org.cactoos.list.ListOf) IsEqual(org.hamcrest.core.IsEqual) TestResource(com.artipie.asto.test.TestResource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Predicate(java.util.function.Predicate) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Matchers(org.hamcrest.Matchers) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) PublisherAs(com.artipie.asto.ext.PublisherAs) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) XML(com.jcabi.xml.XML) PublisherAs(com.artipie.asto.ext.PublisherAs) ListOf(org.cactoos.list.ListOf) Key(com.artipie.asto.Key) XMLDocument(com.jcabi.xml.XMLDocument) Test(org.junit.jupiter.api.Test)

Example 4 with Content

use of com.artipie.asto.Content in project maven-adapter by artipie.

the class AstoMavenTest method generatesMetadata.

@Test
void generatesMetadata() {
    final String latest = "0.20.2";
    this.addFilesToStorage(item -> !item.contains("1.0-SNAPSHOT") && !item.contains(latest), AstoMavenTest.ASTO);
    this.addFilesToStorage(item -> item.contains(latest), AstoMavenTest.ASTO_UPLOAD);
    this.metadataAndVersions(latest);
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.ASTO_UPLOAD, latest), AstoMavenTest.ASTO).toCompletableFuture().join();
    MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.ASTO, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(// @checkstyle LineLengthCheck (20 lines)
    XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.artipie']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'asto']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.15']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.11.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.18']"), XhtmlMatchers.hasXPath("metadata/versioning/versions[count(//version) = 5]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
    MatcherAssert.assertThat("Artifacts were not moved to the correct location", this.storage.list(new Key.From(AstoMavenTest.ASTO, latest)).join().size(), new IsEqual<>(3));
    MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.ASTO_UPLOAD, latest)).join().size(), new IsEqual<>(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataXml(com.artipie.maven.MetadataXml) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) AllOf(org.hamcrest.core.AllOf) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) ListOf(org.cactoos.list.ListOf) IsEqual(org.hamcrest.core.IsEqual) TestResource(com.artipie.asto.test.TestResource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Predicate(java.util.function.Predicate) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Matchers(org.hamcrest.Matchers) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) PublisherAs(com.artipie.asto.ext.PublisherAs) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) XML(com.jcabi.xml.XML) PublisherAs(com.artipie.asto.ext.PublisherAs) ListOf(org.cactoos.list.ListOf) Key(com.artipie.asto.Key) XMLDocument(com.jcabi.xml.XMLDocument) Test(org.junit.jupiter.api.Test)

Example 5 with Content

use of com.artipie.asto.Content in project maven-adapter by artipie.

the class RepositoryChecksumsTest method generatesChecksums.

@Test
void generatesChecksums() {
    final Storage storage = new InMemoryStorage();
    final Key key = new Key.From("my-artifact.jar");
    final byte[] content = "my artifact content".getBytes();
    storage.save(key, new Content.From(content));
    new RepositoryChecksums(storage).generate(key).toCompletableFuture().join();
    MatcherAssert.assertThat("Generates sha1", new PublisherAs(storage.value(new Key.From(String.format("%s.sha1", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha1Hex(content)));
    MatcherAssert.assertThat("Generates sha256", new PublisherAs(storage.value(new Key.From(String.format("%s.sha256", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha256Hex(content)));
    MatcherAssert.assertThat("Generates sha512", new PublisherAs(storage.value(new Key.From(String.format("%s.sha512", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha512Hex(content)));
    MatcherAssert.assertThat("Generates md5", new PublisherAs(storage.value(new Key.From(String.format("%s.md5", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.md5Hex(content)));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) PublisherAs(com.artipie.asto.ext.PublisherAs) Storage(com.artipie.asto.Storage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Content (com.artipie.asto.Content)9 Key (com.artipie.asto.Key)9 MetadataXml (com.artipie.maven.MetadataXml)6 Test (org.junit.jupiter.api.Test)6 Storage (com.artipie.asto.Storage)5 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)5 PublisherAs (com.artipie.asto.ext.PublisherAs)5 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 KeyLastPart (com.artipie.asto.ext.KeyLastPart)4 FileStorage (com.artipie.asto.fs.FileStorage)4 TestResource (com.artipie.asto.test.TestResource)4 PutMetadataSlice (com.artipie.maven.http.PutMetadataSlice)4 XhtmlMatchers (com.jcabi.matchers.XhtmlMatchers)4 XML (com.jcabi.xml.XML)4 XMLDocument (com.jcabi.xml.XMLDocument)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Predicate (java.util.function.Predicate)4 Stream (java.util.stream.Stream)4