correctly export builder params from compile scope

This commit is contained in:
Eugene Zhuravlev
2012-02-21 21:18:50 +01:00
parent 7e2db60abd
commit f869c058bf
8 changed files with 107 additions and 23 deletions
@@ -431,23 +431,22 @@ public class CompileDriver {
final MessageBus messageBus = myProject.getMessageBus();
csManager.cancelAutoMakeTasks(myProject);
final CompileScope scope = compileContext.getCompileScope();
final Map<String, String> userData;
// need to pass scope's user data to server
if (scope instanceof UserDataHolderBase) { // hack
userData = new HashMap<String, String>();
((UserDataHolderBase)scope).copyUserDataTo(new UserDataHolderBase() {
@Override
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
final String _key = key.toString();
final String _value = value != null? value.toString() : "";
userData.put(_key, _value);
}
});
final Map<Key, Object> exported = scope.exportUserData();
final Map<String, String> builderParams;
if (!exported.isEmpty()) {
builderParams = new HashMap<String, String>();
for (Map.Entry<Key, Object> 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) {
@@ -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<CompileScope> myScopes = new ArrayList<CompileScope>();
public CompositeScope(CompileScope scope1, CompileScope scope2) {
@@ -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();
@@ -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<VirtualFile> myRootFiles = new HashSet<VirtualFile>();
private final Set<String> myDirectoryUrls = new HashSet<String>();
private Set<String> myUrls = null; // urls caching
@@ -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;
@@ -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.
@@ -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<Key, Object> exportUserData();
}
@@ -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<Key> myKeys = Collections.synchronizedSet(new HashSet<Key>());
@NotNull
public final Map<Key, Object> exportUserData() {
final Map<Key, Object> result = new HashMap<Key, Object>();
synchronized (myKeys) {
for (Key<?> k : myKeys) {
final Object data = getUserData(k);
if (data != null) {
result.put(k, data);
}
}
}
return result;
}
@Override
public final <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
if (value != null) {
myKeys.add(key);
}
else {
myKeys.remove(key);
}
super.putUserData(key, value);
}
}