diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 8d6d0f39f63d..36a1aa9a2ab0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -431,23 +431,22 @@ public class CompileDriver { final MessageBus messageBus = myProject.getMessageBus(); csManager.cancelAutoMakeTasks(myProject); final CompileScope scope = compileContext.getCompileScope(); - final Map userData; // need to pass scope's user data to server - if (scope instanceof UserDataHolderBase) { // hack - userData = new HashMap(); - ((UserDataHolderBase)scope).copyUserDataTo(new UserDataHolderBase() { - @Override - public void putUserData(@NotNull Key key, @Nullable T value) { - final String _key = key.toString(); - final String _value = value != null? value.toString() : ""; - userData.put(_key, _value); - } - }); + final Map exported = scope.exportUserData(); + final Map builderParams; + if (!exported.isEmpty()) { + builderParams = new HashMap(); + for (Map.Entry entry : exported.entrySet()) { + final String _key = entry.getKey().toString(); + final String _value = entry.getValue().toString(); + builderParams.put(_key, _value); + } } else { - userData = Collections.emptyMap(); + builderParams = Collections.emptyMap(); } - return csManager.submitCompilationTask(myProject, compileContext.isRebuild(), compileContext.isMake(), moduleNames, artifactNames, paths, userData, new JpsServerResponseHandler() { + return csManager.submitCompilationTask(myProject, compileContext.isRebuild(), compileContext.isMake(), moduleNames, artifactNames, paths, + builderParams, new JpsServerResponseHandler() { @Override public void handleCompileMessage(JpsRemoteProto.Message.Response.CompileMessage compilerMessage) { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompositeScope.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompositeScope.java index 9150c49c7a5a..2d18e44931e9 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompositeScope.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompositeScope.java @@ -22,10 +22,10 @@ package com.intellij.compiler.impl; import com.intellij.openapi.compiler.CompileScope; +import com.intellij.openapi.compiler.ExportableUserDataHolderBase; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtil; @@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; -public class CompositeScope extends UserDataHolderBase implements CompileScope{ +public class CompositeScope extends ExportableUserDataHolderBase implements CompileScope{ private final List myScopes = new ArrayList(); public CompositeScope(CompileScope scope1, CompileScope scope2) { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/FileIndexCompileScope.java b/java/compiler/impl/src/com/intellij/compiler/impl/FileIndexCompileScope.java index 9b6058469279..8f1f2dd3d560 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/FileIndexCompileScope.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/FileIndexCompileScope.java @@ -16,9 +16,9 @@ package com.intellij.compiler.impl; import com.intellij.openapi.compiler.CompileScope; +import com.intellij.openapi.compiler.ExportableUserDataHolderBase; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.roots.FileIndex; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -30,7 +30,7 @@ import java.util.List; * @author Eugene Zhuravlev * Date: Dec 18, 2003 */ -public abstract class FileIndexCompileScope extends UserDataHolderBase implements CompileScope { +public abstract class FileIndexCompileScope extends ExportableUserDataHolderBase implements CompileScope { protected abstract FileIndex[] getFileIndices(); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/FileSetCompileScope.java b/java/compiler/impl/src/com/intellij/compiler/impl/FileSetCompileScope.java index 38ab59e6ee7b..ffa703b7215e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/FileSetCompileScope.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/FileSetCompileScope.java @@ -23,10 +23,10 @@ package com.intellij.compiler.impl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.compiler.CompileScope; +import com.intellij.openapi.compiler.ExportableUserDataHolderBase; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.module.Module; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; -public class FileSetCompileScope extends UserDataHolderBase implements CompileScope { +public class FileSetCompileScope extends ExportableUserDataHolderBase implements CompileScope { private final Set myRootFiles = new HashSet(); private final Set myDirectoryUrls = new HashSet(); private Set myUrls = null; // urls caching diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/OneProjectItemCompileScope.java b/java/compiler/impl/src/com/intellij/compiler/impl/OneProjectItemCompileScope.java index d85b28af44e8..4b0b653e3723 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/OneProjectItemCompileScope.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/OneProjectItemCompileScope.java @@ -16,6 +16,7 @@ package com.intellij.compiler.impl; import com.intellij.openapi.compiler.CompileScope; +import com.intellij.openapi.compiler.ExportableUserDataHolderBase; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; @@ -24,7 +25,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ContentIterator; import com.intellij.openapi.roots.FileIndex; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -33,7 +33,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -public class OneProjectItemCompileScope extends UserDataHolderBase implements CompileScope{ +public class OneProjectItemCompileScope extends ExportableUserDataHolderBase implements CompileScope{ private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.OneProjectItemCompileScope"); private final Project myProject; private final VirtualFile myFile; diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompileScope.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompileScope.java index f1329adae1e5..5e1c30445f89 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompileScope.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompileScope.java @@ -17,7 +17,6 @@ package com.intellij.openapi.compiler; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; -import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -28,7 +27,7 @@ import org.jetbrains.annotations.Nullable; * * @see CompilerManager#compile(CompileScope, CompileStatusNotification) */ -public interface CompileScope extends UserDataHolder { +public interface CompileScope extends ExportableUserDataHolder { CompileScope[] EMPTY_ARRAY = new CompileScope[0]; /** * Returns the list of files within the scope. diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/ExportableUserDataHolder.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/ExportableUserDataHolder.java new file mode 100644 index 000000000000..1dda010557ea --- /dev/null +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/ExportableUserDataHolder.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.compiler; + +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolder; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +/** + * @author Eugene Zhuravlev + * Date: 2/21/12 + */ +public interface ExportableUserDataHolder extends UserDataHolder{ + + @NotNull + Map exportUserData(); + +} diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/ExportableUserDataHolderBase.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/ExportableUserDataHolderBase.java new file mode 100644 index 000000000000..4f4e20d569dd --- /dev/null +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/ExportableUserDataHolderBase.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.compiler; + +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolderBase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +public class ExportableUserDataHolderBase extends UserDataHolderBase implements ExportableUserDataHolder{ + private final Set myKeys = Collections.synchronizedSet(new HashSet()); + + @NotNull + public final Map exportUserData() { + final Map result = new HashMap(); + synchronized (myKeys) { + for (Key k : myKeys) { + final Object data = getUserData(k); + if (data != null) { + result.put(k, data); + } + } + } + return result; + } + + @Override + public final void putUserData(@NotNull Key key, @Nullable T value) { + if (value != null) { + myKeys.add(key); + } + else { + myKeys.remove(key); + } + super.putUserData(key, value); + } + +}