Skip to content

Commit

Permalink
Release test: check the staged artifacts are valid
Browse files Browse the repository at this point in the history
Check JDK version for the build
Check Multi-Release jars
Check versions in jar
Check OsgiHeaders

Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Aug 30, 2022
1 parent da45922 commit 9b62041
Show file tree
Hide file tree
Showing 11 changed files with 877 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/release-test/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[//]: # " Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. "
[//]: # " "
[//]: # " This program and the accompanying materials are made available under the "
[//]: # " terms of the Eclipse Public License v. 2.0, which is available at "
[//]: # " http://www.eclipse.org/legal/epl-2.0. "
[//]: # " "
[//]: # " This Source Code may also be made available under the following Secondary "
[//]: # " Licenses when the conditions for such availability set forth in the "
[//]: # " Eclipse Public License v. 2.0 are satisfied: GNU General Public License, "
[//]: # " version 2 with the GNU Classpath Exception, which is available at "
[//]: # " https://www.gnu.org/software/classpath/license.html. "
[//]: # " "
[//]: # " SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 "

This module is to check the built artifacts before release.

The module can check Jersey 2.x, 3.0.x, and 3.1.x versions.

Usage:
* mvn test -Djersey.version=<version> [-Pstaging]
122 changes: 122 additions & 0 deletions tests/release-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.ee4j</groupId>
<artifactId>project</artifactId>
<version>1.0.7</version>
<relativePath>../../../pom.xml</relativePath>
</parent>

<groupId>org.glassfish.jersey.tests</groupId>
<artifactId>release-test</artifactId>
<version>2.37-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jersey-release-test</name>

<description>Jersey post-release validation tests</description>

<properties>
<jersey.version>${jersey.version}</jersey.version> <!-- Must pass using -Djersey.version= -->
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.version>3.8.6</maven.version>
<maven.resolver.version>1.7.3</maven.resolver.version> <!-- 1.8.2 does not work-->
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<enableAssertions>false</enableAssertions>
<includes>
<include>**/DownloadBomPomDependencies.java</include>
<include>**/*Test.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<!-- maven-plugin-testing-harness does not work with junit 5 -->
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.glassfish.jersey.test.artifacts;

import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

class ClassVersionChecker {
static TestResult checkClassVersion(JarFile jar, JarEntry entry, Properties properties) throws IOException {
final String jerseyVersion = MavenUtil.getJerseyVersion(properties);
final int minVersion = jerseyVersion.startsWith("3.1") ? 11 : 8;
return checkClassVersion(jar.getInputStream(entry), jar.getName() + File.separator + entry.getName(), minVersion);
}

private static TestResult checkClassVersion(InputStream inputStream, String filename, int version) throws IOException {
TestResult result = new TestResult();
DataInputStream in = new DataInputStream(inputStream);

int magic = in.readInt();
if (magic != -889275714) {
result.exception().append(filename).println(" is not a valid class!");
}

int minor = in.readUnsignedShort();
int major = in.readUnsignedShort();
int classVersion = convertMajorMinorToSE(major, minor);
TestResult.MessageBuilder builder = classVersion <= version ? result.ok() : result.exception();
builder.append(filename).append(": ").append(major).append(".").append(minor).append(" = JDK ")
.println(String.valueOf(classVersion));
in.close();
return result;
}

private static int convertMajorMinorToSE(int major, int minor) {
int comp = (major - 44 + minor);
return comp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.glassfish.jersey.test.artifacts;

import java.util.Arrays;

class DependencyPair {
private final String groupId;
private final String artifactId;

DependencyPair(String groupId, String artifactId) {
this.groupId = groupId;
this.artifactId = artifactId;
}

String artifactId() {
return artifactId;
}

String groupId() {
return groupId;
}

static DependencyPair[] concat(DependencyPair[] first, DependencyPair[] second) {
DependencyPair[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}

@Override
public String toString() {
return groupId + ':' + artifactId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.glassfish.jersey.test.artifacts;

import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;

import java.util.List;

/**
*
* @author lukas
*/
final class DependencyResolver {
static Artifact resolveArtifact(org.apache.maven.model.Dependency d, List<RemoteRepository> remoteRepos,
RepositorySystem repoSystem, RepositorySystemSession repoSession)
throws ArtifactResolutionException {
DefaultArtifact artifact = new DefaultArtifact(
d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion()
);
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(remoteRepos);
return repoSystem.resolveArtifact(repoSession, request).getArtifact();
}
}
Loading

0 comments on commit 9b62041

Please sign in to comment.