Merge branch 'idea90' of git.labs.intellij.net:idea/community into idea90

This commit is contained in:
peter
2009-12-20 21:25:49 +00:00
11 changed files with 148 additions and 67 deletions
@@ -24,6 +24,8 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.ModuleAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.ui.Messages;
@@ -34,13 +36,11 @@ import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsDirectoryMapping;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* @author yole
@@ -49,6 +49,7 @@ public class ModuleVcsDetector implements ProjectComponent {
private final Project myProject;
private final MessageBus myMessageBus;
private final ProjectLevelVcsManagerImpl myVcsManager;
private MessageBusConnection myConnection;
public ModuleVcsDetector(final Project project, final MessageBus messageBus, final ProjectLevelVcsManager vcsManager) {
myProject = project;
@@ -63,7 +64,7 @@ public class ModuleVcsDetector implements ProjectComponent {
manager.registerStartupActivity(new Runnable() {
public void run() {
if (myVcsManager.needAutodetectMappings()) {
autoDetectVcsMappings();
autoDetectVcsMappings(true);
}
myVcsManager.updateActiveVcss();
}
@@ -71,20 +72,36 @@ public class ModuleVcsDetector implements ProjectComponent {
manager.registerPostStartupActivity(new Runnable() {
public void run() {
if (myMessageBus != null) {
myMessageBus.connect().subscribe(ProjectTopics.MODULES, new ModuleAdapter() {
public void moduleAdded(final Project project, final Module module) {
autoDetectModuleVcsMapping(module);
}
public void beforeModuleRemoved(final Project project, final Module module) {
checkRemoveVcsRoot(module);
}
});
myConnection = myMessageBus.connect();
final MyModulesListener listener = new MyModulesListener();
myConnection.subscribe(ProjectTopics.MODULES, listener);
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
}
}
});
}
private class MyModulesListener extends ModuleAdapter implements ModuleRootListener {
public void beforeRootsChange(ModuleRootEvent event) {
}
public void rootsChanged(ModuleRootEvent event) {
// the check calculates to true only before user has done any change to mappings, i.e. in case modules are detected/added automatically
// on start etc (look inside)
if (myVcsManager.needAutodetectMappings()) {
autoDetectVcsMappings(false);
}
}
public void moduleAdded(final Project project, final Module module) {
autoDetectModuleVcsMapping(module);
}
public void beforeModuleRemoved(final Project project, final Module module) {
checkRemoveVcsRoot(module);
}
}
public void projectClosed() {
}
@@ -98,12 +115,16 @@ public class ModuleVcsDetector implements ProjectComponent {
}
public void disposeComponent() {
if (myConnection != null) {
myConnection.disconnect();
}
}
private void autoDetectVcsMappings() {
private void autoDetectVcsMappings(final boolean tryMapPieces) {
Set<AbstractVcs> usedVcses = new HashSet<AbstractVcs>();
Map<VirtualFile, AbstractVcs> vcsMap = new HashMap<VirtualFile, AbstractVcs>();
for(Module module: ModuleManager.getInstance(myProject).getModules()) {
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for(Module module: moduleManager.getModules()) {
final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
for(VirtualFile file: files) {
AbstractVcs contentRootVcs = myVcsManager.findVersioningVcs(file);
@@ -115,11 +136,31 @@ public class ModuleVcsDetector implements ProjectComponent {
}
if (usedVcses.size() == 1) {
final AbstractVcs[] abstractVcses = usedVcses.toArray(new AbstractVcs[1]);
final Module[] modules = moduleManager.getModules();
final Set<String> contentRoots = new HashSet<String>();
for (Module module : modules) {
final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
for (VirtualFile root : roots) {
contentRoots.add(root.getPath());
}
}
if (abstractVcses [0] != null) {
final List<VcsDirectoryMapping> vcsDirectoryMappings = new ArrayList<VcsDirectoryMapping>(myVcsManager.getDirectoryMappings());
for (Iterator<VcsDirectoryMapping> iterator = vcsDirectoryMappings.iterator(); iterator.hasNext();) {
final VcsDirectoryMapping mapping = iterator.next();
if (! contentRoots.contains(mapping.getDirectory())) {
iterator.remove();
}
}
myVcsManager.setAutoDirectoryMapping("", abstractVcses [0].getName());
for (VcsDirectoryMapping mapping : vcsDirectoryMappings) {
myVcsManager.removeDirectoryMapping(mapping);
}
myVcsManager.cleanupMappings();
}
}
else {
else if (tryMapPieces) {
for(Map.Entry<VirtualFile, AbstractVcs> entry: vcsMap.entrySet()) {
myVcsManager.setAutoDirectoryMapping(entry.getKey().getPath(), entry.getValue() == null ? "" : entry.getValue().getName());
}
@@ -100,6 +100,16 @@ public class NewMappings {
public void setMapping(final String path, final String activeVcsName) {
LOG.debug("setMapping path = '" + path + "' vcs = " + activeVcsName);
final VcsDirectoryMapping newMapping = new VcsDirectoryMapping(path, activeVcsName);
// do not add duplicates
synchronized (myLock) {
if (myVcsToPaths.containsKey(activeVcsName)) {
final List<VcsDirectoryMapping> vcsDirectoryMappings = myVcsToPaths.get(activeVcsName);
if ((vcsDirectoryMappings != null) && (vcsDirectoryMappings.contains(newMapping))) {
return;
}
}
}
final LocalFileSystem.WatchRequest request = addWatchRequest(newMapping);
final Ref<Boolean> switched = new Ref<Boolean>(Boolean.FALSE);
@@ -440,6 +440,7 @@ import.wizard.include.to.import.action.name=Include to Import
message.choose.stored.file.version.title=Choose stored version
error.message.wrong.remote.repository=wrong remote repository: {0}
propmt.text.enter.private.key.password.for=Enter private key password for {0}
prompt.path.to.private.key=Private key path: ''{0}''
close.tab.action.name=Close
cvs.unknown.revision.presentation=<unknown>
browse.changes.user.field.label=&User
@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class SshSharedConnection {
private final static int CHECK_GRANULARITY = 10000;
@@ -38,13 +39,13 @@ public class SshSharedConnection {
private final ConnectionSettings myConnectionSettings;
private final Object myLock;
private boolean myValid;
private AtomicBoolean myValid;
private final ThrowableComputable<Connection, AuthenticationException> myConnectionFactory;
private final List<Cell> myQueue;
public SshSharedConnection(final String repository, final ConnectionSettings connectionSettings, final SshAuthentication authentication) {
myValid = true;
myValid = new AtomicBoolean(true);
myRepository = repository;
myConnectionSettings = connectionSettings;
myLock = new Object();
@@ -56,16 +57,12 @@ public class SshSharedConnection {
return SshConnectionUtils.openConnection(connectionSettings, authentication);
}
catch (AuthenticationException e) {
synchronized (myLock) {
// todo +-
myValid = false;
}
// todo +-
myValid.set(false);
throw e;
} catch (IOException e) {
// todo +-
synchronized (myLock) {
myValid = false;
}
myValid.set(false);
throw new AuthenticationException(e.getMessage(), e);
}
}
@@ -74,9 +71,7 @@ public class SshSharedConnection {
}
public boolean isValid() {
synchronized (myLock) {
return myValid;
}
return myValid.get();
}
@Nullable
@@ -136,11 +131,10 @@ public class SshSharedConnection {
}
}
private static class Cell {
private class Cell {
private final static int SESSIONS_PER_CONNECTION = 8;
private final ConnectionLifeCycle myConnectionLifeCycle;
private final LinkedList<IConnection> mySessions;
private final Object myLock;
private final Consumer<SshSessionConnection> myCloseListener;
private final String myRepository;
@@ -150,7 +144,6 @@ public class SshSharedConnection {
private Cell(final ThrowableComputable<Connection, AuthenticationException> factory, final String repository) {
myConnectionLifeCycle = new ConnectionLifeCycle(CHECK_GRANULARITY, factory);
myRepository = repository;
myLock = new Object();
mySessions = new LinkedList<IConnection>();
myCloseListener = new Consumer<SshSessionConnection>() {
@@ -43,6 +43,7 @@ public class SshConnectionUtil {
if (password == null) {
SshPasswordDialog sshPasswordDialog = new SshPasswordDialog(CvsBundle.message("propmt.text.enter.private.key.password.for", cvsRoot));
sshPasswordDialog.setAdditionalText(CvsBundle.message("prompt.path.to.private.key", settings.PATH_TO_PPK));
sshPasswordDialog.show();
if (!sshPasswordDialog.isOK()) return false;
password = sshPasswordDialog.getPassword();
@@ -1,39 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.cvsSupport2.connections.ssh.ui.SshPasswordDialog">
<grid id="bafd0" binding="myPanel" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="bafd0" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="46" y="24" width="411" height="144"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="69c29">
<constraints>
<xy x="190" y="72" width="11" height="72"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="1d2b3">
<constraints>
<xy x="391" y="30" width="20" height="11"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="e591e" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e591e" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="0" y="0" width="391" height="72"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6f40d" class="javax.swing.JLabel" binding="myLabel">
<constraints>
<xy x="0" y="3" width="22" height="14"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="dummy.label.xxx"/>
@@ -41,8 +36,7 @@
</component>
<component id="e442a" class="javax.swing.JPasswordField" binding="myPasswordField">
<constraints>
<xy x="0" y="25" width="391" height="20"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@@ -50,13 +44,20 @@
</component>
<component id="7e781" class="javax.swing.JCheckBox" binding="myStoreCheckbox">
<constraints>
<xy x="0" y="50" width="391" height="22"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="checkbox.store.scrambled.password.to.the.config"/>
</properties>
</component>
<component id="afad7" class="javax.swing.JLabel" binding="myAdditionalLbl">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -16,6 +16,7 @@
package com.intellij.cvsSupport2.connections.ssh.ui;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
@@ -28,6 +29,7 @@ public class SshPasswordDialog extends DialogWrapper{
private JCheckBox myStoreCheckbox;
private JPanel myPanel;
private JLabel myLabel;
private JLabel myAdditionalLbl;
public SshPasswordDialog(String propmtText) {
@@ -35,6 +37,7 @@ public class SshPasswordDialog extends DialogWrapper{
myLabel.setText(propmtText);
setTitle(com.intellij.CvsBundle.message("dialog.title.ssh.password"));
init();
myAdditionalLbl.setForeground(UIUtil.getInactiveTextColor());
}
protected JComponent createCenterPanel() {
@@ -52,4 +55,8 @@ public class SshPasswordDialog extends DialogWrapper{
public JComponent getPreferredFocusedComponent() {
return myPasswordField;
}
public void setAdditionalText(final String text) {
myAdditionalLbl.setText(text);
}
}
@@ -85,22 +85,14 @@ public abstract class TokenSets implements GroovyTokenTypes {
kDOUBLE
);
public static TokenSet KEYWORD_REFERENCE_NAMES = TokenSet.orSet(TokenSet.create(
kCLASS,
kIN,
kAS,
kDEF,
kIF,
kELSE,
kFOR,
kWHILE,
kSWITCH,
kTRY,
kCATCH,
kFINALLY,
kSTATIC,
kDEFAULT
), BUILT_IN_TYPE);
/**
* all keywords except 'this' and 'super'
*/
public static TokenSet KEYWORD_REFERENCE_NAMES = TokenSet
.create(kPACKAGE, kIMPORT, kSTATIC, kDEF, kCLASS, kINTERFACE, kENUM, kEXTENDS, kSUPER, kVOID, kBOOLEAN, kBYTE, kCHAR, kSHORT, kINT,
kFLOAT, kLONG, kDOUBLE, kAS, kPRIVATE, kPUBLIC, kPROTECTED, kTRANSIENT, kNATIVE, kSYNCHRONIZED, kVOLATILE, kDEFAULT, kTHROWS,
kIMPLEMENTS, kIF, kELSE, kWHILE, kSWITCH, kFOR, kIN, kRETURN, kBREAK, kCONTINUE, kTHROW, kASSERT, kCASE, kTRY, kFINALLY, kCATCH,
kINSTANCEOF, kNEW, kTRUE, kNULL);
public static final TokenSet PROPERTY_NAMES = TokenSet.create(mIDENT, mSTRING_LITERAL, mGSTRING_LITERAL);
@@ -60,7 +60,7 @@ public class GroovyScriptRunConfiguration extends ModuleBasedConfiguration<RunCo
public String workDir;
public boolean isDebugEnabled;
public String scriptParams;
public String scriptPath;
@Nullable public String scriptPath;
public GroovyScriptRunConfiguration(final String name, final Project project, final ConfigurationFactory factory) {
super(name, new RunConfigurationModule(project), factory);
@@ -196,6 +196,7 @@ public class GroovyScriptRunConfiguration extends ModuleBasedConfiguration<RunCo
@Nullable
private VirtualFile getScriptFile() {
if (scriptPath == null) return null;
return LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(scriptPath));
}
@@ -39,6 +39,8 @@ import org.jetbrains.idea.svn.dialogs.WCInfo;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
import org.tmatesoft.svn.core.internal.wc.admin.SVNEntry;
import org.tmatesoft.svn.core.internal.wc.admin.SVNWCAccess;
import org.tmatesoft.svn.core.io.SVNCapability;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.wc.*;
@@ -582,4 +584,24 @@ public class SvnUtil {
}
return false;
}
@Nullable
public static SVNURL getUrl(final File file) {
SVNWCAccess wcAccess = SVNWCAccess.newInstance(null);
try {
wcAccess.probeOpen(file, false, 0);
SVNEntry entry = wcAccess.getVersionedEntry(file, false);
return entry.getSVNURL();
} catch (SVNException e) {
//
} finally {
try {
wcAccess.close();
}
catch (SVNException e) {
//
}
}
return null;
}
}
@@ -877,22 +877,34 @@ public class SvnVcs extends AbstractVcs {
final List<MyPair<S>> infos = new ArrayList<MyPair<S>>(in.size());
final SvnFileUrlMappingImpl mapping = (SvnFileUrlMappingImpl) getSvnFileUrlMapping();
final List<S> notMatched = new LinkedList<S>();
for (S s : in) {
final VirtualFile vf = convertor.convert(s);
final File ioFile = new File(vf.getPath());
final SVNURL url = mapping.getUrlForFile(ioFile);
if (url == null) continue;
SVNURL url = mapping.getUrlForFile(ioFile);
if (url == null) {
url = SvnUtil.getUrl(ioFile);
if (url == null) {
notMatched.add(s);
continue;
}
}
infos.add(new MyPair<S>(vf, url.toString(), s));
}
final List<MyPair<S>> filtered = new ArrayList<MyPair<S>>(infos.size());
ForNestedRootChecker.filterOutSuperfluousChildren(this, infos, filtered);
return ObjectsConvertor.convert(filtered, new Convertor<MyPair<S>, S>() {
final List<S> converted = ObjectsConvertor.convert(filtered, new Convertor<MyPair<S>, S>() {
public S convert(final MyPair<S> o) {
return o.getSrc();
}
});
if (! notMatched.isEmpty()) {
// potential bug is here: order is not kept. but seems it only occurs for cases where result is sorted after filtering so ok
converted.addAll(notMatched);
}
return converted;
}
private static class MyPair<T> implements RootUrlPair {