Skip to content

Commit

Permalink
Merge pull request #3 from noties/F/34
Browse files Browse the repository at this point in the history
Android 34
  • Loading branch information
noties authored Nov 1, 2023
2 parents 1cb48e3 + 24f76bf commit b5a3e47
Show file tree
Hide file tree
Showing 23 changed files with 415 additions and 234 deletions.
9 changes: 4 additions & 5 deletions .run/Enhance.run.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Enhance" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="ALTERNATIVE_JRE_PATH" value="azul-13" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="ru.noties.enhance.Enhance" />
<option name="MAIN_CLASS_NAME" value="io.noties.enhance.Enhance" />
<module name="enhance.main" />
<option name="PROGRAM_PARAMETERS" value="-sdk 33 -format google" />
<option name="PROGRAM_PARAMETERS" value="-sdk 34 -format google" />
<option name="VM_PARAMETERS" value="--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ru.noties.enhance.*" />
<option name="PATTERN" value="io.noties.enhance.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# CHANGELOG

# 34
Applied new version-name strategy - now version equals latest supported Android SDK platform
### Added
* Upside Down Cake (34)

### Changed
* Updated code structure, moved to `io.noties` package (no change for clients)


# 1.3.0
### Added
* Android S_V2 (32)
* Tiramisu (33)


# 1.2.0
### Added
* Android 12, SDK 31 API version
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ java -jar enhance.jar -sdk 26 -sp "/Users/not_me/android/sdk"

If you would like to restore unmodified copy of source code you can find it: `{your-home-directory}/.enhance-backup/android-{sdk}`

## Formatting on JDK 17
Formatting is done with the [google-java-format](https://github.com/google/google-java-format) library
which requires access to the internals of the JDK. This is why on JDK-17 in order to format
the sources additional commandline arguments are required:

```bash
java \
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
-jar enhance-34-all.jar -sdk 34 -format google
```

## Thanks

Big kudos to the maintainers of amazing [javaparser](https://github.com/javaparser/javaparser)!
Expand Down
24 changes: 13 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
plugins {
// https://github.com/johnrengelman/shadow
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'java'
id 'application'
}

group 'ru.noties'
version '1.3.0'
group 'io.noties'
version '34'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

mainClassName = 'ru.noties.enhance.Enhance'
mainClassName = 'io.noties.enhance.Enhance'

repositories {
jcenter()
Expand All @@ -21,14 +22,15 @@ dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'

// https://github.com/javaparser/javaparser
implementation 'com.github.javaparser:javaparser-core:3.24.8'
implementation 'com.github.javaparser:javaparser-core:3.25.5'

// https://github.com/google/google-java-format
implementation 'com.google.googlejavaformat:google-java-format:1.5'
implementation 'com.google.googlejavaformat:google-java-format:1.18.1'

implementation 'commons-cli:commons-cli:1.4'
implementation 'commons-io:commons-io:2.6'
testImplementation 'junit:junit:4.12'
implementation 'commons-io:commons-io:2.7'

testImplementation 'junit:junit:4.13.1'
}

wrapper {
Expand All @@ -37,13 +39,13 @@ wrapper {
}

afterEvaluate {
final def folder = new File(rootDir, '/gen/ru/noties/enhance')
final def folder = new File(rootDir, '/gen/io/noties/enhance')
if (!folder.exists()) {
folder.mkdirs()
}
final def file = new File(folder, 'EnhanceVersion.java')
file.write("""
package ru.noties.enhance;
package io.noties.enhance;
class EnhanceVersion { static final String NAME = \"${version}\"; }
""")
}
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/io/noties/enhance/Api.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.noties.enhance;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.List;

public enum Api {
SDK_1(1, "1.0", "(initial)"),
SDK_2(2, "1.1", "(initial)"),
SDK_3(3, "1.5", "Cupcake"),
SDK_4(4, "1.6", "Donut"),
SDK_5(5, "2.0", "Eclair"),
SDK_6(6, "2.0.1", "Eclair"),
SDK_7(7, "2.1", "Eclair"),
SDK_8(8, "2.2", "Froyo"),
SDK_9(9, "2.3", "Gingerbread"),
SDK_10(10, "2.3.3", "Gingerbread"),
SDK_11(11, "3.0", "Honeycomb"),
SDK_12(12, "3.1", "Honeycomb"),
SDK_13(13, "3.2", "Honeycomb"),
SDK_14(14, "4.0", "Ice Scream Sandwich"),
SDK_15(15, "4.0.3", "Ice Scream Sandwich"),
SDK_16(16, "4.1", "Jelly Bean"),
SDK_17(17, "4.2", "Jelly Bean"),
SDK_18(18, "4.3", "Jelly Bean"),
SDK_19(19, "4.4", "Kitkat"),
SDK_20(20, "4.4W", "Kitkat"),
SDK_21(21, "5.0", "Lollipop"),
SDK_22(22, "5.1", "Lollipop"),
SDK_23(23, "6.0", "Marshmallow"),
SDK_24(24, "7.0", "Nougat"),
SDK_25(25, "7.1", "Nougat"),
SDK_26(26, "8.0", "Oreo"),
SDK_27(27, "8.1", "Oreo"),
SDK_28(28, "9.0", "Pie"),
SDK_29(29, "10", "Android Q"),
SDK_30(30, "11", "Android R"),
SDK_31(31, "12", "Android S"),
SDK_32(32, "12", "Android S_V2"),
SDK_33(33, "13", "Tiramisu"),
SDK_34(34, "14", "Upside Down Cake")
;

public final int sdkInt;
public final String versionName;
public final String codeName;

Api(int sdkInt, @Nonnull String versionName, @Nonnull String codeName) {
this.sdkInt = sdkInt;
this.versionName = versionName;
this.codeName = codeName;
}

@Override
public String toString() {
return "Api.SDK{" +
"sdkInt=" + sdkInt +
", versionName='" + versionName + '\'' +
", codeName='" + codeName + '\'' +
'}';
}

private static final List<Api> VALUES = List.of(values());

@Nonnull
public static Api latest() {
return VALUES.get(VALUES.size() - 1);
}

@Nullable
public static Api of(int sdkInt) {
// NB! we assume that it starts at 1
// so, SDK_1 is at 0, SDK_2 at 1, etc
final int ordinal = sdkInt - 1;
if (ordinal < 0 || ordinal >= VALUES.size()) {
return null;
}
return VALUES.get(ordinal);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ru.noties.enhance;
package io.noties.enhance;

import javax.annotation.Nullable;

public class ApiInfo {

public final ApiVersion since;
public final ApiVersion deprecated;
@Nullable
public final Integer since;
@Nullable public final Integer deprecated;

public ApiInfo(ApiVersion since, ApiVersion deprecated) {
public ApiInfo(@Nullable Integer since, @Nullable Integer deprecated) {
this.since = since;
this.deprecated = deprecated;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.noties.enhance;
package io.noties.enhance;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -13,12 +13,12 @@ public static ApiInfoStore create(@Nonnull File apiVersions) {
return new ApiInfoStoreImpl(apiVersions);
}

static class TypeVersion extends ApiInfo {
public static class TypeVersion extends ApiInfo {

final Map<String, ApiInfo> fields = new HashMap<>(3);
final Map<String, ApiInfo> methods = new HashMap<>(3);

TypeVersion(ApiVersion since, ApiVersion deprecated) {
TypeVersion(@Nullable Integer since, @Nullable Integer deprecated) {
super(since, deprecated);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.noties.enhance;
package io.noties.enhance;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -156,17 +156,17 @@ private static void methods(@Nonnull TypeVersion version, @Nonnull Element paren
private static boolean isEmpty(@Nonnull TypeVersion version) {
return version.since == null
&& version.deprecated == null
&& version.fields.size() == 0
&& version.methods.size() == 0;
&& version.fields.isEmpty()
&& version.methods.isEmpty();
}

@Nullable
private static ApiInfo apiInfo(@Nonnull Element element) {

final ApiInfo apiInfo;

final ApiVersion since = apiVersion(element.getAttribute(SINCE));
final ApiVersion deprecated = apiVersion(element.getAttribute(DEPRECATED));
final Integer since = apiVersion(element.getAttribute(SINCE));
final Integer deprecated = apiVersion(element.getAttribute(DEPRECATED));

if (since == null
&& deprecated == null) {
Expand All @@ -179,21 +179,19 @@ private static ApiInfo apiInfo(@Nonnull Element element) {
}

@Nullable
private static ApiVersion apiVersion(@Nullable String value) {
final ApiVersion version;
if (value == null
|| value.length() == 0) {
version = null;
} else {
int sdk;
try {
sdk = Integer.parseInt(value);
} catch (NumberFormatException e) {
sdk = 0;
}
version = ApiVersion.of(sdk);
private static Integer apiVersion(@Nullable String value) {
if (value == null || value.isEmpty()) {
return null;
}

try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
return version;

return null;
}

private static final Pattern RE = Pattern.compile("L\\w+[/\\w]+[/$](\\w+);");
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/io/noties/enhance/ApiVersionFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.noties.enhance;

import javax.annotation.Nonnull;

public abstract class ApiVersionFormatter {

@Nonnull
public static ApiVersionFormatter create() {
return new Impl();
}

@Nonnull
public abstract String format(int version);


private static class Impl extends ApiVersionFormatter {

@Nonnull
@Override
public String format(int version) {
final Api api = Api.of(version);
if (api != null) {
// for example - @since 5.1 Lollipop (22)
return api.versionName + " " + api.codeName + " (" + api.sdkInt + ")";
}
return "unknown (" + version + ")";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.noties.enhance;
package io.noties.enhance;

import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
Expand Down
Loading

0 comments on commit b5a3e47

Please sign in to comment.