Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2018-02-12 22:43:44 +0000
committerTill Brychcy2018-02-19 21:43:59 +0000
commit86b105d1761e70cf1cca4f74c60ede1ff3f77520 (patch)
treefb39f9a1d3a763b9a70d044cb351e44b837b2504
parente603dedfdfd718d3d302f1cd90c78085d81e98f0 (diff)
downloadeclipse.jdt.core-86b105d1761e70cf1cca4f74c60ede1ff3f77520.tar.gz
eclipse.jdt.core-86b105d1761e70cf1cca4f74c60ede1ff3f77520.tar.xz
eclipse.jdt.core-86b105d1761e70cf1cca4f74c60ede1ff3f77520.zip
Bug 531072 - [testsources][apt] classes generated for test sources need
to be put in a test source folder Change-Id: Ieb06760c55d8fe3bd04954ca13d1b9fb4f67d846
-rw-r--r--org.eclipse.jdt.apt.core/.settings/.api_filters17
-rw-r--r--org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.apt.core/pom.xml4
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/env/EnvironmentFactory.java6
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java36
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptCompilationParticipant.java14
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptProject.java83
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AbstractCompilationEnv.java18
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java9
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BinaryFileOutputStream.java4
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java7
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildFilerImpl.java4
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/FilerImpl.java4
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/JavaSourceFilePrintWriter.java4
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/ReconcileEnv.java9
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/ClasspathUtil.java25
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileManager.java16
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileMap.java18
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedResourceChangeListener.java35
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java56
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/WorkingCopyCleanupListener.java5
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/TestCodeUtil.java35
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptConfig.java51
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java12
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeAnnotationProcessorManager.java9
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeBuildProcessingEnvImpl.java6
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeProcessingEnvImpl.java11
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeReconcileProcessingEnvImpl.java6
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java6
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java4
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeNonSourceOutputStream.java4
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java4
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java16
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java4
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java4
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java84
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java72
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java4
-rw-r--r--org.eclipse.jdt.apt.ui/.settings/.api_filters11
-rw-r--r--org.eclipse.jdt.apt.ui/META-INF/MANIFEST.MF8
-rw-r--r--org.eclipse.jdt.apt.ui/pom.xml2
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AptConfigurationBlock.java52
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java6
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties4
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java4
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java5
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/BuildContext.java8
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java10
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java12
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/CompilationParticipantResult.java10
51 files changed, 642 insertions, 200 deletions
diff --git a/org.eclipse.jdt.apt.core/.settings/.api_filters b/org.eclipse.jdt.apt.core/.settings/.api_filters
new file mode 100644
index 0000000000..8e1d1bd9f5
--- /dev/null
+++ b/org.eclipse.jdt.apt.core/.settings/.api_filters
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jdt.apt.core" version="2">
+ <resource path="src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java" type="org.eclipse.jdt.apt.core.util.AptPreferenceConstants">
+ <filter id="336658481">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.apt.core.util.AptPreferenceConstants"/>
+ <message_argument value="APT_GENTESTSRCDIR"/>
+ </message_arguments>
+ </filter>
+ <filter id="336658481">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.apt.core.util.AptPreferenceConstants"/>
+ <message_argument value="DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
index 8283f1a2bd..85d3f3aec1 100644
--- a/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.core; singleton:=true
-Bundle-Version: 3.5.100.qualifier
+Bundle-Version: 3.6.0.qualifier
Bundle-Localization: plugin
Export-Package: com.sun.mirror.apt,
com.sun.mirror.declaration,
diff --git a/org.eclipse.jdt.apt.core/pom.xml b/org.eclipse.jdt.apt.core/pom.xml
index 3734c3e46f..189836a341 100644
--- a/org.eclipse.jdt.apt.core/pom.xml
+++ b/org.eclipse.jdt.apt.core/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2016 Eclipse Foundation and others.
+ Copyright (c) 2012, 2018 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.apt.core</artifactId>
- <version>3.5.100-SNAPSHOT</version>
+ <version>3.6.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/env/EnvironmentFactory.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/env/EnvironmentFactory.java
index f2e7417bf6..a8480307c9 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/env/EnvironmentFactory.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/env/EnvironmentFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,6 +14,7 @@ package org.eclipse.jdt.apt.core.env;
import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
+import org.eclipse.jdt.apt.core.internal.util.TestCodeUtil;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.dom.CompilationUnit;
@@ -41,7 +42,8 @@ public class EnvironmentFactory {
node,
(IFile)compilationUnit.getResource(),
javaProject,
- Phase.OTHER
+ Phase.OTHER,
+ TestCodeUtil.isTestCode(compilationUnit)
);
return env;
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java
index e6378ef273..ee17cbae8f 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc. and others
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -119,6 +119,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
private final boolean _isFullBuild;
private static final boolean SPLIT_FILES;
private static final String SPLIT_FILES_PROPERTY = "org.eclipse.jdt.apt.core.split_files"; //$NON-NLS-1$
+ private final boolean _isTestCode;
static {
String setting = System.getProperty(SPLIT_FILES_PROPERTY);
@@ -132,7 +133,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
AptProject aptProject,
Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories,
Set<AnnotationProcessorFactory> dispatchedBatchFactories,
- boolean isFullBuild){
+ boolean isFullBuild, boolean isTestCode){
if( filesWithAnnotations == null ){
filesWithAnnotations = NO_FILES_TO_PROCESS;
@@ -145,7 +146,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
filesWithoutAnnotations,
problemRecorder,
aptProject, factories,
- dispatchedBatchFactories, isFullBuild );
+ dispatchedBatchFactories, isFullBuild, isTestCode );
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
workspace.run(runnable, aptProject.getJavaProject().getResource(), IWorkspace.AVOID_UPDATE, null);
@@ -159,13 +160,14 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
public static void runAPTDuringReconcile(
ReconcileContext reconcileContext,
AptProject aptProject,
- Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories)
+ Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories,
+ boolean test)
{
// Reconciling, so we do not want to run this as an atomic workspace
// operation. If we do, it is easy to have locking issues when someone
// calls a reconcile from within a workspace lock
- APTDispatchRunnable runnable = new APTDispatchRunnable( aptProject, factories );
- runnable.reconcile(reconcileContext, aptProject.getJavaProject());
+ APTDispatchRunnable runnable = new APTDispatchRunnable( aptProject, factories, test);
+ runnable.reconcile(reconcileContext, aptProject.getJavaProject(), test);
}
/** create a runnable used during build */
@@ -176,7 +178,8 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
AptProject aptProject,
Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories,
Set<AnnotationProcessorFactory> dispatchedBatchFactories,
- boolean isFullBuild)
+ boolean isFullBuild,
+ boolean isTestCode)
{
assert filesWithAnnotation != null : "missing files"; //$NON-NLS-1$
_filesWithAnnotation = filesWithAnnotation;
@@ -186,14 +189,17 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
_factories = factories;
_dispatchedBatchFactories = dispatchedBatchFactories;
_isFullBuild = isFullBuild;
+ _isTestCode = isTestCode;
}
/** create a runnable used during reconcile */
private APTDispatchRunnable(
AptProject aptProject,
- Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories)
+ Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories,
+ boolean test)
{
_aptProject = aptProject;
_factories = factories;
+ _isTestCode = test;
_isFullBuild = false;
// does not apply in reconcile case. we don't generate file during
// reconcile and no apt rounding ever occur as a result.
@@ -201,7 +207,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
}
private void reconcile(final ReconcileContext reconcileContext,
- IJavaProject javaProject)
+ IJavaProject javaProject, boolean test)
{
if (_factories.size() == 0) {
if (AptPlugin.DEBUG)
@@ -214,7 +220,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
// Construct a reconcile time environment. This will invoke
// dispatch from inside the callback.
- GeneratedFileManager gfm = _aptProject.getGeneratedFileManager();
+ GeneratedFileManager gfm = _aptProject.getGeneratedFileManager(test);
gfm.reconcileStarted();
EnvCallback callback = new ReconcileEnvCallback(reconcileContext, gfm);
AbstractCompilationEnv.newReconcileEnv(reconcileContext, callback);
@@ -308,7 +314,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
// We need to save the file dependency state regardless of whether any Java 5 processing
// was performed, because it may also contain Java 6 information.
- _aptProject.getGeneratedFileManager().writeState();
+ _aptProject.getGeneratedFileManager(_isTestCode).writeState();
}
/**
@@ -341,7 +347,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
private void runAPTInFileBasedMode(final BuildEnv processorEnv)
{
final BuildContext[] cpResults = processorEnv.getFilesWithAnnotation();
- final GeneratedFileManager gfm = _aptProject.getGeneratedFileManager();
+ final GeneratedFileManager gfm = _aptProject.getGeneratedFileManager(_isTestCode);
boolean projectEnablesReconcile = AptConfig.shouldProcessDuringReconcile(_aptProject.getJavaProject());
for (BuildContext curResult : cpResults ) {
processorEnv.beginFileProcessing(curResult);
@@ -566,7 +572,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
// If there are no files to be built, apt will not be involved.
assert firstResult != null : "don't know where to report results"; //$NON-NLS-1$
if(firstResult != null ){
- final GeneratedFileManager gfm = _aptProject.getGeneratedFileManager();
+ final GeneratedFileManager gfm = _aptProject.getGeneratedFileManager(_isTestCode);
reportResult(
firstResult, // just put it all in
processorEnv.getAllGeneratedFiles(),
@@ -608,7 +614,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
}
}
- final GeneratedFileManager gfm = _aptProject.getGeneratedFileManager();
+ final GeneratedFileManager gfm = _aptProject.getGeneratedFileManager(_isTestCode);
reportResult(
curResult,
processorEnv.getAllGeneratedFiles(),
@@ -749,7 +755,7 @@ public class APTDispatchRunnable implements IWorkspaceRunnable
return;
}
final Set<IFile> deleted = new HashSet<>();
- GeneratedFileManager gfm = _aptProject.getGeneratedFileManager();
+ GeneratedFileManager gfm = _aptProject.getGeneratedFileManager(_isTestCode);
Set<IFile> java6GeneratedFiles = AptCompilationParticipant.getInstance().getJava6GeneratedFiles();
for( BuildContext cpResult : cpResults){
final IFile parentFile = cpResult.getFile();
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptCompilationParticipant.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptCompilationParticipant.java
index 3a0a7e7d87..b78916bd8f 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptCompilationParticipant.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptCompilationParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -25,6 +25,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
+import org.eclipse.jdt.apt.core.internal.util.TestCodeUtil;
import org.eclipse.jdt.apt.core.util.AptConfig;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
@@ -135,8 +136,12 @@ public class AptCompilationParticipant extends CompilationParticipant
// also exclude files that has already been processed.
int annoFileCount = 0;
int noAnnoFileCount = 0;
+ boolean test = false;
for( int i=0; i<total; i++ ){
BuildContext bc = allfiles[i];
+ if(bc.isTestCode()) {
+ test = true;
+ }
if( _buildRound > 0 && _processedFiles.containsKey( bc.getFile() )){
// We've already processed this file; we'll skip reprocessing it, on
// the assumption that nothing would change, but we need to re-report
@@ -191,7 +196,8 @@ public class AptCompilationParticipant extends CompilationParticipant
aptProject,
factories,
_previousRoundsBatchFactories,
- _isBatch);
+ _isBatch,
+ test);
_previousRoundsBatchFactories.addAll(dispatchedBatchFactories);
}
finally {
@@ -215,14 +221,14 @@ public class AptCompilationParticipant extends CompilationParticipant
Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories =
AnnotationProcessorFactoryLoader.getLoader().getJava5FactoriesAndAttributesForProject( javaProject );
- APTDispatchRunnable.runAPTDuringReconcile(context, aptProject, factories);
+ APTDispatchRunnable.runAPTDuringReconcile(context, aptProject, factories, TestCodeUtil.isTestCode(workingCopy));
}
@Override
public void cleanStarting(IJavaProject javaProject){
IProject p = javaProject.getProject();
- AptPlugin.getAptProject(javaProject).projectClean( true );
+ AptPlugin.getAptProject(javaProject).projectClean( true, true, true );
try{
// clear out all markers during a clean.
IMarker[] markers = p.findMarkers(AptPlugin.APT_BATCH_PROCESSOR_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptProject.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptProject.java
index 8b28ab7d56..53a266c078 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptProject.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/AptProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,26 +28,32 @@ public class AptProject {
private final IJavaProject _javaProject;
- private final GeneratedFileManager _gfm;
+ private final GeneratedFileManager _main_gfm;
- private final GeneratedSourceFolderManager _gsfm;
+ private final GeneratedSourceFolderManager _main_gsfm;
+
+ private final GeneratedFileManager _test_gfm;
+ private final GeneratedSourceFolderManager _test_gsfm;
+
public AptProject(final IJavaProject javaProject) {
_javaProject = javaProject;
- _gsfm = new GeneratedSourceFolderManager(this);
- _gfm = new GeneratedFileManager(this, _gsfm);
+ _main_gsfm = new GeneratedSourceFolderManager(this, false);
+ _main_gfm = new GeneratedFileManager(this, _main_gsfm);
+ _test_gsfm = new GeneratedSourceFolderManager(this, true);
+ _test_gfm = new GeneratedFileManager(this, _test_gsfm);
}
public IJavaProject getJavaProject() {
return _javaProject;
}
- public GeneratedFileManager getGeneratedFileManager() {
- return _gfm;
+ public GeneratedFileManager getGeneratedFileManager(boolean isTestCode) {
+ return isTestCode ? _test_gfm : _main_gfm;
}
- public GeneratedSourceFolderManager getGeneratedSourceFolderManager() {
- return _gsfm;
+ public GeneratedSourceFolderManager getGeneratedSourceFolderManager(boolean isTestCode) {
+ return isTestCode ? _test_gsfm : _main_gsfm;
}
/**
@@ -55,7 +61,8 @@ public class AptProject {
* initialization and verify configuration.
*/
public void compilationStarted() {
- _gfm.compilationStarted();
+ getGeneratedFileManager(false).compilationStarted();
+ getGeneratedFileManager(true).compilationStarted();
}
/**
@@ -68,10 +75,12 @@ public class AptProject {
*/
public void preferenceChanged(String key) {
if (AptPreferenceConstants.APT_GENSRCDIR.equals(key)) {
- _gsfm.folderNamePreferenceChanged();
- }
- else if(AptPreferenceConstants.APT_ENABLED.equals(key) ){
- _gsfm.enabledPreferenceChanged();
+ _main_gsfm.folderNamePreferenceChanged();
+ } else if (AptPreferenceConstants.APT_GENTESTSRCDIR.equals(key)) {
+ _test_gsfm.folderNamePreferenceChanged();
+ } else if(AptPreferenceConstants.APT_ENABLED.equals(key) ){
+ _main_gsfm.enabledPreferenceChanged();
+ _test_gsfm.enabledPreferenceChanged();
}
}
@@ -84,28 +93,42 @@ public class AptProject {
* deleted, false otherwise.
*/
- public void projectClean( boolean deleteFiles )
+ public void projectClean( boolean deleteFiles, boolean cleanMain, boolean cleanTest )
{
- _gfm.projectCleaned();
+ if(cleanMain)
+ _main_gfm.projectCleaned();
+ if(cleanTest)
+ _test_gfm.projectCleaned();
// delete the contents of the generated source folder, but don't delete
// the generated source folder because that will cause a classpath change,
// which will force the next build to be a full build.
if ( deleteFiles )
{
- IFolder f = _gsfm.getFolder();
- if ( f != null && f.exists() )
- {
- try
- {
- IResource[] members = f.members();
- for ( int i = 0; i<members.length; i++ ){
- FileSystemUtil.deleteDerivedResources(members[i]);
+ if (cleanMain) {
+ IFolder f = _main_gsfm.getFolder();
+ if (f != null && f.exists()) {
+ try {
+ IResource[] members = f.members();
+ for (int i = 0; i < members.length; i++) {
+ FileSystemUtil.deleteDerivedResources(members[i]);
+ }
+ } catch (CoreException ce) {
+ AptPlugin.log(ce, "Could not delete generated files"); //$NON-NLS-1$
}
}
- catch ( CoreException ce )
- {
- AptPlugin.log(ce, "Could not delete generated files"); //$NON-NLS-1$
+ }
+ if (cleanMain) {
+ IFolder f = _test_gsfm.getFolder();
+ if (f != null && f.exists()) {
+ try {
+ IResource[] members = f.members();
+ for (int i = 0; i < members.length; i++) {
+ FileSystemUtil.deleteDerivedResources(members[i]);
+ }
+ } catch (CoreException ce) {
+ AptPlugin.log(ce, "Could not delete generated files"); //$NON-NLS-1$
+ }
}
}
}
@@ -116,7 +139,8 @@ public class AptProject {
*/
public void projectClosed()
{
- _gfm.projectClosed();
+ _main_gfm.projectClosed();
+ _test_gfm.projectClosed();
}
/**
@@ -130,7 +154,8 @@ public class AptProject {
{
if (AptPlugin.DEBUG)
AptPlugin.trace("AptProject.projectDeleted cleaning state for project " + _javaProject.getElementName()); //$NON-NLS-1$
- _gfm.projectDeleted();
+ _main_gfm.projectDeleted();
+ _test_gfm.projectDeleted();
}
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AbstractCompilationEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AbstractCompilationEnv.java
index 60d6bea5bb..1f124d156e 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AbstractCompilationEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AbstractCompilationEnv.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -104,9 +104,16 @@ public abstract class AbstractCompilationEnv
EnvCallback callback)
{
assert filesWithAnnotations != null : "missing files"; //$NON-NLS-1$
-
+ boolean isTestCode;
+ if (filesWithAnnotations != null && filesWithAnnotations.length > 0) {
+ isTestCode = filesWithAnnotations[0].isTestCode();
+ } else if (additionalFiles != null && additionalFiles.length > 0) {
+ isTestCode = additionalFiles[0].isTestCode();
+ } else {
+ isTestCode = false;
+ }
// note, we are not reading any files.
- BuildEnv env = new BuildEnv(filesWithAnnotations, additionalFiles, javaProj);
+ BuildEnv env = new BuildEnv(filesWithAnnotations, additionalFiles, javaProj, isTestCode);
env._callback = callback;
env.createASTs(filesWithAnnotations);
}
@@ -131,9 +138,9 @@ public abstract class AbstractCompilationEnv
CompilationUnit compilationUnit,
IFile file,
IJavaProject javaProj,
- Phase phase)
+ Phase phase, boolean isTestCode)
{
- super(compilationUnit, file, javaProj, phase);
+ super(compilationUnit, file, javaProj, phase, isTestCode);
}
@Override
@@ -361,5 +368,4 @@ public abstract class AbstractCompilationEnv
return options.contains(AptPreferenceConstants.RTTG_ENABLED_OPTION) ||
options.contains(RTTG_ENABLED_DASH_A_OPTION);
}
-
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
index b98ca43c22..53ae29196c 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2017 BEA Systems Inc. and others
+ * Copyright (c) 2005, 2018 BEA Systems Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -107,6 +107,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
protected IFile _file;
protected final IJavaProject _javaProject;
protected final AptProject _aptProject;
+ private final boolean _isTestCode;
/**
* Unmodifiable map of processor options, including -A options.
@@ -139,7 +140,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
public BaseProcessorEnv(CompilationUnit astCompilationUnit,
IFile file,
IJavaProject javaProj,
- Phase phase )
+ Phase phase, boolean isTestCode )
{
_astRoot = astCompilationUnit;
_file = file;
@@ -149,6 +150,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
_modelCompUnit2astCompUnit = new HashMap<>();
_typeBinding2ModelCompUnit = new HashMap<>();
_aptProject = AptPlugin.getAptProject(javaProj);
+ _isTestCode = isTestCode;
}
/**
@@ -168,7 +170,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
* so this will always be up to date with the latest settings.
*/
private Map<String, String> initOptions(IJavaProject jproj) {
- Map<String, String> procOptions = AptConfig.getProcessorOptions(jproj);
+ Map<String, String> procOptions = AptConfig.getProcessorOptions(jproj, isTestCode());
// options is large enough to include the translated -A options
Map<String, String> options = new HashMap<>(procOptions.size() * 2);
@@ -1009,4 +1011,5 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
public IProject getProject(){ return _javaProject.getProject(); }
public IJavaProject getJavaProject(){ return _javaProject; }
public AptProject getAptProject(){ return _aptProject; }
+ public boolean isTestCode() { return _isTestCode; }
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BinaryFileOutputStream.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BinaryFileOutputStream.java
index e6c5cca85b..a0b687b187 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BinaryFileOutputStream.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BinaryFileOutputStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -81,7 +81,7 @@ public class BinaryFileOutputStream extends ByteArrayOutputStream {
IFile parentFile = _env.getFile();
if (parentFile != null) {
- _env.getAptProject().getGeneratedFileManager().addGeneratedFileDependency(Collections.singleton(parentFile), _file);
+ _env.getAptProject().getGeneratedFileManager(_env.isTestCode()).addGeneratedFileDependency(Collections.singleton(parentFile), _file);
_env.addGeneratedNonSourceFile(_file);
}
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java
index 91510b9292..6a306b9b89 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -89,14 +89,15 @@ public class BuildEnv extends AbstractCompilationEnv
* @param additionalFiles
* @param units
* @param javaProj
+ * @param isTestCode
* @param phase
*/
BuildEnv(
final BuildContext[] filesWithAnnotations,
final BuildContext[] additionalFiles,
- final IJavaProject javaProj) {
+ final IJavaProject javaProj, boolean isTestCode) {
- super(null, null, javaProj, Phase.BUILD);
+ super(null, null, javaProj, Phase.BUILD, isTestCode);
_filer = new BuildFilerImpl(this);
_filesWithAnnotation = filesWithAnnotations;
_additionFiles = additionalFiles;
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildFilerImpl.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildFilerImpl.java
index 0ce8dd685b..f35c671dcf 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildFilerImpl.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildFilerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 BEA Systems, Inc.
+ * Copyright (c) 2006, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -61,7 +61,7 @@ public class BuildFilerImpl extends FilerImpl {
return new NoOpOutputStream();
}
- GeneratedSourceFolderManager gsfm = _env.getAptProject().getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager gsfm = _env.getAptProject().getGeneratedSourceFolderManager(_env.isTestCode());
IPath path;
try
{
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/FilerImpl.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/FilerImpl.java
index e46500f09c..b188f5970b 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/FilerImpl.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/FilerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -67,7 +67,7 @@ public abstract class FilerImpl implements Filer {
protected IPath getOutputFileForLocation( Filer.Location loc, String pkg, File relPath )
throws IOException
{
- GeneratedSourceFolderManager gsfm = getEnv().getAptProject().getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager gsfm = getEnv().getAptProject().getGeneratedSourceFolderManager(getEnv().isTestCode());
IPath path = null;
if ( loc == Filer.Location.CLASS_TREE )
{
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/JavaSourceFilePrintWriter.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/JavaSourceFilePrintWriter.java
index fe4d15eed7..012d0f2652 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/JavaSourceFilePrintWriter.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/JavaSourceFilePrintWriter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -47,7 +47,7 @@ public class JavaSourceFilePrintWriter extends PrintWriter {
try {
String contents = _sw.toString();
super.close();
- GeneratedFileManager gfm = _env.getAptProject().getGeneratedFileManager();
+ GeneratedFileManager gfm = _env.getAptProject().getGeneratedFileManager(_env.isTestCode());
Phase phase = _env.getPhase();
FileGenerationResult result = null;
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/ReconcileEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/ReconcileEnv.java
index 1422214990..078ebf053d 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/ReconcileEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/ReconcileEnv.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@ import org.eclipse.jdt.apt.core.env.EclipseAnnotationProcessorEnvironment;
import org.eclipse.jdt.apt.core.env.Phase;
import org.eclipse.jdt.apt.core.internal.AptPlugin;
import org.eclipse.jdt.apt.core.internal.env.MessagerImpl.Severity;
+import org.eclipse.jdt.apt.core.internal.util.TestCodeUtil;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.compiler.ReconcileContext;
@@ -42,21 +43,21 @@ public class ReconcileEnv extends AbstractCompilationEnv implements EclipseAnnot
final ICompilationUnit workingCopy = context.getWorkingCopy();
IJavaProject javaProject = workingCopy.getJavaProject();
final IFile file = (IFile)workingCopy.getResource();
- return new ReconcileEnv(context, workingCopy, file, javaProject);
+ return new ReconcileEnv(context, workingCopy, file, javaProject, TestCodeUtil.isTestCode(workingCopy));
}
private ReconcileEnv(
ReconcileContext context,
ICompilationUnit workingCopy,
IFile file,
- IJavaProject javaProj)
+ IJavaProject javaProj, boolean isTestCode)
{
// See bug 133744: calling ReconcileContext.getAST3() here would result in
// a typesystem whose types are not comparable with the types we get after
// openPipeline(). Instead, we start the env with an EMPTY_AST_UNIT, and
// replace it with the real thing inside the openPipeline() ASTRequestor's
// acceptAST() callback.
- super(EMPTY_AST_UNIT, file, javaProj, Phase.RECONCILE);
+ super(EMPTY_AST_UNIT, file, javaProj, Phase.RECONCILE, isTestCode);
_context = context;
_workingCopy = workingCopy;
if (AptPlugin.DEBUG_COMPILATION_ENV) AptPlugin.trace(
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/ClasspathUtil.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/ClasspathUtil.java
index b46c8abdb7..56bc9659f4 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/ClasspathUtil.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/ClasspathUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -145,8 +145,10 @@ public class ClasspathUtil {
/**
* returns true if we updated the classpath, false otherwise
+ * @param specificOutputLocation
+ * @param
*/
- public static boolean updateProjectClasspath( IJavaProject jp, IFolder folder, IProgressMonitor progressMonitor )
+ public static boolean updateProjectClasspath( IJavaProject jp, IFolder folder, IProgressMonitor progressMonitor, boolean isTestCode, IPath specificOutputLocation )
throws JavaModelException
{
IClasspathEntry[] cp = jp.getRawClasspath();
@@ -196,10 +198,13 @@ public class ClasspathUtil {
}
IPath[] exclusionPatterns = exclusions.toArray( new IPath[exclusions.size()] );
- final IClasspathAttribute[] attrs = new IClasspathAttribute[1];
+ final IClasspathAttribute[] attrs = new IClasspathAttribute[isTestCode ? 2 : 1];
attrs[0] = JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, Boolean.toString(true));
+ if(isTestCode) {
+ attrs[1] = JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, Boolean.toString(true));
+ }
IClasspathEntry generatedSourceClasspathEntry =
- JavaCore.newSourceEntry(folder.getFullPath(), new IPath[] {}, exclusionPatterns, null, attrs );
+ JavaCore.newSourceEntry(folder.getFullPath(), new IPath[] {}, exclusionPatterns, specificOutputLocation, attrs );
IClasspathEntry[] newCp = new IClasspathEntry[cp.length + 1];
System.arraycopy(cp, 0, newCp, 0, cp.length);
@@ -212,6 +217,18 @@ public class ClasspathUtil {
return !found;
}
+ public static IPath findTestOutputLocation(IClasspathEntry[] cp) {
+ for (IClasspathEntry entry : cp) {
+ if(entry.getEntryKind()==IClasspathEntry.CPE_SOURCE && entry.isTest()) {
+ IPath outputLocation = entry.getOutputLocation();
+ if(outputLocation != null) {
+ return outputLocation;
+ }
+ }
+ }
+ return null;
+ }
+
/**
* All methods static. Clients should not instantiate this class.
*/
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileManager.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileManager.java
index 47690dc743..48671c290a 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileManager.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc. and others
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -317,7 +317,7 @@ public class GeneratedFileManager
public GeneratedFileManager(final AptProject aptProject, final GeneratedSourceFolderManager gsfm) {
_jProject = aptProject.getJavaProject();
_gsfm = gsfm;
- _buildDeps = new GeneratedFileMap(_jProject.getProject());
+ _buildDeps = new GeneratedFileMap(_jProject.getProject(), gsfm.isTestCode());
_clearDuringReconcile = new HashSet<>();
_reconcileDeps = new ManyToMany<>();
_reconcileNonDeps = new ManyToMany<>();
@@ -346,11 +346,13 @@ public class GeneratedFileManager
{
try {
// clear out any generated source folder config markers
- IMarker[] markers = _jProject.getProject().findMarkers(AptPlugin.APT_CONFIG_PROBLEM_MARKER, true,
- IResource.DEPTH_INFINITE);
- if (markers != null) {
- for (IMarker marker : markers)
- marker.delete();
+ if(!_gsfm.isTestCode()) {
+ IMarker[] markers = _jProject.getProject().findMarkers(AptPlugin.APT_CONFIG_PROBLEM_MARKER, true,
+ IResource.DEPTH_INFINITE);
+ if (markers != null) {
+ for (IMarker marker : markers)
+ marker.delete();
+ }
}
} catch (CoreException e) {
AptPlugin.log(e, "Unable to delete configuration marker."); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileMap.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileMap.java
index 49d5fb1f3f..aa7d456f0d 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileMap.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedFileMap.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 BEA Systems, Inc.
+ * Copyright (c) 2006, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -50,9 +50,12 @@ public class GeneratedFileMap extends ManyToMany<IFile, IFile> {
private final IProject _proj;
private final Map<IFile, Set<Flags>> _flags = new HashMap<>();
+
+ private final boolean _isTestCode;
- public GeneratedFileMap(IProject proj) {
+ public GeneratedFileMap(IProject proj, boolean isTestCode) {
_proj = proj;
+ _isTestCode = isTestCode;
readState();
}
@@ -114,7 +117,7 @@ public class GeneratedFileMap extends ManyToMany<IFile, IFile> {
*/
public synchronized void clearState() {
clear();
- File state = getStateFile(_proj);
+ File state = getStateFile(_proj, _isTestCode);
if (state != null) {
boolean successfullyDeleted = state.delete();
if (!successfullyDeleted && state.exists()) {
@@ -188,11 +191,12 @@ public class GeneratedFileMap extends ManyToMany<IFile, IFile> {
/**
* Returns the File to use for saving and restoring the last built state for the given project.
* Returns null if the project does not exists (e.g. has been deleted)
+ * @param isTestCode
*/
- private File getStateFile(IProject project) {
+ private File getStateFile(IProject project, boolean isTestCode) {
if (!project.exists()) return null;
IPath workingLocation = project.getWorkingLocation(AptPlugin.PLUGIN_ID);
- return workingLocation.append("state.dat").toFile(); //$NON-NLS-1$
+ return workingLocation.append(isTestCode ? "teststate.dat" : "state.dat").toFile(); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -211,7 +215,7 @@ public class GeneratedFileMap extends ManyToMany<IFile, IFile> {
* This method is not synchronized because it is called only from this object's constructor.
*/
private void readState() {
- File file = getStateFile(_proj);
+ File file = getStateFile(_proj, _isTestCode);
if (file == null || !file.exists()) {
// We'll just start with no dependencies
return;
@@ -288,7 +292,7 @@ public class GeneratedFileMap extends ManyToMany<IFile, IFile> {
if (!isDirty()) {
return;
}
- File file = getStateFile(_proj);
+ File file = getStateFile(_proj, _isTestCode);
if (file == null) {
// Cannot write state, as project has been deleted
return;
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedResourceChangeListener.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedResourceChangeListener.java
index 31e3aba84c..788fb0f734 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedResourceChangeListener.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedResourceChangeListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -90,7 +90,8 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
}
event.getDelta().accept( pbv );
- addGeneratedSrcFolderTo(pbv.getProjectsThatNeedGenSrcFolder());
+ addGeneratedSrcFolderTo(pbv.getProjectsThatNeedGenSrcFolder(), false);
+ addGeneratedSrcFolderTo(pbv.getProjectsThatNeedGenTestSrcFolder(), true);
// Now clear the set of deleted resources,
// as we don't want to re-handle them
@@ -115,12 +116,12 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
}
}
- private void addGeneratedSrcFolderTo(final Set<IProject> projs ){
+ private void addGeneratedSrcFolderTo(final Set<IProject> projs, boolean isTestCode){
for(IProject proj : projs ){
final IJavaProject javaProj = JavaCore.create(proj);
if(javaProj.getProject().isOpen() && AptConfig.isEnabled(javaProj)){
- final GeneratedSourceFolderManager gsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ final GeneratedSourceFolderManager gsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(isTestCode);
gsfm.ensureFolderExists();
}
}
@@ -153,6 +154,8 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
{
// projects that we need to add the generated source folder to.
private final Set<IProject> _addGenFolderTo = new HashSet<>();
+ // projects that we need to add the generated test source folder to.
+ private final Set<IProject> _addGenTestFolderTo = new HashSet<>();
// any projects that is closed or about to be deleted
private final Set<IProject> _removedProjects = new HashSet<>();
@Override
@@ -173,6 +176,7 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
final IProject proj = (IProject)delta.getResource();
if( canUpdate(proj) ){
_addGenFolderTo.add(proj);
+ _addGenTestFolderTo.add(proj);
}
else
_removedProjects.add(proj);
@@ -189,13 +193,14 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
final IJavaProject javaProj = JavaCore.create(project);
final AptProject aptProj = AptPlugin.getAptProject(javaProj);
if( resource instanceof IFile ){
- final GeneratedFileManager gfm = aptProj.getGeneratedFileManager();
+ final GeneratedFileManager gfm = aptProj.getGeneratedFileManager(false);
IFile f = (IFile)resource;
gfm.fileDeleted(f);
+ aptProj.getGeneratedFileManager(true).fileDeleted(f);
}
else if( resource instanceof IFolder ){
- final GeneratedSourceFolderManager gsfm = aptProj.getGeneratedSourceFolderManager();
IFolder f = (IFolder) resource;
+ final GeneratedSourceFolderManager gsfm = aptProj.getGeneratedSourceFolderManager(false);
if ( gsfm.isGeneratedSourceFolder( f ) ){
gsfm.folderDeleted();
// all deletion occurs before any add (adding the generated source directory)
@@ -206,6 +211,17 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
// deleted, will ignore this deletion since we cannot correct
// the classpath anyways.
}
+ final GeneratedSourceFolderManager testgsfm = aptProj.getGeneratedSourceFolderManager(true);
+ if ( testgsfm.isGeneratedSourceFolder( f ) ){
+ testgsfm.folderDeleted();
+ // all deletion occurs before any add (adding the generated source directory)
+ if( !_removedProjects.contains(project) ){
+ _addGenTestFolderTo.add(project);
+ }
+ // if the project is already closed or in the process of being
+ // deleted, will ignore this deletion since we cannot correct
+ // the classpath anyways.
+ }
}
else if( resource instanceof IProject ){
_removedProjects.add((IProject)resource);
@@ -216,7 +232,12 @@ public class GeneratedResourceChangeListener implements IResourceChangeListener
_addGenFolderTo.removeAll(_removedProjects);
return _addGenFolderTo;
}
-
+
+ Set<IProject> getProjectsThatNeedGenTestSrcFolder(){
+ _addGenTestFolderTo.removeAll(_removedProjects);
+ return _addGenTestFolderTo;
+ }
+
private boolean canUpdate(IProject proj)
throws CoreException
{
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java
index b18c776bf6..718b6e4b83 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 BEA Systems, Inc. and others
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -84,13 +84,17 @@ public class GeneratedSourceFolderManager {
*/
private IFolder _generatedSourceFolder = null;
+ private final boolean _isTestCode;
+
+
/**
* Should be constructed only by AptProject. Other clients should call
- * @see AptProject#getGeneratedSourceFolderManager() to get this object.
+ * @see AptProject#getGeneratedSourceFolderManager(boolean) to get this object.
*/
- public GeneratedSourceFolderManager(AptProject aptProject)
+ public GeneratedSourceFolderManager(AptProject aptProject, boolean isTestCode)
{
_aptProject = aptProject;
+ _isTestCode = isTestCode;
final IJavaProject javaProject = aptProject.getJavaProject();
// Set _generatedSourceFolder only if APT is enabled, the folder exists,
@@ -109,12 +113,13 @@ public class GeneratedSourceFolderManager {
/**
* Add the folder to the classpath, unless it's already there.
* @param srcFolder the folder to add to the classpath. Must not be null.
+ * @param specificOutputLocation
* @return true if, at the end of the routine, the folder is on the classpath.
*/
- private boolean addToClasspath(IFolder srcFolder) {
+ private boolean addToClasspath(IFolder srcFolder, IPath specificOutputLocation) {
boolean onClasspath = false;
try {
- ClasspathUtil.updateProjectClasspath( _aptProject.getJavaProject(), srcFolder, null );
+ ClasspathUtil.updateProjectClasspath( _aptProject.getJavaProject(), srcFolder, null, _isTestCode, specificOutputLocation );
if(AptPlugin.DEBUG)
AptPlugin.trace("Ensured classpath has an entry for " + srcFolder); //$NON-NLS-1$
onClasspath = true;
@@ -150,10 +155,30 @@ public class GeneratedSourceFolderManager {
return;
}
+ ensureFolderExists(srcFolder);
+ }
+
+ public void ensureFolderExists(IFolder srcFolder) {
+ IPath specificOutputLocation;
+ if (_isTestCode) {
+ IClasspathEntry[] cp;
+ try {
+ cp = _aptProject.getJavaProject().getRawClasspath();
+ } catch (JavaModelException e) {
+ return;
+ }
+ specificOutputLocation = ClasspathUtil.findTestOutputLocation(cp);
+ if (specificOutputLocation == null) {
+ // not test source folder present
+ return;
+ }
+ } else {
+ specificOutputLocation = null;
+ }
// Ensure that the new folder exists on disk.
if (createOnDisk(srcFolder)) {
// Add it to the classpath.
- if (addToClasspath(srcFolder)) {
+ if (addToClasspath(srcFolder, specificOutputLocation)) {
// Only if we get this far do we actually set _generatedSourceFolder.
synchronized ( this ) {
_generatedSourceFolder = srcFolder;
@@ -187,15 +212,7 @@ public class GeneratedSourceFolderManager {
AptPlugin.log(status);
return;
}
-
- if (createOnDisk(srcFolder)) {
- if (addToClasspath(srcFolder)) {
- synchronized (this) {
- // Only set _generatedSourceFolder if folder is on disk and on classpath.
- _generatedSourceFolder = srcFolder;
- }
- }
- }
+ ensureFolderExists(srcFolder);
}
/**
@@ -298,7 +315,7 @@ public class GeneratedSourceFolderManager {
*/
public void folderDeleted()
{
- _aptProject.projectClean( false );
+ _aptProject.projectClean( false, !_isTestCode, _isTestCode);
IFolder srcFolder;
synchronized(this){
@@ -371,7 +388,7 @@ public class GeneratedSourceFolderManager {
* means that the name is something illegal like "..".
*/
private IFolder getFolderPreference() {
- final String folderName = AptConfig.getGenSrcDir(_aptProject.getJavaProject());
+ final String folderName = _isTestCode ? AptConfig.getGenTestSrcDir(_aptProject.getJavaProject()) : AptConfig.getGenSrcDir(_aptProject.getJavaProject());
IFolder folder = null;
try {
folder = _aptProject.getJavaProject().getProject().getFolder( folderName );
@@ -425,7 +442,7 @@ public class GeneratedSourceFolderManager {
}
// Clear out the generated file maps
- _aptProject.projectClean(false);
+ _aptProject.projectClean(false, !_isTestCode, _isTestCode);
// clean up the classpath first so that when we actually delete the
// generated source folder we won't cause a classpath error.
@@ -512,4 +529,7 @@ public class GeneratedSourceFolderManager {
return succeeded;
}
+ public boolean isTestCode() {
+ return _isTestCode;
+ }
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/WorkingCopyCleanupListener.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/WorkingCopyCleanupListener.java
index 71f83fb9ef..053cd013c7 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/WorkingCopyCleanupListener.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/WorkingCopyCleanupListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,6 +14,7 @@ package org.eclipse.jdt.apt.core.internal.generatedfile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.apt.core.internal.AptPlugin;
+import org.eclipse.jdt.apt.core.internal.util.TestCodeUtil;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IElementChangedListener;
@@ -60,7 +61,7 @@ public class WorkingCopyCleanupListener implements IElementChangedListener
if ( workingCopyDiscarded )
{
IJavaProject jp = cu.getJavaProject();
- GeneratedFileManager gfm = AptPlugin.getAptProject(jp).getGeneratedFileManager();
+ GeneratedFileManager gfm = AptPlugin.getAptProject(jp).getGeneratedFileManager(TestCodeUtil.isTestCode(cu));
try {
gfm.workingCopyDiscarded( cu );
} catch (CoreException e) {
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/TestCodeUtil.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/TestCodeUtil.java
new file mode 100644
index 0000000000..4f44e64e4b
--- /dev/null
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/TestCodeUtil.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Till Brychcy and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Till Brychcy - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.apt.core.internal.util;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaModelException;
+
+public class TestCodeUtil {
+
+ private TestCodeUtil() {
+ }
+
+ public static boolean isTestCode(ICompilationUnit cu) {
+ IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) ((IJavaElement) cu)
+ .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ if (packageFragmentRoot != null) {
+ try {
+ return packageFragmentRoot.getResolvedClasspathEntry().isTest();
+ } catch (JavaModelException e) {
+ // ignore
+ }
+ }
+ return false;
+ }
+}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptConfig.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptConfig.java
index 7729a4384a..9615a792ac 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptConfig.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptConfig.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -40,6 +40,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader;
import org.eclipse.jdt.apt.core.internal.AptPlugin;
import org.eclipse.jdt.apt.core.internal.AptProject;
+import org.eclipse.jdt.apt.core.internal.generatedfile.ClasspathUtil;
import org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedSourceFolderManager;
import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
import org.eclipse.jdt.apt.core.internal.util.FactoryPathUtil;
@@ -58,6 +59,7 @@ import org.osgi.service.prefs.BackingStoreException;
*
* Helpful information about the Eclipse preferences mechanism can be found at:
* http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-core-home/documents/user_settings/faq.html
+ * @since 3.5
*/
public class AptConfig {
@@ -121,6 +123,15 @@ public class AptConfig {
}
/**
+ * @deprecated Use {@link #getProcessorOptions(IJavaProject, boolean)} or
+ * {@link #getRawProcessorOptions(IJavaProject)}
+ */
+ @Deprecated
+ public static Map<String, String> getProcessorOptions(IJavaProject jproj) {
+ return getProcessorOptions(jproj, false);
+ }
+
+ /**
* Get the options that are presented to annotation processors by the
* AnnotationProcessorEnvironment. Options are key/value pairs which
* are set in the project properties.
@@ -160,12 +171,14 @@ public class AptConfig {
* above.
*
* @param jproj a project, or null to query the workspace-wide setting.
+ * @param isTestCode if true, the programmatically set options are computed for test code compilation
* @return a mutable, possibly empty, map of (key, value) pairs.
* The value part of a pair may be null (equivalent to "-Akey" on the Sun apt
* command line).
* The value part may contain spaces.
+ * @since 3.6
*/
- public static Map<String, String> getProcessorOptions(IJavaProject jproj) {
+ public static Map<String, String> getProcessorOptions(IJavaProject jproj, boolean isTestCode) {
Map<String,String> rawOptions = getRawProcessorOptions(jproj);
// map is large enough to also include the programmatically generated options
Map<String, String> options = new HashMap<>(rawOptions.size() + 6);
@@ -195,6 +208,9 @@ public class AptConfig {
Set<IJavaProject> projectsProcessed = new HashSet<>();
projectsProcessed.add(jproj);
for (IClasspathEntry entry : classpathEntries) {
+ if (!isTestCode && entry.isTest()) {
+ continue;
+ }
int kind = entry.getEntryKind();
if (kind == IClasspathEntry.CPE_LIBRARY) {
IPath cpPath = entry.getPath();
@@ -233,7 +249,7 @@ public class AptConfig {
// If it doesn't exist, ignore it
if (otherJavaProject != null && otherJavaProject.getProject().isOpen()) {
- addProjectClasspath(root, otherJavaProject, projectsProcessed, classpath);
+ addProjectClasspath(root, otherJavaProject, projectsProcessed, classpath, isTestCode);
}
}
}
@@ -245,12 +261,12 @@ public class AptConfig {
options.put("-sourcepath", convertPathCollectionToString(sourcepath)); //$NON-NLS-1$
// Get absolute path for generated source dir
- IFolder genSrcDir = jproj.getProject().getFolder(getGenSrcDir(jproj));
+ IFolder genSrcDir = jproj.getProject().getFolder(isTestCode ? getGenTestSrcDir(jproj) : getGenSrcDir(jproj));
String genSrcDirString = genSrcDir.getRawLocation().toOSString();
options.put("-s", genSrcDirString); //$NON-NLS-1$
// Absolute path for bin dir as well
- IPath binPath = jproj.getOutputLocation();
+ IPath binPath = isTestCode ? ClasspathUtil.findTestOutputLocation(jproj.getRawClasspath()) : jproj.getOutputLocation();
IResource binPathResource = root.findMember(binPath);
String binDirString;
if (binPathResource != null) {
@@ -330,7 +346,8 @@ public class AptConfig {
IWorkspaceRoot root,
IJavaProject otherJavaProject,
Set<IJavaProject> projectsProcessed,
- Set<String> classpath) {
+ Set<String> classpath,
+ boolean isTestCode) {
// Check for cycles. If we've already seen this project,
// no need to go any further.
@@ -355,6 +372,9 @@ public class AptConfig {
// Now the rest of the classpath
IClasspathEntry[] classpathEntries = otherJavaProject.getResolvedClasspath(true);
for (IClasspathEntry entry : classpathEntries) {
+ if (!isTestCode && entry.isTest()) {
+ continue;
+ }
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath cpPath = entry.getPath();
@@ -374,7 +394,7 @@ public class AptConfig {
IProject otherProject = root.getProject(otherProjectPath.segment(0));
IJavaProject yetAnotherJavaProject = JavaCore.create(otherProject);
if (yetAnotherJavaProject != null) {
- addProjectClasspath(root, yetAnotherJavaProject, projectsProcessed, classpath);
+ addProjectClasspath(root, yetAnotherJavaProject, projectsProcessed, classpath, isTestCode);
}
}
// Ignore source types
@@ -888,7 +908,24 @@ public class AptConfig {
}
setString(jproject, AptPreferenceConstants.APT_GENSRCDIR, dirString);
}
+
+ /**
+ * @since 3.6
+ */
+ public static String getGenTestSrcDir(IJavaProject jproject) {
+ return getString(jproject, AptPreferenceConstants.APT_GENTESTSRCDIR);
+ }
+ /**
+ * @since 3.6
+ */
+ public static void setGenTestSrcDir(IJavaProject jproject, String dirString) {
+ if (!GeneratedSourceFolderManager.validate(jproject, dirString)) {
+ throw new IllegalArgumentException("Illegal name for generated test source folder: " + dirString); //$NON-NLS-1$
+ }
+ setString(jproject, AptPreferenceConstants.APT_GENTESTSRCDIR, dirString);
+ }
+
public static boolean validateGenSrcDir(IJavaProject jproject, String dirName) {
return GeneratedSourceFolderManager.validate(jproject, dirName);
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java
index ab18c4ce32..afcdc751de 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,6 +23,10 @@ import java.util.Map;
public class AptPreferenceConstants {
public static final String APT_STRING_BASE = "org.eclipse.jdt.apt"; //$NON-NLS-1$
public static final String APT_GENSRCDIR = APT_STRING_BASE + ".genSrcDir"; //$NON-NLS-1$
+ /**
+ * @since 3.6
+ */
+ public static final String APT_GENTESTSRCDIR = APT_STRING_BASE + ".genTestSrcDir"; //$NON-NLS-1$
public static final String APT_PROCESSOROPTIONS = APT_STRING_BASE + ".processorOptions"; //$NON-NLS-1$
public static final String APT_RECONCILEENABLED = APT_STRING_BASE + ".reconcileEnabled"; //$NON-NLS-1$
public static final String APT_PROCESSANNOTATIONS = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$
@@ -37,6 +41,10 @@ public class AptPreferenceConstants {
public static final String APT_NULLVALUE = APT_STRING_BASE + ".NULLVALUE"; //$NON-NLS-1$
public static final String DEFAULT_GENERATED_SOURCE_FOLDER_NAME = ".apt_generated"; //$NON-NLS-1$
+ /**
+ * @since 3.6
+ */
+ public static final String DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME = ".apt_generated_tests"; //$NON-NLS-1$
/**
* Processors should report this option in {@link com.sun.mirror.apt.AnnotationProcessorFactory#supportedOptions()}
@@ -61,6 +69,7 @@ public class AptPreferenceConstants {
Map<String,String> options = new HashMap<>();
options.put(AptPreferenceConstants.APT_ENABLED, "false"); //$NON-NLS-1$
options.put(AptPreferenceConstants.APT_GENSRCDIR, DEFAULT_GENERATED_SOURCE_FOLDER_NAME);
+ options.put(AptPreferenceConstants.APT_GENTESTSRCDIR, DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME);
options.put(AptPreferenceConstants.APT_PROCESSOROPTIONS, ""); //$NON-NLS-1$
options.put(AptPreferenceConstants.APT_RECONCILEENABLED, "true"); //$NON-NLS-1$
DEFAULT_OPTIONS_MAP = Collections.unmodifiableMap(options);
@@ -76,6 +85,7 @@ public class AptPreferenceConstants {
public static final String[] OPTION_NAMES = {
APT_ENABLED,
APT_GENSRCDIR,
+ APT_GENTESTSRCDIR,
APT_PROCESSOROPTIONS,
APT_RECONCILEENABLED,
};
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeAnnotationProcessorManager.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeAnnotationProcessorManager.java
index 12cfc0c66e..aa5a29e5da 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeAnnotationProcessorManager.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeAnnotationProcessorManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 BEA Systems, Inc and others.
+ * Copyright (c) 2007, 2018 BEA Systems, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -60,7 +60,7 @@ public class IdeAnnotationProcessorManager extends BaseAnnotationProcessorManage
* Eclipse platform code.)
*/
@Override
- public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject) {
+ public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject, boolean isTestCode) {
_javaProject = (IJavaProject) javaProject;
_cuLocator = (ICompilationUnitLocator) compilationUnitLocator;
if (null != _processingEnv) {
@@ -69,9 +69,9 @@ public class IdeAnnotationProcessorManager extends BaseAnnotationProcessorManage
}
// If it's a CompilationUnitProblemFinder, we're in reconcile phase. Else it's build.
if (compiler instanceof CompilationUnitProblemFinder) {
- _processingEnv = new IdeReconcileProcessingEnvImpl(this, _javaProject, compiler);
+ _processingEnv = new IdeReconcileProcessingEnvImpl(this, _javaProject, compiler, isTestCode);
} else {
- _processingEnv = new IdeBuildProcessingEnvImpl(this, _javaProject, compiler);
+ _processingEnv = new IdeBuildProcessingEnvImpl(this, _javaProject, compiler, isTestCode);
}
if (Apt6Plugin.DEBUG) {
Apt6Plugin.trace("Java 6 annotation processor manager initialized for compiler " +
@@ -135,5 +135,4 @@ public class IdeAnnotationProcessorManager extends BaseAnnotationProcessorManage
super.processAnnotations(units, referenceBindings, isLastRound);
}
}
-
}
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeBuildProcessingEnvImpl.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeBuildProcessingEnvImpl.java
index 94e1437e92..f173d8f182 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeBuildProcessingEnvImpl.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeBuildProcessingEnvImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc.
+ * Copyright (c) 2007, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,8 +23,8 @@ import org.eclipse.jdt.internal.compiler.Compiler;
public class IdeBuildProcessingEnvImpl extends IdeProcessingEnvImpl {
public IdeBuildProcessingEnvImpl(IdeAnnotationProcessorManager dispatchManager,
- IJavaProject jproject, Compiler compiler) {
- super(dispatchManager, jproject, compiler);
+ IJavaProject jproject, Compiler compiler, boolean isTestCode) {
+ super(dispatchManager, jproject, compiler, isTestCode);
}
@Override
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeProcessingEnvImpl.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeProcessingEnvImpl.java
index 632963cf15..396ef9e791 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeProcessingEnvImpl.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeProcessingEnvImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 - 2017 BEA Systems, Inc and others.
+ * Copyright (c) 2007 - 2018 BEA Systems, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -52,13 +52,15 @@ public abstract class IdeProcessingEnvImpl extends BaseProcessingEnvImpl {
private final IdeAnnotationProcessorManager _dispatchManager;
private final IJavaProject _javaProject;
protected final AptProject _aptProject;
+ private final boolean _isTestCode;
public IdeProcessingEnvImpl(IdeAnnotationProcessorManager dispatchManager,
- IJavaProject jproject, Compiler compiler)
+ IJavaProject jproject, Compiler compiler, boolean isTestCode)
{
_dispatchManager = dispatchManager;
_javaProject = jproject;
_compiler = compiler;
+ this._isTestCode = isTestCode;
_aptProject = AptPlugin.getAptProject(jproject);
_filer = new IdeFilerImpl(_dispatchManager, this);
_messager = new IdeMessagerImpl(_dispatchManager, this);
@@ -78,7 +80,7 @@ public abstract class IdeProcessingEnvImpl extends BaseProcessingEnvImpl {
// Java 5 processor options include items on the command line such as -s,
// -classpath, etc., but Java 6 options only include the options specified
// with -A, which will have been parsed into key/value pairs with no dash.
- Map<String, String> allOptions = AptConfig.getProcessorOptions(_javaProject);
+ Map<String, String> allOptions = AptConfig.getProcessorOptions(_javaProject, isTestCode());
// But we make them available as variables in processor options configured by users
// (e.g. %classpath% in an option value is replaced with the value of -classpath):
@@ -177,4 +179,7 @@ public abstract class IdeProcessingEnvImpl extends BaseProcessingEnvImpl {
return false;
}
+ public boolean isTestCode() {
+ return _isTestCode;
+ }
}
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeReconcileProcessingEnvImpl.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeReconcileProcessingEnvImpl.java
index 128c8b0a3a..d2de0f03ae 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeReconcileProcessingEnvImpl.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeReconcileProcessingEnvImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc.
+ * Copyright (c) 2007, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,8 +23,8 @@ import org.eclipse.jdt.internal.compiler.Compiler;
public class IdeReconcileProcessingEnvImpl extends IdeProcessingEnvImpl {
public IdeReconcileProcessingEnvImpl(IdeAnnotationProcessorManager dispatchManager,
- IJavaProject jproject, Compiler compiler) {
- super(dispatchManager, jproject, compiler);
+ IJavaProject jproject, Compiler compiler, boolean isTestCode) {
+ super(dispatchManager, jproject, compiler, isTestCode);
}
@Override
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
index 54c3ee2f96..309fd8652f 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 - 2010 BEA Systems, Inc. and others
+ * Copyright (c) 2007 - 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -124,7 +124,7 @@ public class IdeFilerImpl implements Filer {
if (null == name) {
throw new IllegalArgumentException("Name is null");
}
- IFile file = _env.getAptProject().getGeneratedFileManager().getIFileForTypeName(name.toString());
+ IFile file = _env.getAptProject().getGeneratedFileManager(_env.isTestCode()).getIFileForTypeName(name.toString());
if (AptCompilationParticipant.getInstance().getJava6GeneratedFiles().contains(file)) {
throw new FilerException("Source file already created: " + file.getFullPath()); //$NON-NLS-1$
}
@@ -165,7 +165,7 @@ public class IdeFilerImpl implements Filer {
protected IFile getFileFromOutputLocation( Location loc, CharSequence pkg, CharSequence relPath )
throws IOException
{
- GeneratedSourceFolderManager gsfm = _env.getAptProject().getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager gsfm = _env.getAptProject().getGeneratedSourceFolderManager(_env.isTestCode());
IPath path = null;
if ( loc == StandardLocation.CLASS_OUTPUT )
{
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java
index 3fd15d187b..c3ef71d45b 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc.
+ * Copyright (c) 2007, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -55,7 +55,7 @@ public class IdeJavaSourceOutputStream extends ByteArrayOutputStream {
_closed = true;
}
try {
- GeneratedFileManager gfm = _env.getAptProject().getGeneratedFileManager();
+ GeneratedFileManager gfm = _env.getAptProject().getGeneratedFileManager(_env.isTestCode());
Phase phase = _env.getPhase();
FileGenerationResult result = null;
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeNonSourceOutputStream.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeNonSourceOutputStream.java
index b6acde8818..bb480081c3 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeNonSourceOutputStream.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeNonSourceOutputStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 BEA Systems, Inc.
+ * Copyright (c) 2007, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -83,7 +83,7 @@ public class IdeNonSourceOutputStream extends ByteArrayOutputStream
// If there are no parents, we don't need to track dependencies
if (_parentFiles != null && !_parentFiles.isEmpty()) {
- _env.getAptProject().getGeneratedFileManager().addGeneratedFileDependency(_parentFiles, _file);
+ _env.getAptProject().getGeneratedFileManager(_env.isTestCode()).addGeneratedFileDependency(_parentFiles, _file);
_env.addNewResource(_file);
}
}
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java
index 7330a148e4..a824825dd8 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 BEA Systems, Inc. and others
+ * Copyright (c) 2007, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -102,7 +102,7 @@ public class IdeOutputJavaFileObject extends IdeOutputFileObject implements Java
*/
@Override
public URI toUri() {
- IFile file = _env.getAptProject().getGeneratedFileManager().getIFileForTypeName(_name.toString());
+ IFile file = _env.getAptProject().getGeneratedFileManager(_env.isTestCode()).getIFileForTypeName(_name.toString());
return file.getLocationURI();
}
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java
index 77b8b6bf6a..1fbd644e88 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -25,6 +25,7 @@ import org.eclipse.jdt.apt.tests.annotations.BaseProcessor;
import org.eclipse.jdt.apt.tests.annotations.ProcessorTestStatus;
import org.eclipse.jdt.apt.tests.annotations.generic.GenericFactory;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.builder.BuilderTests;
import org.eclipse.jdt.core.tests.builder.Problem;
import org.eclipse.jdt.core.tests.util.Util;
@@ -101,6 +102,17 @@ public abstract class APTTestBase extends BuilderTests{
return javaProj;
}
+ /**
+ * Add a test source folder to the current project and return it
+ * @return IPath
+ * @throws JavaModelException
+ */
+ protected IPath addTestSourceFolder() throws JavaModelException {
+ IJavaProject currentJavaProject = getCurrentJavaProject();
+ return env.addPackageFragmentRoot(currentJavaProject.getPath(), "src-tests", null, null,
+ "bin-tests", true);
+ }
+
protected void tearDown()
throws Exception
{
@@ -130,7 +142,7 @@ public abstract class APTTestBase extends BuilderTests{
IPath srcRoot = srcFolder.getFullPath();
return srcRoot;
}
-
+
private String concate(String[] messages){
final int len = messages == null ? 0 : messages.length;
StringBuilder buffer = new StringBuilder();
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java
index dd3efcd0e9..f871f00e11 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 BEA Systems, Inc. and others
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -698,7 +698,7 @@ public class AptBuilderTests extends APTTestBase
expectingNoProblems();
expectingNoMarkers();
- GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(false);
IFolder srcFolder = mgr.getFolder();
assertEquals(true, srcFolder.exists());
// delete the gen source folder
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java
index 423e57bd72..95b7e5457f 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -318,7 +318,7 @@ public class AptReconcileTests extends ModifyingResourceTests
assertProblems( "UnexpectedProblems", "" );
IJavaProject jp = _workingCopy.getJavaProject();
- GeneratedFileManager gfm = AptPlugin.getAptProject(jp).getGeneratedFileManager();
+ GeneratedFileManager gfm = AptPlugin.getAptProject(jp).getGeneratedFileManager(false);
if ( !gfm.containsWorkingCopyMapEntriesForParent((IFile)_workingCopy.getResource()))
fail( "Expected to find map entries in GeneratedFileManager");
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java
index 9078503f56..6bff09ee1b 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -105,7 +105,7 @@ public class FileGenerationTests extends APTTestBase {
fullBuild( project.getFullPath() );
expectingNoProblems();
- Map<String,String> options = AptConfig.getProcessorOptions(jproj);
+ Map<String,String> options = AptConfig.getProcessorOptions(jproj, false);
String sourcepath = options.get("-sourcepath");
assertTrue(sourcepath.contains("__foo_src"));
@@ -159,7 +159,7 @@ public class FileGenerationTests extends APTTestBase {
expectingNoProblems();
// Look for the file
- Map<String,String> options = AptConfig.getProcessorOptions(JavaCore.create(project));
+ Map<String,String> options = AptConfig.getProcessorOptions(JavaCore.create(project), false);
// We'll find it in the binary output directory
String outputRootPath = options.get("-d");
File theFile = new File(new File(outputRootPath), TEXT_FILE_NAME);
@@ -219,7 +219,7 @@ public class FileGenerationTests extends APTTestBase {
expectingNoProblems();
AptProject aptProj = new AptProject(env.getJavaProject(getProjectName()));
- GeneratedFileManager gfm = aptProj.getGeneratedFileManager();
+ GeneratedFileManager gfm = aptProj.getGeneratedFileManager(false);
String genSrcDir = AptConfig.getGenSrcDir(env.getJavaProject(getProjectName()));
String P = File.separator;
@@ -229,4 +229,80 @@ public class FileGenerationTests extends APTTestBase {
assertTrue("expected src/test/Test.java to be designated as parent file", gfm.isParentFile(parentFile));
assertTrue("expected .apt_generated/test/A.java to be designated as generated file", gfm.isGeneratedFile(generatedFile));
}
+
+ public void testTestSourceGen() throws Exception
+ {
+ IJavaProject jproj = env.getJavaProject( getProjectName() );
+ IProject project = env.getProject( getProjectName() );
+ IPath srcRoot = getSourcePath();
+
+ String mainCode =
+ "package test;" + "\n" +
+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;" + "\n" +
+ "@HelloWorldAnnotation(\"GeneratedFileMain\")" + "\n" +
+ "public class Main" + "\n" +
+ "{" + "\n" +
+ " generatedfilepackage.GeneratedFileMain gfm;" + "\n" +
+ "}";
+ String testCode =
+ "package test;" + "\n" +
+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;" + "\n" +
+ "@HelloWorldAnnotation" + "\n" +
+ "public class Test" + "\n" +
+ "{" + "\n" +
+ " generatedfilepackage.GeneratedFileTest gft;" + "\n" +
+ " generatedfilepackage.GeneratedFileMain gfm;" + "\n" +
+ "}";
+
+ AptConfig.setGenSrcDir(jproj, "__main_foo_src");
+ AptConfig.setGenTestSrcDir(jproj, "__test_foo_src");
+
+ IPath testSrcRoot = addTestSourceFolder();
+
+ env.addClass(srcRoot, "test", "Main", mainCode);
+ env.addClass(testSrcRoot, "test", "Test", testCode);
+
+ fullBuild( project.getFullPath() );
+ expectingNoProblems();
+
+ assertTrue(AptConfig.getProcessorOptions(jproj, false).get("-sourcepath").contains("__main_foo_src"));
+ assertTrue(AptConfig.getProcessorOptions(jproj, true).get("-sourcepath").contains("__test_foo_src"));
+ assertEquals(ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
+
+ String P = File.separator;
+
+ AptProject aptProj = new AptProject(env.getJavaProject(getProjectName()));
+ GeneratedFileManager maingfm = aptProj.getGeneratedFileManager(false);
+ GeneratedFileManager testgfm = aptProj.getGeneratedFileManager(true);
+
+ IFile mainParentFile = project.getFile("src" + P + "test" + P + "Main.java");
+ IFile mainGeneratedFile = project.getFile("__main_foo_src" + P + "generatedfilepackage" + P + "GeneratedFileMain.java");
+
+ IFile testParentFile = project.getFile("src-tests" + P + "test" + P + "Test.java");
+ IFile testGeneratedFile = project.getFile("__test_foo_src" + P + "generatedfilepackage" + P + "GeneratedFileTest.java");
+
+ assertTrue("expected "
+ + mainParentFile.getProjectRelativePath()
+ + " to be designated as main parent file", maingfm.isParentFile(mainParentFile));
+ assertTrue("expected " + mainGeneratedFile.getProjectRelativePath()
+ + " to be designated as main generated file", maingfm.isGeneratedFile(mainGeneratedFile));
+ assertFalse("expected "
+ + testParentFile.getProjectRelativePath()
+ + " not to be designated as main parent file", maingfm.isParentFile(testParentFile));
+ assertFalse("expected " + testGeneratedFile.getProjectRelativePath()
+ + " not to be designated as main generated file", maingfm.isGeneratedFile(testGeneratedFile));
+
+ assertTrue("expected "
+ + testParentFile.getProjectRelativePath()
+ + " to be designated as test parent file", testgfm.isParentFile(testParentFile));
+ assertTrue("expected " + testGeneratedFile.getProjectRelativePath()
+ + " to be designated as test generated file", testgfm.isGeneratedFile(testGeneratedFile));
+ assertFalse("expected "
+ + mainParentFile.getProjectRelativePath()
+ + " not to be designated as test parent file", testgfm.isParentFile(mainParentFile));
+ assertFalse("expected " + mainGeneratedFile.getProjectRelativePath()
+ + " not to be designated as test generated file", testgfm.isGeneratedFile(mainGeneratedFile));
+
+ }
+
}
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java
index ff4ded6041..64bd1ba8c8 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -179,7 +179,7 @@ public class PreferencesTests extends APTTestBase {
AptConfig.addProcessorOption(jproj, "space", "\"text with spaces\"");
AptConfig.addProcessorOption(jproj, "quux", null);
AptConfig.addProcessorOption(jproj, "quux", null); // adding twice should have no effect
- Map<String, String> options = AptConfig.getProcessorOptions(jproj);
+ Map<String, String> options = AptConfig.getProcessorOptions(jproj, false);
String val = options.get("foo");
assertEquals(val, "bar");
val = options.get("quux");
@@ -187,7 +187,7 @@ public class PreferencesTests extends APTTestBase {
val = options.get("space");
assertEquals(val, "\"text with spaces\"");
AptConfig.removeProcessorOption(jproj, "foo");
- options = AptConfig.getProcessorOptions(jproj);
+ options = AptConfig.getProcessorOptions(jproj, false);
assertFalse(options.containsKey("foo"));
assertTrue(options.containsKey("quux"));
AptConfig.removeProcessorOption(jproj, "quux");
@@ -196,7 +196,7 @@ public class PreferencesTests extends APTTestBase {
AptConfig.addProcessorOption(null, "workspace option", "corresponding value");
AptConfig.addProcessorOption(null, "foo", "whatever");
AptConfig.removeProcessorOption(null, "foo");
- options = AptConfig.getProcessorOptions(null);
+ options = AptConfig.getProcessorOptions(null, false);
assertFalse(options.containsKey("foo"));
assertTrue(options.containsKey("workspace option"));
AptConfig.removeProcessorOption(null, "workspace option");
@@ -207,7 +207,7 @@ public class PreferencesTests extends APTTestBase {
*/
public void testAutomaticOptions() throws Exception {
IJavaProject jproj = env.getJavaProject( getProjectName() );
- Map<String,String> options = AptConfig.getProcessorOptions(jproj);
+ Map<String,String> options = AptConfig.getProcessorOptions(jproj, false);
String classpath = options.get("-classpath");
assertNotNull(classpath);
@@ -235,13 +235,19 @@ public class PreferencesTests extends APTTestBase {
public void testGenSrcDir() throws Exception {
IJavaProject jproj = env.getJavaProject( getProjectName() );
String genSrcDir = AptConfig.getGenSrcDir(jproj);
+ String genTestSrcDir = AptConfig.getGenTestSrcDir(jproj);
assertEquals(AptPreferenceConstants.DEFAULT_GENERATED_SOURCE_FOLDER_NAME, genSrcDir);
+ assertEquals(AptPreferenceConstants.DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME, genTestSrcDir);
final String newDir = "gen/src";
+ final String newTestDir = "gen/src-tests";
AptConfig.setGenSrcDir(jproj, newDir);
+ AptConfig.setGenTestSrcDir(jproj, newTestDir);
genSrcDir = AptConfig.getGenSrcDir(jproj);
+ genTestSrcDir = AptConfig.getGenTestSrcDir(jproj);
assertEquals(newDir, genSrcDir);
+ assertEquals(newTestDir, genTestSrcDir);
}
@@ -264,56 +270,104 @@ public class PreferencesTests extends APTTestBase {
boolean aptEnabled = AptConfig.isEnabled(javaProj);
// test 1: make sure apt is disabled by default
assertEquals(false, aptEnabled);
- final GeneratedSourceFolderManager gsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ final GeneratedSourceFolderManager gsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(false);
+ final GeneratedSourceFolderManager testgsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(true);
IFolder srcFolder = gsfm.getFolder();
+ IFolder testSrcFolder = testgsfm.getFolder();
String folderName = srcFolder.getProjectRelativePath().toOSString();
+ String testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
// test 2: apt is disabled, then folder should not exists
assertEquals(srcFolder.exists(), false);
+ assertEquals(testSrcFolder.exists(), false);
+
// test 3: folder name has not been configured, then it should be the default.
// folder name should be the default name.
assertEquals(folderName, AptPreferenceConstants.DEFAULT_GENERATED_SOURCE_FOLDER_NAME);
+ assertEquals(testFolderName, AptPreferenceConstants.DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME);
// set folder name while apt is disabled
String newName = ".gensrcdir";
+ String newTestName = ".gentestsrcdir";
+
AptConfig.setGenSrcDir(javaProj, newName);
+ AptConfig.setGenTestSrcDir(javaProj, newTestName);
+
srcFolder = gsfm.getFolder();
+ testSrcFolder = testgsfm.getFolder();
+
folderName = srcFolder.getProjectRelativePath().toOSString();
+ testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
+
// test 4: apt still disabled but folder name changed, make sure the folder is not on disk.
assertEquals(false, srcFolder.exists());
+ assertEquals(false, testSrcFolder.exists());
+
// test 5: make sure we got the new name
assertEquals(newName, folderName);
+ assertEquals(newTestName, testFolderName);
+
// test 6: make sure the source folder is not on the classpath.
assertEquals( false, isOnClasspath(javaProj, srcFolder.getFullPath()) );
+ assertEquals( false, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
// enable apt
AptConfig.setEnabled(javaProj, true);
aptEnabled = AptConfig.isEnabled(javaProj);
// test 7: make sure it's enabled after we called the API to enable it.
assertEquals(true, aptEnabled);
- srcFolder = gsfm.getFolder();
+ srcFolder = gsfm.getFolder();
+ testSrcFolder = testgsfm.getFolder();
+
folderName = srcFolder.getProjectRelativePath().toOSString();
+ testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
+
// test 8: apt enabled, the source folder should be on disk
assertEquals(true, srcFolder.exists());
+ // generated test source folder should NOT exist, as the project has no test source folder
+ assertEquals(false, testSrcFolder.exists());
+
// test 9: make sure the name matches
assertEquals(newName, folderName);
+ assertEquals(newTestName, testFolderName);
+
// test 10: apt is enabled, folder must be on classpath.
assertEquals( true, isOnClasspath(javaProj, srcFolder.getFullPath()) );
-
+ // generated test source folder should NOT be on classpath, as the project has no test source folder
+ assertEquals( false, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
+
+ // test 11: now add a test source folder, generated test source folder should then exist and be on classpath
+ env.removePackageFragmentRoot(projectPath, "");
+ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
+ env.addPackageFragmentRoot( projectPath, "src" );
+ env.addPackageFragmentRoot(javaProj.getPath(), "src-tests", null, null,
+ "bin-tests", true);
+ fullBuild( javaProj.getProject().getFullPath() );
+ assertEquals(true, testSrcFolder.exists());
+ assertEquals(true, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
+
+
// now disable apt.
AptConfig.setEnabled(javaProj, false);
aptEnabled = AptConfig.isEnabled(javaProj);
// test 11: make sure it's disabled.
assertEquals(false, aptEnabled);
+
srcFolder = gsfm.getFolder();
+ testSrcFolder = testgsfm.getFolder();
+
folderName = srcFolder.getProjectRelativePath().toOSString();
+ testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
// test 12: make sure we deleted the source folder when we disable apt
assertEquals(false, srcFolder.exists());
+ assertEquals(false, testSrcFolder.exists());
// test 13: make sure we didn't overwrite the configure folder name
assertEquals(newName, folderName);
+ assertEquals(newTestName, testFolderName);
// test 14: make sure we cleaned up the classpath.
assertEquals( false, isOnClasspath(javaProj, srcFolder.getFullPath()) );
+ assertEquals( false, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
}
-
+
private boolean isOnClasspath(IJavaProject javaProj, IPath path)
throws JavaModelException
{
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java
index 663c8c0728..2a9ee94736 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Walter Harley.
+ * Copyright (c) 2009, 2018 Walter Harley and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -694,7 +694,7 @@ public class StarProcessorTests extends APTTestBase
expectingNoProblems();
expectingNoMarkers();
- GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(false);
IFolder srcFolder = mgr.getFolder();
assertEquals(true, srcFolder.exists());
// delete the gen source folder
diff --git a/org.eclipse.jdt.apt.ui/.settings/.api_filters b/org.eclipse.jdt.apt.ui/.settings/.api_filters
new file mode 100644
index 0000000000..1752455cc3
--- /dev/null
+++ b/org.eclipse.jdt.apt.ui/.settings/.api_filters
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jdt.apt.ui" version="2">
+ <resource path="META-INF/MANIFEST.MF">
+ <filter comment="increased to match org.eclipse.jdt.apt.core" id="926941240">
+ <message_arguments>
+ <message_argument value="3.6.0"/>
+ <message_argument value="3.5.0"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/org.eclipse.jdt.apt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.ui/META-INF/MANIFEST.MF
index 4a30354518..2b64d27fc7 100644
--- a/org.eclipse.jdt.apt.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.apt.ui/META-INF/MANIFEST.MF
@@ -2,12 +2,12 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.ui; singleton:=true
-Bundle-Version: 3.5.100.qualifier
+Bundle-Version: 3.6.0.qualifier
Bundle-Activator: org.eclipse.jdt.apt.ui.internal.AptUIPlugin
Bundle-Localization: plugin
-Require-Bundle: org.eclipse.jdt.apt.core;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.jdt.ui;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)",
+Require-Bundle: org.eclipse.jdt.apt.core;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.jdt.ui;bundle-version="[3.14.0,4.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.14.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
diff --git a/org.eclipse.jdt.apt.ui/pom.xml b/org.eclipse.jdt.apt.ui/pom.xml
index ea45edcf06..eb7bebb8a0 100644
--- a/org.eclipse.jdt.apt.ui/pom.xml
+++ b/org.eclipse.jdt.apt.ui/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.apt.ui</artifactId>
- <version>3.5.100-SNAPSHOT</version>
+ <version>3.6.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AptConfigurationBlock.java b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AptConfigurationBlock.java
index 4824e3dbb4..2527f2c53f 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AptConfigurationBlock.java
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AptConfigurationBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc. and others.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -77,6 +77,7 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
private static final Key KEY_APTENABLED= getKey(AptPlugin.PLUGIN_ID, AptPreferenceConstants.APT_ENABLED);
private static final Key KEY_RECONCILEENABLED= getKey(AptPlugin.PLUGIN_ID, AptPreferenceConstants.APT_RECONCILEENABLED);
private static final Key KEY_GENSRCDIR= getKey(AptPlugin.PLUGIN_ID, AptPreferenceConstants.APT_GENSRCDIR);
+ private static final Key KEY_GENTESTSRCDIR= getKey(AptPlugin.PLUGIN_ID, AptPreferenceConstants.APT_GENTESTSRCDIR);
private static Key[] getAllKeys() {
return new Key[] {
@@ -93,6 +94,7 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
private SelectionButtonDialogField fAptEnabledField;
private SelectionButtonDialogField fReconcileEnabledField;
private StringDialogField fGenSrcDirField;
+ private StringDialogField fGenTestSrcDirField;
private ListDialogField<ProcessorOption> fProcessorOptionsField;
private PixelConverter fPixelConverter;
@@ -100,6 +102,7 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
private Map<String, String> fOriginalProcOptions; // cache of saved values
private String fOriginalGenSrcDir;
+ private String fOriginalGenTestSrcDir;
private boolean fOriginalAptEnabled;
private boolean fOriginalReconcileEnabled;
@@ -218,7 +221,11 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
fGenSrcDirField = new StringDialogField();
fGenSrcDirField.setDialogFieldListener(adapter);
fGenSrcDirField.setLabelText(Messages.AptConfigurationBlock_generatedSrcDir);
-
+
+ fGenTestSrcDirField = new StringDialogField();
+ fGenTestSrcDirField.setDialogFieldListener(adapter);
+ fGenTestSrcDirField.setLabelText(Messages.AptConfigurationBlock_generatedTestSrcDir);
+
String[] buttons= new String[] {
Messages.AptConfigurationBlock_add,
Messages.AptConfigurationBlock_edit,
@@ -254,7 +261,8 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
if (workspaceSettings)
return null;
// if the only thing that changed was the reconcile setting, return null: a rebuild is not necessary
- if (fOriginalGenSrcDir.equals(fGenSrcDirField.getText())) {
+ if (fOriginalGenSrcDir.equals(fGenSrcDirField.getText())
+ && fOriginalGenTestSrcDir.equals(fGenTestSrcDirField.getText())) {
if (fOriginalAptEnabled == fAptEnabledField.isSelected()) {
if (!procOptionsChanged()) {
return null;
@@ -311,11 +319,13 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
fAptEnabledField,
fReconcileEnabledField,
fGenSrcDirField,
+ fGenTestSrcDirField,
fProcessorOptionsField,
} :
new DialogField[] {
fReconcileEnabledField,
fGenSrcDirField,
+ fGenTestSrcDirField,
fProcessorOptionsField,
};
LayoutUtil.doDefaultLayout(fBlockControl, fields, true, SWT.DEFAULT, SWT.DEFAULT);
@@ -337,6 +347,7 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
super.cacheOriginalValues();
fOriginalProcOptions= AptConfig.getRawProcessorOptions(fJProj);
fOriginalGenSrcDir = AptConfig.getGenSrcDir(fJProj);
+ fOriginalGenTestSrcDir = AptConfig.getGenTestSrcDir(fJProj);
fOriginalAptEnabled = AptConfig.isEnabled(fJProj);
fOriginalReconcileEnabled = AptConfig.shouldProcessDuringReconcile(fJProj);
fPerProjSettingsEnabled = hasProjectSpecificOptionsNoCache(fProject);
@@ -366,6 +377,9 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
if (!fOriginalGenSrcDir.equals(AptConfig.getGenSrcDir(null))) {
fAptProject.preferenceChanged(AptPreferenceConstants.APT_GENSRCDIR);
}
+ if (!fOriginalGenTestSrcDir.equals(AptConfig.getGenTestSrcDir(null))) {
+ fAptProject.preferenceChanged(AptPreferenceConstants.APT_GENTESTSRCDIR);
+ }
if (fOriginalAptEnabled != AptConfig.isEnabled(null)) {
// make JDT "processingEnabled" setting track APT "enabled" setting.
setJDTProcessAnnotationsSetting(fAptEnabledField.isSelected());
@@ -379,6 +393,8 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
else { // compare against current settings
if (!fOriginalGenSrcDir.equals(fGenSrcDirField.getText()))
fAptProject.preferenceChanged(AptPreferenceConstants.APT_GENSRCDIR);
+ if (!fOriginalGenTestSrcDir.equals(fGenTestSrcDirField.getText()))
+ fAptProject.preferenceChanged(AptPreferenceConstants.APT_GENTESTSRCDIR);
boolean isAptEnabled = fAptEnabledField.isSelected();
if (fOriginalAptEnabled != isAptEnabled) {
// make JDT "processingEnabled" setting track APT "enabled" setting.
@@ -460,6 +476,11 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
IStatus status = null;
status = validateGenSrcDir();
+
+ if (status.getSeverity() == IStatus.OK) {
+ status = validateGenTestSrcDir();
+ }
+
if (status.getSeverity() == IStatus.OK) {
status = validateProcessorOptions();
}
@@ -487,6 +508,26 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
}
/**
+ * Validate "generated test source directory" setting. It must be a valid
+ * pathname relative to a project, and must not be a source directory.
+ * @return true if current field value is valid
+ */
+ private IStatus validateGenTestSrcDir() {
+ String dirName = fGenTestSrcDirField.getText();
+ if (!AptConfig.validateGenSrcDir(fJProj, dirName)) {
+ return new StatusInfo(IStatus.ERROR, Messages.AptConfigurationBlock_genTestSrcDirMustBeValidRelativePath);
+ }
+ boolean TODO; // check it is not same as validateGenSrcDir, make sure it has its own output folder
+ if (fJProj != null && !dirName.equals(fOriginalGenTestSrcDir)) {
+ IFolder folder = fJProj.getProject().getFolder( dirName );
+ if (folder != null && folder.exists() && !folder.isDerived()) {
+ return new StatusInfo(IStatus.WARNING, Messages.AptConfigurationBlock_warningContentsMayBeDeleted);
+ }
+ }
+ return new StatusInfo();
+ }
+
+ /**
* Validate the currently set processor options. We do this by
* looking at the table contents rather than the packed string,
* just because it's easier.
@@ -516,6 +557,8 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
fReconcileEnabledField.setSelection(reconcileEnabled);
String str= getValue(KEY_GENSRCDIR);
fGenSrcDirField.setText(str == null ? "" : str); //$NON-NLS-1$
+ String teststr= getValue(KEY_GENTESTSRCDIR);
+ fGenTestSrcDirField.setText(teststr == null ? "" : teststr); //$NON-NLS-1$
}
/**
@@ -529,6 +572,9 @@ public class AptConfigurationBlock extends BaseConfigurationBlock {
} else if (field == fGenSrcDirField) {
String newVal = fGenSrcDirField.getText();
setValue(KEY_GENSRCDIR, newVal);
+ } else if (field == fGenTestSrcDirField) {
+ String newVal = fGenTestSrcDirField.getText();
+ setValue(KEY_GENTESTSRCDIR, newVal);
} else if (field == fReconcileEnabledField) {
String newVal = String.valueOf(fReconcileEnabledField.isSelected());
setValue(KEY_RECONCILEENABLED, newVal);
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java
index c4bf99358e..e73517ea15 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc and others.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -31,6 +31,8 @@ public class Messages extends NLS {
public static String AptConfigurationBlock_generatedSrcDir;
+ public static String AptConfigurationBlock_generatedTestSrcDir;
+
public static String AptConfigurationBlock_options;
public static String FactoryPathConfigurationBlock_up;
@@ -99,6 +101,8 @@ public class Messages extends NLS {
public static String AptConfigurationBlock_genSrcDirMustBeValidRelativePath;
+ public static String AptConfigurationBlock_genTestSrcDirMustBeValidRelativePath;
+
public static String FactoryPathConfigurationBlock_advanced;
public static String AdvancedFactoryPathOptionsDialog_advancedOptions;
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties
index d07f4d9523..c297b97f63 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2005, 2007 BEA Systems, Inc.
+# Copyright (c) 2005, 2018 BEA Systems, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -12,10 +12,12 @@ AptConfigurationBlock_edit=&Edit...
AptConfigurationBlock_remove=&Remove
AptConfigurationBlock_value=Value
AptConfigurationBlock_generatedSrcDir=&Generated source directory:
+AptConfigurationBlock_generatedTestSrcDir=&Generated test source directory:
AptConfigurationBlock_warningIgnoredOptions=An automatically set option will override this option
AptConfigurationBlock_warningContentsMayBeDeleted=Contents of generated source directory may be deleted
AptConfigurationBlock_enableReconcileProcessing=Enable processing in edito&r
AptConfigurationBlock_genSrcDirMustBeValidRelativePath=Generated source directory must be a valid relative path
+AptConfigurationBlock_genTestSrcDirMustBeValidRelativePath=Generated test source directory must be a valid relative path
AptConfigurationBlock_options=Processor options (-Akey=value):
AptPreferencePage_preferences=Specify the default annotation processor settings for new projects:
AptPreferencePage_preferencesTitle=Java Annotation Processing Preferences
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java
index fb4001adfd..7fe708c072 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 BEA Systems, Inc.
+ * Copyright (c) 2007, 2018 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -69,7 +69,7 @@ public abstract class BaseAnnotationProcessorManager extends AbstractAnnotationP
* @see org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager#configureFromPlatform(org.eclipse.jdt.internal.compiler.Compiler, java.lang.Object)
*/
@Override
- public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject) {
+ public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject, boolean isTestCode) {
// Implemented by IdeAnnotationProcessorManager.
throw new UnsupportedOperationException();
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 9b596b5501..abd907b71b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -2975,7 +2975,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
}
@Override
- public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject) {
+ public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject, boolean isTestCode) {
// Nothing to do here
}
@SupportedAnnotationTypes("*")
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java
index 5c05f93792..247339a487 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -35,8 +35,9 @@ public abstract class AbstractAnnotationProcessorManager {
* @param compiler the given compiler
* @param compilationUnitLocator the given compilation unit locator
* @param javaProject the given java project
+ * @param isTestCode
*/
- public abstract void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject);
+ public abstract void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject, boolean isTestCode);
/**
* Set the print writer for the standard output.
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/BuildContext.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/BuildContext.java
index abd71174b8..41b07a9457 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/BuildContext.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/BuildContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -92,4 +92,10 @@ public void recordNewProblems(CategorizedProblem[] newProblems) {
// default overridden by concrete implementation
}
+/**
+ * @since 3.14
+ */
+public boolean isTestCode() {
+ return false; // default overridden by concrete implementation
+}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
index 9e4af4ca1a..bda4c6ef7f 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -87,10 +87,12 @@ public final static Integer S_INFO = Integer.valueOf(IMarker.SEVERITY_INFO);
public final static Integer P_HIGH = Integer.valueOf(IMarker.PRIORITY_HIGH);
public final static Integer P_NORMAL = Integer.valueOf(IMarker.PRIORITY_NORMAL);
public final static Integer P_LOW = Integer.valueOf(IMarker.PRIORITY_LOW);
+private CompilationGroup compilationGroup;
protected AbstractImageBuilder(JavaBuilder javaBuilder, boolean buildStarting, State newState, CompilationGroup compilationGroup) {
// local copies
this.javaBuilder = javaBuilder;
+ this.compilationGroup = compilationGroup;
this.nameEnvironment = compilationGroup == CompilationGroup.TEST ? javaBuilder.testNameEnvironment : javaBuilder.nameEnvironment;
this.sourceLocations = this.nameEnvironment.sourceLocations;
this.notifier = javaBuilder.notifier;
@@ -495,7 +497,7 @@ public ICompilationUnit fromIFile(IFile file) {
protected void initializeAnnotationProcessorManager(Compiler newCompiler) {
AbstractAnnotationProcessorManager annotationManager = JavaModelManager.getJavaModelManager().createAnnotationProcessorManager();
if (annotationManager != null) {
- annotationManager.configureFromPlatform(newCompiler, this, this.javaBuilder.javaProject);
+ annotationManager.configureFromPlatform(newCompiler, this, this.javaBuilder.javaProject, this.compilationGroup == CompilationGroup.TEST);
annotationManager.setErr(new PrintWriter(System.err));
annotationManager.setOut(new PrintWriter(System.out));
}
@@ -568,7 +570,7 @@ protected Compiler newCompiler() {
protected CompilationParticipantResult[] notifyParticipants(SourceFile[] unitsAboutToCompile) {
CompilationParticipantResult[] results = new CompilationParticipantResult[unitsAboutToCompile.length];
for (int i = unitsAboutToCompile.length; --i >= 0;)
- results[i] = new CompilationParticipantResult(unitsAboutToCompile[i]);
+ results[i] = new CompilationParticipantResult(unitsAboutToCompile[i], this.compilationGroup == CompilationGroup.TEST);
// TODO (kent) do we expect to have more than one participant?
// and if so should we pass the generated files from the each processor to the others to process?
@@ -598,7 +600,7 @@ protected CompilationParticipantResult[] notifyParticipants(SourceFile[] unitsAb
uniqueFiles.add(unitsAboutToCompile[f]);
}
if (uniqueFiles.addIfNotIncluded(sourceFile) == sourceFile) {
- CompilationParticipantResult newResult = new CompilationParticipantResult(sourceFile);
+ CompilationParticipantResult newResult = new CompilationParticipantResult(sourceFile, this.compilationGroup == CompilationGroup.TEST);
// is there enough room to add all the addedGeneratedFiles.length ?
if (toAdd == null) {
toAdd = new CompilationParticipantResult[addedGeneratedFiles.length];
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java
index 6988ef8f4f..3e8e2b5be1 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/BatchImageBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -103,9 +103,13 @@ protected void cleanOutputFolders(boolean copyBack) throws CoreException {
boolean deleteAll = JavaCore.CLEAN.equals(
this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
if (deleteAll) {
- if (this.javaBuilder.participants != null)
- for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
- this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);
+ if (this.compilationGroup != CompilationGroup.TEST) {
+ // CompilationGroup.MAIN is done first, so this notifies the participants only once
+ // calling this for CompilationGroup.TEST could cases generated files for CompilationGroup.MAIN to be deleted.
+ if (this.javaBuilder.participants != null)
+ for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
+ this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);
+ }
Set<IContainer> visited = new LinkedHashSet<>(this.sourceLocations.length);
for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/CompilationParticipantResult.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/CompilationParticipantResult.java
index acf99b00c3..b76b5ebe72 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/CompilationParticipantResult.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/CompilationParticipantResult.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,9 +22,11 @@ public class CompilationParticipantResult extends BuildContext {
protected IFile[] deletedFiles; // previously generated source files that should be deleted
protected CategorizedProblem[] problems; // new problems to report against this compilationUnit
protected String[] dependencies; // fully-qualified type names of any new dependencies, each name is of the form 'p1.p2.A.B'
+ private boolean isTestCode;
-protected CompilationParticipantResult(SourceFile sourceFile) {
+protected CompilationParticipantResult(SourceFile sourceFile, boolean isTestCode) {
this.sourceFile = sourceFile;
+ this.isTestCode = isTestCode;
this.hasAnnotations = false;
this.addedFiles = null;
this.deletedFiles = null;
@@ -152,4 +154,8 @@ public String toString() {
return this.sourceFile.toString();
}
+@Override
+public boolean isTestCode() {
+ return this.isTestCode;
+}
}

Back to the top