forked from objectionary/eo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(objectionary#1417): Test API sketch.
feat(objectionary#1417): add FakeMaven class feat(objectionary#1417): simplify API code feat(objectionary#1417): add package-info.java
- Loading branch information
1 parent
508b035
commit dcca5ec
Showing
8 changed files
with
322 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
* | ||
* @since 0.29 | ||
*/ | ||
final class Catalogs { | ||
public final class Catalogs { | ||
|
||
/** | ||
* Singleton. | ||
|
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
91 changes: 91 additions & 0 deletions
91
eo-maven-plugin/src/test/java/org/eolang/maven/testapi/CompilationResult.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,91 @@ | ||
/* | ||
* 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.testapi; | ||
|
||
import com.yegor256.tojos.TjSmart; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.eolang.maven.Catalogs; | ||
import org.eolang.maven.Home; | ||
import org.eolang.maven.ParseMojo; | ||
import org.eolang.maven.TranspileMojo; | ||
|
||
/** | ||
* Maven compilation result. | ||
* @since 0.28.12 | ||
*/ | ||
public final class CompilationResult { | ||
/** | ||
* Compiled eo program id. | ||
*/ | ||
private final String id; | ||
|
||
/** | ||
* Target folder with compilation results. | ||
*/ | ||
private final Home target; | ||
|
||
/** | ||
* Tojo for eo-foreign.* file. | ||
*/ | ||
private final TjSmart foreign; | ||
|
||
/** | ||
* The main constructor. | ||
* | ||
* @param id Compiled eo program id | ||
* @param target Target folder with compilation results. | ||
* @param foreign Path to eo-foreign.* file | ||
*/ | ||
public CompilationResult( | ||
final String id, | ||
final Home target, | ||
final Path foreign | ||
) { | ||
this.target = target; | ||
this.foreign = new TjSmart( | ||
Catalogs.INSTANCE.make(foreign) | ||
); | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Checks if eo program was successfully parsed to xmir file. | ||
* eo-foreign tojo also has an entry about it. | ||
* | ||
* @return True if eo program parsed to xmir successfully. | ||
*/ | ||
public boolean xmirCompiled() { | ||
return this.target.exists( | ||
Paths.get( | ||
String.format( | ||
"%s/%s.%s", | ||
ParseMojo.DIR, | ||
this.id.replace(".", "/"), | ||
TranspileMojo.EXT | ||
) | ||
) | ||
) && this.foreign.getById(this.id).exists("xmir"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
eo-maven-plugin/src/test/java/org/eolang/maven/testapi/MavenWorkspace.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,58 @@ | ||
/* | ||
* 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.testapi; | ||
|
||
import java.io.IOException; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
|
||
/** | ||
* Maven testing workspace. | ||
* @since 0.28.12 | ||
*/ | ||
public interface MavenWorkspace { | ||
|
||
/** | ||
* Adds eo program to a workspace. | ||
* @param program Program as a raw string. | ||
* @return Workspace with eo program. | ||
* @throws IOException If can't save eo program in workspace. | ||
*/ | ||
MavenWorkspace program(String program) throws IOException; | ||
|
||
/** | ||
* Executes Mojo in the workspace. | ||
* | ||
* @param mojo Mojo to execute. | ||
* @param <T> Template for descendants of Mojo. | ||
* @return Workspace after executing Mojo. | ||
*/ | ||
<T extends AbstractMojo> MavenWorkspace execute(Class<T> mojo); | ||
|
||
/** | ||
* Builds and returns compilation results after all manipulations. | ||
* | ||
* @return Compilation result. | ||
*/ | ||
CompilationResult result(); | ||
} |
135 changes: 135 additions & 0 deletions
135
eo-maven-plugin/src/test/java/org/eolang/maven/testapi/MwFake.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,135 @@ | ||
/* | ||
* 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.testapi; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.eolang.maven.AssembleMojo; | ||
import org.eolang.maven.Catalogs; | ||
import org.eolang.maven.Home; | ||
import org.eolang.maven.Moja; | ||
|
||
/** | ||
* Fake maven workspace that executes Mojos in order to test | ||
* their behaviour and results. | ||
* @since 0.28.12 | ||
*/ | ||
public final class MwFake implements MavenWorkspace { | ||
|
||
/** | ||
* Default eo program id. | ||
*/ | ||
private static final String PROGRAM_ID = "foo.x.main"; | ||
|
||
/** | ||
* Default eo program path. | ||
*/ | ||
private static final String PROGRAM_PATH = "foo/x/main.eo"; | ||
|
||
/** | ||
* Default eo-foreign.csv file format. | ||
*/ | ||
private static final String FOREIGN_FORMAT = "csv"; | ||
|
||
/** | ||
* Default eo-foreign.csv file path. | ||
*/ | ||
private static final Path FOREIGN_PATH = Paths.get("eo-foreign.csv"); | ||
|
||
/** | ||
* Test workspace where we place all programs, files, compilation results, etc. | ||
*/ | ||
private final Home workspace; | ||
|
||
/** | ||
* Path to a program in workspace. | ||
*/ | ||
private Path prog; | ||
|
||
/** | ||
* The main constructor. | ||
* | ||
* @param workspace Test temporary directory. | ||
*/ | ||
public MwFake(final Path workspace) { | ||
this.workspace = new Home(workspace); | ||
} | ||
|
||
@Override | ||
public MavenWorkspace program(final String program) throws IOException { | ||
final Path path = Paths.get(MwFake.PROGRAM_PATH); | ||
this.workspace.save(program, path); | ||
this.prog = path; | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T extends AbstractMojo> MavenWorkspace execute(final Class<T> mojo) { | ||
this.withEoForeign(); | ||
new Moja<>(mojo) | ||
.with("targetDir", this.targetPath().toFile()) | ||
.with("foreign", this.foreignPath().toFile()) | ||
.with("foreignFormat", MwFake.FOREIGN_FORMAT) | ||
.execute(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public CompilationResult result() { | ||
return new CompilationResult( | ||
MwFake.PROGRAM_ID, | ||
new Home(this.targetPath()), | ||
this.foreignPath() | ||
); | ||
} | ||
|
||
/** | ||
* Creates eo-foreign.* file. In the future it is going to be a method for `MavenWorkspace` | ||
* interface. | ||
*/ | ||
private void withEoForeign() { | ||
Catalogs.INSTANCE.make(this.foreignPath()) | ||
.add(MwFake.PROGRAM_ID) | ||
.set(AssembleMojo.ATTR_SCOPE, "compile") | ||
.set(AssembleMojo.ATTR_EO, this.workspace.absolute(this.prog)); | ||
} | ||
|
||
/** | ||
* Path to 'eo-foreign.csv' or 'eo-foreign.json' file after all changes. | ||
* @return Path to eo-foreign.* file. | ||
*/ | ||
private Path foreignPath() { | ||
return this.workspace.absolute(MwFake.FOREIGN_PATH); | ||
} | ||
|
||
/** | ||
* Path to compilation target directory. | ||
* @return Path to target dir. | ||
*/ | ||
private Path targetPath() { | ||
return this.workspace.absolute(Paths.get("target")); | ||
} | ||
} |
Oops, something went wrong.