From f2b140e83382c60a4c52b3afe4192a1c3cef4f38 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 5 Apr 2011 16:38:32 +0400 Subject: [PATCH] allow to add module test compile output into artifact (IDEA-53226) --- .../ArtifactAntGenerationContextImpl.java | 5 ++ .../ArtifactBySourceFileFinderImpl.java | 8 +- .../impl/artifacts/ArtifactUtil.java | 25 ++---- .../JarArtifactFromModulesDialog.form | 14 ++- .../JarArtifactFromModulesDialog.java | 26 +++--- .../artifacts/JarFromModulesTemplate.java | 19 ++-- .../impl/compiler/ArtifactCompileScope.java | 4 +- ....java => ModuleOutputElementTypeBase.java} | 43 ++++------ .../ModuleOutputPackagingElement.java | 7 ++ ... => ModuleOutputPackagingElementBase.java} | 45 ++++------ .../elements/PackagingElementFactoryImpl.java | 13 ++- .../ProductionModuleOutputElementType.java | 65 ++++++++++++++ ...roductionModuleOutputPackagingElement.java | 75 ++++++++++++++++ .../elements/TestModuleOutputElementType.java | 78 +++++++++++++++++ .../TestModuleOutputPackagingElement.java | 86 +++++++++++++++++++ .../impl/ui/ModuleElementPresentation.java | 17 ++-- .../ArtifactAntGenerationContext.java | 2 + .../elements/PackagingElementFactory.java | 3 + .../sourceItems/ModuleOutputSourceItem.java | 6 +- ...odulesAndLibrariesSourceItemsProvider.java | 4 +- .../src/messages/CompilerBundle.properties | 2 + 21 files changed, 435 insertions(+), 112 deletions(-) rename java/compiler/impl/src/com/intellij/packaging/impl/elements/{ModuleOutputElementType.java => ModuleOutputElementTypeBase.java} (58%) rename java/compiler/impl/src/com/intellij/packaging/impl/elements/{ModuleOutputPackagingElementImpl.java => ModuleOutputPackagingElementBase.java} (77%) create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputElementType.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputPackagingElement.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputElementType.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputPackagingElement.java diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactAntGenerationContextImpl.java b/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactAntGenerationContextImpl.java index e70a69a75722..b422760a1cf2 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactAntGenerationContextImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactAntGenerationContextImpl.java @@ -151,6 +151,11 @@ public class ArtifactAntGenerationContextImpl implements ArtifactAntGenerationCo return BuildProperties.getOutputPathProperty(moduleName); } + @Override + public String getModuleTestOutputPath(@NonNls String moduleName) { + return BuildProperties.getOutputPathForTestsProperty(moduleName); + } + public List getBeforeBuildGenerators() { return myBeforeBuildGenerators; } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java index cbff9ef68971..0083ead2e389 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java @@ -15,9 +15,7 @@ */ package com.intellij.packaging.impl.artifacts; -import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ModuleRootModel; import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.util.MultiValuesMap; import com.intellij.openapi.vfs.VirtualFile; @@ -85,12 +83,8 @@ public class ArtifactBySourceFileFinderImpl extends ArtifactBySourceFileFinder { } } else if (element instanceof ModuleOutputPackagingElement) { - final Module module = ((ModuleOutputPackagingElement)element).findModule(context); - if (module != null) { - final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); - for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) { + for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement)element).getSourceRoots(context)) { result.put(sourceRoot, artifact); - } } } return true; diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java index c8bcf0192b3f..c333b135da30 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java @@ -19,7 +19,6 @@ import com.intellij.compiler.CompilerConfiguration; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.CompilerProjectExtension; -import com.intellij.openapi.roots.ModuleRootModel; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Trinity; @@ -360,13 +359,9 @@ public class ArtifactUtil { @Nullable private static String getRelativePathInSources(@NotNull VirtualFile file, final @NotNull ModuleOutputPackagingElement moduleElement, @NotNull PackagingElementResolvingContext context) { - final Module module = moduleElement.findModule(context); - if (module != null) { - final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); - for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) { - if (VfsUtil.isAncestor(sourceRoot, file, true)) { - return VfsUtil.getRelativePath(file, sourceRoot, '/'); - } + for (VirtualFile sourceRoot : moduleElement.getSourceRoots(context)) { + if (VfsUtil.isAncestor(sourceRoot, file, true)) { + return VfsUtil.getRelativePath(file, sourceRoot, '/'); } } return null; @@ -420,15 +415,11 @@ public class ArtifactUtil { } } else if (element instanceof ModuleOutputPackagingElement) { - final Module module = ((ModuleOutputPackagingElement)element).findModule(context); - if (module != null) { - final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject()); - final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); - for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) { - final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path); - if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) { - result.add(sourceFile); - } + final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject()); + for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement)element).getSourceRoots(context)) { + final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path); + if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) { + result.add(sourceFile); } } } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form index 16d474ec1c9f..59003f1a0353 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form @@ -1,9 +1,9 @@
- + - + @@ -18,7 +18,7 @@ - + @@ -90,6 +90,14 @@ + + + + + + + + diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java index fab2d0833a6b..c53df72d68d9 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java @@ -15,6 +15,7 @@ */ package com.intellij.packaging.impl.artifacts; +import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; @@ -30,7 +31,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.DocumentEvent; -import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; @@ -47,6 +47,7 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { private JLabel myManifestDirLabel; private JRadioButton myExtractJarsRadioButton; private JRadioButton myCopyJarsRadioButton; + private JCheckBox myIncludeTestsCheckBox; private PackagingElementResolvingContext myContext; public JarArtifactFromModulesDialog(PackagingElementResolvingContext context) { @@ -84,7 +85,7 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { for (Module module : modules) { myModuleComboBox.addItem(module); } - myModuleComboBox.setRenderer(new ModuleListRenderer()); + myModuleComboBox.setRenderer(new ModuleListRenderer(myModuleComboBox)); init(); } @@ -122,6 +123,10 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { return myExtractJarsRadioButton.isSelected(); } + public boolean isIncludeTests() { + return myIncludeTestsCheckBox.isSelected(); + } + public String getMainClassName() { return myMainClassField.getText(); } @@ -136,20 +141,21 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { return myMainPanel; } - private static class ModuleListRenderer extends DefaultListCellRenderer { + private static class ModuleListRenderer extends ListCellRendererWrapper { + public ModuleListRenderer(JComboBox comboBox) { + super(comboBox); + } + @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof Module) { - final Module module = (Module)value; - setIcon(module.getModuleType().getNodeIcon(false)); - setText(module.getName()); + public void customize(JList list, Module value, int index, boolean selected, boolean hasFocus) { + if (value != null) { + setIcon(value.getModuleType().getNodeIcon(false)); + setText(value.getName()); } else { setText(""); setIcon(null); } - return component; } } } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java index 30d6468c4ffa..b0fcd6390b24 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java @@ -59,12 +59,14 @@ public class JarFromModulesTemplate extends ArtifactTemplate { } return doCreateArtifact(dialog.getSelectedModules(), dialog.getMainClassName(), dialog.getDirectoryForManifest(), - dialog.isExtractLibrariesToJar()); + dialog.isExtractLibrariesToJar(), dialog.isIncludeTests()); } @Nullable public NewArtifactConfiguration doCreateArtifact(final Module[] modules, final String mainClassName, - final String directoryForManifest, final boolean extractLibrariesToJar) { + final String directoryForManifest, + final boolean extractLibrariesToJar, + final boolean includeTests) { VirtualFile manifestFile = null; final Project project = myContext.getProject(); if (mainClassName != null && !mainClassName.isEmpty() || !extractLibrariesToJar) { @@ -92,14 +94,21 @@ public class JarFromModulesTemplate extends ArtifactTemplate { final PackagingElementFactory factory = PackagingElementFactory.getInstance(); final CompositePackagingElement archive = factory.createArchive(FileUtil.sanitizeFileName(name) + ".jar"); - final OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(project).orderEntries(Arrays.asList(modules)); + OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(project).orderEntries(Arrays.asList(modules)); final Set libraries = new THashSet(); - orderEnumerator.using(myContext.getModulesProvider()).withoutSdk().productionOnly().runtimeOnly().recursively().forEach(new Processor() { + if (!includeTests) { + orderEnumerator = orderEnumerator.productionOnly(); + } + orderEnumerator.using(myContext.getModulesProvider()).withoutSdk().runtimeOnly().recursively().forEach(new Processor() { @Override public boolean process(OrderEntry orderEntry) { if (orderEntry instanceof ModuleSourceOrderEntry) { - archive.addOrFindChild(factory.createModuleOutput(orderEntry.getOwnerModule())); + Module module = orderEntry.getOwnerModule(); + archive.addOrFindChild(factory.createModuleOutput(module)); + if (includeTests) { + archive.addOrFindChild(factory.createTestModuleOutput(module)); + } } else if (orderEntry instanceof LibraryOrderEntry) { ContainerUtil.addIfNotNull(((LibraryOrderEntry)orderEntry).getLibrary(), libraries); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java index 5497a3dc192f..879859bc8540 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java @@ -26,7 +26,7 @@ import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactManager; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.artifacts.ArtifactUtil; -import com.intellij.packaging.impl.elements.ModuleOutputElementType; +import com.intellij.packaging.impl.elements.ProductionModuleOutputElementType; import com.intellij.packaging.impl.elements.ModuleOutputPackagingElement; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; @@ -94,7 +94,7 @@ public class ArtifactCompileScope { private static boolean containsModuleOutput(Artifact artifact, final Set modules, ArtifactManager artifactManager) { final PackagingElementResolvingContext context = artifactManager.getResolvingContext(); - return !ArtifactUtil.processPackagingElements(artifact, ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE, + return !ArtifactUtil.processPackagingElements(artifact, ProductionModuleOutputElementType.ELEMENT_TYPE, new Processor() { public boolean process(ModuleOutputPackagingElement moduleOutputPackagingElement) { final Module module = moduleOutputPackagingElement.findModule(context); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementTypeBase.java similarity index 58% rename from java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementType.java rename to java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementTypeBase.java index 83c3c0a444d0..87b08326e791 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementType.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementTypeBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,12 +15,11 @@ */ package com.intellij.packaging.impl.elements; -import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModulePointer; import com.intellij.openapi.module.ModulePointerManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.util.IconLoader; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; @@ -28,49 +27,37 @@ import com.intellij.packaging.elements.PackagingElementType; import com.intellij.packaging.ui.ArtifactEditorContext; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** -* @author nik -*/ -public class ModuleOutputElementType extends PackagingElementType { - public static final ModuleOutputElementType MODULE_OUTPUT_ELEMENT_TYPE = new ModuleOutputElementType(); - - ModuleOutputElementType() { - super("module-output", CompilerBundle.message("element.type.name.module.output")); - } - - @Override - public Icon getCreateElementIcon() { - return IconLoader.getIcon("/nodes/ModuleOpen.png"); + * @author nik + */ +public abstract class ModuleOutputElementTypeBase extends PackagingElementType { + public ModuleOutputElementTypeBase(String id, String presentableName) { + super(id, presentableName); } @Override public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { - return context.getModulesProvider().getModules().length > 0; + return !getSuitableModules(context).isEmpty(); } @NotNull public List> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement parent) { - List modules = chooseModules(context); + List suitableModules = getSuitableModules(context); + List selected = context.chooseModules(suitableModules, ProjectBundle.message("dialog.title.packaging.choose.module")); + final List> elements = new ArrayList>(); final ModulePointerManager pointerManager = ModulePointerManager.getInstance(context.getProject()); - for (Module module : modules) { - elements.add(new ModuleOutputPackagingElementImpl(context.getProject(), pointerManager.create(module))); + for (Module module : selected) { + elements.add(createElement(context.getProject(), pointerManager.create(module))); } return elements; } - public static List chooseModules(ArtifactEditorContext context) { - return context.chooseModules(Arrays.asList(context.getModulesProvider().getModules()), ProjectBundle.message("dialog.title.packaging.choose.module")); - } + protected abstract ModuleOutputPackagingElementBase createElement(@NotNull Project project, @NotNull ModulePointer pointer); - @NotNull - public ModuleOutputPackagingElementImpl createEmpty(@NotNull Project project) { - return new ModuleOutputPackagingElementImpl(project); - } + protected abstract List getSuitableModules(ArtifactEditorContext context); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElement.java index d2e0bb9da32f..d73572d36529 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElement.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElement.java @@ -16,9 +16,13 @@ package com.intellij.packaging.impl.elements; import com.intellij.openapi.module.Module; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.elements.PackagingElementResolvingContext; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; + /** * @author nik */ @@ -28,4 +32,7 @@ public interface ModuleOutputPackagingElement { @Nullable Module findModule(PackagingElementResolvingContext context); + + @NotNull + Collection getSourceRoots(PackagingElementResolvingContext context); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElementImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElementBase.java similarity index 77% rename from java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElementImpl.java rename to java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElementBase.java index 3d6d71cea825..084cf6ebd456 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElementImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElementBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -27,10 +27,6 @@ import com.intellij.openapi.roots.ui.configuration.ModulesProvider; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.artifacts.ArtifactType; import com.intellij.packaging.elements.*; -import com.intellij.packaging.impl.ui.DelegatedPackagingElementPresentation; -import com.intellij.packaging.impl.ui.ModuleElementPresentation; -import com.intellij.packaging.ui.ArtifactEditorContext; -import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.util.ArrayUtil; import com.intellij.util.xmlb.annotations.Attribute; import org.jetbrains.annotations.NonNls; @@ -43,25 +39,20 @@ import java.util.List; /** * @author nik */ -public class ModuleOutputPackagingElementImpl extends PackagingElement - implements ModuleOutputPackagingElement { +public abstract class ModuleOutputPackagingElementBase extends PackagingElement implements ModuleOutputPackagingElement { @NonNls public static final String MODULE_NAME_ATTRIBUTE = "name"; - private ModulePointer myModulePointer; - private final Project myProject; + protected ModulePointer myModulePointer; + protected final Project myProject; - public ModuleOutputPackagingElementImpl(@NotNull Project project) { - super(ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE); - myProject = project; - } - - public ModuleOutputPackagingElementImpl(@NotNull Project project, @NotNull ModulePointer modulePointer) { - super(ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE); + public ModuleOutputPackagingElementBase(PackagingElementType type, Project project, ModulePointer modulePointer) { + super(type); myProject = project; myModulePointer = modulePointer; } - public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) { - return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModulePointer, context)); + public ModuleOutputPackagingElementBase(PackagingElementType type, Project project) { + super(type); + myProject = project; } @Override @@ -69,12 +60,14 @@ public class ModuleOutputPackagingElementImpl extends PackagingElement element) { - return element instanceof ModuleOutputPackagingElementImpl && myModulePointer != null - && myModulePointer.equals(((ModuleOutputPackagingElementImpl)element).myModulePointer); + return element.getClass() == getClass() && myModulePointer != null + && myModulePointer.equals(((ModuleOutputPackagingElementBase)element).myModulePointer); } public ModuleOutputPackagingElementState getState() { @@ -116,11 +112,6 @@ public class ModuleOutputPackagingElementImpl extends PackagingElement> ARTIFACT_ROOT_ELEMENT_TYPE = new ArtifactRootElementType(); private static final PackagingElementType[] STANDARD_TYPES = { DIRECTORY_ELEMENT_TYPE, ARCHIVE_ELEMENT_TYPE, - LibraryElementType.LIBRARY_ELEMENT_TYPE, ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE, + LibraryElementType.LIBRARY_ELEMENT_TYPE, ProductionModuleOutputElementType.ELEMENT_TYPE, TestModuleOutputElementType.ELEMENT_TYPE, ArtifactElementType.ARTIFACT_ELEMENT_TYPE, FILE_COPY_ELEMENT_TYPE, DIRECTORY_COPY_ELEMENT_TYPE, EXTRACTED_DIRECTORY_ELEMENT_TYPE }; @@ -181,14 +181,21 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { @NotNull public PackagingElement createModuleOutput(@NotNull String moduleName, @NotNull Project project) { final ModulePointer pointer = ModulePointerManager.getInstance(project).create(moduleName); - return new ModuleOutputPackagingElementImpl(project, pointer); + return new ProductionModuleOutputPackagingElement(project, pointer); } @NotNull @Override public PackagingElement createModuleOutput(@NotNull Module module) { final ModulePointer modulePointer = ModulePointerManager.getInstance(module.getProject()).create(module); - return new ModuleOutputPackagingElementImpl(module.getProject(), modulePointer); + return new ProductionModuleOutputPackagingElement(module.getProject(), modulePointer); + } + + @NotNull + @Override + public PackagingElement createTestModuleOutput(@NotNull Module module) { + ModulePointer pointer = ModulePointerManager.getInstance(module.getProject()).create(module); + return new TestModuleOutputPackagingElement(module.getProject(), pointer); } @NotNull diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputElementType.java new file mode 100644 index 000000000000..9545b365961e --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputElementType.java @@ -0,0 +1,65 @@ +/* + * 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.packaging.impl.elements; + +import com.intellij.openapi.compiler.CompilerBundle; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModulePointer; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ui.configuration.ModulesProvider; +import com.intellij.openapi.util.IconLoader; +import com.intellij.packaging.ui.ArtifactEditorContext; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** +* @author nik +*/ +public class ProductionModuleOutputElementType extends ModuleOutputElementTypeBase { + public static final ProductionModuleOutputElementType ELEMENT_TYPE = new ProductionModuleOutputElementType(); + + ProductionModuleOutputElementType() { + super("module-output", CompilerBundle.message("element.type.name.module.output")); + } + + @NotNull + public ProductionModuleOutputPackagingElement createEmpty(@NotNull Project project) { + return new ProductionModuleOutputPackagingElement(project); + } + + protected ModuleOutputPackagingElementBase createElement(@NotNull Project project, @NotNull ModulePointer pointer) { + return new ProductionModuleOutputPackagingElement(project, pointer); + } + + @Override + public Icon getCreateElementIcon() { + return IconLoader.getIcon("/nodes/ModuleOpen.png"); + } + + protected List getSuitableModules(ArtifactEditorContext context) { + ArrayList modules = new ArrayList(); + ModulesProvider modulesProvider = context.getModulesProvider(); + for (Module module : modulesProvider.getModules()) { + if (modulesProvider.getRootModel(module).getSourceRootUrls(false).length > 0) { + modules.add(module); + } + } + return modules; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputPackagingElement.java new file mode 100644 index 000000000000..6ee8e8c52231 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ProductionModuleOutputPackagingElement.java @@ -0,0 +1,75 @@ +/* + * 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.packaging.impl.elements; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModulePointer; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.CompilerModuleExtension; +import com.intellij.openapi.roots.ModuleRootModel; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.elements.ArtifactAntGenerationContext; +import com.intellij.packaging.elements.PackagingElementResolvingContext; +import com.intellij.packaging.impl.ui.DelegatedPackagingElementPresentation; +import com.intellij.packaging.impl.ui.ModuleElementPresentation; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingElementPresentation; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +/** + * @author nik + */ +public class ProductionModuleOutputPackagingElement extends ModuleOutputPackagingElementBase { + public ProductionModuleOutputPackagingElement(@NotNull Project project) { + super(ProductionModuleOutputElementType.ELEMENT_TYPE, project); + } + + public ProductionModuleOutputPackagingElement(@NotNull Project project, @NotNull ModulePointer modulePointer) { + super(ProductionModuleOutputElementType.ELEMENT_TYPE, project, modulePointer); + } + + @NonNls @Override + public String toString() { + return "module:" + getModuleName(); + } + + protected String getModuleOutputAntProperty(ArtifactAntGenerationContext generationContext) { + return generationContext.getModuleOutputPath(myModulePointer.getModuleName()); + } + + protected VirtualFile getModuleOutputPath(CompilerModuleExtension extension) { + return extension.getCompilerOutputPath(); + } + + @NotNull + @Override + public Collection getSourceRoots(PackagingElementResolvingContext context) { + Module module = findModule(context); + if (module == null) return Collections.emptyList(); + + ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); + return Arrays.asList(rootModel.getSourceRoots(false)); + } + + public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) { + return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModulePointer, context, false)); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputElementType.java new file mode 100644 index 000000000000..b8ec5ecab07f --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputElementType.java @@ -0,0 +1,78 @@ +/* + * Copyright 2000-2011 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.packaging.impl.elements; + +import com.intellij.openapi.compiler.CompilerBundle; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModulePointer; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModuleRootModel; +import com.intellij.openapi.roots.SourceFolder; +import com.intellij.openapi.roots.ui.configuration.ModulesProvider; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.util.Icons; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class TestModuleOutputElementType extends ModuleOutputElementTypeBase { + public static final TestModuleOutputElementType ELEMENT_TYPE = new TestModuleOutputElementType(); + + public TestModuleOutputElementType() { + super("module-test-output", CompilerBundle.message("element.type.name.module.test.output")); + } + + @NotNull + @Override + public TestModuleOutputPackagingElement createEmpty(@NotNull Project project) { + return new TestModuleOutputPackagingElement(project); + } + + protected ModuleOutputPackagingElementBase createElement(@NotNull Project project, @NotNull ModulePointer pointer) { + return new TestModuleOutputPackagingElement(project, pointer); + } + + @Override + public Icon getCreateElementIcon() { + return Icons.TEST_SOURCE_FOLDER; + } + + protected List getSuitableModules(ArtifactEditorContext context) { + ModulesProvider modulesProvider = context.getModulesProvider(); + ArrayList modules = new ArrayList(); + for (Module module : modulesProvider.getModules()) { + if (hasTestSourceRoots(modulesProvider.getRootModel(module))) { + modules.add(module); + } + } + return modules; + } + + private static boolean hasTestSourceRoots(final ModuleRootModel rootModel) { + for (ContentEntry entry : rootModel.getContentEntries()) { + for (SourceFolder folder : entry.getSourceFolders()) { + if (folder.isTestSource()) return true; + } + } + return false; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputPackagingElement.java new file mode 100644 index 000000000000..f3110a09f505 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/TestModuleOutputPackagingElement.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2011 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.packaging.impl.elements; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModulePointer; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.CompilerModuleExtension; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModuleRootModel; +import com.intellij.openapi.roots.SourceFolder; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.elements.ArtifactAntGenerationContext; +import com.intellij.packaging.elements.PackagingElementResolvingContext; +import com.intellij.packaging.impl.ui.DelegatedPackagingElementPresentation; +import com.intellij.packaging.impl.ui.ModuleElementPresentation; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingElementPresentation; +import com.intellij.util.SmartList; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * @author nik + */ +public class TestModuleOutputPackagingElement extends ModuleOutputPackagingElementBase { + public TestModuleOutputPackagingElement(Project project) { + super(TestModuleOutputElementType.ELEMENT_TYPE, project); + } + + public TestModuleOutputPackagingElement(Project project, ModulePointer modulePointer) { + super(TestModuleOutputElementType.ELEMENT_TYPE, project, modulePointer); + } + + @Override + public String toString() { + return "module-tests:" + getModuleName(); + } + + protected String getModuleOutputAntProperty(ArtifactAntGenerationContext generationContext) { + return generationContext.getModuleTestOutputPath(myModulePointer.getModuleName()); + } + + protected VirtualFile getModuleOutputPath(CompilerModuleExtension extension) { + return extension.getCompilerOutputPathForTests(); + } + + @NotNull + @Override + public Collection getSourceRoots(PackagingElementResolvingContext context) { + Module module = findModule(context); + if (module == null) return Collections.emptyList(); + + List roots = new SmartList(); + ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); + for (ContentEntry entry : rootModel.getContentEntries()) { + for (SourceFolder folder : entry.getSourceFolders()) { + if (folder.isTestSource()) { + ContainerUtil.addIfNotNull(folder.getFile(), roots); + } + } + } + return roots; + } + + public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) { + return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModulePointer, context, true)); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java index 48d8319dcf64..47c793ba7b28 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java @@ -20,10 +20,11 @@ import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModulePointer; +import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.packaging.ui.TreeNodePresentation; -import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.ui.SimpleTextAttributes; +import com.intellij.util.Icons; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,10 +34,12 @@ import org.jetbrains.annotations.Nullable; public class ModuleElementPresentation extends TreeNodePresentation { private final ModulePointer myModulePointer; private final ArtifactEditorContext myContext; + private final boolean myTestOutput; - public ModuleElementPresentation(@Nullable ModulePointer modulePointer, @NotNull ArtifactEditorContext context) { + public ModuleElementPresentation(@Nullable ModulePointer modulePointer, @NotNull ArtifactEditorContext context, final boolean testOutput) { myModulePointer = modulePointer; myContext = context; + myTestOutput = testOutput; } public String getPresentableName() { @@ -68,7 +71,10 @@ public class ModuleElementPresentation extends TreeNodePresentation { public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { final Module module = findModule(); - if (module != null) { + if (myTestOutput) { + presentationData.setIcons(Icons.TEST_SOURCE_FOLDER); + } + else if (module != null) { presentationData.setOpenIcon(module.getModuleType().getNodeIcon(true)); presentationData.setClosedIcon(module.getModuleType().getNodeIcon(false)); } @@ -90,8 +96,9 @@ public class ModuleElementPresentation extends TreeNodePresentation { moduleName = ""; } - presentationData.addText(CompilerBundle.message("node.text.0.compile.output", moduleName), - module != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES); + String text = myTestOutput ? CompilerBundle.message("node.text.0.test.compile.output", moduleName) + : CompilerBundle.message("node.text.0.compile.output", moduleName); + presentationData.addText(text, module != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES); } @Override diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/ArtifactAntGenerationContext.java b/java/compiler/openapi/src/com/intellij/packaging/elements/ArtifactAntGenerationContext.java index 9adf2bd89663..46864f3984d8 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/ArtifactAntGenerationContext.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/ArtifactAntGenerationContext.java @@ -37,6 +37,8 @@ public interface ArtifactAntGenerationContext { String getModuleOutputPath(@NonNls String moduleName); + String getModuleTestOutputPath(@NonNls String moduleName); + String getSubstitutedPath(@NonNls String path); String getArtifactOutputProperty(@NotNull Artifact artifact); diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java index eaf0c6f2554e..90fb5b610a55 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java @@ -52,6 +52,9 @@ public abstract class PackagingElementFactory { @NotNull public abstract PackagingElement createModuleOutput(@NotNull Module module); + @NotNull + public abstract PackagingElement createTestModuleOutput(@NotNull Module module); + @NotNull public abstract List> createLibraryElements(@NotNull Library library); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleOutputSourceItem.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleOutputSourceItem.java index 9feefd1a5fb0..160f4c4e2599 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleOutputSourceItem.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleOutputSourceItem.java @@ -20,7 +20,7 @@ import com.intellij.openapi.module.ModulePointer; import com.intellij.openapi.module.ModulePointerManager; import com.intellij.packaging.elements.PackagingElement; import com.intellij.packaging.elements.PackagingElementOutputKind; -import com.intellij.packaging.impl.elements.ModuleOutputPackagingElementImpl; +import com.intellij.packaging.impl.elements.ProductionModuleOutputPackagingElement; import com.intellij.packaging.impl.ui.ModuleElementPresentation; import com.intellij.packaging.ui.*; import org.jetbrains.annotations.NotNull; @@ -49,7 +49,7 @@ public class ModuleOutputSourceItem extends PackagingSourceItem { @Override public SourceItemPresentation createPresentation(@NotNull ArtifactEditorContext context) { final ModulePointer modulePointer = ModulePointerManager.getInstance(context.getProject()).create(myModule); - return new DelegatedSourceItemPresentation(new ModuleElementPresentation(modulePointer, context)) { + return new DelegatedSourceItemPresentation(new ModuleElementPresentation(modulePointer, context, false)) { @Override public int getWeight() { return SourceItemWeights.MODULE_OUTPUT_WEIGHT; @@ -60,7 +60,7 @@ public class ModuleOutputSourceItem extends PackagingSourceItem { @NotNull public List> createElements(@NotNull ArtifactEditorContext context) { final ModulePointer modulePointer = ModulePointerManager.getInstance(context.getProject()).create(myModule); - return Collections.singletonList(new ModuleOutputPackagingElementImpl(context.getProject(), modulePointer)); + return Collections.singletonList(new ProductionModuleOutputPackagingElement(context.getProject(), modulePointer)); } @NotNull diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModulesAndLibrariesSourceItemsProvider.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModulesAndLibrariesSourceItemsProvider.java index 48fd8edf35a2..8b3688dd8a25 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModulesAndLibrariesSourceItemsProvider.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModulesAndLibrariesSourceItemsProvider.java @@ -24,7 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.impl.artifacts.ArtifactUtil; import com.intellij.packaging.impl.elements.FileCopyPackagingElement; -import com.intellij.packaging.impl.elements.ModuleOutputElementType; +import com.intellij.packaging.impl.elements.ProductionModuleOutputElementType; import com.intellij.packaging.impl.elements.ModuleOutputPackagingElement; import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl; import com.intellij.packaging.ui.ArtifactEditorContext; @@ -109,7 +109,7 @@ public class ModulesAndLibrariesSourceItemsProvider extends PackagingSourceItems private static List getNotAddedModules(@NotNull final ArtifactEditorContext context, @NotNull Artifact artifact, final Module... allModules) { final Set modules = new HashSet(Arrays.asList(allModules)); - ArtifactUtil.processPackagingElements(artifact, ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE, new Processor() { + ArtifactUtil.processPackagingElements(artifact, ProductionModuleOutputElementType.ELEMENT_TYPE, new Processor() { public boolean process(ModuleOutputPackagingElement moduleOutputPackagingElement) { modules.remove(moduleOutputPackagingElement.findModule(context)); return true; diff --git a/resources-en/src/messages/CompilerBundle.properties b/resources-en/src/messages/CompilerBundle.properties index b7ab2a5bfca9..154f2e72dc1c 100644 --- a/resources-en/src/messages/CompilerBundle.properties +++ b/resources-en/src/messages/CompilerBundle.properties @@ -159,8 +159,10 @@ dialog.title.choose.artifacts=Choose Artifacts node.text.0.directory.content=''{0}'' directory content element.type.name.library.files=Library Files node.text.0.compile.output=''{0}'' compile output +node.text.0.test.compile.output=''{0}'' test compile output node.text.0.with.dependencies=''{0}'' with dependencies element.type.name.module.output=Module Output +element.type.name.module.test.output=Module Test Output element.type.name.directory=Directory element.type.name.archive=Archive artifact.type.plain=Other