migrated to artifacts

This commit is contained in:
nik
2009-10-02 14:45:21 +04:00
parent fcd6e431c0
commit eb9e26d2fa
81 changed files with 501 additions and 4372 deletions
@@ -5,7 +5,6 @@ import com.intellij.compiler.impl.javaCompiler.JavaCompiler;
import com.intellij.compiler.impl.packagingCompiler.IncrementalPackagingCompiler;
import com.intellij.compiler.impl.resourceCompiler.ResourceCompiler;
import com.intellij.compiler.impl.rmiCompiler.RmicCompiler;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.compiler.Compiler;
import com.intellij.openapi.extensions.Extensions;
@@ -15,7 +14,6 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.packaging.impl.compiler.IncrementalArtifactsCompiler;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Chunk;
@@ -57,9 +55,7 @@ public class CompilerManagerImpl extends CompilerManager {
addCompiler(new ResourceCompiler(project, compilerConfiguration));
addCompiler(new RmicCompiler());
addCompiler(new IncrementalPackagingCompiler());
if (ArtifactManager.useArtifacts() || ApplicationManager.getApplication().isUnitTestMode()) {
addCompiler(new IncrementalArtifactsCompiler());
}
addCompiler(new IncrementalArtifactsCompiler());
for(Compiler compiler: Extensions.getExtensions(Compiler.EP_NAME, myProject)) {
addCompiler(compiler);
@@ -1,14 +1,19 @@
package com.intellij.compiler.actions;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.NotNullFunction;
import com.intellij.packaging.artifacts.ArtifactManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* @author nik
*/
@@ -23,12 +28,13 @@ public class BuildArtifactActionGroup extends ActionGroup {
final Project project = e.getData(PlatformDataKeys.PROJECT);
if (project == null) return EMPTY_ARRAY;
final Artifact[] artifacts = ArtifactManager.getInstance(project).getArtifacts();
return ContainerUtil.map2Array(artifacts, AnAction.class, new NotNullFunction<Artifact, AnAction>() {
@NotNull
public AnAction fun(Artifact artifact) {
return new BuildArtifactAction(project, artifact);
final Artifact[] artifacts = ArtifactManager.getInstance(project).getSortedArtifacts();
List<AnAction> actions = new ArrayList<AnAction>();
for (Artifact artifact : artifacts) {
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
actions.add(new BuildArtifactAction(project, artifact));
}
});
}
return actions.toArray(new AnAction[actions.size()]);
}
}
@@ -54,7 +54,7 @@ public abstract class ProjectBuild extends Generator {
myAntProject.add(initTarget, 1);
ArtifactsGenerator artifactsGenerator;
if (ArtifactManager.useArtifacts()) {
if (ArtifactManager.getInstance(project).getArtifacts().length > 0) {
artifactsGenerator = new ArtifactsGenerator(project, genOptions);
}
else {
@@ -12,7 +12,6 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
@@ -413,16 +412,6 @@ public class DeploymentUtilImpl extends DeploymentUtil {
}
}
public void addModuleOutputJarToParent(@NotNull BuildRecipe instructions,
@NotNull Module module,
@NotNull String relativePath,
@NotNull CompileContext context,
String linkContainerDescription,
@Nullable PackagingFileFilter fileFilter) {
String path = getRelativePathForManifestLinking(relativePath);
addJarJavaModuleOutput(instructions, module, path, context, linkContainerDescription, fileFilter);
}
private static void addJarJavaModuleOutput(BuildRecipe instructions,
Module module,
String relativePath,
@@ -449,38 +438,10 @@ public class DeploymentUtilImpl extends DeploymentUtil {
return new LibraryLinkImpl(library, parentModule);
}
public PackagingConfiguration createPackagingConfiguration(@NotNull Module module) {
return new PackagingConfigurationImpl(module);
}
public BuildRecipe createBuildRecipe() {
return new BuildRecipeImpl();
}
public @Nullable ContainerElement findElementByOrderEntry(PackagingConfiguration packagingConfiguration, OrderEntry entry) {
if (entry instanceof ModuleOrderEntry) {
final Module module = ((ModuleOrderEntry)entry).getModule();
if (module == null) return null;
for (ModuleLink link : packagingConfiguration.getContainingModules()) {
if (link.getModule() == module) {
return link;
}
}
}
else if (entry instanceof LibraryOrderEntry) {
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) return null;
for (LibraryLink link : packagingConfiguration.getContainingLibraries()) {
if (OrderEntryUtil.equals(library, link.getLibrary())) {
return link;
}
}
}
return null;
}
@Nullable
public String getConfigFileErrorMessage(final ConfigFile configFile) {
if (configFile.getVirtualFile() == null) {
@@ -1,5 +1,6 @@
package com.intellij.packaging.impl.artifacts;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.packaging.artifacts.ArtifactProperties;
import com.intellij.packaging.artifacts.ArtifactPropertiesProvider;
import com.intellij.packaging.artifacts.ArtifactType;
@@ -16,7 +17,7 @@ import java.util.Map;
/**
* @author nik
*/
public class ArtifactImpl implements ModifiableArtifact {
public class ArtifactImpl extends UserDataHolderBase implements ModifiableArtifact {
private CompositePackagingElement<?> myRootElement;
private String myName;
private boolean myBuildOnMake;
@@ -8,8 +8,10 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.packaging.artifacts.*;
import com.intellij.packaging.elements.*;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import gnu.trove.THashSet;
@@ -18,10 +20,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* @author nik
@@ -36,18 +35,19 @@ import java.util.Set;
public class ArtifactManagerImpl extends ArtifactManager implements ProjectComponent, PersistentStateComponent<ArtifactManagerState> {
private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.artifacts.ArtifactManagerImpl");
@NonNls public static final String COMPONENT_NAME = "ArtifactManager";
@NonNls public static final String PACKAGING_ELEMENT_NAME = "element";
@NonNls public static final String TYPE_ID_ATTRIBUTE = "id";
private final ArtifactManagerModel myModel = new ArtifactManagerModel();
private final Project myProject;
private final DefaultPackagingElementResolvingContext myResolvingContext;
private boolean myInsideCommit = false;
@NonNls public static final String PACKAGING_ELEMENT_NAME = "element";
@NonNls public static final String TYPE_ID_ATTRIBUTE = "id";
private long myModificationCount;
private final ModificationTracker myModificationTracker = new ModificationTracker() {
public long getModificationCount() {
return myModificationCount;
}
};
private Map<String, LocalFileSystem.WatchRequest> myWatchedOutputs = new HashMap<String, LocalFileSystem.WatchRequest>();
public ArtifactManagerImpl(Project project) {
myProject = project;
@@ -182,6 +182,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
}
public void disposeComponent() {
LocalFileSystem.getInstance().removeWatchedRoots(myWatchedOutputs.values());
}
@NotNull
@@ -190,6 +191,34 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
}
public void initComponent() {
updateWatchedRoots();
}
private void updateWatchedRoots() {
Set<String> pathsToRemove = new HashSet<String>(myWatchedOutputs.keySet());
Set<String> toAdd = new HashSet<String>();
for (Artifact artifact : getArtifacts()) {
final String path = artifact.getOutputPath();
if (path != null && path.length() > 0) {
pathsToRemove.remove(path);
if (!myWatchedOutputs.containsKey(path)) {
toAdd.add(path);
}
}
}
List<LocalFileSystem.WatchRequest> requestsToRemove = new ArrayList<LocalFileSystem.WatchRequest>();
for (String path : pathsToRemove) {
final LocalFileSystem.WatchRequest request = myWatchedOutputs.remove(path);
ContainerUtil.addIfNotNull(request, requestsToRemove);
}
final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
fileSystem.removeWatchedRoots(requestsToRemove);
final Set<LocalFileSystem.WatchRequest> newRequests = fileSystem.addRootsToWatch(toAdd, true);
for (LocalFileSystem.WatchRequest request : newRequests) {
myWatchedOutputs.put(request.getRootPath(), request);
}
}
public void projectOpened() {
@@ -198,6 +227,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
public void projectClosed() {
}
@Override
public Artifact[] getSortedArtifacts() {
return myModel.getSortedArtifacts();
}
@Override
public ModifiableArtifactModel createModifiableModel() {
((ArtifactPointerManagerImpl)ArtifactPointerManager.getInstance(myProject)).updateAllPointers();
@@ -278,6 +312,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
}.execute().getResultObject();
}
@Override
public void addElementsToDirectory(@NotNull Artifact artifact, @NotNull String relativePath, @NotNull PackagingElement<?> element) {
addElementsToDirectory(artifact, relativePath, Collections.singletonList(element));
}
@Override
public void addElementsToDirectory(@NotNull Artifact artifact, @NotNull String relativePath,
@NotNull Collection<? extends PackagingElement<?>> elements) {
@@ -298,15 +337,30 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
private static class ArtifactManagerModel extends ArtifactModelBase {
private List<ArtifactImpl> myArtifactsList = new ArrayList<ArtifactImpl>();
private Artifact[] mySortedArtifacts;
public void setArtifactsList(List<ArtifactImpl> artifactsList) {
myArtifactsList = artifactsList;
artifactsChanged();
}
@Override
protected void artifactsChanged() {
super.artifactsChanged();
mySortedArtifacts = null;
}
protected List<? extends Artifact> getArtifactsList() {
return myArtifactsList;
}
public Artifact[] getSortedArtifacts() {
if (mySortedArtifacts == null) {
mySortedArtifacts = getArtifacts().clone();
Arrays.sort(mySortedArtifacts, ARTIFACT_COMPARATOR);
}
return mySortedArtifacts;
}
}
}
@@ -57,9 +57,10 @@ public class ArtifactPointerManagerImpl extends ArtifactPointerManager {
}
public ArtifactPointer create(@NotNull Artifact artifact) {
ArtifactPointerImpl pointer = myPointers.get(artifact.getName());
final String name = artifact.getName();
ArtifactPointerImpl pointer = myPointers.get(name);
if (pointer == null) {
pointer = new ArtifactPointerImpl(myProject, artifact);
pointer = new ArtifactPointerImpl(myProject, name);
myPointers.put(artifact.getName(), pointer);
}
return pointer;
@@ -2,6 +2,7 @@ package com.intellij.packaging.impl.artifacts;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.CompilerProjectExtension;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -181,19 +182,31 @@ public class ArtifactUtil {
return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
}
public static boolean processElements(@NotNull List<? extends PackagingElement<?>> elements,
public static <E extends PackagingElement<?>> boolean processElements(@NotNull List<? extends PackagingElement<?>> elements,
@NotNull PackagingElementResolvingContext context,
@NotNull ArtifactType artifactType,
@NotNull Processor<PackagingElement<?>> processor) {
@NotNull final Processor<E> processor) {
return processElements(elements, context, artifactType, new PackagingElementProcessor<E>() {
@Override
public boolean process(@NotNull List<CompositePackagingElement<?>> parents, @NotNull E e) {
return processor.process(e);
}
});
}
public static <E extends PackagingElement<?>> boolean processElements(@NotNull List<? extends PackagingElement<?>> elements,
@NotNull PackagingElementResolvingContext context,
@NotNull ArtifactType artifactType,
@NotNull PackagingElementProcessor<E> processor) {
for (PackagingElement<?> element : elements) {
if (element instanceof ComplexPackagingElement<?>) {
if (element instanceof ComplexPackagingElement<?> && processor.shouldProcessSubstitution((ComplexPackagingElement)element)) {
final List<? extends PackagingElement<?>> substitution =
((ComplexPackagingElement<?>)element).getSubstitution(context, artifactType);
if (substitution != null && !processElements(substitution, context, artifactType, processor)) {
return false;
}
}
else if (!processor.process(element)) {
else if (!processor.process(FList.<CompositePackagingElement<?>>emptyList(), (E)element)) {
return false;
}
}
@@ -444,4 +457,22 @@ public class ArtifactUtil {
public static boolean isArchiveName(String name) {
return name.length() >= 4 && name.charAt(name.length() - 4) == '.' && StringUtil.endsWithIgnoreCase(name, "ar");
}
public static void removeChildrenRecursively(@NotNull CompositePackagingElement<?> element, @NotNull Condition<PackagingElement<?>> condition) {
List<PackagingElement<?>> toRemove = new ArrayList<PackagingElement<?>>();
for (PackagingElement<?> child : element.getChildren()) {
if (child instanceof CompositePackagingElement<?>) {
final CompositePackagingElement<?> compositeChild = (CompositePackagingElement<?>)child;
removeChildrenRecursively(compositeChild, condition);
if (compositeChild.getChildren().isEmpty()) {
toRemove.add(child);
}
}
else if (condition.value(child)) {
toRemove.add(child);
}
}
element.removeChildren(toRemove);
}
}
@@ -1,10 +1,8 @@
package com.intellij.packaging.impl.artifacts;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.packaging.elements.ComplexPackagingElement;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElement;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -23,11 +21,14 @@ public abstract class PackagingElementProcessor<E extends PackagingElement<?>> {
public abstract boolean process(@NotNull List<CompositePackagingElement<?>> parents, @NotNull E e);
protected final String getPathFromRoot(List<CompositePackagingElement<?>> parents, String separator) {
return StringUtil.join(parents, new Function<CompositePackagingElement<?>, String>() {
public String fun(CompositePackagingElement<?> element) {
return element.getName();
protected static String getPathFromRoot(List<CompositePackagingElement<?>> parents, String separator) {
StringBuilder builder = new StringBuilder();
for (int i = parents.size() - 1; i >= 0; i--) {
builder.append(parents.get(i).getName());
if (i > 0) {
builder.append(separator);
}
}, separator);
}
return builder.toString();
}
}
@@ -11,25 +11,24 @@ import org.jetbrains.annotations.Nullable;
* @author nik
*/
public class CopyToDirectoryInstructionCreator extends IncrementalCompilerInstructionCreatorBase {
private final ArtifactsProcessingItemsBuilderContext myContext;
private final String myOutputPath;
private final @Nullable VirtualFile myOutputFile;
public CopyToDirectoryInstructionCreator(ArtifactsProcessingItemsBuilderContext context, String outputPath, @Nullable VirtualFile outputFile) {
myContext = context;
super(context);
myOutputPath = outputPath;
myOutputFile = outputFile;
}
public void addFileCopyInstruction(@NotNull VirtualFile file, String outputFileName) {
public void addFileCopyInstruction(@NotNull VirtualFile file, @NotNull String outputFileName) {
myContext.addDestination(file, new ExplodedDestinationInfo(myOutputPath + "/" + outputFileName, outputChild(outputFileName)));
}
public IncrementalCompilerInstructionCreator subFolder(String directoryName) {
public IncrementalCompilerInstructionCreator subFolder(@NotNull String directoryName) {
return new CopyToDirectoryInstructionCreator(myContext, myOutputPath + "/" + directoryName, outputChild(directoryName));
}
public IncrementalCompilerInstructionCreator archive(String archiveFileName) {
public IncrementalCompilerInstructionCreator archive(@NotNull String archiveFileName) {
String jarOutputPath = myOutputPath + "/" + archiveFileName;
final JarInfo jarInfo = new JarInfo();
VirtualFile outputFile = outputChild(archiveFileName);
@@ -1,21 +1,36 @@
package com.intellij.packaging.impl.compiler;
import com.intellij.openapi.compiler.make.PackagingFileFilter;
import com.intellij.packaging.elements.IncrementalCompilerInstructionCreator;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public abstract class IncrementalCompilerInstructionCreatorBase implements IncrementalCompilerInstructionCreator {
public void addDirectoryCopyInstructions(VirtualFile directory) {
protected final ArtifactsProcessingItemsBuilderContext myContext;
public IncrementalCompilerInstructionCreatorBase(ArtifactsProcessingItemsBuilderContext context) {
myContext = context;
}
public void addDirectoryCopyInstructions(@NotNull VirtualFile directory) {
addDirectoryCopyInstructions(directory, null);
}
public void addDirectoryCopyInstructions(@NotNull VirtualFile directory, @Nullable PackagingFileFilter filter) {
final VirtualFile[] children = directory.getChildren();
if (children != null) {
for (VirtualFile child : children) {
if (!child.isDirectory()) {
addFileCopyInstruction(child, child.getName());
}
else {
subFolder(child.getName()).addDirectoryCopyInstructions(child);
if (filter == null || filter.accept(child, myContext.getCompileContext())) {
if (!child.isDirectory()) {
addFileCopyInstruction(child, child.getName());
}
else {
subFolder(child.getName()).addDirectoryCopyInstructions(child, filter);
}
}
}
}
@@ -12,20 +12,19 @@ import org.jetbrains.annotations.NotNull;
* @author nik
*/
public class PackIntoArchiveInstructionCreator extends IncrementalCompilerInstructionCreatorBase {
private final ArtifactsProcessingItemsBuilderContext myContext;
private final DestinationInfo myJarDestination;
private final JarInfo myJarInfo;
private final String myPathInJar;
public PackIntoArchiveInstructionCreator(ArtifactsProcessingItemsBuilderContext context, JarInfo jarInfo, String pathInJar,
DestinationInfo jarDestination) {
myContext = context;
super(context);
myJarInfo = jarInfo;
myPathInJar = pathInJar;
myJarDestination = jarDestination;
}
public void addFileCopyInstruction(@NotNull VirtualFile file, String outputFileName) {
public void addFileCopyInstruction(@NotNull VirtualFile file, @NotNull String outputFileName) {
final String pathInJar = childPathInJar(outputFileName);
myContext.addDestination(file, new JarDestinationInfo(pathInJar, myJarInfo, myJarDestination));
myJarInfo.addContent(pathInJar, file);
@@ -35,11 +34,11 @@ public class PackIntoArchiveInstructionCreator extends IncrementalCompilerInstru
return myPathInJar.length() == 0 ? fileName : myPathInJar + "/" + fileName;
}
public IncrementalCompilerInstructionCreator subFolder(String directoryName) {
public IncrementalCompilerInstructionCreator subFolder(@NotNull String directoryName) {
return new PackIntoArchiveInstructionCreator(myContext, myJarInfo, childPathInJar(directoryName), myJarDestination);
}
public IncrementalCompilerInstructionCreator archive(String archiveFileName) {
public IncrementalCompilerInstructionCreator archive(@NotNull String archiveFileName) {
final JarInfo jarInfo = new JarInfo();
if (myJarDestination instanceof ExplodedDestinationInfo) {
myContext.registerJarFile(jarInfo, myJarDestination.getOutputPath());
@@ -3,6 +3,7 @@ package com.intellij.packaging.impl.elements;
import com.intellij.openapi.compiler.CompilerBundle;
import com.intellij.openapi.project.Project;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.packaging.artifacts.ArtifactPointerManager;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElementType;
@@ -70,7 +71,9 @@ public class ArtifactElementType extends PackagingElementType<ArtifactPackagingE
iterator.remove();
}
}
return new ArrayList<Artifact>(result);
final ArrayList<Artifact> list = new ArrayList<Artifact>(result);
Collections.sort(list, ArtifactManager.ARTIFACT_COMPARATOR);
return list;
}
@NotNull
@@ -78,7 +78,7 @@ public class FileCopyPackagingElement extends PackagingElement<FileCopyPackaging
return;
}
if (file.isDirectory()) {
creator.addDirectoryCopyInstructions(file);
creator.addDirectoryCopyInstructions(file, null);
}
else {
creator.addFileCopyInstruction(file, getOutputFileName());
@@ -55,7 +55,7 @@ public class ModuleOutputPackagingElement extends PackagingElement<ModuleOutputP
if (module != null) {
final VirtualFile output = CompilerModuleExtension.getInstance(module).getCompilerOutputPath();
if (output != null) {
creator.addDirectoryCopyInstructions(output);
creator.addDirectoryCopyInstructions(output, null);
}
}
}
@@ -22,7 +22,6 @@ import com.intellij.openapi.compiler.make.BuildRecipe;
import com.intellij.openapi.compiler.make.PackagingFileFilter;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -148,12 +147,8 @@ public abstract class DeploymentUtil {
public abstract LibraryLink createLibraryLink(Library library, @NotNull Module parentModule);
public abstract PackagingConfiguration createPackagingConfiguration(@NotNull Module module);
public abstract BuildRecipe createBuildRecipe();
public @Nullable abstract ContainerElement findElementByOrderEntry(PackagingConfiguration packagingConfiguration, OrderEntry entry);
@Nullable
public abstract String getConfigFileErrorMessage(ConfigFile configFile);
@@ -203,10 +198,4 @@ public abstract class DeploymentUtil {
public abstract void checkConfigFile(final ConfigFile descriptor, final CompileContext compileContext, final Module module);
public abstract void addModuleOutputJarToParent(@NotNull BuildRecipe instructions,
@NotNull Module module,
@NotNull String relativePath,
@NotNull CompileContext context,
String linkContainerDescription,
@Nullable PackagingFileFilter fileFilter);
}
@@ -1,5 +1,6 @@
package com.intellij.packaging.artifacts;
import com.intellij.openapi.util.UserDataHolder;
import com.intellij.packaging.elements.CompositePackagingElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -9,7 +10,7 @@ import java.util.Collection;
/**
* @author nik
*/
public interface Artifact {
public interface Artifact extends UserDataHolder {
@NotNull
ArtifactType getArtifactType();
@@ -1,6 +1,5 @@
package com.intellij.packaging.artifacts;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ModificationTracker;
@@ -13,17 +12,25 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Comparator;
/**
* @author nik
*/
public abstract class ArtifactManager implements ArtifactModel {
public static final Topic<ArtifactListener> TOPIC = Topic.create("artifacts changes", ArtifactListener.class);
public static final Comparator<Artifact> ARTIFACT_COMPARATOR = new Comparator<Artifact>() {
public int compare(Artifact o1, Artifact o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
};
public static ArtifactManager getInstance(@NotNull Project project) {
return ServiceManager.getService(project, ArtifactManager.class);
}
public abstract Artifact[] getSortedArtifacts();
public abstract ModifiableArtifactModel createModifiableModel();
public abstract PackagingElementResolvingContext getResolvingContext();
@@ -34,13 +41,8 @@ public abstract class ArtifactManager implements ArtifactModel {
public abstract void addElementsToDirectory(@NotNull Artifact artifact, @NotNull String relativePath,
@NotNull Collection<? extends PackagingElement<?>> elements);
public abstract void addElementsToDirectory(@NotNull Artifact artifact, @NotNull String relativePath,
@NotNull PackagingElement<?> element);
public abstract ModificationTracker getModificationTracker();
public static boolean useArtifactsForDeployment() {
return Boolean.parseBoolean(System.getProperty("idea.use.artifacts.for.deployment"));
}
public static boolean useArtifacts() {
return ApplicationManagerEx.getApplicationEx().isInternal();
}
}
@@ -65,6 +65,11 @@ public abstract class CompositePackagingElement<S> extends PackagingElement<S> i
myUnmodifiableChildren = null;
}
public void removeChildren(@NotNull Collection<? extends PackagingElement<?>> children) {
myChildren.removeAll(children);
myUnmodifiableChildren = null;
}
@NotNull
public List<PackagingElement<?>> getChildren() {
if (myUnmodifiableChildren == null) {
@@ -1,18 +1,22 @@
package com.intellij.packaging.elements;
import com.intellij.openapi.compiler.make.PackagingFileFilter;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public interface IncrementalCompilerInstructionCreator {
void addFileCopyInstruction(@NotNull VirtualFile file, String outputFileName);
void addFileCopyInstruction(@NotNull VirtualFile file, @NotNull String outputFileName);
void addDirectoryCopyInstructions(VirtualFile directory);
void addDirectoryCopyInstructions(@NotNull VirtualFile directory);
IncrementalCompilerInstructionCreator subFolder(String directoryName);
void addDirectoryCopyInstructions(@NotNull VirtualFile directory, @Nullable PackagingFileFilter filter);
IncrementalCompilerInstructionCreator archive(String archiveFileName);
IncrementalCompilerInstructionCreator subFolder(@NotNull String directoryName);
IncrementalCompilerInstructionCreator archive(@NotNull String archiveFileName);
}
@@ -272,7 +272,6 @@ public class ProjectFacetsConfigurator implements FacetsProvider, ModuleEditor.C
editor.disposeUIResources();
}
myProjectData = null;
((ProjectFacetManagerImpl)ProjectFacetManagerImpl.getInstance(myProject)).fireRunnableOnProjectSettingsClosed();
}
@NotNull
@@ -1,36 +0,0 @@
package com.intellij.jar;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import java.util.Collection;
/**
* @author cdr
*/
public class BuildJarAction extends AnAction {
public void actionPerformed(AnActionEvent e) {
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
Collection<Module> modulesToJar = BuildJarDialog.getModulesToJar(project);
if (modulesToJar.isEmpty()) {
Messages.showErrorDialog(project, IdeBundle.message("jar.no.java.modules.in.project.error"),
IdeBundle.message("jar.no.java.modules.in.project.title"));
return;
}
BuildJarDialog dialog = new BuildJarDialog(project);
dialog.show();
if (dialog.isOK()) {
BuildJarProjectSettings.getInstance(project).buildJarsWithProgress();
}
}
public void update(AnActionEvent e) {
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
e.getPresentation().setEnabled(project != null);
}
}
@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.jar.BuildJarDialog">
<grid id="2f03e" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="138" y="83" width="214" height="490"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="57a88" class="javax.swing.JCheckBox" binding="myBuildJarsOnMake">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/IdeBundle" key="jar.build.on.make"/>
</properties>
</component>
<grid id="1ac16" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<splitpane id="70aa">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties>
<orientation value="0"/>
</properties>
<border type="none"/>
<children>
<grid id="603c0" binding="myModuleSettingsPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<splitpane position="right"/>
</constraints>
<properties/>
<border type="none" title-resource-bundle="messages/IdeBundle" title-key="jar.build.module.0.jar.settings"/>
<children>
<xy id="a3d48" binding="myEditorPanel" layout-manager="XYLayout" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="130"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</xy>
<component id="85dcb" class="com.intellij.openapi.ui.LabeledComponent" binding="myJarFilePathComponent">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<text resource-bundle="messages/IdeBundle" key="jar.build.path"/>
</properties>
</component>
<component id="d106c" class="com.intellij.openapi.ui.LabeledComponent" binding="myMainClassComponent">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<text resource-bundle="messages/IdeBundle" key="jar.build.main.class"/>
</properties>
</component>
<component id="9bc53" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/IdeBundle" key="jar.build.include.in.jar.file"/>
</properties>
</component>
</children>
</grid>
<grid id="cf86b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<splitpane position="left"/>
</constraints>
<properties/>
<border type="none" title-resource-bundle="messages/IdeBundle" title-key="jar.build.modules.to.jar"/>
<children>
<grid id="a223d" binding="myModulesPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="100"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>
</splitpane>
</children>
</grid>
<component id="7d0b2" class="javax.swing.JLabel" binding="myWarningLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="1111111111111111"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -1,437 +0,0 @@
package com.intellij.jar;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.facet.impl.DefaultFacetsProvider;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.RecentProjectsManager;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.deployment.DeploymentUtil;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.deployment.PackagingConfiguration;
import com.intellij.openapi.deployment.PackagingMethod;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.module.JavaModuleType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditor;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorImpl;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.ui.SplitterProportionsData;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.peer.PeerFactory;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.GuiUtils;
import com.intellij.util.io.FileTypeFilter;
import gnu.trove.THashMap;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileView;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.MessageFormat;
import java.util.*;
/**
* @author cdr
*/
public class BuildJarDialog extends DialogWrapper {
private static final Logger LOG = Logger.getInstance("#com.intellij.j2ee.jar.BuildJarDialog");
@NonNls private static final String WARNING_TEMPLATE = "<html><body><b>{0}: </b>{1}</body><body>";
private final Project myProject;
private JPanel myModulesPanel;
private JPanel myEditorPanel;
private TextFieldWithBrowseButton myJarPath;
private TextFieldWithBrowseButton myMainClass;
private JPanel myPanel;
private final Map<Module, SettingsEditor> mySettings = new THashMap<Module, SettingsEditor>();
private Module myCurrentModule;
private ElementsChooser<Module> myElementsChooser;
private JPanel myModuleSettingsPanel;
private LabeledComponent<TextFieldWithBrowseButton> myMainClassComponent;
private LabeledComponent<TextFieldWithBrowseButton> myJarFilePathComponent;
private JCheckBox myBuildJarsOnMake;
private JLabel myWarningLabel;
private final SplitterProportionsData mySplitterProportionsData = PeerFactory.getInstance().getUIHelper().createSplitterProportionsData();
protected BuildJarDialog(Project project) {
super(true);
myProject = project;
setupControls();
setTitle(IdeBundle.message("jar.build.dialog.title"));
mySplitterProportionsData.externalizeFromDimensionService(getDimensionKey());
mySplitterProportionsData.restoreSplitterProportions(myPanel);
getOKAction().putValue(Action.NAME, IdeBundle.message("jar.build.button"));
init();
updateWarning();
}
private void updateWarning() {
for (Map.Entry<Module, SettingsEditor> entry : mySettings.entrySet()) {
try {
final SettingsEditor editor = entry.getValue();
if (editor.myModule == myCurrentModule) {
editor.saveUI();
}
editor.checkSettings();
}
catch (RuntimeConfigurationException e) {
myWarningLabel.setText(MessageFormat.format(WARNING_TEMPLATE, entry.getKey().getName(), e.getMessage()));
myWarningLabel.setVisible(true);
repaint();
return;
}
}
repaint();
myWarningLabel.setVisible(false);
}
protected void doHelpAction() {
HelpManager.getInstance().invokeHelp("editing.generateJarFiles");
}
protected Action[] createActions() {
return new Action[]{getOKAction(), getCancelAction(), getHelpAction()};
}
public static Collection<Module> getModulesToJar(Project project) {
final Module[] modules = ModuleManager.getInstance(project).getModules();
ArrayList<Module> result = new ArrayList<Module>();
for (Module module : modules) {
if (module.getModuleType() instanceof JavaModuleType) {
result.add(module);
}
}
Collections.sort(result, new Comparator<Module>() {
public int compare(final Module o1, final Module o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
return result;
}
private void setupControls() {
myWarningLabel.setIcon(IconLoader.getIcon("/runConfigurations/configurationWarning.png"));
myBuildJarsOnMake.setSelected(BuildJarProjectSettings.getInstance(myProject).isBuildJarOnMake());
myJarPath = myJarFilePathComponent.getComponent();
myMainClass = myMainClassComponent.getComponent();
myElementsChooser = new ElementsChooser<Module>(true) {
@Override
protected String getItemText(@NotNull final Module value) {
return value.getName();
}
};
myElementsChooser.setColorUnmarkedElements(false);
myModulesPanel.setLayout(new BorderLayout());
myModulesPanel.add(myElementsChooser, BorderLayout.CENTER);
final Collection<Module> modules = getModulesToJar(myProject);
for (final Module module : modules) {
BuildJarSettings buildJarSettings = BuildJarSettings.getInstance(module);
myElementsChooser.addElement(module, buildJarSettings.isBuildJar(), new ChooserElementProperties(module));
}
myElementsChooser.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (myCurrentModule != null) {
saveEditor(myCurrentModule);
}
Module selectedModule = myElementsChooser.getSelectedElement();
myCurrentModule = selectedModule;
if (selectedModule != null) {
BuildJarSettings buildJarSettings = BuildJarSettings.getInstance(selectedModule);
SettingsEditor settingsEditor = mySettings.get(selectedModule);
if (settingsEditor == null) {
settingsEditor = new SettingsEditor(selectedModule, buildJarSettings);
mySettings.put(selectedModule, settingsEditor);
}
settingsEditor.refreshControls();
boolean isBuildJar = myElementsChooser.getMarkedElements().contains(selectedModule);
GuiUtils.enableChildren(myModuleSettingsPanel, isBuildJar);
settingsEditor.rebuildTree();
TitledBorder titledBorder = (TitledBorder)myModuleSettingsPanel.getBorder();
titledBorder.setTitle(IdeBundle.message("jar.build.module.0.jar.settings", selectedModule.getName()));
myModuleSettingsPanel.repaint();
}
}
});
myElementsChooser.addElementsMarkListener(new ElementsChooser.ElementsMarkListener<Module>() {
public void elementMarkChanged(final Module element, final boolean isMarked) {
GuiUtils.enableChildren(myModuleSettingsPanel, isMarked);
SettingsEditor settingsEditor = mySettings.get(element);
if (isMarked) {
setDefaultJarPath();
if (settingsEditor != null) {
PackagingConfiguration configuration = settingsEditor.getEditor().getModifiedConfiguration();
if (configuration.getElements().length == 0) {
ModuleLink moduleLink = DeploymentUtil.getInstance().createModuleLink(element, element);
moduleLink.setPackagingMethod(PackagingMethod.COPY_FILES);
moduleLink.setURI("/");
configuration.addOrReplaceElement(moduleLink);
}
}
}
if (settingsEditor != null) {
settingsEditor.rebuildTree();
}
}
});
myJarPath.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String lastFilePath = myJarPath.getText();
String path = lastFilePath == null ? RecentProjectsManager.getInstance().getLastProjectPath() : lastFilePath;
File file = new File(path);
if (!file.exists()) {
path = file.getParent();
}
JFileChooser fileChooser = new JFileChooser(path);
FileView fileView = new FileView() {
public Icon getIcon(File f) {
if (f.isDirectory()) return super.getIcon(f);
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(f.getName());
return fileType.getIcon();
}
};
fileChooser.setFileView(fileView);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setDialogTitle(IdeBundle.message("jar.build.save.title"));
fileChooser.addChoosableFileFilter(new FileTypeFilter(FileTypes.ARCHIVE));
if (fileChooser.showSaveDialog(WindowManager.getInstance().suggestParentWindow(myProject)) != JFileChooser.APPROVE_OPTION) {
return;
}
file = fileChooser.getSelectedFile();
if (file == null) return;
myJarPath.setText(file.getPath());
}
});
myMainClass.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String mainClass = myMainClass.getText();
GlobalSearchScope scope = createMainClassScope();
PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(mainClass, scope);
TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
final TreeClassChooser dialog =
factory.createNoInnerClassesScopeChooser(IdeBundle.message("jar.build.main.class.title"), scope, null, aClass);
dialog.showDialog();
final PsiClass psiClass = dialog.getSelectedClass();
if (psiClass != null && psiClass.getQualifiedName() != null) {
myMainClass.setText(psiClass.getQualifiedName());
}
updateWarning();
}
});
myMainClass.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(DocumentEvent e) {
updateWarning();
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Module element = myElementsChooser.getElementAt(0);
myElementsChooser.selectElements(Collections.singletonList(element));
}
});
GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
}
private GlobalSearchScope createMainClassScope() {
GlobalSearchScope result = null;
for (Module module : mySettings.keySet()) {
GlobalSearchScope scope = GlobalSearchScope.moduleWithLibrariesScope(module);
if (result == null) {
result = scope;
}
else {
result = result.uniteWith(scope);
}
}
return result != null ? result : GlobalSearchScope.allScope(myProject);
}
public JComponent getPreferredFocusedComponent() {
return myJarPath;
}
private void setDefaultJarPath() {
if (!Comparing.strEqual(myJarPath.getText(), "") || myCurrentModule == null) {
return;
}
VirtualFile[] contentRoots = ModuleRootManager.getInstance(myCurrentModule).getContentRoots();
if (contentRoots.length == 0) return;
VirtualFile contentRoot = contentRoots[0];
if (contentRoot == null) return;
VirtualFile moduleFile = myCurrentModule.getModuleFile();
if (moduleFile == null) return;
String jarPath = FileUtil.toSystemDependentName(contentRoot.getPath() + "/" + moduleFile.getNameWithoutExtension() + ".jar");
myJarPath.setText(jarPath);
}
protected JComponent createCenterPanel() {
return myPanel;
}
protected String getDimensionServiceKey() {
return "#com.intellij.j2ee.jar.BuildJarDialog";
}
public void dispose() {
mySplitterProportionsData.saveSplitterProportions(myPanel);
mySplitterProportionsData.externalizeToDimensionService(getDimensionKey());
for (SettingsEditor editor : mySettings.values()) {
editor.dispose();
}
super.dispose();
}
protected void doOKAction() {
if (myCurrentModule != null) {
saveEditor(myCurrentModule);
}
for (SettingsEditor editor : mySettings.values()) {
editor.apply();
}
BuildJarProjectSettings.getInstance(myProject).setBuildJarOnMake(myBuildJarsOnMake.isSelected());
super.doOKAction();
}
private void saveEditor(final Module module) {
SettingsEditor settingsEditor = mySettings.get(module);
if (settingsEditor != null) {
settingsEditor.saveUI();
}
}
private class SettingsEditor {
private final Module myModule;
private final BuildJarSettings myBuildJarSettings;
private final BuildJarSettings myModifiedBuildJarSettings;
private final PackagingEditor myEditor;
public SettingsEditor(@NotNull Module module, @NotNull BuildJarSettings buildJarSettings) {
myModule = module;
myBuildJarSettings = buildJarSettings;
myModifiedBuildJarSettings = new BuildJarSettings(module);
copySettings(buildJarSettings, myModifiedBuildJarSettings);
DefaultModulesProvider modulesProvider = new DefaultModulesProvider(myProject);
PackagingConfiguration originalConfiguration = myBuildJarSettings.getPackagingConfiguration();
PackagingConfiguration modifiedConfiguration = myModifiedBuildJarSettings.getPackagingConfiguration();
JarPackagingEditorPolicy editorPolicy = new JarPackagingEditorPolicy(module);
JarPackagingTreeBuilder treeBuilder = new JarPackagingTreeBuilder(module);
myEditor = new PackagingEditorImpl(originalConfiguration, modifiedConfiguration, modulesProvider, DefaultFacetsProvider.INSTANCE,
editorPolicy, treeBuilder, false);
myEditor.reset();
myEditor.createMainComponent();
}
private void refreshControls() {
myEditorPanel.removeAll();
myEditorPanel.setLayout(new BorderLayout());
myEditorPanel.add(myEditor.getMainPanel(), BorderLayout.CENTER);
myEditorPanel.revalidate();
myJarPath.setText(FileUtil.toSystemDependentName(VfsUtil.urlToPath(myModifiedBuildJarSettings.getJarUrl())));
myMainClass.setText(myModifiedBuildJarSettings.getMainClass());
}
public void dispose() {
}
public void apply() {
copySettings(myModifiedBuildJarSettings, myBuildJarSettings);
}
public void rebuildTree() {
getEditor().rebuildTree();
}
public PackagingEditor getEditor() {
return myEditor;
}
public void saveUI() {
myEditor.saveData();
String url = VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(myJarPath.getText()));
myModifiedBuildJarSettings.setJarUrl(url);
boolean isBuildJar = myElementsChooser.getMarkedElements().contains(myModule);
myModifiedBuildJarSettings.setBuildJar(isBuildJar);
myModifiedBuildJarSettings.setMainClass(myMainClass.getText());
}
public void checkSettings() throws RuntimeConfigurationException {
myModifiedBuildJarSettings.checkSettings();
}
}
private static void copySettings(BuildJarSettings from, BuildJarSettings to) {
@NonNls Element element = new Element("dummy");
try {
from.writeExternal(element);
}
catch (WriteExternalException ignored) {
}
try {
to.readExternal(element);
}
catch (InvalidDataException e) {
LOG.error(e);
}
}
private static class ChooserElementProperties implements ElementsChooser.ElementProperties {
private final Module myModule;
public ChooserElementProperties(final Module module) {
myModule = module;
}
public Icon getIcon() {
return myModule.getModuleType().getNodeIcon(false);
}
public Color getColor() {
return null;
}
}
}
@@ -1,270 +0,0 @@
package com.intellij.jar;
import com.intellij.CommonBundle;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.compiler.DummyCompileContext;
import com.intellij.openapi.compiler.make.*;
import com.intellij.openapi.components.*;
import com.intellij.openapi.deployment.DeploymentUtil;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.deployment.PackagingConfiguration;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.wm.WindowManager;
import gnu.trove.THashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
/**
* @author cdr
*/
@State(
name = "BuildJarProjectSettings",
storages = {
@Storage(id = "default", file = "$PROJECT_FILE$")
,@Storage(id = "dir", file = "$PROJECT_CONFIG_DIR$/compiler.xml", scheme = StorageScheme.DIRECTORY_BASED)
}
)
public class BuildJarProjectSettings implements PersistentStateComponent<Element>, ProjectComponent {
private static final Logger LOG = Logger.getInstance("#com.intellij.jar.BuildJarProjectSettings");
public boolean BUILD_JARS_ON_MAKE = false;
@NonNls private static final String MAIN_CLASS = Attributes.Name.MAIN_CLASS.toString();
@NonNls private static final String JAR_EXTENSION = ".jar";
@NonNls public static final String BUILD_JAR_PROJECT_SETTINGS_COMPONENT_NAME = "BuildJarProjectSettings";
private final Project myProject;
public static BuildJarProjectSettings getInstance(Project project) {
return project.getComponent(BuildJarProjectSettings.class);
}
public BuildJarProjectSettings(Project project) {
myProject = project;
}
public Element getState() {
try {
final Element e = new Element("state");
DefaultJDOMExternalizer.writeExternal(this, e);
return e;
}
catch (WriteExternalException e1) {
LOG.error(e1);
return null;
}
}
public void loadState(Element state) {
try {
DefaultJDOMExternalizer.readExternal(this, state);
}
catch (InvalidDataException e) {
LOG.error(e);
}
}
public boolean isBuildJarOnMake() {
return BUILD_JARS_ON_MAKE;
}
public void projectOpened() {
if (BUILD_JARS_ON_MAKE) {
CompilerManager compilerManager = CompilerManager.getInstance(myProject);
compilerManager.addCompiler(JarCompiler.getInstance());
}
}
public void projectClosed() {
}
@NonNls @NotNull
public String getComponentName() {
return BUILD_JAR_PROJECT_SETTINGS_COMPONENT_NAME;
}
public void initComponent() {
}
public void disposeComponent() {
}
public void setBuildJarOnMake(final boolean buildJar) {
if (buildJar != BUILD_JARS_ON_MAKE) {
CompilerManager compilerManager = CompilerManager.getInstance(myProject);
if (buildJar) {
compilerManager.addCompiler(JarCompiler.getInstance());
}
else {
compilerManager.removeCompiler(JarCompiler.getInstance());
}
}
BUILD_JARS_ON_MAKE = buildJar;
}
public void buildJarsWithProgress() {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable(){
public void run() {
buildJars(ProgressManager.getInstance().getProgressIndicator());
}
}, IdeBundle.message("jar.build.progress.title"), true, myProject);
}
private void buildJars(final ProgressIndicator progressIndicator) {
Module[] modules = ModuleManager.getInstance(myProject).getModules();
try {
for (Module module : modules) {
BuildJarSettings buildJarSettings = BuildJarSettings.getInstance(module);
if (buildJarSettings == null || !buildJarSettings.isBuildJar()) continue;
String presentableJarPath = "'" + FileUtil.toSystemDependentName(VfsUtil.urlToPath(buildJarSettings.getJarUrl() + "'"));
if (progressIndicator != null) {
progressIndicator.setText(IdeBundle.message("jar.build.progress", presentableJarPath));
}
buildJar(module, buildJarSettings,progressIndicator, null);
WindowManager.getInstance().getStatusBar(myProject).setInfo(IdeBundle.message("jar.build.success.message", presentableJarPath));
}
}
catch (ProcessCanceledException e) {
WindowManager.getInstance().getStatusBar(myProject).setInfo(IdeBundle.message("jar.build.cancelled"));
}
catch (final IOException e) {
ApplicationManager.getApplication().invokeLater(new Runnable(){
public void run() {
Messages.showErrorDialog(myProject, e.toString(), IdeBundle.message("jar.build.error.title"));
}
});
}
}
static void buildJar(final Module module, final BuildJarSettings buildJarSettings, final ProgressIndicator progressIndicator,
@Nullable CompileContext context) throws IOException {
String jarPath = buildJarSettings.getJarUrl();
final File jarFile = new File(VfsUtil.urlToPath(jarPath));
jarFile.delete();
FileUtil.createParentDirs(jarFile);
BuildRecipe buildRecipe = new ReadAction<BuildRecipe>() {
protected void run(final Result<BuildRecipe> result) {
result.setResult(getBuildRecipe(module, buildJarSettings));
}
}.execute().getResultObject();
Manifest manifest = DeploymentUtil.getInstance().createManifest(buildRecipe);
String mainClass = buildJarSettings.getMainClass();
if (manifest != null && !Comparing.strEqual(mainClass, null)) {
manifest.getMainAttributes().putValue(MAIN_CLASS,mainClass);
}
// write temp file and rename it to the jar to avoid deployment of incomplete jar. SCR #30303
final File tempFile;
try {
tempFile = File.createTempFile("___"+ FileUtil.getNameWithoutExtension(jarFile), JAR_EXTENSION, jarFile.getParentFile());
}
catch (IOException e) {
final String errorMessage =
IdeBundle.message("error.message.jar.build.cannot.create.temporary.file.in.0", jarFile.getParentFile().getAbsolutePath());
if (context != null) {
context.addMessage(CompilerMessageCategory.ERROR, errorMessage, null, -1, -1);
}
else {
Messages.showErrorDialog(module.getProject(), errorMessage, CommonBundle.getErrorTitle());
}
return;
}
final JarOutputStream jarOutputStream = manifest == null ?
new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile))) :
new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)), manifest);
final Set<String> tempWrittenRelativePaths = new THashSet<String>();
final BuildRecipe dependencies = DeploymentUtil.getInstance().createBuildRecipe();
try {
buildRecipe.visitInstructionsWithExceptions(new BuildInstructionVisitor() {
public boolean visitInstruction(BuildInstruction instruction) throws IOException {
ProgressManager.getInstance().checkCanceled();
if (instruction instanceof FileCopyInstruction) {
FileCopyInstruction fileCopyInstruction = (FileCopyInstruction)instruction;
File file = fileCopyInstruction.getFile();
if (file == null || !file.exists()) return true;
String presentablePath = FileUtil.toSystemDependentName(file.getPath());
if (progressIndicator != null) {
progressIndicator.setText2(IdeBundle.message("jar.build.processing.file.progress", presentablePath));
}
}
//todo[nik] use IncrementalPackagingCompiler instead
instruction.addFilesToJar(DummyCompileContext.getInstance(), tempFile, jarOutputStream, dependencies, tempWrittenRelativePaths, null);
return true;
}
}, false);
buildRecipe.visitInstructionsWithExceptions(new BuildInstructionVisitor() {
public boolean visitJarAndCopyBuildInstruction(final JarAndCopyBuildInstruction instruction) throws Exception {
instruction.deleteTemporaryJars();
return true;
}
}, false);
}
catch (ProcessCanceledException e) {
throw e;
}
catch (Exception e) {
LOG.error(e);
}
finally {
jarOutputStream.close();
try {
FileUtil.rename(tempFile, jarFile);
}
catch (IOException e) {
ApplicationManager.getApplication().invokeLater(new Runnable(){
public void run() {
String message = IdeBundle.message("jar.build.cannot.overwrite.error", FileUtil.toSystemDependentName(jarFile.getPath()),
FileUtil.toSystemDependentName(tempFile.getPath()));
Messages.showErrorDialog(module.getProject(), message, IdeBundle.message("jar.build.error.title"));
}
});
}
}
}
static BuildRecipe getBuildRecipe(final Module module, final BuildJarSettings buildJarSettings) {
final DummyCompileContext compileContext = DummyCompileContext.getInstance();
PackagingConfiguration packagingConfiguration = buildJarSettings.getPackagingConfiguration();
BuildRecipe buildRecipe = DeploymentUtil.getInstance().createBuildRecipe();
LibraryLink[] libraries = packagingConfiguration.getContainingLibraries();
for (LibraryLink libraryLink : libraries) {
DeploymentUtil.getInstance().addLibraryLink(compileContext, buildRecipe, libraryLink, module, null);
}
ModuleLink[] modules = packagingConfiguration.getContainingModules();
DeploymentUtil.getInstance().addJavaModuleOutputs(module, modules, buildRecipe, compileContext, null, IdeBundle.message("jar.build.module.presentable.name", module.getName()));
return buildRecipe;
}
}
@@ -1,57 +0,0 @@
package com.intellij.jar;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.listeners.RefactoringElementListener;
import com.intellij.refactoring.listeners.RefactoringElementListenerComposite;
import com.intellij.refactoring.listeners.RefactoringElementListenerProvider;
import org.jetbrains.annotations.NotNull;
public class BuildJarRefactoringListenerProvider implements RefactoringElementListenerProvider {
private Project myProject;
public BuildJarRefactoringListenerProvider(Project project) {
myProject = project;
}
public RefactoringElementListener getListener(PsiElement element) {
if (element instanceof PsiClass) {
String className = ((PsiClass)element).getQualifiedName();
if (className == null) return null;
final Module[] modules = ModuleManager.getInstance(myProject).getModules();
RefactoringElementListenerComposite listener = null;
for (Module module : modules) {
final BuildJarSettings settings = BuildJarSettings.getInstance(module);
final String mainClass = settings.getMainClass();
if (className.equals(mainClass)) {
if (listener == null) {
listener = new RefactoringElementListenerComposite();
}
listener.addListener(new MainClassRefactoringListener(settings));
}
}
return listener;
}
return null;
}
private static class MainClassRefactoringListener implements RefactoringElementListener {
private final BuildJarSettings mySettings;
public MainClassRefactoringListener(final BuildJarSettings settings) {
mySettings = settings;
}
public void elementMoved(@NotNull PsiElement newElement) {
mySettings.setMainClass(((PsiClass)newElement).getQualifiedName());
}
public void elementRenamed(@NotNull PsiElement newElement) {
mySettings.setMainClass(((PsiClass)newElement).getQualifiedName());
}
}
}
@@ -1,140 +0,0 @@
package com.intellij.jar;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.configurations.RuntimeConfigurationError;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.deployment.DeploymentUtil;
import com.intellij.openapi.deployment.PackagingConfiguration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleComponent;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.JDOMExternalizer;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiMethodUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* @author cdr
*/
public class BuildJarSettings implements ModuleComponent, JDOMExternalizable {
@NonNls public static final String ELEMENT_CONTAINER_INFO = "containerInfo";
@NonNls public static final String BUILD_JAR_SETTINGS_COMPONENT_NAME = "BuildJarSettings";
@NonNls public static final String JAR_URL_ATTRIBUTE = "jarUrl";
@NonNls public static final String MAIN_CLASS_ATTRIBUTE = "mainClass";
private final PackagingConfiguration myPackagingConfiguration;
private final Module myModule;
private String myJarUrl = "";
private boolean myBuildJar;
private String myMainClass = "";
public static BuildJarSettings getInstance(Module module) {
return module.getComponent(BuildJarSettings.class);
}
public BuildJarSettings(Module module) {
myModule = module;
myPackagingConfiguration = DeploymentUtil.getInstance().createPackagingConfiguration(myModule);
}
public boolean isBuildJar() {
return myBuildJar;
}
public String getMainClass() {
return myMainClass;
}
public void readExternal(Element element) throws InvalidDataException {
Element settings = element.getChild(ELEMENT_CONTAINER_INFO);
if (settings != null) {
myPackagingConfiguration.readExternal(settings);
}
myJarUrl = JDOMExternalizer.readString(element, JAR_URL_ATTRIBUTE);
if (myJarUrl == null) {
final String jarPath = JDOMExternalizer.readString(element, "jarPath");
if (jarPath != null) {
myJarUrl = VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(jarPath));
}
}
myBuildJar = JDOMExternalizer.readBoolean(element, "buildJar");
myMainClass = JDOMExternalizer.readString(element, MAIN_CLASS_ATTRIBUTE);
}
public void writeExternal(Element element) throws WriteExternalException {
if (!myBuildJar) throw new WriteExternalException();
Element settings = new Element(ELEMENT_CONTAINER_INFO);
element.addContent(settings);
myPackagingConfiguration.writeExternal(settings);
JDOMExternalizer.write(element, JAR_URL_ATTRIBUTE, myJarUrl);
JDOMExternalizer.write(element, "buildJar", myBuildJar);
JDOMExternalizer.write(element, MAIN_CLASS_ATTRIBUTE, myMainClass);
}
public PackagingConfiguration getPackagingConfiguration() {
return myPackagingConfiguration;
}
public String getJarUrl() {
return myJarUrl;
}
public void setJarUrl(final String jarUrl) {
myJarUrl = jarUrl;
}
public void projectOpened() {
}
public void projectClosed() {
}
public void moduleAdded() {
}
@NonNls @NotNull
public String getComponentName() {
return BUILD_JAR_SETTINGS_COMPONENT_NAME;
}
public void initComponent() {
}
public void disposeComponent() {
}
public void setBuildJar(final boolean buildJar) {
myBuildJar = buildJar;
}
public void setMainClass(final String mainClass) {
myMainClass = mainClass;
}
public void checkSettings() throws RuntimeConfigurationException {
if (myMainClass != null && myMainClass.length() > 0) {
final PsiManager psiManager = PsiManager.getInstance(myModule.getProject());
final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject())
.findClass(myMainClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule));
if (aClass == null) {
throw new RuntimeConfigurationError(IdeBundle.message("jar.build.class.not.found", myMainClass));
}
if (!PsiMethodUtil.hasMainMethod(aClass)) {
throw new RuntimeConfigurationError(ExecutionBundle.message("main.method.not.found.in.class.error.message", myMainClass));
}
}
}
}
@@ -1,246 +0,0 @@
package com.intellij.jar;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.PackagingCompiler;
import com.intellij.openapi.compiler.ValidityState;
import com.intellij.openapi.compiler.make.BuildInstructionVisitor;
import com.intellij.openapi.compiler.make.BuildRecipe;
import com.intellij.openapi.compiler.make.FileCopyInstruction;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.deployment.PackagingConfiguration;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.io.IOUtil;
import gnu.trove.THashSet;
import gnu.trove.TObjectLongHashMap;
import gnu.trove.TObjectLongProcedure;
import org.jetbrains.annotations.NotNull;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
public class JarCompiler implements PackagingCompiler {
private static final Logger LOG = Logger.getInstance("#com.intellij.jar.JarCompiler");
private static final JarCompiler INSTANCE = new JarCompiler();
public static JarCompiler getInstance() {
return INSTANCE;
}
public void processOutdatedItem(final CompileContext context, String url, final ValidityState state) {
if (state != null) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
MyValState valState = (MyValState)state;
String jarPath = valState.getOutputJarUrl();
if (jarPath != null) {
FileUtil.delete(new File(VfsUtil.urlToPath(jarPath)));
}
}
});
}
}
public ValidityState createValidityState(DataInput in) throws IOException {
return new MyValState(in);
}
static class MyValState implements ValidityState {
private final String myModuleName;
private final String[] sourceUrls;
private final long[] timestamps;
private final String outputJarUrl;
private final long outputJarTimestamp;
public MyValState(final Module module) {
myModuleName = module.getName();
final BuildJarSettings jarSettings = BuildJarSettings.getInstance(module);
outputJarUrl = jarSettings.getJarUrl();
outputJarTimestamp = new File(VfsUtil.urlToPath(outputJarUrl)).lastModified();
final TObjectLongHashMap<String> url2Timestamps = new TObjectLongHashMap<String>();
ApplicationManager.getApplication().runReadAction(new Runnable(){
public void run() {
BuildRecipe buildRecipe = BuildJarProjectSettings.getBuildRecipe(module, jarSettings);
buildRecipe.visitInstructions(new BuildInstructionVisitor() {
public boolean visitFileCopyInstruction(FileCopyInstruction instruction) throws Exception {
File source = instruction.getFile();
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(source.getPath()));
if (virtualFile != null) {
addFilesToMap(virtualFile, url2Timestamps);
}
return true;
}
}, false);
}
});
sourceUrls = ArrayUtil.newStringArray(url2Timestamps.size());
timestamps = new long[url2Timestamps.size()];
TObjectLongProcedure<String> iterator = new TObjectLongProcedure<String>() {
int i = 0;
public boolean execute(final String url, final long timestamp) {
sourceUrls[i] = url;
timestamps[i] = timestamp;
i++;
return true;
}
};
url2Timestamps.forEachEntry(iterator);
}
private static void addFilesToMap(final VirtualFile virtualFile, final TObjectLongHashMap<String> url2Timestamps) {
if (virtualFile.isDirectory()) {
VirtualFile[] children = virtualFile.getChildren();
for (VirtualFile child : children) {
addFilesToMap(child, url2Timestamps);
}
}
else {
long timestamp = virtualFile.getModificationStamp();
url2Timestamps.put(virtualFile.getUrl(), timestamp);
}
}
public MyValState(final DataInput is) throws IOException {
myModuleName = IOUtil.readString(is);
int size = is.readInt();
sourceUrls = ArrayUtil.newStringArray(size);
timestamps = new long[size];
for (int i=0;i<size;i++) {
String url = IOUtil.readString(is);
long timestamp = is.readLong();
sourceUrls[i] = url;
timestamps[i] = timestamp;
}
outputJarUrl = IOUtil.readString(is);
outputJarTimestamp = is.readLong();
}
public void save(DataOutput out) throws IOException {
IOUtil.writeString(myModuleName, out);
int size = sourceUrls.length;
out.writeInt(size);
for (int i=0;i<size;i++) {
String url = sourceUrls[i];
long timestamp = timestamps[i];
IOUtil.writeString(url, out);
out.writeLong(timestamp);
}
IOUtil.writeString(outputJarUrl, out);
out.writeLong(outputJarTimestamp);
}
public String getOutputJarUrl() {
return outputJarUrl;
}
public boolean equalsTo(ValidityState otherState) {
if (!(otherState instanceof MyValState)) return false;
final MyValState other = (MyValState)otherState;
if (!myModuleName.equals(other.myModuleName)) return false;
if (sourceUrls.length != other.sourceUrls.length) return false;
for (int i = 0; i < sourceUrls.length; i++) {
String url = sourceUrls[i];
long timestamp = timestamps[i];
if (!url.equals(other.sourceUrls[i]) || timestamp != other.timestamps[i]) return false;
}
if (!Comparing.strEqual(outputJarUrl,other.outputJarUrl)) return false;
if (outputJarTimestamp != other.outputJarTimestamp) return false;
return true;
}
}
static class MyProcItem implements ProcessingItem {
private final Module myModule;
public MyProcItem(Module module) {
myModule = module;
}
@NotNull
public VirtualFile getFile() {
// return (semifake) file url to store compiler cache entry under
return myModule.getModuleFile();
}
@NotNull
public MyValState getValidityState() {
return new MyValState(myModule);
}
public Module getModule() {
return myModule;
}
}
@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext context) {
return ApplicationManager.getApplication().runReadAction(new Computable<ProcessingItem[]>(){
public ProcessingItem[] compute() {
final CompileScope compileScope = context.getCompileScope();
final Module[] affectedModules = compileScope.getAffectedModules();
if (affectedModules.length == 0) return ProcessingItem.EMPTY_ARRAY;
Project project = affectedModules[0].getProject();
Module[] modules = ModuleManager.getInstance(project).getModules();
Collection<Module> modulesToRebuild = new THashSet<Module>();
for (Module module : modules) {
BuildJarSettings jarSettings = BuildJarSettings.getInstance(module);
if (jarSettings == null || !jarSettings.isBuildJar()) continue;
PackagingConfiguration packagingConfiguration = jarSettings.getPackagingConfiguration();
ModuleLink[] containingModules = packagingConfiguration.getContainingModules();
for (ModuleLink moduleLink : containingModules) {
Module containingModule = moduleLink.getModule();
if (ArrayUtil.find(affectedModules, containingModule) != -1) {
modulesToRebuild.add(module);
}
}
}
ProcessingItem[] result = new ProcessingItem[modulesToRebuild.size()];
int i=0;
for (Module moduleToBuild : modulesToRebuild) {
if (moduleToBuild.getModuleFile() == null) continue;
result[i++] = new MyProcItem(moduleToBuild);
}
return result;
}
});
}
public ProcessingItem[] process(final CompileContext context, final ProcessingItem[] items) {
try {
for (ProcessingItem item : items) {
MyProcItem procItem = (MyProcItem)item;
Module module = procItem.getModule();
BuildJarSettings jarSettings = BuildJarSettings.getInstance(module);
BuildJarProjectSettings.buildJar(module, jarSettings, context.getProgressIndicator(), context);
}
}
catch (IOException e) {
LOG.error(e);
}
return items;
}
@NotNull
public String getDescription() {
return "jar compile";
}
public boolean validateConfiguration(CompileScope scope) {
return true;
}
}
@@ -1,94 +0,0 @@
package com.intellij.jar;
import com.intellij.openapi.deployment.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditor;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorPolicy;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author nik
*/
public class JarPackagingEditorPolicy extends PackagingEditorPolicy {
private static final Logger LOG = Logger.getInstance("#com.intellij.jar.JarPackagingEditorPolicy");
@NonNls private static final String JAR_EXTENSION = ".jar";
private static final PackagingMethod[] COPY_OR_JAR_PACKAGING_METHODS = new PackagingMethod[]{
PackagingMethod.COPY_FILES,
PackagingMethod.JAR_AND_COPY_FILE,
PackagingMethod.JAR_AND_COPY_FILE_AND_LINK_VIA_MANIFEST
};
private static final PackagingMethod[] COPY_PACKAGING_METHODS = new PackagingMethod[]{
PackagingMethod.COPY_FILES,
PackagingMethod.COPY_FILES_AND_LINK_VIA_MANIFEST
};
public JarPackagingEditorPolicy(final @NotNull Module module) {
super(module);
}
protected PackagingMethod[] getAllowedPackagingMethodsForLibrary(LibraryLink libraryLink) {
return libraryLink.hasDirectoriesOnly() ? COPY_OR_JAR_PACKAGING_METHODS : COPY_PACKAGING_METHODS;
}
protected PackagingMethod[] getAllowedPackagingMethodsForModule(@NotNull Module module) {
if (StdModuleTypes.JAVA.equals(module.getModuleType())) {
return COPY_OR_JAR_PACKAGING_METHODS;
}
return PackagingMethod.EMPTY_ARRAY;
}
protected ContainerElement[] getModifiedElements(final PackagingEditor packagingEditor) {
return packagingEditor.getModifiedConfiguration().getElements();
}
protected PackagingMethod[] getPackagingMethodForUnresolvedElement(final ContainerElement element) {
return PackagingMethod.EMPTY_ARRAY;
}
public void setDefaultAttributes(ContainerElement element) {
if (element instanceof LibraryLink) {
element.setPackagingMethod(PackagingMethod.DO_NOT_PACKAGE);
}
if (element instanceof ModuleLink) {
PackagingMethod[] allowedDeploymentMethods = getAllowedPackagingMethods(element);
if (allowedDeploymentMethods.length < 1) {
LOG.error("illegal Packaging methods for " + element);
}
element.setPackagingMethod(allowedDeploymentMethods[0]);
}
element.setURI(suggestDefaultRelativePath(element));
}
public String suggestDefaultRelativePath(ContainerElement element) {
PackagingMethod packagingMethod = element.getPackagingMethod();
if (packagingMethod == PackagingMethod.DO_NOT_PACKAGE) return NOT_APPLICABLE;
boolean targetIsJar = packagingMethod == PackagingMethod.JAR_AND_COPY_FILE
|| packagingMethod == PackagingMethod.JAR_AND_COPY_FILE_AND_LINK_VIA_MANIFEST;
String relativePath = "/";
if (targetIsJar && element instanceof ModuleLink) {
relativePath = DeploymentUtil.appendToPath(relativePath, element.getPresentableName());
if (!relativePath.endsWith(JAR_EXTENSION)) {
relativePath += JAR_EXTENSION;
}
}
return relativePath;
}
protected List<Module> getSuitableModules(final PackagingEditor packagingEditor) {
List<Module> moduleList = PackagingEditorUtil.getModulesFromDependentOrderEntries(ModuleRootManager.getInstance(getModule()));
moduleList.add(getModule());
return moduleList;
}
protected List<Library> getSuitableLibraries(final PackagingEditor packagingEditor) {
return PackagingEditorUtil.getLibrariesFromDependentOrderEntries(ModuleRootManager.getInstance(getModule()));
}
}
@@ -1,48 +0,0 @@
package com.intellij.jar;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingArtifact;
import com.intellij.openapi.roots.ui.configuration.packaging.PackagingTreeBuilder;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Icons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public class JarPackagingTreeBuilder extends PackagingTreeBuilder {
private final Module myModule;
public JarPackagingTreeBuilder(final Module module) {
myModule = module;
}
public PackagingArtifact createRootArtifact() {
return new PackagingArtifact() {
@NotNull
@Override
public String getOutputFileName() {
return myModule.getName();
}
@Override
public void render(@NotNull final ColoredTreeCellRenderer renderer, final SimpleTextAttributes mainAttributes, final SimpleTextAttributes commentAttributes) {
renderer.setIcon(Icons.JAR_ICON);
renderer.append(myModule.getName() + ".jar", mainAttributes);
}
@Override
public void navigate(final ModuleStructureConfigurable configurable, @Nullable final ContainerElement element) {
}
@Override
public String getDisplayName() {
return myModule.getName();
}
};
}
}
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.ui.components.panels.Wrapper;
import com.intellij.ui.navigation.BackAction;
import com.intellij.ui.navigation.ForwardAction;
@@ -198,9 +197,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
}
private void addArtifactsConfig() {
if (ArtifactManager.useArtifacts()) {
addConfigurable(myArtifactsStructureConfigurable);
}
addConfigurable(myArtifactsStructureConfigurable);
}
public ArtifactsStructureConfigurable getArtifactsStructureConfigurable() {
@@ -1,30 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author nik
*/
public abstract class AddPackagingElementAction {
private final String myText;
private final Icon myIcon;
protected AddPackagingElementAction(final String text, final Icon icon) {
myText = text;
myIcon = icon;
}
public String getText() {
return myText;
}
public Icon getIcon() {
return myIcon;
}
public abstract boolean isEnabled(@NotNull PackagingEditor editor);
public abstract void perform(final PackagingEditor packagingEditor);
}
@@ -1,48 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.List;
/**
* @author nik
*/
class AddPackagingElementPopupStep extends BaseListPopupStep<AddPackagingElementAction> {
private final PackagingEditor myEditor;
public AddPackagingElementPopupStep(final PackagingEditor editor, final List<AddPackagingElementAction> addActions) {
super(null, addActions);
myEditor = editor;
}
@Override
public PopupStep onChosen(final AddPackagingElementAction selectedValue, final boolean finalChoice) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
selectedValue.perform(myEditor);
}
}, ModalityState.stateForComponent(myEditor.getMainPanel()));
return FINAL_CHOICE;
}
@Override
public boolean isSelectable(final AddPackagingElementAction value) {
return value.isEnabled(myEditor);
}
@Override
public Icon getIconFor(final AddPackagingElementAction aValue) {
return aValue.getIcon();
}
@NotNull
@Override
public String getTextFor(final AddPackagingElementAction value) {
return value.getText();
}
}
@@ -1,44 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Icons;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
class ArchiveNode extends PackagingTreeNode {
private final String myArchiveName;
ArchiveNode(final String archiveName, final PackagingArtifact owner) {
super(owner);
myArchiveName = archiveName;
}
@NotNull
public String getOutputFileName() {
return myArchiveName;
}
public double getWeight() {
return PackagingNodeWeights.ARCHIVE;
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
renderer.setIcon(Icons.JAR_ICON);
renderer.append(myArchiveName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
public boolean canNavigate() {
return false;
}
public void navigate(final ModuleStructureConfigurable configurable) {
}
public Object getSourceObject() {
return null;
}
}
@@ -1,44 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Icons;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
class DirectoryNode extends PackagingTreeNode {
private final String myDirectoryName;
DirectoryNode(final String directoryName, PackagingArtifact owner) {
super(owner);
myDirectoryName = directoryName;
}
@NotNull
public String getOutputFileName() {
return myDirectoryName;
}
public double getWeight() {
return PackagingNodeWeights.DIRECTORY;
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
renderer.setIcon(Icons.FOLDER_ICON);
renderer.append(myDirectoryName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
public boolean canNavigate() {
return false;
}
public void navigate(final ModuleStructureConfigurable configurable) {
}
public Object getSourceObject() {
return null;
}
}
@@ -1,39 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ColoredTreeCellRenderer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
class LibraryFileNode extends LibraryNodeBase {
private final VirtualFile myFile;
private final Library myLibrary;
LibraryFileNode(final @NotNull VirtualFile file, final @NotNull Library library, @NotNull LibraryLink libraryLink, final @Nullable PackagingArtifact owner) {
super(owner, libraryLink);
myFile = file;
myLibrary = library;
}
@NotNull
public String getOutputFileName() {
return myFile.getName();
}
public double getWeight() {
return PackagingNodeWeights.FILE;
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
PackagingEditorUtil.renderLibraryFile(renderer, myLibrary, myFile, getMainAttributes(), getCommentAttributes());
}
public VirtualFile getFile() {
return myFile;
}
}
@@ -1,65 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
class LibraryNode extends LibraryNodeBase {
LibraryNode(final LibraryLink libraryLink, PackagingArtifact owner) {
super(owner, libraryLink);
}
@NotNull
public String getOutputFileName() {
return myLibraryLink.getPresentableName();
}
public double getWeight() {
return PackagingNodeWeights.LIBRARY;
}
@Override
public String getSearchName() {
Library library = myLibraryLink.getLibrary();
if (library == null) {
return myLibraryLink.getPresentableName();
}
String name = library.getName();
if (name != null) {
return name;
}
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
if (files.length > 0) {
return files[0].getName();
}
return super.getSearchName();
}
@Override
public int compareTo(final PackagingTreeNode node) {
return getSearchName().compareToIgnoreCase(node.getSearchName());
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
Library library = myLibraryLink.getLibrary();
if (library == null) {
String libraryName = myLibraryLink.getPresentableName();
renderer.append(libraryName, SimpleTextAttributes.ERROR_ATTRIBUTES);
}
else {
PackagingEditorUtil.renderLibraryNode(renderer, library, getMainAttributes(), getCommentAttributes());
}
}
public boolean canNavigate() {
return true;
}
}
@@ -1,70 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
abstract class LibraryNodeBase extends PackagingTreeNode {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.packaging.LibraryNodeBase");
protected final LibraryLink myLibraryLink;
public LibraryNodeBase(final @Nullable PackagingArtifact owner, @NotNull LibraryLink libraryLink) {
super(owner);
myLibraryLink = libraryLink;
}
@Override
public ContainerElement getContainerElement() {
return myLibraryLink;
}
public boolean canNavigate() {
return true;
}
@Override
public String getTooltipText() {
if (belongsToIncludedArtifact()) {
PackagingArtifact owner = getOwner();
LOG.assertTrue(owner != null);
return ProjectBundle.message("node.text.packaging.included.from.0", owner.getDisplayName());
}
return null;
}
public void navigate(final ModuleStructureConfigurable configurable) {
Module parentModule = myLibraryLink.getParentModule();
final PackagingArtifact owner = getOwner();
if (owner != null) {
owner.navigate(configurable, myLibraryLink);
}
else {
ModulesConfigurator modulesConfigurator = configurable.getContext().getModulesConfigurator();
ModuleRootModel rootModel = modulesConfigurator.getRootModel(parentModule);
LibraryOrderEntry orderEntry = OrderEntryUtil.findLibraryOrderEntry(rootModel, myLibraryLink.getLibrary(), true, modulesConfigurator);
configurable.selectOrderEntry(orderEntry != null ? orderEntry.getOwnerModule() : parentModule, orderEntry);
}
}
public Object getSourceObject() {
return myLibraryLink.getLibrary();
}
public LibraryLink getLibraryLink() {
return myLibraryLink;
}
}
@@ -1,71 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModuleOrderEntry;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
abstract class ModuleOutputBaseNode extends PackagingTreeNode {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.packaging.ModuleOutputBaseNode");
protected final ModuleLink myModuleLink;
public ModuleOutputBaseNode(final @Nullable PackagingArtifact owner, final ModuleLink moduleLink) {
super(owner);
myModuleLink = moduleLink;
}
public ModuleLink getModuleLink() {
return myModuleLink;
}
public boolean canNavigate() {
return true;
}
public void navigate(final ModuleStructureConfigurable configurable) {
Module parentModule = myModuleLink.getParentModule();
PackagingArtifact owner = getOwner();
if (owner != null) {
owner.navigate(configurable, myModuleLink);
}
else {
ModulesConfigurator modulesConfigurator = configurable.getContext().getModulesConfigurator();
ModuleRootModel rootModel = modulesConfigurator.getRootModel(parentModule);
ModuleOrderEntry orderEntry = OrderEntryUtil.findModuleOrderEntry(rootModel, myModuleLink.getModule(), true, modulesConfigurator);
configurable.selectOrderEntry(orderEntry != null ? orderEntry.getOwnerModule() : parentModule, orderEntry);
}
}
public double getWeight() {
return PackagingNodeWeights.MODULE;
}
@Override
public String getTooltipText() {
if (belongsToIncludedArtifact()) {
PackagingArtifact owner = getOwner();
LOG.assertTrue(owner != null);
return ProjectBundle.message("node.text.packaging.included.from.0", owner.getDisplayName());
}
return null;
}
public Object getSourceObject() {
return myModuleLink.getModule();
}
public ContainerElement getContainerElement() {
return myModuleLink;
}
}
@@ -1,36 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
class ModuleOutputNode extends ModuleOutputBaseNode {
ModuleOutputNode(final ModuleLink moduleLink, final PackagingArtifact owner) {
super(owner, moduleLink);
}
@NotNull
public String getOutputFileName() {
return myModuleLink.getName();
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
final Module module = myModuleLink.getModule();
if (module == null) {
renderer.append(myModuleLink.getName(), SimpleTextAttributes.ERROR_ATTRIBUTES);
}
else {
renderer.append(module.getName(), getMainAttributes());
renderer.setIcon(module.getModuleType().getNodeIcon(false));
}
renderer.append(" " + ProjectBundle.message("node.text.packaging.compile.output"), getCommentAttributes());
}
}
@@ -1,29 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public abstract class PackagingArtifact {
@NotNull
public abstract String getOutputFileName();
public abstract void render(@NotNull ColoredTreeCellRenderer renderer, final SimpleTextAttributes mainAttributes,
final SimpleTextAttributes commentAttributes);
public abstract void navigate(ModuleStructureConfigurable configurable, @Nullable ContainerElement element);
public abstract String getDisplayName();
@Nullable
public ContainerElement getContainerElement() {
return null;
}
}
@@ -1,52 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class PackagingArtifactNode extends PackagingTreeNode {
private final PackagingArtifact myArtifact;
PackagingArtifactNode(final PackagingArtifact artifact, PackagingArtifact owner) {
super(owner);
myArtifact = artifact;
}
public PackagingArtifact getArtifact() {
return myArtifact;
}
@NotNull
public String getOutputFileName() {
return myArtifact.getOutputFileName();
}
public double getWeight() {
return PackagingNodeWeights.ARTIFACT;
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
myArtifact.render(renderer, getMainAttributes(), getCommentAttributes());
}
public boolean canNavigate() {
return true;
}
public void navigate(final ModuleStructureConfigurable configurable) {
myArtifact.navigate(configurable, null);
}
public Object getSourceObject() {
return null;
}
@Override
public ContainerElement getContainerElement() {
return myArtifact.getContainerElement();
}
}
@@ -1,50 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.PackagingConfiguration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.OrderEntry;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.List;
import java.util.Set;
/**
* @author nik
*/
public interface PackagingEditor {
void saveData();
void moduleStateChanged();
ContainerElement[] getModifiedElements();
boolean isModified();
void reset();
JComponent createMainComponent();
JPanel getMainPanel();
void addModules(final List<Module> modules);
void addLibraries(final List<Library> libraries);
PackagingConfiguration getModifiedConfiguration();
void rebuildTree();
void addElement(ContainerElement element);
void selectElement(@NotNull ContainerElement toSelect, final boolean requestFocus);
void processNewOrderEntries(final Set<OrderEntry> newEntries);
void addListener(@NotNull PackagingEditorListener listener);
void removeListener(@NotNull PackagingEditorListener listener);
}
@@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorImpl">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="b7166" binding="myTreePanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="f4662" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="1f25d" class="javax.swing.JButton" binding="myAddButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ProjectBundle" key="button.text.packaging.tree.add"/>
</properties>
</component>
<vspacer id="f9924">
<constraints>
<grid row="3" 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="d2d2f" class="javax.swing.JButton" binding="myRemoveButton" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/CommonBundle" key="button.remove"/>
</properties>
</component>
<component id="afa32" class="javax.swing.JButton" binding="myEditButton" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ProjectBundle" key="button.text.packaging.tree.edit"/>
</properties>
</component>
</children>
</grid>
<grid id="648e5" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d6cc" class="javax.swing.JCheckBox" binding="myShowIncludedCheckBox">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ProjectBundle" key="checkbox.text.show.content.of.included.facets"/>
</properties>
</component>
<component id="cc5b3" class="javax.swing.JCheckBox" binding="myShowLibraryFilesCheckBox" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ProjectBundle" key="checkbox.text.show.library.files"/>
</properties>
</component>
<hspacer id="4c207">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</form>
@@ -1,536 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ide.CommonActionsManager;
import com.intellij.ide.DefaultTreeExpander;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.deployment.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.roots.ui.configuration.projectRoot.FindUsagesInProjectStructureActionBase;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.*;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.containers.Convertor;
import com.intellij.util.ui.tree.TreeUtil;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.List;
/**
* @author nik
*/
public class PackagingEditorImpl implements PackagingEditor {
private static final Convertor<TreePath, String> SPEED_SEARCH_CONVERTOR = new Convertor<TreePath, String>() {
public String convert(final TreePath path) {
Object o = path.getLastPathComponent();
if (o instanceof PackagingTreeNode) {
return ((PackagingTreeNode)o).getSearchName();
}
return "";
}
};
private final PackagingConfiguration myOriginalConfiguration;
private final PackagingConfiguration myModifiedConfiguration;
private final ModulesProvider myModulesProvider;
private final FacetsProvider myFacetsProvider;
private final PackagingEditorPolicy myPolicy;
private Tree myTree;
private RootNode myRoot;
private DefaultTreeModel myTreeModel;
private final PackagingTreeBuilder myBuilder;
private JPanel myMainPanel;
private JPanel myTreePanel;
private JButton myAddButton;
private JButton myRemoveButton;
private JButton myEditButton;
private JCheckBox myShowIncludedCheckBox;
private JCheckBox myShowLibraryFilesCheckBox;
private PackagingArtifact myRootArtifact;
private final Project myProject;
private PackagingTreeParameters myTreeParameters;
private final EventDispatcher<PackagingEditorListener> myDispatcher = EventDispatcher.create(PackagingEditorListener.class);
public PackagingEditorImpl(final PackagingConfiguration originalConfiguration,
final PackagingConfiguration modifiedConfiguration,
final ModulesProvider modulesProvider, final FacetsProvider facetsProvider, final PackagingEditorPolicy policy,
final PackagingTreeBuilder builder, final boolean showIncludedCheckboxVisible) {
myOriginalConfiguration = originalConfiguration;
myModifiedConfiguration = modifiedConfiguration;
myModulesProvider = modulesProvider;
myFacetsProvider = facetsProvider;
myPolicy = policy;
myBuilder = builder;
myProject = myPolicy.getModule().getProject();
setTreeParameters(myBuilder.getDefaultParameters());
myAddButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
JBPopupFactory.getInstance().createListPopup(new AddPackagingElementPopupStep(PackagingEditorImpl.this, myPolicy.getAddActions())).showUnderneathOf(myAddButton);
}
});
myEditButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
PackagingElementsToEditInfo elementsToEdit = getSelectedElements().getElementsToEdit(myPolicy);
if (elementsToEdit != null) {
editElement(elementsToEdit);
}
}
});
myRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
removeSelectedElements();
}
});
ActionListener actionListener = new ActionListener() {
public void actionPerformed(final ActionEvent e) {
myTreeParameters = new PackagingTreeParameters(myShowIncludedCheckBox.isSelected(), myShowLibraryFilesCheckBox.isSelected());
myBuilder.updateParameters(myTreeParameters);
rebuildTree();
}
};
myShowIncludedCheckBox.addActionListener(actionListener);
myShowLibraryFilesCheckBox.addActionListener(actionListener);
myShowIncludedCheckBox.setVisible(showIncludedCheckboxVisible);
}
public void removeSelectedElements() {
SelectedPackagingElements selectedElements = getSelectedElements();
if (!selectedElements.showRemovingWarning(this)) return;
saveData();
for (ContainerElement containerElement : selectedElements.getContainerElements()) {
myModifiedConfiguration.removeContainerElement(containerElement);
}
for (PackagingArtifact owner : selectedElements.getOwners()) {
ContainerElement element = owner.getContainerElement();
if (element != null) {
myModifiedConfiguration.removeContainerElement(element);
}
}
rebuildTree();
}
public PackagingArtifact getRootArtifact() {
return myRootArtifact;
}
private SelectedPackagingElements getSelectedElements() {
PackagingTreeNode[] treeNodes = myTree.getSelectedNodes(PackagingTreeNode.class, null);
return new SelectedPackagingElements(treeNodes);
}
public void addModules(final List<Module> modules) {
if (modules.isEmpty()) return;
saveData();
modules.removeAll(Arrays.asList(myModifiedConfiguration.getContainingIdeaModules()));
ContainerElement last = null;
for (Module module : modules) {
ModuleLink element = DeploymentUtil.getInstance().createModuleLink(module, myPolicy.getModule());
addElement(element);
last = element;
}
rebuildTree();
if (last != null) {
selectElement(last, false);
}
}
private void editElement(final @NotNull PackagingElementsToEditInfo elementsToEdit) {
saveData();
boolean ok = PackagingElementPropertiesComponent.showDialog(elementsToEdit, myMainPanel, myPolicy, myDispatcher.getMulticaster());
if (ok) {
rebuildTree();
selectElements(elementsToEdit.getElements());
}
}
@TestOnly
@Nullable
public PackagingElementPropertiesComponent editSelectedElements() {
SelectedPackagingElements selectedElements = getSelectedElements();
if (selectedElements == null) return null;
PackagingElementsToEditInfo elementsInfo = selectedElements.getElementsToEdit(myPolicy);
if (elementsInfo == null) return null;
return PackagingElementPropertiesComponent.createPropertiesComponent(elementsInfo, myPolicy, null);
}
private void selectElements(final List<ContainerElement> elements) {
//todo[nik]
selectElement(elements.get(0), false);
}
public void addElement(final ContainerElement element) {
if (myPolicy.isAllowedToPackage(element)) {
myPolicy.setDefaultAttributes(element);
PackagingMethod method = element.getPackagingMethod();
if (method == PackagingMethod.DO_NOT_PACKAGE) {
//todo[nik] is it correct?
PackagingMethod[] methods = myPolicy.getAllowedPackagingMethods(element);
element.setPackagingMethod(methods[0]);
element.setURI(myPolicy.suggestDefaultRelativePath(element));
}
myModifiedConfiguration.addOrReplaceElement(element);
}
}
public void selectElement(@NotNull final ContainerElement toSelect, final boolean requestFocus) {
PackagingTreeNode node = findNodeByElement(toSelect);
if (node != null) {
TreeUtil.selectNode(myTree, node);
if (requestFocus) {
IdeFocusManager.getInstance(myProject).requestFocus(myTree, true);
}
}
}
public void processNewOrderEntries(final Set<OrderEntry> newEntries) {
List<Library> libraries = new ArrayList<Library>();
for (OrderEntry entry : newEntries) {
if (entry instanceof LibraryOrderEntry) {
libraries.add(((LibraryOrderEntry)entry).getLibrary());
}
}
myPolicy.processNewLibraries(this, libraries);
}
public void addListener(@NotNull final PackagingEditorListener listener) {
myDispatcher.addListener(listener);
}
public void removeListener(@NotNull final PackagingEditorListener listener) {
myDispatcher.removeListener(listener);
}
@TestOnly
public boolean selectNodes(@NotNull @NonNls final String... nodeNames) {
final List<PackagingTreeNode> toSelect = new ArrayList<PackagingTreeNode>();
TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() {
public boolean accept(final Object node) {
if (node instanceof PackagingTreeNode) {
PackagingTreeNode packagingNode = (PackagingTreeNode)node;
if (Arrays.asList(nodeNames).contains(packagingNode.getOutputFileName())) {
toSelect.add(packagingNode);
}
}
return true;
}
});
myTree.getSelectionModel().clearSelection();
for (PackagingTreeNode node : toSelect) {
myTree.getSelectionModel().addSelectionPath(new TreePath(node.getPath()));
}
return toSelect.size() == nodeNames.length;
}
@Nullable
private PackagingTreeNode findNodeByElement(final ContainerElement toSelect) {
final Ref<PackagingTreeNode> ref = Ref.create(null);
TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() {
public boolean accept(final Object node) {
if (node instanceof PackagingTreeNode) {
PackagingTreeNode packagingNode = (PackagingTreeNode)node;
ContainerElement element = packagingNode.getContainerElement();
if (toSelect.equals(element)) {
ref.set(packagingNode);
return false;
}
}
return true;
}
});
return ref.get();
}
public Tree getTree() {
return myTree;
}
public void addLibraries(final List<Library> libraries) {
if (libraries.isEmpty()) return;
saveData();
libraries.removeAll(Arrays.asList(myModifiedConfiguration.getContainingLibraries()));
ContainerElement last = null;
for (Library library : libraries) {
LibraryLink libraryLink = DeploymentUtil.getInstance().createLibraryLink(library, myPolicy.getModule());
addElement(libraryLink);
last = libraryLink;
}
rebuildTree();
if (last != null) {
selectElement(last, false);
}
}
public void setTreeParameters(PackagingTreeParameters parameters) {
myShowIncludedCheckBox.setSelected(parameters.isShowIncludedContent());
myShowLibraryFilesCheckBox.setSelected(parameters.isShowLibraryFiles());
myTreeParameters = parameters;
}
public void rebuildTree() {
PackagingTreeState state = PackagingTreeState.saveState(myTree);
myRoot.removeAllChildren();
myRootArtifact = myBuilder.createRootArtifact();
PackagingArtifactNode root = PackagingTreeNodeFactoryOld.createArtifactNode(myRootArtifact, myRoot, null);
for (ContainerElement element : getPackagedElements()) {
myBuilder.createNodes(root, element, null, myTreeParameters);
}
myTreeModel.nodeStructureChanged(myRoot);
TreeUtil.sort(myTreeModel, new Comparator<PackagingTreeNode>() {
public int compare(final PackagingTreeNode node1, final PackagingTreeNode node2) {
double weight1 = node1.getWeight();
double weight2 = node2.getWeight();
if (weight1 < weight2) return -1;
if (weight1 > weight2) return 1;
return node1.compareTo(node2);
}
});
state.restoreState(myTree);
}
public void saveData() {
}
public void moduleStateChanged() {
if (myPolicy.removeObsoleteElements(this)) {
rebuildTree();
}
}
public PackagingConfiguration getModifiedConfiguration() {
return myModifiedConfiguration;
}
public ContainerElement[] getModifiedElements() {
return myModifiedConfiguration.getElements(myModulesProvider, myFacetsProvider, true, true, true);
}
public boolean isModified() {
final ContainerElement[] elements1 = getPackagedElements();
final ContainerElement[] elements2 = myOriginalConfiguration.getElements(myModulesProvider, myFacetsProvider, true, true, false);
return !Comparing.haveEqualElements(elements1, elements2);
}
private ContainerElement[] getPackagedElements() {
return myModifiedConfiguration.getElements(myModulesProvider, myFacetsProvider, true, true, false);
}
public void reset() {
final ContainerElement[] elements = myOriginalConfiguration.getElements(myModulesProvider, myFacetsProvider, true, true, true);
ContainerElement[] newElements = new ContainerElement[elements.length];
for (int i = 0; i < elements.length; i++) {
newElements[i] = elements[i].clone();
}
myModifiedConfiguration.setElements(newElements);
if (myTree != null) {
rebuildTree();
}
}
public JComponent createMainComponent() {
myMainPanel.setMinimumSize(new Dimension(-1, 250));
myRoot = new RootNode();
myTreeModel = new DefaultTreeModel(myRoot);
myTree = new Tree(myTreeModel) {
@Override
public String getToolTipText(final MouseEvent event) {
TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
if (path != null) {
return ((PackagingTreeNode)path.getLastPathComponent()).getTooltipText();
}
return super.getToolTipText();
}
};
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.setCellRenderer(new PackagingTreeCellRenderer());
myTreePanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
new TreeSpeedSearch(myTree, SPEED_SEARCH_CONVERTOR, true);
myTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(final TreeSelectionEvent e) {
updateButtons();
}
});
myTree.addMouseListener(new PackagingTreeMouseListener());
DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new MyNavigateAction());
actionGroup.add(new MyFindUsagesAction());
actionGroup.add(Separator.getInstance());
CommonActionsManager actionsManager = CommonActionsManager.getInstance();
DefaultTreeExpander treeExpander = new DefaultTreeExpander(myTree);
actionGroup.add(actionsManager.createExpandAllAction(treeExpander, myTree));
actionGroup.add(actionsManager.createCollapseAllAction(treeExpander, myTree));
PopupHandler.installPopupHandler(myTree, actionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
TreeToolTipHandler.install(myTree);
ToolTipManager.sharedInstance().registerComponent(myTree);
rebuildTree();
TreeUtil.expandAll(myTree);
updateButtons();
return myMainPanel;
}
private void updateButtons() {
SelectedPackagingElements selectedElements = getSelectedElements();
List<ContainerElement> elements = selectedElements.getContainerElements();
Set<PackagingArtifact> artifacts = selectedElements.getOwners();
myRemoveButton.setEnabled(!elements.isEmpty() || !artifacts.isEmpty());
PackagingElementsToEditInfo elementsToEdit = selectedElements.getElementsToEdit(myPolicy);
myEditButton.setEnabled(elementsToEdit != null && PackagingElementPropertiesComponent.isEnabled(elementsToEdit));
}
public JPanel getMainPanel() {
return myMainPanel;
}
public PackagingTreeNode getRoot() {
return myRoot;
}
private void navigate(PackagingTreeNode treeNode) {
treeNode.navigate(ModuleStructureConfigurable.getInstance(myProject));
}
private static class RootNode extends PackagingTreeNode {
private RootNode() {
super(null);
}
@NotNull
public String getOutputFileName() {
return "";
}
public double getWeight() {
return 0;
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
}
public boolean canNavigate() {
return false;
}
public void navigate(final ModuleStructureConfigurable configurable) {
}
public Object getSourceObject() {
return null;
}
}
private class PackagingTreeMouseListener extends MouseAdapter {
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
PackagingTreeNode[] nodes = myTree.getSelectedNodes(PackagingTreeNode.class, null);
if (nodes.length == 1) {
PackagingTreeNode node = nodes[0];
if (node.getChildren().isEmpty()) {
ContainerElement element = node.getContainerElement();
if (element != null) {
if (node.getOwner() == null) {
editElement(new PackagingElementsToEditInfo(element, myPolicy));
}
else {
navigate(node);
}
}
}
}
}
}
}
private static class PackagingTreeCellRenderer extends ColoredTreeCellRenderer {
public void customizeCellRenderer(final JTree tree,
final Object value,
final boolean selected,
final boolean expanded,
final boolean leaf,
final int row,
final boolean hasFocus) {
PackagingTreeNode node = (PackagingTreeNode)value;
node.render(this);
setEnabled(tree.isEnabled());
}
}
private class MyNavigateAction extends AnAction {
private MyNavigateAction() {
super(ProjectBundle.message("action.name.facet.navigate"));
registerCustomShortcutSet(CommonShortcuts.getEditSource(), myTree);
}
public void update(final AnActionEvent e) {
PackagingTreeNode[] treeNodes = myTree.getSelectedNodes(PackagingTreeNode.class, null);
e.getPresentation().setEnabled(treeNodes.length == 1 && treeNodes[0].canNavigate());
}
public void actionPerformed(final AnActionEvent e) {
PackagingTreeNode[] treeNodes = myTree.getSelectedNodes(PackagingTreeNode.class, null);
if (treeNodes.length == 1) {
navigate(treeNodes[0]);
}
}
}
private class MyFindUsagesAction extends FindUsagesInProjectStructureActionBase {
public MyFindUsagesAction() {
super(myTree, myProject);
}
protected boolean isEnabled() {
PackagingTreeNode[] treeNodes = myTree.getSelectedNodes(PackagingTreeNode.class, null);
return treeNodes.length == 1 && treeNodes[0].getSourceObject() != null;
}
protected Object getSelectedObject() {
PackagingTreeNode[] treeNodes = myTree.getSelectedNodes(PackagingTreeNode.class, null);
return treeNodes.length == 1 ? treeNodes[0].getSourceObject() : null;
}
protected RelativePoint getPointToShowResults() {
final int selectedRow = myTree.getSelectionRows()[0];
final Rectangle rowBounds = myTree.getRowBounds(selectedRow);
final Point location = rowBounds.getLocation();
location.y += rowBounds.height;
return new RelativePoint(myTree, location);
}
}
}
@@ -1,15 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import org.jetbrains.annotations.NotNull;
import java.util.EventListener;
/**
* @author nik
*/
public interface PackagingEditorListener extends EventListener {
void packagingMethodChanged(@NotNull ContainerElement element);
}
@@ -1,216 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.deployment.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
import com.intellij.util.Icons;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.*;
/**
* @author nik
*/
public abstract class PackagingEditorPolicy {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorPolicy");
public static final String NOT_APPLICABLE = IdeBundle.message("text.not.applicable");
private final Module myModule;
protected PackagingEditorPolicy(final @NotNull Module module) {
myModule = module;
}
protected abstract PackagingMethod[] getAllowedPackagingMethodsForLibrary(LibraryLink libraryLink);
protected abstract PackagingMethod[] getAllowedPackagingMethodsForModule(@NotNull Module module);
public abstract void setDefaultAttributes(ContainerElement element);
public abstract String suggestDefaultRelativePath(ContainerElement element);
protected abstract List<Module> getSuitableModules(final PackagingEditor packagingEditor);
protected abstract List<Library> getSuitableLibraries(final PackagingEditor packagingEditor);
protected abstract ContainerElement[] getModifiedElements(PackagingEditor packagingEditor);
public boolean isRelativePathCellEditable(final ContainerElement element) {
return element instanceof LibraryLink
|| element instanceof ModuleLink && ((ModuleLink)element).getModule() != null;
}
@Nullable
public AdditionalPropertiesConfigurable getAdditionalPropertiesConfigurable(@NotNull ContainerElement element) {
return null;
}
public PackagingMethod[] getAllowedPackagingMethods(ContainerElement element) {
if (element instanceof LibraryLink) {
final LibraryLink libraryLink = (LibraryLink)element;
if (libraryLink.getLibrary() == null) {
return getPackagingMethodForUnresolvedElement(libraryLink);
}
return getAllowedPackagingMethodsForLibrary(libraryLink);
}
if (element instanceof ModuleLink) {
final ModuleLink moduleLink = (ModuleLink)element;
final Module module = moduleLink.getModule();
if (module != null) {
return getAllowedPackagingMethodsForModule(module);
}
return getPackagingMethodForUnresolvedElement(moduleLink);
}
LOG.assertTrue(false, "unexpected element: " + element.getClass());
return null;
}
protected PackagingMethod[] getPackagingMethodForUnresolvedElement(final ContainerElement element) {
final PackagingMethod method = element.getPackagingMethod();
if (method == PackagingMethod.DO_NOT_PACKAGE) {
return PackagingMethod.EMPTY_ARRAY;
}
return new PackagingMethod[]{method};
}
public boolean isAllowedToPackage(ContainerElement element) {
return getAllowedPackagingMethods(element).length > 0;
}
@NotNull
public Module getModule() {
return myModule;
}
protected List<AddPackagingElementAction> getAddActions() {
List<AddPackagingElementAction> actions = new ArrayList<AddPackagingElementAction>();
actions.add(new AddPackagingElementAction(ProjectBundle.message("action.name.packaging.add.library"), Icons.LIBRARY_ICON) {
public boolean isEnabled(@NotNull final PackagingEditor editor) {
return !getLibrariesToAdd(editor).isEmpty();
}
public void perform(final PackagingEditor packagingEditor) {
List<Library> libraries = getLibrariesToAdd(packagingEditor);
ContainerUtil.removeDuplicates(libraries);
ChooseLibrariesDialog dialog = new ChooseLibrariesDialog(packagingEditor.getMainPanel(),
ProjectBundle.message("dialog.title.packaging.choose.library"), libraries);
dialog.show();
if (dialog.isOK()) {
packagingEditor.addLibraries(dialog.getChosenElements());
}
}
});
actions.add(new AddPackagingElementAction(ProjectBundle.message("action.name.packaging.add.module"), StdModuleTypes.JAVA.getNodeIcon(false)) {
public boolean isEnabled(@NotNull final PackagingEditor editor) {
return !getModulesToAdd(editor).isEmpty();
}
public void perform(final PackagingEditor packagingEditor) {
List<Module> moduleList = getModulesToAdd(packagingEditor);
ContainerUtil.removeDuplicates(moduleList);
ChooseModulesDialog dialog = new ChooseModulesDialog(packagingEditor.getMainPanel(), moduleList,
ProjectBundle.message("dialog.title.packaging.choose.module"));
dialog.show();
List<Module> modules = new ArrayList<Module>(dialog.getChosenElements());
if (dialog.isOK()) {
packagingEditor.addModules(modules);
}
}
});
return actions;
}
private List<Library> getLibrariesToAdd(final PackagingEditor editor) {
List<Library> libraries = new ArrayList<Library>(getSuitableLibraries(editor));
Set<Library> addedLibraries = new HashSet<Library>();
for (ContainerElement element : getModifiedElements(editor)) {
if (element instanceof LibraryLink) {
addedLibraries.add(((LibraryLink)element).getLibrary());
}
}
libraries.removeAll(addedLibraries);
return libraries;
}
private List<Module> getModulesToAdd(final PackagingEditor editor) {
List<Module> moduleList = new ArrayList<Module>(getSuitableModules(editor));
Set<Module> addedModules = new HashSet<Module>();
for (ContainerElement element : getModifiedElements(editor)) {
if (element instanceof ModuleLink) {
addedModules.add(((ModuleLink)element).getModule());
}
}
moduleList.removeAll(addedModules);
return moduleList;
}
public boolean removeObsoleteElements(final PackagingEditor packagingEditor) {
boolean modelChanged = false;
Set<Library> libraries = new HashSet<Library>(getSuitableLibraries(packagingEditor));
Set<Module> modules = new HashSet<Module>(getSuitableModules(packagingEditor));
List<ContainerElement> elements = new ArrayList<ContainerElement>(Arrays.asList(getModifiedElements(packagingEditor)));
PackagingConfiguration configuration = packagingEditor.getModifiedConfiguration();
for (ContainerElement element : elements) {
boolean remove = false;
if (element instanceof LibraryLink) {
Library library = ((LibraryLink)element).getLibrary();
remove = library != null && !libraries.contains(library);
}
else if (element instanceof ModuleLink) {
Module module = ((ModuleLink)element).getModule();
remove = module != null && !modules.contains(module);
}
if (remove) {
configuration.removeContainerElement(element);
modelChanged = true;
}
}
return modelChanged;
}
public String getElementText(final ContainerElement element) {
if (element instanceof LibraryLink) {
final LibraryLink libraryLink = (LibraryLink)element;
Library library = libraryLink.getLibrary();
if (library != null) {
return PackagingEditorUtil.getLibraryDescription(library);
}
}
if (element instanceof ModuleLink) {
final ModuleLink moduleLink = (ModuleLink)element;
return ProjectBundle.message("text.module.link.description.0.module", moduleLink.getName());
}
return element.getPresentableName();
}
public void processNewLibraries(final PackagingEditor editor, final List<Library> libraries) {
List<Library> toAdd = new ArrayList<Library>();
Set<Library> suitable = new HashSet<Library>(getLibrariesToAdd(editor));
for (Library library : libraries) {
if (suitable.contains(library) && shouldAddSilently(library)) {
toAdd.add(library);
}
}
editor.addLibraries(toAdd);
}
protected boolean shouldAddSilently(final Library library) {
return false;
}
protected static abstract class AdditionalPropertiesConfigurable {
public abstract JComponent getLabelsComponent();
public abstract JComponent getFieldsComponent();
public abstract void resetFrom(ContainerElement element);
public abstract void applyTo(ContainerElement element);
}
}
@@ -1,24 +1,12 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.ui.util.OrderEntryCellAppearanceUtils;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Icons;
import com.intellij.packaging.impl.ui.LibraryElementPresentation;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author nik
*/
@@ -26,76 +14,6 @@ public class PackagingEditorUtil {
private PackagingEditorUtil() {
}
public static void renderLibraryNode(final ColoredTreeCellRenderer renderer, final Library library,
final SimpleTextAttributes mainAttributes, final SimpleTextAttributes commentAttributes) {
String name = library.getName();
if (name != null) {
renderer.setIcon(Icons.LIBRARY_ICON);
renderer.append(name, mainAttributes);
renderer.append(LibraryElementPresentation.getLibraryTableComment(library), commentAttributes);
}
else {
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
if (files.length > 0) {
VirtualFile file = files[0];
renderer.setIcon(file.getIcon());
renderer.append(file.getName(), mainAttributes);
renderer.append(LibraryElementPresentation.getLibraryTableComment(library), commentAttributes);
}
else {
OrderEntryCellAppearanceUtils.forLibrary(library).customize(renderer);
}
}
}
public static void renderLibraryFile(final ColoredTreeCellRenderer renderer, final Library library, final VirtualFile file,
final SimpleTextAttributes mainAttributes, final SimpleTextAttributes commentAttributes) {
renderer.setIcon(file.getIcon());
renderer.append(file.getName(), mainAttributes);
String name = library.getName();
LibraryTable table = library.getTable();
if (name != null) {
StringBuilder comment = new StringBuilder();
comment.append(" ('").append(name).append("' ");
comment.append(LibraryElementPresentation.getLibraryTableDisplayName(library));
comment.append(")");
renderer.append(comment.toString(), commentAttributes);
}
else if (table == null) {
Module module = ((LibraryImpl)library).getModule();
String comment;
if (module == null) {
comment = " (" + LibraryElementPresentation.getLibraryTableDisplayName(library) + ")";
}
else {
comment = " " + ProjectBundle.message("node.text.library.of.module", module.getName());
}
renderer.append(comment, commentAttributes);
}
}
public static String getLibraryDescription(final @NotNull Library library) {
String name = library.getName();
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
if (name != null) {
return "'" + name + "' " + LibraryElementPresentation.getLibraryTableDisplayName(library);
}
else if (files.length > 0) {
Module module = ((LibraryImpl)library).getModule();
final String description;
if (module == null) {
description = "(" + LibraryElementPresentation.getLibraryTableDisplayName(library) + ")";
}
else {
description = ProjectBundle.message("node.text.library.of.module", module.getName());
}
return files[0].getName() + " " + description;
}
else {
return ProjectBundle.message("library.empty.item");
}
}
public static String getLibraryItemText(final @NotNull Library library, final boolean includeTableName) {
String name = library.getName();
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
@@ -110,31 +28,4 @@ public class PackagingEditorUtil {
}
}
public static List<Module> getModulesFromDependentOrderEntries(final @NotNull ModuleRootModel rootModel) {
List<Module> moduleList = new ArrayList<Module>();
Collection<OrderEntry> orderEntries = OrderEntryUtil.getDependentOrderEntries(rootModel);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof ModuleOrderEntry) {
Module module = ((ModuleOrderEntry)orderEntry).getModule();
if (module != null) {
moduleList.add(module);
}
}
}
return moduleList;
}
public static List<Library> getLibrariesFromDependentOrderEntries(final @NotNull ModuleRootModel rootModel) {
List<Library> libraries = new ArrayList<Library>();
for (OrderEntry orderEntry : OrderEntryUtil.getDependentOrderEntries(rootModel)) {
if (orderEntry instanceof LibraryOrderEntry) {
Library library = ((LibraryOrderEntry)orderEntry).getLibrary();
if (library != null) {
libraries.add(library);
}
}
}
return libraries;
}
}
@@ -1,79 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.roots.ui.configuration.packaging.PackagingElementPropertiesComponent">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" 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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8361c" class="javax.swing.JLabel" binding="myPackagingMethodLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="c3339"/>
<text resource-bundle="messages/ProjectBundle" key="label.text.packaging.method"/>
</properties>
</component>
<hspacer id="90f34">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="f4b7c">
<constraints>
<grid row="4" 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="295b7" class="javax.swing.JLabel" binding="myOutputPathLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="22b1d"/>
<text resource-bundle="messages/ProjectBundle" key="label.text.output.relative.path"/>
</properties>
</component>
<component id="c3339" class="javax.swing.JComboBox" binding="myPackagingMethodBox">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="22b1d" class="javax.swing.JTextField" binding="myOutputPathField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="64ac7" class="javax.swing.JLabel" binding="myElementNameLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="111111"/>
</properties>
</component>
<grid id="2ead5" binding="myLabelsPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="f5f49" binding="myFieldPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
@@ -1,224 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.PackagingMethod;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
/**
* @author nik
*/
public class PackagingElementPropertiesComponent {
private JPanel myMainPanel;
private JComboBox myPackagingMethodBox;
private JTextField myOutputPathField;
private JLabel myPackagingMethodLabel;
private JLabel myOutputPathLabel;
private JLabel myElementNameLabel;
private JPanel myLabelsPanel;
private JPanel myFieldPanel;
private final PackagingEditorPolicy myEditorPolicy;
private PackagingMethod myLastSelectedMethod;
private PackagingEditorPolicy.AdditionalPropertiesConfigurable myAdditionalPropertiesConfigurable;
private final PackagingElementsToEditInfo myElementsInfo;
private Map<ContainerElement,String> myPathTails;
private final PackagingEditorListener myListener;
private PackagingElementPropertiesComponent(PackagingElementsToEditInfo elementsInfo, PackagingEditorPolicy editorPolicy,
final @Nullable PackagingEditorListener listener) {
myElementsInfo = elementsInfo;
myListener = listener;
myElementNameLabel.setText(elementsInfo.getElementText());
myEditorPolicy = editorPolicy;
if (elementsInfo.getAllowedPackagingMethods().length > 1 && elementsInfo.getPackagingMethod() != null) {
for (PackagingMethod method : elementsInfo.getAllowedPackagingMethods()) {
myPackagingMethodBox.addItem(method);
}
myPackagingMethodBox.setRenderer(new PackagingMethodListCellRenderer());
myPackagingMethodBox.setSelectedItem(myLastSelectedMethod = elementsInfo.getPackagingMethod());
myPackagingMethodBox.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
updateOutputPath();
}
});
}
else {
myPackagingMethodBox.setVisible(false);
myPackagingMethodLabel.setVisible(false);
}
String outputPath = elementsInfo.getRelativePath();
myPathTails = elementsInfo.getPathTails();
if (outputPath != null) {
myOutputPathField.setText(outputPath);
}
else {
myOutputPathField.setVisible(false);
myOutputPathLabel.setVisible(false);
}
List<ContainerElement> elements = elementsInfo.getElements();
if (elements.size() == 1) {
ContainerElement element = elements.get(0);
myAdditionalPropertiesConfigurable = editorPolicy.getAdditionalPropertiesConfigurable(element);
if (myAdditionalPropertiesConfigurable != null) {
myLabelsPanel.add(myAdditionalPropertiesConfigurable.getLabelsComponent(), BorderLayout.CENTER);
myFieldPanel.add(myAdditionalPropertiesConfigurable.getFieldsComponent(), BorderLayout.CENTER);
myAdditionalPropertiesConfigurable.resetFrom(element);
}
}
}
private void updateOutputPath() {
PackagingMethod method = getSelectedMethod();
if (method != myLastSelectedMethod && method != null) {
Map<ContainerElement, String> paths = new HashMap<ContainerElement, String>();
for (ContainerElement element : myElementsInfo.getElements()) {
PackagingMethod oldMethod = element.getPackagingMethod();
element.setPackagingMethod(method);
paths.put(element, myEditorPolicy.suggestDefaultRelativePath(element));
element.setPackagingMethod(oldMethod);
}
Pair<String,Map<ContainerElement,String>> pair = PackagingElementsToEditInfo.getPrefixAndSuffixes(paths, myEditorPolicy);
if (pair != null) {
myOutputPathField.setText(pair.getFirst());
myPathTails = pair.getSecond();
}
myOutputPathField.setEnabled(pair != null);
myLastSelectedMethod = method;
}
}
@TestOnly
public JTextField getOutputPathField() {
return myOutputPathField;
}
public JPanel getMainPanel() {
return myMainPanel;
}
public void applyChanges() {
PackagingMethod packagingMethod = getSelectedMethod();
List<ContainerElement> changedElements = new ArrayList<ContainerElement>();
if (packagingMethod != null && myElementsInfo.getPackagingMethod() != null) {
for (ContainerElement element : myElementsInfo.getElements()) {
element.setPackagingMethod(packagingMethod);
}
}
String text = myOutputPathField.getText();
if (text.length() == 0) {
text = "/";
}
if (myElementsInfo.getRelativePath() != null) {
for (ContainerElement element : myElementsInfo.getElements()) {
String path = text;
if (myPathTails != null) {
String tail = myPathTails.get(element);
if (tail.startsWith("/")) {
tail = tail.substring(1);
}
if (!path.endsWith("/")) {
path += "/";
}
path += tail;
}
if (path.length() > 1 && path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
element.setURI(FileUtil.toSystemIndependentName(path));
}
}
if (myAdditionalPropertiesConfigurable != null && myElementsInfo.getElements().size() == 1) {
myAdditionalPropertiesConfigurable.applyTo(myElementsInfo.getElements().get(0));
}
if (myListener != null) {
for (ContainerElement changedElement : changedElements) {
myListener.packagingMethodChanged(changedElement);
}
}
}
@Nullable
private PackagingMethod getSelectedMethod() {
return (PackagingMethod)myPackagingMethodBox.getSelectedItem();
}
@TestOnly
public JComboBox getPackagingMethodBox() {
return myPackagingMethodBox;
}
public static boolean isEnabled(PackagingElementsToEditInfo elementsToEdit) {
boolean showPackagingMethodBox = elementsToEdit.getAllowedPackagingMethods().length > 1 && elementsToEdit.getPackagingMethod() != null;
boolean showOutputPathField = elementsToEdit.getRelativePath() != null;
return showOutputPathField || showPackagingMethodBox;
}
@Nullable
public static PackagingElementPropertiesComponent createPropertiesComponent(PackagingElementsToEditInfo elementsToEdit,
PackagingEditorPolicy editorPolicy,
final PackagingEditorListener listener) {
if (!isEnabled(elementsToEdit)) return null;
return new PackagingElementPropertiesComponent(elementsToEdit, editorPolicy, listener);
}
public static boolean showDialog(final PackagingElementsToEditInfo elementsToEdit, JPanel component, PackagingEditorPolicy policy,
final PackagingEditorListener listener) {
PackagingElementPropertiesComponent propertiesComponent = createPropertiesComponent(elementsToEdit, policy, listener);
if (propertiesComponent == null) {
return false;
}
PackagingElementPropertiesDialog dialog = new PackagingElementPropertiesDialog(component, propertiesComponent);
dialog.show();
return dialog.isOK();
}
private class PackagingMethodListCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(final JList list,
Object value,
final int index,
final boolean isSelected,
final boolean cellHasFocus) {
ContainerElement element = myElementsInfo.getElements().get(0);
value = element.getDescriptionForPackagingMethod((PackagingMethod)value);
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
}
public static class PackagingElementPropertiesDialog extends DialogWrapper {
private final PackagingElementPropertiesComponent myPropertiesComponent;
public PackagingElementPropertiesDialog(JComponent parent, PackagingElementPropertiesComponent propertiesComponent) {
super(parent, false);
setTitle(ProjectBundle.message("dialog.title.packaging.edit.properties"));
myPropertiesComponent = propertiesComponent;
init();
}
protected JComponent createCenterPanel() {
return myPropertiesComponent.getMainPanel();
}
@Override
protected void doOKAction() {
myPropertiesComponent.applyChanges();
super.doOKAction();
}
}
}
@@ -1,155 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.PackagingMethod;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
class PackagingElementsToEditInfo {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.packaging.PackagingElementsToEditInfo");
private final List<ContainerElement> myElements;
private final PackagingMethod myPackagingMethod;
private final String myRelativePath;
private final PackagingMethod[] myAllowedPackagingMethods;
private final String myElementText;
private Map<ContainerElement, String> myPathTails;
public PackagingElementsToEditInfo(final ContainerElement element, @NotNull PackagingEditorPolicy policy) {
myElements = Collections.singletonList(element);
myRelativePath = policy.isRelativePathCellEditable(element) ? element.getURI() : null;
myPackagingMethod = element.getPackagingMethod();
myAllowedPackagingMethods = policy.getAllowedPackagingMethods(element);
myElementText = policy.getElementText(element);
}
public PackagingElementsToEditInfo(final Set<ContainerElement> elements, @NotNull PackagingEditorPolicy policy) {
LOG.assertTrue(elements.size() > 1);
myElements = new ArrayList<ContainerElement>(elements);
myPackagingMethod = getCommonPackagingMethod(elements);
String commonPath = getCommonRelativePath(elements, policy);
if (commonPath == null) {
final Map<ContainerElement, String> elementsToPaths = new HashMap<ContainerElement, String>();
for (ContainerElement element : elements) {
elementsToPaths.put(element, element.getURI());
}
Pair<String, Map<ContainerElement, String>> pair = getPrefixAndSuffixes(elementsToPaths, policy);
if (pair != null) {
commonPath = pair.getFirst();
myPathTails = pair.getSecond();
}
}
myRelativePath = commonPath;
myAllowedPackagingMethods = getAllowedPackagingMethods(elements, policy);
myElementText = ProjectBundle.message("element.description.0.items", elements.size());
}
public List<ContainerElement> getElements() {
return myElements;
}
@Nullable
public PackagingMethod getPackagingMethod() {
return myPackagingMethod;
}
@Nullable
public String getRelativePath() {
return myRelativePath;
}
@Nullable
public Map<ContainerElement, String> getPathTails() {
return myPathTails;
}
@NotNull
public PackagingMethod[] getAllowedPackagingMethods() {
return myAllowedPackagingMethods;
}
public String getElementText() {
return myElementText;
}
@NotNull
private static PackagingMethod[] getAllowedPackagingMethods(final Set<ContainerElement> elements, final PackagingEditorPolicy policy) {
List<PackagingMethod> methods = null;
for (ContainerElement element : elements) {
List<PackagingMethod> otherMethods = Arrays.asList(policy.getAllowedPackagingMethods(element));
if (methods == null) {
methods = new ArrayList<PackagingMethod>(otherMethods);
}
else {
methods.retainAll(otherMethods);
}
}
return methods != null ? methods.toArray(new PackagingMethod[methods.size()]) : PackagingMethod.EMPTY_ARRAY;
}
@Nullable
public static Pair<String, Map<ContainerElement, String>> getPrefixAndSuffixes(final Map<ContainerElement, String> elementsToPaths, final PackagingEditorPolicy policy) {
String prefix = null;
for (Map.Entry<ContainerElement,String> entry : elementsToPaths.entrySet()) {
if (!policy.isRelativePathCellEditable(entry.getKey())) {
return null;
}
String path = entry.getValue();
if (prefix == null) {
prefix = path;
}
else {
prefix = StringUtil.commonPrefix(prefix, path);
if (!path.equals(prefix) && !StringUtil.startsWithConcatenationOf(path, prefix, "/")) {
int i = prefix.lastIndexOf('/');
prefix = i != -1 ? prefix.substring(0, i) : "";
}
}
}
if (prefix == null) {
return null;
}
Map<ContainerElement, String> map = new HashMap<ContainerElement, String>();
for (Map.Entry<ContainerElement,String> entry : elementsToPaths.entrySet()) {
String path = entry.getValue();
map.put(entry.getKey(), path.substring(prefix.length()));
}
return Pair.create(prefix, map);
}
@Nullable
private static String getCommonRelativePath(final Set<ContainerElement> elements, final PackagingEditorPolicy policy) {
String path = null;
for (ContainerElement element : elements) {
if (!policy.isRelativePathCellEditable(element)) {
return null;
}
if (path == null) {
path = element.getURI();
}
else if (!path.equals(element.getURI())) {
return null;
}
}
return path;
}
@Nullable
private static PackagingMethod getCommonPackagingMethod(final Set<ContainerElement> elements) {
PackagingMethod method = null;
for (ContainerElement element : elements) {
if (method == null) {
method = element.getPackagingMethod();
}
else if (!method.equals(element.getPackagingMethod())) {
return null;
}
}
return method;
}
}
@@ -1,17 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
/**
* @author nik
*/
public class PackagingNodeWeights {
public static final double ARTIFACT = 0;
public static final double DIRECTORY = 1;
public static final double FILE = 2;
public static final double ARCHIVE = FILE;
public static final double MODULE = FILE;
public static final double LIBRARY = FILE;
private PackagingNodeWeights() {
}
}
@@ -1,132 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.deployment.PackagingMethod;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.NonNls;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author nik
*/
public abstract class PackagingTreeBuilder {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.packaging.PackagingTreeBuilder");
public abstract PackagingArtifact createRootArtifact();
@NotNull
public PackagingTreeParameters getDefaultParameters() {
return new PackagingTreeParameters(false, false);
}
public void updateParameters(final @NotNull PackagingTreeParameters treeParameters) {
}
@NotNull
public List<? extends PackagingTreeNode> createNodes(@NotNull PackagingArtifactNode artifactRoot, @NotNull ContainerElement element,
final PackagingArtifact owner, final PackagingTreeParameters parameters) {
if (element instanceof LibraryLink) {
return createLibraryNodes((LibraryLink)element, artifactRoot, owner, parameters);
}
if (element instanceof ModuleLink) {
return Collections.singletonList(createModuleNode((ModuleLink)element, artifactRoot, owner));
}
LOG.error("unknown element: " + element.getClass());
return Collections.emptyList();
}
@NotNull
private static List<PackagingTreeNode> createLibraryNodes(final LibraryLink libraryLink, final PackagingArtifactNode root, final PackagingArtifact owner,
final PackagingTreeParameters parameters) {
PackagingTreeNode parent = getOrCreateParentNode(libraryLink, root, owner);
if (parameters.isShowLibraryFiles()) {
Library library = libraryLink.getLibrary();
if (library != null) {
VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
List<PackagingTreeNode> nodes = new ArrayList<PackagingTreeNode>();
for (VirtualFile file : files) {
nodes.add(PackagingTreeNodeFactoryOld.createLibraryFileNode(file, library, libraryLink, parent, owner));
}
return nodes;
}
}
return Collections.singletonList(PackagingTreeNodeFactoryOld.createLibraryNode(libraryLink, parent, owner));
}
protected static PackagingTreeNode getOrCreateParentNode(final ContainerElement element, final PackagingArtifactNode root, final PackagingArtifact owner) {
PackagingMethod method = element.getPackagingMethod();
PackagingTreeNode parent;
String path = element.getURI();
if (path == null) {
LOG.error("path==null for " + element + ", method = " + element.getPackagingMethod());
}
path = fixPath(element, method, path);
if (method == PackagingMethod.JAR_AND_COPY_FILE) {
parent = PackagingTreeNodeFactoryOld.getOrCreateArchiveNode(path, root, owner);
}
else if (method == PackagingMethod.JAR_AND_COPY_FILE_AND_LINK_VIA_MANIFEST) {
parent = PackagingTreeNodeFactoryOld.getOrCreateArchiveNode(path, root.getParent(), owner);
}
else if (method == PackagingMethod.COPY_FILES_AND_LINK_VIA_MANIFEST) {
parent = PackagingTreeNodeFactoryOld.getOrCreateDirectoryNode(path, root.getParent(), owner);
}
else {
parent = PackagingTreeNodeFactoryOld.getOrCreateDirectoryNode(path, root, owner);
}
return parent;
}
private static String fixPath(final ContainerElement element, final PackagingMethod method, final String path) {
if (element instanceof LibraryLink) {
final LibraryLink libraryLink = (LibraryLink)element;
@NonNls String jarSuffix = ".jar";
if ((method == PackagingMethod.COPY_FILES_AND_LINK_VIA_MANIFEST || method == PackagingMethod.COPY_FILES)
&& libraryLink.getUrls().size() == 1 && LibraryLink.MODULE_LEVEL.equals(libraryLink.getLevel()) && path.endsWith(jarSuffix)) {
int index = path.lastIndexOf('/');
if (index >= 0) {
return path.substring(0, index);
}
else {
return "";
}
}
}
return path;
}
@NotNull
private static PackagingTreeNode createModuleNode(ModuleLink moduleLink, PackagingArtifactNode root, final PackagingArtifact owner) {
PackagingMethod method = moduleLink.getPackagingMethod();
if (method == PackagingMethod.JAR_AND_COPY_FILE_AND_LINK_VIA_MANIFEST || method == PackagingMethod.JAR_AND_COPY_FILE) {
String path = moduleLink.getURI();
int i = path.lastIndexOf('/');
String jarName = path.substring(i+1);
PackagingTreeNode parent = root;
if (i != -1) {
String parentPath = path.substring(0, i);
if (method == PackagingMethod.JAR_AND_COPY_FILE) {
parent = PackagingTreeNodeFactoryOld.getOrCreateDirectoryNode(parentPath, root, owner);
}
else {
parent = PackagingTreeNodeFactoryOld.getOrCreateDirectoryNode(parentPath, root.getParent(), owner);
}
}
return PackagingTreeNodeFactoryOld.createPackedModuleOutputNode(moduleLink, jarName, parent, owner);
}
PackagingTreeNode parent = getOrCreateParentNode(moduleLink, root, owner);
return PackagingTreeNodeFactoryOld.createModuleOutputNode(moduleLink, parent, owner);
}
}
@@ -1,97 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.ArrayList;
import java.util.List;
/**
* @author nik
*/
public abstract class PackagingTreeNode extends DefaultMutableTreeNode implements Comparable<PackagingTreeNode> {
private final PackagingArtifact myOwner;
protected PackagingTreeNode(final @Nullable PackagingArtifact owner) {
myOwner = owner;
}
@NotNull
public abstract String getOutputFileName();
public abstract double getWeight();
public String getSearchName() {
return getOutputFileName();
}
public abstract void render(@NotNull ColoredTreeCellRenderer renderer);
public abstract boolean canNavigate();
public abstract void navigate(ModuleStructureConfigurable configurable);
@Nullable
public abstract Object getSourceObject();
@Nullable
public String getTooltipText() {
return null;
}
public int compareTo(final PackagingTreeNode node) {
return getOutputFileName().compareToIgnoreCase(node.getOutputFileName());
}
@Nullable
public PackagingArtifact getOwner() {
return myOwner;
}
@Nullable
public ContainerElement getContainerElement() {
return null;
}
@Nullable
public PackagingTreeNode findChildByName(final @NotNull String outputFileName) {
for (int i = 0; i < getChildCount(); i++) {
PackagingTreeNode node = (PackagingTreeNode)getChildAt(i);
if (node.getOutputFileName().equals(outputFileName)) {
return node;
}
}
return null;
}
@Override
public PackagingTreeNode getParent() {
return (PackagingTreeNode)super.getParent();
}
@NotNull
public List<PackagingTreeNode> getChildren() {
List<PackagingTreeNode> children = new ArrayList<PackagingTreeNode>(getChildCount());
for (int i = 0; i < getChildCount(); i++) {
children.add((PackagingTreeNode)getChildAt(i));
}
return children;
}
protected SimpleTextAttributes getMainAttributes() {
return !belongsToIncludedArtifact() ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES;
}
protected SimpleTextAttributes getCommentAttributes() {
return !belongsToIncludedArtifact() ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES;
}
protected boolean belongsToIncludedArtifact() {
return myOwner != null;
}
}
@@ -1,104 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.StringTokenizer;
/**
* @author nik
*/
public class PackagingTreeNodeFactoryOld {
private PackagingTreeNodeFactoryOld() {
}
@NotNull
public static PackagingTreeNode getOrCreateDirectoryNode(@NotNull String path, @NotNull PackagingTreeNode root, PackagingArtifact owner) {
StringTokenizer tokenizer = new StringTokenizer(path, "/");
PackagingTreeNode current = root;
while (tokenizer.hasMoreTokens()) {
String name = tokenizer.nextToken();
if (name.length() == 0 || name.equals(".")) continue;
PackagingTreeNode child = current.findChildByName(name);
if (child == null) {
child = new DirectoryNode(name, owner);
current.add(child);
}
current = child;
}
return current;
}
@NotNull
public static PackagingTreeNode getOrCreateArchiveNode(@NotNull String path, @NotNull PackagingTreeNode root, PackagingArtifact owner) {
int i = path.lastIndexOf('/');
String archiveName = path.substring(i+1);
PackagingTreeNode parent = i != -1 ? getOrCreateDirectoryNode(path.substring(0, i), root, owner) : root;
PackagingTreeNode child = parent.findChildByName(archiveName);
if (child == null) {
child = new ArchiveNode(archiveName, owner);
parent.add(child);
}
return child;
}
@NotNull
public static PackagingTreeNode createLibraryNode(@NotNull LibraryLink libraryLink, @NotNull PackagingTreeNode parent, final PackagingArtifact owner) {
for (PackagingTreeNode child : parent.getChildren()) {
if (child instanceof LibraryNode && ((LibraryNode)child).getLibraryLink().equals(libraryLink)) {
return child;
}
}
LibraryNode node = new LibraryNode(libraryLink, owner);
parent.add(node);
return node;
}
@NotNull
public static PackagingTreeNode createPackedModuleOutputNode(@NotNull ModuleLink moduleLink, String jarName, @NotNull PackagingTreeNode parent, final PackagingArtifact owner) {
for (PackagingTreeNode child : parent.getChildren()) {
if (child instanceof PackedModuleOutputNode && ((PackedModuleOutputNode)child).getModuleLink().equals(moduleLink)) {
return child;
}
}
PackedModuleOutputNode node = new PackedModuleOutputNode(moduleLink, jarName, owner);
parent.add(node);
return node;
}
@NotNull
public static PackagingTreeNode createModuleOutputNode(@NotNull ModuleLink moduleLink, @NotNull PackagingTreeNode parent, final PackagingArtifact owner) {
for (PackagingTreeNode child : parent.getChildren()) {
if (child instanceof ModuleOutputNode && ((ModuleOutputNode)child).getModuleLink().equals(moduleLink)) {
return child;
}
}
ModuleOutputNode node = new ModuleOutputNode(moduleLink, owner);
parent.add(node);
return node;
}
public static PackagingArtifactNode createArtifactNode(@NotNull PackagingArtifact artifact, @NotNull PackagingTreeNode parent,
PackagingArtifact owner) {
PackagingArtifactNode node = new PackagingArtifactNode(artifact, owner);
parent.add(node);
return node;
}
public static PackagingTreeNode createLibraryFileNode(@NotNull VirtualFile file, @NotNull Library library, @NotNull LibraryLink libraryLink,
@NotNull PackagingTreeNode parent, @Nullable PackagingArtifact owner) {
for (PackagingTreeNode child : parent.getChildren()) {
if (child instanceof LibraryFileNode && ((LibraryFileNode)child).getFile().equals(file)) {
return child;
}
}
LibraryFileNode node = new LibraryFileNode(file, library, libraryLink, owner);
parent.add(node);
return node;
}
}
@@ -1,39 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
/**
* @author nik
*/
@Tag("packaging-tree")
public class PackagingTreeParameters {
private boolean myShowIncludedContent;
private boolean myShowLibraryFiles;
public PackagingTreeParameters() {
}
public PackagingTreeParameters(final boolean showIncludedContent, final boolean showLibraryFiles) {
myShowIncludedContent = showIncludedContent;
myShowLibraryFiles = showLibraryFiles;
}
@Attribute("show-included-content")
public boolean isShowIncludedContent() {
return myShowIncludedContent;
}
@Attribute("show-library-files")
public boolean isShowLibraryFiles() {
return myShowLibraryFiles;
}
public void setShowIncludedContent(final boolean showIncludedContent) {
myShowIncludedContent = showIncludedContent;
}
public void setShowLibraryFiles(final boolean showLibraryFiles) {
myShowLibraryFiles = showLibraryFiles;
}
}
@@ -1,117 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.tree.TreePath;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
/**
* @author nik
*/
public class PackagingTreeState {
private final PackagingNodeState myRootState;
private final List<String[]> mySelectedPaths;
private PackagingTreeState(Tree tree) {
myRootState = saveState(tree, (PackagingTreeNode)tree.getModel().getRoot());
mySelectedPaths = new ArrayList<String[]>();
TreePath[] treePaths = tree.getSelectionPaths();
if (treePaths != null) {
for (TreePath path : treePaths) {
Object[] pathElements = path.getPath();
String[] names = ArrayUtil.newStringArray(pathElements.length);
for (int i = 0; i < pathElements.length; i++) {
names[i] = ((PackagingTreeNode)pathElements[i]).getOutputFileName();
}
mySelectedPaths.add(names);
}
}
}
public static PackagingTreeState saveState(Tree tree) {
return new PackagingTreeState(tree);
}
public void restoreState(Tree tree) {
if (myRootState != null) {
expandNodes(tree, (PackagingTreeNode)tree.getModel().getRoot(), myRootState);
}
List<TreePath> paths = new ArrayList<TreePath>();
for (String[] selectedPath : mySelectedPaths) {
PackagingTreeNode node = (PackagingTreeNode)tree.getModel().getRoot();
TreePath path = new TreePath(node);
for (int i = 1; i < selectedPath.length; i++) {
node = node.findChildByName(selectedPath[i]);
if (node == null) break;
path = path.pathByAddingChild(node);
}
if (path.getPathCount() > 1) {
paths.add(path);
}
}
tree.setSelectionPaths(paths.toArray(new TreePath[paths.size()]));
}
private static void expandNodes(final Tree tree, final PackagingTreeNode node, final PackagingNodeState nodeState) {
TreePath path = new TreePath(node.getPath());
if (!tree.isExpanded(path)) {
tree.expandPath(path);
}
for (PackagingTreeNode child : node.getChildren()) {
PackagingNodeState childState = nodeState.findChild(child.getOutputFileName());
if (childState != null) {
expandNodes(tree, child, childState);
}
}
}
@Nullable
private static PackagingNodeState saveState(final Tree tree, final PackagingTreeNode node) {
if (tree.isExpanded(new TreePath(node.getPath()))) {
List<PackagingTreeNode> children = node.getChildren();
if (!children.isEmpty()) {
PackagingNodeState nodeState = new PackagingNodeState(node.getOutputFileName());
for (PackagingTreeNode child : children) {
PackagingNodeState childState = saveState(tree, child);
if (childState != null) {
nodeState.addChild(childState);
}
}
return nodeState;
}
}
return null;
}
private static class PackagingNodeState {
private final String myName;
private Map<String, PackagingNodeState> myChildren;
private PackagingNodeState(final String name) {
myName = name;
}
public void addChild(@NotNull PackagingNodeState childState) {
if (myChildren == null) {
myChildren = new HashMap<String, PackagingNodeState>();
}
myChildren.put(childState.myName, childState);
}
public boolean isExpanded() {
return myChildren != null && !myChildren.isEmpty();
}
@Nullable
private PackagingNodeState findChild(String name) {
return myChildren != null ? myChildren.get(name) : null;
}
}
}
@@ -1,46 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ModuleLink;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author nik
*/
class PackedModuleOutputNode extends ModuleOutputBaseNode {
private static final Icon MODULE_JAR_ICON = IconLoader.getIcon("/nodes/moduleJar.png");
private final String myJarFileName;
PackedModuleOutputNode(@NotNull ModuleLink moduleLink, String jarFileName, PackagingArtifact owner) {
super(owner, moduleLink);
myJarFileName = jarFileName;
}
@NotNull
public String getOutputFileName() {
return myJarFileName;
}
public void render(@NotNull final ColoredTreeCellRenderer renderer) {
Module module = myModuleLink.getModule();
renderer.setIcon(MODULE_JAR_ICON);
if (module != null) {
renderer.append(myJarFileName, getMainAttributes());
renderer.append(getComment(module.getName()), getCommentAttributes());
}
else {
renderer.append(myJarFileName, SimpleTextAttributes.ERROR_ATTRIBUTES);
renderer.append(getComment(myModuleLink.getName()), getCommentAttributes());
}
}
private static String getComment(final String name) {
return " " + ProjectBundle.message("node.text.packed.0.compile.output", name);
}
}
@@ -1,139 +0,0 @@
package com.intellij.openapi.roots.ui.configuration.packaging;
import com.intellij.openapi.deployment.ContainerElement;
import com.intellij.openapi.deployment.LibraryLink;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.BidirectionalMap;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* @author nik
*/
class SelectedPackagingElements {
private final List<ContainerElement> myContainerElements = new ArrayList<ContainerElement>();
private final Set<PackagingArtifact> myOwners = new HashSet<PackagingArtifact>();
private final Collection<LibraryLink> myParentLibraryLinks;
public SelectedPackagingElements(final PackagingTreeNode[] treeNodes) {
BidirectionalMap<VirtualFile, LibraryLink> selectedFiles = new BidirectionalMap<VirtualFile, LibraryLink>();
Set<LibraryLink> fullySelectedLibraries = new HashSet<LibraryLink>();
for (PackagingTreeNode treeNode : treeNodes) {
ContainerElement containerElement = treeNode.getContainerElement();
if (containerElement == null) continue;
if (treeNode instanceof LibraryFileNode) {
LibraryFileNode node = (LibraryFileNode)treeNode;
selectedFiles.put(node.getFile(), node.getLibraryLink());
}
else if (containerElement instanceof LibraryLink) {
fullySelectedLibraries.add((LibraryLink)containerElement);
}
PackagingArtifact owner = treeNode.getOwner();
if (owner != null && owner.getContainerElement() != null) {
myOwners.add(owner);
}
else {
myContainerElements.add(containerElement);
}
}
for (LibraryLink libraryLink : selectedFiles.values()) {
Library library = libraryLink.getLibrary();
if (library != null) {
VirtualFile[] roots = library.getFiles(OrderRootType.CLASSES);
List<VirtualFile> files = selectedFiles.getKeysByValue(libraryLink);
if (Comparing.haveEqualElements(files, Arrays.asList(roots))) {
fullySelectedLibraries.add(libraryLink);
}
}
}
for (LibraryLink libraryLink : fullySelectedLibraries) {
selectedFiles.removeValue(libraryLink);
}
myParentLibraryLinks = selectedFiles.values();
ContainerUtil.removeDuplicates(myContainerElements);
}
public Collection<LibraryLink> getParentLibraryLinks() {
return myParentLibraryLinks;
}
public List<ContainerElement> getContainerElements() {
return myContainerElements;
}
public Set<PackagingArtifact> getOwners() {
return myOwners;
}
public boolean showRemovingWarning(final PackagingEditorImpl editor) {
Set<PackagingArtifact> owners = getOwners();
Collection<LibraryLink> parentLibraryLinks = getParentLibraryLinks();
if (!parentLibraryLinks.isEmpty()) {
StringBuilder librariesNames = new StringBuilder();
for (LibraryLink link : parentLibraryLinks) {
if (librariesNames.length() > 0) librariesNames.append(", ");
librariesNames.append('\'').append(link.getPresentableName()).append('\'');
}
String message = ProjectBundle.message("message.text.individial.files.cannot.be.removed.from.packaging.do.you.want.to.remove.the.whole.libraries",
librariesNames.toString(), parentLibraryLinks.size());
int answer = Messages.showYesNoDialog(editor.getMainPanel(), message, ProjectBundle.message("dialog.title.packaging.remove.included"), null);
if (answer != 0) {
return false;
}
}
if (!owners.isEmpty()) {
String message;
if (owners.size() == 1 && getContainerElements().isEmpty()) {
PackagingArtifact artifact = owners.iterator().next();
message = ProjectBundle.message("message.text.packaging.selected.item.belongs.to.0.do.you.want.to.exlude.1.from.2",
artifact.getDisplayName(), artifact.getDisplayName(), editor.getRootArtifact().getDisplayName());
}
else {
StringBuilder ownersBuffer = new StringBuilder();
for (PackagingArtifact owner : owners) {
if (ownersBuffer.length() > 0) {
ownersBuffer.append(", ");
}
ownersBuffer.append(owner.getDisplayName());
}
message = ProjectBundle.message("message.text.packaging.do.you.want.to.exlude.0.from.1", ownersBuffer, editor.getRootArtifact().getDisplayName());
}
int answer = Messages.showYesNoDialog(editor.getMainPanel(), message, ProjectBundle.message("dialog.title.packaging.remove.included"), null);
if (answer != 0) {
return false;
}
}
return true;
}
@Nullable
public PackagingElementsToEditInfo getElementsToEdit(final PackagingEditorPolicy policy) {
Set<ContainerElement> elements = new HashSet<ContainerElement>(myContainerElements);
for (PackagingArtifact owner : myOwners) {
ContainerElement element = owner.getContainerElement();
if (element != null) {
elements.add(element);
}
}
if (elements.isEmpty()) {
return null;
}
if (elements.size() == 1) {
return new PackagingElementsToEditInfo(elements.iterator().next(), policy);
}
return new PackagingElementsToEditInfo(elements, policy);
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 727 B

After

Width:  |  Height:  |  Size: 727 B

@@ -35,4 +35,7 @@ public interface ConversionContext {
@Nullable
ComponentManagerSettings getCompilerSettings();
@Nullable
ComponentManagerSettings getProjectRootManagerSettings();
}
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.List;
/**
* @author nik
@@ -31,4 +32,11 @@ public interface ModuleSettings extends ComponentManagerSettings {
@NotNull
Collection<File> getSourceRoots(boolean includeTests);
@NotNull
Collection<File> getContentRoots();
void addExcludedFolder(@NotNull File directory);
List<File> getModuleLibraryRootUrls(String libraryName);
}
@@ -46,6 +46,7 @@ public class ConversionContextImpl implements ConversionContext {
private RunManagerSettingsImpl myRunManagerSettings;
private File mySettingsBaseDir;
private ComponentManagerSettings myCompilerManagerSettings;
private ComponentManagerSettings myProjectRootManagerSettings;
public ConversionContextImpl(String projectPath) throws CannotConvertException {
myProjectFile = new File(projectPath);
@@ -68,6 +69,32 @@ public class ConversionContextImpl implements ConversionContext {
myModuleFiles = findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement());
}
public Set<File> getAllProjectFiles() {
final HashSet<File> files = new HashSet<File>(Arrays.asList(myModuleFiles));
if (myStorageScheme == StorageScheme.DEFAULT) {
files.add(myProjectFile);
files.add(myWorkspaceFile);
}
else {
addFilesRecursively(mySettingsBaseDir, files);
}
return files;
}
private static void addFilesRecursively(File file, Set<File> files) {
if (file.isDirectory()) {
final File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
addFilesRecursively(child, files);
}
}
}
else if (StringUtil.endsWithIgnoreCase(file.getName(), ".xml") && !file.getName().startsWith(".")) {
files.add(file);
}
}
@NotNull
public File getProjectBaseDir() {
return myProjectBaseDir;
@@ -97,21 +124,36 @@ public class ConversionContextImpl implements ConversionContext {
@NotNull
public String expandPath(@NotNull String path, @NotNull ModuleSettingsImpl moduleSettings) {
return createExpandMacroMap(moduleSettings).substitute(path, true, null);
}
private ExpandMacroToPathMap createExpandMacroMap(@Nullable ModuleSettingsImpl moduleSettings) {
final ExpandMacroToPathMap map = createExpandMacroMap();
final String modulePath = FileUtil.toSystemIndependentName(moduleSettings.getModuleFile().getParentFile().getAbsolutePath());
map.addMacroExpand(PathMacrosImpl.MODULE_DIR_MACRO_NAME, modulePath);
return map.substitute(path, true, null);
if (moduleSettings != null) {
final String modulePath = FileUtil.toSystemIndependentName(moduleSettings.getModuleFile().getParentFile().getAbsolutePath());
map.addMacroExpand(PathMacrosImpl.MODULE_DIR_MACRO_NAME, modulePath);
}
return map;
}
@NotNull
public String collapsePath(@NotNull String path) {
ReplacePathToMacroMap map = new ReplacePathToMacroMap();
final String projectDir = FileUtil.toSystemIndependentName(myProjectBaseDir.getAbsolutePath());
map.addMacroReplacement(projectDir, PathMacrosImpl.PROJECT_DIR_MACRO_NAME);
PathMacrosImpl.getInstanceEx().addMacroReplacements(map);
ReplacePathToMacroMap map = createCollapseMacroMap(PathMacrosImpl.PROJECT_DIR_MACRO_NAME, myProjectBaseDir);
return map.substitute(path, SystemInfo.isFileSystemCaseSensitive, null);
}
public String collapsePath(@NotNull String path, @NotNull ModuleSettingsImpl moduleSettings) {
final ReplacePathToMacroMap map = createCollapseMacroMap(PathMacrosImpl.MODULE_DIR_MACRO_NAME, moduleSettings.getModuleFile().getParentFile());
return map.substitute(path, SystemInfo.isFileSystemCaseSensitive, null);
}
private static ReplacePathToMacroMap createCollapseMacroMap(final String macroName, final File dir) {
ReplacePathToMacroMap map = new ReplacePathToMacroMap();
map.addMacroReplacement(FileUtil.toSystemIndependentName(dir.getAbsolutePath()), macroName);
PathMacrosImpl.getInstanceEx().addMacroReplacements(map);
return map;
}
public Collection<File> getLibraryClassRoots(@NotNull String name, @NotNull String level) {
try {
Element libraryElement = null;
@@ -123,19 +165,7 @@ public class ConversionContextImpl implements ConversionContext {
}
if (libraryElement != null) {
//todo[nik] support jar directories
final Element classesChild = libraryElement.getChild("CLASSES");
if (classesChild != null) {
final List<Element> roots = JDomConvertingUtil.getChildren(classesChild, "root");
List<File> files = new ArrayList<File>();
final ExpandMacroToPathMap pathMap = createExpandMacroMap();
for (Element root : roots) {
final String url = root.getAttributeValue("url");
final String path = VfsUtil.urlToPath(url);
files.add(new File(PathUtil.getLocalPath(pathMap.substitute(path, true, null))));
}
return files;
}
return getClassRoots(libraryElement, null);
}
return Collections.emptyList();
@@ -145,26 +175,54 @@ public class ConversionContextImpl implements ConversionContext {
}
}
public ComponentManagerSettings getCompilerSettings() {
if (myCompilerManagerSettings == null) {
try {
File file;
if (myStorageScheme == StorageScheme.DEFAULT) {
file = myProjectFile;
}
else {
file = new File(mySettingsBaseDir, "compiler.xml");
}
myCompilerManagerSettings = new ComponentManagerSettingsImpl(file, this);
}
catch (CannotConvertException e) {
LOG.info(e);
return null;
public List<File> getClassRoots(Element libraryElement, ModuleSettingsImpl moduleSettings) {
List<File> files = new ArrayList<File>();
//todo[nik] support jar directories
final Element classesChild = libraryElement.getChild("CLASSES");
if (classesChild != null) {
final List<Element> roots = JDomConvertingUtil.getChildren(classesChild, "root");
final ExpandMacroToPathMap pathMap = createExpandMacroMap(moduleSettings);
for (Element root : roots) {
final String url = root.getAttributeValue("url");
final String path = VfsUtil.urlToPath(url);
files.add(new File(PathUtil.getLocalPath(pathMap.substitute(path, true, null))));
}
}
return files;
}
public ComponentManagerSettings getCompilerSettings() {
if (myCompilerManagerSettings == null) {
myCompilerManagerSettings = createProjectSettings("compiler.xml");
}
return myCompilerManagerSettings;
}
public ComponentManagerSettings getProjectRootManagerSettings() {
if (myProjectRootManagerSettings == null) {
myProjectRootManagerSettings = createProjectSettings("misc.xml");
}
return myProjectRootManagerSettings;
}
@Nullable
private ComponentManagerSettingsImpl createProjectSettings(final String fileName) {
try {
File file;
if (myStorageScheme == StorageScheme.DEFAULT) {
file = myProjectFile;
}
else {
file = new File(mySettingsBaseDir, fileName);
}
return new ComponentManagerSettingsImpl(file, this);
}
catch (CannotConvertException e) {
LOG.info(e);
return null;
}
}
@Nullable
private Element findGlobalLibraryElement(String name) throws CannotConvertException {
final File file = PathManager.getOptionsFile("applicationLibraries");
@@ -22,6 +22,7 @@ import com.intellij.util.graph.DFSTBuilder;
import com.intellij.util.graph.GraphGenerator;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.MapAnnotation;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Document;
import org.jetbrains.annotations.NotNull;
@@ -153,7 +154,43 @@ public class ConversionServiceImpl extends ConversionService {
private List<ConversionRunner> getSortedConverters(final ConversionContextImpl context) throws CannotConvertException {
final CachedConversionResult conversionResult = loadCachedConversionResult(context.getProjectFile());
return createConversionRunners(context, conversionResult.myAppliedConverters);
final Map<String, Long> oldMap = conversionResult.myProjectFilesTimestamps;
Map<String, Long> newMap = getProjectFilesMap(context);
boolean changed = false;
LOG.debug("Checking project files");
for (Map.Entry<String, Long> entry : newMap.entrySet()) {
final String path = entry.getKey();
final Long oldValue = oldMap.get(path);
if (oldValue == null) {
LOG.debug(" new file: " + path);
changed = true;
}
else if (!entry.getValue().equals(oldValue)) {
LOG.debug(" changed file: " + path);
changed = true;
}
}
final Set<String> performedConversionIds;
if (changed) {
performedConversionIds = Collections.emptySet();
LOG.debug("Project files were modified.");
}
else {
performedConversionIds = conversionResult.myAppliedConverters;
LOG.debug("Project files are up to date. Applied converters: " + performedConversionIds);
}
return createConversionRunners(context, performedConversionIds);
}
private static Map<String, Long> getProjectFilesMap(ConversionContextImpl context) {
final Map<String, Long> map = new HashMap<String, Long>();
for (File file : context.getAllProjectFiles()) {
if (file.exists()) {
map.put(file.getAbsolutePath(), file.lastModified());
}
}
return map;
}
private List<ConversionRunner> createConversionRunners(ConversionContextImpl context, final Set<String> performedConversionIds) {
@@ -179,14 +216,21 @@ public class ConversionServiceImpl extends ConversionService {
return runners;
}
public void saveConversionResult(String projectPath) {
try {
saveConversionResult(new ConversionContextImpl(projectPath));
}
catch (CannotConvertException e) {
LOG.info(e);
}
}
private void saveConversionResult(ConversionContextImpl context) {
final CachedConversionResult conversionResult = loadCachedConversionResult(context.getProjectFile());
final CachedConversionResult conversionResult = new CachedConversionResult();
for (ConverterProvider provider : ConverterProvider.EP_NAME.getExtensions()) {
conversionResult.myAppliedConverters.add(provider.getId());
}
for (File file : context.getNonExistingModuleFiles()) {
conversionResult.myNotConvertedModules.add(file.getAbsolutePath());
}
conversionResult.myProjectFilesTimestamps = getProjectFilesMap(context);
final File infoFile = getConversionInfoFile(context.getProjectFile());
infoFile.getParentFile().mkdirs();
try {
@@ -280,13 +324,13 @@ public class ConversionServiceImpl extends ConversionService {
@Tag("conversion")
public static class CachedConversionResult {
@Tag("applied-converters")
@AbstractCollection(surroundWithTag = false, elementTag = "converter", elementValueAttribute = "id")
@Tag("applied-converters") @AbstractCollection(surroundWithTag = false, elementTag = "converter", elementValueAttribute = "id")
public Set<String> myAppliedConverters = new HashSet<String>();
@Tag("not-converted-modules")
@AbstractCollection(surroundWithTag = false, elementTag = "module", elementValueAttribute = "path")
public Set<String> myNotConvertedModules = new HashSet<String>();
@Tag("project-files")
@MapAnnotation(surroundWithTag = false, surroundKeyWithTag = false, surroundValueWithTag = false, entryTagName = "file",
keyAttributeName = "path", valueAttributeName = "timestamp")
public Map<String, Long> myProjectFilesTimestamps = new HashMap<String, Long>();
}
private class ConverterProvidersGraph implements GraphGenerator.SemiGraph<ConverterProvider> {
@@ -1,23 +1,28 @@
package com.intellij.conversion.impl;
import com.intellij.conversion.CannotConvertException;
import com.intellij.conversion.ComponentManagerSettings;
import com.intellij.conversion.ModuleSettings;
import com.intellij.facet.FacetManagerImpl;
import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.ide.impl.convert.JDomConvertingUtil;
import com.intellij.openapi.module.impl.ModuleImpl;
import com.intellij.openapi.roots.impl.*;
import com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl;
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.roots.impl.ContentEntryImpl;
import com.intellij.openapi.roots.impl.SourceFolderImpl;
import com.intellij.openapi.vfs.VfsUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
@@ -25,6 +30,7 @@ import java.util.List;
*/
public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements ModuleSettings {
private String myModuleName;
@NonNls private static final String MODULE_ROOT_MANAGER_COMPONENT = "NewModuleRootManager";
public ModuleSettingsImpl(File moduleFile, ConversionContextImpl context) throws CannotConvertException {
super(moduleFile, context);
@@ -69,17 +75,90 @@ public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements
@NotNull
public Collection<File> getSourceRoots(boolean includeTests) {
final Element rootManager = getComponentElement("NewModuleRootManager");
final List<File> result = new ArrayList<File>();
for (Element contentRoot : JDomConvertingUtil.getChildren(rootManager, ContentEntryImpl.ELEMENT_NAME)) {
for (Element contentRoot : getContentRootElements()) {
for (Element sourceFolder : JDomConvertingUtil.getChildren(contentRoot, SourceFolderImpl.ELEMENT_NAME)) {
boolean isTestFolder = Boolean.parseBoolean(sourceFolder.getAttributeValue(SourceFolderImpl.TEST_SOURCE_ATTR));
if (includeTests || !isTestFolder) {
final String path = VfsUtil.urlToPath(sourceFolder.getAttributeValue(SourceFolderImpl.URL_ATTR));
result.add(new File(FileUtil.toSystemDependentName(expandPath(path))));
result.add(getFile(sourceFolder.getAttributeValue(SourceFolderImpl.URL_ATTRIBUTE)));
}
}
}
return result;
}
private List<Element> getContentRootElements() {
return JDomConvertingUtil.getChildren(getComponentElement(MODULE_ROOT_MANAGER_COMPONENT), ContentEntryImpl.ELEMENT_NAME);
}
@NotNull
public Collection<File> getContentRoots() {
final List<File> result = new ArrayList<File>();
for (Element contentRoot : getContentRootElements()) {
String path = VfsUtil.urlToPath(contentRoot.getAttributeValue(ContentEntryImpl.URL_ATTRIBUTE));
result.add(new File(FileUtil.toSystemDependentName(expandPath(path))));
}
return result;
}
public void addExcludedFolder(@NotNull File directory) {
final ComponentManagerSettings rootManagerSettings = myContext.getProjectRootManagerSettings();
if (rootManagerSettings != null) {
final Element projectRootManager = rootManagerSettings.getComponentElement("ProjectRootManager");
if (projectRootManager != null) {
final Element outputElement = projectRootManager.getChild("output");
if (outputElement != null) {
final String outputUrl = outputElement.getAttributeValue("url");
if (outputUrl != null) {
final File outputFile = getFile(outputUrl);
try {
if (FileUtil.isAncestor(outputFile, directory, false)) {
return;
}
}
catch (IOException ignored) {
}
}
}
}
}
for (Element contentRoot : getContentRootElements()) {
final File root = getFile(contentRoot.getAttributeValue(ContentEntryImpl.URL_ATTRIBUTE));
try {
if (FileUtil.isAncestor(root, directory, true)) {
addExcludedFolder(directory, contentRoot);
}
}
catch (IOException ignored) {
}
}
}
public List<File> getModuleLibraryRootUrls(String libraryName) {
final Element component = getComponentElement(MODULE_ROOT_MANAGER_COMPONENT);
for (Element element : JDomConvertingUtil.getChildren(component, OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME)) {
if (ModuleLibraryOrderEntryImpl.ENTRY_TYPE.equals(element.getAttributeValue(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR))) {
final Element library = element.getChild(LibraryImpl.ELEMENT);
if (library != null && libraryName.equals(library.getAttributeValue(LibraryImpl.LIBRARY_NAME_ATTR))) {
return myContext.getClassRoots(library, this);
}
}
}
return Collections.emptyList();
}
private void addExcludedFolder(File directory, Element contentRoot) throws IOException {
for (Element excludedFolder : JDomConvertingUtil.getChildren(contentRoot, ExcludeFolderImpl.ELEMENT_NAME)) {
final File excludedDir = getFile(excludedFolder.getAttributeValue(ExcludeFolderImpl.URL_ATTRIBUTE));
if (FileUtil.isAncestor(excludedDir, directory, false)) {
return;
}
}
String path = myContext.collapsePath(FileUtil.toSystemIndependentName(directory.getAbsolutePath()), this);
contentRoot.addContent(new Element(ExcludeFolderImpl.ELEMENT_NAME).setAttribute(ExcludeFolderImpl.URL_ATTRIBUTE, VfsUtil.pathToUrl(path)));
}
private File getFile(String url) {
return new File(FileUtil.toSystemDependentName(expandPath(VfsUtil.urlToPath(url))));
}
}
@@ -3,7 +3,7 @@
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="154" height="400"/>
<xy x="20" y="20" width="354" height="400"/>
</constraints>
<properties/>
<border type="none"/>
@@ -16,7 +16,7 @@
<component id="f024" class="javax.swing.JTextPane" binding="myTextPane">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
<preferred-size width="350" height="-1"/>
</grid>
</constraints>
<properties/>
@@ -122,7 +122,7 @@ public class ConvertProjectDialog extends DialogWrapper {
}
}
private String getFilesString(List<File> files) {
private static String getFilesString(List<File> files) {
StringBuilder buffer = new StringBuilder();
for (File file : files) {
buffer.append(file.getAbsolutePath()).append("<br>");
@@ -34,7 +34,6 @@ public class ProjectFacetManagerImpl extends ProjectFacetManagerEx implements Pe
@NonNls public static final String COMPONENT_NAME = "ProjectFacetManager";
private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.ProjectFacetManagerImpl");
private ProjectFacetManagerState myState = new ProjectFacetManagerState();
private final List<Runnable> myRunnablesToRunOnProjectSettingsClosed = new ArrayList<Runnable>();
private Project myProject;
public ProjectFacetManagerImpl(Project project) {
@@ -94,17 +93,6 @@ public class ProjectFacetManagerImpl extends ProjectFacetManagerEx implements Pe
}
}
//todo[nik] remove
public void registerRunnableToRunOnProjectSettingsClosed(@NotNull Runnable runnable) {
myRunnablesToRunOnProjectSettingsClosed.add(runnable);
}
public void fireRunnableOnProjectSettingsClosed() {
for (Runnable runnable : myRunnablesToRunOnProjectSettingsClosed) {
runnable.run();
}
}
@Tag("default-facet-configuration")
public static class DefaultFacetConfigurationState {
private Element myDefaultConfiguration;
@@ -42,7 +42,7 @@ public class JDomConvertingUtil {
throw new CannotConvertException(file.getAbsolutePath() + ": " + e.getMessage(), e);
}
catch (IOException e) {
throw new CannotConvertException(e.getMessage(), e);
throw new CannotConvertException(file.getAbsolutePath() + ": " + e.getMessage(), e);
}
}
@@ -9,7 +9,6 @@ import com.intellij.openapi.project.Project;
/**
* @author nik
*/
@Deprecated
public abstract class ProjectFileVersion {
public static ProjectFileVersion getInstance(Project project) {
return project.getComponent(ProjectFileVersion.class);
@@ -4,19 +4,21 @@
package com.intellij.ide.impl.convert;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.conversion.ConversionService;
import com.intellij.conversion.impl.ConversionServiceImpl;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.impl.stores.IProjectStore;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectEx;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*
* DO NOT CONVERT THIS COMPONENT TO SERVICE. ITS CONFIGURATION IS ACCESSED VIA JDOM BEFORE PROJECT OPENING
*/
//todo[nik] remove
@State(
name = ProjectFileVersionImpl.COMPONENT_NAME,
storages = {
@@ -27,7 +29,13 @@ import org.jetbrains.annotations.NotNull;
}
)
public class ProjectFileVersionImpl extends ProjectFileVersion implements ProjectComponent, PersistentStateComponent<ProjectFileVersionImpl.ProjectFileVersionState> {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.impl.convert.ProjectFileVersionImpl");
@NonNls public static final String COMPONENT_NAME = "ProjectFileVersion";
private Project myProject;
public ProjectFileVersionImpl(Project project) {
myProject = project;
}
public void projectOpened() {
}
@@ -45,6 +53,22 @@ public class ProjectFileVersionImpl extends ProjectFileVersion implements Projec
}
public void disposeComponent() {
if (myProject.isDefault()) return;
final IProjectStore stateStore = ((ProjectEx)myProject).getStateStore();
final String filePath;
if (stateStore.getStorageScheme() == StorageScheme.DEFAULT) {
filePath = stateStore.getProjectFilePath();
}
else {
final VirtualFile baseDir = stateStore.getProjectBaseDir();
filePath = baseDir != null ? baseDir.getPath() : null;
}
if (filePath != null) {
((ConversionServiceImpl)ConversionService.getInstance()).saveConversionResult(FileUtil.toSystemDependentName(filePath));
}
else {
LOG.info("Cannot save conversion result: filePath == null");
}
}
public ProjectFileVersionState getState() {
@@ -30,7 +30,7 @@ public class ContentEntryImpl extends RootModelComponentBase implements ContentE
private final LinkedHashSet<SourceFolder> mySourceFolders = new LinkedHashSet<SourceFolder>();
private final TreeSet<ExcludeFolder> myExcludeFolders = new TreeSet<ExcludeFolder>(ContentFolderComparator.INSTANCE);
private final TreeSet<ExcludedOutputFolder> myExcludedOutputFolders = new TreeSet<ExcludedOutputFolder>(ContentFolderComparator.INSTANCE);
@NonNls private static final String URL_ATTR = "url";
@NonNls public static final String URL_ATTRIBUTE = "url";
ContentEntryImpl(VirtualFile file, RootModelImpl m) {
this(file.getUrl(), m);
@@ -49,7 +49,7 @@ public class ContentEntryImpl extends RootModelComponentBase implements ContentE
private static String getUrlFrom(Element e) throws InvalidDataException {
LOG.assertTrue(ELEMENT_NAME.equals(e.getName()));
String url = e.getAttributeValue(URL_ATTR);
String url = e.getAttributeValue(URL_ATTRIBUTE);
if (url == null) throw new InvalidDataException();
return url;
}
@@ -292,7 +292,7 @@ public class ContentEntryImpl extends RootModelComponentBase implements ContentE
public void writeExternal(Element element) throws WriteExternalException {
assert !isDisposed();
LOG.assertTrue(ELEMENT_NAME.equals(element.getName()));
element.setAttribute(URL_ATTR, myRoot.getUrl());
element.setAttribute(URL_ATTRIBUTE, myRoot.getUrl());
for (final SourceFolder sourceFolder : mySourceFolders) {
if (sourceFolder instanceof SourceFolderImpl) {
final Element subElement = new Element(SourceFolderImpl.ELEMENT_NAME);
@@ -18,7 +18,7 @@ public abstract class ContentFolderBaseImpl extends RootModelComponentBase imple
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.SimpleContentFolderBaseImpl");
private final VirtualFilePointer myFilePointer;
protected final ContentEntryImpl myContentEntry;
@NonNls public static final String URL_ATTR = "url";
@NonNls public static final String URL_ATTRIBUTE = "url";
ContentFolderBaseImpl(VirtualFile file, ContentEntryImpl contentEntry) {
this(VirtualFilePointerManager.getInstance().create(file, contentEntry.getRootModel().getModule(), contentEntry.getRootModel().myVirtualFilePointerListener), contentEntry);
@@ -37,7 +37,7 @@ public abstract class ContentFolderBaseImpl extends RootModelComponentBase imple
}
private static String getUrlFrom(Element element) throws InvalidDataException {
String url = element.getAttributeValue(URL_ATTR);
String url = element.getAttributeValue(URL_ATTRIBUTE);
if (url == null) throw new InvalidDataException();
return url;
}
@@ -65,7 +65,7 @@ public abstract class ContentFolderBaseImpl extends RootModelComponentBase imple
protected void writeFolder(Element element, String elementName) {
LOG.assertTrue(element.getName().equals(elementName));
element.setAttribute(URL_ATTR, myFilePointer.getUrl());
element.setAttribute(URL_ATTRIBUTE, myFilePointer.getUrl());
}
@NotNull
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.NotNull;
public class ExcludeFolderImpl extends ContentFolderBaseImpl implements ClonableContentFolder,
UserDefinedExcludeFolder {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.SimpleExcludeFolderImpl");
@NonNls static final String ELEMENT_NAME = "excludeFolder";
@NonNls public static final String ELEMENT_NAME = "excludeFolder";
ExcludeFolderImpl(@NotNull VirtualFile file, @NotNull ContentEntryImpl contentEntry) {
super(file, contentEntry);
@@ -18,10 +18,10 @@ import org.jetbrains.annotations.NotNull;
* Library entry for module ("in-place") libraries
* @author dsl
*/
class ModuleLibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements LibraryOrderEntry, ClonableOrderEntry, WritableOrderEntry {
public class ModuleLibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements LibraryOrderEntry, ClonableOrderEntry, WritableOrderEntry {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.LibraryOrderEntryImpl");
private final Library myLibrary;
@NonNls static final String ENTRY_TYPE = "module-library";
@NonNls public static final String ENTRY_TYPE = "module-library";
private boolean myExported;
@NonNls private static final String EXPORTED_ATTR = "exported";
@@ -58,16 +58,24 @@ public class FileUtil {
if (base.equals(file)) return ".";
String basePath = base.getAbsolutePath();
if (!basePath.endsWith(File.separator)) basePath += File.separatorChar;
final String filePath = file.getAbsolutePath();
String basePath = base.getAbsolutePath();
return getRelativePath(basePath, filePath, File.separatorChar);
}
public static String getRelativePath(String basePath, String filePath, final char separator) {
return getRelativePath(basePath, filePath, separator, SystemInfo.isFileSystemCaseSensitive);
}
public static String getRelativePath(String basePath, String filePath, final char separator, final boolean caseSensitive) {
if (!StringUtil.endsWithChar(basePath, separator)) basePath += separator;
int len = 0;
int lastSeparatorIndex = 0; // need this for cases like this: base="/temp/abcde/base" and file="/temp/ab"
String basePathToCompare = SystemInfo.isFileSystemCaseSensitive ? basePath : basePath.toLowerCase();
String filePathToCompare = SystemInfo.isFileSystemCaseSensitive ? filePath : filePath.toLowerCase();
String basePathToCompare = caseSensitive ? basePath : basePath.toLowerCase();
String filePathToCompare = caseSensitive ? filePath : filePath.toLowerCase();
while (len < filePath.length() && len < basePath.length() && filePathToCompare.charAt(len) == basePathToCompare.charAt(len)) {
if (basePath.charAt(len) == File.separatorChar) {
if (basePath.charAt(len) == separator) {
lastSeparatorIndex = len;
}
len++;
@@ -77,9 +85,9 @@ public class FileUtil {
StringBuilder relativePath = new StringBuilder();
for (int i=len; i < basePath.length(); i++) {
if (basePath.charAt(i) == File.separatorChar) {
if (basePath.charAt(i) == separator) {
relativePath.append("..");
relativePath.append(File.separatorChar);
relativePath.append(separator);
}
}
relativePath.append(filePath.substring(lastSeparatorIndex + 1));
@@ -1,13 +1,14 @@
package org.jetbrains.idea.maven.importing;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.artifacts.PackagingElementProcessor;
import com.intellij.openapi.roots.ui.configuration.artifacts.ManifestFilesInfo;
import com.intellij.openapi.util.Pair;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElement;
import com.intellij.packaging.elements.PackagingElementResolvingContext;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.artifacts.PackagingElementProcessor;
import com.intellij.packaging.impl.elements.ArtifactElementType;
import com.intellij.packaging.impl.elements.ArtifactPackagingElement;
import com.intellij.packaging.ui.ManifestFileConfiguration;
@@ -41,6 +42,7 @@ public class ArtifactExternalDependenciesImporter {
public void applyChanges(ModifiableArtifactModel artifactModel, final PackagingElementResolvingContext context) {
myManifestFiles.saveManifestFiles();
final List<Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>>> elementsToInclude = new ArrayList<Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>>>();
for (Artifact artifact : artifactModel.getArtifacts()) {
ArtifactUtil.processPackagingElements(artifact, ArtifactElementType.ARTIFACT_ELEMENT_TYPE, new PackagingElementProcessor<ArtifactPackagingElement>() {
@Override
@@ -51,12 +53,16 @@ public class ArtifactExternalDependenciesImporter {
final CompositePackagingElement<?> parent = parents.get(0);
final List<PackagingElement<?>> elements = myExternalDependencies.get(included);
if (elements != null) {
parent.addOrFindChildren(elements);
elementsToInclude.add(Pair.create(parent, elements));
}
}
return true;
}
}, context, false);
}
for (Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>> pair : elementsToInclude) {
pair.getFirst().addOrFindChildren(pair.getSecond());
}
}
}
@@ -65,6 +65,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
try {
setUpInWriteAction();
}
-1
View File
@@ -1062,7 +1062,6 @@
<todoIndexer filetype="JAVA" implementationClass="com.intellij.psi.impl.cache.impl.idCache.JavaTodoIndexer"/>
<refactoring.elementListenerProvider implementation="com.intellij.execution.impl.RunConfigurationRefactoringElementListenerProvider"/>
<refactoring.elementListenerProvider implementation="com.intellij.jar.BuildJarRefactoringListenerProvider"/>
<bundledKeymapProvider implementation="com.intellij.openapi.keymap.JBuilderKeymapProvider"/>
-9
View File
@@ -45,10 +45,6 @@
<implementation-class>com.intellij.pom.java.impl.PomJavaAspectImpl</implementation-class>
<skipForDummyProject/>
</component>
<component>
<implementation-class>com.intellij.jar.BuildJarProjectSettings</implementation-class>
<skipForDummyProject/>
</component>
<component>
<implementation-class>com.intellij.openapi.roots.impl.PushedFilePropertiesUpdater</implementation-class>
@@ -56,9 +52,4 @@
</project-components>
<module-components>
<component>
<implementation-class>com.intellij.jar.BuildJarSettings</implementation-class>
</component>
</module-components>
</components>
-1
View File
@@ -192,7 +192,6 @@
<action id="GenerateAntBuild" class="com.intellij.compiler.actions.GenerateAntBuildAction"/>
<separator/>
<group id="BuildArtifactsGroup" class="com.intellij.compiler.actions.BuildArtifactActionGroup"/>
<action id="BuildJar" class="com.intellij.jar.BuildJarAction"/>
<add-to-group group-id="MainMenu" anchor="before" relative-to-action="RunMenu"/>
</group>