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

This commit is contained in:
irengrig
2009-11-09 10:14:04 +03:00
7 changed files with 182 additions and 2 deletions
@@ -211,7 +211,7 @@ public abstract class ElementWithManifestPropertiesPanel<E extends CompositeElem
public void reset() {
myTitleLabel.setText("'" + myElement.getName() + "' manifest properties:");
myManifestNotFoundLabel.setText("Manifest.mf file not found in '" + myElement.getName() + "'");
myManifestNotFoundLabel.setText("META-INF/MANIFEST.MF file not found in '" + myElement.getName() + "'");
final VirtualFile file = ManifestFileUtil.findManifestFile(myElement, myContext, myContext.getArtifactType());
String path = file != null ? file.getPath() : null;
if (!Comparing.equal(path, myManifestFileConfiguration.getManifestFilePath())) {
@@ -15,11 +15,12 @@
*/
package com.intellij.openapi.module;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
public abstract class ModulePointerManager {
public static ModulePointerManager getInstance(Project project) {
return project.getComponent(ModulePointerManager.class);
return ServiceManager.getService(project, ModulePointerManager.class);
}
public abstract ModulePointer create(Module module);
+1
View File
@@ -18,6 +18,7 @@
<orderEntry type="module" module-name="vcs-impl" />
<orderEntry type="module" module-name="platform-impl" exported="" />
<orderEntry type="module" module-name="usageView" exported="" />
<orderEntry type="module" module-name="testFramework" scope="TEST" />
</component>
</module>
@@ -0,0 +1,83 @@
/*
* Copyright 2000-2009 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.module.impl;
import com.intellij.ProjectTopics;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModulePointer;
import com.intellij.openapi.module.ModulePointerManager;
import com.intellij.openapi.project.ModuleAdapter;
import com.intellij.openapi.project.Project;
import java.util.HashMap;
import java.util.Map;
/**
* @author nik
*/
public class ModulePointerManagerImpl extends ModulePointerManager {
private Map<String, ModulePointerImpl> myUnresolved = new HashMap<String, ModulePointerImpl>();
private Map<Module, ModulePointerImpl> myPointers = new HashMap<Module, ModulePointerImpl>();
private final Project myProject;
public ModulePointerManagerImpl(Project project) {
myProject = project;
project.getMessageBus().connect().subscribe(ProjectTopics.MODULES, new ModuleAdapter() {
@Override
public void beforeModuleRemoved(Project project, Module module) {
final ModulePointerImpl pointer = myPointers.remove(module);
if (pointer != null) {
pointer.moduleRemoved(module);
myUnresolved.put(pointer.getModuleName(), pointer);
}
}
@Override
public void moduleAdded(Project project, Module module) {
final ModulePointerImpl pointer = myUnresolved.remove(module.getName());
if (pointer != null) {
pointer.moduleAdded(module);
myPointers.put(module, pointer);
}
}
});
}
@Override
public ModulePointer create(Module module) {
ModulePointerImpl pointer = myPointers.get(module);
if (pointer == null) {
pointer = new ModulePointerImpl(module);
myPointers.put(module, pointer);
}
return pointer;
}
@Override
public ModulePointer create(String moduleName) {
final Module module = ModuleManagerImpl.getInstance(myProject).findModuleByName(moduleName);
if (module != null) {
return create(module);
}
ModulePointerImpl pointer = myUnresolved.get(moduleName);
if (pointer == null) {
pointer = new ModulePointerImpl(moduleName);
myUnresolved.put(moduleName, pointer);
}
return pointer;
}
}
@@ -0,0 +1,92 @@
/*
* Copyright 2000-2009 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.module;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.module.*;
import com.intellij.testFramework.PlatformTestCase;
/**
* @author nik
*/
public class ModulePointerTest extends PlatformTestCase {
public void testCreateByName() throws Exception {
final ModulePointer pointer = getPointerManager().create("m");
assertNull(pointer.getModule());
assertEquals("m", pointer.getModuleName());
final Module module = addModule("m");
assertSame(module, pointer.getModule());
assertEquals("m", pointer.getModuleName());
}
public void testCreateByModule() throws Exception {
final Module module = addModule("x");
final ModulePointer pointer = getPointerManager().create(module);
assertSame(module, pointer.getModule());
assertEquals("x", pointer.getModuleName());
ModifiableModuleModel model = getModuleManager().getModifiableModel();
model.disposeModule(module);
commitModel(model);
assertNull(pointer.getModule());
assertEquals("x", pointer.getModuleName());
}
public void testRenameModule() throws Exception {
final ModulePointer pointer = getPointerManager().create("abc");
final Module module = addModule("abc");
ModifiableModuleModel model = getModuleManager().getModifiableModel();
model.renameModule(module, "xyz");
commitModel(model);
assertSame(module, pointer.getModule());
assertEquals("xyz", pointer.getModuleName());
}
private ModuleManager getModuleManager() {
return ModuleManager.getInstance(myProject);
}
private Module addModule(final String name) {
final ModifiableModuleModel model = getModuleManager().getModifiableModel();
final Module module = model.newModule(myProject.getBaseDir().getPath() + "/" + name + ".iml", EmptyModuleType.getInstance());
commitModel(model);
disposeOnTearDown(new Disposable() {
public void dispose() {
if (!module.isDisposed()) {
getModuleManager().disposeModule(module);
}
}
});
return module;
}
private static void commitModel(final ModifiableModuleModel model) {
new WriteAction() {
protected void run(final Result result) {
model.commit();
}
}.execute();
}
private ModulePointerManager getPointerManager() {
return ModulePointerManager.getInstance(myProject);
}
}
+3
View File
@@ -293,6 +293,9 @@
<projectService serviceInterface="com.intellij.facet.impl.ui.FacetEditorsStateManager"
serviceImplementation="com.intellij.facet.impl.ui.FacetEditorsStateManagerImpl"/>
<projectService serviceInterface="com.intellij.openapi.module.ModulePointerManager"
serviceImplementation="com.intellij.openapi.module.impl.ModulePointerManagerImpl"/>
<applicationService serviceInterface="com.intellij.facet.ui.FacetEditorsFactory"
serviceImplementation="com.intellij.facet.impl.ui.FacetEditorsFactoryImpl"/>