mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-53319: IDEA 9.0.1 Very Brittle With Deployments (corrupts projects, overwrites directories, ...)
This commit is contained in:
@@ -105,11 +105,11 @@ public class ArtifactUtil {
|
||||
final @NotNull PackagingElementResolvingContext resolvingContext,
|
||||
final boolean processSubstitutions,
|
||||
final ArtifactType artifactType) {
|
||||
return processElement(rootElement, type, processor, resolvingContext, processSubstitutions, artifactType,
|
||||
return processElementRecursively(rootElement, type, processor, resolvingContext, processSubstitutions, artifactType,
|
||||
PackagingElementPath.EMPTY, new HashSet<PackagingElement<?>>());
|
||||
}
|
||||
|
||||
private static <E extends PackagingElement<?>> boolean processElements(final List<? extends PackagingElement<?>> elements,
|
||||
private static <E extends PackagingElement<?>> boolean processElementsRecursively(final List<? extends PackagingElement<?>> elements,
|
||||
@Nullable PackagingElementType<E> type,
|
||||
@NotNull PackagingElementProcessor<? super E> processor,
|
||||
final @NotNull PackagingElementResolvingContext resolvingContext,
|
||||
@@ -117,14 +117,14 @@ public class ArtifactUtil {
|
||||
@NotNull PackagingElementPath path,
|
||||
Set<PackagingElement<?>> processed) {
|
||||
for (PackagingElement<?> element : elements) {
|
||||
if (!processElement(element, type, processor, resolvingContext, processSubstitutions, artifactType, path, processed)) {
|
||||
if (!processElementRecursively(element, type, processor, resolvingContext, processSubstitutions, artifactType, path, processed)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static <E extends PackagingElement<?>> boolean processElement(@NotNull PackagingElement<?> element, @Nullable PackagingElementType<E> type,
|
||||
private static <E extends PackagingElement<?>> boolean processElementRecursively(@NotNull PackagingElement<?> element, @Nullable PackagingElementType<E> type,
|
||||
@NotNull PackagingElementProcessor<? super E> processor,
|
||||
@NotNull PackagingElementResolvingContext resolvingContext,
|
||||
final boolean processSubstitutions,
|
||||
@@ -140,7 +140,7 @@ public class ArtifactUtil {
|
||||
}
|
||||
if (element instanceof CompositePackagingElement<?>) {
|
||||
final CompositePackagingElement<?> composite = (CompositePackagingElement<?>)element;
|
||||
return processElements(composite.getChildren(), type, processor, resolvingContext, processSubstitutions, artifactType,
|
||||
return processElementsRecursively(composite.getChildren(), type, processor, resolvingContext, processSubstitutions, artifactType,
|
||||
path.appendComposite(composite), processed);
|
||||
}
|
||||
else if (element instanceof ComplexPackagingElement<?> && processSubstitutions) {
|
||||
@@ -148,7 +148,7 @@ public class ArtifactUtil {
|
||||
if (processor.shouldProcessSubstitution(complexElement)) {
|
||||
final List<? extends PackagingElement<?>> substitution = complexElement.getSubstitution(resolvingContext, artifactType);
|
||||
if (substitution != null) {
|
||||
return processElements(substitution, type, processor, resolvingContext, processSubstitutions, artifactType,
|
||||
return processElementsRecursively(substitution, type, processor, resolvingContext, processSubstitutions, artifactType,
|
||||
path.appendComplex(complexElement), processed);
|
||||
}
|
||||
}
|
||||
@@ -207,16 +207,30 @@ public class ArtifactUtil {
|
||||
return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
|
||||
}
|
||||
|
||||
public static <E extends PackagingElement<?>> boolean processElements(@NotNull List<? extends PackagingElement<?>> elements,
|
||||
public static <E extends PackagingElement<?>> boolean processElementsWithSubstitutions(@NotNull List<? extends PackagingElement<?>> elements,
|
||||
@NotNull PackagingElementResolvingContext context,
|
||||
@NotNull ArtifactType artifactType,
|
||||
@NotNull PackagingElementPath parentPath,
|
||||
@NotNull PackagingElementProcessor<E> processor) {
|
||||
return processElementsWithSubstitutions(elements, context, artifactType, parentPath, processor, new HashSet<PackagingElement<?>>());
|
||||
}
|
||||
|
||||
private static <E extends PackagingElement<?>> boolean processElementsWithSubstitutions(@NotNull List<? extends PackagingElement<?>> elements,
|
||||
@NotNull PackagingElementResolvingContext context,
|
||||
@NotNull ArtifactType artifactType,
|
||||
@NotNull PackagingElementPath parentPath,
|
||||
@NotNull PackagingElementProcessor<E> processor,
|
||||
final Set<PackagingElement<?>> processed) {
|
||||
for (PackagingElement<?> element : elements) {
|
||||
if (!processed.add(element)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (element instanceof ComplexPackagingElement<?> && processor.shouldProcessSubstitution((ComplexPackagingElement)element)) {
|
||||
final ComplexPackagingElement<?> complexElement = (ComplexPackagingElement<?>)element;
|
||||
final List<? extends PackagingElement<?>> substitution = complexElement.getSubstitution(context, artifactType);
|
||||
if (substitution != null && !processElements(substitution, context, artifactType, parentPath.appendComplex(complexElement), processor)) {
|
||||
if (substitution != null &&
|
||||
!processElementsWithSubstitutions(substitution, context, artifactType, parentPath.appendComplex(complexElement), processor, processed)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -253,7 +267,7 @@ public class ArtifactUtil {
|
||||
final String firstName = i != -1 ? relativePath.substring(0, i) : relativePath;
|
||||
final String tail = i != -1 ? relativePath.substring(i+1) : "";
|
||||
|
||||
return processElements(parent.getChildren(), context, artifactType, parentPath.appendComposite(parent), new PackagingElementProcessor<PackagingElement<?>>() {
|
||||
return processElementsWithSubstitutions(parent.getChildren(), context, artifactType, parentPath.appendComposite(parent), new PackagingElementProcessor<PackagingElement<?>>() {
|
||||
@Override
|
||||
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
|
||||
boolean process = false;
|
||||
@@ -291,7 +305,7 @@ public class ArtifactUtil {
|
||||
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
|
||||
if (element instanceof DirectoryPackagingElement) {
|
||||
final List<PackagingElement<?>> children = ((DirectoryPackagingElement)element).getChildren();
|
||||
if (!processElements(children, context, artifactType, path.appendComposite((DirectoryPackagingElement)element), processor)) {
|
||||
if (!processElementsWithSubstitutions(children, context, artifactType, path.appendComposite((DirectoryPackagingElement)element), processor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -387,7 +401,7 @@ public class ArtifactUtil {
|
||||
final String tail = i != -1 ? path.substring(i+1) : "";
|
||||
|
||||
final List<VirtualFile> result = new SmartList<VirtualFile>();
|
||||
processElements(parent.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
|
||||
processElementsWithSubstitutions(parent.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
|
||||
@Override
|
||||
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath elementPath) {
|
||||
//todo[nik] replace by method findSourceFile() in PackagingElement
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.packaging.impl.artifacts;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class ArtifactValidationUtil {
|
||||
public static ArtifactValidationUtil getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, ArtifactValidationUtil.class);
|
||||
}
|
||||
|
||||
public abstract Set<Artifact> getSelfIncludingArtifacts();
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.packaging.impl.artifacts;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.impl.elements.ArtifactElementType;
|
||||
import com.intellij.packaging.impl.elements.ArtifactPackagingElement;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ArtifactValidationUtilImpl extends ArtifactValidationUtil {
|
||||
private Project myProject;
|
||||
private CachedValue<Set<Artifact>> mySelfIncludingArtifacts;
|
||||
|
||||
public ArtifactValidationUtilImpl(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Artifact> getSelfIncludingArtifacts() {
|
||||
if (mySelfIncludingArtifacts == null) {
|
||||
mySelfIncludingArtifacts = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Set<Artifact>>() {
|
||||
public Result<Set<Artifact>> compute() {
|
||||
return Result.create(computeSelfIncludingArtifacts(), ArtifactManager.getInstance(myProject).getModificationTracker());
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
return mySelfIncludingArtifacts.getValue();
|
||||
}
|
||||
|
||||
private Set<Artifact> computeSelfIncludingArtifacts() {
|
||||
final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);
|
||||
Set<Artifact> result = new HashSet<Artifact>();
|
||||
final PackagingElementResolvingContext context = artifactManager.getResolvingContext();
|
||||
for (final Artifact artifact : artifactManager.getSortedArtifacts()) {
|
||||
if (!ArtifactUtil.processPackagingElements(artifact, ArtifactElementType.ARTIFACT_ELEMENT_TYPE,
|
||||
new PackagingElementProcessor<ArtifactPackagingElement>() {
|
||||
@Override
|
||||
public boolean process(@NotNull ArtifactPackagingElement element,
|
||||
@NotNull PackagingElementPath path) {
|
||||
return !artifact.equals(element.findArtifact(context));
|
||||
}
|
||||
}, context, true)) {
|
||||
result.add(artifact);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -49,6 +49,7 @@ import com.intellij.packaging.artifacts.ArtifactProperties;
|
||||
import com.intellij.packaging.artifacts.ArtifactPropertiesProvider;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactValidationUtil;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
@@ -121,9 +122,22 @@ public class IncrementalArtifactsCompiler implements PackagingCompiler {
|
||||
public ProcessingItem[] getProcessingItems(final CompileContext context) {
|
||||
return new ReadAction<ProcessingItem[]>() {
|
||||
protected void run(final Result<ProcessingItem[]> result) {
|
||||
final Project project = context.getProject();
|
||||
final Set<Artifact> selfIncludingArtifacts = ArtifactValidationUtil.getInstance(project).getSelfIncludingArtifacts();
|
||||
if (!selfIncludingArtifacts.isEmpty()) {
|
||||
LOG.info("Self including artifacts: " + selfIncludingArtifacts);
|
||||
if (!ArtifactCompileScope.getArtifactsToBuild(project, context.getCompileScope()).isEmpty()) {
|
||||
for (Artifact artifact : selfIncludingArtifacts) {
|
||||
context.addMessage(CompilerMessageCategory.ERROR, "Artifact '" + artifact.getName() + "' includes itself in the output layout", null, -1, -1);
|
||||
}
|
||||
}
|
||||
result.setResult(ProcessingItem.EMPTY_ARRAY);
|
||||
return;
|
||||
}
|
||||
|
||||
ArtifactsProcessingItemsBuilderContext builderContext = new ArtifactsProcessingItemsBuilderContext(context);
|
||||
context.putUserData(BUILDER_CONTEXT_KEY, builderContext);
|
||||
ArtifactPackagingProcessingItem[] allProcessingItems = collectItems(builderContext, context.getProject());
|
||||
ArtifactPackagingProcessingItem[] allProcessingItems = collectItems(builderContext, project);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
int num = Math.min(5000, allProcessingItems.length);
|
||||
@@ -135,7 +149,7 @@ public class IncrementalArtifactsCompiler implements PackagingCompiler {
|
||||
|
||||
try {
|
||||
final FileProcessingCompilerStateCache cache =
|
||||
CompilerCacheManager.getInstance(context.getProject()).getFileProcessingCompilerCache(IncrementalArtifactsCompiler.this);
|
||||
CompilerCacheManager.getInstance(project).getFileProcessingCompilerCache(IncrementalArtifactsCompiler.this);
|
||||
for (ArtifactPackagingProcessingItem item : allProcessingItems) {
|
||||
item.init(cache);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ManifestFileUtil {
|
||||
|
||||
final Ref<VirtualFile> sourceDir = Ref.create(null);
|
||||
final Ref<VirtualFile> sourceFile = Ref.create(null);
|
||||
ArtifactUtil.processElements(root.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
|
||||
ArtifactUtil.processElementsWithSubstitutions(root.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
|
||||
@Override
|
||||
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
|
||||
if (element instanceof FileCopyPackagingElement) {
|
||||
|
||||
+3
-1
@@ -19,11 +19,13 @@ import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ComplexElementSubstitutionParameters;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.ui.treeStructure.SimpleNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -47,7 +49,7 @@ public class CompositePackagingElementNode extends PackagingElementNode<Composit
|
||||
List<PackagingElementNode<?>> children = new ArrayList<PackagingElementNode<?>>();
|
||||
for (CompositePackagingElement<?> element : getPackagingElements()) {
|
||||
PackagingTreeNodeFactory.addNodes(element.getChildren(), this, element, myContext, mySubstitutionParameters, getNodeSource(element), children,
|
||||
myArtifactType);
|
||||
myArtifactType, new HashSet<PackagingElement<?>>());
|
||||
}
|
||||
return children.toArray(new SimpleNode[children.size()]);
|
||||
}
|
||||
|
||||
+5
-3
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -41,7 +42,8 @@ public class PackagingTreeNodeFactory {
|
||||
@NotNull CompositePackagingElement parentElement, @NotNull ArtifactEditorContext context,
|
||||
@NotNull ComplexElementSubstitutionParameters substitutionParameters, @NotNull Collection<PackagingNodeSource> nodeSources,
|
||||
@NotNull List<PackagingElementNode<?>> nodes,
|
||||
ArtifactType artifactType) {
|
||||
ArtifactType artifactType,
|
||||
Set<PackagingElement<?>> processed) {
|
||||
for (PackagingElement<?> element : elements) {
|
||||
final PackagingElementNode<?> prev = findEqual(nodes, element);
|
||||
if (prev != null) {
|
||||
@@ -58,12 +60,12 @@ public class PackagingTreeNodeFactory {
|
||||
}
|
||||
else if (element instanceof ComplexPackagingElement) {
|
||||
final ComplexPackagingElement<?> complexElement = (ComplexPackagingElement<?>)element;
|
||||
if (substitutionParameters.shouldSubstitute(complexElement)) {
|
||||
if (processed.add(element) && substitutionParameters.shouldSubstitute(complexElement)) {
|
||||
final List<? extends PackagingElement<?>> substitution = complexElement.getSubstitution(context, artifactType);
|
||||
if (substitution != null) {
|
||||
final PackagingNodeSource source = new PackagingNodeSource(complexElement, parentNode, parentElement, nodeSources);
|
||||
addNodes(substitution, parentNode, parentElement, context, substitutionParameters, Collections.singletonList(source), nodes,
|
||||
artifactType);
|
||||
artifactType, processed);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +352,8 @@
|
||||
serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactPointerManagerImpl"/>
|
||||
<projectService serviceInterface="com.intellij.packaging.impl.artifacts.ArtifactBySourceFileFinder"
|
||||
serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactBySourceFileFinderImpl"/>
|
||||
<projectService serviceInterface="com.intellij.packaging.impl.artifacts.ArtifactValidationUtil"
|
||||
serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactValidationUtilImpl"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.conversion.ConversionService"
|
||||
serviceImplementation="com.intellij.conversion.impl.ConversionServiceImpl"/>
|
||||
|
||||
Reference in New Issue
Block a user