Skip to content

Commit

Permalink
Do Not ignore Maven group ids #59
Browse files Browse the repository at this point in the history
  • Loading branch information
b8 committed Nov 13, 2018
1 parent 98fea65 commit 588e252
Show file tree
Hide file tree
Showing 19 changed files with 440 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void applyNewVersion() {
}

public String getProjectId() {
return project.id();
return project.id().getArtifactId();
}

public MavenVersion getOldVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

public interface Project extends Versionable, Comparable<Project>, 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);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.inventage.tools.versiontiger;

/**
* The project id.
* <p>It is a composite id from its group id and artifact id.</p>
*
* @author Christian Bräm
*/
public interface ProjectId extends Comparable<ProjectId> {

/**
* 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ public interface ProjectUniverse {

Set<Project> addRootProjectPath(String projectRootFilePath);

String idForProjectPath(String projectPath);
ProjectId idForProjectPath(String projectPath);

Set<Project> 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();

Expand All @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -61,15 +62,15 @@ 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;
for (Element featureElement : featuresElement.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 && id.getArtifactId().equals(idAttribute.getValue())) {
if (oldVersion == null || oldVersion.toString().equals(versionAttribute.getValue())) {
versionAttribute.setValue(newVersion.toString());
hasModifications = true;
Expand All @@ -93,7 +94,7 @@ private String getProductXmlContent() {
}

private File getProductXmlFile() {
return new File(projectPath(), id() + ".product");
return new File(projectPath(), id().getArtifactId() + ".product");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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<Element> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -74,35 +75,35 @@ 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();
return result;
}

@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;
}
Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 588e252

Please sign in to comment.