From cad428ea74d9c922f40e1933d6d5a48efeee10d1 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sun, 28 Jan 2024 15:50:22 +0100 Subject: [PATCH 1/3] Use version numbers in eclipse dependency downloader --- buildScripts/setup.ant.xml | 4 +- .../DownloadEclipseDependencies.java | 21 +++++ .../eclipse/dependencies/UniqueQueue.java | 21 ----- .../eclipse/dependencies/UpdateSite.java | 79 ++++++++++-------- .../eclipse/dependencies/model/Child.java | 21 +++++ .../eclipse/dependencies/model/Provided.java | 30 ++++++- .../dependencies/model/Repository.java | 21 +++++ .../eclipse/dependencies/model/Required.java | 30 ++++++- .../eclipse/dependencies/model/Unit.java | 31 ++++++- .../eclipse/dependencies/model/Version.java | 66 +++++++++++++++ .../dependencies/model/VersionAdapter.java | 38 +++++++++ .../dependencies/model/VersionRange.java | 80 +++++++++++++++++++ .../model/VersionRangeAdapter.java | 38 +++++++++ 13 files changed, 418 insertions(+), 62 deletions(-) delete mode 100644 src/support/lombok/eclipse/dependencies/UniqueQueue.java create mode 100644 src/support/lombok/eclipse/dependencies/model/Version.java create mode 100644 src/support/lombok/eclipse/dependencies/model/VersionAdapter.java create mode 100644 src/support/lombok/eclipse/dependencies/model/VersionRange.java create mode 100644 src/support/lombok/eclipse/dependencies/model/VersionRangeAdapter.java diff --git a/buildScripts/setup.ant.xml b/buildScripts/setup.ant.xml index f8fb5e51..ba15d491 100644 --- a/buildScripts/setup.ant.xml +++ b/buildScripts/setup.ant.xml @@ -201,11 +201,9 @@ This buildfile is part of projectlombok.org. It sets up the build itself. - - + - diff --git a/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java b/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java index 2391a1a9..0e8d5895 100644 --- a/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java +++ b/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2022-2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies; import java.io.BufferedInputStream; diff --git a/src/support/lombok/eclipse/dependencies/UniqueQueue.java b/src/support/lombok/eclipse/dependencies/UniqueQueue.java deleted file mode 100644 index 6a97612e..00000000 --- a/src/support/lombok/eclipse/dependencies/UniqueQueue.java +++ /dev/null @@ -1,21 +0,0 @@ -package lombok.eclipse.dependencies; - -import java.util.ArrayDeque; -import java.util.HashSet; -import java.util.Set; - -/** - * An incomplete implementation of a queue that maintains a history of all queued items and ensures unique elements. - * Elements cannot be added to the queue if they already exist in the history. - */ -public class UniqueQueue extends ArrayDeque { - private Set added = new HashSet<>(); - - @Override - public boolean add(T e) { - if (added.add(e)) { - return super.add(e); - } - return false; - } -} diff --git a/src/support/lombok/eclipse/dependencies/UpdateSite.java b/src/support/lombok/eclipse/dependencies/UpdateSite.java index c3379361..40524568 100644 --- a/src/support/lombok/eclipse/dependencies/UpdateSite.java +++ b/src/support/lombok/eclipse/dependencies/UpdateSite.java @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies; import java.io.BufferedInputStream; @@ -5,11 +26,9 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.ArrayDeque; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Queue; import java.util.Set; import java.util.stream.Collectors; @@ -25,10 +44,10 @@ import javax.xml.transform.sax.SAXSource; import org.xml.sax.InputSource; import lombok.eclipse.dependencies.model.Child; -import lombok.eclipse.dependencies.model.Provided; import lombok.eclipse.dependencies.model.Repository; import lombok.eclipse.dependencies.model.Required; import lombok.eclipse.dependencies.model.Unit; +import lombok.eclipse.dependencies.model.VersionRange; public class UpdateSite { private static final String OS_NAME = System.getProperty("os.name").toLowerCase(); @@ -38,13 +57,11 @@ public class UpdateSite { private JAXBContext jaxbContext; private Repository repository; - private Map> providesIndex; private String resolvedUrl; private SAXParserFactory saxParserFactory; public UpdateSite() throws Exception { jaxbContext = JAXBContext.newInstance(Repository.class); - providesIndex = new HashMap<>(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); @@ -72,15 +89,7 @@ public class UpdateSite { try (InputStream inputStream = readJarOrXml(resolvedUrl, "content")) { repository = unmarshalRepository(inputStream); - - // Build index - for (Unit unit : repository.units) { - for (Provided provides : unit.provides) { - providesIndex.computeIfAbsent(provides.namespace + ":" + provides.name, k -> new ArrayList<>()).add(unit); - } - } } - ; } public Set resolveWithoutDependencies(List dependencies) { @@ -92,40 +101,42 @@ public class UpdateSite { } private Set resolve(List dependencies, boolean withDependencies) { - Queue toResolve = new UniqueQueue<>(); + Queue toResolve = new ArrayDeque<>(); for (String dependency : dependencies) { - toResolve.add(dependency); + String[] split = dependency.split(":"); + Required required = new Required(); + required.namespace = split[0]; + required.name = split[1]; + required.range = VersionRange.ALL; + toResolve.add(required); } Set resolved = new HashSet<>(); while (!toResolve.isEmpty()) { - String next = toResolve.poll(); + Required next = toResolve.poll(); - List providedUnits = providesIndex.get(next); + // Skip already resolved + if (resolved.stream().anyMatch(u -> u.satisfies(next))) { + continue; + } + + List satisfyingUnits = repository.units.stream().filter(u -> u.satisfies(next)).collect(Collectors.toList()); // Skip unknown - if (providedUnits == null) { + if (satisfyingUnits.isEmpty()) { System.out.println("Skipping unknown unit " + next); continue; } - // Remove a.jre.javase dependency - List filteredProvidedUnits = providedUnits.stream() - .filter(u -> !u.id.equals("a.jre.javase")) // Remove - .collect(Collectors.toList()); - if (filteredProvidedUnits.size() == 0) { - // This is a JDK only dependency, skip + // Skip JDK dependencies + boolean jdkDependency = satisfyingUnits.stream().anyMatch(u -> u.id.equals("a.jre.javase")); + if (jdkDependency) { continue; } - // Skip ambiguous (we could use version ranges to solve that...) - if (filteredProvidedUnits.size() > 1) { - boolean alreadyResolved = filteredProvidedUnits.stream().anyMatch(resolved::contains); - if (!alreadyResolved) { - System.out.println("Ambiguous resolution for " + next + ": " + filteredProvidedUnits.toString()); - continue; - } + if (satisfyingUnits.size() > 1) { + System.out.println("Ambiguous resolution for " + next + ": " + satisfyingUnits.toString() + ", picking first"); } - Unit unit = filteredProvidedUnits.get(0); + Unit unit = satisfyingUnits.get(0); resolved.add(unit); if (withDependencies && unit.requires != null) { @@ -133,7 +144,7 @@ public class UpdateSite { if (required.optional) continue; if (!matchesFilter(required.filter)) continue; - toResolve.add(required.namespace + ":" + required.name); + toResolve.add(required); } } } diff --git a/src/support/lombok/eclipse/dependencies/model/Child.java b/src/support/lombok/eclipse/dependencies/model/Child.java index 818645e2..1aedc77f 100644 --- a/src/support/lombok/eclipse/dependencies/model/Child.java +++ b/src/support/lombok/eclipse/dependencies/model/Child.java @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2023-2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies.model; import javax.xml.bind.annotation.XmlAttribute; diff --git a/src/support/lombok/eclipse/dependencies/model/Provided.java b/src/support/lombok/eclipse/dependencies/model/Provided.java index b531d3e1..29762f8c 100644 --- a/src/support/lombok/eclipse/dependencies/model/Provided.java +++ b/src/support/lombok/eclipse/dependencies/model/Provided.java @@ -1,6 +1,28 @@ +/* + * Copyright (C) 2023-2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies.model; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; public class Provided { @XmlAttribute @@ -8,5 +30,11 @@ public class Provided { @XmlAttribute public String name; @XmlAttribute - public String version; + @XmlJavaTypeAdapter(VersionAdapter.class) + public Version version; + + @Override + public String toString() { + return namespace + ":" + name + "_" + version; + } } diff --git a/src/support/lombok/eclipse/dependencies/model/Repository.java b/src/support/lombok/eclipse/dependencies/model/Repository.java index 1d81bf8c..17c1b236 100644 --- a/src/support/lombok/eclipse/dependencies/model/Repository.java +++ b/src/support/lombok/eclipse/dependencies/model/Repository.java @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2023-2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies.model; import java.util.List; diff --git a/src/support/lombok/eclipse/dependencies/model/Required.java b/src/support/lombok/eclipse/dependencies/model/Required.java index 36fbe46e..0d5ae2d0 100644 --- a/src/support/lombok/eclipse/dependencies/model/Required.java +++ b/src/support/lombok/eclipse/dependencies/model/Required.java @@ -1,7 +1,29 @@ +/* + * Copyright (C) 2023-2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies.model; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; public class Required { @XmlAttribute @@ -9,9 +31,15 @@ public class Required { @XmlAttribute public String name; @XmlAttribute - public String range; + @XmlJavaTypeAdapter(VersionRangeAdapter.class) + public VersionRange range; @XmlAttribute public boolean optional; @XmlElement public String filter; + + @Override + public String toString() { + return namespace + ":" + name + "_" + range; + } } diff --git a/src/support/lombok/eclipse/dependencies/model/Unit.java b/src/support/lombok/eclipse/dependencies/model/Unit.java index 82d7809e..781651ec 100644 --- a/src/support/lombok/eclipse/dependencies/model/Unit.java +++ b/src/support/lombok/eclipse/dependencies/model/Unit.java @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2023-2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package lombok.eclipse.dependencies.model; import java.util.List; @@ -5,12 +26,14 @@ import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; public class Unit { @XmlAttribute public String id; @XmlAttribute - public String version; + @XmlJavaTypeAdapter(VersionAdapter.class) + public Version version; @XmlElementWrapper(name = "provides") @XmlElement(name="provided") @@ -19,7 +42,11 @@ public class Unit { @XmlElementWrapper(name = "requires") @XmlElement(name="required") public List requires; - + + public boolean satisfies(Required required) { + return provides.stream().anyMatch(p -> p.namespace.equals(required.namespace) && p.name.equals(required.name) && required.range.contains(p.version)); + } + @Override public String toString() { return id + "_" + version; diff --git a/src/support/lombok/eclipse/dependencies/model/Version.java b/src/support/lombok/eclipse/dependencies/model/Version.java new file mode 100644 index 00000000..0ebcf2ef --- /dev/null +++ b/src/support/lombok/eclipse/dependencies/model/Version.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.dependencies.model; + +public class Version { + private int major; + private int minor; + private int micro; + private String qualifier = ""; + + public static Version parse(String v) { + String[] parts = v.split("\\.", 4); + + Version version = new Version(); + version.major = Integer.parseInt(parts[0]); + if (parts.length > 1) { + version.minor = Integer.parseInt(parts[1]); + } + if (parts.length > 2) { + version.micro = Integer.parseInt(parts[2]); + } + if (parts.length > 3) { + version.qualifier = parts[3]; + } + return version; + } + + public int compareTo(Version other) { + int result = major - other.major; + if (result != 0) return result; + + result = minor - other.minor; + if (result != 0) return result; + + result = micro - other.micro; + if (result != 0) return result; + + return qualifier.compareTo(other.qualifier); + } + + @Override + public String toString() { + String result = major + "." + minor + "." + micro; + if (!qualifier.isEmpty()) result += "." + qualifier; + return result; + } +} diff --git a/src/support/lombok/eclipse/dependencies/model/VersionAdapter.java b/src/support/lombok/eclipse/dependencies/model/VersionAdapter.java new file mode 100644 index 00000000..3c0f0ca1 --- /dev/null +++ b/src/support/lombok/eclipse/dependencies/model/VersionAdapter.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.dependencies.model; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class VersionAdapter extends XmlAdapter { + + @Override + public Version unmarshal(String v) throws Exception { + return Version.parse(v); + } + + @Override + public String marshal(Version v) throws Exception { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/support/lombok/eclipse/dependencies/model/VersionRange.java b/src/support/lombok/eclipse/dependencies/model/VersionRange.java new file mode 100644 index 00000000..7dda2dce --- /dev/null +++ b/src/support/lombok/eclipse/dependencies/model/VersionRange.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.dependencies.model; + +public class VersionRange { + public static final VersionRange ALL = VersionRange.parse("0.0.0"); + + private Version min; + private Version max; + private boolean leftInclusive; + private boolean leftExclusive; + private boolean rightInclusive; + private boolean rightExclusive; + + public static VersionRange parse(String v) { + VersionRange versionRange = new VersionRange(); + versionRange.leftInclusive = v.startsWith("["); + versionRange.leftExclusive = v.startsWith("("); + versionRange.rightInclusive = v.endsWith("]"); + versionRange.rightExclusive = v.endsWith(")"); + + if (!versionRange.leftInclusive && !versionRange.leftExclusive) { + Version version = Version.parse(v); + versionRange.min = version; + versionRange.leftInclusive = true; + return versionRange; + } + + String[] parts = v.replaceAll("[\\[\\(\\)\\]]", "").split(","); + versionRange.min = Version.parse(parts[0]); + versionRange.max = Version.parse(parts[1]); + return versionRange; + } + + public boolean contains(Version version) { + if (min != null) { + int result = min.compareTo(version); + if (result > 0) return false; + if (result == 0 && !leftInclusive) return false; + } + if (max != null) { + int result = max.compareTo(version); + if (result < 0) return false; + if (result == 0 && !rightInclusive) return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (leftInclusive) sb.append("["); + if (leftExclusive) sb.append("("); + if (min != null) sb.append(min); + sb.append(","); + if (max != null) sb.append(max); + if (rightInclusive) sb.append("]"); + if (rightExclusive) sb.append(")"); + return sb.toString(); + } +} diff --git a/src/support/lombok/eclipse/dependencies/model/VersionRangeAdapter.java b/src/support/lombok/eclipse/dependencies/model/VersionRangeAdapter.java new file mode 100644 index 00000000..43331817 --- /dev/null +++ b/src/support/lombok/eclipse/dependencies/model/VersionRangeAdapter.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.dependencies.model; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class VersionRangeAdapter extends XmlAdapter { + + @Override + public VersionRange unmarshal(String v) throws Exception { + return VersionRange.parse(v); + } + + @Override + public String marshal(VersionRange v) throws Exception { + throw new UnsupportedOperationException(); + } + +} From dd95627811e0883f31991087552e080cd5119009 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Thu, 1 Feb 2024 21:20:38 +0100 Subject: [PATCH 2/3] Remove equals and now final hashCode method from test compilation unit hashCode is now final in the parent class, so we cannot override it. To avoid an NPE in the base implementation, we need to set the owner field. The PRIMARY working copy owner seems to be sufficient. --- test/core/src/lombok/RunTestsViaEcj.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 8e9369e7..352ba4e6 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -52,6 +52,7 @@ import org.eclipse.jdt.internal.compiler.batch.FileSystem; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner; import org.eclipse.jdt.internal.core.JavaModelManager; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -308,7 +309,7 @@ public class RunTestsViaEcj extends AbstractRunTests { private final char[] mainTypeName; private TestCompilationUnitEclipse(String name, String source) { - super(null, name, null); + super(null, name, DefaultWorkingCopyOwner.PRIMARY); this.source = source.toCharArray(); char[] fileNameCharArray = getFileName(); @@ -320,14 +321,6 @@ public class RunTestsViaEcj extends AbstractRunTests { mainTypeName = CharOperation.subarray(fileNameCharArray, start, end); } - @Override public int hashCode() { - return System.identityHashCode(this); - } - - @Override public boolean equals(Object obj) { - return this == obj; - } - @Override public char[] getContents() { return source; } From de4f6023bede61b446cc98f48538feb5f79374cb Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Fri, 2 Feb 2024 07:38:21 +0100 Subject: [PATCH 3/3] Update deprecated tasks --- .github/workflows/ant.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 2eb66be8..2022b3a6 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -10,16 +10,16 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 11 - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ivyCache @@ -31,7 +31,7 @@ jobs: - name: Build with Ant run: ant -noinput dist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: lombok.jar path: dist/lombok.jar @@ -55,11 +55,11 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK ${{ matrix.jdk }} if: ${{ matrix.jdk < env.EA_JDK }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.jdk }} distribution: 'zulu' @@ -82,7 +82,7 @@ jobs: echo "${HOME}/apache-ant-$ANT_VERSION/bin" >> $GITHUB_PATH - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ivyCache @@ -120,16 +120,16 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ivyCache @@ -140,7 +140,7 @@ jobs: - name: Cache base testenv if: ${{ !endsWith(matrix.version, 'full') }} - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | testenv @@ -148,7 +148,7 @@ jobs: - name: Cache full testenv if: ${{ endsWith(matrix.version, 'full') }} - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | testenv @@ -176,9 +176,9 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: lombok.jar