From 9bc13edebdc06fcdc33182ef0bd8ea83e99916c0 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 8 May 2025 22:32:12 +0200 Subject: [PATCH] Remove now unused POM-enrichment for publication to Maven-Central And downgrade the JDK used in the publishToMaven Jenkins pipeline as we don't need the latest Java-22/23 features anymore, i.e. the ability to launch multi-file source-code programs. Follow-up on - https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/pull/3035 --- JenkinsJobs/Releng/publishToMaven.jenkinsfile | 5 +- .../publish-to-maven-central/.classpath | 6 - .../publish-to-maven-central/.project | 6 - .../.settings/org.eclipse.jdt.core.prefs | 14 -- .../releng/maven/pom/ArtifactInfo.java | 140 ------------------ .../platform/releng/maven/pom/EnrichPoms.java | 136 ----------------- .../releng/maven/pom/ManifestReader.java | 66 --------- 7 files changed, 2 insertions(+), 371 deletions(-) delete mode 100644 eclipse.platform.releng/publish-to-maven-central/.classpath delete mode 100644 eclipse.platform.releng/publish-to-maven-central/.settings/org.eclipse.jdt.core.prefs delete mode 100644 eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ArtifactInfo.java delete mode 100644 eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/EnrichPoms.java delete mode 100644 eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ManifestReader.java diff --git a/JenkinsJobs/Releng/publishToMaven.jenkinsfile b/JenkinsJobs/Releng/publishToMaven.jenkinsfile index 83f5d73669b..2eec4b50e88 100644 --- a/JenkinsJobs/Releng/publishToMaven.jenkinsfile +++ b/JenkinsJobs/Releng/publishToMaven.jenkinsfile @@ -10,7 +10,7 @@ pipeline { label 'basic' } tools { - jdk 'temurin-jdk23-latest' + jdk 'temurin-jdk21-latest' maven 'apache-maven-latest' } environment { @@ -31,8 +31,7 @@ pipeline { echo "==== Install and run the CBI aggregator ====" DIR_AGGREGATOR="${WORKSPACE}/tools/aggregator" - MAVEN_PUBLISH_BASE="${WORKSPACE}/git-repo/eclipse.platform.releng/publish-to-maven-central" - FILE_SDK_AGGR="${MAVEN_PUBLISH_BASE}/SDK4Mvn.aggr" + FILE_SDK_AGGR="${WORKSPACE}/git-repo/eclipse.platform.releng/publish-to-maven-central/SDK4Mvn.aggr" # Set whether this is a snapshot build or not if [ "${snapshotOrRelease}" = "-snapshot" ]; then diff --git a/eclipse.platform.releng/publish-to-maven-central/.classpath b/eclipse.platform.releng/publish-to-maven-central/.classpath deleted file mode 100644 index ae2f7b264b6..00000000000 --- a/eclipse.platform.releng/publish-to-maven-central/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/eclipse.platform.releng/publish-to-maven-central/.project b/eclipse.platform.releng/publish-to-maven-central/.project index b2d2cc85dda..a5757fe60e7 100644 --- a/eclipse.platform.releng/publish-to-maven-central/.project +++ b/eclipse.platform.releng/publish-to-maven-central/.project @@ -5,13 +5,7 @@ - - org.eclipse.jdt.core.javabuilder - - - - org.eclipse.jdt.core.javanature diff --git a/eclipse.platform.releng/publish-to-maven-central/.settings/org.eclipse.jdt.core.prefs b/eclipse.platform.releng/publish-to-maven-central/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 92dd3c26a85..00000000000 --- a/eclipse.platform.releng/publish-to-maven-central/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,14 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=21 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning -org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=21 diff --git a/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ArtifactInfo.java b/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ArtifactInfo.java deleted file mode 100644 index ad04cfde282..00000000000 --- a/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ArtifactInfo.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2016, 2025 GK Software SE and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Stephan Herrmann - initial implementation - * Hannes Wellmann - Simplify and remove now unncessary elements - ********************************************************************************/ -package org.eclipse.platform.releng.maven.pom; - -import java.io.InputStream; -import java.net.URI; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public record ArtifactInfo(String bsn, String scmConnection) { - - private static final String SCM_TAG_START = ";tag=\""; // git tag inside Eclipse-SourceReference - private static final String INDENT = " "; - private static final Pattern GITHUB_PATTERN = Pattern.compile("https://github.com/([^/]+)/.*"); - - public ArtifactInfo { - Objects.requireNonNull(bsn); - Objects.requireNonNull(scmConnection); - } - - String toPomFragment() { - try { - StringBuilder buf = new StringBuilder(); - String projectURL = getProjectURL(); - element("url", INDENT, buf, projectURL); - String url = extractScmUrl(); - buf.append(getFrontMatter(url)); - element("scm", INDENT, buf, subElement("connection", extractScmConnection()), - subElement("tag", extractScmTag()), subElement("url", url)); - addUrlDevelopers(projectURL, INDENT, buf); - return buf.toString(); - } catch (RuntimeException e) { - throw new IllegalStateException("Failed for " + this, e); - } - } - - private static String getFrontMatter(String scmURL) { - return String.format(""" - - - Eclipse Public License - v 2.0 - https://www.eclipse.org/legal/epl-2.0/ - repo - - - - Eclipse Foundation - https://www.eclipse.org/ - - - Github - %s/issues - - """, scmURL); - } - - private String getProjectURL() { - String scmURL = extractScmUrl(); - Matcher matcher = GITHUB_PATTERN.matcher(scmURL); - if (matcher.matches()) { - String organization = matcher.group(1); - return "https://projects.eclipse.org/projects/" + organization.replace('-', '.'); - } - throw new IllegalArgumentException("Unexpected scm-URL: " + scmURL); - } - - private String extractScmConnection() { - return substringTo(this.scmConnection, 0, ';'); - } - - private String extractScmTag() { - int tagStart = this.scmConnection.indexOf(SCM_TAG_START); - if (tagStart == -1) { - throw new IllegalArgumentException("scm-tag not found in " + this.scmConnection); - } - return substringTo(this.scmConnection, tagStart + SCM_TAG_START.length(), '"'); - } - - private static void addUrlDevelopers(String projectURL, String indent, StringBuilder buf) { - StringBuilder subElements = new StringBuilder(); - element("developer", "", subElements, subElement("url", projectURL + "/who")); - element("developers", indent, buf, subElements.toString()); - } - - private static final Set visitedSCMs = new HashSet<>(); - - private String extractScmUrl() { - String connection = extractScmConnection(); - String scmURL = connection.replaceFirst("^scm:git:", "").replaceFirst("^scm:githttps:", "https:") - .replaceFirst("\\.git$", ""); - if (EnrichPoms.test && visitedSCMs.add(scmURL)) { - try (InputStream in = new URI(scmURL).toURL().openStream()) { - } catch (Exception ex) { - ex.printStackTrace(); - } - } - return scmURL; - } - - private static String substringTo(String string, int beginIndex, char endChar) { - int endIndex = string.indexOf(endChar, beginIndex); - return endIndex == -1 ? string.substring(beginIndex) : string.substring(beginIndex, endIndex); - } - - private static void element(String tag, String indent, StringBuilder buf, String... contents) { - buf.append(indent).append('<').append(tag).append('>'); - if (contents.length == 1 && !contents[0].contains("\n")) { - buf.append(contents[0]); - } else { - buf.append("\n"); - for (String content : contents) { - content.lines().forEach(line -> buf.append(indent).append(INDENT).append(line).append('\n')); - } - buf.append(indent); - } - buf.append("\n"); - } - - private static String subElement(String tag, String content) { - Objects.requireNonNull(content); - StringBuilder buf = new StringBuilder(); - element(tag, "", buf, content); - return buf.toString(); - } -} diff --git a/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/EnrichPoms.java b/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/EnrichPoms.java deleted file mode 100644 index 550783585e1..00000000000 --- a/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/EnrichPoms.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2016, 2025 GK Software SE and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Stephan Herrmann - initial implementation - ********************************************************************************/ -package org.eclipse.platform.releng.maven.pom; - -import java.io.IOException; -import java.io.Writer; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.stream.Stream; - -/** - * To test locally, the /publish-to-maven-central/SDK4Mvn.aggr must be used to - * produce the Mavenized p2 repository. To do that, you need to install the "CBI - * Aggregator Editor" from https://download.eclipse.org/cbi/updates/p2-aggregator/tools/nightly/latest. - * Then you can open the SDK4Mvn.aggr in the Aggregator Editor and invoke - * Build Aggregation from the context menu. That generates results in - * ${user.home}/build. Only the contents of following three folders are - * actually published to Maven (perhaps equinox in the future), so you can run - * main for just those folders: - * - *
- * ~/build/final/org/eclipse/pde
- * ~/build/final/org/eclipse/jdt
- * ~/build/final/org/eclipse/platform
- * -test
- * -verbose
- * 
- * - * The -test will test that the SCM URL actually exists. The - * -verbose will print the contents to each enriched pom to - * System.out. - */ -public class EnrichPoms { - - private static final String DOT_POM = ".pom"; - private static final String DOT_JAR = ".jar"; - private static final String BAK_SUFFIX = "-bak"; - - static boolean test; - - static boolean verbose; - - public static void main(String[] args) throws IOException { - Set paths = new LinkedHashSet<>(); - for (String arg : args) { - if ("-test".equals(arg)) { - test = true; - } else if ("-verbose".equals(arg)) { - verbose = true; - } else { - Path path = FileSystems.getDefault().getPath(arg); - if (!Files.exists(path) || !Files.isDirectory(path)) { - throw new IllegalArgumentException(path.toString() + " is not a directory"); - } - paths.add(path); - } - } - - if (paths.isEmpty()) { - throw new IllegalArgumentException("No directories specified"); - } - - for (Path path : paths) { - try (Stream files = Files.walk(path)) { - int enrichedCount = files.filter(EnrichPoms::isArtifact).mapToInt(EnrichPoms::enrich).sum(); - System.out.println("Enriched " + enrichedCount + " POM files under " + path); - } - } - } - - private static boolean isArtifact(Path path) { - if (!path.getFileName().toString().endsWith(DOT_POM) || Files.isDirectory(path)) { - return false; - } - Path jarPath = getCorrespondingJarPath(path); - return Files.exists(jarPath); - } - - private static Path getCorrespondingJarPath(Path pomPath) { - String fileName = pomPath.getFileName().toString(); - String jarName = fileName.substring(0, fileName.length() - DOT_POM.length()) + DOT_JAR; - return pomPath.resolveSibling(jarName); - } - - public static int enrich(Path pomPath) { - try { - Path jarPath = getCorrespondingJarPath(pomPath); - ArtifactInfo info = ManifestReader.read(jarPath); - if (info == null) { - // Don't process features because they aren't published. - return 0; - } - - Path backPath = pomPath.resolveSibling(pomPath.getFileName().toString() + BAK_SUFFIX); - Path newPom = Files.createTempFile(pomPath.getParent(), "", DOT_POM); - try (Stream lines = Files.lines(Files.exists(backPath) ? backPath : pomPath); - Writer out = Files.newBufferedWriter(newPom);) { - boolean detailsInserted = false; - for (String line : (Iterable) lines::iterator) { - out.append(line).append('\n'); - if (!detailsInserted && line.contains("")) { - out.append(info.toPomFragment()); - detailsInserted = true; - } - } - } - if (verbose) { - String pomText = Files.readString(newPom); - System.out.println(pomText); - } - if (!Files.exists(backPath)) { - Files.move(pomPath, backPath); - } - Files.move(newPom, pomPath, StandardCopyOption.REPLACE_EXISTING); - return 1; - } catch (IOException e) { - throw new IllegalStateException("Failed to rewrite pom " + pomPath, e); - } - } -} diff --git a/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ManifestReader.java b/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ManifestReader.java deleted file mode 100644 index 7a6b89b57ee..00000000000 --- a/eclipse.platform.releng/publish-to-maven-central/src/org/eclipse/platform/releng/maven/pom/ManifestReader.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2016, 2025 GK Software SE and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Stephan Herrmann - initial implementation - ********************************************************************************/ -package org.eclipse.platform.releng.maven.pom; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Map.Entry; -import java.util.jar.Attributes; -import java.util.jar.Manifest; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class ManifestReader { - - private static final String FEATURE_XML = "feature.xml"; - private static final String MANIFEST_MF = "META-INF/MANIFEST.MF"; - // Eclipse headers in MANIFEST.MF: - private static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName"; - private static final String ECLIPSE_SOURCE_REFERENCES = "Eclipse-SourceReferences"; - - public static ArtifactInfo read(Path path) throws FileNotFoundException, IOException { - try (ZipFile zip = new ZipFile(path.toFile())) { - ZipEntry featureEntry = zip.getEntry(FEATURE_XML); - if (featureEntry != null) { - return null; - } - - ZipEntry entry = zip.getEntry(MANIFEST_MF); - Manifest mf = new Manifest(zip.getInputStream(entry)); - Attributes mainAttributes = mf.getMainAttributes(); - // printAllMainAttributes(mainAttributes); - - String bsn = getSymbolicName(mainAttributes); - String scmConnection = mainAttributes.getValue(ECLIPSE_SOURCE_REFERENCES); - return new ArtifactInfo(bsn, scmConnection); - } - } - - private static String getSymbolicName(Attributes mainAttributes) { - String bsn = mainAttributes.getValue(BUNDLE_SYMBOLIC_NAME); - int semi = bsn.indexOf(';'); - if (semi != -1) { - return bsn.substring(0, semi); // cut off ;singleton etc... - } - return bsn; - } - - // debugging - static void printAllMainAttributes(Attributes mainAttributes) { - for (Entry entry : mainAttributes.entrySet()) { - System.out.println(entry.getKey() + " -> " + entry.getValue()); - } - } -}