diff --git a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/IApackManifest.java b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/IApackManifest.java index 44f6b48f..c87c9aec 100644 --- a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/IApackManifest.java +++ b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/IApackManifest.java @@ -8,12 +8,46 @@ public interface IApackManifest { public static final String MASTER_BRANCH = "refs/heads/master"; //$NON-NLS-1$ + public enum EApackVersionDependencyClassifier { + inclusive, exclusive; + } + + public interface IApackVersionDependency { + String getMinimum(); + + EApackVersionDependencyClassifier getMinimumClassifier(); + + String getMaximum(); + + EApackVersionDependencyClassifier getMaximumClassifier(); + + boolean isVersionCompatible(String version); + + int getMinimumMajor(); + + int getMinimumMinor(); + + int getMinimumPatch(); + + int getMaximumMajor(); + + int getMaximumMinor(); + + int getMaximumPatch(); + + boolean hasRange(); + + boolean isValid(); + } + public interface IApackDependency { String getGroupId(); String getArtifactId(); + IApackVersionDependency getVersion(); + String getGitUrl(); boolean isEmpty(); diff --git a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackDependency.java b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackDependency.java index 2146fa25..949f1c1b 100644 --- a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackDependency.java +++ b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackDependency.java @@ -1,6 +1,7 @@ package org.abapgit.adt.backend.internal; import org.abapgit.adt.backend.IApackManifest.IApackDependency; +import org.abapgit.adt.backend.IApackManifest.IApackVersionDependency; import com.sap.adt.tools.core.model.adtcore.IAdtObjectReference; @@ -8,6 +9,7 @@ public class ApackDependency implements IApackDependency { private String groupId; private String artifactId; + private IApackVersionDependency version; private String gitUrl; private IAdtObjectReference targetPackage; private boolean requiresSynchronization; @@ -50,6 +52,8 @@ public String toString() { builder.append(this.groupId); builder.append(", artifactId="); //$NON-NLS-1$ builder.append(this.artifactId); + builder.append(", version="); //$NON-NLS-1$ + builder.append(this.version); builder.append(", gitUrl="); //$NON-NLS-1$ builder.append(this.gitUrl); builder.append(", targetPackage="); //$NON-NLS-1$ @@ -66,8 +70,9 @@ public int hashCode() { // NOPMD int result = 1; result = prime * result + ((this.groupId == null) ? 0 : this.groupId.hashCode()); result = prime * result + ((this.artifactId == null) ? 0 : this.artifactId.hashCode()); + result = prime * result + ((this.version == null) ? 0 : this.version.hashCode()); result = prime * result + ((this.gitUrl == null) ? 0 : this.gitUrl.hashCode()); - result = prime * result + ((this.targetPackage == null) ? 0 : this.targetPackage.hashCode()); + // No target package as it doesn't implement a correct equals and is also not really relevant for comparison ;) result = prime * result + (this.requiresSynchronization ? 1337 : 7331); return result; } @@ -98,20 +103,21 @@ public boolean equals(Object obj) { // NOPMD } else if (!this.artifactId.equals(other.artifactId)) { return false; } - if (this.gitUrl == null) { - if (other.gitUrl != null) { + if (this.version == null) { + if (other.version != null) { return false; } - } else if (!this.gitUrl.equals(other.gitUrl)) { + } else if (!this.version.equals(other.version)) { return false; } - if (this.targetPackage == null) { - if (other.targetPackage != null) { + if (this.gitUrl == null) { + if (other.gitUrl != null) { return false; } - } else if (!this.targetPackage.equals(other.targetPackage)) { + } else if (!this.gitUrl.equals(other.gitUrl)) { return false; } + // No target package as it doesn't implement a correct equals and is also not really relevant for comparison ;) return this.requiresSynchronization == other.requiresSynchronization; } @@ -141,4 +147,13 @@ public void setRequiresSynchronization(boolean requiresSynchronization) { this.requiresSynchronization = requiresSynchronization; } + @Override + public IApackVersionDependency getVersion() { + return this.version; + } + + public void setVersion(IApackVersionDependency version) { + this.version = version; + } + } diff --git a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackGitManifestDeserializer.java b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackGitManifestDeserializer.java index 938dc4d0..bcd335e9 100644 --- a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackGitManifestDeserializer.java +++ b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackGitManifestDeserializer.java @@ -104,6 +104,9 @@ private IApackDependency deserializeApackDependency(XMLStreamReader xmlReader) t case "git_url": //$NON-NLS-1$ apackDependency.setGitUrl(xmlReader.getElementText()); break; + case "version": //$NON-NLS-1$ + apackDependency.setVersion(new ApackVersionDependency(xmlReader.getElementText())); + break; case "target_package": //$NON-NLS-1$ // Manually deserialize until we have found an open ADT Core API IAdtObjectReference objectReference = IAdtCoreFactory.eINSTANCE.createAdtObjectReference(); diff --git a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackVersionDependency.java b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackVersionDependency.java new file mode 100644 index 00000000..3b6a2537 --- /dev/null +++ b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/ApackVersionDependency.java @@ -0,0 +1,262 @@ +package org.abapgit.adt.backend.internal; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.abapgit.adt.backend.IApackManifest.EApackVersionDependencyClassifier; +import org.abapgit.adt.backend.IApackManifest.IApackVersionDependency; + +public class ApackVersionDependency implements IApackVersionDependency { + + public static final String SINGLE_VERSION = "([0-9]{1,9})\\.?([0-9]{1,9})?\\.?([0-9]{1,9})?"; //$NON-NLS-1$ + public static final String VERSION_RANGE = "(\\(|\\[)(" + SINGLE_VERSION + "),(" + SINGLE_VERSION + ")(\\]|\\))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + public static final Pattern PATTERN_SINGLE_VERSION = Pattern.compile(SINGLE_VERSION); + public static final Pattern PATTERN_VERSION_RANGE = Pattern.compile(VERSION_RANGE); + + private String minimum; + private int minimumMajor; + private int minimumMinor; + private int minimumPatch; + private int maximumMajor; + private int maximumMinor; + private int maximumPatch; + private boolean range; + private EApackVersionDependencyClassifier minimumClassifier; + private String maximum; + private EApackVersionDependencyClassifier maximumClassifier; + private boolean valid; + + public ApackVersionDependency(String rawVersion) { + this.valid = false; + if (rawVersion == null) { + return; + } + if (rawVersion.matches(VERSION_RANGE)) { + Matcher rangeMatcher = PATTERN_VERSION_RANGE.matcher(rawVersion); + rangeMatcher.find(); + if ("(".equals(rangeMatcher.group(1))) { //$NON-NLS-1$ + this.minimumClassifier = EApackVersionDependencyClassifier.inclusive; + } else { + this.minimumClassifier = EApackVersionDependencyClassifier.exclusive; + } + if (")".equals(rangeMatcher.group(10))) { //$NON-NLS-1$ + this.maximumClassifier = EApackVersionDependencyClassifier.inclusive; + } else { + this.maximumClassifier = EApackVersionDependencyClassifier.exclusive; + } + this.minimum = rangeMatcher.group(2); + this.minimumMajor = Integer.parseInt(rangeMatcher.group(3)); + this.minimumMinor = rangeMatcher.group(4) == null ? 0 : Integer.parseInt(rangeMatcher.group(4)); + this.minimumPatch = rangeMatcher.group(5) == null ? 0 : Integer.parseInt(rangeMatcher.group(5)); + this.maximum = rangeMatcher.group(6); + this.maximumMajor = Integer.parseInt(rangeMatcher.group(7)); + this.maximumMinor = rangeMatcher.group(8) == null ? 0 : Integer.parseInt(rangeMatcher.group(8)); + this.maximumPatch = rangeMatcher.group(9) == null ? 0 : Integer.parseInt(rangeMatcher.group(9)); + this.range = true; + this.valid = true; + } else if (rawVersion.matches(SINGLE_VERSION)) { + Matcher versionMatcher = PATTERN_SINGLE_VERSION.matcher(rawVersion); + versionMatcher.find(); + this.minimumClassifier = EApackVersionDependencyClassifier.inclusive; + this.minimum = versionMatcher.group(0); + this.minimumMajor = Integer.parseInt(versionMatcher.group(1)); + this.minimumMinor = versionMatcher.group(2) == null ? 0 : Integer.parseInt(versionMatcher.group(2)); + this.minimumPatch = versionMatcher.group(3) == null ? 0 : Integer.parseInt(versionMatcher.group(3)); + this.maximumClassifier = EApackVersionDependencyClassifier.inclusive; + this.maximum = this.minimum; + this.maximumMajor = this.minimumMajor; + this.maximumMinor = this.minimumMinor; + this.maximumPatch = this.minimumPatch; + this.range = false; + this.valid = true; + } + } + + @Override + public String getMinimum() { + return this.minimum; + } + + @Override + public EApackVersionDependencyClassifier getMinimumClassifier() { + return this.minimumClassifier; + } + + @Override + public String getMaximum() { + return this.maximum; + } + + @Override + public EApackVersionDependencyClassifier getMaximumClassifier() { + return this.maximumClassifier; + } + + @Override + public boolean isVersionCompatible(String version) { + String versionWithSuffixRegex = "(" + SINGLE_VERSION + ").*"; //$NON-NLS-1$ //$NON-NLS-2$ + if (version.matches(versionWithSuffixRegex)) { + Matcher versionSuffixMatcher = Pattern.compile(versionWithSuffixRegex).matcher(version); + versionSuffixMatcher.find(); + IApackVersionDependency otherVersion = new ApackVersionDependency(versionSuffixMatcher.group(1)); + if (getMinimumMajor() > otherVersion.getMinimumMajor()) { + return false; + } + if (getMinimumMajor() == otherVersion.getMinimumMajor()) { + if (getMinimumMinor() > otherVersion.getMinimumMinor()) { + return false; + } + if (getMinimumMinor() == otherVersion.getMinimumMinor()) { + if (getMinimumPatch() > otherVersion.getMinimumPatch()) { + return false; + } + if (getMinimumPatch() == otherVersion.getMinimumPatch() + && getMinimumClassifier() == EApackVersionDependencyClassifier.exclusive) { + return false; + } + } + } + + if (getMaximumMajor() < otherVersion.getMaximumMajor()) { + return false; + } + if (getMaximumMajor() > otherVersion.getMaximumMajor()) { + return true; + } + if (getMaximumMinor() < otherVersion.getMaximumMinor()) { + return false; + } + if (getMaximumMinor() > otherVersion.getMaximumMinor()) { + return true; + } + if (getMaximumPatch() < otherVersion.getMaximumPatch()) { + return false; + } + if (getMaximumPatch() > otherVersion.getMaximumPatch()) { + return true; + } + if (getMaximumClassifier() == EApackVersionDependencyClassifier.inclusive) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("APACK Version Dependency [minimum="); //$NON-NLS-1$ + builder.append(this.getMinimum()); + builder.append(", minimumClassifier="); //$NON-NLS-1$ + builder.append(this.getMinimumClassifier()); + builder.append(", maximum="); //$NON-NLS-1$ + builder.append(this.getMaximum()); + builder.append(", maximumClassifier="); //$NON-NLS-1$ + builder.append(this.getMaximumClassifier()); + builder.append("]"); //$NON-NLS-1$ + return builder.toString(); + } + + @Override + public int hashCode() { // NOPMD + final int prime = 31; + int result = 1; + result = prime * result + ((this.getMinimum() == null) ? 0 : this.getMinimum().hashCode()); + result = prime * result + ((this.getMinimumClassifier() == null) ? 0 : this.getMinimumClassifier().hashCode()); + result = prime * result + ((this.getMaximum() == null) ? 0 : this.getMaximum().hashCode()); + result = prime * result + ((this.getMaximumClassifier() == null) ? 0 : this.getMaximumClassifier().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { // NOPMD + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ApackVersionDependency other = (ApackVersionDependency) obj; + if (this.getMinimum() == null) { + if (other.getMinimum() != null) { + return false; + } + } else if (!this.getMinimum().equals(other.getMinimum())) { + return false; + } + if (this.getMinimumClassifier() != other.getMinimumClassifier()) { + return false; + } + if (this.getMaximum() == null) { + if (other.getMaximum() != null) { + return false; + } + } else if (!this.getMaximum().equals(other.getMaximum())) { + return false; + } + return this.getMaximumClassifier() == other.getMaximumClassifier(); + } + + public void setMinimum(String minimum) { + this.minimum = minimum; + } + + public void setMaximum(String maximum) { + this.maximum = maximum; + } + + public void setMinimumClassifier(EApackVersionDependencyClassifier minimumClassifier) { + this.minimumClassifier = minimumClassifier; + } + + public void setMaximumClassifier(EApackVersionDependencyClassifier maximumClassifier) { + this.maximumClassifier = maximumClassifier; + } + + @Override + public int getMinimumMajor() { + return this.minimumMajor; + } + + @Override + public int getMinimumMinor() { + return this.minimumMinor; + } + + @Override + public int getMinimumPatch() { + return this.minimumPatch; + } + + @Override + public int getMaximumMajor() { + return this.maximumMajor; + } + + @Override + public int getMaximumMinor() { + return this.maximumMinor; + } + + @Override + public int getMaximumPatch() { + return this.maximumPatch; + } + + @Override + public boolean hasRange() { + return this.range; + } + + @Override + public boolean isValid() { + return this.valid; + } + +} diff --git a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repositories.java b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repositories.java index 0f3ed47d..cbdda544 100644 --- a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repositories.java +++ b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repositories.java @@ -22,7 +22,9 @@ public List getRepositories() { @Override public void add(IRepository repository) { - this.repositories.add(repository); + if (!this.repositories.contains(repository)) { + this.repositories.add(repository); + } } @Override diff --git a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repository.java b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repository.java index 388bbeb6..ebaa03f7 100644 --- a/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repository.java +++ b/org.abapgit.adt.backend/src/org/abapgit/adt/backend/internal/Repository.java @@ -207,4 +207,42 @@ public void addStatusLink(String relation, URI uri) { this.statusLink.put(relation, uri); } + @Override + public int hashCode() { // NOPMD + final int prime = 31; + int result = 1; + result = prime * result + ((this.url == null) ? 0 : this.url.hashCode()); + result = prime * result + ((this.branch == null) ? 0 : this.branch.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { // NOPMD + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Repository other = (Repository) obj; + if (this.url == null) { + if (other.url != null) { + return false; + } + } else if (!this.url.equals(other.url)) { + return false; + } + if (this.branch == null) { + if (other.branch != null) { + return false; + } + } else if (!this.branch.equals(other.branch)) { + return false; + } + return true; + } + } diff --git a/pom.xml b/pom.xml index b9b85233..29fd7a6f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ org.abapgit.adt.ui org.abapgit.adt.feature org.abapgit.adt.updatesite + test diff --git a/test/org.abapgit.adt.backend.test/.classpath b/test/org.abapgit.adt.backend.test/.classpath new file mode 100644 index 00000000..eca7bdba --- /dev/null +++ b/test/org.abapgit.adt.backend.test/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/org.abapgit.adt.backend.test/.project b/test/org.abapgit.adt.backend.test/.project new file mode 100644 index 00000000..54a03e0a --- /dev/null +++ b/test/org.abapgit.adt.backend.test/.project @@ -0,0 +1,39 @@ + + + org.abapgit.adt.backend.test + + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + com.sap.adt.pde.ManifestBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + com.sap.adt.pde.PluginNature + + diff --git a/test/org.abapgit.adt.backend.test/META-INF/MANIFEST.MF b/test/org.abapgit.adt.backend.test/META-INF/MANIFEST.MF new file mode 100644 index 00000000..3ab04d38 --- /dev/null +++ b/test/org.abapgit.adt.backend.test/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Unit Tests for abapGit ADT Backend components +Bundle-SymbolicName: org.abapgit.adt.backend.test;singleton:=true +Bundle-Version: 0.13.2 +Bundle-ClassPath: . +Bundle-Vendor: abapGit +Fragment-Host: org.abapgit.adt.backend +Export-Package: org.abapgit.adt.backend +Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: org.abapgit.adt.backend +Automatic-Module-Name: org.abapgit.adt.backend.test diff --git a/test/org.abapgit.adt.backend.test/build.properties b/test/org.abapgit.adt.backend.test/build.properties new file mode 100644 index 00000000..78666891 --- /dev/null +++ b/test/org.abapgit.adt.backend.test/build.properties @@ -0,0 +1,3 @@ +#Fri Sep 24 08:21:39 CEST 2010 +bin.includes=META-INF/,., +source..=src/ diff --git a/test/org.abapgit.adt.backend.test/pom.xml b/test/org.abapgit.adt.backend.test/pom.xml new file mode 100644 index 00000000..b4990950 --- /dev/null +++ b/test/org.abapgit.adt.backend.test/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + org.abapgit.adt.backend.test + 0.13.2 + org.abapgit.adt.backend.test + eclipse-test-plugin + + org.abapgit.adt + tests + 0.13.2 + ../pom.xml + + diff --git a/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitApackDependency.java b/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitApackDependency.java new file mode 100644 index 00000000..f64d9fc7 --- /dev/null +++ b/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitApackDependency.java @@ -0,0 +1,33 @@ +package org.abapgit.adt.backend.internal; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.sap.adt.tools.core.model.adtcore.IAdtCoreFactory; +import com.sap.adt.tools.core.model.adtcore.IAdtObjectReference; + +public class TestsUnitApackDependency { + + @Test + public void sameDependency() { + ApackDependency apackDependencyOne = new ApackDependency(); + apackDependencyOne.setGroupId("sap.com"); + apackDependencyOne.setArtifactId("my-fancy-component"); + apackDependencyOne.setGitUrl("https://github.com/SAP/abap-platform-fancy-component"); + apackDependencyOne.setRequiresSynchronization(true); + IAdtObjectReference targetPackageOne = IAdtCoreFactory.eINSTANCE.createAdtObjectReference(); + apackDependencyOne.setTargetPackage(targetPackageOne); + + ApackDependency apackDependencyTwo = new ApackDependency(); + apackDependencyTwo.setGroupId("sap.com"); + apackDependencyTwo.setArtifactId("my-fancy-component"); + apackDependencyTwo.setGitUrl("https://github.com/SAP/abap-platform-fancy-component"); + apackDependencyTwo.setRequiresSynchronization(true); + IAdtObjectReference targetPackageTwo = IAdtCoreFactory.eINSTANCE.createAdtObjectReference(); + apackDependencyTwo.setTargetPackage(targetPackageTwo); + + assertEquals(apackDependencyOne, apackDependencyTwo); + + } +} diff --git a/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitApackVersionDependency.java b/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitApackVersionDependency.java new file mode 100644 index 00000000..fe988f7c --- /dev/null +++ b/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitApackVersionDependency.java @@ -0,0 +1,186 @@ +package org.abapgit.adt.backend.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.abapgit.adt.backend.IApackManifest.EApackVersionDependencyClassifier; +import org.abapgit.adt.backend.IApackManifest.IApackVersionDependency; +import org.junit.Test; + +public class TestsUnitApackVersionDependency { + + @Test + public void standardRange() { + IApackVersionDependency versionDependency = new ApackVersionDependency("(0.2,1.0]"); + assertEquals("0.2", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMinimumClassifier()); + assertEquals(0, versionDependency.getMinimumMajor()); + assertEquals(2, versionDependency.getMinimumMinor()); + assertEquals(0, versionDependency.getMinimumPatch()); + assertEquals("1.0", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.exclusive, versionDependency.getMaximumClassifier()); + assertEquals(1, versionDependency.getMaximumMajor()); + assertEquals(0, versionDependency.getMaximumMinor()); + assertEquals(0, versionDependency.getMaximumPatch()); + assertTrue(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void singleCompleteVersion() { + IApackVersionDependency versionDependency = new ApackVersionDependency("0.23.42"); + assertEquals("0.23.42", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMinimumClassifier()); + assertEquals(0, versionDependency.getMinimumMajor()); + assertEquals(23, versionDependency.getMinimumMinor()); + assertEquals(42, versionDependency.getMinimumPatch()); + assertEquals("0.23.42", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMaximumClassifier()); + assertEquals(0, versionDependency.getMaximumMajor()); + assertEquals(23, versionDependency.getMaximumMinor()); + assertEquals(42, versionDependency.getMaximumPatch()); + assertFalse(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void singleVersionMajorOnly() { + IApackVersionDependency versionDependency = new ApackVersionDependency("5"); + assertEquals("5", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMinimumClassifier()); + assertEquals(5, versionDependency.getMinimumMajor()); + assertEquals(0, versionDependency.getMinimumMinor()); + assertEquals(0, versionDependency.getMinimumPatch()); + assertEquals("5", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMaximumClassifier()); + assertEquals(5, versionDependency.getMaximumMajor()); + assertEquals(0, versionDependency.getMaximumMinor()); + assertEquals(0, versionDependency.getMaximumPatch()); + assertFalse(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void singleVersionMajorMinor() { + IApackVersionDependency versionDependency = new ApackVersionDependency("0.2"); + assertEquals("0.2", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMinimumClassifier()); + assertEquals(0, versionDependency.getMinimumMajor()); + assertEquals(2, versionDependency.getMinimumMinor()); + assertEquals(0, versionDependency.getMinimumPatch()); + assertEquals("0.2", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMaximumClassifier()); + assertEquals(0, versionDependency.getMaximumMajor()); + assertEquals(2, versionDependency.getMaximumMinor()); + assertEquals(0, versionDependency.getMaximumPatch()); + assertFalse(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void singleCompleteVersionBuildNumber() { + // We don't allow dependency declarations using build IDs! + IApackVersionDependency versionDependency = new ApackVersionDependency("0.34.453-45"); + assertFalse(versionDependency.isValid()); + } + + @Test + public void rangeDoubleInclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("(0.3,1.11.4)"); + assertEquals("0.3", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMinimumClassifier()); + assertEquals(0, versionDependency.getMinimumMajor()); + assertEquals(3, versionDependency.getMinimumMinor()); + assertEquals(0, versionDependency.getMinimumPatch()); + assertEquals("1.11.4", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMaximumClassifier()); + assertEquals(1, versionDependency.getMaximumMajor()); + assertEquals(11, versionDependency.getMaximumMinor()); + assertEquals(4, versionDependency.getMaximumPatch()); + assertTrue(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void rangeExclusiveInclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("[0.1,1.0)"); + assertEquals("0.1", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.exclusive, versionDependency.getMinimumClassifier()); + assertEquals(0, versionDependency.getMinimumMajor()); + assertEquals(1, versionDependency.getMinimumMinor()); + assertEquals(0, versionDependency.getMinimumPatch()); + assertEquals("1.0", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.inclusive, versionDependency.getMaximumClassifier()); + assertEquals(1, versionDependency.getMaximumMajor()); + assertEquals(0, versionDependency.getMaximumMinor()); + assertEquals(0, versionDependency.getMaximumPatch()); + assertTrue(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void rangeExclusiveExclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("[0.34.45,1.1.0]"); + assertEquals("0.34.45", versionDependency.getMinimum()); + assertEquals(EApackVersionDependencyClassifier.exclusive, versionDependency.getMinimumClassifier()); + assertEquals(0, versionDependency.getMinimumMajor()); + assertEquals(34, versionDependency.getMinimumMinor()); + assertEquals(45, versionDependency.getMinimumPatch()); + assertEquals("1.1.0", versionDependency.getMaximum()); + assertEquals(EApackVersionDependencyClassifier.exclusive, versionDependency.getMaximumClassifier()); + assertEquals(1, versionDependency.getMaximumMajor()); + assertEquals(1, versionDependency.getMaximumMinor()); + assertEquals(0, versionDependency.getMaximumPatch()); + assertTrue(versionDependency.hasRange()); + assertTrue(versionDependency.isValid()); + } + + @Test + public void versionCompatibleInclusiveExclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("(0.1.42,1.0.33]"); + assertFalse(versionDependency.isVersionCompatible("0.1.11")); + assertTrue(versionDependency.isVersionCompatible("0.1.42-42")); + assertTrue(versionDependency.isVersionCompatible("0.999.999")); + assertTrue(versionDependency.isVersionCompatible("1.0")); + assertFalse(versionDependency.isVersionCompatible("1.0.33")); + assertFalse(versionDependency.isVersionCompatible("1.0.34")); + } + + @Test + public void versionCompatibleInclusiveInclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("(0.1.42,1.0.33)"); + assertFalse(versionDependency.isVersionCompatible("0.1.11")); + assertTrue(versionDependency.isVersionCompatible("0.1.42-42")); + assertTrue(versionDependency.isVersionCompatible("0.999.999")); + assertTrue(versionDependency.isVersionCompatible("1.0")); + assertTrue(versionDependency.isVersionCompatible("1.0.33")); + assertFalse(versionDependency.isVersionCompatible("1.0.34")); + } + + @Test + public void versionCompatibleExclusiveInclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("[0.1.42,1.0.33)"); + assertFalse(versionDependency.isVersionCompatible("0.1.11")); + assertFalse(versionDependency.isVersionCompatible("0.1.42-42")); + assertTrue(versionDependency.isVersionCompatible("0.1.43-42")); + assertTrue(versionDependency.isVersionCompatible("0.999.999")); + assertTrue(versionDependency.isVersionCompatible("1.0")); + assertTrue(versionDependency.isVersionCompatible("1.0.33")); + assertFalse(versionDependency.isVersionCompatible("1.0.34")); + } + + @Test + public void versionCompatibleExclusiveExclusive() { + IApackVersionDependency versionDependency = new ApackVersionDependency("[0.1.42,1.0.33]"); + assertFalse(versionDependency.isVersionCompatible("0.1.11")); + assertFalse(versionDependency.isVersionCompatible("0.1.42-42")); + assertTrue(versionDependency.isVersionCompatible("0.1.43-42")); + assertTrue(versionDependency.isVersionCompatible("0.999.999")); + assertTrue(versionDependency.isVersionCompatible("1.0")); + assertFalse(versionDependency.isVersionCompatible("1.0.33")); + assertFalse(versionDependency.isVersionCompatible("1.0.34")); + } + + +} diff --git a/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitRepositories.java b/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitRepositories.java new file mode 100644 index 00000000..2ccf13c9 --- /dev/null +++ b/test/org.abapgit.adt.backend.test/src/org/abapgit/adt/backend/internal/TestsUnitRepositories.java @@ -0,0 +1,26 @@ +package org.abapgit.adt.backend.internal; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.abapgit.adt.backend.IRepository; +import org.junit.Test; + +public class TestsUnitRepositories { + + @Test + public void avoidDuplicateRepositoriesAddSingle() { + Repositories allRepositories = new Repositories(); + Repository repositoryOne = new Repository(); + repositoryOne.setUrl("https://github.com/SAP/abap-platform-jak.git"); + allRepositories.add(repositoryOne); + Repository repositoryTwo = new Repository(); + repositoryTwo.setUrl("https://github.com/SAP/abap-platform-jak.git"); + allRepositories.add(repositoryTwo); + + List actualRepositories = allRepositories.getRepositories(); + assertEquals(1, actualRepositories.size()); + } + +} diff --git a/test/pom.xml b/test/pom.xml new file mode 100644 index 00000000..72cbcbea --- /dev/null +++ b/test/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + org.abapgit.adt + tests + 0.13.2 + Test Fragments + pom + Test Fragments + + + org.abapgit.adt + org.abapgit.adt.parent + 0.13.2 + ../pom.xml + + + + org.abapgit.adt.backend.test + + +