diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java index cb6b581d4f55..eaa2293cb824 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java @@ -111,7 +111,7 @@ public class JpsLibraryTableSerializer { } for (Element rootsElement : libraryElement.getChildren()) { final String rootTypeId = rootsElement.getName(); - if (!rootTypeId.equals(JAR_DIRECTORY_TAG)) { + if (!rootTypeId.equals(JAR_DIRECTORY_TAG) && !rootTypeId.equals(PROPERTIES_TAG)) { final JpsOrderRootType rootType = getRootType(rootTypeId); for (Element rootElement : JDOMUtil.getChildren(rootsElement, ROOT_TAG)) { String url = rootElement.getAttributeValue(URL_ATTRIBUTE); diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/RepositoryLibraryDescriptor.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/RepositoryLibraryDescriptor.java new file mode 100644 index 000000000000..c821d94b31e6 --- /dev/null +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/RepositoryLibraryDescriptor.java @@ -0,0 +1,84 @@ +/* + * Copyright 2000-2016 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.maven.model; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Eugene Zhuravlev + * Date: 13-Jun-16 + */ +public class RepositoryLibraryDescriptor { + private final String myMavenId; + private final String myGroupId; + private final String myArtifactId; + private final String myVersion; + + public RepositoryLibraryDescriptor(@NotNull String groupId, @NotNull String artifactId, @NotNull String version) { + myGroupId = groupId; + myArtifactId = artifactId; + myVersion = version; + myMavenId = groupId + ":" + artifactId + ":" + version; + } + + public RepositoryLibraryDescriptor(@Nullable String mavenId) { + myMavenId = mavenId; + if (mavenId == null) { + myGroupId = myArtifactId = myVersion = null; + } + else { + String[] parts = mavenId.split(":"); + myGroupId = parts.length > 0 ? parts[0] : null; + myArtifactId = parts.length > 1 ? parts[1] : null; + myVersion = parts.length > 2 ? parts[2] : null; + } + } + + + public String getMavenId() { + return myMavenId; + } + + public String getGroupId() { + return myGroupId; + } + + public String getArtifactId() { + return myArtifactId; + } + + public String getVersion() { + return myVersion; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RepositoryLibraryDescriptor that = (RepositoryLibraryDescriptor)o; + + if (myMavenId != null ? !myMavenId.equals(that.myMavenId) : that.myMavenId != null) return false; + + return true; + } + + @Override + public int hashCode() { + return myMavenId != null ? myMavenId.hashCode() : 0; + } +} diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenModelSerializationExtension.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenModelSerializationExtension.java index ece4d5cecdf4..7f7a3bf5b851 100644 --- a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenModelSerializationExtension.java +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenModelSerializationExtension.java @@ -6,6 +6,10 @@ import org.jetbrains.jps.maven.model.JpsMavenExtensionService; import org.jetbrains.jps.model.module.JpsDependencyElement; import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; +import org.jetbrains.jps.model.serialization.library.JpsLibraryPropertiesSerializer; + +import java.util.Collections; +import java.util.List; /** * @author nik @@ -41,4 +45,10 @@ public class JpsMavenModelSerializationExtension extends JpsModelSerializerExten orderEntry.setAttribute(PRODUCTION_ON_TEST_ATTRIBUTE, ""); } } + + @NotNull + @Override + public List> getLibraryPropertiesSerializers() { + return Collections.singletonList(JpsMavenRepositoryLibraryType.createPropertiesSerializer()); + } } diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenRepositoryLibraryType.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenRepositoryLibraryType.java new file mode 100644 index 000000000000..782ca6f084d0 --- /dev/null +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/model/impl/JpsMavenRepositoryLibraryType.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2016 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.maven.model.impl; + +import org.jdom.Element; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.maven.model.RepositoryLibraryDescriptor; +import org.jetbrains.jps.model.JpsElementFactory; +import org.jetbrains.jps.model.JpsSimpleElement; +import org.jetbrains.jps.model.ex.JpsElementTypeBase; +import org.jetbrains.jps.model.library.JpsLibraryType; +import org.jetbrains.jps.model.serialization.library.JpsLibraryPropertiesSerializer; + +public class JpsMavenRepositoryLibraryType extends JpsElementTypeBase> + implements JpsLibraryType> { + + public static JpsMavenRepositoryLibraryType INSTANCE = new JpsMavenRepositoryLibraryType(); + private static final String MAVEN_ID_ATTRIBUTE = "maven-id"; + + /** @noinspection MethodMayBeStatic*/ + public final String getTypeId() { + return "repository"; + } + + public static JpsLibraryPropertiesSerializer> createPropertiesSerializer() { + return new JpsLibraryPropertiesSerializer>(INSTANCE, INSTANCE.getTypeId()) { + @Override + public JpsSimpleElement loadProperties(@Nullable Element elem) { + return JpsElementFactory.getInstance().createSimpleElement(new RepositoryLibraryDescriptor( + elem != null? elem.getAttributeValue(MAVEN_ID_ATTRIBUTE, (String)null) : null + )); + } + + @Override + public void saveProperties(JpsSimpleElement properties, Element element) { + final String mavenId = properties.getData().getMavenId(); + if (mavenId != null) { + element.setAttribute(MAVEN_ID_ATTRIBUTE, mavenId); + } + } + }; + } +} diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibraryProperties.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibraryProperties.java index 4aa1d4d5d026..f3d3215eeb81 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibraryProperties.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibraryProperties.java @@ -19,38 +19,30 @@ import com.intellij.openapi.roots.libraries.LibraryProperties; import com.intellij.openapi.util.Comparing; import com.intellij.util.xmlb.annotations.Attribute; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.maven.model.RepositoryLibraryDescriptor; + +import java.util.function.Function; /** * @author nik */ public class RepositoryLibraryProperties extends LibraryProperties { - private String mavenId; - private String groupId; - private String artifactId; - private String version; + private RepositoryLibraryDescriptor myDescriptor; public RepositoryLibraryProperties() { } public RepositoryLibraryProperties(String mavenId) { - setMavenId(mavenId); + myDescriptor = new RepositoryLibraryDescriptor(mavenId); } public RepositoryLibraryProperties(@NotNull String groupId, @NotNull String artifactId, @NotNull String version) { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.mavenId = groupId + ":" + artifactId + ":" + version; + myDescriptor = new RepositoryLibraryDescriptor(groupId, artifactId, version); } @Override public boolean equals(Object obj) { - if (!(obj instanceof RepositoryLibraryProperties)) { - return false; - } - RepositoryLibraryProperties other = (RepositoryLibraryProperties)obj; - return Comparing.equal(mavenId, other.mavenId); - + return obj instanceof RepositoryLibraryProperties && Comparing.equal(myDescriptor, ((RepositoryLibraryProperties)obj).myDescriptor); } @Override @@ -65,41 +57,36 @@ public class RepositoryLibraryProperties extends LibraryProperties 0 ? parts[0] : null; - artifactId = parts.length > 1 ? parts[1] : null; - version = parts.length > 2 ? parts[2] : null; - } + myDescriptor = new RepositoryLibraryDescriptor(mavenId); } public String getGroupId() { - return groupId; + return call(RepositoryLibraryDescriptor::getGroupId); } public String getArtifactId() { - return artifactId; + return call(RepositoryLibraryDescriptor::getArtifactId); } public String getVersion() { - return version; + return call(RepositoryLibraryDescriptor::getVersion); } public void changeVersion(String version) { - this.version = version; - this.mavenId = groupId + ":" + artifactId + ":" + version; + myDescriptor = new RepositoryLibraryDescriptor(getGroupId(), getArtifactId(), version); + } + + private String call(Function method) { + final RepositoryLibraryDescriptor descriptor = myDescriptor; + return descriptor != null ? method.apply(descriptor) : null; } }