Skip to content

Commit

Permalink
[Build|RelEng] Clean-up and fix EnrichPom java code and fix warning
Browse files Browse the repository at this point in the history
- Move publish-to-maven project from Java-11 to 21 as the
Maven-publication process already requires Java-21
- Remove fix of scmConnection value as it's not necessary anymore (ECJ
metadata are fine out of the box) and it removes (accidentally) the
scm-tag information
- Remove now obsolete SCM-mapping
- Throw exceptions on missing information instead of using default and
be strict
- Add print-out about basic statics, i.e. the number of enhanced POM
files

- Remove unused enrichPoms.jardesc
  • Loading branch information
HannesWell committed Jan 12, 2025
1 parent 88d9506 commit be64d99
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 253 deletions.
8 changes: 4 additions & 4 deletions JenkinsJobs/Releng/publishToMaven.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pipeline {
ENRICH_POMS_JAR=${WORKSPACE}/work/EnrichPoms.jar
ENRICH_POMS_PACKAGE=org.eclipse.platform.releng.maven.pom

#TODO: Just launch as multi-file source-code program as soon as Java-22 or later is used: https://openjdk.org/jeps/458
# build the jar:
mkdir -p ${WORKSPACE}/work/bin
javac -d "${WORKSPACE}/work/bin" $(find "${MAVEN_PUBLISH_BASE}/src" -name \\*.java)
Expand All @@ -82,10 +83,9 @@ pipeline {
popd
ls -l ${ENRICH_POMS_JAR}

for project in {platform,jdt,pde}; do
echo "${project}"
java -jar ${ENRICH_POMS_JAR} "${REPO}/org/eclipse/${project}"
done
set -x
java -jar ${ENRICH_POMS_JAR} ${REPO}/org/eclipse/{platform,jdt,pde}
set +x

echo "==== Add Javadoc stubs ===="

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
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
Expand All @@ -11,4 +11,4 @@ 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=11
org.eclipse.jdt.core.compiler.source=21

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2016, 2018 GK Software SE and others.
*
* 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
Expand All @@ -10,204 +10,129 @@
*
* 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.URL;
import java.util.HashMap;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ArtifactInfo {
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 Map<String, String> MOVED_SCMS = new HashMap<>();

private static final Pattern GITHUB_PATTERN = Pattern.compile("https://github.com/([^/]+)/.*");

static {
MOVED_SCMS.put("git://git.eclipse.org/gitroot/platform/eclipse.platform.releng",
"https://github.com/eclipse-platform/eclipse.platform.releng");
MOVED_SCMS.put("https://git.eclipse.org/r/platform/eclipse.platform.releng",
"https://github.com/eclipse-platform/eclipse.platform.releng");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/platform/eclipse.platform.ui",
"https://github.com/eclipse-platform/eclipse.platform.ui");
MOVED_SCMS.put("https://git.eclipse.org/r/platform/eclipse.platform.ui",
"https://github.com/eclipse-platform/eclipse.platform.ui");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/platform/eclipse.platform.text",
"https://github.com/eclipse-platform/eclipse.platform.text");
MOVED_SCMS.put("https://git.eclipse.org/r/platform/eclipse.platform.text",
"https://github.com/eclipse-platform/eclipse.platform.text");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/platform/eclipse.platform.debug",
"https://github.com/eclipse-platform/eclipse.platform.debug");
MOVED_SCMS.put("http://git.eclipse.org/gitroot/e4/org.eclipse.e4.tools",
"https://github.com/eclipse-platform/eclipse.platform.ui.tools");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/platform/eclipse.platform.ua",
"https://github.com/eclipse-platform/eclipse.platform.ua");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/platform/eclipse.platform.swt",
"https://github.com/eclipse-platform/eclipse.platform.swt");

MOVED_SCMS.put("https://gihub.com/eclipse-platform/eclipse.platform.ua",
"https://github.com/eclipse-platform/eclipse.platform.ua");
MOVED_SCMS.put("https://github.com/eclipse-platform/org.eclipse.ui.tools",
"https://github.com/eclipse-platform/eclipse.platform.ui.tools");

MOVED_SCMS.put("https://git.eclipse.org/r/equinox/rt.equinox.bundles", "https://github.com/eclipse-equinox/p2");
MOVED_SCMS.put("https://git.eclipse.org/r/equinox/rt.equinox.p2", "https://github.com/eclipse-equinox/p2");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/equinox/rt.equinox.p2", "https://github.com/eclipse-equinox/p2");
MOVED_SCMS.put("https://git.eclipse.org/r/equinox/rt.equinox.framework",
"https://github.com/eclipse-equinox/equinox");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/equinox/rt.equinox.bundles",
"https://github.com/eclipse-equinox/equinox");

MOVED_SCMS.put("git://git.eclipse.org/gitroot/jdt/eclipse.jdt.core.binaries",
"https://github.com/eclipse-jdt/eclipse.jdt.core.binaries");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui",
"https://github.com/eclipse-jdt/eclipse.jdt.ui");
MOVED_SCMS.put("git://git.eclipse.org/gitroot/jdt/eclipse.jdt.core",
"https://github.com/eclipse-jdt/eclipse.jdt.core");
MOVED_SCMS.put("https://git.eclipse.org/r/jdt/eclipse.jdt.core",
"https://github.com/eclipse-jdt/eclipse.jdt.core");

MOVED_SCMS.put("git://git.eclipse.org/gitroot/pde/eclipse.pde.ui",
"https://github.com/eclipse-pde/eclipse.pde");
MOVED_SCMS.put("https://git.eclipse.org/r/pde/eclipse.pde.ui", "https://github.com/eclipse-pde/eclipse.pde");
}

public String bsn;
public String scmConnection;

@Override
public String toString() {
return "ArtifactInfo [bsn=" + bsn + ", scmConnection=" + scmConnection + "]";
public ArtifactInfo {
Objects.requireNonNull(bsn);
Objects.requireNonNull(scmConnection);
}

public String toPomFragment() {
String toPomFragment() {
try {
fixData();
StringBuilder buf = new StringBuilder();
String indent = INDENT;
element("url", indent, buf, getProjectURL());
if (this.scmConnection == null) {
System.err.println("No scm info for " + this.bsn);
} else {
String connectionUrl = extractScmConnection();
String url = extractScmUrl(connectionUrl);
buf.append(getFrontMatter(url));
element("scm", indent, buf, subElement("connection", connectionUrl), subElement("tag", extractScmTag()),
subElement("url", url));
Developer.addUrlDevelopers(getProjectURL(), indent, buf);
}
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) {
System.err.println("Failed for " + this);
throw e;
throw new IllegalStateException("Failed for " + this, e);
}
}

private static String getFrontMatter(String scmURL) {
String FRONT_MATTER = "" + //
" <licenses>\n" + //
" <license>\n" + //
" <name>Eclipse Public License - v 2.0</name>\n" + //
" <url>https://www.eclipse.org/legal/epl-2.0/</url>\n" + //
" <distribution>repo</distribution>\n" + //
" </license>\n" + //
" </licenses>\n" + //
" <organization>\n" + //
" <name>Eclipse Foundation</name>\n" + //
" <url>https://www.eclipse.org/</url>\n" + //
" </organization>\n" + //
" <issueManagement>\n" + //
" <system>Github</system>\n" + //
" <url>" + scmURL + "/issues</url>\n" + //
" </issueManagement>\n"; //
return FRONT_MATTER;
return String.format("""
<licenses>
<license>
<name>Eclipse Public License - v 2.0</name>
<url>https://www.eclipse.org/legal/epl-2.0/</url>
<distribution>repo</distribution>
</license>
</licenses>
<organization>
<name>Eclipse Foundation</name>
<url>https://www.eclipse.org/</url>
</organization>
<issueManagement>
<system>Github</system>
<url>%s/issues</url>
</issueManagement>
""", scmURL);
}

private void fixData() {
if (this.scmConnection == null) {
if (this.bsn.equals("org.eclipse.jdt.core.compiler.batch")) {
// not a regular OSGi bundle, scm info missing:
this.scmConnection = "scm:git:https://github.com/eclipse-jdt/eclipse.jdt.core.git;path=\"org.eclipse.jdt.core\"";
System.out.println("Fixed scmUrl for " + this.bsn);
}
} else {
this.scmConnection = "scm:git:" + extractScmUrl(extractScmConnection()) + ".git";
}
}

String getProjectURL() {
String scmURL = extractScmUrl(extractScmConnection());
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('-', '.');
}

return "https://projects.eclipse.org/projects/";
throw new IllegalArgumentException("Unexpected scm-URL: " + scmURL);
}

String extractScmConnection() {
int semi = this.scmConnection.indexOf(';');
if (semi == -1)
return this.scmConnection;
return this.scmConnection.substring(0, semi);
private String extractScmConnection() {
return substringTo(this.scmConnection, 0, ';');
}

String extractScmTag() {
private String extractScmTag() {
int tagStart = this.scmConnection.indexOf(SCM_TAG_START);
if (tagStart == -1)
return null;
int next = this.scmConnection.indexOf("\"", tagStart + SCM_TAG_START.length());
if (next == -1)
next = this.scmConnection.length();
return this.scmConnection.substring(tagStart + SCM_TAG_START.length(), next);
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<String> visitedSCMs = new HashSet<>();

String extractScmUrl(String connection) {
String scmURL = connection.replaceAll("^scm:git:", "").replaceAll("^scm:githttps:", "https:")
.replaceAll("\\.git$", "");
String movedSCMURL = MOVED_SCMS.get(scmURL);
if (movedSCMURL != null) {
scmURL = movedSCMURL;
}
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 URL(scmURL).openStream()) {
try (InputStream in = new URI(scmURL).toURL().openStream()) {
} catch (Exception ex) {
ex.printStackTrace();
}
}
return scmURL;
}

public static void element(String tag, String indent, StringBuilder buf, String... contents) {
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)
if (content != null)
for (String line : content.split("\\n"))
buf.append(indent).append(INDENT).append(line).append('\n');
for (String content : contents) {
content.lines().forEach(line -> buf.append(indent).append(INDENT).append(line).append('\n'));
}
buf.append(indent);
}
buf.append("</").append(tag).append(">\n");
}

public static String subElement(String tag, String content) {
if (content == null)
return null;
private static String subElement(String tag, String content) {
Objects.requireNonNull(content);
StringBuilder buf = new StringBuilder();
element(tag, "", buf, content);
return buf.toString();
Expand Down

This file was deleted.

Loading

0 comments on commit be64d99

Please sign in to comment.