diff --git a/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/EditVersionModel.java b/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/EditVersionModel.java index cc66a43..c7a5edf 100644 --- a/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/EditVersionModel.java +++ b/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/EditVersionModel.java @@ -56,7 +56,7 @@ private void updateProjects() { /* If one project fails to create, we want the others being added nevertheless. */ try { VersioningProject newVersioningProject = new VersioningProject(project); - newVersioningProject.setSelected(isSelected(project.id())); + newVersioningProject.setSelected(isSelected(project.id().getArtifactId())); if (versioningStrategy != null) { newVersioningProject.setNewVersion(versioningStrategy.apply(project.getVersion())); diff --git a/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/VersioningProject.java b/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/VersioningProject.java index b703dc2..9998aa4 100644 --- a/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/VersioningProject.java +++ b/com.inventage.tools.versiontiger.ui/src/main/java/com/inventage/tools/versiontiger/ui/edit/VersioningProject.java @@ -28,7 +28,7 @@ public void applyNewVersion() { } public String getProjectId() { - return project.id(); + return project.id().getArtifactId(); } public MavenVersion getOldVersion() { diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/AbstractVersioningLoggerItem.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/AbstractVersioningLoggerItem.java index 09ba230..a019c7b 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/AbstractVersioningLoggerItem.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/AbstractVersioningLoggerItem.java @@ -8,7 +8,7 @@ public abstract class AbstractVersioningLoggerItem implements VersioningLoggerIt public final static String DELIMITER = " - "; private Project project; - private String originalProject; + private ProjectId originalProjectId; private Version oldVersion; private Version newVersion; private VersioningLoggerStatus versioningLoggerStatus = VersioningLoggerStatus.SUCCESS; @@ -28,16 +28,16 @@ private boolean hasProject() { } @Override - public void setOriginalProject(String originalProject) { - this.originalProject = originalProject; + public void setOriginalProject(ProjectId originalProjectId) { + this.originalProjectId = originalProjectId; } - protected String getOriginalProject() { - return originalProject; + protected ProjectId getOriginalProject() { + return originalProjectId; } private boolean isReference() { - return originalProject != null; + return originalProjectId != null; } @Override @@ -109,7 +109,7 @@ public String formatLine() { if (isReference()) { /* If this is a reference to the examined project in another project, we first display the examined project. */ result.append(DELIMITER); - result.append(originalProject); + result.append(originalProjectId); appendVersionTransistion(result); diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/Project.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/Project.java index a06ead7..9562e5e 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/Project.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/Project.java @@ -2,18 +2,18 @@ public interface Project extends Versionable, Comparable, PropertyHolder { - String id(); + ProjectId id(); String projectPath(); MavenVersion getVersion(); - void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse); + void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse); boolean isVersionInherited(); boolean exists(); - boolean ensureStrictOsgiDependencyTo(String projectId); + boolean ensureStrictOsgiDependencyTo(ProjectId projectId); } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectId.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectId.java new file mode 100644 index 0000000..053ba26 --- /dev/null +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectId.java @@ -0,0 +1,26 @@ +package com.inventage.tools.versiontiger; + +/** + * The project id. + *

It is a composite id from its group id and artifact id.

+ * + * @author Christian Bräm + */ +public interface ProjectId extends Comparable { + + /** + * This separator should be used to concatenate the composite key. + */ + String IDENTIFICATION_SEPARATOR = ":"; + + String getFullId(); + + String getGroupId(); + + String getArtifactId(); + + boolean hasUnknownGroupId(); + + boolean equalsIgnoreGroupIfUnknown(ProjectId id); + +} diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectUniverse.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectUniverse.java index 0dae337..e7e5c2a 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectUniverse.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/ProjectUniverse.java @@ -16,13 +16,17 @@ public interface ProjectUniverse { Set addRootProjectPath(String projectRootFilePath); - String idForProjectPath(String projectPath); + ProjectId idForProjectPath(String projectPath); Set removeProjectsInPath(String path); void removeProject(String projectId); - Project getProjectWithId(String projectId); + void removeProject(ProjectId projectId); + + Project getProjectWithId(String projectIdQuery); + + Project getProjectWithId(ProjectId projectId); Versionable getAllProjects(); @@ -31,7 +35,11 @@ public interface ProjectUniverse { Versionable getAllProjectsWithMatchingIdPattern(String projectIdPattern); void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion); + + void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion); + + boolean ensureStrictOsgiDependencyTo(String projectId); - boolean ensureStrictOsgiDependencyTo(String argument); + boolean ensureStrictOsgiDependencyTo(ProjectId projectId); } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/VersioningLoggerItem.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/VersioningLoggerItem.java index 4f39c14..99c83ac 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/VersioningLoggerItem.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/VersioningLoggerItem.java @@ -9,7 +9,7 @@ public interface VersioningLoggerItem { void setProject(Project project); - void setOriginalProject(String originalProject); + void setOriginalProject(ProjectId originalProjectId); void setOldVersion(Version oldVersion); void setNewVersion(Version newVersion); void setStatus(VersioningLoggerStatus versioningLoggerStatus); diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseApplication.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseApplication.java index 05d70da..c6eb25c 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseApplication.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseApplication.java @@ -4,6 +4,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.OsgiVersion; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.VersioningLogger; import com.inventage.tools.versiontiger.util.FileHandler; @@ -40,7 +41,7 @@ private void setProductVersion(OsgiVersion newVersion, OsgiVersion oldVersion) { } @Override - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { super.updateReferencesFor(id, oldVersion, newVersion, projectUniverse); OsgiVersion oldOsgiVersion = asOsgiVersion(oldVersion); @@ -51,8 +52,8 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion } } - private boolean updateProductVersion(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { - if (id().equals(id)) { + private boolean updateProductVersion(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { + if (id().equalsIgnoreGroupIfUnknown(id)) { productContent = new XmlHandler().writeAttribute(getProductXmlContent(), "product", "version", newVersion.toString()); logSuccess(getProductXmlFile() + ": product#version = " + newVersion, oldVersion, newVersion); @@ -61,7 +62,7 @@ private boolean updateProductVersion(String id, OsgiVersion oldVersion, OsgiVers return false; } - private boolean updateFeatureReferences(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private boolean updateFeatureReferences(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { Element featuresElement = new XmlHandler().getElement(getProductXmlContent(), "product/features"); boolean hasModifications = false; @@ -69,7 +70,7 @@ private boolean updateFeatureReferences(String id, OsgiVersion oldVersion, OsgiV Attribute idAttribute = featureElement.getAttribute("id"); Attribute versionAttribute = featureElement.getAttribute("version"); - if (idAttribute != null && versionAttribute != null && id.equals(idAttribute.getValue())) { + if (idAttribute != null && versionAttribute != null && id.getArtifactId().equals(idAttribute.getValue())) { if (oldVersion == null || oldVersion.toString().equals(versionAttribute.getValue())) { versionAttribute.setValue(newVersion.toString()); hasModifications = true; @@ -93,7 +94,7 @@ private String getProductXmlContent() { } private File getProductXmlFile() { - return new File(projectPath(), id() + ".product"); + return new File(projectPath(), id().getArtifactId() + ".product"); } } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseFeature.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseFeature.java index ce1322b..5614faf 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseFeature.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseFeature.java @@ -5,6 +5,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.OsgiVersion; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.VersioningLogger; import com.inventage.tools.versiontiger.util.FileHandler; @@ -41,7 +42,7 @@ private void setFeatureVersion(OsgiVersion newVersion, OsgiVersion oldVersion) { } @Override - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { super.updateReferencesFor(id, oldVersion, newVersion, projectUniverse); OsgiVersion oldOsgiVersion = asOsgiVersion(oldVersion); @@ -53,8 +54,8 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion } } - private boolean updateFeatureVersion(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { - if (id().equals(id)) { + private boolean updateFeatureVersion(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { + if (id().equalsIgnoreGroupIfUnknown(id)) { featureContent = new XmlHandler().writeAttribute(getFeatureXmlContent(), "feature", "version", newVersion.toString()); logSuccess(getFeatureXmlFile() + ": feature#version = " + newVersion, oldVersion, newVersion); @@ -63,7 +64,7 @@ private boolean updateFeatureVersion(String id, OsgiVersion oldVersion, OsgiVers return false; } - private boolean updateFeatureXmlReferencesFor(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private boolean updateFeatureXmlReferencesFor(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { Element featureElement = new XmlHandler().getElement(getFeatureXmlContent(), "feature"); if (updatePluginReferences(featureElement, "plugin", id, oldVersion, newVersion) @@ -75,13 +76,13 @@ private boolean updateFeatureXmlReferencesFor(String id, OsgiVersion oldVersion, return false; } - private boolean updatePluginReferences(Element featureElement, String elementName, String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private boolean updatePluginReferences(Element featureElement, String elementName, ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { boolean hasModifications = false; List children = featureElement.getChildren(elementName); for (Element child : children) { Attribute idAttribute = child.getAttribute("id"); - if (idAttribute != null && id.equals(idAttribute.getValue())) { + if (idAttribute != null && id.getArtifactId().equals(idAttribute.getValue())) { Attribute versionAttribute = child.getAttribute("version"); if (versionAttribute != null && (oldVersion == null || oldVersion.toString().equals(versionAttribute.getValue()))) { versionAttribute.setValue(newVersion.toString()); diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipsePlugin.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipsePlugin.java index a688e88..1fcf519 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipsePlugin.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipsePlugin.java @@ -5,6 +5,7 @@ import com.inventage.tools.versiontiger.internal.manifest.ManifestParser; import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.OsgiVersion; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.VersioningLogger; import com.inventage.tools.versiontiger.VersioningLoggerItem; @@ -44,7 +45,7 @@ private void setPluginVersion(OsgiVersion newVersion, OsgiVersion oldVersion) { } @Override - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { super.updateReferencesFor(id, oldVersion, newVersion, projectUniverse); OsgiVersion oldOsgiVersion = asOsgiVersion(oldVersion); @@ -61,8 +62,8 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion } } - private boolean updatePluginVersion(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { - if (id().equals(id)) { + private boolean updatePluginVersion(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { + if (id().equalsIgnoreGroupIfUnknown(id)) { Manifest manifest = parseManifest(); manifest.setBundleVersion(newVersion.toString()); manifestContent = manifest.print(); @@ -74,22 +75,22 @@ private boolean updatePluginVersion(String id, OsgiVersion oldVersion, OsgiVersi return false; } - private boolean updateRequireBundleReferences(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private boolean updateRequireBundleReferences(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { Manifest manifest = parseManifest(); VersioningLoggerItem loggerItem = createLoggerItem(oldVersion, newVersion, id); - boolean result = manifest.updateRequireBundleReference(id, oldVersion, newVersion, loggerItem, getVersionFactory().getVersionRangeChangeStrategy()); + boolean result = manifest.updateRequireBundleReference(id.getArtifactId(), oldVersion, newVersion, loggerItem, getVersionFactory().getVersionRangeChangeStrategy()); getLogger().addVersioningLoggerItem(loggerItem); manifestContent = manifest.print(); return result; } - private boolean updateFragmentHostReference(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private boolean updateFragmentHostReference(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { Manifest manifest = parseManifest(); VersioningLoggerItem loggerItem = createLoggerItem(oldVersion, newVersion, id); - boolean result = manifest.updateFragmentHostReference(id, oldVersion, newVersion, loggerItem, getVersionFactory().getVersionRangeChangeStrategy()); + boolean result = manifest.updateFragmentHostReference(id.getArtifactId(), oldVersion, newVersion, loggerItem, getVersionFactory().getVersionRangeChangeStrategy()); getLogger().addVersioningLoggerItem(loggerItem); manifestContent = manifest.print(); @@ -97,12 +98,12 @@ private boolean updateFragmentHostReference(String id, OsgiVersion oldVersion, O } @Override - public boolean ensureStrictOsgiDependencyTo(String projectId) { + public boolean ensureStrictOsgiDependencyTo(ProjectId projectId) { boolean result = super.ensureStrictOsgiDependencyTo(projectId); VersioningLoggerItem loggerItem = createLoggerItem(null, null, projectId); loggerItem.setStatus(VersioningLoggerStatus.ERROR); - if (!parseManifest().ensureStrictDependencyTo(projectId, loggerItem)) { + if (!parseManifest().ensureStrictDependencyTo(projectId.getArtifactId(), loggerItem)) { getLogger().addVersioningLoggerItem(loggerItem); return false; } @@ -130,10 +131,10 @@ private File getManifestFile() { return new File(metaInfFolder, "MANIFEST.MF"); } - private VersioningLoggerItem createLoggerItem(OsgiVersion oldVersion, OsgiVersion newVersion, String originalProject) { + private VersioningLoggerItem createLoggerItem(OsgiVersion oldVersion, OsgiVersion newVersion, ProjectId originalProjectId) { VersioningLoggerItem loggerItem = getLogger().createVersioningLoggerItem(); loggerItem.setProject(this); - loggerItem.setOriginalProject(originalProject); + loggerItem.setOriginalProject(originalProjectId); loggerItem.setOldVersion(oldVersion); loggerItem.setNewVersion(newVersion); diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseRepository.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseRepository.java index 3c6dbd9..829cf37 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseRepository.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseRepository.java @@ -9,6 +9,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.OsgiVersion; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.VersioningLogger; import com.inventage.tools.versiontiger.util.FileHandler; @@ -52,7 +53,7 @@ private void setProductVersion(OsgiVersion newVersion, OsgiVersion oldVersion, F } @Override - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { super.updateReferencesFor(id, oldVersion, newVersion, projectUniverse); OsgiVersion oldOsgiVersion = asOsgiVersion(oldVersion); @@ -62,7 +63,7 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion updateProductReferences(productFile, id, oldOsgiVersion, newOsgiVersion, "product/features", "feature"); updateProductReferences(productFile, id, oldOsgiVersion, newOsgiVersion, "product/plugins", "plugin"); - if (id().equals(id)) { + if (id().equalsIgnoreGroupIfUnknown(id)) { setProductVersion(newOsgiVersion, oldOsgiVersion, productFile); } } @@ -70,7 +71,7 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion updateCategoryFeatureReferences(getCategoryXmlFile(), id, oldOsgiVersion, newOsgiVersion); } - private void updateProductReferences(File file, String id, OsgiVersion oldVersion, OsgiVersion newVersion, String elementsPath, String elementName) { + private void updateProductReferences(File file, ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion, String elementsPath, String elementName) { String content = new FileHandler().readFileContent(file); Element elements = new XmlHandler().getElement(content, elementsPath); @@ -80,7 +81,7 @@ private void updateProductReferences(File file, String id, OsgiVersion oldVersio Attribute idAttribute = element.getAttribute("id"); Attribute versionAttribute = element.getAttribute("version"); - if (idAttribute != null && versionAttribute != null && id.equals(idAttribute.getValue())) { + if (idAttribute != null && versionAttribute != null && id.getArtifactId().equals(idAttribute.getValue())) { if (oldVersion == null || oldVersion.toString().equals(versionAttribute.getValue())) { versionAttribute.setValue(newVersion.toString()); hasModifications = true; @@ -97,17 +98,18 @@ private void updateProductReferences(File file, String id, OsgiVersion oldVersio } } - private void updateCategoryFeatureReferences(File categoryXmlFile, String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private void updateCategoryFeatureReferences(File categoryXmlFile, ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { if (categoryXmlFile.exists()) { String content = getCategoryXmlContent(); Element siteElement = new XmlHandler().getElement(content, "site"); + String aId = id.getArtifactId(); boolean hasModifications = false; for (Element featureElement : siteElement.getChildren("feature")) { Attribute idAttribute = featureElement.getAttribute("id"); Attribute versionAttribute = featureElement.getAttribute("version"); - if (idAttribute != null && versionAttribute != null && id.equals(idAttribute.getValue())) { + if (idAttribute != null && versionAttribute != null && aId.equals(idAttribute.getValue())) { String attributeOldVersion = versionAttribute.getValue(); if (oldVersion == null || oldVersion.toString().equals(attributeOldVersion)) { hasModifications = true; @@ -118,10 +120,10 @@ private void updateCategoryFeatureReferences(File categoryXmlFile, String id, Os Attribute urlAttribute = featureElement.getAttribute("url"); if (urlAttribute != null) { String oldUrl = urlAttribute.getValue(); - Matcher matcher = Pattern.compile(id + "_" + attributeOldVersion, Pattern.LITERAL).matcher(oldUrl); + Matcher matcher = Pattern.compile(aId + "_" + attributeOldVersion, Pattern.LITERAL).matcher(oldUrl); StringBuffer newUrl = new StringBuffer(); while (matcher.find()) { - matcher.appendReplacement(newUrl, id + "_" + newVersion); + matcher.appendReplacement(newUrl, aId + "_" + newVersion); } matcher.appendTail(newUrl); diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseUpdateSite.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseUpdateSite.java index 0f632e3..35fcc5c 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseUpdateSite.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/EclipseUpdateSite.java @@ -6,6 +6,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.OsgiVersion; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.VersioningLogger; import com.inventage.tools.versiontiger.util.FileHandler; @@ -23,7 +24,7 @@ class EclipseUpdateSite extends MavenProjectImpl { } @Override - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { super.updateReferencesFor(id, oldVersion, newVersion, projectUniverse); updateSiteFeatures(id, asOsgiVersion(oldVersion), asOsgiVersion(newVersion)); @@ -33,13 +34,14 @@ private OsgiVersion asOsgiVersion(MavenVersion mavenVersion) { return mavenVersion == null ? null : getVersionFactory().createOsgiVersion(mavenVersion); } - private void updateSiteFeatures(String id, OsgiVersion oldVersion, OsgiVersion newVersion) { + private void updateSiteFeatures(ProjectId id, OsgiVersion oldVersion, OsgiVersion newVersion) { Element siteElement = new XmlHandler().getElement(getSiteXmlContent(), "site"); + String aId = id.getArtifactId(); boolean hasModifications = false; for (Element featureElement : siteElement.getChildren("feature")) { Attribute idAttribute = featureElement.getAttribute("id"); - if (idAttribute != null && id.equals(idAttribute.getValue())) { + if (idAttribute != null && aId.equals(idAttribute.getValue())) { Attribute versionAttribute = featureElement.getAttribute("version"); String attributeOldVersion = versionAttribute.getValue(); if (versionAttribute != null && (oldVersion == null || oldVersion.toString().equals(attributeOldVersion))) { @@ -50,10 +52,10 @@ private void updateSiteFeatures(String id, OsgiVersion oldVersion, OsgiVersion n Attribute urlAttribute = featureElement.getAttribute("url"); if (urlAttribute != null) { String oldUrl = urlAttribute.getValue(); - Matcher matcher = Pattern.compile(id + "_" + attributeOldVersion, Pattern.LITERAL).matcher(oldUrl); + Matcher matcher = Pattern.compile(aId + "_" + attributeOldVersion, Pattern.LITERAL).matcher(oldUrl); StringBuffer newUrl = new StringBuffer(); while (matcher.find()) { - matcher.appendReplacement(newUrl, id + "_" + newVersion); + matcher.appendReplacement(newUrl, aId + "_" + newVersion); } matcher.appendTail(newUrl); diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/InexistingProject.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/InexistingProject.java index 54aa6a8..7df1320 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/InexistingProject.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/InexistingProject.java @@ -2,6 +2,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.Project; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.Version; import com.inventage.tools.versiontiger.VersioningLogger; @@ -66,8 +67,8 @@ public void useReleaseVersionWithSuffix(String newSuffix) { @Override public int compareTo(Project o) { - String thisId = id(); - String otherId = o.id(); + ProjectId thisId = id(); + ProjectId otherId = o.id(); if (thisId != null && otherId != null) { return thisId.compareTo(otherId); } @@ -86,8 +87,8 @@ public String getProperty(String key) { } @Override - public String id() { - return "_INEXISTING: " + projectPath; + public ProjectId id() { + return ProjectIdImpl.create("_INEXISTING", projectPath); } @Override @@ -101,7 +102,7 @@ public MavenVersion getVersion() { } @Override - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { } @Override @@ -127,7 +128,7 @@ public boolean ensureIsRelease() { } @Override - public boolean ensureStrictOsgiDependencyTo(String projectId) { + public boolean ensureStrictOsgiDependencyTo(ProjectId projectId) { return true; } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/KarafFeature.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/KarafFeature.java index f6ee4a6..6c862c2 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/KarafFeature.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/KarafFeature.java @@ -5,6 +5,7 @@ import java.util.Set; import com.inventage.tools.versiontiger.MavenVersion; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.util.FileHandler; import com.inventage.tools.versiontiger.util.XmlHandler; @@ -25,7 +26,7 @@ class KarafFeature { this.filePath = filePath; } - Set updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion) { + Set updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion) { XmlHandler xmlHandler = new XmlHandler(); Set result = new LinkedHashSet(); @@ -49,13 +50,15 @@ Set updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion return result; } - private String updateBundleReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, Element bundle) { + private String updateBundleReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, Element bundle) { String bundleReference = bundle.getTrimmedText(); if (bundleReference.startsWith(BUNDLE_MVN_PREFIX)) { bundleReference = bundleReference.substring(4); String[] gav = bundleReference.split(GAV_SEPARATOR, 3); if (gav != null && gav.length == 3) { - if (id.equals(gav[1]) && (oldVersion == null || gav[2].equals(oldVersion.toString()))) { + ProjectId curId = ProjectIdImpl.create(gav[0], gav[1]); + if (curId.equalsIgnoreGroupIfUnknown(id) && (oldVersion == null || gav[2].equals(oldVersion.toString()))) { + bundleReference = BUNDLE_MVN_PREFIX + gav[0] + GAV_SEPARATOR + gav[1] + GAV_SEPARATOR + newVersion; bundle.setText(bundleReference); return bundle.getChildPath() + " = " + bundleReference; diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/MavenProjectImpl.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/MavenProjectImpl.java index b927bd7..889139d 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/MavenProjectImpl.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/MavenProjectImpl.java @@ -7,6 +7,7 @@ import com.inventage.tools.versiontiger.MavenProject; import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.Project; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.Version; import com.inventage.tools.versiontiger.VersioningLogger; @@ -22,22 +23,22 @@ class MavenProjectImpl implements MavenProject { private final String projectPath; private String pomContent; - private String id; + private ProjectId id; private MavenVersion version; private MavenVersion oldVersion; private final VersioningLogger logger; - private final VersionFactory versionFactory; - + private final VersionFactory versionFactory; + protected MavenProjectImpl(String projectPath, VersioningLogger logger, VersionFactory versionFactory) { this.projectPath = projectPath; this.logger = logger; this.versionFactory = versionFactory; } - + protected VersioningLogger getLogger() { return logger; } - + protected VersionFactory getVersionFactory() { return versionFactory; } @@ -46,9 +47,9 @@ public String projectPath() { return projectPath; } - public String id() { + public ProjectId id() { if (id == null) { - id = new XmlHandler().readElement(getPomContent(), "project/artifactId"); + id = ProjectIdImpl.create(groupId(), artifactId()); } return id; @@ -56,8 +57,8 @@ public String id() { @Override public int compareTo(Project o) { - String thisId = id(); - String otherId = o.id(); + ProjectId thisId = id(); + ProjectId otherId = o.id(); if (thisId != null && otherId != null) { return thisId.compareTo(otherId); } @@ -75,7 +76,7 @@ public MavenVersion getVersion() { return version; } - + @Override public boolean isVersionInherited() { return new XmlHandler().readElement(getPomContent(), "project/version") == null; @@ -113,7 +114,7 @@ public void incrementBugfixVersionAndSnapshot() { public void useReleaseVersion() { setVersion(getVersion().releaseVersion()); } - + @Override public void useReleaseVersionWithSuffix(String newSuffix) { setVersion(getVersion().releaseVersionWithSuffix(newSuffix)); @@ -124,8 +125,13 @@ public void useSnapshotVersion() { } public void setProperty(String key, String value) { + String oldValue = getProperty(key); + if (oldValue == null) { + logError("Unknown property '" + key + "' in project: " + id(), null, null); + return; + } + pomContent = new XmlHandler().writeElement(getPomContent(), "project/properties/" + key, value); - new FileHandler().writeFileContent(getPomXmlFile(), pomContent); logSuccess(getPomXmlFile() + ": project/properties/" + key + " = " + value, null, null); @@ -142,19 +148,19 @@ public String getProperty(String key) { return null; } - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { Element projectElement = new XmlHandler().getElement(getPomContent(), "project"); Element dependenciesElement = projectElement.getChild("dependencies"); Element dependencyManagementElement = projectElement.getChild("dependencyManagement/dependencies"); - + if (oldVersion == null || !oldVersion.equals(newVersion)) { if (updateDependencies(dependenciesElement, id, oldVersion, newVersion) | updateDependencies(dependencyManagementElement, id, oldVersion, newVersion) | updateParent(projectElement, id, oldVersion, newVersion, projectUniverse)) { - + pomContent = projectElement.getDocument().toXML(); new FileHandler().writeFileContent(getPomXmlFile(), pomContent); } - + for (File karafFile : getKarafFiles()) { Set updatedReferences = new KarafFeature(karafFile).updateReferencesFor(id, oldVersion, newVersion); for (String updatedKarafReference : updatedReferences) { @@ -164,14 +170,28 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion } } - private boolean updateDependencies(Element dependenciesElement, String id, MavenVersion oldVersion, MavenVersion newVersion) { + private String groupId() { + String groupId = new XmlHandler().readElement(getPomContent(), "project/groupId"); + if (groupId == null) { + groupId = new XmlHandler().readElement(getPomContent(), "project/parent/groupId"); + } + return groupId; + } + + private String artifactId() { + return new XmlHandler().readElement(getPomContent(), "project/artifactId"); + } + + private boolean updateDependencies(Element dependenciesElement, ProjectId id, MavenVersion oldVersion, MavenVersion newVersion) { boolean hasModifications = false; if (dependenciesElement != null) { for (Element dependencyElement : dependenciesElement.getChildren()) { + Element groupIdElement = dependencyElement.getChild("groupId"); Element artifactIdElement = dependencyElement.getChild("artifactId"); Element versionElement = dependencyElement.getChild("version"); - if (artifactIdElement != null && versionElement != null && id.equals(artifactIdElement.getTrimmedText()) + ProjectId curId = getIdFromElements(groupIdElement, artifactIdElement); + if (curId.equalsIgnoreGroupIfUnknown(id) && versionElement != null && (oldVersion == null || oldVersion.toString().equals(versionElement.getTrimmedText()))) { // reference match @@ -186,20 +206,23 @@ private boolean updateDependencies(Element dependenciesElement, String id, Maven return hasModifications; } - private boolean updateParent(Element projectElement, String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + private boolean updateParent(Element projectElement, ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { boolean hasModifications = false; Element parentElement = projectElement.getChild("parent"); if (parentElement != null) { + Element groupIdElement = parentElement.getChild("groupId"); Element artifactIdElement = parentElement.getChild("artifactId"); Element versionElement = parentElement.getChild("version"); - if (artifactIdElement != null && id.equals(artifactIdElement.getTrimmedText()) && versionElement != null + ProjectId curId = getIdFromElements(groupIdElement, artifactIdElement); + + if (curId.equalsIgnoreGroupIfUnknown(id) && versionElement != null && (oldVersion == null || versionElement.getTrimmedText().equals(oldVersion.toString()))) { versionElement.setText(newVersion.toString()); hasModifications = true; logReferenceSuccess(getPomXmlFile() + ": " + versionElement.getChildPath() + " = " + newVersion, oldVersion, newVersion, id); - + if (isVersionInherited()) { // our (inherited) version changed so lets propagate our version change too projectUniverse.updateReferencesFor(id(), oldVersion, newVersion); @@ -209,10 +232,18 @@ private boolean updateParent(Element projectElement, String id, MavenVersion old return hasModifications; } - + + private ProjectId getIdFromElements(Element groupIdElement, Element artifactIdElement) { + ProjectId compositeId = null; + if (groupIdElement != null && artifactIdElement != null) { + compositeId = ProjectIdImpl.create(groupIdElement.getTrimmedText(), artifactIdElement.getTrimmedText()); + } + return compositeId; + } + private Set getKarafFiles() { Set result = new LinkedHashSet(); - + Element propertyElement = new XmlHandler().getElement(getPomContent(), "project/properties/versionTigerFiles"); if (propertyElement != null) { String propertyValue = propertyElement.getText(); @@ -227,10 +258,10 @@ private Set getKarafFiles() { } } } - + return result; } - + private void setVersionInKarafFiles(MavenVersion oldVersion, MavenVersion newVersion) { for (File karafFile : getKarafFiles()) { Set updatedReferences = new KarafFeature(karafFile).updateReferencesFor(id, oldVersion, newVersion); @@ -251,40 +282,40 @@ private String getPomContent() { return pomContent; } - + protected void logSuccess(String message, Version oldVersion, Version newVersion) { log(message, VersioningLoggerStatus.SUCCESS, oldVersion, newVersion, null); } - - protected void logReferenceSuccess(String message, Version oldVersion, Version newVersion, String originalProject) { - log(message, VersioningLoggerStatus.SUCCESS, oldVersion, newVersion, originalProject); + + protected void logReferenceSuccess(String message, Version oldVersion, Version newVersion, ProjectId originalProjectId) { + log(message, VersioningLoggerStatus.SUCCESS, oldVersion, newVersion, originalProjectId); } - + protected void logWarning(String message, Version oldVersion, Version newVersion) { log(message, VersioningLoggerStatus.WARNING, oldVersion, newVersion, null); } - + protected void logError(String message, Version oldVersion, Version newVersion) { log(message, VersioningLoggerStatus.ERROR, oldVersion, newVersion, null); } - - protected void logReferenceError(String message, Version oldVersion, Version newVersion, String originalProject) { - log(message, VersioningLoggerStatus.ERROR, oldVersion, newVersion, originalProject); + + protected void logReferenceError(String message, Version oldVersion, Version newVersion, ProjectId originalProjectId) { + log(message, VersioningLoggerStatus.ERROR, oldVersion, newVersion, originalProjectId); } - - private void log(String message, VersioningLoggerStatus status, Version oldVersion, Version newVersion, String originalProject) { + + private void log(String message, VersioningLoggerStatus status, Version oldVersion, Version newVersion, ProjectId originalProjectId) { VersioningLoggerItem loggerItem = logger.createVersioningLoggerItem(); - + loggerItem.setProject(this); loggerItem.setStatus(status); - - loggerItem.setOriginalProject(originalProject); - + + loggerItem.setOriginalProject(originalProjectId); + loggerItem.setOldVersion(oldVersion); loggerItem.setNewVersion(newVersion); - + loggerItem.appendToMessage(message); - + logger.addVersioningLoggerItem(loggerItem); } @@ -297,7 +328,7 @@ public String toString() { public boolean exists() { return true; } - + @Override public boolean ensureIsSnapshot() { if (!getVersion().isSnapshot()) { @@ -315,9 +346,9 @@ public boolean ensureIsRelease() { } return true; } - + @Override - public boolean ensureStrictOsgiDependencyTo(String projectId) { + public boolean ensureStrictOsgiDependencyTo(ProjectId projectId) { return true; } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectIdImpl.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectIdImpl.java new file mode 100644 index 0000000..ae50fdf --- /dev/null +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectIdImpl.java @@ -0,0 +1,112 @@ +package com.inventage.tools.versiontiger.internal.impl; + +import com.inventage.tools.versiontiger.Project; +import com.inventage.tools.versiontiger.ProjectId; + +/** + * The id of a {@link Project}. + * + * @author Christian Bräm + */ +public class ProjectIdImpl implements ProjectId { + + private static final String UNKNOWN_GROUP = ".UnknownGroupId"; + + private final String groupId; + private final String artifactId; + + public static ProjectId createWithUnknownGroup(String artifactId) { + return new ProjectIdImpl(UNKNOWN_GROUP, artifactId); + } + + public static ProjectId create(String groupId, String artifactId) { + return new ProjectIdImpl(groupId, artifactId); + } + + /** + * The constructor for project ids. + * + * @param groupId the group id. + * @param artifactId the artifact id. Must not be {@code null}. + */ + protected ProjectIdImpl(String groupId, String artifactId) { + if (groupId == null || artifactId == null) { + throw new IllegalArgumentException("Illegal project id: groupId=" + groupId + ", artifactId=" + artifactId); + } + + this.groupId = groupId; + this.artifactId = artifactId; + } + + @Override + public String getFullId() { + return groupId + IDENTIFICATION_SEPARATOR + artifactId; + } + + @Override + public String getGroupId() { + return groupId; + } + + @Override + public boolean hasUnknownGroupId() { + return UNKNOWN_GROUP.equals(getGroupId()); + } + + @Override + public boolean equalsIgnoreGroupIfUnknown(ProjectId id) { + return getArtifactId().equals(id.getArtifactId()) && (hasUnknownGroupId() || id.hasUnknownGroupId() || getGroupId().equals(id.getGroupId())); + } + + @Override + public String getArtifactId() { + return artifactId; + } + + @Override + public String toString() { + return getFullId(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + artifactId.hashCode(); + result = prime * result + groupId.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ProjectIdImpl other = (ProjectIdImpl) obj; + if (!artifactId.equals(other.artifactId)) { + return false; + } + if (!groupId.equals(other.groupId)) { + return false; + } + return true; + } + + @Override + public int compareTo(ProjectId other) { + int result = getGroupId().compareTo(other.getGroupId()); + + if (result == 0) { + result = getArtifactId().compareTo(other.getArtifactId()); + } + + return result; + } + +} diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectUniverseImpl.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectUniverseImpl.java index d55ca23..98326ee 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectUniverseImpl.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ProjectUniverseImpl.java @@ -1,9 +1,14 @@ package com.inventage.tools.versiontiger.internal.impl; +import static com.inventage.tools.versiontiger.ProjectId.IDENTIFICATION_SEPARATOR; + import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -11,6 +16,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.Project; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.Versionable; import com.inventage.tools.versiontiger.VersioningLogger; @@ -20,12 +26,14 @@ class ProjectUniverseImpl implements ProjectUniverse { - private final Map projects = new TreeMap(); + private static final Pattern SEPARATOR_PATTERN = Pattern.compile("[^(]:"); + + private final Map projects = new TreeMap(); private final String id; private final String name; private final ProjectFactory projectFactory; private final VersioningLogger logger; - + ProjectUniverseImpl(String id, ProjectFactory projectFactory, VersioningLogger logger) { this(id, null, projectFactory, logger); } @@ -34,7 +42,7 @@ class ProjectUniverseImpl implements ProjectUniverse { this.id = id; this.name = name; this.projectFactory = projectFactory; - + this.logger = logger; } @@ -51,14 +59,14 @@ public String name() { public Project createProjectFromPath(String projectRootFilePath) { return projectFactory.createProjectFromRootFilePath(projectRootFilePath, logger); } - + @Override public void addProject(Project project) { if (project != null) { projects.put(project.id(), project); } } - + @Override public Project addProjectPath(String projectRootFilePath) { Project project = projectFactory.createProjectFromRootFilePath(projectRootFilePath, logger); @@ -72,30 +80,30 @@ public Project addProjectPath(String projectRootFilePath) { logItem.appendToMessage("Removing project from universe (id conflict): " + existingProject.projectPath()); logger.addVersioningLoggerItem(logItem); } - + projects.put(project.id(), project); } return project; } - + @Override public Set addRootProjectPath(String projectRootFilePath) { Set recursiveProjects = projectFactory.createRecursiveProjectsFromRootFilePath(projectRootFilePath, logger); Set result = new HashSet(); - + for (Project project: recursiveProjects) { projects.put(project.id(), project); result.add(project); } - + return result; } @Override - public String idForProjectPath(String projectPath) { + public ProjectId idForProjectPath(String projectPath) { File canonicalProjectPath = new FileHandler().getCanonicalFile(new File(projectPath)); - + for (Project project : projects.values()) { if (canonicalProjectPath.equals(new File(project.projectPath()))) { return project.id(); @@ -106,30 +114,35 @@ public String idForProjectPath(String projectPath) { @Override public void removeProject(String projectId) { + removeProject(createProjectIdQuery(projectId)); + } + + @Override + public void removeProject(ProjectId projectId) { if (projectId != null) { projects.remove(projectId); } } - + @Override public Set removeProjectsInPath(String path) { FileHandler fileHandler = new FileHandler(); String matcherPath = fileHandler.getCanonicalPath(new File(path)); - + Set result = new HashSet(); for (Project project : new ArrayList(projects.values())) { String currentPath = fileHandler.getCanonicalPath(new File(project.projectPath())); if (currentPath.startsWith(matcherPath)) { projects.remove(project.id()); result.add(project); - + VersioningLoggerItem loggerItem = logger.createVersioningLoggerItem(); loggerItem.setStatus(VersioningLoggerStatus.SUCCESS); loggerItem.appendToMessage("Removed project: " + project.id()); logger.addVersioningLoggerItem(loggerItem); } } - + return result; } @@ -145,8 +158,14 @@ public Set listAllProjects() { @Override public Project getProjectWithId(String projectId) { - if (projects.containsKey(projectId)) { - return new ReferencesUpdater(projects.get(projectId), this, logger); + return getProjectWithId(createProjectIdQuery(projectId)); + } + + @Override + public Project getProjectWithId(ProjectId projectId) { + Project project = projects.get(projectId); + if (project != null) { + return new ReferencesUpdater(project, this, logger); } return null; } @@ -159,19 +178,51 @@ public Versionable getAllProjects() { @Override public Versionable getAllProjectsWithMatchingIdPattern(String projectIdPattern) { Set result = new LinkedHashSet(); - Pattern pattern = Pattern.compile(projectIdPattern); + + final Pattern pattern; + final boolean legacyPattern; + + if (! SEPARATOR_PATTERN.matcher(projectIdPattern).find()) { + // make old version compatible + final String newPatternString = ".+" + IDENTIFICATION_SEPARATOR + projectIdPattern; + pattern = Pattern.compile(newPatternString); + legacyPattern = true; + } else { + pattern = Pattern.compile(projectIdPattern); + legacyPattern = false; + } for (Project project : listAllProjects()) { - if (pattern.matcher(project.id()).matches()) { + if (pattern.matcher(project.id().getFullId()).matches()) { result.add(project); } } + if (result.isEmpty()) { + VersioningLoggerItem loggerItem = logger.createVersioningLoggerItem(); + loggerItem.setStatus(VersioningLoggerStatus.WARNING); + loggerItem.appendToMessage("No project matched the pattern: " + pattern); + logger.addVersioningLoggerItem(loggerItem); + } + else if (legacyPattern && result.size() > 1 && hasProjectsWithSameArtifactId()) { + VersioningLoggerItem loggerItem = logger.createVersioningLoggerItem(); + loggerItem.setStatus(VersioningLoggerStatus.WARNING); + loggerItem.appendToMessage("The pattern '" + projectIdPattern + "' may match too many projects since the pattern doesn't include a group id pattern " + + "and there are multiple projects with the same artifact id. " + + "A fully specified project id pattern looks like this: \"groupId" + IDENTIFICATION_SEPARATOR + "artifactId\"."); + logger.addVersioningLoggerItem(loggerItem); + } + return new MultiProjectVersionable(result); } @Override public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion) { + updateReferencesFor(createProjectIdQuery(id), oldVersion, newVersion); + } + + @Override + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion) { for (Project project : listAllProjects()) { project.updateReferencesFor(id, oldVersion, newVersion, this); } @@ -179,6 +230,11 @@ public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion @Override public boolean ensureStrictOsgiDependencyTo(String projectId) { + return ensureStrictOsgiDependencyTo(createProjectIdQuery(projectId)); + } + + @Override + public boolean ensureStrictOsgiDependencyTo(ProjectId projectId) { boolean result = true; for (Project project : listAllProjects()) { if (!project.ensureStrictOsgiDependencyTo(projectId)) { @@ -187,4 +243,59 @@ public boolean ensureStrictOsgiDependencyTo(String projectId) { } return result; } + + private boolean hasProjectsWithSameArtifactId() { + Set artifactIds = new HashSet(); + + for (ProjectId projectId : projects.keySet()) { + if (artifactIds.contains(projectId.getArtifactId())) { + return true; + } + artifactIds.add(projectId.getArtifactId()); + } + + return false; + } + + @SuppressWarnings("unchecked") + private ProjectId createProjectIdQuery(String projectIdQuery) { + if (projectIdQuery == null) { + throw new IllegalArgumentException("The project id should not be null"); + } + + String[] ids = projectIdQuery.split(IDENTIFICATION_SEPARATOR, 2); + if (ids.length == 1) { + String artifactId = projectIdQuery; + + List similarIds = new LinkedList(); + for (Project project : listAllProjects()) { + String projectArtifactId = project.id().getArtifactId(); + if (artifactId.equals(projectArtifactId)) { + similarIds.add(project.id()); + } + } + + if (similarIds.size() > 1) { + throw new IllegalStateException("Project id (" + projectIdQuery + + ") is not unique: multiple candidates found: " + Arrays.asList(similarIds)); + } + else if (similarIds.isEmpty()) { + VersioningLoggerItem loggerItem = logger.createVersioningLoggerItem(); + loggerItem.appendToMessage("Project unknown to universe: " + projectIdQuery); + loggerItem.setStatus(VersioningLoggerStatus.WARNING); + logger.addVersioningLoggerItem(loggerItem); + + return ProjectIdImpl.createWithUnknownGroup(artifactId); + } + return similarIds.get(0); + + } else if (ids.length == 2){ + String groupId = ids[0]; + String artifactId = ids[1]; + return ProjectIdImpl.create(groupId, artifactId); + } + else { + throw new IllegalArgumentException("Invalid project id: " + projectIdQuery); + } + } } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ReferencesUpdater.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ReferencesUpdater.java index 1213903..5cff8e8 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ReferencesUpdater.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/ReferencesUpdater.java @@ -2,6 +2,7 @@ import com.inventage.tools.versiontiger.MavenVersion; import com.inventage.tools.versiontiger.Project; +import com.inventage.tools.versiontiger.ProjectId; import com.inventage.tools.versiontiger.ProjectUniverse; import com.inventage.tools.versiontiger.VersioningLogger; import com.inventage.tools.versiontiger.VersioningLoggerItem; @@ -32,7 +33,7 @@ public void setVersion(MavenVersion newVersion) { projectUniverse.updateReferencesFor(project.id(), oldVersion, newVersion); } - public String id() { + public ProjectId id() { return project.id(); } @@ -70,7 +71,7 @@ public void useReleaseVersionWithSuffix(String newSuffix) { setVersion(getVersion().releaseVersionWithSuffix(newSuffix)); } - public void updateReferencesFor(String id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { + public void updateReferencesFor(ProjectId id, MavenVersion oldVersion, MavenVersion newVersion, ProjectUniverse projectUniverse) { project.updateReferencesFor(id, oldVersion, newVersion, projectUniverse); } @@ -119,7 +120,7 @@ public boolean ensureIsRelease() { } @Override - public boolean ensureStrictOsgiDependencyTo(String projectId) { + public boolean ensureStrictOsgiDependencyTo(ProjectId projectId) { return project.ensureStrictOsgiDependencyTo(projectId); } diff --git a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/VersionTigerBatchOperation.java b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/VersionTigerBatchOperation.java index 581eb4e..c83ca7b 100644 --- a/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/VersionTigerBatchOperation.java +++ b/com.inventage.tools.versiontiger/src/main/java/com/inventage/tools/versiontiger/internal/impl/VersionTigerBatchOperation.java @@ -49,7 +49,7 @@ void internalExecute(CommandExecuter commandExecuter, Command command) { logMessage(commandExecuter.getLogger(), "Summary: Added " + projects.size() + " projects."); } }, - IGNOREPROJECT(1, "ignoreProject ") { + IGNOREPROJECT(1, "ignoreProject ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { String projectId = command.getArgument(0); @@ -65,56 +65,56 @@ void internalExecute(CommandExecuter commandExecuter, Command command) { logSuccess(commandExecuter.getLogger(), "Ignored " + removedProjects.size() + " projects in: " + path); } }, - VERSION(2, "version <1.2.3-SNAPSHOT>") { + VERSION(2, "version <1.2.3-SNAPSHOT>") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.setVersion(commandExecuter.getVersioning().createMavenVersion(command.getArgument(1))); } }, - INCREMENTMAJOR(1, "incrementMajor ") { + INCREMENTMAJOR(1, "incrementMajor ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.incrementMajorVersionAndSnapshot(); } }, - INCREMENTMINOR(1, "incrementMinor ") { + INCREMENTMINOR(1, "incrementMinor ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.incrementMinorVersionAndSnapshot(); } }, - INCREMENTBUGFIX(1, "incrementBugfix ") { + INCREMENTBUGFIX(1, "incrementBugfix ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.incrementBugfixVersionAndSnapshot(); } }, - RELEASE(1, "release ") { + RELEASE(1, "release ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.useReleaseVersion(); } }, - SNAPSHOT(1, "snapshot ") { + SNAPSHOT(1, "snapshot ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.useSnapshotVersion(); } }, - RELEASEWITHSUFFIX(2, "releaseWithSuffix ") { + RELEASEWITHSUFFIX(2, "releaseWithSuffix ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable versionable = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); versionable.useReleaseVersionWithSuffix(command.getArgument(1)); } }, - UPDATEREFERENCES(2, "updateReferences <1.2.3-SNAPSHOT>") { + UPDATEREFERENCES(2, "updateReferences <1.2.3-SNAPSHOT>") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { commandExecuter.getUniverse().updateReferencesFor(command.getArgument(0), null, commandExecuter.getVersioning().createMavenVersion(command.getArgument(1))); @@ -133,7 +133,7 @@ void internalExecute(CommandExecuter commandExecuter, Command command) { Collections.sort(projects); for (Project project : projects) { - logMessage(commandExecuter.getLogger(), project.id()); + logMessage(commandExecuter.getLogger(), project.id().toString()); } } }, @@ -199,7 +199,7 @@ void internalExecute(CommandExecuter commandExecuter, Command command) { } } }, - ENSURESNAPSHOT(1, "ensureSnapshot ") { + ENSURESNAPSHOT(1, "ensureSnapshot ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable projects = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0)); @@ -212,7 +212,7 @@ void internalExecute(CommandExecuter commandExecuter, Command command) { } } }, - ENSURERELEASE(1, "ensureRelease ") { + ENSURERELEASE(1, "ensureRelease ") { @Override void internalExecute(CommandExecuter commandExecuter, Command command) { Versionable projects = commandExecuter.getUniverse().getAllProjectsWithMatchingIdPattern(command.getArgument(0));