Skip to content

Commit

Permalink
fix(objectionary#2790):deleted dangerous code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Jan 23, 2024
1 parent 7133336 commit 771f8eb
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -55,7 +54,7 @@ public final class OptCached implements Optimization {
private final Optimization delegate;

/**
* Cache folder.
* Absolute path of cache folder.
*/
private final Path folder;

Expand All @@ -74,7 +73,7 @@ public OptCached(
}

@Override
public XML apply(final Path path) throws FileNotFoundException {
public XML apply(final Path path) throws Exception {
try {
final XML optimized;
if (this.contains(path)) {
Expand All @@ -89,8 +88,8 @@ public XML apply(final Path path) throws FileNotFoundException {
}
return optimized;
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("Can't optimize '%s'", new XMLDocument(path)),
throw new IOException(
String.format("Can't optimize '%s'", path),
ex
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.Train;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import org.eolang.maven.Place;
import org.eolang.maven.SpyTrain;
Expand Down Expand Up @@ -68,7 +67,7 @@ public OptSpy(final Train<Shift> trn, final Path target) {
}

@Override
public XML apply(final Path path) throws FileNotFoundException {
public XML apply(final Path path) throws Exception {
final Path dir = new Place(
new XMLDocument(path)
.xpath("/program/@name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.yegor256.xsline.TrFast;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.io.FileNotFoundException;
import java.nio.file.Path;

/**
Expand Down Expand Up @@ -120,7 +119,7 @@ public OptTrain(
}

@Override
public XML apply(final Path path) throws FileNotFoundException {
public XML apply(final Path path) throws Exception {
return new Xsline(this.shifts).pass(this.delegate.apply(path));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,14 @@
package org.eolang.maven.optimization;

import com.jcabi.xml.XML;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.util.function.Function;
import org.cactoos.Func;

/**
* Abstraction for XML optimizations.
*
* @since 0.28.11
*/
@FunctionalInterface
public interface Optimization extends ThrowingFunction<Path, XML, FileNotFoundException> {

/**
* Return function if it works without exception.
*
* @return The function result
*/
default Function<Path, XML> unchecked() {
return input -> {
try {
return this.apply(input);
} catch (final FileNotFoundException exception) {
throw new PathNotFoundException(input, exception);
}
};
}
public interface Optimization extends Func<Path, XML> {
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class OptCachedTest {
*/
@Test
void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path cache, @TempDir final Path dir)
throws IOException {
throws Exception {
final XML xml = OptCachedTest.program();
final FileTime time = FileTime.fromMillis(System.currentTimeMillis());
final Path program = OptCachedTest.save(dir, xml);
Expand All @@ -83,7 +83,7 @@ void returnsFromCacheButTimesSaveAndExecuteDifferent(
@TempDir final Path cache,
@TempDir final Path dir
)
throws IOException {
throws Exception {
final XML xml = OptCachedTest.program();
final Path program = OptCachedTest.save(dir, xml);
OptCachedTest.setTime(
Expand All @@ -109,7 +109,7 @@ void returnsFromCacheButTimesSaveAndExecuteDifferent(

@Test
void returnsFromCacheCorrectProgram(@TempDir final Path cache, @TempDir final Path dir)
throws IOException {
throws Exception {
final Path cached = OptCachedTest.save(
cache,
OptCachedTest.program("first program")
Expand All @@ -134,7 +134,7 @@ void returnsFromCacheCorrectProgram(@TempDir final Path cache, @TempDir final Pa

@Test
void optimizesIfXmlIsAbsentInCache(@TempDir final Path cache, @TempDir final Path dir)
throws IOException {
throws Exception {
final Path program = OptCachedTest.save(dir, OptCachedTest.program());
MatcherAssert.assertThat(
"We expect that the program will be created and returned as is (same instance)",
Expand All @@ -151,7 +151,7 @@ void optimizesIfXmlIsAbsentInCache(@TempDir final Path cache, @TempDir final Pat
@Test
void optimizesBecauseCacheIsExpired(
@TempDir final Path cache,
@TempDir final Path dir) throws IOException {
@TempDir final Path dir) throws Exception {
final Path program = OptCachedTest.save(
dir,
OptCachedTest.program("new program")
Expand Down

0 comments on commit 771f8eb

Please sign in to comment.