diff --git a/pom.xml b/pom.xml index 951bc1b..f7dc65b 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ org.rascalmpl rascal - 0.40.7 + 0.40.8-SNAPSHOT org.rascalmpl diff --git a/src/main/java/org/rascalmpl/maven/CompileRascalDocumentation.java b/src/main/java/org/rascalmpl/maven/CompileRascalDocumentation.java index 70caf9b..1437b29 100644 --- a/src/main/java/org/rascalmpl/maven/CompileRascalDocumentation.java +++ b/src/main/java/org/rascalmpl/maven/CompileRascalDocumentation.java @@ -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; @@ -57,10 +58,18 @@ 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; @@ -68,6 +77,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.directory}/generatedSources") + private String generatedSources; + @Parameter(property = "srcs", required = true ) private List srcs; @@ -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 srcLocs = MojoUtils.locations(srcs); List libLocs = MojoUtils.locations(libs); List ignoredLocs = MojoUtils.locations(ignores); - List classpath = collectClasspath(); if (System.getProperty("rascal.documentation.skip") != null || System.getProperty("rascal.tutor.skip") != null) { @@ -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 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); @@ -223,15 +231,6 @@ private List collectClasspath() throws URISyntaxException { return builder; } - private List collectPluginClasspath() throws URISyntaxException { - List 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> eval, PathConfig pcfg) throws URISyntaxException, IOException { try { IConstructor pc = pcfg.asConstructor(); @@ -261,7 +260,9 @@ private IList runCompiler(IRascalMonitor monitor, IEvaluator> eva try { eval.getStdErr().flush(); eval.getStdOut().flush(); - } catch (IOException ignored) { + } + catch (IOException ignored) { + // this is ok } } } diff --git a/src/main/java/org/rascalmpl/maven/CompileRascalMojo.java b/src/main/java/org/rascalmpl/maven/CompileRascalMojo.java index 2727feb..7fd3666 100644 --- a/src/main/java/org/rascalmpl/maven/CompileRascalMojo.java +++ b/src/main/java/org/rascalmpl/maven/CompileRascalMojo.java @@ -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; @@ -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; @@ -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 ) @@ -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); diff --git a/src/main/java/org/rascalmpl/maven/GenerateSourcesUsingRascalMojo.java b/src/main/java/org/rascalmpl/maven/GenerateSourcesUsingRascalMojo.java index 1c5011b..a1b3e60 100644 --- a/src/main/java/org/rascalmpl/maven/GenerateSourcesUsingRascalMojo.java +++ b/src/main/java/org/rascalmpl/maven/GenerateSourcesUsingRascalMojo.java @@ -15,7 +15,6 @@ 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; @@ -23,6 +22,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. @@ -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 command = new LinkedList(); - command.add(javaBin); + try { + List command = new LinkedList(); + 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(); @@ -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); - } } diff --git a/src/main/java/org/rascalmpl/maven/MojoUtils.java b/src/main/java/org/rascalmpl/maven/MojoUtils.java index 3833cc6..8b65634 100644 --- a/src/main/java/org/rascalmpl/maven/MojoUtils.java +++ b/src/main/java/org/rascalmpl/maven/MojoUtils.java @@ -47,7 +47,7 @@ private static void safeLog(Log log, Consumer 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 { diff --git a/src/main/java/org/rascalmpl/maven/PackageRascalMojo.java b/src/main/java/org/rascalmpl/maven/PackageRascalMojo.java index b61cc8b..4a9c777 100644 --- a/src/main/java/org/rascalmpl/maven/PackageRascalMojo.java +++ b/src/main/java/org/rascalmpl/maven/PackageRascalMojo.java @@ -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; @@ -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; diff --git a/src/main/java/org/rascalmpl/maven/RascalConsoleMojo.java b/src/main/java/org/rascalmpl/maven/RascalConsoleMojo.java index 25f35bc..9be0365 100644 --- a/src/main/java/org/rascalmpl/maven/RascalConsoleMojo.java +++ b/src/main/java/org/rascalmpl/maven/RascalConsoleMojo.java @@ -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. @@ -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 command = new LinkedList(); - 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 command = new LinkedList(); + 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(); @@ -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); - } - }