mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test on external build for ui designer restored, required test cases moved to community
This commit is contained in:
+116
@@ -0,0 +1,116 @@
|
||||
package com.intellij.compiler.artifacts;
|
||||
|
||||
import com.intellij.compiler.BaseCompilerTestCase;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.impl.artifacts.PlainArtifactType;
|
||||
import com.intellij.util.io.TestFileSystemBuilder;
|
||||
import com.intellij.util.io.TestFileSystemItem;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.intellij.compiler.artifacts.ArtifactsTestCase.commitModel;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class ArtifactCompilerTestCase extends BaseCompilerTestCase {
|
||||
|
||||
protected void deleteArtifact(final Artifact artifact) {
|
||||
final ModifiableArtifactModel model = getArtifactManager().createModifiableModel();
|
||||
model.removeArtifact(artifact);
|
||||
commitModel(model);
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(TestPackagingElementBuilder builder) {
|
||||
return addArtifact("a", builder);
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(final String name, TestPackagingElementBuilder builder) {
|
||||
return addArtifact(name, builder.build());
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(String name, final CompositePackagingElement<?> root) {
|
||||
return addArtifact(name, PlainArtifactType.getInstance(), root);
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(final String name, final ArtifactType type, final CompositePackagingElement<?> root) {
|
||||
return getArtifactManager().addArtifact(name, type, root);
|
||||
}
|
||||
|
||||
protected Library addProjectLibrary(final @Nullable Module module, final String name, final VirtualFile... jars) {
|
||||
return addProjectLibrary(module, name, DependencyScope.COMPILE, jars);
|
||||
}
|
||||
|
||||
protected Library addProjectLibrary(final @Nullable Module module, final String name, final DependencyScope scope,
|
||||
final VirtualFile... jars) {
|
||||
return PackagingElementsTestCase.addProjectLibrary(myProject, module, name, scope, jars);
|
||||
}
|
||||
|
||||
protected TestPackagingElementBuilder root() {
|
||||
return TestPackagingElementBuilder.root(myProject);
|
||||
}
|
||||
|
||||
protected TestPackagingElementBuilder archive(String name) {
|
||||
return TestPackagingElementBuilder.archive(myProject, name);
|
||||
}
|
||||
|
||||
protected CompilationLog compileProject() {
|
||||
return make(getArtifactManager().getArtifacts());
|
||||
}
|
||||
|
||||
protected void changeFileInJar(String jarPath, String pathInJar) throws Exception {
|
||||
final VirtualFile jarFile = LocalFileSystem.getInstance().findFileByPath(jarPath);
|
||||
assertNotNull(jarFile);
|
||||
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jarFile);
|
||||
assertNotNull(jarRoot);
|
||||
VirtualFile jarEntry = jarRoot.findFileByRelativePath(pathInJar);
|
||||
assertNotNull(jarEntry);
|
||||
assertNotNull(jarFile);
|
||||
changeFile(jarFile);
|
||||
jarFile.refresh(false, false);
|
||||
|
||||
jarEntry = jarRoot.findFileByRelativePath(pathInJar);
|
||||
assertNotNull(jarEntry);
|
||||
}
|
||||
|
||||
protected static TestFileSystemBuilder fs() {
|
||||
return TestFileSystemItem.fs();
|
||||
}
|
||||
|
||||
public static void assertNoOutput(Artifact artifact) {
|
||||
final String outputPath = artifact.getOutputPath();
|
||||
assertNotNull("output path not specified for " + artifact.getName(), outputPath);
|
||||
assertFalse(new File(FileUtil.toSystemDependentName(outputPath)).exists());
|
||||
}
|
||||
|
||||
public static void assertEmptyOutput(Artifact a1) throws IOException {
|
||||
assertOutput(a1, ArtifactCompilerTestCase.fs());
|
||||
}
|
||||
|
||||
public static void assertOutput(Artifact artifact, TestFileSystemBuilder item) {
|
||||
final VirtualFile outputFile = getOutputDir(artifact);
|
||||
outputFile.refresh(false, true);
|
||||
item.build().assertDirectoryEqual(VfsUtil.virtualToIoFile(outputFile));
|
||||
}
|
||||
|
||||
protected static VirtualFile getOutputDir(Artifact artifact) {
|
||||
final String output = artifact.getOutputPath();
|
||||
assertNotNull("output path not specified for " + artifact.getName(), output);
|
||||
final VirtualFile outputFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(output);
|
||||
assertNotNull("output file not found " + output, outputFile);
|
||||
return outputFile;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
package com.intellij.compiler.artifacts;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.impl.DefaultFacetsProvider;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.*;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.ManifestFileProvider;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.impl.artifacts.PlainArtifactType;
|
||||
import com.intellij.packaging.impl.elements.ManifestFileUtil;
|
||||
import com.intellij.packaging.ui.ArtifactEditor;
|
||||
import com.intellij.packaging.ui.ManifestFileConfiguration;
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class ArtifactsTestCase extends IdeaTestCase {
|
||||
protected boolean mySetupModule;
|
||||
|
||||
protected ArtifactManager getArtifactManager() {
|
||||
return ArtifactManager.getInstance(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpModule() {
|
||||
if (mySetupModule) {
|
||||
super.setUpModule();
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteArtifact(final Artifact artifact) {
|
||||
final ModifiableArtifactModel model = getArtifactManager().createModifiableModel();
|
||||
model.removeArtifact(artifact);
|
||||
commitModel(model);
|
||||
}
|
||||
|
||||
protected static void commitModel(final ModifiableArtifactModel model) {
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(final Result result) {
|
||||
model.commit();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
protected Artifact rename(Artifact artifact, String newName) {
|
||||
final ModifiableArtifactModel model = getArtifactManager().createModifiableModel();
|
||||
model.getOrCreateModifiableArtifact(artifact).setName(newName);
|
||||
commitModel(model);
|
||||
return artifact;
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(String name) {
|
||||
return addArtifact(name, null);
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(String name, final CompositePackagingElement<?> root) {
|
||||
return addArtifact(name, PlainArtifactType.getInstance(), root);
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(final String name, final ArtifactType type, final CompositePackagingElement<?> root) {
|
||||
return getArtifactManager().addArtifact(name, type, root);
|
||||
}
|
||||
|
||||
protected PackagingElementResolvingContext getContext() {
|
||||
return ArtifactManager.getInstance(myProject).getResolvingContext();
|
||||
}
|
||||
|
||||
public static void renameFile(final VirtualFile file, final String newName) {
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(final Result result) {
|
||||
try {
|
||||
file.rename(IdeaTestCase.class, newName);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
protected Module addModule(final String moduleName, final @Nullable VirtualFile sourceRoot) {
|
||||
return new WriteAction<Module>() {
|
||||
@Override
|
||||
protected void run(final Result<Module> result) {
|
||||
final Module module = createModule(moduleName);
|
||||
if (sourceRoot != null) {
|
||||
PsiTestUtil.addSourceContentToRoots(module, sourceRoot);
|
||||
}
|
||||
ModuleRootModificationUtil.setModuleSdk(module, getTestProjectJdk());
|
||||
result.setResult(module);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
public static class MockPackagingEditorContext extends ArtifactEditorContextImpl {
|
||||
public MockPackagingEditorContext(ArtifactsStructureConfigurableContext parent, final ArtifactEditorEx editor) {
|
||||
super(parent, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectArtifact(@NotNull Artifact artifact) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectFacet(@NotNull Facet<?> facet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectModule(@NotNull Module module) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectLibrary(@NotNull Library library) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueValidation() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Artifact> chooseArtifacts(List<? extends Artifact> artifacts, String title) {
|
||||
return new ArrayList<Artifact>(artifacts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Module> chooseModules(List<Module> modules, String title) {
|
||||
return modules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Library> chooseLibraries(String title) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public class MockArtifactsStructureConfigurableContext implements ArtifactsStructureConfigurableContext {
|
||||
private ModifiableArtifactModel myModifiableModel;
|
||||
private final Map<Module, ModifiableRootModel> myModifiableRootModels = new HashMap<Module, ModifiableRootModel>();
|
||||
private final Map<CompositePackagingElement<?>, ManifestFileConfiguration> myManifestFiles =
|
||||
new HashMap<CompositePackagingElement<?>, ManifestFileConfiguration>();
|
||||
private final ArtifactEditorManifestFileProvider myManifestFileProvider = new ArtifactEditorManifestFileProvider(this);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ModifiableArtifactModel getOrCreateModifiableArtifactModel() {
|
||||
if (myModifiableModel == null) {
|
||||
myModifiableModel = ArtifactManager.getInstance(myProject).createModifiableModel();
|
||||
}
|
||||
return myModifiableModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModifiableModuleModel getModifiableModuleModel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ModifiableRootModel getOrCreateModifiableRootModel(@NotNull Module module) {
|
||||
ModifiableRootModel model = myModifiableRootModels.get(module);
|
||||
if (model == null) {
|
||||
model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
myModifiableRootModels.put(module, model);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactEditorSettings getDefaultSettings() {
|
||||
return new ArtifactEditorSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ArtifactModel getArtifactModel() {
|
||||
if (myModifiableModel != null) {
|
||||
return myModifiableModel;
|
||||
}
|
||||
return ArtifactManager.getInstance(myProject);
|
||||
}
|
||||
|
||||
public void commitModel() {
|
||||
if (myModifiableModel != null) {
|
||||
myModifiableModel.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ModulesProvider getModulesProvider() {
|
||||
return new DefaultModulesProvider(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public FacetsProvider getFacetsProvider() {
|
||||
return DefaultFacetsProvider.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Library findLibrary(@NotNull String level, @NotNull String libraryName) {
|
||||
return ArtifactManager.getInstance(myProject).getResolvingContext().findLibrary(level, libraryName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ManifestFileProvider getManifestFileProvider() {
|
||||
return myManifestFileProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManifestFileConfiguration getManifestFile(CompositePackagingElement<?> element, ArtifactType artifactType) {
|
||||
final VirtualFile manifestFile = ManifestFileUtil.findManifestFile(element, this, PlainArtifactType.getInstance());
|
||||
if (manifestFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ManifestFileConfiguration configuration = myManifestFiles.get(element);
|
||||
if (configuration == null) {
|
||||
configuration = ManifestFileUtil.createManifestFileConfiguration(manifestFile);
|
||||
myManifestFiles.put(element, configuration);
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompositePackagingElement<?> getRootElement(@NotNull Artifact artifact) {
|
||||
return artifact.getRootElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editLayout(@NotNull Artifact artifact, Runnable action) {
|
||||
final ModifiableArtifact modifiableArtifact = getOrCreateModifiableArtifactModel().getOrCreateModifiableArtifact(artifact);
|
||||
modifiableArtifact.setRootElement(artifact.getRootElement());
|
||||
action.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactEditor getOrCreateEditor(Artifact artifact) {
|
||||
throw new UnsupportedOperationException("'getOrCreateEditor' not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Artifact getOriginalArtifact(@NotNull Artifact artifact) {
|
||||
if (myModifiableModel != null) {
|
||||
return myModifiableModel.getOriginalArtifact(artifact);
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueValidation(Artifact artifact) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ArtifactProjectStructureElement getOrCreateArtifactElement(@NotNull Artifact artifact) {
|
||||
throw new UnsupportedOperationException("'getOrCreateArtifactElement' not implemented in " + getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.intellij.compiler.artifacts;
|
||||
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementFactory;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.impl.elements.ArchivePackagingElement;
|
||||
import com.intellij.packaging.impl.elements.DirectoryPackagingElement;
|
||||
import com.intellij.packaging.impl.elements.ManifestFileUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ArtifactsTestUtil {
|
||||
public static String printToString(PackagingElement element, int level) {
|
||||
StringBuilder builder = new StringBuilder(StringUtil.repeatSymbol(' ', level));
|
||||
if (element instanceof ArchivePackagingElement) {
|
||||
builder.append(((ArchivePackagingElement)element).getArchiveFileName());
|
||||
}
|
||||
else if (element instanceof DirectoryPackagingElement) {
|
||||
builder.append(((DirectoryPackagingElement)element).getDirectoryName()).append("/");
|
||||
}
|
||||
else {
|
||||
builder.append(element.toString());
|
||||
}
|
||||
builder.append("\n");
|
||||
if (element instanceof CompositePackagingElement) {
|
||||
for (PackagingElement<?> child : ((CompositePackagingElement<?>)element).getChildren()) {
|
||||
builder.append(printToString(child, level + 1));
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static void assertLayout(PackagingElement element, String expected) {
|
||||
assertEquals(adjustMultiLine(expected), printToString(element, 0));
|
||||
}
|
||||
|
||||
private static String adjustMultiLine(String expected) {
|
||||
final List<String> strings = StringUtil.split(StringUtil.trimStart(expected, "\n"), "\n");
|
||||
int min = Integer.MAX_VALUE;
|
||||
for (String s : strings) {
|
||||
int k = 0;
|
||||
while (k < s.length() && s.charAt(k) == ' ') {
|
||||
k++;
|
||||
}
|
||||
min = Math.min(min, k);
|
||||
}
|
||||
List<String> lines = new ArrayList<String>();
|
||||
for (String s : strings) {
|
||||
lines.add(s.substring(min));
|
||||
}
|
||||
return StringUtil.join(lines, "\n") + "\n";
|
||||
}
|
||||
|
||||
public static void assertLayout(Project project, String artifactName, String expected) {
|
||||
assertLayout(findArtifact(project, artifactName).getRootElement(), expected);
|
||||
}
|
||||
|
||||
public static void assertOutputPath(Project project, String artifactName, String expected) {
|
||||
assertEquals(expected, findArtifact(project, artifactName).getOutputPath());
|
||||
}
|
||||
|
||||
public static void assertOutputFileName(Project project, String artifactName, String expected) {
|
||||
assertEquals(expected, findArtifact(project, artifactName).getRootElement().getName());
|
||||
}
|
||||
|
||||
public static void setOutput(final Project project, final String artifactName, final String outputPath) {
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(final Result result) {
|
||||
final ModifiableArtifactModel model = ArtifactManager.getInstance(project).createModifiableModel();
|
||||
model.getOrCreateModifiableArtifact(findArtifact(project, artifactName)).setOutputPath(outputPath);
|
||||
model.commit();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public static void addArtifactToLayout(final Project project, final Artifact parent, final Artifact toAdd) {
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(final Result result) {
|
||||
final ModifiableArtifactModel model = ArtifactManager.getInstance(project).createModifiableModel();
|
||||
final PackagingElement<?> artifactElement = PackagingElementFactory.getInstance().createArtifactElement(toAdd, project);
|
||||
model.getOrCreateModifiableArtifact(parent).getRootElement().addOrFindChild(artifactElement);
|
||||
model.commit();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public static Artifact findArtifact(Project project, String artifactName) {
|
||||
final ArtifactManager manager = ArtifactManager.getInstance(project);
|
||||
final Artifact artifact = manager.findArtifact(artifactName);
|
||||
assertNotNull("'" + artifactName + "' artifact not found", artifact);
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public static void assertManifest(Artifact artifact, PackagingElementResolvingContext context, @Nullable String mainClass, @Nullable String classpath) {
|
||||
final CompositePackagingElement<?> rootElement = artifact.getRootElement();
|
||||
final ArtifactType type = artifact.getArtifactType();
|
||||
assertManifest(rootElement, context, type, mainClass, classpath);
|
||||
}
|
||||
|
||||
public static void assertManifest(CompositePackagingElement<?> rootElement,
|
||||
PackagingElementResolvingContext context,
|
||||
ArtifactType type,
|
||||
@Nullable String mainClass, @Nullable String classpath) {
|
||||
final VirtualFile file = ManifestFileUtil.findManifestFile(rootElement, context, type);
|
||||
assertNotNull(file);
|
||||
final Manifest manifest = ManifestFileUtil.readManifest(file);
|
||||
assertEquals(mainClass, manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS));
|
||||
assertEquals(classpath, manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH));
|
||||
}
|
||||
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.intellij.compiler.artifacts;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.testFramework.VfsTestUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class PackagingElementsTestCase extends ArtifactsTestCase {
|
||||
protected Artifact addArtifact(TestPackagingElementBuilder builder) {
|
||||
return addArtifact("a", builder);
|
||||
}
|
||||
|
||||
protected Artifact addArtifact(final String name, TestPackagingElementBuilder builder) {
|
||||
return addArtifact(name, builder.build());
|
||||
}
|
||||
|
||||
protected static void assertLayout(Artifact artifact, String expected) {
|
||||
assertLayout(artifact.getRootElement(), expected);
|
||||
}
|
||||
|
||||
protected static void assertLayout(PackagingElement element, String expected) {
|
||||
ArtifactsTestUtil.assertLayout(element, expected);
|
||||
}
|
||||
|
||||
protected String getProjectBasePath() {
|
||||
return getBaseDir().getPath();
|
||||
}
|
||||
|
||||
protected VirtualFile getBaseDir() {
|
||||
final VirtualFile baseDir = myProject.getBaseDir();
|
||||
assertNotNull(baseDir);
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
protected TestPackagingElementBuilder root() {
|
||||
return TestPackagingElementBuilder.root(myProject);
|
||||
}
|
||||
|
||||
protected TestPackagingElementBuilder archive(String name) {
|
||||
return TestPackagingElementBuilder.archive(myProject, name);
|
||||
}
|
||||
|
||||
protected VirtualFile createFile(final String path) {
|
||||
return createFile(path, "");
|
||||
}
|
||||
|
||||
protected VirtualFile createFile(final String path, final String text) {
|
||||
return VfsTestUtil.createFile(getBaseDir(), path, text);
|
||||
}
|
||||
|
||||
protected VirtualFile createDir(final String path) {
|
||||
return VfsTestUtil.createDir(getBaseDir(), path);
|
||||
}
|
||||
|
||||
protected static VirtualFile getJDomJar() {
|
||||
return getJarFromLibDirectory("jdom.jar");
|
||||
}
|
||||
|
||||
protected static String getLocalJarPath(VirtualFile jarEntry) {
|
||||
return PathUtil.getLocalFile(jarEntry).getPath();
|
||||
}
|
||||
|
||||
protected static String getJUnitJarPath() {
|
||||
return getLocalJarPath(getJarFromLibDirectory("junit.jar"));
|
||||
}
|
||||
|
||||
private static VirtualFile getJarFromLibDirectory(final String relativePath) {
|
||||
final File file = PathManager.findFileInLibDirectory(relativePath);
|
||||
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
|
||||
assertNotNull(file.getAbsolutePath() + " not found", virtualFile);
|
||||
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
|
||||
assertNotNull(jarRoot);
|
||||
return jarRoot;
|
||||
}
|
||||
|
||||
protected Library addProjectLibrary(final @Nullable Module module, final String name, final VirtualFile... jars) {
|
||||
return addProjectLibrary(module, name, DependencyScope.COMPILE, jars);
|
||||
}
|
||||
|
||||
protected Library addProjectLibrary(final @Nullable Module module, final String name, final DependencyScope scope,
|
||||
final VirtualFile... jars) {
|
||||
return addProjectLibrary(myProject, module, name, scope, jars);
|
||||
}
|
||||
|
||||
static Library addProjectLibrary(final Project project, final @Nullable Module module, final String name, final DependencyScope scope,
|
||||
final VirtualFile[] jars) {
|
||||
return new WriteAction<Library>() {
|
||||
@Override
|
||||
protected void run(final Result<Library> result) {
|
||||
final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(project).createLibrary(name);
|
||||
final Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
for (VirtualFile jar : jars) {
|
||||
libraryModel.addRoot(jar, OrderRootType.CLASSES);
|
||||
}
|
||||
libraryModel.commit();
|
||||
if (module != null) {
|
||||
ModuleRootModificationUtil.addDependency(module, library, scope, false);
|
||||
}
|
||||
result.setResult(library);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
protected static void addModuleLibrary(final Module module, final VirtualFile jar) {
|
||||
ModuleRootModificationUtil.addModuleLibrary(module, jar.getUrl());
|
||||
}
|
||||
|
||||
protected static void addModuleDependency(final Module module, final Module dependency) {
|
||||
ModuleRootModificationUtil.addDependency(module, dependency);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.intellij.compiler.artifacts;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementFactory;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class TestPackagingElementBuilder {
|
||||
private final CompositePackagingElement<?> myElement;
|
||||
private final TestPackagingElementBuilder myParent;
|
||||
private final Project myProject;
|
||||
|
||||
private TestPackagingElementBuilder(Project project, CompositePackagingElement<?> element, TestPackagingElementBuilder parent) {
|
||||
myElement = element;
|
||||
myParent = parent;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public static TestPackagingElementBuilder root(Project project) {
|
||||
return new TestPackagingElementBuilder(project, PackagingElementFactory.getInstance().createArtifactRootElement(), null);
|
||||
}
|
||||
|
||||
public static TestPackagingElementBuilder archive(final Project project, String name) {
|
||||
return new TestPackagingElementBuilder(project, PackagingElementFactory.getInstance().createArchive(name), null);
|
||||
}
|
||||
|
||||
public CompositePackagingElement<?> build() {
|
||||
TestPackagingElementBuilder builder = this;
|
||||
while (builder.myParent != null) {
|
||||
builder = builder.myParent;
|
||||
}
|
||||
return builder.myElement;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder file(VirtualFile file) {
|
||||
return file(file.getPath());
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder file(String path) {
|
||||
myElement.addOrFindChild(getFactory().createFileCopyWithParentDirectories(path, "/"));
|
||||
return this;
|
||||
}
|
||||
|
||||
private static PackagingElementFactory getFactory() {
|
||||
return PackagingElementFactory.getInstance();
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder dirCopy(VirtualFile dir) {
|
||||
return dirCopy(dir.getPath());
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder dirCopy(String path) {
|
||||
myElement.addOrFindChild(getFactory().createDirectoryCopyWithParentDirectories(path, "/"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder extractedDir(String jarPath, String pathInJar) {
|
||||
myElement.addOrFindChild(getFactory().createExtractedDirectoryWithParentDirectories(jarPath, pathInJar, "/"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder module(Module module) {
|
||||
myElement.addOrFindChild(getFactory().createModuleOutput(module));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder lib(Library library) {
|
||||
myElement.addOrFindChildren(getFactory().createLibraryElements(library));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder artifact(Artifact artifact) {
|
||||
myElement.addOrFindChild(getFactory().createArtifactElement(artifact, myProject));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder archive(String name) {
|
||||
final CompositePackagingElement<?> archive = getFactory().createArchive(name);
|
||||
return new TestPackagingElementBuilder(myProject, myElement.addOrFindChild(archive), this);
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder dir(String name) {
|
||||
return new TestPackagingElementBuilder(myProject, myElement.addOrFindChild(getFactory().createDirectory(name)), this);
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder add(PackagingElement<?> element) {
|
||||
myElement.addOrFindChild(element);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestPackagingElementBuilder end() {
|
||||
return myParent;
|
||||
}
|
||||
}
|
||||
+33
-35
@@ -15,47 +15,45 @@
|
||||
*/
|
||||
package com.intellij.uiDesigner.make;
|
||||
|
||||
//import com.intellij.compiler.artifacts.ArtifactCompilerTestCase;
|
||||
//import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
//import com.intellij.openapi.module.Module;
|
||||
//import com.intellij.openapi.util.io.FileUtil;
|
||||
//import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
//import com.intellij.openapi.vfs.VirtualFile;
|
||||
//import com.intellij.packaging.artifacts.Artifact;
|
||||
//import com.intellij.uiDesigner.core.AbstractLayout;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
import com.intellij.compiler.artifacts.ArtifactCompilerTestCase;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.uiDesigner.core.AbstractLayout;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class UiDesignerExternalBuildTest /*extends ArtifactCompilerTestCase*/ {
|
||||
//@Override
|
||||
//protected boolean useExternalCompiler() {
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
////IDEA-94779
|
||||
public void _testCopyFormsRuntimeToArtifact() throws IOException {
|
||||
// VirtualFile file = createFile("src/A.java", "class A{}");
|
||||
// VirtualFile srcRoot = file.getParent();
|
||||
// Module module = addModule("a", srcRoot);
|
||||
// Artifact a = addArtifact(root().module(module));
|
||||
// make(a);
|
||||
// assertOutput(a, fs().file("A.class"));
|
||||
//
|
||||
// File dir = PathManagerEx.findFileUnderCommunityHome("plugins/ui-designer/testData/build/copyFormsRuntimeToArtifact");
|
||||
// FileUtil.copyDir(dir, VfsUtilCore.virtualToIoFile(srcRoot));
|
||||
// srcRoot.refresh(false, false);
|
||||
// make(a);
|
||||
// File outputDir = VfsUtilCore.virtualToIoFile(getOutputDir(a));
|
||||
// assertTrue(new File(outputDir, "A.class").exists());
|
||||
// assertTrue(new File(outputDir, "B.class").exists());
|
||||
//
|
||||
// assertTrue(new File(outputDir, AbstractLayout.class.getName().replace('.', '/') + ".class").exists());
|
||||
public class UiDesignerExternalBuildTest extends ArtifactCompilerTestCase {
|
||||
@Override
|
||||
protected boolean useExternalCompiler() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//IDEA-94779
|
||||
public void testCopyFormsRuntimeToArtifact() throws IOException {
|
||||
VirtualFile file = createFile("src/A.java", "class A{}");
|
||||
VirtualFile srcRoot = file.getParent();
|
||||
Module module = addModule("a", srcRoot);
|
||||
Artifact a = addArtifact(root().module(module));
|
||||
make(a);
|
||||
assertOutput(a, fs().file("A.class"));
|
||||
|
||||
File dir = PathManagerEx.findFileUnderCommunityHome("plugins/ui-designer/testData/build/copyFormsRuntimeToArtifact");
|
||||
FileUtil.copyDir(dir, VfsUtilCore.virtualToIoFile(srcRoot));
|
||||
srcRoot.refresh(false, false);
|
||||
make(a);
|
||||
File outputDir = VfsUtilCore.virtualToIoFile(getOutputDir(a));
|
||||
assertTrue(new File(outputDir, "A.class").exists());
|
||||
assertTrue(new File(outputDir, "B.class").exists());
|
||||
|
||||
assertTrue(new File(outputDir, AbstractLayout.class.getName().replace('.', '/') + ".class").exists());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user