Skip to content

Commit

Permalink
replaced use of lib scheme and removed superfluous code that created …
Browse files Browse the repository at this point in the history
…big classpaths for the JVM which were then again constructed inside of the REPL by PathConfig calling into mvn
  • Loading branch information
jurgenvinju committed Sep 25, 2024
1 parent db04934 commit 2d4c7bb
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 94 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.40.7</version>
<version>0.40.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.rascalmpl</groupId>
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/org/rascalmpl/maven/CompileRascalDocumentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -68,6 +69,9 @@ public class CompileRascalDocumentation extends AbstractMojo
@Parameter(property = "bin", required = true, defaultValue = "${project.build.outputDirectory}")
private String bin;

@Parameter(property = "generatedSources", required = true, defaultValue = "${project.build}/generatedSources")
private String generatedSources;

@Parameter(property = "srcs", required = true )
private List<String> srcs;

Expand Down Expand Up @@ -126,10 +130,10 @@ private Evaluator makeEvaluator(OutputStream err, OutputStream out) throws URISy
public void execute() throws MojoExecutionException {
try {
ISourceLocation binLoc = URIUtil.getChildLocation(MojoUtils.location(bin), "docs");
ISourceLocation generatedSourcesLoc = URIUtil.getChildLocation(MojoUtils.location(generatedSources), "docs");
List<ISourceLocation> srcLocs = MojoUtils.locations(srcs);
List<ISourceLocation> libLocs = MojoUtils.locations(libs);
List<ISourceLocation> ignoredLocs = MojoUtils.locations(ignores);
List<ISourceLocation> classpath = collectClasspath();

if (System.getProperty("rascal.documentation.skip") != null
|| System.getProperty("rascal.tutor.skip") != null) {
Expand All @@ -151,11 +155,7 @@ public void execute() throws MojoExecutionException {
getLog().info("\tregistered library location: " + lib);
}

// the compiler classpath (for generated parser compilation) is based on the classpath for the compiler itself,
// rather than what it is compiling currently.
List<ISourceLocation> compilerClassPath = collectPluginClasspath();

PathConfig pcfg = new PathConfig(srcLocs, libLocs, binLoc, ignoredLocs, compilerClassPath, classpath);
PathConfig pcfg = new PathConfig(srcLocs, libLocs, binLoc, ignoredLocs, generatedSourcesLoc, Collections.emptyList());

getLog().info("Paths have been configured: " + pcfg);

Expand Down Expand Up @@ -223,15 +223,6 @@ private List<ISourceLocation> collectClasspath() throws URISyntaxException {
return builder;
}

private List<ISourceLocation> collectPluginClasspath() throws URISyntaxException {
List<ISourceLocation> builder = new LinkedList<>();

builder.add(MojoUtils.location(IValue.class.getProtectionDomain().getCodeSource().getLocation().getPath()));
builder.add(MojoUtils.location(Evaluator.class.getProtectionDomain().getCodeSource().getLocation().getPath()));

return builder;
}

private IList runCompiler(IRascalMonitor monitor, IEvaluator<Result<IValue>> eval, PathConfig pcfg) throws URISyntaxException, IOException {
try {
IConstructor pc = pcfg.asConstructor();
Expand Down Expand Up @@ -261,7 +252,9 @@ private IList runCompiler(IRascalMonitor monitor, IEvaluator<Result<IValue>> eva
try {
eval.getStdErr().flush();
eval.getStdOut().flush();
} catch (IOException ignored) {
}
catch (IOException ignored) {
// this is ok
}
}
}
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/org/rascalmpl/maven/CompileRascalMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -79,21 +80,30 @@
* compiler instead of the source code of the compiler inside the Rascal interpreter.
*
*/
@Mojo(name="compile", inheritByDefault=false, defaultPhase = LifecyclePhase.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
@Mojo(name="compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class CompileRascalMojo extends AbstractMojo
{
private static final String UNEXPECTED_ERROR = "unexpected error during Rascal compiler run";
private static final String MAIN_COMPILER_MODULE = "lang::rascalcore::check::Checker";
private static final String COMPILER_CONFIG_MODULE = "lang::rascalcore::check::RascalConfig";

private static final ISourceLocation[] MAIN_COMPILER_SEARCH_PATH = new ISourceLocation[] {
URIUtil.correctLocation("lib", "typepal", ""),
URIUtil.correctLocation("lib", "rascal-core", "")
};
private static final ISourceLocation[] MAIN_COMPILER_SEARCH_PATH;

private static final URIResolverRegistry reg = URIResolverRegistry.getInstance();
private static final IValueFactory VF = ValueFactoryFactory.getValueFactory();


static {
try {
MAIN_COMPILER_SEARCH_PATH= new ISourceLocation[] {
PathConfig.resolveProjectOnClasspath("typepal"),
PathConfig.resolveProjectOnClasspath("rascal-core")
};
}
catch (IOException e) {
throw new RuntimeException(e);
}
}

@Parameter(defaultValue="${project}", readonly=true, required=true)
private MavenProject project;

Expand All @@ -104,7 +114,7 @@ public class CompileRascalMojo extends AbstractMojo
private String resources;

// generatedSources
@Parameter(defaultValue = "${project.basedir}/generated-sources", property = "generatedSources", required = true)
@Parameter(defaultValue = "${project.build}/generatedSources", property = "generatedSources", required = true)
private String generatedSources;

@Parameter(property = "srcs", required = true )
Expand Down Expand Up @@ -203,8 +213,7 @@ public void execute() throws MojoExecutionException {

getLog().info("Paths have been configured.");

PathConfig pcfg = new PathConfig(srcLocs, libLocs, binLoc);

PathConfig pcfg = new PathConfig(srcLocs, libLocs, binLoc, ignoredLocs, generatedSourcesLoc);

IList messages = runChecker(verbose, todoList, pcfg, resourcesLoc, generatedSourcesLoc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.rascalmpl.library.util.PathConfig;

/**
* Maven Goal for running local Rascal programs during the maven generate-source phase.
Expand All @@ -48,19 +49,19 @@ public void execute() throws MojoExecutionException {
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
getLog().info("Using " + javaBin + " as java process for nested jvm call");

List<String> command = new LinkedList<String>();
command.add(javaBin);
try {
List<String> command = new LinkedList<String>();
command.add(javaBin);

System.getProperties().forEach((key, value) -> {
command.add("-D" + key + "=" + value);
});

command.add("-cp");
command.add(collectClasspath());
command.add("org.rascalmpl.shell.RascalShell");
command.add(mainModule);
System.getProperties().forEach((key, value) -> {
command.add("-D" + key + "=" + value);
});
command.add("-cp");
command.add(PathConfig.resolveCurrentRascalRuntimeJar().getPath());
command.add("org.rascalmpl.shell.RascalShell");
command.add(mainModule);

try {
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(project.getBasedir());
Process process = builder.inheritIO().start();
Expand All @@ -77,16 +78,4 @@ public void execute() throws MojoExecutionException {
}
finally {}
}

private String collectClasspath() {
StringBuilder builder = new StringBuilder();

for (Artifact a : project.getArtifacts()) {
File file = a.getFile().getAbsoluteFile();
getLog().debug("Adding " + file + " to classpath");
builder.append(File.pathSeparator + file.getAbsolutePath());
}

return builder.toString().substring(1);
}
}
18 changes: 14 additions & 4 deletions src/main/java/org/rascalmpl/maven/PackageRascalMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.library.util.PathConfig;
import org.rascalmpl.uri.URIUtil;
import org.rascalmpl.values.ValueFactoryFactory;
import io.usethesource.vallang.IList;
Expand All @@ -43,10 +44,19 @@
public class PackageRascalMojo extends AbstractMojo
{
private static final String MAIN_PACKAGER_MODULE = "lang::rascalcore::package::Packager";
private static final ISourceLocation[] MAIN_PACKAGER_SEARCH_PATH = new ISourceLocation[] {
URIUtil.correctLocation("lib", "typepal", ""),
URIUtil.correctLocation("lib", "rascal-core", "")
};
private static final ISourceLocation[] MAIN_PACKAGER_SEARCH_PATH;

static {
try {
MAIN_PACKAGER_SEARCH_PATH = new ISourceLocation[] {
PathConfig.resolveProjectOnClasspath("typepal"),
PathConfig.resolveProjectOnClasspath("rascal-core")
};
}
catch (IOException e) {
throw new RuntimeException(e);
}
}

@Parameter(defaultValue="${project}", readonly=true, required=true)
private MavenProject project;
Expand Down
53 changes: 12 additions & 41 deletions src/main/java/org/rascalmpl/maven/RascalConsoleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.rascalmpl.library.util.PathConfig;

/**
* Maven Goal for starting a rascal console for the current mvn project.
Expand All @@ -37,18 +38,18 @@ public void execute() throws MojoExecutionException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";

List<String> command = new LinkedList<String>();
command.add(javaBin);

System.getProperties().forEach((key, value) -> {
command.add("-D" + key + "=" + value);
});

command.add("-cp");
command.add(collectClasspath());
command.add("org.rascalmpl.shell.RascalShell");

try {
List<String> command = new LinkedList<String>();
command.add(javaBin);

System.getProperties().forEach((key, value) -> {
command.add("-D" + key + "=" + value);
});

command.add("-cp");
command.add(PathConfig.resolveCurrentRascalRuntimeJar().getPath());
command.add("org.rascalmpl.shell.RascalShell");

ProcessBuilder builder = new ProcessBuilder(command);
Process process = builder.inheritIO().start();
process.waitFor();
Expand All @@ -57,35 +58,5 @@ public void execute() throws MojoExecutionException {
} catch (InterruptedException e) {
getLog().warn(e);
}
finally {}
}

private String collectClasspath() {
StringBuilder builder = new StringBuilder();
boolean dependsOnRascal = false;

if ("org.rascalmpl".equals(project.getGroupId()) && "rascal".equals(project.getArtifactId())){
File r = new File(project.getBuild().getOutputDirectory());
builder.append(File.pathSeparator + r.getAbsolutePath());
dependsOnRascal = true;
}

for (Object o : project.getArtifacts()) {
Artifact a = (Artifact) o;
File file = a.getFile().getAbsoluteFile();
builder.append(File.pathSeparator + file.getAbsolutePath());
if ("org.rascalmpl".equals(a.getGroupId()) && "rascal".equals(a.getArtifactId())) {
dependsOnRascal = true;
}
}

if (!dependsOnRascal) {
String msg = "Current project does not have a dependency on org.rascalmpl:rascal";
getLog().error(msg);
throw new RuntimeException(msg);
}

return builder.toString().substring(1);
}

}

0 comments on commit 2d4c7bb

Please sign in to comment.