Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#69): factorialize #70

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/it/factorial/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean install
152 changes: 152 additions & 0 deletions src/it/factorial/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)

Copyright (c) 2016-2023 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--
The version of 3.2.0 and similar requires rather high java
version: 17 or higher. So we intentionally use the version 2.7.18
here that requires java 11 since our plugin should be compatible with
java 11.
-->
<version>2.7.18</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eolang</groupId>
<artifactId>factorial</artifactId>
<version>@project.version@</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jeo.version>0.4.4</jeo.version>
<opeo.version>0.2.0</opeo.version>
<jeo.disassemble.output>${project.build.directory}/generated-sources/jeo-disassemble-xmir</jeo.disassemble.output>
<opeo.decompile.output>${project.build.directory}/generated-sources/opeo-decompile-xmir</opeo.decompile.output>
<opeo.modified>${project.build.directory}/generated-sources/opeo-decompile-modified-xmir</opeo.modified>
<opeo.compile.input>${opeo.decompile.output}</opeo.compile.input>
<opeo.compile.output>${project.build.directory}/generated-sources/opeo-compile-xmir</opeo.compile.output>
<ineo.factorialize.output>${project.build.directory}/generated-sources/ineo-factorialized-xmir</ineo.factorialize.output>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<!--
@todo #229:90min Handle module-info.class files correctly.
Currently we just exclude all `module-info.class` files from the downloaded dependencies.
This means that we don't support Java 9+ modules.
We should handle them correctly and ensure support Java 9+ modules in 'spring-fat' integration test.
Otherwise the application of our solution will be limited to Java 8.
-->
<excludes>
module-info.class
</excludes>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eolang</groupId>
<artifactId>jeo-maven-plugin</artifactId>
<version>${jeo.version}</version>
<executions>
<execution>
<id>bytecode-to-eo</id>
<goals>
<goal>disassemble</goal>
</goals>
<configuration>
<outputDir>${jeo.disassemble.output}</outputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eolang</groupId>
<artifactId>opeo-maven-plugin</artifactId>
<version>${opeo.version}</version>
<executions>
<execution>
<id>opeo-decompile</id>
<goals>
<goal>decompile</goal>
</goals>
<configuration>
<sourcesDir>${jeo.disassemble.output}</sourcesDir>
<outputDir>${opeo.decompile.output}</outputDir>
<modifiedDir>${opeo.modified}</modifiedDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eolang</groupId>
<artifactId>ineo-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>factorialize</goal>
</goals>
<configuration>
<sourcesDir>${opeo.decompile.output}</sourcesDir>
<outputDir>${ineo.factorialize.output}</outputDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
55 changes: 55 additions & 0 deletions src/it/factorial/src/main/java/org/eolang/benchmark/Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 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.benchmark;

/**
* Implementation of factorial using pure OOP approach.
* The methods in this class are going to be replaced by optimization.
* @since 0.2
*/
class Factorial {
/**
* Current value.
*/
private int d;

/**
* Constructor.
* @param d Value.
*/
Factorial(int d) {
this.d = d;
}

/**
* Get factorial.
* @return Factorial.
*/
public int get() {
if (d <= 1) {
return 1;
}
return new Factorial(d - 1).get() * d;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 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.benchmark;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Spring Application Entry Point.
* @since 0.2
*/
@SpringBootApplication
public class FactorialApplication {

/**
* Entry point for Factorial Spring Application.
* @param args Command line arguments.
*/
public static void main(String[] args) {
SpringApplication.run(FactorialApplication.class, args);
}

}
57 changes: 57 additions & 0 deletions src/it/factorial/src/main/java/org/eolang/benchmark/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 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.benchmark;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* Main class.
* We expect that the usage of Factorial objects in this class will be replaced.
* @since 0.2
*/
@RestController
public final class Main {

@GetMapping("/factorial")
public String factorial(
@RequestParam(value = "rounds", defaultValue = "1") String prounds,
@RequestParam(value = "value", defaultValue = "10") String pvalue
) {
long rounds = Long.parseLong(prounds);
int value = Integer.parseInt(pvalue);
long sum = 0L;
long start = System.currentTimeMillis();
for (long i = 0; i < rounds; ++i) {
sum += new Factorial(value).get();
}
final String response = String.format(
"sum=%d time=%d\n", sum, System.currentTimeMillis() - start
);
System.out.println(response);
return response;
}

}
26 changes: 26 additions & 0 deletions src/it/factorial/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 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.
*/

assert new File(basedir, 'target/generated-sources/ineo-factorialized-xmir/org/eolang/benchmark/Factorialized.xmir').exists()
assert new File(basedir, 'target/generated-sources/ineo-factorialized-xmir/org/eolang/benchmark/Main.xmir').exists()
Loading