-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
eo-maven-plugin/src/main/java/org/eolang/maven/OyFallbackSwap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.eolang.maven; | ||
|
||
import java.io.IOException; | ||
import org.cactoos.Input; | ||
import org.cactoos.scalar.Sticky; | ||
import org.cactoos.scalar.Unchecked; | ||
|
||
/** | ||
* Fallback which can swap primary/secondary repos. | ||
* <p/> | ||
* The key purpose of this class is to allow dynamic determination | ||
* of which Oy (fist or second) to use as primary and which as fallback based on given | ||
* boolean property. | ||
* <p/> | ||
* For {@link PullMojo} this is used to bypass reading from cache by always checking remote | ||
* first and only fallback to local in case of object miss: | ||
* <pre> | ||
* new PullMojo.FallbackSwapOy( | ||
* < local >, | ||
* < remote >, | ||
* this.forceUpdate() | ||
* ); | ||
* </pre> | ||
* @since 1.0 | ||
*/ | ||
public final class OyFallbackSwap implements Objectionary { | ||
/** | ||
* Swapped Oy. | ||
*/ | ||
private final Unchecked<Objectionary> swapped; | ||
|
||
/** | ||
* Ctor. | ||
* @param first Initial primary | ||
* @param second Initial secondary | ||
* @param swap Whether to swap | ||
*/ | ||
public OyFallbackSwap( | ||
final Objectionary first, | ||
final Objectionary second, | ||
final boolean swap | ||
) { | ||
this.swapped = new Unchecked<>( | ||
new Sticky<>( | ||
() -> { | ||
final Objectionary result; | ||
if (swap) { | ||
result = new OyFallback( | ||
second, | ||
first | ||
); | ||
} else { | ||
result = new OyFallback( | ||
first, | ||
second | ||
); | ||
} | ||
return result; | ||
} | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public Input get(final String name) throws IOException { | ||
return this.swapped.value().get(name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.swapped.value().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
eo-maven-plugin/src/test/java/org/eolang/maven/OyFallbackSwapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.eolang.maven; | ||
|
||
import java.io.IOException; | ||
import org.cactoos.io.InputOf; | ||
import org.cactoos.text.TextOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link OyFallbackSwap}. | ||
* @since 1.0 | ||
*/ | ||
class OyFallbackSwapTest { | ||
@Test | ||
public void testFallbackNoSwapOy() throws Exception { | ||
MatcherAssert.assertThat( | ||
new TextOf( | ||
new OyFallbackSwap( | ||
s -> new InputOf("[] > local\n"), | ||
s -> new InputOf("[] > remote\n"), | ||
false | ||
).get("") | ||
).asString(), | ||
Matchers.containsString("local") | ||
); | ||
} | ||
|
||
@Test | ||
public void testFallbackSwapOyFail() throws Exception { | ||
MatcherAssert.assertThat( | ||
new TextOf( | ||
new OyFallbackSwap( | ||
s -> new InputOf("[] > local\n"), | ||
s -> { | ||
throw new IOException("Can't get object"); | ||
}, | ||
false | ||
).get("") | ||
).asString(), | ||
Matchers.containsString("local") | ||
); | ||
} | ||
|
||
@Test | ||
public void testFallbackSwapOy() throws Exception { | ||
MatcherAssert.assertThat( | ||
new TextOf( | ||
new OyFallbackSwap( | ||
s -> new InputOf("[] > local\n"), | ||
s -> new InputOf("[] > remote\n"), | ||
true | ||
).get("") | ||
).asString(), | ||
Matchers.containsString("remote") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,5 +69,4 @@ public void testSimplePull(@TempDir final Path temp) { | |
Matchers.is(true) | ||
); | ||
} | ||
|
||
} |
67ebcd9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
561-386b5824
disappeared fromeo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
), that's why I closed #624. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.