jps-bootstrap initial commit

this is a utility to run any main class from intellij project.
it incrementally compiles Java/Kotlin/Groovy code and runs main class from specified module

GitOrigin-RevId: 0a095bfe8d64fe9c0b031ae142612b56d69049c8
This commit is contained in:
Leonid Shalupov
2021-08-22 23:25:48 +03:00
committed by intellij-monorepo-bot
parent f0c087f452
commit 7c7e1a1c57
12 changed files with 561 additions and 0 deletions

3
platform/jps-bootstrap/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/target
/classpath.pathlist
/out

8
platform/jps-bootstrap/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
platform/jps-bootstrap/.idea/ant.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<buildFile url="file://$PROJECT_DIR$/jps-bootstrap-classpath.xml" />
</component>
</project>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="jps-bootstrap" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$APPLICATION_HOME_DIR$/bin/src/main/java" charset="UTF-8" />
<file url="file://$APPLICATION_HOME_DIR$/bin/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="intellij-dependencies" />
<option name="name" value="intellij-dependencies" />
<option name="url" value="https://cache-redirector.jetbrains.com/intellij-dependencies" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="kotlin-ide-plugin-dependencies" />
<option name="name" value="kotlin-ide-plugin-dependencies" />
<option name="url" value="https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies" />
</remote-repository>
</component>
</project>

14
platform/jps-bootstrap/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="corretto-11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
platform/jps-bootstrap/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,128 @@
<!-- Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<project name="Prepare classpath for jps bootstrap" xmlns:resolver="antlib:org.apache.maven.resolver.ant" default="jps-bootstrap-classpath">
<dirname property="jps.bootstrap.dir" file="${ant.file}"/>
<property name="community.home" value="${jps.bootstrap.dir}/../.."/>
<property name="build.dir" value="${community.home}/out/jps-bootstrap" />
<property name="classes.dir" value="${build.dir}/jps-bootstrap.classes" />
<property name="uber.jar" value="${build.dir}/jps-bootstrap-all.jar" />
<property name="m2.dir" value="${build.dir}/m2" />
<property environment="env"/>
<property prefix="dependencies" file="${community.home}/build/dependencies/gradle.properties" />
<mkdir dir="${build.dir}" />
<property name="maven.resolver.ant.tasks.version" value="1.2.1"/>
<property name="maven.resolver.ant.tasks.file.name" value="maven-resolver-ant-tasks-${maven.resolver.ant.tasks.version}-uber.jar"/>
<property name="maven.resolver.ant.tasks.file.path" value="${build.dir}/${maven.resolver.ant.tasks.file.name}"/>
<available file="${maven.resolver.ant.tasks.file.path}" property="maven.resolver.ant.tasks.file.exists"/>
<xmlproperty file="${community.home}/.idea/libraries/kotlinc_kotlin_compiler.xml" prefix="kotlinc.library.xml"/>
<loadresource property="kotlin.channel">
<string value="${dependencies.kotlinCompilerBuild}" />
<filterchain>
<tokenfilter>
<replaceregex pattern="^.*:([a-zA-Z\-0-9.]+)$" replace="\1"/>
</tokenfilter>
</filterchain>
</loadresource>
<loadresource property="kotlin.version">
<string value="${dependencies.kotlinCompilerBuild}" />
<filterchain>
<tokenfilter>
<replaceregex pattern="^([a-zA-Z\-0-9.]+):.*$" replace="\1"/>
</tokenfilter>
</filterchain>
</loadresource>
<property name="kotlin.home" value="${build.dir}/kotlin" />
<property name="kotlin.url" value="https://cache-redirector.jetbrains.com/plugins.jetbrains.com/maven/${kotlin.channel}/com/jetbrains/plugins/org.jetbrains.kotlin/${kotlin.version}/org.jetbrains.kotlin-${kotlin.version}.zip" />
<condition property="kotlin.home.ok">
<resourcecontains resource="${kotlin.home}/.flag" substring="${kotlin.url}"/>
</condition>
<target name="download.and.extract.kotlin" unless="kotlin.home.ok">
<echo message="Downloading Kotlin ${kotlin.version} channel ${kotlin.channel} to ${kotlin.home}" />
<delete dir="${kotlin.home}" />
<mkdir dir="${kotlin.home}" />
<get src="${kotlin.url}" dest="${kotlin.home}/kotlin.zip" />
<unzip src="${kotlin.home}/kotlin.zip" dest="${kotlin.home}" />
<delete file="${kotlin.home}/kotlin.zip" />
<echo file="${kotlin.home}/.flag" message="${kotlin.url}" />
</target>
<target name="download.resolver" unless="maven.resolver.ant.tasks.file.exists">
<get
src="https://cache-redirector.jetbrains.com/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-ant-tasks/${maven.resolver.ant.tasks.version}/maven-resolver-ant-tasks-${maven.resolver.ant.tasks.version}-uber.jar"
dest="${maven.resolver.ant.tasks.file.path}.tmp"
verbose="true"/>
<move
file="${maven.resolver.ant.tasks.file.path}.tmp"
tofile="${maven.resolver.ant.tasks.file.path}"
overwrite="true"/>
</target>
<target name="jps-bootstrap-classpath" depends="download.resolver,download.and.extract.kotlin">
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml"
classpath="${maven.resolver.ant.tasks.file.path}"/>
<resolver:remoterepos id="remoterepos.buildscript">
<resolver:remoterepo id="central" url="https://cache-redirector.jetbrains.com/repo1.maven.org/maven2"/>
<resolver:remoterepo id="intellij-dependencies" url="https://cache-redirector.jetbrains.com/intellij-dependencies"/>
<resolver:remoterepo id="kotlin-ide-plugin-dependencies" url="https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies"/>
</resolver:remoterepos>
<resolver:pom file="${jps.bootstrap.dir}/pom.xml" id="jps.bootstrap.pom"/>
<resolver:resolve failOnMissingAttachments="true">
<resolver:localrepo dir="${m2.dir}" />
<resolver:remoterepos refid="remoterepos.buildscript"/>
<resolver:dependencies pomRef="jps.bootstrap.pom" />
<resolver:path refid="classpath.buildscripts" classpath="runtime"/>
</resolver:resolve>
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />
<javac
srcdir="${jps.bootstrap.dir}/src/main/java"
destdir="${classes.dir}"
encoding="UTF-8"
release="11"
includeantruntime="false"
classpathref="classpath.buildscripts"
/>
<path id="whole.classpath.id" cache="true">
<path refid="classpath.buildscripts" />
<pathelement path="${kotlin.home}/Kotlin/lib/jps/kotlin-jps-plugin.jar" />
<pathelement path="${kotlin.home}/Kotlin/lib/kotlin-jps-common.jar" />
<pathelement path="${kotlin.home}/Kotlin/lib/kotlin-plugin.jar" />
<pathelement path="${kotlin.home}/Kotlin/lib/kotlin-common.jar" />
<pathelement path="${kotlin.home}/Kotlin/lib/kotlin-reflect.jar" />
</path>
<pathconvert pathsep="${path.separator}" property="whole.classpath.property" refid="whole.classpath.id"/>
<echo file="${build.dir}/classpath.pathlist" message="&quot;${whole.classpath.property}${path.separator}${classes.dir}&quot;" />
<echo message="JpsBootstrapMain classpath: see ${build.dir}/classpath.pathlist" />
</target>
<target name="jps-bootstrap-all-jar" depends="jps-bootstrap-classpath">
<delete dir="${build.dir}/libs"/>
<mkdir dir="${build.dir}/libs"/>
<copy todir="${build.dir}/libs" flatten="true">
<path refid="whole.classpath.id" />
</copy>
<jar destfile="${uber.jar}" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="JpsBootstrapMain"/>
</manifest>
<zipgroupfileset dir="${build.dir}/libs"/>
</jar>
</target>
</project>

View File

@@ -0,0 +1,106 @@
#!/bin/sh
# Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
set -eu
JPS_BOOTSTRAP_DIR="$(cd "$(dirname "$0")"; pwd)"
COMMUNITY_HOME="$(cd "$JPS_BOOTSTRAP_DIR/../.."; pwd)"
JPS_BOOTSTRAP_WORK_DIR=${JPS_BOOTSTRAP_WORK_DIR:-$COMMUNITY_HOME/out/jps-bootstrap}
SCRIPT_VERSION=jps-bootstrap-cmd-v1
warn () {
echo "$@"
}
die () {
echo 2>&1
echo "$@" 2>&1
echo 2>&1
exit 1
}
darwin=false
case "$(uname)" in
Darwin* )
darwin=true
;;
esac
if [ "$darwin" = "true" ]; then
case $(uname -m) in
x86_64)
JVM_URL=https://corretto.aws/downloads/resources/11.0.9.12.1/amazon-corretto-11.0.9.12.1-macosx-x64.tar.gz
JVM_TARGET_DIR="$JPS_BOOTSTRAP_WORK_DIR/jvm/amazon-corretto-11.0.9.12.1-macosx-x64-$SCRIPT_VERSION"
;;
arm64)
JVM_URL=https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz
JVM_TARGET_DIR="$JPS_BOOTSTRAP_WORK_DIR/jvm/zulu-11.0.10-macosx-arm64-$SCRIPT_VERSION"
;;
*)
die "Unknown architecture $(uname -m)"
;;
esac
else
case $(uname -m) in
x86_64)
JVM_URL=https://corretto.aws/downloads/resources/11.0.9.12.1/amazon-corretto-11.0.9.12.1-linux-x64.tar.gz
JVM_TARGET_DIR="$JPS_BOOTSTRAP_WORK_DIR/jvm/amazon-corretto-11.0.9.12.1-linux-x64-$SCRIPT_VERSION"
;;
aarch64)
JVM_URL=https://corretto.aws/downloads/resources/11.0.9.12.1/amazon-corretto-11.0.9.12.1-linux-aarch64.tar.gz
JVM_TARGET_DIR="$JPS_BOOTSTRAP_WORK_DIR/jvm/amazon-corretto-11.0.9.12.1-linux-aarch64-$SCRIPT_VERSION"
;;
*)
die "Unknown architecture $(uname -m)"
;;
esac
fi
mkdir -p "$JPS_BOOTSTRAP_WORK_DIR/jvm"
if [ -e "$JVM_TARGET_DIR/.flag" ] && [ -n "$(ls "$JVM_TARGET_DIR")" ] && [ "x$(cat "$JVM_TARGET_DIR/.flag")" = "x${JVM_URL}" ]; then
# Everything is up-to-date in $JVM_TARGET_DIR, do nothing
true
else
warn "Downloading $JVM_URL to $JVM_TEMP_FILE"
JVM_TEMP_FILE=$(mktemp "$JPS_BOOTSTRAP_WORK_DIR/jvm.tar.gz.XXXXXXXXX")
trap 'echo "Removing $JVM_TEMP_FILE"; rm -f "$JVM_TEMP_FILE"; trap - EXIT' EXIT INT HUP
if command -v curl >/dev/null 2>&1; then
if [ -t 1 ]; then CURL_PROGRESS="--progress-bar"; else CURL_PROGRESS="--silent --show-error"; fi
curl $CURL_PROGRESS --output "${JVM_TEMP_FILE}" "$JVM_URL"
elif command -v wget >/dev/null 2>&1; then
if [ -t 1 ]; then WGET_PROGRESS=""; else WGET_PROGRESS="-nv"; fi
wget $WGET_PROGRESS -O "${JVM_TEMP_FILE}" "$JVM_URL"
else
die "ERROR: Please install wget or curl"
fi
warn "Extracting $JVM_TEMP_FILE to $JVM_TARGET_DIR"
rm -rf "$JVM_TARGET_DIR"
mkdir -p "$JVM_TARGET_DIR"
tar -x -f "$JVM_TEMP_FILE" -C "$JVM_TARGET_DIR"
rm -f "$JVM_TEMP_FILE"
echo "$JVM_URL" >"$JVM_TARGET_DIR/.flag"
fi
JAVA_HOME=
for d in "$JVM_TARGET_DIR" "$JVM_TARGET_DIR"/* "$JVM_TARGET_DIR/Contents/Home" "$JVM_TARGET_DIR/"*/Contents/Home; do
if [ -e "$d/bin/java" ]; then
JAVA_HOME="$d"
fi
done
if [ ! -e "$JAVA_HOME/bin/java" ]; then
die "Unable to find bin/java under $JVM_TARGET_DIR"
fi
set -x
"$JAVA_HOME/bin/java" -jar "$COMMUNITY_HOME/lib/ant/lib/ant-launcher.jar" -f "$JPS_BOOTSTRAP_DIR/jps-bootstrap-classpath.xml"
exec "$JAVA_HOME/bin/java" -classpath "@$JPS_BOOTSTRAP_WORK_DIR/classpath.pathlist" JpsBootstrapMain "$@"

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.jps-bootstrap</groupId>
<artifactId>jps-bootstrap</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.release>11</maven.compiler.release>
<bootstrap.intellij.version>213.2547</bootstrap.intellij.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.jetbrains.intellij.platform</groupId>
<artifactId>jps-model</artifactId>
<version>${bootstrap.intellij.version}</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.platform</groupId>
<artifactId>jps-model-impl</artifactId>
<version>${bootstrap.intellij.version}</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.platform</groupId>
<artifactId>jps-model-serialization</artifactId>
<version>${bootstrap.intellij.version}</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.tools</groupId>
<artifactId>jps-build-standalone</artifactId>
<version>${bootstrap.intellij.version}</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.groovy</groupId>
<artifactId>groovy-jps</artifactId>
<version>${bootstrap.intellij.version}</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.groovy</groupId>
<artifactId>groovy-rt</artifactId>
<version>${bootstrap.intellij.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>intellij-dependencies</id>
<url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
</repository>
<repository>
<id>kotlin-ide-plugin-dependencies</id>
<url>https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies</url>
</repository>
</repositories>
</project>

View File

@@ -0,0 +1,167 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.URLUtil;
import org.jetbrains.groovy.compiler.rt.GroovyRtConstants;
import org.jetbrains.jps.api.GlobalOptions;
import org.jetbrains.jps.build.Standalone;
import org.jetbrains.jps.incremental.groovy.JpsGroovycRunner;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator;
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.serialization.JpsModelSerializationDataService;
import org.jetbrains.jps.model.serialization.JpsPathVariablesConfiguration;
import org.jetbrains.jps.model.serialization.JpsProjectLoader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "SameParameterValue"})
public class JpsBootstrapMain {
private static final String PROJECT_HOME_ENV = "JPS_BOOTSTRAP_PROJECT_HOME";
@SuppressWarnings("ConfusingArgumentToVarargsMethod")
public static void main(String[] args) throws Throwable {
long startTime = System.currentTimeMillis();
String projectHomeString = System.getenv(PROJECT_HOME_ENV);
if (projectHomeString == null) {
System.err.println("Please set " + PROJECT_HOME_ENV + " environment variable");
System.exit(1);
}
Path projectHome = Path.of(projectHomeString);
Path buildDir = projectHome.resolve("out").resolve("jps-bootstrap");
JpsModel model = JpsElementFactory.getInstance().createModel();
JpsPathVariablesConfiguration pathVariablesConfiguration =
JpsModelSerializationDataService.getOrCreatePathVariablesConfiguration(model.getGlobal());
pathVariablesConfiguration.addPathVariable(
"MAVEN_REPOSITORY",
FileUtilRt.toSystemIndependentName(buildDir.resolve("m2").toAbsolutePath().toString()));
System.setProperty("kotlin.incremental.compilation", "true");
System.setProperty(GlobalOptions.COMPILE_PARALLEL_OPTION, "true");
Map<String, String> pathVariables = JpsModelSerializationDataService.computeAllPathVariables(model.getGlobal());
JpsProjectLoader.loadProject(model.getProject(), pathVariables, projectHome.toString());
System.out.println(
"Loaded project " + projectHome + ": " +
model.getProject().getModules().size() + " modules, " +
model.getProject().getLibraryCollection().getLibraries().size() + " libraries in " +
(System.currentTimeMillis() - startTime) + " ms");
long buildStart = System.currentTimeMillis();
addSdk(model, "corretto-11", System.getProperty("java.home"));
String url = "file://" + FileUtilRt.toSystemIndependentName(buildDir.resolve("out").toString());
JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(model.getProject()).setOutputUrl(url);
System.setProperty(JpsGroovycRunner.GROOVYC_IN_PROCESS, "true");
System.setProperty(GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY, "false");
System.setProperty(GlobalOptions.USE_DEFAULT_FILE_LOGGING_OPTION, "true");
System.setProperty(GlobalOptions.LOG_DIR_OPTION, buildDir.resolve("log").toString());
System.out.println("Log: " + System.getProperty(GlobalOptions.LOG_DIR_OPTION));
JpsModule module = model.getProject().getModules()
.stream()
.filter(m -> "intellij.idea.community.build".equals(m.getName()))
.findFirst().orElseThrow();
final boolean[] errors = {false};
Path dataStorageRoot = buildDir.resolve("jps-build-data");
Standalone.runBuild(
() -> model,
dataStorageRoot.toFile(),
false,
// setOf("intellij.platform.util"),
ContainerUtil.set(module.getName()),
false,
Collections.emptyList(),
false,
msg -> {
BuildMessage.Kind kind = msg.getKind();
//if (kind == BuildMessage.Kind.ERROR || kind == BuildMessage.Kind.INTERNAL_BUILDER_ERROR || kind == BuildMessage.Kind.PROGRESS) {
if (kind == BuildMessage.Kind.ERROR || kind == BuildMessage.Kind.INTERNAL_BUILDER_ERROR) {
System.out.println(kind + " " + msg.getMessageText());
}
if (kind == BuildMessage.Kind.ERROR || kind == BuildMessage.Kind.INTERNAL_BUILDER_ERROR) {
errors[0] = true;
}
}
);
System.out.println("Finished build in " + (System.currentTimeMillis() - buildStart) + " ms");
if (errors[0]) {
System.err.println("Build finished with errors");
System.exit(1);
}
JpsJavaDependenciesEnumerator enumerator = JpsJavaExtensionService
.dependencies(module)
.runtimeOnly()
.productionOnly()
.recursively()
.withoutSdk();
List<URL> roots = new ArrayList<>();
for (File file : enumerator.classes().getRoots()) {
URL toURL = file.toURI().toURL();
roots.add(toURL);
}
try (URLClassLoader classloader = new URLClassLoader(roots.toArray(new URL[0]), ClassLoader.getSystemClassLoader())) {
Class<?> mainClass = classloader.loadClass("org.jetbrains.intellij.build.ExampleGroovyMain");
MethodHandles.lookup()
.findStatic(mainClass, "main", MethodType.methodType(Void.TYPE, String[].class))
.invokeExact(args);
}
}
private static List<String> readModulesFromReleaseFile(Path jdkDir) throws IOException {
Path releaseFile = jdkDir.resolve("release");
Properties p = new Properties();
try (InputStream is = Files.newInputStream(releaseFile)) {
p.load(is);
}
String jbrBaseUrl = URLUtil.JRT_PROTOCOL + URLUtil.SCHEME_SEPARATOR +
FileUtil.toSystemIndependentName(jdkDir.toFile().getAbsolutePath()) +
URLUtil.JAR_SEPARATOR;
String modules = p.getProperty("MODULES");
return ContainerUtil.map(StringUtil.split(StringUtil.unquoteString(modules), " "), s -> jbrBaseUrl + s);
}
private static void addSdk(JpsModel model, String sdkName, String sdkHome) throws IOException {
JpsJavaExtensionService.getInstance().addJavaSdk(model.getGlobal(), sdkName, sdkHome);
JpsLibrary additionalSdk = model.getGlobal().getLibraryCollection().findLibrary(sdkName);
if (additionalSdk == null) {
throw new IllegalStateException("SDK " + sdkHome + " was not found");
}
for (String moduleUrl : readModulesFromReleaseFile(Path.of(sdkHome))) {
additionalSdk.addRoot(moduleUrl, JpsOrderRootType.COMPILED);
}
}
}