Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 20, 2024
2 parents 4758a14 + 4b60150 commit b48b7c7
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/rultor/agents/daemons/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.logging.Level;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.io.input.AutoCloseInputStream;

/**
* Script to run.
Expand Down Expand Up @@ -77,7 +78,10 @@ public int exec(final XML xml) throws IOException {
"cd %s && cat > %s && chmod a+x %1$s/%2$s",
Ssh.escape(dir), Ssh.escape(this.name)
),
this.getClass().getResourceAsStream(this.name),
AutoCloseInputStream.builder()
.setInputStream(
this.getClass().getResourceAsStream(this.name)
).get(),
Logger.stream(Level.INFO, this),
Logger.stream(Level.WARNING, this)
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/daemons/StartsDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private InputStream ring(final String name) throws IOException {
return new ByteArrayInputStream(
Base64.decodeBase64(
IOUtils.toByteArray(
this.getClass().getResourceAsStream(
this.getClass().getResource(
String.format("%s.base64", name)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/docker/DockerExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public DockerExec(final Shell ssh, final String scrpt) {
public void execute(final Talks talks) throws IOException {
new Shell.Safe(this.shell).exec(
IOUtils.toString(
this.getClass().getResourceAsStream(this.script),
this.getClass().getResource(this.script),
StandardCharsets.UTF_8
),
new NullInputStream(0L),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public DockerHealthCheck(final Shell ssh) {
public void execute(final Talks talks) throws IOException {
new Shell.Safe(this.shell).exec(
IOUtils.toString(
this.getClass().getResourceAsStream("checkhost.sh"),
this.getClass().getResource("checkhost.sh"),
StandardCharsets.UTF_8
),
new NullInputStream(0L),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/github/qtn/QnStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public final class QnStatus implements Question {
* XSL to generate report.
*/
private static final XSL REPORT = XSLDocument.make(
QnStatus.class.getResourceAsStream("status.xsl")
QnStatus.class.getResource("status.xsl")
);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rultor/agents/req/StartsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ private String script(final XML req, final String type, final String name)
Collections.singleton(this.asRoot()),
Collections.singleton(
IOUtils.toString(
this.getClass().getResourceAsStream("_head.sh"),
this.getClass().getResource("_head.sh"),
StandardCharsets.UTF_8
)
),
Collections.singleton(this.sensitive()),
this.decryptor().commands(),
Collections.singleton(
IOUtils.toString(
this.getClass().getResourceAsStream(
this.getClass().getResource(
String.format("%s.sh", type)
),
StandardCharsets.UTF_8
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/spi/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface Profile {
* Schema.
*/
XSD SCHEMA = XSDDocument.make(
Talk.class.getResourceAsStream("profile.xsd")
Talk.class.getResource("profile.xsd")
);

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rultor/spi/Talk.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public interface Talk {
* Schema.
*/
XSD SCHEMA = XSDDocument.make(
Talk.class.getResourceAsStream("talk.xsd")
Talk.class.getResource("talk.xsd")
);

/**
Expand All @@ -79,12 +79,12 @@ public interface Talk {
XSL UPGRADE = new XSLChain(
Arrays.asList(
XSLDocument.make(
Talk.class.getResourceAsStream(
Talk.class.getResource(
"upgrade/001-talks.xsl"
)
),
XSLDocument.make(
Talk.class.getResourceAsStream(
Talk.class.getResource(
"upgrade/002-public-attribute.xsl"
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/web/TkButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Response act(final RqRegex req) throws IOException {
return new RsWithType(
new RsWithHeaders(
new RsWithBody(
this.getClass().getResourceAsStream(
this.getClass().getResource(
String.format("button-%s.svg", suffix)
)
),
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/com/rultor/web/TkDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package com.rultor.web;

import com.jcabi.log.Logger;
import com.rultor.agents.daemons.Tail;
import com.rultor.spi.Talk;
import com.rultor.spi.Talks;
Expand All @@ -43,6 +44,7 @@
import java.util.Collections;
import java.util.logging.Level;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.AutoCloseInputStream;
import org.apache.commons.io.input.ProxyReader;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.text.StringEscapeUtils;
Expand Down Expand Up @@ -98,14 +100,23 @@ public Response act(final RqRegex req) throws IOException {
);
}
final String hash = req.matcher().group(2);
return new RsFluent()
.withStatus(HttpURLConnection.HTTP_OK)
.withBody(this.html(number, hash))
.withType("text/html; charset=utf-8")
.withHeader(
"X-Rultor-Daemon",
String.format("%s-%s", number, hash)
try {
return new RsFluent()
.withStatus(HttpURLConnection.HTTP_OK)
.withBody(this.html(number, hash))
.withType("text/html; charset=utf-8")
.withHeader(
"X-Rultor-Daemon",
String.format("%s-%s", number, hash)
);
} catch (final IOException err) {
Logger.error(
this,
"Error during answering in talk %d to %s. %s",
hash, err
);
throw err;
}
}

/**
Expand All @@ -119,7 +130,7 @@ private InputStream html(final long number, final String hash)
throws IOException {
final Talk talk = this.talks.get(number);
final String head = IOUtils.toString(
this.getClass().getResourceAsStream("daemon/head.html"),
this.getClass().getResource("daemon/head.html"),
StandardCharsets.UTF_8
).trim();
return new SequenceInputStream(
Expand All @@ -137,7 +148,10 @@ private InputStream html(final long number, final String hash)
StandardCharsets.UTF_8
),
TkDaemon.escape(new Tail(talk.read(), hash).read()),
this.getClass().getResourceAsStream("daemon/tail.html")
AutoCloseInputStream.builder()
.setInputStream(
this.getClass().getResourceAsStream("daemon/tail.html")
).get()
)
)
);
Expand All @@ -154,7 +168,7 @@ private static InputStream escape(
) throws IOException {
final PushbackReader src = new PushbackReader(
new InputStreamReader(input, StandardCharsets.UTF_8),
10_000
100_000
);
return ReaderInputStream.builder()
.setCharset(StandardCharsets.UTF_8)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/web/TkTicks.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class TkTicks implements Take {
* XSLT for pulse render.
*/
private static final XSL PULSE = XSLDocument.make(
TkTicks.class.getResourceAsStream("pulse.xsl")
TkTicks.class.getResource("pulse.xsl")
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void runsCheckHostScript() throws Exception {
Mockito.verify(shell).exec(
Mockito.eq(
IOUtils.toString(
DockerHealthCheck.class.getResourceAsStream("checkhost.sh"),
DockerHealthCheck.class.getResource("checkhost.sh"),
StandardCharsets.UTF_8
)
),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/rultor/agents/req/DecryptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void decryptsAssets(@TempDir final Path temp) throws Exception {
final String[] keys = {"secring"};
for (final String key : keys) {
final String gpg = IOUtils.toString(
this.getClass().getResourceAsStream(
this.getClass().getResource(
String.format("%s.gpg.base64", key)
),
StandardCharsets.UTF_8
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/rultor/agents/req/StartsRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void startsMergeRequest(
new Joined(
"",
"<p><entry key='merge'><entry key='script'>",
"echo HEY</entry></entry></p>"
"echo \"some('.env');\"</entry></entry></p>"
).asString()
)
)
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/rultor/spi/TalkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ final class TalkTest {
/**
* Talk can accept correct XML.
* @throws Exception In case of error.
* @checkstyle AbbreviationAsWordInNameCheck (5 lines)
*/
@Test
void acceptsValidXML() throws Exception {
void acceptsValidXml() throws Exception {
final Talk talk = new Talk.InFile();
talk.modify(
new Directives()
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/rultor/web/TkAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class TkAppTest {
@BeforeEach
void resourcesAvailable() {
Assumptions.assumeFalse(
TkAppTest.class.getResourceAsStream("/xsl/home.xsl") == null
TkAppTest.class.getResource("/xsl/home.xsl") == null
);
}

Expand Down

0 comments on commit b48b7c7

Please sign in to comment.