Skip to content

Commit

Permalink
Reading version into Java from pom properties
Browse files Browse the repository at this point in the history
Small improvements of the web page layout
Version 2.2.1
  • Loading branch information
cardillan committed Sep 30, 2024
1 parent 651f47f commit 25f72f3
Show file tree
Hide file tree
Showing 31 changed files with 409 additions and 405 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

All notable changes to this project will be documented in this file.

## 2.3.0 - unreleased
## 2.2.1 - 2024-09-30

### Fixed

* Fixed the layout of the web page not rendering well on smaller screens and mobile devices.

### Changed

* Changed the [Single Step Elimination optimization](doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown#single-step-elimination) to remove the last instruction if it jumps to the start of the program (not just `end`, but also unconditional jump) on `advanced` optimization level.


## 2.2.0 - 2024-09-29

### Fixed
Expand Down
8 changes: 2 additions & 6 deletions doc/syntax/MINDUSTRY-TIPS-N-TRICKS.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,11 @@ destroyed unit (as well as a destroyed building, actually) by querying the `dead
`false`) means the unit is alive, a value of `1` (or `true`) means it is, well, dead as a parrot.

When querying the `@unit.dead` property, you can possibly obtain three values
* `null` when no unit is actually bound,
* `0` when a unit is bound and alive,
* `1` when a unit is bound, but dead.

A single strict comparison (`===` or `!==`) can be used to recognize live unit from the other two alternatives.
An improved way to detect units no longer available to processor therefore is:
* `1` when a unit is not bound, or is dead.

```
if @unit.controller != @this or @unit.dead !== 0 then
if @unit.controller != @this or @unit.dead == 1 then
// We lost our unit. Immediatelly get a new one.
findFreeUnit(@mega, STATE_INIT);
end;
Expand Down
2 changes: 1 addition & 1 deletion doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ This optimizer simplifies the following sequences of jump that are a result of c

* A conditional or unconditional jump targeting the next instruction (such a jump is obviously unnecessary).
* A conditional or unconditional jump identical to the next instruction (unconditional jumps would be also eliminated by Unreachable Code Elimination, but that isn't true for conditional jumps).
* On the `advanced` level, the `end` instruction at the very end of the program is removed, as the processor will jump to the first instruction of the program upon reaching the end of the instruction list anyway.
* On the `advanced` level, the `end` and `jump 0 always` instructions at the very end of the program are removed, as the processor will jump to the first instruction of the program upon reaching the end of the instruction list anyway, saving one instruction.

## Expression Optimization

Expand Down
19 changes: 19 additions & 0 deletions mindcode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<propertiesEncoding>ISO-8859-1</propertiesEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -86,6 +94,17 @@
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</build>

<dependencies>
Expand Down
15 changes: 12 additions & 3 deletions mindcode/src/main/java/info/teksol/mindcode/Version.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package info.teksol.mindcode;

public class Version {
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

private static final String VERSION = "2.2.0";
public class Version {

public static String getVersion() {
return VERSION;
try (InputStream in = Version.class.getResourceAsStream("mindcode.properties")) {
final Properties properties = new Properties();
properties.load(in);
return properties.getProperty("mindcode.version");
}
catch (IOException e) {
throw new RuntimeException("Error obtaining version information", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Version
mindcode.version = ${revision}
13 changes: 13 additions & 0 deletions mindcode/src/test/java/info/teksol/mindcode/VersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package info.teksol.mindcode;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

class VersionTest {

@Test
void readsVersion() {
assertDoesNotThrow(Version::getVersion);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.5.RELEASE</spring.version>
<revision>2.2.0</revision>
<revision>2.2.1</revision>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.time.Instant;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import java.util.stream.Collectors;

import static info.teksol.mindcode.compiler.CompilerFacade.compile;

Expand All @@ -30,41 +30,28 @@ public class HomeController {
private static final Map<String, String> samples;

static {
final Map<String, String> theSamples = new HashMap<>();
final List<String> sampleNames = List.of(
"control-two-units",
"one-thorium",
"heal-damaged-building",
"many-thorium",
"mine-coord",
"heal-damaged-building",
"mining-drone",
"upgrade-conveyors",
"sum-of-primes"
);

final List<String> sources = Stream.of(
"1-control-units-using-variables.mnd",
"2-thorium-reactor-stopper.mnd",
"8-heal-damaged-building.mnd",
"3-multi-thorium-reactor.mnd",
"5-mining-drone.mnd",
"6-upgrade-copper-conveyors-to-titanium.mnd",
"compute-sum-of-primes.mnd"
).map((filename) -> {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(HomeController.class.getClassLoader().getResourceAsStream("samples/mindcode/" + filename)))) {
final StringWriter out = new StringWriter();
reader.transferTo(out);
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Failed to read sample: " + filename);
}
})
.toList();

for (int i = 0; i < sampleNames.size(); i++) {
theSamples.put(sampleNames.get(i), sources.get(i));
}
samples = sampleNames.stream().collect(Collectors.toMap(s -> s, HomeController::loadSample));
}

samples = theSamples;
private static String loadSample(String sampleName) {
try (final BufferedReader reader = new BufferedReader(
new InputStreamReader(HomeController.class.getClassLoader().getResourceAsStream("samples/mindcode/" + sampleName + ".mnd")))) {
final StringWriter out = new StringWriter();
reader.transferTo(out);
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Failed to read sample: " + sampleName);
}
}

private final Random random = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.Instant;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Controller
@RequestMapping(value = "/schematics")
Expand All @@ -30,7 +31,6 @@ public class SchematicsController {
private static final List<String> quickSamples;

static {
final Map<String, String> theSamples = new HashMap<>();
final List<String> sampleNames = List.of(
"detector",
"healing-center",
Expand All @@ -42,26 +42,21 @@ public class SchematicsController {
"slow:mandelbrot-generator"
);

final List<String> sources = sampleNames.stream()
samples = sampleNames.stream()
.map(s -> s.replace("slow:", ""))
.map(s -> s.concat(".sdf"))
.map((filename) -> {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(SchematicsController.class.getClassLoader().getResourceAsStream("samples/schematics/" + filename)))) {
final StringWriter out = new StringWriter();
reader.transferTo(out);
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Failed to read schematic sample: " + filename);
}
})
.toList();
.collect(Collectors.toMap(s -> s, SchematicsController::loadSample));
quickSamples = sampleNames.stream().filter(s -> !s.startsWith("slow:")).toList();
}

for (int i = 0; i < sampleNames.size(); i++) {
theSamples.put(sampleNames.get(i).replace("slow:", ""), sources.get(i));
private static String loadSample(String sampleName) {
try (final BufferedReader reader = new BufferedReader(
new InputStreamReader(SchematicsController.class.getClassLoader().getResourceAsStream("samples/schematics/" + sampleName + ".sdf")))) {
final StringWriter out = new StringWriter();
reader.transferTo(out);
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Failed to read sample: " + sampleName);
}

samples = theSamples;
quickSamples = sampleNames.stream().filter(s -> !s.startsWith("slow:")).toList();
}

private final Random random = new Random();
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion webapp/src/main/resources/samples/mindcode/4-demo.mnd

This file was deleted.

40 changes: 0 additions & 40 deletions webapp/src/main/resources/samples/mindcode/7-bind-one-unit.mnd

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions webapp/src/main/resources/samples/mindcode/9-function-decl.mnd

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Binds two different units, stores them in a variable
// and controls both them (moves them around in a pattern)
// Binds two different units, stores them in variables and controls
// both them simultaneously by moving them around in a pattern

// These are local variables
poly = ubind(@poly); // We just assume the units exist
mega = ubind(@mega);
poly = ubind(@poly); // We just assume the unit exists
mega = ubind(@mega); // dtto

// This is a global variable
ANGLE = 0;
Expand Down
Loading

0 comments on commit 25f72f3

Please sign in to comment.