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

fix(regression): add created source files to spoon input #70

Merged
merged 17 commits into from
May 22, 2020
Merged
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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ script:
- cd src/test/projects/hello-world-with-test
- mvn spoon:check
- cd ../../../..
# try processor on javacc-generate
- cd src/test/projects/javacc-generate
- mvn package
- cd ../../../..

12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ It's also possible to skip the plugin execution using `skip` property as in :

or from command line using `-Dspoon.skip=true`.

## How to set Spoon in FULLCLASSPATH mode?
## How to set Spoon in NOCLASSPATH mode?

Add `<noClasspath>false</noClasspath>` (which means FULLCLASSPATH is activated) or `<noClasspath>true</noClasspath>` to the `<configuration>` block of the plugin.
Add `<noClasspath>true</noClasspath>` (which means NOCLASSPATH is activated) to the `<configuration>` block of the plugin.

## Command-line usage

Expand All @@ -265,6 +265,14 @@ Then, the plugin is automatically discovered ([through prefix resolution](https:

## Changelogs

* Version 3.4.1
* Allow analysis of generated source files e.g. from javacc, see https://github.com/SpoonLabs/spoon-maven-plugin/pull/70
* Use fullclasspath by default

* Version 3.4
* Replacement of srcFolder(s) parameter with new includeSrc parameter
* Allow analysis of test dependencies, see https://github.com/SpoonLabs/spoon-maven-plugin/pull/68

* Version 3.3
* Update to Spoon 8.1
* Fixes noclasspath, see https://github.com/INRIA/spoon/issues/3325
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/inria/gforge/spoon/SpoonMojoCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
name = "check",
defaultPhase = LifecyclePhase.VERIFY,
// Use the TEST scope so that both compile and test dependency artifacts are put in the Spoon classloader
// so that Spoon processors can also analyze test files. Note that by default the test source folder is not
// included by default and requires the usage of the testFolder/testFolders configuration parameters.
// so that Spoon processors can also analyze test files. Note that the test source folder is not
// included by default and requires the usage of the includeTest configuration parameter.
requiresDependencyResolution = ResolutionScope.TEST)

public class SpoonMojoCheck extends SpoonMojoGenerate {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/inria/gforge/spoon/SpoonMojoGenerate.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
name = "generate",
defaultPhase = LifecyclePhase.GENERATE_SOURCES,
// Use the TEST scope so that both compile and test dependency artifacts are put in the Spoon classloader
// so that Spoon processors can also analyze test files. Note that by default the test source folder is not
// included by default and requires the usage of the testFolder/testFolders configuration parameters.
// so that Spoon processors can also analyze test files. Note that the test source folder is not
// included by default and requires the usage of the includeTest configuration parameter.
requiresDependencyResolution = ResolutionScope.TEST)
public class SpoonMojoGenerate extends AbstractMojo {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@ protected AbstractSpoonConfigurationBuilder(SpoonMojoGenerate spoon,
@Override
public SpoonConfigurationBuilder addInputFolder() throws SpoonMavenPluginException {
final List<File> srcDir = new ArrayList<>();
if(spoon.isIncludeSrcDirectories()) {
if (spoon.isIncludeSrcDirectories()) {
srcDir.add(new File(spoon.getProject().getBuild().getSourceDirectory()));
if (!spoon.getSkipGeneratedSources()) {
for (String s : spoon.getProject().getCompileSourceRoots()) {
srcDir.add(new File(s));
}
}
}
if(spoon.isIncludeTestDirectories()) {
srcDir.add(new File(spoon.getProject().getBuild().getTestSourceDirectory()));
if (!spoon.getSkipGeneratedSources()) {
for (String s : spoon.getProject().getTestCompileSourceRoots()) {
srcDir.add(new File(s));
}
}
}


srcDir.removeIf(file -> !file.exists());

if (srcDir.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;

public final class SpoonConfigurationBuilderTest {
@Rule
Expand Down Expand Up @@ -44,7 +45,7 @@ public void testConfigurationOfTheEnableCommentsKeepsDefaults() throws Exception
assertThat(config[0]).isEqualTo("--level");
assertThat(config[1]).isEqualTo("INFO");
}

@Test
public void testConfigurationOfTheDefaultInputFolder() throws Exception {
final File basedir = resources.getBasedir("hello-world");
Expand All @@ -55,7 +56,7 @@ public void testConfigurationOfTheDefaultInputFolder() throws Exception {
assertThat(config[0]).isEqualTo("--level");
assertThat(config[1]).isEqualTo("INFO");
assertThat(config[2]).isEqualTo("-i");
assertThat(config[3]).isEqualTo(basedir + File.separator + "src" + File.separator + "main" + File.separator + "java");
assertTrue(Arrays.stream(config).anyMatch(v->v.contains(basedir + File.separator + "src" + File.separator + "main" + File.separator + "java")));
}

@Test
Expand Down
1 change: 0 additions & 1 deletion src/test/projects/hello-world-with-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<plugin>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<version>3.4-SNAPSHOT</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand Down
66 changes: 66 additions & 0 deletions src/test/projects/javacc-generate/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test.javacc.spoon</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javacc-maven-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>javacc</id>
<goals>
<goal>javacc</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.java.dev.javacc</groupId>
<artifactId>javacc</artifactId>
<version>7.0.6</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<version>3.5-SNAPSHOT</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because i normally use gradle and didn't knew it. Going to have a look thx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about simply removing <version>3.5-SNAPSHOT</version> as you did above?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the version the build won't be reproducible and maven will use the latest version available. You need a version (and you should actually use the maven enforcer to always make sure all versions are set).

<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<includeTest>false</includeTest>
<includeSource>true</includeSource>
<noClasspath>false</noClasspath>
<debug>true</debug>
<processors>
<processor>fr.inria.gforge.spoon.mojo.CountStatementProcessor</processor>
</processors>
</configuration>
<dependencies>
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>processors</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test.javacc.spoon;

import generate.javacc.spoon.Example;
/**
* Hello world!
*/
public final class App {
private App() {
}

/**
* Says hello to the world.
* @param args The arguments of the program.
*/
public static void main(String[] args) {
Example example = new Example(System.in);
System.out.println("Hello World!");
}
}
28 changes: 28 additions & 0 deletions src/test/projects/javacc-generate/src/main/javacc/Example.jj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PARSER_BEGIN(Example)
package generate.javacc.spoon;
/** Simple brace matcher. */
public class Example {

/** Main entry point. */
public static void main(String args[]) throws ParseException {
Example parser = new Example(System.in);
parser.Input();
}

}

PARSER_END(Example)

/** Root production. */
void Input() :
{}
{
MatchedBraces() ("\n"|"\r")* <EOF>
}

/** Brace matching production. */
void MatchedBraces() :
{}
{
"{" [ MatchedBraces() ] "}"
}