Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing lib scheme #23

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 21 additions & 20 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 @@ -57,17 +58,28 @@ public class CompileRascalDocumentation extends AbstractMojo
{
private static final String UNEXPECTED_ERROR = "unexpected error during Rascal compiler run";
private static final String MAIN_COMPILER_MODULE = "lang::rascal::tutor::Compiler";
private static final ISourceLocation[] MAIN_COMPILER_SEARCH_PATH = new ISourceLocation[] {
URIUtil.correctLocation("lib", "rascal-tutor", ""),
URIUtil.correctLocation("lib", "rascal", ""),
};
private static final ISourceLocation[] MAIN_COMPILER_SEARCH_PATH;

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

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

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

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

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

Expand Down Expand Up @@ -126,10 +138,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 +163,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 +231,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 +260,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.directory}/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 @@ -15,14 +15,14 @@
import java.util.LinkedList;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
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 +48,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 +77,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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/rascalmpl/maven/MojoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static void safeLog(Log log, Consumer<Log> action) {

private static void addSearchPath(Log log, Evaluator eval, ISourceLocation loc) {
safeLog(log, l -> l.info("\trascal module path addition: " + loc));
eval.addRascalSearchPath(loc);
eval.addRascalSearchPath(JarURIResolver.jarify(loc));
}

static Evaluator makeEvaluator(Log log, MavenSession session, OutputStream err, OutputStream out, ISourceLocation[] searchPath, String... importedModules) throws URISyntaxException, FactTypeUseException, IOException {
Expand Down
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);
}

}
Loading