Skip to content
Open
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
44 changes: 39 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
description: "version number for this release."
required: true

permissions: {}

jobs:
build-maven-jars:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down Expand Up @@ -59,15 +62,46 @@
env:
GITHUB_EVENT_INPUTS_VERSION: ${{ github.event.inputs.version }}

- name: Deploy to Sonatype staging
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
workload_identity_provider: "projects/305452601764/locations/global/workloadIdentityPools/builders/providers/github"

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1

- name: Clean up stale releases from staging repo
run: |
# clean up stale releases from staging repo
packages=$(gcloud artifacts packages list \
--project="oss-exit-gate-prod" \
--location="us" \
--repository="google-java-fmt--mavencentral" \
--format="value(name)" 2>/dev/null)
echo "${packages}" | xargs -r -I {} sh -c '
package_name=$(basename "{}")
echo "Deleting package: $package_name..."
gcloud artifacts packages delete "{}" \
--project="'"oss-exit-gate-prod"'" \
--location="'"us"'" \
--repository="'"google-java-fmt--mavencentral"'" \
--quiet
'

- name: Deploy to OSS Exit Gate staging and trigger release
env:
CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: mvn --no-transfer-progress -pl '!eclipse_plugin' -P sonatype-oss-release clean deploy -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}"
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
mvn --no-transfer-progress -pl '!eclipse_plugin' -P sonatype-oss-release,oss-exit-gate clean deploy -Dgpg.passphrase="${GPG_PASSPHRASE}"
echo '{"publish_all": true}' > manifest.json
gcloud storage cp manifest.json "gs://oss-exit-gate-prod-projects-bucket/google-java-fmt/mavencentral/manifests/manifest-${RUN_ID}-${RUN_ATTEMPT}.json"

- name: Build Eclipse plugin
run: mvn --no-transfer-progress -pl 'eclipse_plugin' verify gpg:sign -DskipTests=true -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}"
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: mvn --no-transfer-progress -pl 'eclipse_plugin' verify gpg:sign -DskipTests=true -Dgpg.passphrase="${GPG_PASSPHRASE}"

- name: Push tag
run: |
Expand All @@ -76,7 +110,7 @@
GITHUB_EVENT_INPUTS_VERSION: ${{ github.event.inputs.version }}

- name: Add Artifacts to Release Entry
uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3.0.2

Check notice on line 113 in .github/workflows/release.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

superfluous-actions

release.yml:113: action functionality is already included by the runner: use `gh release` in a script step
with:
draft: true
name: ${{ github.event.input.version }}
Expand Down
6 changes: 3 additions & 3 deletions idea_plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import org.jetbrains.intellij.platform.gradle.TestFrameworkType

// https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
plugins {
id("org.jetbrains.intellij.platform") version "2.20.0"
id("org.jetbrains.intellij.platform") version "2.18.1"
// See https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#bundled-stdlib-versions
kotlin("jvm") version "2.4.21"
kotlin("jvm") version "2.4.10"
}

repositories {
Expand All @@ -31,7 +31,7 @@ repositories {

// https://github.com/google/google-java-format/releases
val googleJavaFormatVersion = "2.0.0"
val pluginPatchVersion = "1"
val pluginPatchVersion = "0"

java {
toolchain { languageVersion = JavaLanguageVersion.of(21) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.google.googlejavaformat.intellij.GoogleJavaFormatConfigurable">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand All @@ -18,7 +18,7 @@
</component>
<vspacer id="19e83">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c93e1" class="javax.swing.JLabel">
Expand All @@ -35,20 +35,6 @@
</constraints>
<properties/>
</component>
<component id="e92a1" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Max line length"/>
</properties>
</component>
<component id="a1b2c" class="com.intellij.ui.components.JBTextField" binding="maxLineLengthField" custom-create="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="1" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

package com.google.googlejavaformat.intellij;

import com.google.googlejavaformat.Doc;
import com.google.googlejavaformat.intellij.GoogleJavaFormatSettings.EnabledState;
import com.intellij.openapi.options.BaseConfigurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.SimpleListCellRenderer;
import com.intellij.ui.components.JBTextField;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
Expand All @@ -44,7 +41,6 @@ class GoogleJavaFormatConfigurable extends BaseConfigurable implements Searchabl
private JPanel panel;
private JCheckBox enable;
private JComboBox styleComboBox;
private JBTextField maxLineLengthField;

public GoogleJavaFormatConfigurable(Project project) {
this.project = project;
Expand Down Expand Up @@ -85,17 +81,6 @@ public void apply() throws ConfigurationException {
GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project);
settings.setEnabled(enable.isSelected() ? EnabledState.ENABLED : getDisabledState());
settings.setStyle(((UiFormatterStyle) styleComboBox.getSelectedItem()).convert());
int maxLineLength;
try {
maxLineLength = Integer.parseInt(maxLineLengthField.getText().trim());
} catch (NumberFormatException e) {
throw new ConfigurationException("Max line length must be a valid integer");
}
if (maxLineLength <= 0 || maxLineLength >= Doc.MAX_LINE_WIDTH) {
throw new ConfigurationException(
String.format("Max line length must be between 1 and %d", Doc.MAX_LINE_WIDTH - 1));
}
settings.setMaxLineLength(maxLineLength);
}

private EnabledState getDisabledState() {
Expand All @@ -110,25 +95,20 @@ public void reset() {
GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project);
enable.setSelected(settings.isEnabled());
styleComboBox.setSelectedItem(UiFormatterStyle.convert(settings.getStyle()));
maxLineLengthField.setText(String.valueOf(settings.getMaxLineLength()));
}

@Override
public boolean isModified() {
GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project);
return enable.isSelected() != settings.isEnabled()
|| !styleComboBox.getSelectedItem().equals(UiFormatterStyle.convert(settings.getStyle()))
|| !maxLineLengthField.getText().trim().equals(String.valueOf(settings.getMaxLineLength()));
|| !styleComboBox.getSelectedItem().equals(UiFormatterStyle.convert(settings.getStyle()));
}

@Override
public void disposeUIResources() {}

private void createUIComponents() {
styleComboBox = new ComboBox<>(UiFormatterStyle.values());
styleComboBox.setRenderer(SimpleListCellRenderer.create("", UiFormatterStyle::getDescription));
maxLineLengthField = new JBTextField();
maxLineLengthField.setColumns(4);
}

{
Expand All @@ -147,7 +127,7 @@ private void createUIComponents() {
private void $$$setupUI$$$() {
createUIComponents();
panel = new JPanel();
panel.setLayout(new GridLayoutManager(4, 2, new Insets(0, 0, 0, 0), -1, -1));
panel.setLayout(new GridLayoutManager(3, 2, new Insets(0, 0, 0, 0), -1, -1));
enable = new JCheckBox();
enable.setText("Enable google-java-format");
panel.add(
Expand All @@ -170,7 +150,7 @@ private void createUIComponents() {
panel.add(
spacer1,
new GridConstraints(
3,
2,
0,
1,
2,
Expand Down Expand Up @@ -217,40 +197,6 @@ private void createUIComponents() {
null,
1,
false));
final JLabel label2 = new JLabel();
label2.setText("Max line length");
panel.add(
label2,
new GridConstraints(
2,
0,
1,
1,
GridConstraints.ANCHOR_WEST,
GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED,
null,
null,
null,
0,
false));
panel.add(
maxLineLengthField,
new GridConstraints(
2,
1,
1,
1,
GridConstraints.ANCHOR_WEST,
GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED,
GridConstraints.SIZEPOLICY_FIXED,
null,
null,
null,
1,
false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,11 @@ boolean isUninitialized() {
}

JavaFormatterOptions.Style getStyle() {
UiFormatterStyle style = state.style != null ? state.style : UiFormatterStyle.GOOGLE;
return style.convert().toBuilder().maxLineLength(state.maxLineLength).build();
return state.style;
}

void setStyle(JavaFormatterOptions.Style style) {
state.style = UiFormatterStyle.convert(style);
state.maxLineLength = style.maxLineLength();
}

int getMaxLineLength() {
return state.maxLineLength;
}

void setMaxLineLength(int maxLineLength) {
state.maxLineLength = maxLineLength;
state.style = style;
}

enum EnabledState {
Expand All @@ -98,8 +88,7 @@ enum EnabledState {
static class State {

private EnabledState enabled = EnabledState.UNKNOWN;
public UiFormatterStyle style = UiFormatterStyle.GOOGLE;
public int maxLineLength = JavaFormatterOptions.Style.GOOGLE.maxLineLength();
public JavaFormatterOptions.Style style = JavaFormatterOptions.Style.GOOGLE;

// enabled used to be a boolean so we use bean property methods for backwards compatibility
public void setEnabled(@Nullable String enabledStr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.google.googlejavaformat.java.JavaFormatterOptions;
import com.google.googlejavaformat.java.JavaFormatterOptions.Style;
import java.util.Arrays;
import java.util.Objects;

/** Configuration options for the formatting style. */
enum UiFormatterStyle {
Expand All @@ -32,7 +34,8 @@ enum UiFormatterStyle {
this.style = style;
}

public String getDescription() {
@Override
public String toString() {
return description;
}

Expand All @@ -41,6 +44,9 @@ public JavaFormatterOptions.Style convert() {
}

static UiFormatterStyle convert(JavaFormatterOptions.Style style) {
return style.isAosp() ? AOSP : GOOGLE;
return Arrays.stream(UiFormatterStyle.values())
.filter(value -> Objects.equals(value.style, style))
.findFirst()
.get();
}
}
3 changes: 0 additions & 3 deletions idea_plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
]]></description>
<change-notes><![CDATA[
<dl>
<dt>2.0.0.1</dt>
<dd>Add max-line-length configuration support.</dd>
<dd>Fix NPEs and other errors related to a null style.</dd>
<dt>2.0.0.0</dt>
<dd>Updated to use google-java-format 2.0.0.</dd>
<dt>1.36.1.1</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,6 @@ public void aospStyle() throws Exception {
assertThat(delegatingFormatter.wasInvoked()).isTrue();
}

@Test
public void customMaxLineLength() throws Exception {
settings.setMaxLineLength(40);
PsiFile file =
createPsiFile(
"com/foo/FormatTest.java",
"package com.foo;",
"public class FormatTest {",
"void foo() {",
"System.out.println(\"This is a long string that wraps\");",
"}",
"}");
String origText = file.getText();
CodeStyleManager manager = CodeStyleManager.getInstance(file.getProject());
WriteCommandAction.runWriteCommandAction(
file.getProject(), () -> manager.reformatText(file, 0, file.getTextLength()));

Style styleWith40 = Style.GOOGLE.toBuilder().maxLineLength(40).build();
assertThat(file.getText())
.isEqualTo(
new Formatter(JavaFormatterOptions.builder().style(styleWith40).build())
.formatSource(origText));
assertThat(delegatingFormatter.wasInvoked()).isTrue();
}

@Test
public void canChangeWhitespaceOnlyDoesNotReorderModifiers() throws Exception {
settings.setStyle(Style.GOOGLE);
Expand Down
Loading
Loading