Skip to content

Commit

Permalink
Add license check pre-release test
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol authored and senivam committed Dec 7, 2023
1 parent 9e8a293 commit bd7774f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bundles/jaxrs-ri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@
<jar destfile="${project.build.directory}/${project.artifactId}-sources.jar" update="true">
<zipfileset dir="../.." includes="NOTICE.md" prefix="META-INF" />
</jar>
<jar destfile="${project.build.directory}/${project.artifactId}.jar" update="true">
<zipfileset dir="../.." includes="LICENSE.md" prefix="META-INF" />
</jar>
</target>
</configuration>
<goals>
Expand Down
2 changes: 1 addition & 1 deletion tests/release-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2023 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
*/

package org.glassfish.jersey.test.artifacts;

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.jar.JarFile;
import java.util.stream.Collectors;

public class LegalDocsIncludedTest extends AbstractMojoTestCase {
private static final File localRepository = MavenUtil.getLocalMavenRepository();
private static final Properties properties = MavenUtil.getMavenProperties();

private static final String LICENSE_FILE = "LICENSE.md";
private static final String NOTICE_FILE = "NOTICE.md";

@Test
public void testLegalFiles() throws IOException, XmlPullParserException {
TestResult testResult = new TestResult();
List<File> jars = MavenUtil.streamJerseyJars()
.map(dependency -> MavenUtil.getArtifactJar(localRepository, dependency, properties))
.collect(Collectors.toList());

for (File jar : jars) {
for (String filename : new String[]{LICENSE_FILE, NOTICE_FILE}) {
JarFile jarFile = new JarFile(jar);
String value;
try {
value = jarFile.getEntry("META-INF/" + filename).getName();
} catch (NullPointerException npe) {
value = null;
}
TestResult.MessageBuilder builder = value != null ? testResult.ok() : testResult.exception();
builder.append(jar.getName()).append(value == null ? " DOES NOT CONTAIN " : " CONTAINS ")
.append(filename).println(" file");
}
}

//Assertions.assertTrue(testResult.result(), "Some error occurred, see previous messages");
Assert.assertTrue("Some error occurred, see previous messages", testResult.result());
}
}

0 comments on commit bd7774f

Please sign in to comment.