diff --git a/.idea/modules.xml b/.idea/modules.xml index 66fc3157477d..69d964ff14a5 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -16,6 +16,7 @@ + diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 818aa55c8ac4..b4ea255f8c12 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -209,7 +209,11 @@ public def layoutCommunityPlugins(String home) { layoutPlugin it } - layoutPlugin("ant", "ant", "antIntegration") + layoutPlugin("ant", "ant", "antIntegration") { + jar("ant-jps-plugin.jar") { + module("ant-jps-plugin") + } + } layoutPlugin("InspectionGadgets", "InspectionGadgetsPlugin") layoutPlugin("IntentionPowerPack", "IntentionPowerPackPlugin") layoutPlugin("ToString", "generate-tostring", "toString") diff --git a/jps/model-serialization/jps-model-serialization.iml b/jps/model-serialization/jps-model-serialization.iml index 08d18aaac7da..2738e97f2275 100644 --- a/jps/model-serialization/jps-model-serialization.iml +++ b/jps/model-serialization/jps-model-serialization.iml @@ -11,7 +11,7 @@ - + diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsModelSerializerExtension.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsModelSerializerExtension.java index 11f68f5fef87..38ca66af9392 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsModelSerializerExtension.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsModelSerializerExtension.java @@ -7,6 +7,7 @@ import org.jetbrains.jps.model.JpsCompositeElement; import org.jetbrains.jps.model.JpsElementReference; import org.jetbrains.jps.model.module.JpsDependencyElement; import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.model.serialization.artifact.JpsArtifactExtensionSerializer; import org.jetbrains.jps.model.serialization.artifact.JpsArtifactPropertiesSerializer; import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementSerializer; import org.jetbrains.jps.model.serialization.facet.JpsFacetConfigurationSerializer; @@ -103,6 +104,10 @@ public abstract class JpsModelSerializerExtension { return Collections.emptyList(); } + public List> getArtifactExtensionSerializers() { + return Collections.emptyList(); + } + @Nullable public JpsModuleClasspathSerializer getClasspathSerializer() { return null; diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactExtensionSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactExtensionSerializer.java new file mode 100644 index 000000000000..34a537de693e --- /dev/null +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactExtensionSerializer.java @@ -0,0 +1,32 @@ +package org.jetbrains.jps.model.serialization.artifact; + +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.JpsElementChildRole; + +/** + * @author nik + */ +public abstract class JpsArtifactExtensionSerializer { + private JpsElementChildRole myRole; + private String myId; + + protected JpsArtifactExtensionSerializer(String id, JpsElementChildRole role) { + myId = id; + myRole = role; + } + + public JpsElementChildRole getRole() { + return myRole; + } + + public String getId() { + return myId; + } + + public abstract E loadExtension(@Nullable Element optionsTag); + + public abstract void saveExtension(@NotNull E extension, @NotNull Element optionsTag); +} diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactSerializer.java index 1705f9599485..c741641a064f 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactSerializer.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/JpsArtifactSerializer.java @@ -14,6 +14,8 @@ import org.jetbrains.jps.model.module.JpsModuleReference; import org.jetbrains.jps.model.serialization.library.JpsLibraryTableSerializer; import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; +import java.util.List; + /** * @author nik */ @@ -50,10 +52,17 @@ public class JpsArtifactSerializer { private static

void loadArtifact(JpsProject project, JpsArtifactService service, ArtifactState state, JpsArtifactPropertiesSerializer

serializer) { JpsPackagingElement rootElement = loadPackagingElement(state.getRootElement()); if (rootElement != null) { + List propertiesList = state.getPropertiesList(); JpsArtifact artifact = service.addArtifact(project, state.getName(), (JpsCompositePackagingElement)rootElement, - serializer.getType(), serializer.loadProperties(state.getPropertiesList())); + serializer.getType(), serializer.loadProperties(propertiesList)); artifact.setBuildOnMake(state.isBuildOnMake()); artifact.setOutputPath(state.getOutputPath()); + for (ArtifactPropertiesState propertiesState : propertiesList) { + JpsArtifactExtensionSerializer extensionSerializer = getExtensionSerializer(propertiesState.getId()); + if (extensionSerializer != null) { + loadExtension(extensionSerializer, artifact, propertiesState.getOptions()); + } + } } } @@ -70,11 +79,38 @@ public class JpsArtifactSerializer { JpsArtifactPropertiesSerializer

serializer) { state.setArtifactType(serializer.getTypeId()); state.setRootElement(savePackagingElement(artifact.getRootElement())); + List propertiesList = state.getPropertiesList(); //noinspection unchecked - serializer.saveProperties((P)artifact.getProperties(), state.getPropertiesList()); + serializer.saveProperties((P)artifact.getProperties(), propertiesList); + for (JpsModelSerializerExtension serializerExtension : JpsModelSerializerExtension.getExtensions()) { + for (JpsArtifactExtensionSerializer extensionSerializer : serializerExtension.getArtifactExtensionSerializers()) { + JpsElement extension = artifact.getContainer().getChild(extensionSerializer.getRole()); + if (extension != null) { + ArtifactPropertiesState propertiesState = new ArtifactPropertiesState(); + propertiesState.setId(extensionSerializer.getId()); + propertiesState.setOptions(saveExtension(extensionSerializer, extension)); + propertiesList.add(propertiesState); + } + } + } componentElement.addContent(XmlSerializer.serialize(state, SERIALIZATION_FILTERS)); } + private static void loadExtension(JpsArtifactExtensionSerializer serializer, + JpsArtifact artifact, + Element options) { + E e = serializer.loadExtension(options); + artifact.getContainer().setChild(serializer.getRole(), e); + } + + private static Element saveExtension(JpsArtifactExtensionSerializer serializer, + E extension) { + Element optionsTag = new Element("options"); + //noinspection unchecked + ((JpsArtifactExtensionSerializer)serializer).saveExtension(extension, optionsTag); + return optionsTag; + } + private static

Element savePackagingElement(P element) { //noinspection unchecked JpsPackagingElementSerializer

serializer = findElementSerializer((Class

)element.getClass()); @@ -148,6 +184,18 @@ public class JpsArtifactSerializer { throw new IllegalArgumentException("Serializer not found for " + elementClass); } + @Nullable + private static JpsArtifactExtensionSerializer getExtensionSerializer(String id) { + for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) { + for (JpsArtifactExtensionSerializer serializer : extension.getArtifactExtensionSerializers()) { + if (serializer.getId().equals(id)) { + return serializer; + } + } + } + return null; + } + private static JpsArtifactPropertiesSerializer getTypePropertiesSerializer(String typeId) { for (JpsArtifactPropertiesSerializer serializer : STANDARD_TYPE_SERIALIZERS) { if (serializer.getTypeId().equals(typeId)) { diff --git a/plugins/ant/ant.iml b/plugins/ant/ant.iml index 61cd5a6bd878..9f7c99239c68 100644 --- a/plugins/ant/ant.iml +++ b/plugins/ant/ant.iml @@ -24,6 +24,7 @@ + diff --git a/plugins/ant/jps-plugin/ant-jps-plugin.iml b/plugins/ant/jps-plugin/ant-jps-plugin.iml new file mode 100644 index 000000000000..95102008ef44 --- /dev/null +++ b/plugins/ant/jps-plugin/ant-jps-plugin.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/ant/jps-plugin/src/META-INF/services/org.jetbrains.jps.model.serialization.JpsModelSerializerExtension b/plugins/ant/jps-plugin/src/META-INF/services/org.jetbrains.jps.model.serialization.JpsModelSerializerExtension new file mode 100644 index 000000000000..00e77bab1796 --- /dev/null +++ b/plugins/ant/jps-plugin/src/META-INF/services/org.jetbrains.jps.model.serialization.JpsModelSerializerExtension @@ -0,0 +1 @@ +org.jetbrains.jps.ant.model.impl.JpsAntModelSerializerExtension \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/BuildFileProperty.java b/plugins/ant/jps-plugin/src/com/intellij/lang/ant/config/impl/BuildFileProperty.java similarity index 78% rename from plugins/ant/src/com/intellij/lang/ant/config/impl/BuildFileProperty.java rename to plugins/ant/jps-plugin/src/com/intellij/lang/ant/config/impl/BuildFileProperty.java index 598682575a0f..6632212e7223 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/BuildFileProperty.java +++ b/plugins/ant/jps-plugin/src/com/intellij/lang/ant/config/impl/BuildFileProperty.java @@ -17,8 +17,6 @@ package com.intellij.lang.ant.config.impl; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.JDOMExternalizable; -import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.util.containers.Convertor; import com.intellij.util.xmlb.annotations.Attribute; import com.intellij.util.xmlb.annotations.Tag; import org.jdom.Element; @@ -30,21 +28,6 @@ public final class BuildFileProperty implements JDOMExternalizable { @NonNls private static final String VALUE = "value"; private String myPropertyName; private String myPropertyValue; - public static final Convertor TO_COMMAND_LINE = new Convertor() { - @NonNls public String convert(BuildFileProperty buildFileProperty) { - @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc(); - try { - builder.append("-D"); - builder.append(buildFileProperty.getPropertyName()); - builder.append('='); - builder.append(buildFileProperty.getPropertyValue()); - return builder.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(builder); - } - } - }; public BuildFileProperty() { this("", ""); diff --git a/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/JpsAntExtensionService.java b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/JpsAntExtensionService.java new file mode 100644 index 000000000000..f41c576b8fdf --- /dev/null +++ b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/JpsAntExtensionService.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2012 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.ant.model; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension; +import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl; +import org.jetbrains.jps.model.artifact.JpsArtifact; + +/** + * @author nik + */ +public class JpsAntExtensionService { + @Nullable + public static JpsAntArtifactExtension getPreprocessingExtension(@NotNull JpsArtifact artifact) { + return artifact.getContainer().getChild(JpsAntArtifactExtensionImpl.PREPROCESSING_ROLE); + } + + @Nullable + public static JpsAntArtifactExtension getPostprocessingExtension(@NotNull JpsArtifact artifact) { + return artifact.getContainer().getChild(JpsAntArtifactExtensionImpl.POSTPROCESSING_ROLE); + } +} diff --git a/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/artifacts/JpsAntArtifactExtension.java b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/artifacts/JpsAntArtifactExtension.java new file mode 100644 index 000000000000..0bc7d2fb6bae --- /dev/null +++ b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/artifacts/JpsAntArtifactExtension.java @@ -0,0 +1,19 @@ +package org.jetbrains.jps.ant.model.artifacts; + +import com.intellij.lang.ant.config.impl.BuildFileProperty; +import org.jetbrains.jps.model.JpsElement; + +import java.util.List; + +/** + * @author nik + */ +public interface JpsAntArtifactExtension extends JpsElement { + boolean isEnabled(); + + String getFileUrl(); + + String getTargetName(); + + List getAntProperties(); +} diff --git a/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/JpsAntModelSerializerExtension.java b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/JpsAntModelSerializerExtension.java new file mode 100644 index 000000000000..e5f6555dd451 --- /dev/null +++ b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/JpsAntModelSerializerExtension.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2012 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.ant.model.impl; + +import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; +import com.intellij.util.xmlb.XmlSerializer; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension; +import org.jetbrains.jps.ant.model.impl.artifacts.AntArtifactExtensionProperties; +import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl; +import org.jetbrains.jps.model.JpsElementChildRole; +import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; +import org.jetbrains.jps.model.serialization.artifact.JpsArtifactExtensionSerializer; + +import java.util.Arrays; +import java.util.List; + +/** + * @author nik + */ +public class JpsAntModelSerializerExtension extends JpsModelSerializerExtension { + @Override + public List> getArtifactExtensionSerializers() { + return Arrays.asList(new JpsAntArtifactExtensionSerializer("ant-postprocessing", JpsAntArtifactExtensionImpl.POSTPROCESSING_ROLE), + new JpsAntArtifactExtensionSerializer("ant-preprocessing", JpsAntArtifactExtensionImpl.PREPROCESSING_ROLE)); + } + + private static class JpsAntArtifactExtensionSerializer extends JpsArtifactExtensionSerializer { + private JpsAntArtifactExtensionSerializer(final String id, final JpsElementChildRole role) { + super(id, role); + } + + @Override + public JpsAntArtifactExtension loadExtension(@Nullable Element optionsTag) { + AntArtifactExtensionProperties properties = optionsTag != null ? XmlSerializer.deserialize(optionsTag, AntArtifactExtensionProperties.class) : null; + return new JpsAntArtifactExtensionImpl(properties != null ? properties : null); + } + + @Override + public void saveExtension(@NotNull JpsAntArtifactExtension extension, @NotNull Element optionsTag) { + AntArtifactExtensionProperties properties = ((JpsAntArtifactExtensionImpl)extension).getProperties(); + XmlSerializer.serializeInto(properties, optionsTag, new SkipDefaultValuesSerializationFilters()); + } + } +} diff --git a/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/artifacts/AntArtifactExtensionProperties.java b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/artifacts/AntArtifactExtensionProperties.java new file mode 100644 index 000000000000..779b4ef36d98 --- /dev/null +++ b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/artifacts/AntArtifactExtensionProperties.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2012 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.ant.model.impl.artifacts; + +import com.intellij.lang.ant.config.impl.BuildFileProperty; +import com.intellij.util.xmlb.annotations.AbstractCollection; +import com.intellij.util.xmlb.annotations.Attribute; +import com.intellij.util.xmlb.annotations.Tag; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class AntArtifactExtensionProperties { + @Tag("file") + public String myFileUrl; + + @Tag("target") + public String myTargetName; + + @Attribute("enabled") + public boolean myEnabled; + + @Tag("build-properties") + @AbstractCollection(surroundWithTag = false) + public List myUserProperties = new ArrayList(); +} diff --git a/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/artifacts/JpsAntArtifactExtensionImpl.java b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/artifacts/JpsAntArtifactExtensionImpl.java new file mode 100644 index 000000000000..43567ff10639 --- /dev/null +++ b/plugins/ant/jps-plugin/src/org/jetbrains/jps/ant/model/impl/artifacts/JpsAntArtifactExtensionImpl.java @@ -0,0 +1,70 @@ +package org.jetbrains.jps.ant.model.impl.artifacts; + +import com.intellij.lang.ant.config.impl.BuildFileProperty; +import com.intellij.util.xmlb.XmlSerializerUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension; +import org.jetbrains.jps.model.JpsElementChildRole; +import org.jetbrains.jps.model.artifact.JpsArtifact; +import org.jetbrains.jps.model.ex.JpsCompositeElementBase; +import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class JpsAntArtifactExtensionImpl extends JpsCompositeElementBase implements JpsAntArtifactExtension { + public static final JpsElementChildRole PREPROCESSING_ROLE = JpsElementChildRoleBase.create("ant preprocessing"); + public static final JpsElementChildRole POSTPROCESSING_ROLE = JpsElementChildRoleBase.create("ant postprocessing"); + @NonNls public static final String ARTIFACT_OUTPUT_PATH_PROPERTY = "artifact.output.path"; + private final AntArtifactExtensionProperties myProperties; + + public JpsAntArtifactExtensionImpl(AntArtifactExtensionProperties properties) { + myProperties = properties; + } + + private JpsAntArtifactExtensionImpl(JpsAntArtifactExtensionImpl original) { + super(original); + myProperties = XmlSerializerUtil.createCopy(original.myProperties); + } + + @NotNull + @Override + public JpsAntArtifactExtensionImpl createCopy() { + return new JpsAntArtifactExtensionImpl(this); + } + + public AntArtifactExtensionProperties getProperties() { + return myProperties; + } + + @Override + public boolean isEnabled() { + return myProperties.myEnabled; + } + + @Override + public String getFileUrl() { + return myProperties.myFileUrl; + } + + @Override + public String getTargetName() { + return myProperties.myTargetName; + } + + private JpsArtifact getArtifact() { + return (JpsArtifact)myParent; + } + + @Override + public List getAntProperties() { + final List properties = new ArrayList(); + properties.add(new BuildFileProperty(ARTIFACT_OUTPUT_PATH_PROPERTY, getArtifact().getOutputPath())); + properties.addAll(myProperties.myUserProperties); + return properties; + } +} diff --git a/plugins/ant/jps-plugin/testData/ant-project/.idea/ant.xml b/plugins/ant/jps-plugin/testData/ant-project/.idea/ant.xml new file mode 100644 index 000000000000..4674eeac9ebb --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/.idea/ant.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/plugins/ant/jps-plugin/testData/ant-project/.idea/artifacts/dir.xml b/plugins/ant/jps-plugin/testData/ant-project/.idea/artifacts/dir.xml new file mode 100644 index 000000000000..fe19aa126116 --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/.idea/artifacts/dir.xml @@ -0,0 +1,21 @@ + + + $PROJECT_DIR$/out/artifacts/dir + + + file://$PROJECT_DIR$/build.xml + create-file + + + + + + + + file://$PROJECT_DIR$/build.xml + show-message + + + + + \ No newline at end of file diff --git a/plugins/ant/jps-plugin/testData/ant-project/.idea/artifacts/jar.xml b/plugins/ant/jps-plugin/testData/ant-project/.idea/artifacts/jar.xml new file mode 100644 index 000000000000..9954178c897e --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/.idea/artifacts/jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/jar + + + + + \ No newline at end of file diff --git a/plugins/ant/jps-plugin/testData/ant-project/.idea/compiler.xml b/plugins/ant/jps-plugin/testData/ant-project/.idea/compiler.xml new file mode 100644 index 000000000000..217af471a9e6 --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/plugins/ant/jps-plugin/testData/ant-project/.idea/misc.xml b/plugins/ant/jps-plugin/testData/ant-project/.idea/misc.xml new file mode 100644 index 000000000000..eb487c644328 --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugins/ant/jps-plugin/testData/ant-project/.idea/modules.xml b/plugins/ant/jps-plugin/testData/ant-project/.idea/modules.xml new file mode 100644 index 000000000000..4ada332fbe3d --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/plugins/ant/jps-plugin/testData/ant-project/ant-project.iml b/plugins/ant/jps-plugin/testData/ant-project/ant-project.iml new file mode 100644 index 000000000000..d5c074327501 --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/ant-project.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/plugins/ant/jps-plugin/testData/ant-project/build.xml b/plugins/ant/jps-plugin/testData/ant-project/build.xml new file mode 100644 index 000000000000..cd54dcb1aa82 --- /dev/null +++ b/plugins/ant/jps-plugin/testData/ant-project/build.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.java b/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.java new file mode 100644 index 000000000000..633a4959babd --- /dev/null +++ b/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2012 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.ant; + +import com.intellij.lang.ant.config.impl.BuildFileProperty; +import org.jetbrains.jps.ant.model.JpsAntExtensionService; +import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension; +import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl; +import org.jetbrains.jps.model.artifact.JpsArtifact; +import org.jetbrains.jps.model.artifact.JpsArtifactService; +import org.jetbrains.jps.model.serialization.JpsSerializationTestCase; + +import java.util.List; + +/** + * @author nik + */ +public class JpsAntSerializationTest extends JpsSerializationTestCase { + private static final String PROJECT_PATH = "plugins/ant/jps-plugin/testData/ant-project"; + + public void testLoadArtifactProperties() { + loadProject(PROJECT_PATH); + List artifacts = JpsArtifactService.getInstance().getSortedArtifacts(myProject); + assertEquals(2, artifacts.size()); + JpsArtifact dir = artifacts.get(0); + assertEquals("dir", dir.getName()); + + JpsAntArtifactExtension preprocessing = JpsAntExtensionService.getPreprocessingExtension(dir); + assertNotNull(preprocessing); + assertTrue(preprocessing.isEnabled()); + assertEquals(getUrl("build.xml"), preprocessing.getFileUrl()); + assertEquals("show-message", preprocessing.getTargetName()); + assertEquals(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, + assertOneElement(preprocessing.getAntProperties()).getPropertyName()); + + JpsAntArtifactExtension postprocessing = JpsAntExtensionService.getPostprocessingExtension(dir); + assertNotNull(postprocessing); + assertEquals(getUrl("build.xml"), postprocessing.getFileUrl()); + assertEquals("create-file", postprocessing.getTargetName()); + List properties = postprocessing.getAntProperties(); + assertEquals(2, properties.size()); + assertEquals(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, properties.get(0).getPropertyName()); + assertEquals(dir.getOutputPath(), properties.get(0).getPropertyValue()); + assertEquals("message.text", properties.get(1).getPropertyName()); + assertEquals("post", properties.get(1).getPropertyValue()); + + + JpsArtifact jar = artifacts.get(1); + assertEquals("jar", jar.getName()); + assertNull(JpsAntExtensionService.getPostprocessingExtension(jar)); + assertNull(JpsAntExtensionService.getPreprocessingExtension(jar)); + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactBuildExtension.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactBuildExtension.java index ee63fa363517..5e650fbd62bc 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactBuildExtension.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactBuildExtension.java @@ -27,6 +27,7 @@ import com.intellij.packaging.elements.ArtifactAntGenerationContext; import com.intellij.util.ArrayUtil; import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl; /** * @author nik @@ -52,7 +53,7 @@ public class AntArtifactBuildExtension extends ChunkBuildExtension { final Tag ant = new Tag("ant", Pair.create("antfile", fileName), Pair.create("target", properties.getTargetName()), Pair.create("dir", relativePath)); final String outputPath = BuildProperties.propertyRef(context.getArtifactOutputProperty(artifact)); - ant.add(new Property(AntArtifactProperties.ARTIFACT_OUTPUT_PATH_PROPERTY, outputPath)); + ant.add(new Property(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, outputPath)); for (BuildFileProperty property : properties.getUserProperties()) { ant.add(new Property(property.getPropertyName(), property.getPropertyValue())); } diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactProperties.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactProperties.java index b8d0d4ba7652..a39f4fca9882 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactProperties.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/artifacts/AntArtifactProperties.java @@ -31,13 +31,10 @@ import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactProperties; import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.ArtifactPropertiesEditor; -import com.intellij.util.xmlb.XmlSerializerUtil; -import com.intellij.util.xmlb.annotations.AbstractCollection; -import com.intellij.util.xmlb.annotations.Attribute; -import com.intellij.util.xmlb.annotations.Tag; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.ant.model.impl.artifacts.AntArtifactExtensionProperties; +import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl; import java.util.ArrayList; import java.util.List; @@ -45,16 +42,9 @@ import java.util.List; /** * @author nik */ -public class AntArtifactProperties extends ArtifactProperties { - @NonNls static final String ARTIFACT_OUTPUT_PATH_PROPERTY = "artifact.output.path"; - private String myFileUrl; - private String myTargetName; - private boolean myEnabled; +public class AntArtifactProperties extends ArtifactProperties { + private AntArtifactExtensionProperties myExtensionProperties = new AntArtifactExtensionProperties(); private boolean myPostProcessing; - private List myUserProperties = new ArrayList(); - - public AntArtifactProperties() { - } public AntArtifactProperties(boolean postProcessing) { myPostProcessing = postProcessing; @@ -64,8 +54,8 @@ public class AntArtifactProperties extends ArtifactProperties getUserProperties() { - return myUserProperties; + return myExtensionProperties.myUserProperties; } public void setUserProperties(List userProperties) { - myUserProperties = userProperties; + myExtensionProperties.myUserProperties = userProperties; } public void setEnabled(boolean enabled) { - myEnabled = enabled; + myExtensionProperties.myEnabled = enabled; } public void setFileUrl(String fileUrl) { - myFileUrl = fileUrl; + myExtensionProperties.myFileUrl = fileUrl; } public void setTargetName(String targetName) { - myTargetName = targetName; + myExtensionProperties.myTargetName = targetName; } @Nullable public AntBuildTarget findTarget(final AntConfiguration antConfiguration) { - if (myFileUrl == null || myTargetName == null) return null; + String fileUrl = getFileUrl(); + String targetName = getTargetName(); + if (fileUrl == null || targetName == null) return null; final AntBuildFile[] buildFiles = antConfiguration.getBuildFiles(); for (AntBuildFile buildFile : buildFiles) { final VirtualFile file = buildFile.getVirtualFile(); - if (file != null && file.getUrl().equals(myFileUrl)) { + if (file != null && file.getUrl().equals(fileUrl)) { final AntBuildModel buildModel = buildFile.getModel(); - return buildModel != null ? buildModel.findTarget(myTargetName) : null; + return buildModel != null ? buildModel.findTarget(targetName) : null; } } return null; @@ -155,12 +142,12 @@ public class AntArtifactProperties extends ArtifactProperties getAllProperties(@NotNull Artifact artifact) { final List properties = new ArrayList(); - properties.add(new BuildFileProperty(ARTIFACT_OUTPUT_PATH_PROPERTY, artifact.getOutputPath())); - properties.addAll(myUserProperties); + properties.add(new BuildFileProperty(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, artifact.getOutputPath())); + properties.addAll(myExtensionProperties.myUserProperties); return properties; } public static boolean isPredefinedProperty(String propertyName) { - return ARTIFACT_OUTPUT_PATH_PROPERTY.equals(propertyName); + return JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY.equals(propertyName); } }