diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 47346bffe..034994b19 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,11 +21,14 @@ on: 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 @@ -59,15 +62,46 @@ jobs: 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: | diff --git a/idea_plugin/build.gradle.kts b/idea_plugin/build.gradle.kts index c4e9d610b..132d79bf0 100644 --- a/idea_plugin/build.gradle.kts +++ b/idea_plugin/build.gradle.kts @@ -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 { @@ -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) } diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form index 7f299f589..1db1d7920 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.form @@ -1,6 +1,6 @@
diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java index 72c0f49e2..3a98c2eb9 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable.java @@ -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; @@ -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; @@ -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() { @@ -110,15 +95,13 @@ 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 @@ -126,9 +109,6 @@ public void disposeUIResources() {} private void createUIComponents() { styleComboBox = new ComboBox<>(UiFormatterStyle.values()); - styleComboBox.setRenderer(SimpleListCellRenderer.create("", UiFormatterStyle::getDescription)); - maxLineLengthField = new JBTextField(); - maxLineLengthField.setColumns(4); } { @@ -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( @@ -170,7 +150,7 @@ private void createUIComponents() { panel.add( spacer1, new GridConstraints( - 3, + 2, 0, 1, 2, @@ -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)); } /** diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatSettings.java b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatSettings.java index 1e443f7e6..4546f68a3 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatSettings.java +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatSettings.java @@ -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 { @@ -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) { diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/UiFormatterStyle.java b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/UiFormatterStyle.java index eddd498ac..24ed6f62c 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/UiFormatterStyle.java +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/UiFormatterStyle.java @@ -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 { @@ -32,7 +34,8 @@ enum UiFormatterStyle { this.style = style; } - public String getDescription() { + @Override + public String toString() { return description; } @@ -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(); } } diff --git a/idea_plugin/src/main/resources/META-INF/plugin.xml b/idea_plugin/src/main/resources/META-INF/plugin.xml index 8efab4b59..403fd1a1f 100644 --- a/idea_plugin/src/main/resources/META-INF/plugin.xml +++ b/idea_plugin/src/main/resources/META-INF/plugin.xml @@ -35,9 +35,6 @@ ]]>