-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
update to Spoon 8.1 #67
Changes from all commits
5ae7b1c
b4b7fda
108d31b
7b9ce48
5672666
d8171f2
2d8d42f
7563acc
fcef7a1
97ed773
ab68753
2bb56f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>fr.inria.gforge.spoon</groupId> | ||
<artifactId>hello-world-with-processor</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>fr.inria.gforge.spoon</groupId> | ||
<artifactId>spoon-maven-plugin</artifactId> | ||
<version>3.2</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<processors> | ||
<processor>fr.inria.gforge.spoon.mojo.CountStatementProcessor</processor> | ||
<processor>fr.inria.gforge.spoon.mojo.ProcessorWithProperty</processor> | ||
</processors> | ||
<processorProperties> | ||
<processorProperty> | ||
<name>fr.inria.gforge.spoon.mojo.ProcessorWithProperty</name> | ||
<properties> | ||
<property> | ||
<name>methods</name> | ||
<value><![CDATA[ | ||
{ | ||
"java.io.File": ["deleteOnExit"], | ||
"java.net.URL": ["equals"] | ||
} | ||
]]></value> | ||
</property> | ||
<property> | ||
<name>oldClassName</name> | ||
<value>App</value> | ||
</property> | ||
<property> | ||
<name>newClassName</name> | ||
<value>NewName</value> | ||
</property> | ||
<property> | ||
<name>comments</name> | ||
<value>["hello","hello, world"]</value> | ||
</property> | ||
<property> | ||
<name>other</name> | ||
<value>[0,2,4]</value> | ||
</property> | ||
<property> | ||
<name>mapTest</name> | ||
<value>{"un":1,"deux":"two","trois":"3,1"}</value> | ||
</property> | ||
</properties> | ||
</processorProperty> | ||
</processorProperties> | ||
</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,10 @@ | ||
package fr.inria.gforge.spoon; | ||
|
||
/** | ||
* Hello world! | ||
*/ | ||
public class App { | ||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>fr.inria.gforge.spoon</groupId> | ||
<artifactId>processors</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>fr.inria.gforge.spoon</groupId> | ||
<artifactId>spoon-core</artifactId> | ||
<version>8.1.0</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better on long term view to make it configurable or at least based on the version specified in the actual pom.xml of the project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only example code plus it only depends on core stable features of spoon (extends Processor), so the overhead maintenance in the build script is not worth it IMHO. OK for you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah indeed it will be only used to compile the processor to be used in the test, right? Should be good indeed then. |
||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package fr.inria.gforge.spoon; | ||
|
||
/** | ||
* Hello world! | ||
*/ | ||
public class App { | ||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package fr.inria.gforge.spoon.mojo; | ||
|
||
import spoon.processing.AbstractProcessor; | ||
import spoon.reflect.code.CtStatement; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.PrintWriter; | ||
|
||
public class CountStatementProcessor extends AbstractProcessor<CtStatement> { | ||
|
||
private int count = 0; | ||
|
||
@Override | ||
public void process(CtStatement element) { | ||
count++; | ||
} | ||
|
||
@Override | ||
public void processingDone() { | ||
super.processingDone(); | ||
PrintWriter writer = null; | ||
try { | ||
// Creates output file for performance. | ||
final String project = "target" + File.separator + "test-projects" + File.separator + "SpoonMojoTest_testSpoonGoalWithAProcessor_processor"; | ||
final String performancePath = project + File.separator + "target" + File.separator + "spoon-maven-plugin" + File.separator + "spoon-nb-statement.txt"; | ||
final File performanceFile = new File(performancePath); | ||
|
||
if (!performanceFile.getParentFile().exists()) { | ||
performanceFile.getParentFile().mkdirs(); | ||
} | ||
if (!performanceFile.exists()) { | ||
performanceFile.createNewFile(); | ||
} | ||
writer = new PrintWriter(new FileWriter(performanceFile, true)); | ||
|
||
// Saves number of statement. | ||
writer.println(count); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
if (writer != null) { | ||
writer.close(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fr.inria.gforge.spoon.mojo; | ||
|
||
|
||
import spoon.SpoonException; | ||
import spoon.processing.AbstractProcessor; | ||
import spoon.reflect.declaration.CtElement; | ||
|
||
/** | ||
* Created by urli on 05/10/2017. | ||
*/ | ||
public class ProcessorWithException extends AbstractProcessor { | ||
|
||
@Override | ||
public void process(CtElement element) { | ||
throw new SpoonException("Try to throw spoonException"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well you know better than me the parameters for this feature so I trust you here but I definitely think we should refactor it to not rely anymore on the command line arguments: it's really fragile in case of evolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, but we don't have a better solution for now