Skip to content

Commit

Permalink
Run CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Jan 28, 2024
1 parent 2773ed5 commit e509f71
Show file tree
Hide file tree
Showing 10 changed files with 418 additions and 40 deletions.
4 changes: 1 addition & 3 deletions buildScripts/setup.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,9 @@ This buildfile is part of projectlombok.org. It sets up the build itself.
<sequential>
<fetchdep.eclipse.updatesite name="@{name}" version="@{version}">
<bundles>
<!-- Ambiguous + osgi.extender dependecies -->
<arg value="osgi.bundle:javax.el-api" />
<!-- osgi.extender dependecies -->
<arg value="osgi.bundle:org.apache.felix.scr" />
<arg value="osgi.bundle:org.apache.aries.spifly.dynamic.bundle" />
<arg value="osgi.bundle:org.apache.commons.commons-io" />
<!-- Real dependencies -->
<arg value="osgi.bundle:org.eclipse.jdt.core" />
<arg value="osgi.bundle:org.eclipse.jdt.ui" />
Expand Down
50 changes: 50 additions & 0 deletions src/support/lombok/eclipse/dependencies/Dependency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.util.Objects;

import lombok.eclipse.dependencies.model.VersionRange;

public class Dependency {
public Dependency(String id, VersionRange versionRange) {
this.id = id;
this.versionRange = versionRange;
}

String namespace;
String id;
VersionRange versionRange;

@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Dependency other = (Dependency) obj;
return Objects.equals(id, other.id);
}
}
88 changes: 54 additions & 34 deletions src/support/lombok/eclipse/dependencies/UpdateSite.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
/*
* 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;
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.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -25,10 +43,10 @@
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();
Expand All @@ -38,13 +56,11 @@ public class UpdateSite {

private JAXBContext jaxbContext;
private Repository repository;
private Map<String, List<Unit>> 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);
Expand Down Expand Up @@ -72,15 +88,7 @@ public void read(String url) throws Exception {

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<String> resolveWithoutDependencies(List<String> dependencies) {
Expand All @@ -92,48 +100,60 @@ public Set<String> resolveWithDependencies(List<String> dependencies) {
}

private Set<String> resolve(List<String> dependencies, boolean withDependencies) {
Queue<String> toResolve = new UniqueQueue<>();
Queue<Required> toResolve = new UniqueQueue<>();
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<Unit> resolved = new HashSet<>();
while (!toResolve.isEmpty()) {
String next = toResolve.poll();
Required next = toResolve.poll();

// Skip already resolved
if (resolved.stream().anyMatch(u -> u.satisfies(next))) {
continue;
}

List<Unit> providedUnits = providesIndex.get(next);
List<Unit> 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<Unit> 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;
}
// Required differentVersion = new Required();
// differentVersion.namespace = next.namespace;
// differentVersion.name = next.name;
// differentVersion.range = VersionRange.ALL;
// List<Unit> resolvedInDifferentVersion = resolved.stream().filter(u -> u.satisfies(next)).collect(Collectors.toList());
//
// if (!resolvedInDifferentVersion.isEmpty()) {
//
// }

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) {
for (Required required : unit.requires) {
if (required.optional) continue;
if (!matchesFilter(required.filter)) continue;

toResolve.add(required.namespace + ":" + required.name);
toResolve.add(required);
}
}
}
Expand Down
30 changes: 29 additions & 1 deletion src/support/lombok/eclipse/dependencies/model/Provided.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
/*
* 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.XmlAttribute;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

public class Provided {
@XmlAttribute
public String namespace;
@XmlAttribute
public String name;
@XmlAttribute
public String version;
@XmlJavaTypeAdapter(VersionAdapter.class)
public Version version;

@Override
public String toString() {
return namespace + ":" + name + "_" + version;
}
}
30 changes: 29 additions & 1 deletion src/support/lombok/eclipse/dependencies/model/Required.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
/*
* 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.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

public class Required {
@XmlAttribute
public String namespace;
@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;
}
}
34 changes: 33 additions & 1 deletion src/support/lombok/eclipse/dependencies/model/Unit.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
/*
* 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 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")
Expand All @@ -24,4 +47,13 @@ public class Unit {
public String toString() {
return id + "_" + version;
}

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));
// .filter(p -> p.namespace.equals(required.namespace))
// .filter(p -> p.name.equals(required.name))
// .filter(p -> required.range.contains(p.version))
// .findAny()
// .isPresent();
}
}
Loading

0 comments on commit e509f71

Please sign in to comment.