Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Add genTestSrcDir to eclipse.jdt.apt
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
tbroyer committed Jan 24, 2019
1 parent 9fd1598 commit ce474d5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ If you're interested in better IDE support, please vote for those issues to even
* in IntelliJ IDEA: [for annotation processing in the IDE](https://youtrack.jetbrains.com/issue/IDEA-187868),
and/or simply [`options.annotationProcessorGeneratedSourcesDirectory` (e.g. if delegating build/run actions to Gradle)](https://youtrack.jetbrains.com/issue/IDEA-182577)

**Note: the documentation below only applies to version 0.20. For previous versions, please see [the previous version of this README](https://github.com/tbroyer/gradle-apt-plugin/blob/648bf2810097799796fdeb327255cdc99733aabd/README.md).**
**Note: the documentation below only applies to version 0.21.
For version 0.20, see [the previous version of this README](https://github.com/tbroyer/gradle-apt-plugin/blob/v0.20/README.md).
For previous versions, please see [this even earlier version](https://github.com/tbroyer/gradle-apt-plugin/blob/648bf2810097799796fdeb327255cdc99733aabd/README.md).**

## Do without the plugin

Expand Down Expand Up @@ -319,8 +321,9 @@ eclipse {
apt {
// whether annotation processing is enabled in Eclipse
aptEnabled = compileJava.aptOptions.annotationProcessing
// where Eclipse will output the generated sources; value is interpreted as per project.file()
// where Eclipse will output the generated sources; values are interpreted as per project.file()
genSrcDir = file('.apt_generated')
genTestSrcDir = file('.apt_generated_tests')
// whether annotation processing is enabled in the editor
reconcileEnabled = true
// a map of annotation processor options; a null value will pass the argument as -Akey rather than -Akey=value
Expand Down Expand Up @@ -365,8 +368,9 @@ eclipse {
apt {
// whether annotation processing is enabled in Eclipse
isAptEnabled = tasks.getByName<JavaCompile>("compileJava").aptOptions.annotationProcessing
// where Eclipse will output the generated sources; value is interpreted as per project.file()
// where Eclipse will output the generated sources; values are interpreted as per project.file()
genSrcDir = file(".apt_generated")
genTestSrcDir = file(".apt_generated_tests")
// whether annotation processing is enabled in the editor
isReconcileEnabled = true
// a map of annotation processor options; a null value will pass the argument as -Akey rather than -Akey=value
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/ltgt/gradle/apt/EclipseJdtApt.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public EclipseJdtApt(Project project, PropertiesFileContentMerger file) {
reconcileEnabled.set(true);
this.genSrcDir = project.getObjects().property(File.class);
genSrcDir.set(project.file(".apt_generated"));
this.genTestSrcDir = project.getObjects().property(File.class);
genTestSrcDir.set(project.file(".apt_generated_tests"));
this.processorOptions =
(Property<Map<String, ?>>) (Property<?>) project.getObjects().property(Map.class);
processorOptions.set(new LinkedHashMap<>());
Expand Down Expand Up @@ -90,6 +92,21 @@ public void setGenSrcDir(Object genSrcDir) {
this.genSrcDir.set(project.provider(() -> project.file(genSrcDir)));
}

private final Property<File> genTestSrcDir;

public File getGenTestSrcDir() {
return project.file(genTestSrcDir);
}

public void setGenTestSrcDir(File genTestSrcDir) {
this.genTestSrcDir.set(Objects.requireNonNull(genTestSrcDir));
}

public void setGenTestSrcDir(Object genTestSrcDir) {
Objects.requireNonNull(genTestSrcDir);
this.genTestSrcDir.set(project.provider(() -> project.file(genTestSrcDir)));
}

private final Property<Map<String, ?>> processorOptions;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void configure(JdtApt jdtApt) {
jdtAptModel.getFile().getBeforeMerged().execute(jdtApt);
jdtApt.setAptEnabled(jdtAptModel.isAptEnabled());
jdtApt.setGenSrcDir(getProject().relativePath(jdtAptModel.getGenSrcDir()));
jdtApt.setGenTestSrcDir(getProject().relativePath(jdtAptModel.getGenTestSrcDir()));
jdtApt.setReconcileEnabled(jdtAptModel.isReconcileEnabled());
jdtApt.getProcessorOptions().clear();
if (jdtAptModel.getProcessorOptions() != null) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/ltgt/gradle/apt/JdtApt.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
public class JdtApt extends PropertiesPersistableConfigurationObject {

private static final String GEN_SRC_DIR_KEY = "org.eclipse.jdt.apt.genSrcDir";
private static final String GEN_TEST_SRC_DIR_KEY = "org.eclipse.jdt.apt.genTestSrcDir";
private static final String RECONCILE_ENABLED_KEY = "org.eclipse.jdt.apt.reconcileEnabled";
private static final String PROCESSOR_OPTIONS_KEY_PREFIX =
"org.eclipse.jdt.apt.processorOptions/";
private static final String PROCESSOR_OPTION_NULLVALUE = "org.eclipse.jdt.apt.NULLVALUE";

private boolean aptEnabled;
@Nullable private String genSrcDir;
@Nullable private String genTestSrcDir;
private boolean reconcileEnabled;
private Map<String, String> processorOptions = new LinkedHashMap<>();

Expand All @@ -48,6 +50,7 @@ protected String getDefaultResourceName() {
protected void load(Properties properties) {
// Ignore aptEnabled when loading, see comment about storing it
genSrcDir = properties.getProperty(GEN_SRC_DIR_KEY);
genTestSrcDir = properties.getProperty(GEN_TEST_SRC_DIR_KEY);
reconcileEnabled = Boolean.parseBoolean(RECONCILE_ENABLED_KEY);
for (String name : properties.stringPropertyNames()) {
if (name.startsWith(PROCESSOR_OPTIONS_KEY_PREFIX)) {
Expand All @@ -68,6 +71,7 @@ protected void store(Properties properties) {
properties.setProperty("org.eclipse.jdt.apt.aptEnabled", Boolean.toString(isAptEnabled()));

properties.setProperty(GEN_SRC_DIR_KEY, getGenSrcDir());
properties.setProperty(GEN_TEST_SRC_DIR_KEY, getGenTestSrcDir());
properties.setProperty(RECONCILE_ENABLED_KEY, Boolean.toString(isReconcileEnabled()));
for (String name : properties.stringPropertyNames()) {
if (name.startsWith(PROCESSOR_OPTIONS_KEY_PREFIX)
Expand Down Expand Up @@ -100,6 +104,15 @@ public void setGenSrcDir(@Nullable String genSrcDir) {
this.genSrcDir = genSrcDir;
}

@Nullable
public String getGenTestSrcDir() {
return genTestSrcDir;
}

public void setGenTestSrcDir(@Nullable String genTestSrcDir) {
this.genTestSrcDir = genTestSrcDir;
}

public boolean isReconcileEnabled() {
return reconcileEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=.apt_generated
org.eclipse.jdt.apt.genTestSrcDir=.apt_generated_tests
org.eclipse.jdt.apt.reconcileEnabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class EclipseIntegrationSpec extends Specification {
def aptSettings = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs')
aptSettings.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'true'
aptSettings.getProperty('org.eclipse.jdt.apt.genSrcDir') == '.apt_generated'
aptSettings.getProperty('org.eclipse.jdt.apt.genTestSrcDir') == '.apt_generated_tests'
aptSettings.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'true'

// Test idempotency of eclipseFactorypath
Expand Down Expand Up @@ -254,6 +255,7 @@ class EclipseIntegrationSpec extends Specification {
apt {
aptEnabled = false
genSrcDir = file('whatever')
genTestSrcDir = file('tests_whatever')
reconcileEnabled = false
file.whenMerged {
processorOptions.baz = 'qux'
Expand Down Expand Up @@ -294,6 +296,7 @@ class EclipseIntegrationSpec extends Specification {
def aptSettings = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs')
aptSettings.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'false'
aptSettings.getProperty('org.eclipse.jdt.apt.genSrcDir') == 'whatever'
aptSettings.getProperty('org.eclipse.jdt.apt.genTestSrcDir') == 'tests_whatever'
aptSettings.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'false'
aptSettings.getProperty('org.eclipse.jdt.apt.processorOptions/foo') == 'bar'
aptSettings.getProperty('org.eclipse.jdt.apt.processorOptions/baz') == 'qux'
Expand All @@ -315,6 +318,7 @@ class EclipseIntegrationSpec extends Specification {
def aptSettings2 = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs')
aptSettings2.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'false'
aptSettings2.getProperty('org.eclipse.jdt.apt.genSrcDir') == 'whatever'
aptSettings2.getProperty('org.eclipse.jdt.apt.genTestSrcDir') == 'tests_whatever'
aptSettings2.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'false'
aptSettings2.getProperty('org.eclipse.jdt.apt.processorOptions/quux') == 'bar'
!aptSettings2.containsKey('org.eclipse.jdt.apt.processorOptions/foo')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class KotlinDslIntegrationSpec extends Specification {
apt {
isAptEnabled = true
genSrcDir = file(".apt_generated")
genTestSrcDir = file(".apt_generated_tests")
isReconcileEnabled = true
processorOptions = mapOf("foo" to "bar")
}
Expand Down

0 comments on commit ce474d5

Please sign in to comment.