-
Notifications
You must be signed in to change notification settings - Fork 127
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
37 changed files
with
748 additions
and
88 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
target/ | ||
.idea | ||
.vscode/ | ||
.idea/ | ||
.DS_Store | ||
*.iml | ||
.project | ||
|
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
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
53 changes: 53 additions & 0 deletions
53
eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.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,53 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Objectionary.com | ||
* | ||
* 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.Scalar; | ||
|
||
/** | ||
* Program footprint of EO compilation process. | ||
* @since 1.0 | ||
*/ | ||
public interface Footprint { | ||
|
||
/** | ||
* Get program content of a specific type. | ||
* @param program Program name | ||
* @param ext File extension which defines the type | ||
* @return Content of a file | ||
* @throws IOException In case of IO issue. | ||
*/ | ||
String load(String program, String ext) throws IOException; | ||
|
||
/** | ||
* Save content. | ||
* @param program Program name | ||
* @param ext File extension | ||
* @param content File content | ||
* @throws IOException In case of IO issues | ||
*/ | ||
void save(String program, String ext, Scalar<String> content) | ||
throws IOException; | ||
} |
118 changes: 118 additions & 0 deletions
118
eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.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,118 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Objectionary.com | ||
* | ||
* 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 com.jcabi.log.Logger; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.scalar.IoChecked; | ||
import org.cactoos.text.IoCheckedText; | ||
import org.cactoos.text.TextOf; | ||
|
||
/** | ||
* Program footprint of EO compilation process. | ||
* <p/>The footprint consists of file in {@link #main} folder and optionally cached | ||
* file in {@link #cache} folder. | ||
* Caching is applied if {@link #hash} is not empty otherwise caching is ignored. | ||
* <p/>Usage example: | ||
* <code> | ||
* <pre> | ||
* final Footprint footprint = new Footprint( | ||
* hash, | ||
* targetRoot, | ||
* cacheRoot | ||
* ).save(program, ext); | ||
* | ||
* String content = footprint.content(program, ext); | ||
* </pre> | ||
* </code> | ||
* @since 1.0 | ||
*/ | ||
public final class FtCached implements Footprint { | ||
/** | ||
* Path to target root. | ||
*/ | ||
private final Path main; | ||
|
||
/** | ||
* Version tag. | ||
*/ | ||
private final String hash; | ||
|
||
/** | ||
* Path to cache root. | ||
*/ | ||
private final Path cache; | ||
|
||
/** | ||
* Ctor. | ||
* @param hash Version tag | ||
* @param main Main root | ||
* @param cache Cache root | ||
*/ | ||
public FtCached(final String hash, final Path main, final Path cache) { | ||
this.hash = hash; | ||
this.main = main; | ||
this.cache = cache; | ||
} | ||
|
||
@Override | ||
public String load(final String program, final String ext) throws IOException { | ||
final Path cached = new Place(program).make(this.cache.resolve(this.hash), ext); | ||
final Path target = new Place(program).make(this.main, ext); | ||
final IoCheckedText content; | ||
if (cached.toFile().exists()) { | ||
content = new IoCheckedText( | ||
new TextOf(cached) | ||
); | ||
} else { | ||
content = new IoCheckedText( | ||
new TextOf(target) | ||
); | ||
} | ||
return content.asString(); | ||
} | ||
|
||
@Override | ||
public void save(final String program, final String ext, final Scalar<String> content) | ||
throws IOException { | ||
final Path cached = new Place(program).make(this.cache.resolve(this.hash), ext); | ||
final Path target = new Place(program).make(this.main, ext); | ||
final String text; | ||
if (cached.toFile().exists()) { | ||
Logger.info( | ||
this, | ||
"Program %s found in cache: %s", | ||
program, | ||
cached | ||
); | ||
text = this.load(program, ext); | ||
} else { | ||
text = new IoChecked<>(content).value(); | ||
new Save(text, cached).save(); | ||
} | ||
new Save(text, target).save(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
eo-maven-plugin/src/main/java/org/eolang/maven/FtDefault.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,69 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Objectionary.com | ||
* | ||
* 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 java.nio.file.Path; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.scalar.IoChecked; | ||
import org.cactoos.text.IoCheckedText; | ||
import org.cactoos.text.TextOf; | ||
|
||
/** | ||
* Default implementation of a Footprint. | ||
* @since 1.0 | ||
*/ | ||
public final class FtDefault implements Footprint { | ||
|
||
/** | ||
* Path to main location. | ||
*/ | ||
private final Path main; | ||
|
||
/** | ||
* Ctor. | ||
* @param main Main location. | ||
*/ | ||
public FtDefault(final Path main) { | ||
this.main = main; | ||
} | ||
|
||
@Override | ||
public String load(final String program, final String ext) throws IOException { | ||
return new IoCheckedText( | ||
new TextOf( | ||
new Place(program).make(this.main, ext) | ||
) | ||
).asString(); | ||
} | ||
|
||
@Override | ||
public void save(final String program, final String ext, final Scalar<String> content) | ||
throws IOException { | ||
new Save( | ||
new IoChecked<>(content).value(), | ||
new Place(program).make(this.main, ext) | ||
).save(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.