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

update to Spoon 8.1 #67

Merged
merged 12 commits into from
Apr 16, 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
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,28 @@ git:

language: java

sudo: required

before_install:
- sudo apt-get install -y xmlstarlet
- SPOON_MAVEN_PLUGIN_VERSION=`xmlstarlet sel -t -v '/_:project/_:version' pom.xml`

jdk:
- openjdk8

install: true

script:
# we need to install the processors first
- cd src/test/projects/processors
- mvn install
- cd ../../../..
- mvn install
# trying a real transformation as done in reality
- cd src/test/projects/hello-world-with-processor
# updating to latest version
- xmlstarlet edit -L --update '/_:project/_:build/_:plugins/_:plugin/_:version' --value $SPOON_MAVEN_PLUGIN_VERSION pom.xml
- mvn install
- cd ../../../..


8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- Compilation -->
<java.version>1.8</java.version>
<spoon.version>7.0.0</spoon.version>
<spoon.version>8.1.0</spoon.version>
<commons-io.version>2.6</commons-io.version>
<jaxb-api.version>2.2.11</jaxb-api.version>
<jaxb-runtime.version>2.3.1</jaxb-runtime.version>
Expand Down Expand Up @@ -91,6 +91,12 @@

<dependencies>
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>processors</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.9</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ public SpoonConfigurationBuilder addSourceClasspath() throws SpoonMavenPluginExc
@Override
public SpoonConfigurationBuilder addNoClasspath() {
if (spoon.isNoClasspath()) {
parameters.add("-x");
parameters.add("--cpmode");
parameters.add("NOCLASSPATH");
} else {
parameters.add("--cpmode");
parameters.add("FULLCLASSPATH");
Copy link
Collaborator

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.

Copy link
Contributor Author

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

}
return this;
}
Expand Down
75 changes: 75 additions & 0 deletions src/test/projects/hello-world-with-processor/pom.xml
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!");
}
}
16 changes: 16 additions & 0 deletions src/test/projects/processors/pom.xml
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>
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import java.util.List;
import java.util.Map;

/**
* Created by urli on 21/09/2017.
*/
public class ProcessorWithProperty extends AbstractProcessor<CtClass> {
@Property
String methods;

@Property
String oldClassName;
Expand All @@ -30,6 +29,7 @@ public class ProcessorWithProperty extends AbstractProcessor<CtClass> {

@Override
public void process(CtClass element) {
System.out.println(methods);
if (!(comments != null && comments.size() == 2 && comments.get(0).equals("hello") && comments.get(1).equals("hello, world"))) {
element.addComment(this.getFactory().createInlineComment("Content comments: "+ StringUtils.join(comments.iterator(),",")));
return;
Expand Down