jps model: load ant pre/postprocessing options for artifacts

This commit is contained in:
nik
2012-11-06 13:16:20 +04:00
parent 72fdab422b
commit 05d30b399e
26 changed files with 537 additions and 60 deletions
+1
View File
@@ -16,6 +16,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/android/rt/android-rt.iml" filepath="$PROJECT_DIR$/plugins/android/rt/android-rt.iml" group="plugins/Android" />
<module fileurl="file://$PROJECT_DIR$/platform/annotations/annotations.iml" filepath="$PROJECT_DIR$/platform/annotations/annotations.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/plugins/ant/ant.iml" filepath="$PROJECT_DIR$/plugins/ant/ant.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/ant/jps-plugin/ant-jps-plugin.iml" filepath="$PROJECT_DIR$/plugins/ant/jps-plugin/ant-jps-plugin.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/jps/antLayout/antlayout.iml" filepath="$PROJECT_DIR$/jps/antLayout/antlayout.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/boot/boot.iml" filepath="$PROJECT_DIR$/platform/boot/boot.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/bootstrap/bootstrap.iml" filepath="$PROJECT_DIR$/platform/bootstrap/bootstrap.iml" group="platform" />
+5 -1
View File
@@ -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")
@@ -11,7 +11,7 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="library" exported="" name="JDOM" level="project" />
<orderEntry type="module" module-name="jps-model-impl" scope="TEST" />
<orderEntry type="module" module-name="jps-model-impl" exported="" scope="TEST" />
<orderEntry type="module" module-name="testFramework" exported="" scope="TEST" />
</component>
</module>
@@ -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<? extends JpsArtifactExtensionSerializer<?>> getArtifactExtensionSerializers() {
return Collections.emptyList();
}
@Nullable
public JpsModuleClasspathSerializer getClasspathSerializer() {
return null;
@@ -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<E extends JpsElement> {
private JpsElementChildRole<E> myRole;
private String myId;
protected JpsArtifactExtensionSerializer(String id, JpsElementChildRole<E> role) {
myId = id;
myRole = role;
}
public JpsElementChildRole<E> 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);
}
@@ -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 <P extends JpsElement> void loadArtifact(JpsProject project, JpsArtifactService service, ArtifactState state, JpsArtifactPropertiesSerializer<P> serializer) {
JpsPackagingElement rootElement = loadPackagingElement(state.getRootElement());
if (rootElement != null) {
List<ArtifactPropertiesState> 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<P> serializer) {
state.setArtifactType(serializer.getTypeId());
state.setRootElement(savePackagingElement(artifact.getRootElement()));
List<ArtifactPropertiesState> 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 <E extends JpsElement> void loadExtension(JpsArtifactExtensionSerializer<E> serializer,
JpsArtifact artifact,
Element options) {
E e = serializer.loadExtension(options);
artifact.getContainer().setChild(serializer.getRole(), e);
}
private static <E extends JpsElement> Element saveExtension(JpsArtifactExtensionSerializer<?> serializer,
E extension) {
Element optionsTag = new Element("options");
//noinspection unchecked
((JpsArtifactExtensionSerializer<E>)serializer).saveExtension(extension, optionsTag);
return optionsTag;
}
private static <P extends JpsPackagingElement> Element savePackagingElement(P element) {
//noinspection unchecked
JpsPackagingElementSerializer<P> serializer = findElementSerializer((Class<P>)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)) {
+1
View File
@@ -24,6 +24,7 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="ant-jps-plugin" />
</component>
<component name="copyright">
<Base>
+16
View File
@@ -0,0 +1,16 @@
<?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$/testSrc" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="module" module-name="jps-model-serialization" />
<orderEntry type="module" module-name="util" />
</component>
</module>
@@ -0,0 +1 @@
org.jetbrains.jps.ant.model.impl.JpsAntModelSerializerExtension
@@ -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<BuildFileProperty, String> TO_COMMAND_LINE = new Convertor<BuildFileProperty, String>() {
@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("", "");
@@ -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);
}
}
@@ -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<BuildFileProperty> getAntProperties();
}
@@ -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<? extends JpsArtifactExtensionSerializer<?>> getArtifactExtensionSerializers() {
return Arrays.asList(new JpsAntArtifactExtensionSerializer("ant-postprocessing", JpsAntArtifactExtensionImpl.POSTPROCESSING_ROLE),
new JpsAntArtifactExtensionSerializer("ant-preprocessing", JpsAntArtifactExtensionImpl.PREPROCESSING_ROLE));
}
private static class JpsAntArtifactExtensionSerializer extends JpsArtifactExtensionSerializer<JpsAntArtifactExtension> {
private JpsAntArtifactExtensionSerializer(final String id, final JpsElementChildRole<JpsAntArtifactExtension> 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());
}
}
}
@@ -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<BuildFileProperty> myUserProperties = new ArrayList<BuildFileProperty>();
}
@@ -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<JpsAntArtifactExtensionImpl> implements JpsAntArtifactExtension {
public static final JpsElementChildRole<JpsAntArtifactExtension> PREPROCESSING_ROLE = JpsElementChildRoleBase.create("ant preprocessing");
public static final JpsElementChildRole<JpsAntArtifactExtension> 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<BuildFileProperty> getAntProperties() {
final List<BuildFileProperty> properties = new ArrayList<BuildFileProperty>();
properties.add(new BuildFileProperty(ARTIFACT_OUTPUT_PATH_PROPERTY, getArtifact().getOutputPath()));
properties.addAll(myProperties.myUserProperties);
return properties;
}
}
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<defaultAnt bundledAnt="true" />
<buildFile url="file://$PROJECT_DIR$/build.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />
<maximumHeapSize value="128" />
<maximumStackSize value="2" />
<properties />
</buildFile>
</component>
</project>
@@ -0,0 +1,21 @@
<component name="ArtifactManager">
<artifact name="dir">
<output-path>$PROJECT_DIR$/out/artifacts/dir</output-path>
<properties id="ant-postprocessing">
<options enabled="true">
<file>file://$PROJECT_DIR$/build.xml</file>
<target>create-file</target>
<build-properties>
<build-property name="message.text" value="post" />
</build-properties>
</options>
</properties>
<properties id="ant-preprocessing">
<options enabled="true">
<file>file://$PROJECT_DIR$/build.xml</file>
<target>show-message</target>
</options>
</properties>
<root id="root" />
</artifact>
</component>
@@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="jar">
<output-path>$PROJECT_DIR$/out/artifacts/jar</output-path>
<root id="archive" name="jar.jar">
<element id="artifact" artifact-name="dir" />
</root>
</artifact>
</component>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<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>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ant-project.iml" filepath="$PROJECT_DIR$/ant-project.iml" />
</modules>
</component>
</project>
@@ -0,0 +1,12 @@
<?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" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,9 @@
<project name="ant-project" default="show-message">
<target name="show-message">
<echo message="message"/>
</target>
<target name="create-file">
<echo file="${artifact.output.dir}/echo.txt" message="${message.text}"/>
</target>
</project>
@@ -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<JpsArtifact> 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<BuildFileProperty> 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));
}
}
@@ -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()));
}
@@ -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<AntArtifactProperties> {
@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<AntArtifactExtensionProperties> {
private AntArtifactExtensionProperties myExtensionProperties = new AntArtifactExtensionProperties();
private boolean myPostProcessing;
private List<BuildFileProperty> myUserProperties = new ArrayList<BuildFileProperty>();
public AntArtifactProperties() {
}
public AntArtifactProperties(boolean postProcessing) {
myPostProcessing = postProcessing;
@@ -64,8 +54,8 @@ public class AntArtifactProperties extends ArtifactProperties<AntArtifactPropert
return new AntArtifactPropertiesEditor(this, context, myPostProcessing);
}
public AntArtifactProperties getState() {
return this;
public AntArtifactExtensionProperties getState() {
return myExtensionProperties;
}
@Override
@@ -83,7 +73,7 @@ public class AntArtifactProperties extends ArtifactProperties<AntArtifactPropert
}
private void runAntTarget(CompileContext compileContext, final Artifact artifact) {
if (myEnabled) {
if (myExtensionProperties.myEnabled) {
final Project project = compileContext.getProject();
final AntBuildTarget target = findTarget(AntConfiguration.getInstance(project));
if (target != null) {
@@ -97,57 +87,54 @@ public class AntArtifactProperties extends ArtifactProperties<AntArtifactPropert
}
}
public void loadState(AntArtifactProperties state) {
XmlSerializerUtil.copyBean(state, this);
public void loadState(AntArtifactExtensionProperties state) {
myExtensionProperties = state;
}
@Tag("file")
public String getFileUrl() {
return myFileUrl;
return myExtensionProperties.myFileUrl;
}
@Tag("target")
public String getTargetName() {
return myTargetName;
return myExtensionProperties.myTargetName;
}
@Attribute("enabled")
public boolean isEnabled() {
return myEnabled;
return myExtensionProperties.myEnabled;
}
@Tag("build-properties")
@AbstractCollection(surroundWithTag = false)
public List<BuildFileProperty> getUserProperties() {
return myUserProperties;
return myExtensionProperties.myUserProperties;
}
public void setUserProperties(List<BuildFileProperty> 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<AntArtifactPropert
public List<BuildFileProperty> getAllProperties(@NotNull Artifact artifact) {
final List<BuildFileProperty> properties = new ArrayList<BuildFileProperty>();
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);
}
}