Skip to content

Commit

Permalink
wip dev launch injector; wip netbeans
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolMineman committed Sep 20, 2021
1 parent 3a61318 commit d83d09a
Show file tree
Hide file tree
Showing 22 changed files with 2,437 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/testprogram/netbeans/NetbeansProject/nbproject/private/
/testmod/netbeans/NetbeansProject/nbproject/private/
5 changes: 5 additions & 0 deletions brachyura/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<artifactId>javacompilelib</artifactId>
<version>0.2</version>
</dependency>
<!-- <dependency>
<groupId>io.github.coolcrabs</groupId>
<artifactId>crabloader</artifactId>
<version>0.1</version>
</dependency> -->
<dependency>
<groupId>net.fabricmc</groupId>
<artifactId>mapping-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
public interface Ide {
public static Ide[] getIdes() {
return new Ide[] {
Vscode.INSTANCE
Vscode.INSTANCE,
Netbeans.INSTANCE
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static class RunConfigBuilder {
private String mainClass;
private Path cwd;
private List<String> vmArgs = Collections.emptyList();
public List<String> args = Collections.emptyList();
private List<String> args = Collections.emptyList();
private List<Path> classpath = Collections.emptyList();

public RunConfigBuilder name(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package io.github.coolcrabs.brachyura.ide;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import java.util.concurrent.ThreadLocalRandom;

import org.benf.cfr.reader.util.annotation.Nullable;
import org.tinylog.Logger;

import io.github.coolcrabs.brachyura.dependency.JavaJarDependency;
import io.github.coolcrabs.brachyura.util.AtomicDirectory;
import io.github.coolcrabs.brachyura.util.PathUtil;
import io.github.coolcrabs.brachyura.util.Util;

public enum Netbeans implements Ide {
INSTANCE;

static final Properties defaultProperties = new Properties();

static {
try {
try (InputStreamReader reader = new InputStreamReader(Netbeans.class.getResourceAsStream("/nb/nbdefault.properties"))) {
defaultProperties.load(reader);
}
} catch (Exception e) {
throw Util.sneak(e);
}
}

@Override
public String ideName() {
return "netbeans";
}

@Override
public void updateProject(Path projectDir, IdeProject ideProject) {
Path nb = PathUtil.resolveAndCreateDir(projectDir, "netbeans");
PathUtil.deleteDirectoryChildren(nb);
new NetbeansProject(nb.resolve("NetbeansProject"), ideProject).write();
}

static class NetbeansProject {
final Properties projectProperties = new Properties(defaultProperties);
final Path dir;

NetbeansProject(Path dir, IdeProject ideProject) {
if (ideProject.sourcePaths.size() != 1) throw new UnsupportedOperationException("Netbeans support for >1 source path not impl");
projectProperties.setProperty("src.dir", ideProject.sourcePaths.get(0).toString());
StringBuilder javacClasspath = new StringBuilder();
for (JavaJarDependency j : ideProject.dependencies) {
if (javacClasspath.length() > 0) javacClasspath.append(File.pathSeparator);
javacClasspath.append(createFileReference(j).getListString());
}
projectProperties.setProperty("javac.classpath", javacClasspath.toString());
this.dir = dir;
}

@SuppressWarnings("all")
void write() {
try {
try (AtomicDirectory d = new AtomicDirectory(dir)) {
cp(d.tempPath, "gamerbuild.xml");
cp(d.tempPath, "manifest.mf");
cp(d.tempPath, "nbproject", "build-impl.xml");
cp(d.tempPath, "nbproject", "genfiles.properties");
cp(d.tempPath, "nbproject", "project.xml");
try (OutputStream o = PathUtil.outputStream(d.tempPath.resolve("nbproject").resolve("project.properties"))) {
projectProperties.store(o, null);
}
d.commit();
}
} catch (Exception e) {
throw Util.sneak(e);
}
}

void cp(Path dir, String... p) throws IOException {
Path target = dir;
for (String p0 : p) {
target = target.resolve(p0);
}
Files.createDirectories(target.getParent());
try (InputStream is = Netbeans.class.getClassLoader().getResourceAsStream("nb/" + String.join("/", p))) {
Files.copy(is, target);
}
}

static class SourceSet {
@Nullable String name;
}

static class FileReference {
String property;
String getListString() {
return "${" + property + "}";
}
}

FileReference createFileReference(Path path, @Nullable Path source) {
FileReference result = new FileReference();
String fileName = path.getFileName().toString();
result.property = "file.reference." + fileName;
if (projectProperties.containsKey(result.property) && !projectProperties.getProperty(result.property).equals(path.toString())) {
Logger.warn("Duplicate file names for " + fileName);
fileName = String.valueOf(ThreadLocalRandom.current().nextLong());
result.property = "file.reference." + fileName;
}
projectProperties.setProperty(result.property, path.toString());
if (source != null) {
projectProperties.setProperty("source.reference." + fileName, source.toString());
}
return result;
}

FileReference createFileReference(JavaJarDependency dependency) {
return createFileReference(dependency.jar, dependency.sourcesJar);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw Util.sneak(e);
Expand Down
73 changes: 73 additions & 0 deletions brachyura/src/main/resources/nb/gamerbuild.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="JavaProject1" default="default" basedir=".">
<description>Builds, tests, and runs the project JavaProject1.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="JavaProject1-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
3 changes: 3 additions & 0 deletions brachyura/src/main/resources/nb/manifest.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

115 changes: 115 additions & 0 deletions brachyura/src/main/resources/nb/nbdefault.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=BrachyuraProject
application.vendor=brachyura
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
buildfile=gamerbuild.xml
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/BrachyuraProject.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/BrachyuraProject
endorsed.classpath=
excludes=
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=16
javac.target=16
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
# The jlink additional root modules to resolve
jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=BrachyuraProject
jnlp.codebase.type=no.codebase
jnlp.descriptor=application
jnlp.enabled=false
jnlp.mixed.code=default
jnlp.offline-allowed=false
jnlp.signed=false
jnlp.signing=
jnlp.signing.alias=
jnlp.signing.keystore=
main.class=
# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found.
manifest.custom.application.library.allowable.codebase=
# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts.
manifest.custom.caller.allowable.codebase=
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
manifest.custom.codebase=
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
Loading

0 comments on commit d83d09a

Please sign in to comment.