Skip to content

Commit

Permalink
Multi-Release jar experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
cushon committed Aug 5, 2024
1 parent 86df5cf commit f208837
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 55 deletions.
1 change: 1 addition & 0 deletions bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-fixupmessages: "Classes found in the wrong directory"; restrict:=error; is:=warning
73 changes: 59 additions & 14 deletions check_api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,67 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${autovalue.version}</version>
</path>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${autoservice.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<jdkToolchain>
<version>11</version>
</jdkToolchain>
<fork>true</fork>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${autovalue.version}</version>
</path>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${autoservice.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>java24</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>24</source>
<target>24</target>
<jdkToolchain>
<version>24</version>
</jdkToolchain>
<fork>true</fork>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/java24</compileSourceRoot>
</compileSourceRoots>
<!-- multiReleaseOutput requires setting release -->
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/24</outputDirectory>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${autovalue.version}</version>
</path>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${autoservice.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>

</plugin>
</plugins>

</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 The Error Prone Authors.
*
* 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 com.google.errorprone.util;

import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.Name;

import java.util.Arrays;

import static java.nio.charset.StandardCharsets.UTF_8;

class ErrorProneSignatureGenerator extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected ErrorProneSignatureGenerator(Types types) {
super(types);
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@Override
public String toString() {
// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
}
}
40 changes: 2 additions & 38 deletions check_api/src/main/java/com/google/errorprone/util/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.errorprone.util;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.joining;

import com.sun.tools.javac.code.BoundKind;
Expand All @@ -25,60 +24,25 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.code.Types.DefaultTypeVisitor;
import com.sun.tools.javac.code.Types.SignatureGenerator;
import com.sun.tools.javac.util.Name;
import java.util.Arrays;

/** Signature generation. */
public final class Signatures {

/** Returns the binary names of the class. */
public static String classDescriptor(Type type, Types types) {
SigGen sig = new SigGen(types);
ErrorProneSignatureGenerator sig = new ErrorProneSignatureGenerator(types);
sig.assembleClassSig(types.erasure(type));
return sig.toString();
}

/** Returns a JVMS 4.3.3 method descriptor. */
public static String descriptor(Type type, Types types) {
SigGen sig = new SigGen(types);
ErrorProneSignatureGenerator sig = new ErrorProneSignatureGenerator(types);
sig.assembleSig(types.erasure(type));
return sig.toString();
}

private static class SigGen extends SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected SigGen(Types types) {
super(types);
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@Override
public String toString() {
// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
}
}

/**
* Pretty-prints a method signature for use in diagnostics.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 The Error Prone Authors.
*
* 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 com.google.errorprone.util;

import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.Name;

import java.util.Arrays;

import static java.nio.charset.StandardCharsets.UTF_8;

class ErrorProneSignatureGenerator extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected ErrorProneSignatureGenerator(Types types) {
types.super();
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@Override
public String toString() {
// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
}
}
5 changes: 3 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>11</compilerVersion>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
Expand All @@ -397,7 +398,7 @@
</configuration>
</plugin>
<!-- Include the @BugPattern annotation in the main distribution
so users have only one jar to add to their classpath. -->
so users have only one jar to add to their classpath. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand All @@ -413,7 +414,7 @@
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<!-- Include only dependencies with compatible licenses.
Apache, BSD, and MIT are OK; others are not. -->
Apache, BSD, and MIT are OK; others are not. -->
<includes>
<include>com.github.kevinstern:software-and-algorithms</include>
<include>com.google.errorprone:error_prone_annotation</include>
Expand Down
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
Expand Down Expand Up @@ -264,6 +264,25 @@
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<toolchains>
<jdk>
<version>11</version>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down

0 comments on commit f208837

Please sign in to comment.