separate inspection profile wrappers based on local and shared profiles to avoid conflicts when same names are used (IDEA-97051)

This commit is contained in:
Anna Kozlova
2015-10-14 11:12:32 +02:00
parent f29517700f
commit 4a900f191d
3 changed files with 49 additions and 6 deletions
@@ -81,6 +81,27 @@ public class InspectionProfileTest extends LightIdeaTestCase {
return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), base);
}
public void testSameNameSharedProfile() throws Exception {
InspectionProfileManager profileManager = InspectionProfileManager.getInstance();
InspectionProfileImpl localProfile = createProfile();
profileManager.updateProfile(localProfile);
InspectionProjectProfileManager projectProfileManager = InspectionProjectProfileManager.getInstance(getProject());
try {
//normally on open project profile wrappers are init for both managers
profileManager.updateProfile(localProfile);
InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), projectProfileManager,
InspectionProfileImpl.getDefaultProfile());
projectProfileManager.updateProfile(profile);
projectProfileManager.setProjectProfile(profile.getName());
assertTrue(projectProfileManager.getInspectionProfile() == profile);
}
finally {
projectProfileManager.deleteProfile(PROFILE);
}
}
public void testConvertOldProfile() throws Exception {
Element element = JDOMUtil.loadDocument("<inspections version=\"1.0\">\n" +
" <option name=\"myName\" value=\"ToConvert\" />\n" +
@@ -227,7 +227,9 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
setProjectProfile(myProfiles.keySet().iterator().next());
}
final Profile profile = myProfiles.get(myProjectProfile);
profile.setProfileManager(this);
if (profile.isProjectLevel()) {
profile.setProfileManager(this);
}
return profile;
}
@@ -57,6 +57,7 @@ import java.util.concurrent.ConcurrentHashMap;
)
public class InspectionProjectProfileManagerImpl extends InspectionProjectProfileManager {
private final Map<String, InspectionProfileWrapper> myName2Profile = new ConcurrentHashMap<String, InspectionProfileWrapper>();
private final Map<String, InspectionProfileWrapper> myAppName2Profile = new ConcurrentHashMap<String, InspectionProfileWrapper>();
private final SeverityRegistrar mySeverityRegistrar;
private final NamedScopeManager myLocalScopesHolder;
private NamedScopesHolder.ScopeListener myScopeListener;
@@ -76,17 +77,27 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
@Override
public boolean isProfileLoaded() {
return myName2Profile.containsKey(getInspectionProfile().getName());
final InspectionProfile profile = getInspectionProfile();
final String name = profile.getName();
return profile.getProfileManager() == this ? myName2Profile.containsKey(name) : myAppName2Profile.containsKey(name);
}
@NotNull
public synchronized InspectionProfileWrapper getProfileWrapper(){
final InspectionProfile profile = getInspectionProfile();
final String profileName = profile.getName();
if (!myName2Profile.containsKey(profileName)){
initProfileWrapper(profile);
if (profile.getProfileManager() == this) {
if (!myName2Profile.containsKey(profileName)){
initProfileWrapper(profile);
}
return myName2Profile.get(profileName);
}
else {
if (!myAppName2Profile.containsKey(profileName)) {
initProfileWrapper(profile);
}
return myAppName2Profile.get(profileName);
}
return myName2Profile.get(profileName);
}
public InspectionProfileWrapper getProfileWrapper(final String profileName){
@@ -163,7 +174,13 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
public void initProfileWrapper(@NotNull Profile profile) {
final InspectionProfileWrapper wrapper = new InspectionProfileWrapper((InspectionProfile)profile);
wrapper.init(myProject);
myName2Profile.put(profile.getName(), wrapper);
String profileName = profile.getName();
if (profile.getProfileManager() == this) {
myName2Profile.put(profileName, wrapper);
}
else {
myAppName2Profile.put(profileName, wrapper);
}
}
@Override
@@ -175,6 +192,9 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
for (InspectionProfileWrapper wrapper : myName2Profile.values()) {
wrapper.cleanup(myProject);
}
for (InspectionProfileWrapper wrapper : myAppName2Profile.values()) {
wrapper.cleanup(myProject);
}
fireProfilesShutdown();
}
};