Write Kotlin-Version to runtime artifacts built with Maven
Add a test that checks that Kotlin-Version and Kotlin-Runtime-Component have been written to all relevant runtime libraries
This commit is contained in:
@@ -1073,7 +1073,7 @@
|
||||
</class-path>
|
||||
</new-kotlinc>
|
||||
|
||||
<pack-runtime-jar jar-name="kotlin-test.jar" implementation-title="${manifest.impl.title.kotlin.test}">
|
||||
<pack-runtime-jar jar-name="kotlin-test.jar" implementation-title="${manifest.impl.title.kotlin.test}" runtime-component="Test">
|
||||
<jar-content>
|
||||
<fileset dir="${output}/classes/kotlin-test" includes="**/*" excludes="kotlin/internal/OnlyInputTypes*,kotlin/internal/InlineOnly*,kotlin/internal"/>
|
||||
</jar-content>
|
||||
@@ -1118,6 +1118,7 @@
|
||||
<attribute name="jar-dir" default="${kotlin-home}/lib"/>
|
||||
<attribute name="jar-name"/>
|
||||
<attribute name="implementation-title"/>
|
||||
<attribute name="runtime-component" default="${manifest.impl.value.kotlin.runtime.component.core}"/>
|
||||
<element name="jar-content"/>
|
||||
|
||||
<sequential>
|
||||
@@ -1130,7 +1131,7 @@
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
|
||||
<attribute name="${manifest.impl.attribute.kotlin.version}" value="${manifest.impl.value.kotlin.version}"/>
|
||||
<attribute name="${manifest.impl.attribute.kotlin.runtime.component}" value="${manifest.impl.value.kotlin.runtime.component.core}"/>
|
||||
<attribute name="${manifest.impl.attribute.kotlin.runtime.component}" value="@{runtime-component}"/>
|
||||
|
||||
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
|
||||
<attribute name="Implementation-Title" value="@{implementation-title}"/>
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
<kotlin-sdk>${kotlin-dist}/kotlinc</kotlin-sdk>
|
||||
<kotlin.compiler.jdkHome>${env.JDK_16}</kotlin.compiler.jdkHome>
|
||||
|
||||
<kotlin.language.version>1.1</kotlin.language.version>
|
||||
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
@@ -108,6 +108,18 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Kotlin-Version>${kotlin.language.version}</Kotlin-Version>
|
||||
<Kotlin-Runtime-Component>Core</Kotlin-Runtime-Component>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -78,6 +78,19 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Kotlin-Version>${kotlin.language.version}</Kotlin-Version>
|
||||
<Kotlin-Runtime-Component>Core</Kotlin-Runtime-Component>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
@@ -79,6 +79,19 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Kotlin-Version>${kotlin.language.version}</Kotlin-Version>
|
||||
<Kotlin-Runtime-Component>Core</Kotlin-Runtime-Component>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
@@ -68,6 +68,20 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Kotlin-Version>${kotlin.language.version}</Kotlin-Version>
|
||||
<Kotlin-Runtime-Component>Core</Kotlin-Runtime-Component>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
@@ -38,6 +38,21 @@
|
||||
<artifactId>kotlin-js-library</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>test-kotlin-version-in-manifest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-common</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-script-runtime</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>process-test-sources</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package test
|
||||
|
||||
import java.net.URL
|
||||
import java.util.jar.Attributes
|
||||
import java.util.jar.Manifest
|
||||
|
||||
// "Kotlin Reflect" and "Kotlin Script Runtime" are different because unlike other libraries which are built with Maven, they're copied from dist
|
||||
val LIBRARIES = listOf(
|
||||
"kotlin-runtime",
|
||||
"kotlin-stdlib",
|
||||
"kotlin-stdlib-common",
|
||||
"kotlin-stdlib-jre7",
|
||||
"kotlin-stdlib-jre8",
|
||||
"Kotlin Reflect",
|
||||
"Kotlin Script Runtime"
|
||||
)
|
||||
|
||||
const val KOTLIN_VERSION = "Kotlin-Version"
|
||||
const val KOTLIN_RUNTIME_COMPONENT = "Kotlin-Runtime-Component"
|
||||
const val KOTLIN_RUNTIME_COMPONENT_VALUE = "Core"
|
||||
val KOTLIN_VERSION_VALUE = with(KotlinVersion.CURRENT) { "$major.$minor" }
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val implementationTitles = arrayListOf<String>()
|
||||
|
||||
val versionValues = hashMapOf<URL, String?>()
|
||||
val runtimeComponentValues = hashMapOf<URL, String?>()
|
||||
|
||||
for (resource in object {}.javaClass.classLoader.getResources("META-INF/MANIFEST.MF")) {
|
||||
val manifest = resource.openStream().use(::Manifest).mainAttributes
|
||||
val title = manifest.getValue(Attributes.Name.IMPLEMENTATION_TITLE) ?: continue
|
||||
if ("kotlin" !in title.toLowerCase()) continue
|
||||
|
||||
implementationTitles.add(title)
|
||||
versionValues[resource] = manifest.getValue(KOTLIN_VERSION)
|
||||
runtimeComponentValues[resource] = manifest.getValue(KOTLIN_RUNTIME_COMPONENT)
|
||||
}
|
||||
|
||||
val errors = StringBuilder()
|
||||
|
||||
val uncheckedLibraries = LIBRARIES - implementationTitles
|
||||
if (uncheckedLibraries.isNotEmpty()) {
|
||||
errors.appendln("These libraries are not found in the dependencies of this test project, thus their manifests cannot be checked. " +
|
||||
"Please ensure they are listed in the <dependencies> section in the corresponding pom.xml:\n$uncheckedLibraries")
|
||||
errors.appendln("(all found libraries: $implementationTitles)")
|
||||
errors.appendln()
|
||||
}
|
||||
|
||||
fun renderEntry(entry: Map.Entry<URL, String?>) = buildString {
|
||||
val (url, value) = entry
|
||||
append(url)
|
||||
if (value != null) append(" (actual value: $value)")
|
||||
else append(" (attribute is not found)")
|
||||
}
|
||||
|
||||
val incorrectVersionValues = versionValues.filterValues { it != KOTLIN_VERSION_VALUE }
|
||||
if (incorrectVersionValues.isNotEmpty()) {
|
||||
errors.appendln("Manifests at these locations do not have the correct value of the $KOTLIN_VERSION attribute ($KOTLIN_VERSION_VALUE). " +
|
||||
"Please ensure that kotlin.language.version in libraries/pom.xml corresponds to the value in kotlin.KotlinVersion:")
|
||||
incorrectVersionValues.entries.joinTo(errors, "\n", transform = ::renderEntry)
|
||||
errors.appendln()
|
||||
errors.appendln()
|
||||
}
|
||||
|
||||
val incorrectRuntimeComponentValues = runtimeComponentValues.filterValues { it != KOTLIN_RUNTIME_COMPONENT_VALUE }
|
||||
if (incorrectRuntimeComponentValues.isNotEmpty()) {
|
||||
errors.appendln("Manifests at these locations do not have the correct value of the $KOTLIN_RUNTIME_COMPONENT attribute ($KOTLIN_RUNTIME_COMPONENT_VALUE):")
|
||||
incorrectRuntimeComponentValues.entries.joinTo(errors, "\n", transform = ::renderEntry)
|
||||
}
|
||||
|
||||
if (errors.isNotEmpty()) {
|
||||
throw AssertionError(errors)
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestKotlinVersionInManifest {
|
||||
@Test
|
||||
public void greeting() {
|
||||
test.TestKt.main(new String[0]);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import java.io.*;
|
||||
|
||||
File file = new File(basedir, "target/test-kotlin-version-in-manifest-1.0-SNAPSHOT.jar");
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new FileNotFoundException("Could not find generated JAR: " + file);
|
||||
}
|
||||
@@ -107,6 +107,19 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Kotlin-Version>${kotlin.language.version}</Kotlin-Version>
|
||||
<Kotlin-Runtime-Component>Core</Kotlin-Runtime-Component>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user