Skip to content

Commit

Permalink
SortPomStep can now live within the normal src/main/java, and only …
Browse files Browse the repository at this point in the history
…`SortPomFormatterFunc` needs `src/sortPom/java`.
  • Loading branch information
nedtwigg committed Sep 29, 2021
1 parent bcd3735 commit 4b780c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.JarState;
import com.diffplug.spotless.Provisioner;

public class SortPomStep {

public static final String NAME = "sortPom";

private SortPomStep() {}
Expand All @@ -48,10 +45,9 @@ public State(SortPomCfg cfg, Provisioner provisioner) throws IOException {
this.jarState = JarState.from("com.github.ekryd.sortpom:sortpom-sorter:3.0.0", provisioner);
}

FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException {
ClassLoader classLoader = AccessController.doPrivileged((PrivilegedAction<DelegatingClassLoader>) () -> new DelegatingClassLoader(this.getClass().getClassLoader(), jarState.getClassLoader()));
Constructor<?> constructor = classLoader.loadClass(SortPomFormatterFunc.class.getName()).getConstructor(classLoader.loadClass(SortPomCfg.class.getName()));
constructor.setAccessible(true);
FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Class<?> formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.ext.pom.SortPomFormatterFunc");
Constructor<?> constructor = formatterFunc.getConstructor(SortPomCfg.class);
return (FormatterFunc) constructor.newInstance(cfg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.pom;
package com.diffplug.spotless.glue.pom;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -23,12 +23,13 @@
import org.apache.commons.io.IOUtils;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.pom.SortPomCfg;

import sortpom.SortPomImpl;
import sortpom.logger.SortPomLogger;
import sortpom.parameter.PluginParameters;

class SortPomFormatterFunc implements FormatterFunc {
public class SortPomFormatterFunc implements FormatterFunc {
private static final Logger logger = Logger.getLogger(SortPomFormatterFunc.class.getName());
private final SortPomCfg cfg;

Expand Down

0 comments on commit 4b780c0

Please sign in to comment.