Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-558.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: break
break:
description: Remove square javapoet references
links:
- https://github.com/palantir/goethe/pull/558
2 changes: 0 additions & 2 deletions goethe/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ apply plugin: 'com.palantir.shadow-jar'

dependencies {
compileOnlyApi 'com.palantir.javapoet:javapoet'
compileOnlyApi 'com.squareup:javapoet'

// Avoid conflicts with formatters used elsewhere
shadeTransitively 'com.palantir.javaformat:palantir-java-format'
shadeTransitively 'com.palantir.javaformat:palantir-java-format-spi'

testImplementation 'com.palantir.javapoet:javapoet'
testImplementation 'com.squareup:javapoet'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
Expand Down
76 changes: 6 additions & 70 deletions goethe/src/main/java/com/palantir/goethe/Goethe.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.palantir.javapoet.JavaFile;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
Expand All @@ -40,12 +41,12 @@ public final class Goethe {
private static final FormatterFacade JAVA_FORMATTER = FormatterFacadeFactory.create();

/**
* Format a {@link com.palantir.javapoet.JavaFile javapoet java file} into a {@link String}.
* Format a {@link JavaFile javapoet java file} into a {@link String}.
*
* @param file Javapoet file to format
* @return Formatted source code
*/
public static String formatAsString(com.palantir.javapoet.JavaFile file) {
public static String formatAsString(JavaFile file) {
StringBuilder rawSource = new StringBuilder();
try {
file.writeTo(rawSource);
Expand All @@ -57,29 +58,13 @@ public static String formatAsString(com.palantir.javapoet.JavaFile file) {
}

/**
* Format a {@link com.squareup.javapoet.JavaFile javapoet java file} into a {@link String}.
*
* @param file Javapoet file to format
* @return Formatted source code
*/
public static String formatAsString(com.squareup.javapoet.JavaFile file) {
StringBuilder rawSource = new StringBuilder();
try {
file.writeTo(rawSource);
return JAVA_FORMATTER.formatSource(file.packageName + '.' + file.typeSpec.name, rawSource.toString());
} catch (IOException e) {
throw new GoetheException("Formatting failed", e);
}
}

/**
* Format a {@link com.palantir.javapoet.JavaFile javapoet java file} and write the result to an {@link Filer annotation processing
* Format a {@link JavaFile javapoet java file} and write the result to an {@link Filer annotation processing
* filer}.
*
* @param file Javapoet file to format
* @param filer Destination for the formatted file
*/
public static void formatAndEmit(com.palantir.javapoet.JavaFile file, Filer filer) {
public static void formatAndEmit(JavaFile file, Filer filer) {
String formatted = formatAsString(file);

JavaFileObject filerSourceFile = null;
Expand All @@ -104,45 +89,14 @@ public static void formatAndEmit(com.palantir.javapoet.JavaFile file, Filer file
}
}

/**
* Format a {@link com.squareup.javapoet.JavaFile javapoet java file} and write the result to an {@link Filer annotation processing
* filer}.
*
* @param file Javapoet file to format
* @param filer Destination for the formatted file
*/
public static void formatAndEmit(com.squareup.javapoet.JavaFile file, Filer filer) {
String formatted = formatAsString(file);

JavaFileObject filerSourceFile = null;
try {
String className =
file.packageName.isEmpty() ? file.typeSpec.name : file.packageName + "." + file.typeSpec.name;
filerSourceFile =
filer.createSourceFile(className, file.typeSpec.originatingElements.toArray(new Element[0]));
try (Writer writer = filerSourceFile.openWriter()) {
writer.write(formatted);
}
} catch (IOException e) {
if (filerSourceFile != null) {
try {
filerSourceFile.delete();
} catch (Exception deletionFailure) {
e.addSuppressed(deletionFailure);
}
}
throw new GoetheException("Failed to write formatted code to the filer", e);
}
}

/**
* Formats the given Java file and emits it to the appropriate directory under {@code baseDir}.
*
* @param file Javapoet file to format
* @param baseDir Source set root where the formatted file will be written
* @return the new file location
*/
public static Path formatAndEmit(com.palantir.javapoet.JavaFile file, Path baseDir) {
public static Path formatAndEmit(JavaFile file, Path baseDir) {
String formatted = formatAsString(file);
try {
Path output =
Expand All @@ -154,24 +108,6 @@ public static Path formatAndEmit(com.palantir.javapoet.JavaFile file, Path baseD
}
}

/**
* Formats the given Java file and emits it to the appropriate directory under {@code baseDir}.
*
* @param file Javapoet file to format
* @param baseDir Source set root where the formatted file will be written
* @return the new file location
*/
public static Path formatAndEmit(com.squareup.javapoet.JavaFile file, Path baseDir) {
String formatted = formatAsString(file);
try {
Path output = getFilePath(baseDir, file.packageName, file.typeSpec.name);
Files.writeString(output, formatted);
return output;
} catch (IOException e) {
throw new GoetheException("Failed to write formatted sources", e);
}
}

/**
* Returns the full path for the given Java file and Java base dir. In a nutshell, turns packages into directories,
* e.g., {@code com.foo.bar.MyClass -> /<baseDir>/com/foo/bar/MyClass.java} and creates all directories.
Expand Down
135 changes: 0 additions & 135 deletions goethe/src/test/java/com/palantir/goethe/GoetheSquareTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;

class GoethePalantirTest {
class GoetheTest {

@TempDir
Path tempDir;
Expand Down
1 change: 0 additions & 1 deletion versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ com.google.j2objc:j2objc-annotations:3.0.0 (1 constraints: 150aeab4)
com.palantir.javaformat:palantir-java-format:2.50.0 (1 constraints: 39053f3b)
com.palantir.javaformat:palantir-java-format-spi:2.50.0 (2 constraints: 42183e8e)
com.palantir.javapoet:javapoet:0.1.0 (1 constraints: 0305ee35)
com.squareup:javapoet:1.13.0 (1 constraints: 3705323b)
org.checkerframework:checker-qual:3.43.0 (1 constraints: 4c0a4abf)
org.functionaljava:functionaljava:4.8 (1 constraints: 81129900)

Expand Down
1 change: 0 additions & 1 deletion versions.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
com.fasterxml.jackson.core:jackson-databind = 2.18.1
com.squareup:javapoet = 1.13.0
com.palantir.javapoet:javapoet = 0.1.0
com.palantir.javaformat:* = 2.50.0
com.google.guava:guava = 33.3.1-jre
Expand Down