Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Commit

Permalink
Merge github.com:CoolCrabs/brachyura
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolykt committed Aug 30, 2022
2 parents 36cb1f1 + 10e2f2a commit caa3f9e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion brachyura/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.coolcrabs</groupId>
<artifactId>brachyura</artifactId>
<version>0.91.0</version>
<version>0.92.0</version>

<properties>
<java.version>1.8</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -45,9 +50,42 @@ protected String getProjectName() {
if (concreteBuildscriptInstance instanceof DescriptiveBuildscriptName) {
ideBuildscriptName = ((DescriptiveBuildscriptName) concreteBuildscriptInstance).getBuildscriptName();
}
} else if (properties.get().containsKey("name")) {
ideBuildscriptName = "BScript-" + properties.get().getProperty("name");
}
return ideBuildscriptName;
}
// Slbrachyura end

public final Lazy<Properties> properties = new Lazy<>(this::createProperties);

Properties createProperties() {
try {
Path file = getProjectDir().resolve("buildscript.properties");
Properties properties0 = new Properties();
if (Files.exists(file)) {
try (BufferedReader r = Files.newBufferedReader(file)) {
properties0.load(r);
}
} else {
Logger.info("Didn't find buildscript.properties; autogenerating it.");
// properties0.setProperty("name", super.getProjectDir().getFileName().toString()); // Slbrachyura: We use our own buildscript name system
properties0.setProperty("javaVersion", "8");
try (BufferedWriter w = Files.newBufferedWriter(file)) {
properties0.store(w, "Brachyura Buildscript Properties");
}
}
return properties0;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

String getPropOrThrow(String property) {
String r = properties.get().getProperty(property);
if (r == null) throw new RuntimeException("Missing property " + property + " in buildscript.properties");
return r;
}

@Override
@NotNull
Expand All @@ -59,7 +97,7 @@ public IdeModule[] getIdeModules() {
if (buildscriptInstance.isPresent()) {
tasks.addAll(buildscriptInstance.get().getTasks());
}
// Slbrachyura end
int javaVersion = Integer.parseInt(getPropOrThrow("javaVersion"));

return new @NotNull IdeModule[] {
new IdeModule.IdeModuleBuilder()
Expand All @@ -68,8 +106,10 @@ public IdeModule[] getIdeModules() {
.sourcePath(getSrcDir())
.dependencies(this::getIdeDependencies)
.withTasks(tasks)
.javaVersion(javaVersion)
.build()
};
// Slbrachyura end
}

public final Lazy<Optional<Project>> project = new Lazy<>(this::createProject);
Expand All @@ -96,11 +136,12 @@ public Optional<Project> createProject() {
}

public ClassLoader getBuildscriptClassLoader() {
int javaVersion = Integer.parseInt(getPropOrThrow("javaVersion"));
try {
JavaCompilationResult compilation = new JavaCompilation()
.addSourceDir(getSrcDir())
.addClasspath(getCompileDependencies())
.addOption(JvmUtil.compileArgs(JvmUtil.CURRENT_JAVA_VERSION, 8)) // TODO: Make configurable - somehow
.addOption(JvmUtil.compileArgs(JvmUtil.CURRENT_JAVA_VERSION, javaVersion))
.compile();
BuildscriptClassloader r = new BuildscriptClassloader(BuildscriptProject.class.getClassLoader());
compilation.getInputs(r);
Expand Down

0 comments on commit caa3f9e

Please sign in to comment.