mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
resource java roots: added 'for generated resources' and 'relative output path' properties
This commit is contained in:
+114
-3
@@ -15,18 +15,30 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.CustomShortcutSet;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.SourceFolder;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.roots.IconActionComponent;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsDummyElement;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootProperties;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JavaResourceRootEditHandlerBase extends ModuleSourceRootEditHandler<JpsDummyElement> {
|
||||
protected JavaResourceRootEditHandlerBase(JpsModuleSourceRootType<JpsDummyElement> rootType) {
|
||||
public abstract class JavaResourceRootEditHandlerBase extends ModuleSourceRootEditHandler<JavaResourceRootProperties> {
|
||||
public JavaResourceRootEditHandlerBase(JpsModuleSourceRootType<JavaResourceRootProperties> rootType) {
|
||||
super(rootType);
|
||||
}
|
||||
|
||||
@@ -41,4 +53,103 @@ public abstract class JavaResourceRootEditHandlerBase extends ModuleSourceRootEd
|
||||
public CustomShortcutSet getMarkRootShortcutSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getRootIcon(@NotNull JavaResourceRootProperties properties) {
|
||||
return properties.isForGeneratedSources() ? getGeneratedRootIcon() : getRootIcon();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Icon getGeneratedRootIcon() {
|
||||
return getRootIcon();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPropertiesString(@NotNull JavaResourceRootProperties properties) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
if (properties.isForGeneratedSources()) {
|
||||
buffer.append(" [generated]");
|
||||
}
|
||||
String relativeOutputPath = properties.getRelativeOutputPath();
|
||||
if (!relativeOutputPath.isEmpty()) {
|
||||
buffer.append(" (").append(relativeOutputPath).append(")");
|
||||
}
|
||||
return buffer.length() > 0 ? buffer.toString() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createPropertiesEditor(@NotNull final SourceFolder folder,
|
||||
@NotNull final JComponent parentComponent,
|
||||
@NotNull final ContentRootPanel.ActionCallback callback) {
|
||||
final IconActionComponent iconComponent = new IconActionComponent(AllIcons.Modules.SetPackagePrefix,
|
||||
AllIcons.Modules.SetPackagePrefixRollover,
|
||||
ProjectBundle.message("module.paths.edit.properties.tooltip"),
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JavaResourceRootProperties properties = folder.getJpsElement().getProperties( JavaModuleSourceRootTypes.RESOURCES);
|
||||
assert properties != null;
|
||||
ResourceRootPropertiesDialog
|
||||
dialog = new ResourceRootPropertiesDialog(parentComponent, properties);
|
||||
if (dialog.showAndGet()) {
|
||||
callback.onSourceRootPropertiesChanged(folder);
|
||||
}
|
||||
}
|
||||
});
|
||||
final JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setOpaque(false);
|
||||
panel.add(iconComponent, BorderLayout.CENTER);
|
||||
panel.add(Box.createHorizontalStrut(3), BorderLayout.EAST);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private static class ResourceRootPropertiesDialog extends DialogWrapper {
|
||||
private final JTextField myRelativeOutputPathField;
|
||||
private final JCheckBox myIsGeneratedCheckBox;
|
||||
private final JPanel myMainPanel;
|
||||
@NotNull private final JavaResourceRootProperties myProperties;
|
||||
|
||||
private ResourceRootPropertiesDialog(@NotNull JComponent parentComponent, @NotNull JavaResourceRootProperties properties) {
|
||||
super(parentComponent, true);
|
||||
myProperties = properties;
|
||||
setTitle(ProjectBundle.message("module.paths.edit.properties.title"));
|
||||
myRelativeOutputPathField = new JTextField();
|
||||
myIsGeneratedCheckBox = new JCheckBox(UIUtil.replaceMnemonicAmpersand("For &generated resources"));
|
||||
myMainPanel = FormBuilder.createFormBuilder()
|
||||
.addLabeledComponent("Relative output &path:", myRelativeOutputPathField)
|
||||
.addComponent(myIsGeneratedCheckBox)
|
||||
.getPanel();
|
||||
myRelativeOutputPathField.setText(myProperties.getRelativeOutputPath());
|
||||
myRelativeOutputPathField.setColumns(25);
|
||||
myIsGeneratedCheckBox.setSelected(myProperties.isForGeneratedSources());
|
||||
init();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myRelativeOutputPathField;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
myProperties.setRelativeOutputPath(normalizePath(myRelativeOutputPathField.getText()));
|
||||
myProperties.setForGeneratedSources(myIsGeneratedCheckBox.isSelected());
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String normalizePath(String path) {
|
||||
return StringUtil.trimEnd(StringUtil.trimStart(FileUtil.toSystemIndependentName(path.trim()), "/"), "/");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return myMainPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -51,7 +52,8 @@ public class JavaProjectRootsUtil {
|
||||
|
||||
private static boolean isForGeneratedSources(SourceFolder sourceFolder) {
|
||||
JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
|
||||
return properties != null && properties.isForGeneratedSources();
|
||||
JavaResourceRootProperties resourceProperties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.RESOURCES);
|
||||
return properties != null && properties.isForGeneratedSources() || resourceProperties != null && resourceProperties.isForGeneratedSources();
|
||||
}
|
||||
|
||||
public static boolean isInGeneratedCode(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
|
||||
@@ -32,10 +32,7 @@ import org.jetbrains.jps.cmdline.ProjectDescriptor;
|
||||
import org.jetbrains.jps.indices.IgnoredFileIndex;
|
||||
import org.jetbrains.jps.indices.ModuleExcludeIndex;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||
import org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot;
|
||||
@@ -101,10 +98,11 @@ public final class ResourcesTarget extends JVMModuleBuildTarget<ResourceRootDesc
|
||||
}
|
||||
|
||||
JavaResourceRootType resourceType = isTests() ? JavaResourceRootType.TEST_RESOURCE : JavaResourceRootType.RESOURCE;
|
||||
for (JpsModuleSourceRoot root : myModule.getSourceRoots(resourceType)) {
|
||||
for (JpsTypedModuleSourceRoot<JavaResourceRootProperties> root : myModule.getSourceRoots(resourceType)) {
|
||||
if (!isExcludedFromCompilation(excludedRootProviders, root)) {
|
||||
File rootFile = root.getFile();
|
||||
roots.add(new ResourceRootDescriptor(rootFile, this, "", computeRootExcludes(rootFile, index)));
|
||||
String relativeOutputPath = root.getProperties().getRelativeOutputPath();
|
||||
roots.add(new ResourceRootDescriptor(rootFile, this, relativeOutputPath.replace('/', '.'), computeRootExcludes(rootFile, index)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.jps.builders.rebuild
|
||||
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@@ -71,4 +77,17 @@ public class ModuleRebuildTest: JpsRebuildTestCase() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun testResourceRootWithRelativeOutputPath() {
|
||||
val m = addModule("m")
|
||||
val res = PathUtil.getParentPath(createFile("res/a.txt", "42"))
|
||||
val url = JpsPathUtil.pathToUrl(res)
|
||||
m.addSourceRoot(url, JavaResourceRootType.RESOURCE, JpsJavaExtensionService.getInstance().createResourceRootProperties("foo", false))
|
||||
rebuild()
|
||||
assertOutput(getAbsolutePath("out/production/m"), fs {
|
||||
dir("foo") {
|
||||
file("a.txt", "42")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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 org.jetbrains.jps.model.java;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.ex.JpsElementBase;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JavaResourceRootProperties extends JpsElementBase<JavaResourceRootProperties> {
|
||||
private String myRelativeOutputPath = "";
|
||||
private boolean myForGeneratedSources;
|
||||
|
||||
public JavaResourceRootProperties(@NotNull String relativeOutputPath, boolean forGeneratedSources) {
|
||||
myRelativeOutputPath = relativeOutputPath;
|
||||
myForGeneratedSources = forGeneratedSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return relative path to the target directory under the module output directory for resource files from this root
|
||||
*/
|
||||
@NotNull
|
||||
public String getRelativeOutputPath() {
|
||||
return myRelativeOutputPath;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResourceRootProperties createCopy() {
|
||||
return new JavaResourceRootProperties(myRelativeOutputPath, myForGeneratedSources);
|
||||
}
|
||||
|
||||
public boolean isForGeneratedSources() {
|
||||
return myForGeneratedSources;
|
||||
}
|
||||
|
||||
public void setRelativeOutputPath(@NotNull String relativeOutputPath) {
|
||||
if (!Comparing.equal(myRelativeOutputPath, relativeOutputPath)) {
|
||||
myRelativeOutputPath = relativeOutputPath;
|
||||
fireElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setForGeneratedSources(boolean forGeneratedSources) {
|
||||
if (myForGeneratedSources != forGeneratedSources) {
|
||||
myForGeneratedSources = forGeneratedSources;
|
||||
fireElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyChanges(@NotNull JavaResourceRootProperties modified) {
|
||||
setRelativeOutputPath(modified.myRelativeOutputPath);
|
||||
setForGeneratedSources(modified.myForGeneratedSources);
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,14 @@
|
||||
package org.jetbrains.jps.model.java;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsDummyElement;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.ex.JpsElementTypeWithDummyProperties;
|
||||
import org.jetbrains.jps.model.ex.JpsElementTypeBase;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JavaResourceRootType extends JpsElementTypeWithDummyProperties implements JpsModuleSourceRootType<JpsDummyElement> {
|
||||
public class JavaResourceRootType extends JpsElementTypeBase<JavaResourceRootProperties> implements
|
||||
JpsModuleSourceRootType<JavaResourceRootProperties> {
|
||||
public static final JavaResourceRootType RESOURCE = new JavaResourceRootType();
|
||||
public static final JavaResourceRootType TEST_RESOURCE = new JavaResourceRootType();
|
||||
|
||||
@@ -33,7 +32,7 @@ public class JavaResourceRootType extends JpsElementTypeWithDummyProperties impl
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsDummyElement createDefaultProperties() {
|
||||
return JpsElementFactory.getInstance().createDummyElement();
|
||||
public JavaResourceRootProperties createDefaultProperties() {
|
||||
return JpsJavaExtensionService.getInstance().createResourceRootProperties("", false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,4 +121,7 @@ public abstract class JpsJavaExtensionService {
|
||||
|
||||
@NotNull
|
||||
public abstract JavaSourceRootProperties createSourceRootProperties(@NotNull String packagePrefix);
|
||||
|
||||
@NotNull
|
||||
public abstract JavaResourceRootProperties createResourceRootProperties(@NotNull String relativeOutputPath, boolean forGeneratedResource);
|
||||
}
|
||||
|
||||
@@ -188,6 +188,12 @@ public class JpsJavaExtensionServiceImpl extends JpsJavaExtensionService {
|
||||
return createSourceRootProperties(packagePrefix, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResourceRootProperties createResourceRootProperties(@NotNull String relativeOutputPath, boolean forGeneratedResource) {
|
||||
return new JavaResourceRootProperties(relativeOutputPath, forGeneratedResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JpsProductionModuleOutputPackagingElement createProductionModuleOutput(@NotNull JpsModuleReference moduleReference) {
|
||||
|
||||
+30
-4
@@ -19,7 +19,9 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.*;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.JpsUrlList;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
import org.jetbrains.jps.model.module.JpsDependencyElement;
|
||||
@@ -32,7 +34,6 @@ import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementSeriali
|
||||
import org.jetbrains.jps.model.serialization.java.compiler.*;
|
||||
import org.jetbrains.jps.model.serialization.library.JpsLibraryRootTypeSerializer;
|
||||
import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer;
|
||||
import org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootDummyPropertiesSerializer;
|
||||
import org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -56,6 +57,7 @@ public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension
|
||||
private static final String JAVADOC_PATHS_TAG = "javadoc-paths";
|
||||
private static final String MODULE_LANGUAGE_LEVEL_ATTRIBUTE = "LANGUAGE_LEVEL";
|
||||
public static final String ROOT_TAG = "root";
|
||||
private static final String RELATIVE_OUTPUT_PATH_ATTRIBUTE = "relativeOutputPath";
|
||||
private static final String IS_GENERATED_ATTRIBUTE = "generated";
|
||||
public static final JavaSourceRootPropertiesSerializer JAVA_SOURCE_ROOT_PROPERTIES_SERIALIZER =
|
||||
new JavaSourceRootPropertiesSerializer(JavaSourceRootType.SOURCE, JpsModuleRootModelSerializer.JAVA_SOURCE_ROOT_TYPE_ID);
|
||||
@@ -88,8 +90,8 @@ public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension
|
||||
public List<? extends JpsModuleSourceRootPropertiesSerializer<?>> getModuleSourceRootPropertiesSerializers() {
|
||||
return Arrays.asList(JAVA_SOURCE_ROOT_PROPERTIES_SERIALIZER,
|
||||
new JavaSourceRootPropertiesSerializer(JavaSourceRootType.TEST_SOURCE, JpsModuleRootModelSerializer.JAVA_TEST_ROOT_TYPE_ID),
|
||||
new JpsModuleSourceRootDummyPropertiesSerializer(JavaResourceRootType.RESOURCE, "java-resource"),
|
||||
new JpsModuleSourceRootDummyPropertiesSerializer(JavaResourceRootType.TEST_RESOURCE, "java-test-resource"));
|
||||
new JavaResourceRootPropertiesSerializer(JavaResourceRootType.RESOURCE, "java-resource"),
|
||||
new JavaResourceRootPropertiesSerializer(JavaResourceRootType.TEST_RESOURCE, "java-test-resource"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -328,4 +330,28 @@ public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class JavaResourceRootPropertiesSerializer extends JpsModuleSourceRootPropertiesSerializer<JavaResourceRootProperties> {
|
||||
private JavaResourceRootPropertiesSerializer(JpsModuleSourceRootType<JavaResourceRootProperties> type, String typeId) {
|
||||
super(type, typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaResourceRootProperties loadProperties(@NotNull Element sourceRootTag) {
|
||||
String relativeOutputPath = StringUtil.notNullize(sourceRootTag.getAttributeValue(RELATIVE_OUTPUT_PATH_ATTRIBUTE));
|
||||
boolean isGenerated = Boolean.parseBoolean(sourceRootTag.getAttributeValue(IS_GENERATED_ATTRIBUTE));
|
||||
return getService().createResourceRootProperties(relativeOutputPath, isGenerated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties(@NotNull JavaResourceRootProperties properties, @NotNull Element sourceRootTag) {
|
||||
String relativeOutputPath = properties.getRelativeOutputPath();
|
||||
if (!relativeOutputPath.isEmpty()) {
|
||||
sourceRootTag.setAttribute(RELATIVE_OUTPUT_PATH_ATTRIBUTE, relativeOutputPath);
|
||||
}
|
||||
if (properties.isForGeneratedSources()) {
|
||||
sourceRootTag.setAttribute(IS_GENERATED_ATTRIBUTE, Boolean.TRUE.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen-foo" type="java-resource" relativeOutputPath="foo" generated="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/resourceRoots.iml" filepath="$PROJECT_DIR$/resourceRoots.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.4" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
+23
-3
@@ -151,11 +151,31 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
assertEquals("UTF-8", configuration.getEncoding(new File(getAbsolutePath("other"))));
|
||||
}
|
||||
|
||||
public void testResourceRoots() {
|
||||
String projectPath = "/jps/model-serialization/testData/resourceRoots/";
|
||||
loadProject(projectPath + "resourceRoots.ipr");
|
||||
JpsModule module = assertOneElement(myProject.getModules());
|
||||
List<JpsModuleSourceRoot> roots = module.getSourceRoots();
|
||||
assertSame(JavaSourceRootType.SOURCE, roots.get(0).getRootType());
|
||||
checkResourceRoot(roots.get(1), false, "");
|
||||
checkResourceRoot(roots.get(2), true, "");
|
||||
checkResourceRoot(roots.get(3), true, "foo");
|
||||
doTestSaveModule(module, projectPath + "resourceRoots.iml");
|
||||
}
|
||||
|
||||
private static void checkResourceRoot(JpsModuleSourceRoot root, boolean forGenerated, String relativeOutput) {
|
||||
assertSame(JavaResourceRootType.RESOURCE, root.getRootType());
|
||||
JavaResourceRootProperties properties = root.getProperties(JavaResourceRootType.RESOURCE);
|
||||
assertNotNull(properties);
|
||||
assertEquals(forGenerated, properties.isForGeneratedSources());
|
||||
assertEquals(relativeOutput, properties.getRelativeOutputPath());
|
||||
}
|
||||
|
||||
public void testSaveProject() {
|
||||
loadProject(SAMPLE_PROJECT_PATH);
|
||||
List<JpsModule> modules = myProject.getModules();
|
||||
doTestSaveModule(modules.get(0), "main.iml");
|
||||
doTestSaveModule(modules.get(1), "util/util.iml");
|
||||
doTestSaveModule(modules.get(0), SAMPLE_PROJECT_PATH + "/main.iml");
|
||||
doTestSaveModule(modules.get(1), SAMPLE_PROJECT_PATH + "/util/util.iml");
|
||||
//tod[nik] remember that test output root wasn't specified and doesn't save it to avoid unnecessary modifications of iml files
|
||||
//doTestSaveModule(modules.get(2), "xxx/xxx.iml");
|
||||
|
||||
@@ -188,7 +208,7 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
try {
|
||||
Element actual = JDomSerializationUtil.createComponentElement("NewModuleRootManager");
|
||||
JpsModuleRootModelSerializer.saveRootModel(module, actual);
|
||||
File imlFile = getFileInSampleProject(moduleFilePath);
|
||||
File imlFile = new File(getTestDataFileAbsolutePath(moduleFilePath));
|
||||
Element rootElement = loadModuleRootTag(imlFile);
|
||||
Element expected = JDomSerializationUtil.findComponent(rootElement, "NewModuleRootManager");
|
||||
PlatformTestUtil.assertElementsEqual(expected, actual);
|
||||
|
||||
+11
-3
@@ -28,6 +28,10 @@ import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -58,7 +62,7 @@ public class ContentEntryTreeCellRenderer extends NodeRenderer {
|
||||
if (file != null && file.isDirectory()) {
|
||||
final ContentEntry contentEntry = editor.getContentEntry();
|
||||
if (contentEntry != null) {
|
||||
final String prefix = getPrefix(contentEntry, file);
|
||||
final String prefix = getPresentablePrefix(contentEntry, file);
|
||||
if (!prefix.isEmpty()) {
|
||||
append(" (" + prefix + ")", new SimpleTextAttributes(Font.PLAIN, JBColor.GRAY));
|
||||
}
|
||||
@@ -70,10 +74,14 @@ public class ContentEntryTreeCellRenderer extends NodeRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPrefix(final ContentEntry entry, final VirtualFile file) {
|
||||
private static String getPresentablePrefix(final ContentEntry entry, final VirtualFile file) {
|
||||
for (final SourceFolder sourceFolder : entry.getSourceFolders()) {
|
||||
if (file.equals(sourceFolder.getFile())) {
|
||||
return sourceFolder.getPackagePrefix();
|
||||
JpsModuleSourceRoot element = sourceFolder.getJpsElement();
|
||||
JavaSourceRootProperties properties = element.getProperties(JavaModuleSourceRootTypes.SOURCES);
|
||||
if (properties != null) return properties.getPackagePrefix();
|
||||
JavaResourceRootProperties resourceRootProperties = element.getProperties(JavaModuleSourceRootTypes.RESOURCES);
|
||||
if (resourceRootProperties != null) return resourceRootProperties.getRelativeOutputPath();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
+22
-11
@@ -27,10 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
import org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot;
|
||||
@@ -78,7 +75,14 @@ public class SourceFolderImpl extends ContentFolderBaseImpl implements SourceFol
|
||||
@Override
|
||||
public String getPackagePrefix() {
|
||||
JavaSourceRootProperties properties = getJavaProperties();
|
||||
return properties != null ? properties.getPackagePrefix() : DEFAULT_PACKAGE_PREFIX;
|
||||
if (properties != null) {
|
||||
return properties.getPackagePrefix();
|
||||
}
|
||||
JavaResourceRootProperties resourceJavaProperties = getResourceJavaProperties();
|
||||
if (resourceJavaProperties != null) {
|
||||
return resourceJavaProperties.getRelativeOutputPath().replace('/', '.');
|
||||
}
|
||||
return DEFAULT_PACKAGE_PREFIX;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -86,6 +90,11 @@ public class SourceFolderImpl extends ContentFolderBaseImpl implements SourceFol
|
||||
return myJpsElement.getProperties(JavaModuleSourceRootTypes.SOURCES);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JavaResourceRootProperties getResourceJavaProperties() {
|
||||
return myJpsElement.getProperties(JavaModuleSourceRootTypes.RESOURCES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPackagePrefix(@NotNull String packagePrefix) {
|
||||
JavaSourceRootProperties properties = getJavaProperties();
|
||||
@@ -112,6 +121,12 @@ public class SourceFolderImpl extends ContentFolderBaseImpl implements SourceFol
|
||||
return myJpsElement;
|
||||
}
|
||||
|
||||
private boolean isForGeneratedSources() {
|
||||
JavaSourceRootProperties properties = getJavaProperties();
|
||||
JavaResourceRootProperties resourceJavaProperties = getResourceJavaProperties();
|
||||
return properties != null && properties.isForGeneratedSources() || resourceJavaProperties != null && resourceJavaProperties.isForGeneratedSources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ContentFolderBaseImpl folder) {
|
||||
if (!(folder instanceof SourceFolderImpl)) return -1;
|
||||
@@ -124,12 +139,8 @@ public class SourceFolderImpl extends ContentFolderBaseImpl implements SourceFol
|
||||
if (i!= 0) return i;
|
||||
i = Boolean.valueOf(isTestSource()).compareTo(sourceFolder.isTestSource());
|
||||
if (i != 0) return i;
|
||||
JavaSourceRootProperties properties1 = getJavaProperties();
|
||||
JavaSourceRootProperties properties2 = sourceFolder.getJavaProperties();
|
||||
if (properties1 != null && properties2 != null) {
|
||||
i = Boolean.valueOf(properties1.isForGeneratedSources()).compareTo(properties2.isForGeneratedSources());
|
||||
if (i != 0) return i;
|
||||
}
|
||||
i = Boolean.valueOf(isForGeneratedSources()).compareTo(sourceFolder.isForGeneratedSources());
|
||||
if (i != 0) return i;
|
||||
//todo[nik] perhaps we should use LinkedSet instead of SortedSet and get rid of this method
|
||||
return myJpsElement.getRootType().getClass().getName().compareTo(sourceFolder.getRootType().getClass().getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user