Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jun 6, 2023
2 parents f04635c + 7960752 commit 85754ce
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 71 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ SOFTWARE.
<dependency>
<groupId>org.eolang</groupId>
<artifactId>ddr</artifactId>
<version>0.0.9</version>
<version>0.0.10</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
Expand Down
73 changes: 73 additions & 0 deletions src/main/kotlin/org/objectionary/aoi/launch/AoiWorkflow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 Olesia Subbotina
*
* 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.objectionary.aoi.launch

import org.objectionary.aoi.process.AtomsProcessor
import org.objectionary.aoi.process.InnerUsageProcessor
import org.objectionary.aoi.process.InstanceUsageProcessor
import org.objectionary.aoi.transformer.XmirTransformer
import org.objectionary.ddr.graph.AttributesSetter
import org.objectionary.ddr.graph.CondAttributesSetter
import org.objectionary.ddr.graph.GraphBuilder
import org.objectionary.ddr.graph.InnerPropagator
import org.objectionary.ddr.sources.SrsTransformed
import org.objectionary.ddr.transform.XslTransformer
import org.w3c.dom.Document

/**
* Stores all the information from xmir files in the form of a graph. Launches various analysis or transformation steps
* on the graph.
*
* @property documents all documents from analyzed directory
*/
/* todo #54:30min this class is almost copy-paste of DdrWorkflow class from ddr repository. So Workflow interface and
AnalysisWorkflow base class should be created in ddr repository. After next ddr release this class should be
rewritten. */
class AoiWorkflow(val documents: MutableMap<Document, String>) {
/** @property graph decoration hierarchy graph of xmir files from analyzed directory */
private val graph = GraphBuilder(documents).createGraph()

/**
* Constructs [documents] from [path]
*
* @param path path to the directory to be analysed
* @param postfix postfix of the resulting directory
*/
constructor(path: String, postfix: String = "aoi") : this(
SrsTransformed(path, XslTransformer(), postfix, false).walk())

/**
* Aggregates all steps of analysis
*/
fun launch() {
CondAttributesSetter(graph).processConditions()
AttributesSetter(graph).setAttributes()
AtomsProcessor(graph).processAtoms()
InnerPropagator(graph).propagateInnerAttrs()
InnerUsageProcessor(graph).processInnerUsages()
InstanceUsageProcessor(graph).processInstanceUsages()
XmirTransformer(graph, documents).addAoiSection()
}
}
60 changes: 0 additions & 60 deletions src/main/kotlin/org/objectionary/aoi/launch/Launcher.kt

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/org/objectionary/aoi/launch/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ package org.objectionary.aoi.launch
* - args[0] path to the folder with the program to be analyzed
*/
fun main(args: Array<String>) {
launch(path = args[0])
AoiWorkflow(path = args[0]).launch()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
package org.objectionary.aoi.integration

import org.objectionary.aoi.TestBase
import org.objectionary.aoi.launch.launch
import org.objectionary.ddr.launch.documents
import org.objectionary.aoi.launch.AoiWorkflow
import org.apache.commons.io.FileUtils
import org.slf4j.LoggerFactory
import java.io.BufferedReader
Expand All @@ -42,8 +41,7 @@ open class IntegrationTestBase : TestBase {

override fun doTest() {
val path = getTestName()
documents.clear()
launch(constructInPath(path))
AoiWorkflow(constructInPath(path)).launch()
val actualFiles: MutableList<String> = mutableListOf()
Files.walk(Paths.get(constructOutPath(path)))
.filter(Files::isRegularFile)
Expand Down
13 changes: 8 additions & 5 deletions src/test/kotlin/org/objectionary/aoi/unit/UnitTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import org.objectionary.aoi.TestBase
import org.objectionary.aoi.data.FreeAttributesHolder
import org.objectionary.ddr.graph.AttributesSetter
import org.objectionary.ddr.graph.CondAttributesSetter
import org.objectionary.ddr.graph.GraphBuilder
import org.objectionary.ddr.graph.InnerPropagator
import org.objectionary.ddr.graph.repr.Graph
import org.objectionary.ddr.launch.buildGraph
import org.objectionary.ddr.launch.documents
import org.objectionary.ddr.sources.SrsTransformed
import org.objectionary.ddr.transform.XslTransformer
import org.apache.commons.io.FileUtils
import org.slf4j.LoggerFactory
import java.io.BufferedReader
Expand All @@ -47,9 +48,9 @@ open class UnitTestBase : TestBase {

override fun doTest() {
val path = getTestName()
documents.clear()
FreeAttributesHolder.storage.clear()
val graph = buildGraph(constructInPath(path))
val graph = GraphBuilder(
SrsTransformed(constructInPath(path), XslTransformer(), "aoi", false).walk()).createGraph()
CondAttributesSetter(graph).processConditions()
AttributesSetter(graph).setAttributes()
InnerPropagator(graph).propagateInnerAttrs()
Expand All @@ -63,7 +64,9 @@ open class UnitTestBase : TestBase {
checkOutput(expected, actual)
try {
val tmpDir =
Paths.get("${constructInPath(path).replace('/', sep).substringBeforeLast(sep)}${sep}TMP").toString()
Paths.get(
"${constructInPath(path).replace('/', sep).substringBeforeLast(sep)}${sep}TMP"
).toString()
FileUtils.deleteDirectory(File(tmpDir))
} catch (e: Exception) {
logger.error(e.printStackTrace().toString())
Expand Down

0 comments on commit 85754ce

Please sign in to comment.