allow to add module test compile output into artifact (IDEA-53226)

This commit is contained in:
nik
2011-04-06 08:59:34 +04:00
parent cce2c02db1
commit f2b140e833
21 changed files with 435 additions and 112 deletions
@@ -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<Generator> getBeforeBuildGenerators() {
return myBeforeBuildGenerators;
}
@@ -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;
@@ -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);
}
}
}
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.packaging.impl.artifacts.JarArtifactFromModulesDialog">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="7" 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="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="521" height="400"/>
</constraints>
<properties/>
<border type="none"/>
@@ -18,7 +18,7 @@
</component>
<vspacer id="8cb38">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="6" 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>
<component id="535a8" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myMainClassField">
@@ -90,6 +90,14 @@
</component>
</children>
</grid>
<component id="d5a56" class="javax.swing.JCheckBox" binding="myIncludeTestsCheckBox">
<constraints>
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Include tests"/>
</properties>
</component>
</children>
</grid>
<buttonGroups>
@@ -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<Module> {
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("<All Modules>");
setIcon(null);
}
return component;
}
}
}
@@ -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<Library> libraries = new THashSet<Library>();
orderEnumerator.using(myContext.getModulesProvider()).withoutSdk().productionOnly().runtimeOnly().recursively().forEach(new Processor<OrderEntry>() {
if (!includeTests) {
orderEnumerator = orderEnumerator.productionOnly();
}
orderEnumerator.using(myContext.getModulesProvider()).withoutSdk().runtimeOnly().recursively().forEach(new Processor<OrderEntry>() {
@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);
@@ -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<Module> 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<ModuleOutputPackagingElement>() {
public boolean process(ModuleOutputPackagingElement moduleOutputPackagingElement) {
final Module module = moduleOutputPackagingElement.findModule(context);
@@ -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<ModuleOutputPackagingElementImpl> {
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<E extends ModuleOutputPackagingElementBase> extends PackagingElementType<E> {
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<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
@NotNull CompositePackagingElement<?> parent) {
List<Module> modules = chooseModules(context);
List<Module> suitableModules = getSuitableModules(context);
List<Module> selected = context.chooseModules(suitableModules, ProjectBundle.message("dialog.title.packaging.choose.module"));
final List<PackagingElement<?>> elements = new ArrayList<PackagingElement<?>>();
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<Module> 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<Module> getSuitableModules(ArtifactEditorContext context);
}
@@ -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<VirtualFile> getSourceRoots(PackagingElementResolvingContext context);
}
@@ -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<ModuleOutputPackagingElementImpl.ModuleOutputPackagingElementState>
implements ModuleOutputPackagingElement {
public abstract class ModuleOutputPackagingElementBase extends PackagingElement<ModuleOutputPackagingElementBase.ModuleOutputPackagingElementState> 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<ModuleOut
@NotNull ArtifactAntGenerationContext generationContext,
@NotNull ArtifactType artifactType) {
if (myModulePointer != null) {
final String moduleOutput = BuildProperties.propertyRef(generationContext.getModuleOutputPath(myModulePointer.getModuleName()));
final String moduleOutput = BuildProperties.propertyRef(getModuleOutputAntProperty(generationContext));
return Collections.singletonList(creator.createDirectoryContentCopyInstruction(moduleOutput));
}
return Collections.emptyList();
}
protected abstract String getModuleOutputAntProperty(ArtifactAntGenerationContext generationContext);
@Override
public void computeIncrementalCompilerInstructions(@NotNull IncrementalCompilerInstructionCreator creator,
@NotNull PackagingElementResolvingContext resolvingContext,
@@ -83,7 +76,7 @@ public class ModuleOutputPackagingElementImpl extends PackagingElement<ModuleOut
if (module != null) {
final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
if (extension != null) {
final VirtualFile output = extension.getCompilerOutputPath();
final VirtualFile output = getModuleOutputPath(extension);
if (output != null) {
creator.addDirectoryCopyInstructions(output, null);
}
@@ -91,6 +84,9 @@ public class ModuleOutputPackagingElementImpl extends PackagingElement<ModuleOut
}
}
@Nullable
protected abstract VirtualFile getModuleOutputPath(CompilerModuleExtension extension);
@NotNull
@Override
public PackagingElementOutputKind getFilesKind(PackagingElementResolvingContext context) {
@@ -99,8 +95,8 @@ public class ModuleOutputPackagingElementImpl extends PackagingElement<ModuleOut
@Override
public boolean isEqualTo(@NotNull 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<ModuleOut
myModulePointer = moduleName != null ? ModulePointerManager.getInstance(myProject).create(moduleName) : null;
}
@NonNls @Override
public String toString() {
return "module:" + getModuleName();
}
@Override
@Nullable
public String getModuleName() {
@@ -58,7 +58,7 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
public static final PackagingElementType<ArtifactRootElement<?>> 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
@@ -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<ProductionModuleOutputPackagingElement> {
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<Module> getSuitableModules(ArtifactEditorContext context) {
ArrayList<Module> modules = new ArrayList<Module>();
ModulesProvider modulesProvider = context.getModulesProvider();
for (Module module : modulesProvider.getModules()) {
if (modulesProvider.getRootModel(module).getSourceRootUrls(false).length > 0) {
modules.add(module);
}
}
return modules;
}
}
@@ -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<VirtualFile> 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));
}
}
@@ -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<TestModuleOutputPackagingElement> {
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<Module> getSuitableModules(ArtifactEditorContext context) {
ModulesProvider modulesProvider = context.getModulesProvider();
ArrayList<Module> modules = new ArrayList<Module>();
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;
}
}
@@ -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<VirtualFile> getSourceRoots(PackagingElementResolvingContext context) {
Module module = findModule(context);
if (module == null) return Collections.emptyList();
List<VirtualFile> roots = new SmartList<VirtualFile>();
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));
}
}
@@ -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 = "<unknown>";
}
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
@@ -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);
@@ -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<? extends PackagingElement<?>> createLibraryElements(@NotNull Library library);
@@ -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<? extends PackagingElement<?>> 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
@@ -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<? extends Module> getNotAddedModules(@NotNull final ArtifactEditorContext context, @NotNull Artifact artifact,
final Module... allModules) {
final Set<Module> modules = new HashSet<Module>(Arrays.asList(allModules));
ArtifactUtil.processPackagingElements(artifact, ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE, new Processor<ModuleOutputPackagingElement>() {
ArtifactUtil.processPackagingElements(artifact, ProductionModuleOutputElementType.ELEMENT_TYPE, new Processor<ModuleOutputPackagingElement>() {
public boolean process(ModuleOutputPackagingElement moduleOutputPackagingElement) {
modules.remove(moduleOutputPackagingElement.findModule(context));
return true;
@@ -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