Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/INRIA/spoon into field-ac…
Browse files Browse the repository at this point in the history
…cess-test-jdk11
  • Loading branch information
nharrand committed Dec 2, 2018
2 parents 44a35c7 + aafee0b commit da0ca50
Show file tree
Hide file tree
Showing 67 changed files with 1,424 additions and 148 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ env:
- SCRIPT=travis-maven339-jdk8.sh
- SCRIPT=travis-spoon-decompiler.sh

# in langage:java, Travis executes by default "mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V"
# This is not what we want because:
# - it executes checkstyle (we have a specific job for this)
# - it's useless ("mvn test" later does all the necessary tasks automatically)
# - it makes the build longer (we want a fast job)
install: true

script: ./chore/travis/$SCRIPT

cache:
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ For contributing to Spoon, the recommended way is to create a pull request (PR)
The integrator code of conduct
------------------------------

The integrators are the developers who have write access to the repository. Developers are given the integrator role after lasting and significant contributions, as assessed by the other integrators. They shall respect the following rules:
The integrators are the developers who have write access to the repository. The integrators shall respect the following rules:

* Spoon integrators only merge atomic pull requests (single bug fix or single feature)
* Spoon integrators only merge well tested and well documented pull requests, after thorough code review
Expand All @@ -13,6 +13,8 @@ The integrators are the developers who have write access to the repository. Deve
* Spoon integrators leave pull requests opened at least 1 day before merging, so that the community is aware and can comment on them
* Serious conflicts, who cannot be resolved by time and discussion, are resolved by a vote among integrators.

How to become integrator? The integrators are the developers who have made significant contributions over the last 12 months (gliding window). Significance is assessed by the current set of integrators who co-opt the new ones.

Current integrators (alphabetical order):

- Benjamin Danglot @danglotb
Expand Down
4 changes: 3 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@

<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="LeftCurly" />
<module name="LeftCurly" >
<property name="tokens" value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF, INTERFACE_DEF, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF, OBJBLOCK, STATIC_INIT"/>
</module>
<module name="RightCurly" />
<module name="NeedBraces"/>

Expand Down
4 changes: 1 addition & 3 deletions doc/doc_homepage.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ Star Spoon on Github: [https://github.com/INRIA/spoon](https://github.com/INRIA/

### Jar file

[v{{site.spoon_release}} JAR](https://gforge.inria.fr/frs/?group_id=73) - [Javadoc](http://spoon.gforge.inria.fr/mvnsites/spoon-core/apidocs)

The source code to the Spoon and this website is [available on GitHub](https://github.com/INRIA/spoon).
Latest version: <https://search.maven.org/remote_content?g=fr.inria.gforge.spoon&a=spoon-core&v=LATEST&c=jar-with-dependencies> - [Javadoc](http://spoon.gforge.inria.fr/mvnsites/spoon-core/spoon-core/apidocs/index.html)

### Maven

Expand Down
8 changes: 6 additions & 2 deletions doc/jenkins/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ rm pom.bak*.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins" --type elem -n plugin -v "" pom.xml > pom.bak.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]" --type elem -n groupId -v "fr.inria.gforge.spoon" pom.bak.xml > pom.bak2.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]" --type elem -n artifactId -v "spoon-maven-plugin" pom.bak2.xml > pom.bak3.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]" --type elem -n version -v "2.4" pom.bak3.xml > pom.bak4.xml

# we depend on the latest version of spoon-maven-plugin, one that does not use http://spoon.gforge.inria.fr/repositories/snapshots/ (decommissioned)
# but the correct http://maven.inria.fr/artifactory/spoon-public-snapshot/ (Inria's artifactory)
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]" --type elem -n version -v "3.1" pom.bak3.xml > pom.bak4.xml

xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]" --type elem -n executions -v "" pom.bak4.xml > pom.bak5.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:executions" --type elem -n execution -v "" pom.bak5.xml > pom.bak6.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:executions/x:execution" --type elem -n phase -v "generate-sources" pom.bak6.xml > pom.bak7.xml
Expand All @@ -168,7 +172,7 @@ xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:dependencies" --type elem -n dependency -v "" pom.bak14.xml > pom.bak19.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:dependencies/x:dependency[last()]" --type elem -n groupId -v "fr.inria.gforge.spoon" pom.bak19.xml > pom.bak20.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:dependencies/x:dependency[last()]" --type elem -n artifactId -v "spoon-core" pom.bak20.xml > pom.bak21.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:dependencies/x:dependency[last()]" --type elem -n version -v "[5.5.0-SNAPSHOT,)" pom.bak21.xml > pom.bak22.xml
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:dependencies/x:dependency[last()]" --type elem -n version -v "[7.0.0-SNAPSHOT,)" pom.bak21.xml > pom.bak22.xml
mv pom.bak22.xml pom.xml
rm pom.bak*.xml

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<version>3.0.0</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>checkstyle.xml</configLocation>
Expand Down
2 changes: 1 addition & 1 deletion spoon-decompiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<version>3.0.0</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>../checkstyle.xml</configLocation>
Expand Down
11 changes: 6 additions & 5 deletions spoon-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@
<header>../LICENSE-short.txt</header>
<basedir>src</basedir>
<includes>
<include>main/java/**</include>
<include>../src/main/java/**</include>
<!-- We also want to check the license in templates to generate files with the proper header -->
<include>test/java/spoon/generating/clone/*</include>
<!-- excluding the code coming from Javaparser -->
<exclude>../src/main/java/spoon/javadoc/internal/*</exclude>
</includes>
</configuration>
<executions>
Expand Down Expand Up @@ -304,12 +306,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<version>3.0.1</version>
<configuration>
<quiet>true</quiet>
<additionalparam>-Xdoclint:none</additionalparam>
<!--maven-javadoc-plugin version 2.9 onwards uses additionalJOption, see https://stackoverflow.com/questions/39616344/how-to-disable-javadoc-warnings-in-maven-javadoc-plugin/48511911#48511911 -->
<additionalJOption>-Xdoclint:none</additionalJOption>
<!-- doclin, since 3.0.1, see https://stackoverflow.com/a/53497998/1153476 -->
<doclint>none</doclint>
</configuration>
<reportSets>
<reportSet>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/spoon/compiler/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.log4j.Level;
import spoon.OutputType;
import spoon.compiler.builder.EncodingProvider;
import spoon.support.modelobs.FineModelChangeListener;
import spoon.processing.FileGenerator;
import spoon.processing.ProblemFixer;
Expand Down Expand Up @@ -378,11 +379,21 @@ void report(Processor<?> processor, Level level,
*/
Charset getEncoding();

/**
* Get encoding provider, which is used to detect encoding for each file separately
*/
EncodingProvider getEncodingProvider();

/**
* Set the encoding to use for parsing source code
*/
void setEncoding(Charset encoding);

/**
* Set encoding provider, which is used to detect encoding for each file separately
*/
void setEncodingProvider(EncodingProvider encodingProvider);

/**
* Set the output type used for processing files
*/
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/spoon/compiler/SpoonFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
*/
package spoon.compiler;

import org.apache.commons.io.IOUtils;
import spoon.SpoonException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

/**
* This interface represents files that can be used as resources for the Spoon
Expand All @@ -41,4 +47,25 @@ public interface SpoonFile extends SpoonResource {
* @return
*/
boolean isActualFile();

/**
* Gets the file content as a char array, considering encoding or encoding
* provider.
*/
default char[] getContentChars(Environment env) {
byte[] bytes;
try (InputStream contentStream = getContent()) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
IOUtils.copy(contentStream, outputStream);
bytes = outputStream.toByteArray();
} catch (IOException e) {
throw new SpoonException(e);
}
if (env.getEncodingProvider() == null) {
return new String(bytes, env.getEncoding()).toCharArray();
} else {
Charset encoding = env.getEncodingProvider().detectEncoding(this, bytes);
return new String(bytes, encoding).toCharArray();
}
}
}
28 changes: 28 additions & 0 deletions src/main/java/spoon/compiler/builder/EncodingProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2006-2018 INRIA and contributors
* Spoon - http://spoon.gforge.inria.fr/
*
* This software is governed by the CeCILL-C License under French law and
* abiding by the rules of distribution of free software. You can use, modify
* and/or redistribute the software under the terms of the CeCILL-C license as
* circulated by CEA, CNRS and INRIA at http://www.cecill.info.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package spoon.compiler.builder;

import spoon.compiler.SpoonFile;
import java.nio.charset.Charset;

public interface EncodingProvider {

/**
* User-defined function, which is used to detect encoding for each file
*/
Charset detectEncoding(SpoonFile file, byte[] fileBytes);
}
Loading

0 comments on commit da0ca50

Please sign in to comment.