-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature flagged native image palantir-java-format #1200
Merged
+689
−256
Merged
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
52712d6
add benchmarks
crogoz 217a7b0
.
crogoz 0618efc
.
crogoz fa35c61
spotlessApply
crogoz ef7b081
test?
crogoz 25d20ea
some nativeImage
crogoz e5e8492
execute permissions
crogoz a73f12f
executable
crogoz 5de0181
working transforms
crogoz c475f83
add replacement reflect classes for native-image
crogoz 07a2d0e
.
crogoz b1119e2
bump gradle-jdks version
crogoz 0fbf044
Add generated changelog entries
svc-changelog 782f075
Add generated changelog entries
svc-changelog 25bce25
natieImage
crogoz 6d346d9
Merge branch 'cr/graal-1' of github.com:palantir/palantir-java-format…
crogoz 2a2d086
spotless
crogoz 320c77e
gradlew
crogoz d1323a4
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz 12f2b1d
compatibility
crogoz 4c058df
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz b9a2cc5
OS as part of classifier
crogoz cbccc19
configurable
crogoz 2b0d8f9
fix tests
crogoz ce67ada
no log line
crogoz 0f01291
no logging
crogoz ddad367
use gradle utils
crogoz f7fe10c
publishing
crogoz 374729d
cleanup circle configs
crogoz 09cd140
configurations
crogoz 6fd3877
cleanup
crogoz 7e0c6c7
cleanup
crogoz bb5c552
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz e37e8e3
wip
crogoz be60611
wip
crogoz 7113b17
wip
crogoz 760922c
spotless
crogoz 1191756
different plugin
crogoz ca6969b
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz a399b9e
.
crogoz 1336054
wip
crogoz b0a1950
using gradle-utils
crogoz 975ba5d
separate project
crogoz 65bc162
Merge branch 'develop' into cr/graal-1
crogoz 23b563f
name
crogoz 8db364f
keep :
crogoz 22a9f7d
fix path
crogoz 8456625
publication
crogoz 0825b1b
osExtension
crogoz 561286d
change
crogoz c492501
circleci check publishLocal
crogoz 4e1e128
glibc or musl
crogoz ecbc2ed
only bin or exe
crogoz cc3a0f2
publishing
crogoz adf33ac
if else CI
crogoz 76ea3fc
fix getEnv
crogoz c8bc7a5
fix
crogoz 3a8850d
typo
crogoz 6b9fa1f
old circle-all job
crogoz 072f22c
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz fa45c1e
fix native
crogoz 67ab915
fix
crogoz 0f28770
Merge branch 'develop' into cr/use-graal-image
crogoz c9e4c0f
.
crogoz fbf59e7
gradle utils
crogoz 0d39ef0
spotless
crogoz 25330df
formatDiff
crogoz 0937083
cleanup
crogoz 53484ad
cleanup
crogoz d47bc98
cleanup
crogoz 7e40b3a
cleanup
crogoz 1119558
.
crogoz 3baf58a
transform
crogoz 1f084a1
no usenativeImageClasspath
crogoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
working transforms
commit 5de0181db4c5af45534ccdd22a27a9697406e04d
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...alantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* (c) Copyright 2025 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* 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.palantir.javaformat.gradle; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.PosixFilePermission; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.gradle.api.artifacts.transform.InputArtifact; | ||
import org.gradle.api.artifacts.transform.TransformAction; | ||
import org.gradle.api.artifacts.transform.TransformOutputs; | ||
import org.gradle.api.artifacts.transform.TransformParameters; | ||
import org.gradle.api.file.FileSystemLocation; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
import org.gradle.api.provider.Provider; | ||
|
||
public abstract class ExecutableTransform implements TransformAction<TransformParameters.None> { | ||
|
||
private static Logger logger = Logging.getLogger(ExecutableTransform.class); | ||
|
||
@InputArtifact | ||
public abstract Provider<FileSystemLocation> getInputArtifact(); | ||
|
||
@Override | ||
public void transform(TransformOutputs outputs) { | ||
File inputFile = getInputArtifact().get().getAsFile(); | ||
makeFileExecutable(inputFile.toPath()); | ||
logger.info("Output is the input file: {}", inputFile); | ||
outputs.file(inputFile); | ||
logger.info("Output is the input file: {}", outputs); | ||
} | ||
|
||
private static void makeFileExecutable(Path pathToExe) { | ||
try { | ||
Set<PosixFilePermission> existingPermissions = Files.getPosixFilePermissions(pathToExe); | ||
Files.setPosixFilePermissions( | ||
pathToExe, | ||
Stream.concat( | ||
existingPermissions.stream(), | ||
Stream.of( | ||
PosixFilePermission.OWNER_EXECUTE, | ||
PosixFilePermission.GROUP_EXECUTE, | ||
PosixFilePermission.OTHERS_EXECUTE)) | ||
.collect(Collectors.toSet())); | ||
CRogers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logger.info("Marking is the input file as executable: {}", pathToExe); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to set execute permissions on native-image", e); | ||
} | ||
} | ||
|
||
interface Parameters extends TransformParameters {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused I think |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,27 +18,33 @@ | |
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Optional; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.type.ArtifactTypeDefinition; | ||
|
||
public final class PalantirJavaFormatProviderPlugin implements Plugin<Project> { | ||
|
||
static final String CONFIGURATION_NAME = "palantirJavaFormat"; | ||
static final String CONFIGURATION_NAME_NATIVE = "palantirJavaFormatNative"; | ||
|
||
@Override | ||
public void apply(Project rootProject) { | ||
Preconditions.checkState( | ||
rootProject == rootProject.getRootProject(), | ||
"May only apply com.palantir.java-format-provider to the root project"); | ||
Boolean legacyFormatter = Optional.ofNullable(rootProject.findProperty("palantir.legacy.formatter")) | ||
.map(value -> Boolean.getBoolean((String) value)) | ||
.orElse(false); | ||
|
||
Configuration _configuration = rootProject.getConfigurations().create(CONFIGURATION_NAME, conf -> { | ||
conf.setDescription("Internal configuration for resolving the palantir-java-format implementation"); | ||
conf.setVisible(false); | ||
conf.setCanBeConsumed(false); | ||
Configuration configuration = rootProject.getConfigurations().create(CONFIGURATION_NAME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
configuration.setDescription("Internal configuration for resolving the palantir-java-format implementation"); | ||
configuration.setVisible(false); | ||
configuration.setCanBeConsumed(false); | ||
configuration.setCanBeResolved(true); | ||
|
||
conf.defaultDependencies(deps -> { | ||
if (legacyFormatter) { | ||
configuration.defaultDependencies(deps -> { | ||
deps.add(rootProject | ||
.getDependencies() | ||
.create(ImmutableMap.of( | ||
|
@@ -49,15 +55,8 @@ public void apply(Project rootProject) { | |
"version", | ||
JavaFormatExtension.class.getPackage().getImplementationVersion()))); | ||
}); | ||
}); | ||
|
||
Configuration configuration2 = rootProject.getConfigurations().create(CONFIGURATION_NAME_NATIVE, conf -> { | ||
conf.setDescription("Internal configuration for resolving the palantir-java-format-native implementation"); | ||
conf.setVisible(false); | ||
conf.setCanBeConsumed(false); | ||
conf.setCanBeResolved(true); | ||
|
||
conf.defaultDependencies(deps -> { | ||
} else { | ||
configuration.defaultDependencies(deps -> { | ||
deps.add(rootProject | ||
.getDependencies() | ||
.create(ImmutableMap.of( | ||
|
@@ -72,8 +71,17 @@ public void apply(Project rootProject) { | |
"ext", | ||
"sh"))); | ||
}); | ||
}); | ||
configuration | ||
.getAttributes() | ||
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "executable-nativeImage"); | ||
rootProject.getDependencies().registerTransform(ExecutableTransform.class, transformSpec -> { | ||
transformSpec.getFrom().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "sh"); | ||
transformSpec | ||
.getTo() | ||
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "executable-nativeImage"); | ||
}); | ||
} | ||
|
||
rootProject.getExtensions().create("palantirJavaFormat", JavaFormatExtension.class, configuration2); | ||
rootProject.getExtensions().create("palantirJavaFormat", JavaFormatExtension.class, configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,9 +166,7 @@ publishing { | |
extension="sh" | ||
} | ||
artifactId = 'palantir-java-format-native' | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is modifying the executable in the cache, no? Really we should copy it first to not modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has other strange effects - like when I run with a
publishToMavenLocal
d executable, it changes the file in the maven local~/.m2
repo