diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/jarr/JarBuildParticipantProvider.java b/java/compiler/impl/src/com/intellij/compiler/impl/jarr/JarBuildParticipantProvider.java new file mode 100644 index 000000000000..7931214acd58 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/impl/jarr/JarBuildParticipantProvider.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.compiler.impl.jarr; + +import com.intellij.openapi.compiler.CompileContext; +import com.intellij.openapi.compiler.make.BuildParticipant; +import com.intellij.openapi.compiler.make.BuildParticipantProvider; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.CompilerModuleExtension; +import com.intellij.openapi.roots.CompilerProjectExtension; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.elements.ArtifactRootElement; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.PackagingElementFactory; +import com.intellij.packaging.impl.artifacts.ArtifactImpl; +import com.intellij.packaging.impl.artifacts.PlainArtifactType; + +import java.util.Collection; +import java.util.Collections; + +/** + * @author Dmitry Avdeev + */ +public class JarBuildParticipantProvider extends BuildParticipantProvider { + + @Override + public Collection getParticipants(final Module module) { + + if (!Registry.is("jar.build")) return Collections.emptySet(); + + return Collections.singleton(new BuildParticipant() { + @Override + public Artifact createArtifact(CompileContext context) { + + PackagingElementFactory factory = PackagingElementFactory.getInstance(); + ArtifactRootElement root = factory.createArtifactRootElement(); + + CompositePackagingElement classesJar = factory.createArchive(module.getName() + ".jar"); + classesJar.addOrFindChild(factory.createModuleOutput(module)); + String s = CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath(); + classesJar.addOrFindChild(factory.createDirectoryCopyWithParentDirectories(s, "")); + root.addOrFindChild(classesJar); + + Project project = module.getProject(); + VirtualFile output = CompilerProjectExtension.getInstance(project).getCompilerOutput(); + String path = output == null ? null : output.getPath() + "/jars"; + return path == null ? null : new ArtifactImpl(module.getName(), PlainArtifactType.getInstance(), false, root, path); + } + }); + } + +} diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java index 9b2b412c20f4..4faa3870e213 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java @@ -23,15 +23,13 @@ import com.intellij.openapi.module.LanguageLevelUtil; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.JdkOrderEntry; -import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.OrderEntry; -import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.*; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import com.intellij.util.Chunk; +import com.intellij.util.JarClasspathHelper; import com.intellij.util.PathUtil; import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.containers.OrderedSet; @@ -198,6 +196,7 @@ public class ModuleChunk extends Chunk { final OrderedSet cpFiles = new OrderedSet(TObjectHashingStrategy.CANONICAL); for (final Module module : modules) { + final OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries(); boolean skip = true; for (OrderEntry orderEntry : orderEntries) { @@ -208,12 +207,13 @@ public class ModuleChunk extends Chunk { if (skip) { continue; } - if ((mySourcesFilter & TEST_SOURCES) == 0) { - cpFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES))); - } - else { - cpFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.COMPILATION_CLASSES))); + + VirtualFile[] files = orderEntry.getFiles((mySourcesFilter & TEST_SOURCES) == 0 ? OrderRootType.PRODUCTION_COMPILATION_CLASSES : OrderRootType.COMPILATION_CLASSES); + if (orderEntry instanceof ModuleOrderEntry) { + Project project = module.getProject(); + JarClasspathHelper.patchFiles(files, project); } + cpFiles.addAll(Arrays.asList(files)); } } return cpFiles; diff --git a/java/execution/impl/src/com/intellij/execution/impl/JarProgramPatcher.java b/java/execution/impl/src/com/intellij/execution/impl/JarProgramPatcher.java new file mode 100644 index 000000000000..033596d689c0 --- /dev/null +++ b/java/execution/impl/src/com/intellij/execution/impl/JarProgramPatcher.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.impl; + +import com.intellij.execution.Executor; +import com.intellij.execution.configurations.JavaParameters; +import com.intellij.execution.configurations.RunConfiguration; +import com.intellij.execution.configurations.RunProfile; +import com.intellij.execution.runners.JavaProgramPatcher; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.JarClasspathHelper; +import com.intellij.util.PathsList; + +import java.io.File; +import java.util.List; + +/** + * @author Dmitry Avdeev + */ +public class JarProgramPatcher extends JavaProgramPatcher { + + @Override + public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) { + + if (!(configuration instanceof RunConfiguration) || !Registry.is("jar.build")) return; + + String path = JarClasspathHelper.getJarsPath(((RunConfiguration)configuration).getProject()); + if (path == null) return; + + PathsList classPath = javaParameters.getClassPath(); + List pathList = classPath.getPathList(); + for (String s: pathList) { + String name = new File(s).getName(); + VirtualFile jarFile = JarClasspathHelper.getJarFile(path, name); + if (jarFile != null) { + classPath.remove(s); + classPath.add(jarFile); + } + } + } + +} diff --git a/java/java-impl/src/com/intellij/util/JarClasspathHelper.java b/java/java-impl/src/com/intellij/util/JarClasspathHelper.java new file mode 100644 index 000000000000..41d0daff27b5 --- /dev/null +++ b/java/java-impl/src/com/intellij/util/JarClasspathHelper.java @@ -0,0 +1,64 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.CompilerProjectExtension; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.Nullable; + +/** + * @author Dmitry Avdeev + */ +public class JarClasspathHelper { + + public static void patchFiles(VirtualFile[] files, Project project) { + if (!Registry.is("jar.build")) { + return; + } + String path = getJarsPath(project); + for (int i = 0, filesLength = files.length; i < filesLength; i++) { + VirtualFile file = files[i]; + + VirtualFile jar = getJarFile(path, file.getName()); + if (jar != null) { + files[i] = jar; + } + } + } + + @Nullable + public static VirtualFile getJarFile(String path, String moduleName) { + VirtualFile jar = LocalFileSystem.getInstance().refreshAndFindFileByPath(path + "/" + moduleName + ".jar"); + System.out.println(jar); + return jar; + } + + @Nullable + public static String getJarsPath(Project project) { + CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project); + if (extension == null) { + return null; + } + VirtualFile output = extension.getCompilerOutput(); + if (output == null) { + return null; + } + return output.getPath() + "/jars"; + } +} diff --git a/platform/lang-api/src/com/intellij/util/PathsList.java b/platform/lang-api/src/com/intellij/util/PathsList.java index ea63462fc243..3a434da9033c 100644 --- a/platform/lang-api/src/com/intellij/util/PathsList.java +++ b/platform/lang-api/src/com/intellij/util/PathsList.java @@ -22,7 +22,6 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import static com.intellij.util.containers.ContainerUtil.*; import com.intellij.util.containers.FilteringIterator; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NonNls; @@ -30,6 +29,8 @@ import org.jetbrains.annotations.NonNls; import java.io.File; import java.util.*; +import static com.intellij.util.containers.ContainerUtil.*; + public class PathsList { private final List myPath = new ArrayList(); private final List myPathTail = new ArrayList(); @@ -63,6 +64,11 @@ public class PathsList { addAllLast(chooseFirstTimeItems(path), myPath); } + public void remove(String path) { + myPath.remove(path); + myPathSet.remove(path); + } + public void add(VirtualFile file) { add(LOCAL_PATH.fun(file)); } diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 07c58ae7873f..d80bcb9cc44c 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -58,4 +58,5 @@ vcs.show.colored.annotations=true vcs.showConsole=true psi.viewer.selection.color=0,153,153 -structureView.coalesceTime=500 \ No newline at end of file +structureView.coalesceTime=500 +jar.build=false \ No newline at end of file diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 868085e39c42..c5600cc53164 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -440,6 +440,9 @@ + + + com.intellij.codeInsight.intention.impl.SplitIfAction Control Flow