Skip to content
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

[Maven plugin] importOrder with order element does not work as expected #731

Closed
Xendar opened this issue Nov 12, 2020 · 1 comment
Closed
Labels

Comments

@Xendar
Copy link

Xendar commented Nov 12, 2020

I am currently implementing Spotless (plugin version 2.5.0) in a Maven project (3.6.3) and it seems that the importOrder does not work as expected when using the order element.

Maven configuration:

<configuration>
  <ratchetFrom>origin/main</ratchetFrom>
  <java>
    <importOrder>
      <order>java,javafx,com.mycompany,</order>
    </importOrder>
    <removeUnusedImports />
    <toggleOffOn />
    <eclipse>
      <file>${basedir}/config/formatter.xml</file>
    </eclipse>
    <licenseHeader>
      <file>${basedir}/config/header</file>
    </licenseHeader>
  </java>
</configuration>

After running the spotless:apply goal I get this formatting:

package com.mycompany.mytool;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javafx.beans.property.ObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.PopOver.ArrowLocation;
import org.controlsfx.control.textfield.CustomTextField;
import org.controlsfx.control.textfield.TextFields;
import org.controlsfx.validation.Severity;
import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.ValidationSupport;
import org.controlsfx.validation.Validator;
import org.controlsfx.validation.decoration.GraphicValidationDecoration;

import com.mycompany.mytool.api.SomeApi;
import com.mycompany.mytool.impl.SomeImpl;
import com.mycompany.mytool.javafx.SomeJavaFX;

import com.google.inject.Inject;
import com.google.inject.name.Named;

Now if I use an importorder file:

3=
2=com.mycompany
1=javafx
0=java

And reference it in the Maven configuration:

<configuration>
  <ratchetFrom>origin/main</ratchetFrom>
  <java>
    <importOrder>
      <!--order>java,javafx,com.mycompany,</order-->
      <file>${basedir}/config/importorder</file>
    </importOrder>
    <removeUnusedImports />
    <toggleOffOn />
    <eclipse>
      <file>${basedir}/config/formatter.xml</file>
    </eclipse>
    <licenseHeader>
      <file>${basedir}/config/header</file>
    </licenseHeader>
  </java>
</configuration>

And running again the spotless:apply goal then I get this formatting:

package com.mycompany.mytool;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javafx.beans.property.ObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

import com.mycompany.mytool.api.SomeApi;
import com.mycompany.mytool.impl.SomeImpl;
import com.mycompany.mytool.javafx.SomeJavaFX;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.PopOver.ArrowLocation;
import org.controlsfx.control.textfield.CustomTextField;
import org.controlsfx.control.textfield.TextFields;
import org.controlsfx.validation.Severity;
import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.ValidationSupport;
import org.controlsfx.validation.Validator;
import org.controlsfx.validation.decoration.GraphicValidationDecoration;

There is no error nor warning in the console.
It's a private repo so I cannot share it, but I can try to create a public one to reproduce.
Can it be linked to the usage of split method (https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java#L41), that discards the 'empty' recommended last element?

      <order>java,javax,org,com,com.diffplug,</order>  <!-- or use <file>${basedir}/eclipse.importorder</file> -->
      <!-- You probably want an empty string at the end - all of the
           imports you didn't specify explicitly will go there. -->
@nedtwigg
Copy link
Member

Published in plugin-gradle 5.8.1 and plugin-maven 2.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants