Skip to content

Commit

Permalink
moving npm based formatters from lib-extra to lib
Browse files Browse the repository at this point in the history
and adapt dependencies where needed.
  • Loading branch information
simschla committed Sep 12, 2018
1 parent 3d3f304 commit 6ee4e77
Show file tree
Hide file tree
Showing 29 changed files with 48 additions and 60 deletions.
4 changes: 0 additions & 4 deletions lib-extra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,3 @@ dependencies {

// we'll hold the core lib to a high standard
spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes)

test { useJUnit { excludeCategories 'com.diffplug.spotless.category.NpmTest' } }

task npmTest(type: Test) { useJUnit { includeCategories 'com.diffplug.spotless.category.NpmTest' } }
4 changes: 4 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ dependencies {

// we'll hold the core lib to a high standard
spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes)

test { useJUnit { excludeCategories 'com.diffplug.spotless.category.NpmTest' } }

task npmTest(type: Test) { useJUnit { includeCategories 'com.diffplug.spotless.category.NpmTest' } }
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.extra.npm;
package com.diffplug.spotless.npm;

class BlacklistedOptionException extends RuntimeException {
private static final long serialVersionUID = -5876348893394153811L;
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.extra.npm;
package com.diffplug.spotless.npm;

import java.io.File;
import java.util.Map;
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.extra.npm;
package com.diffplug.spotless.npm;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.extra.npm;
package com.diffplug.spotless.npm;

import static com.diffplug.spotless.extra.npm.PlatformInfo.OS.WINDOWS;
import static com.diffplug.spotless.npm.PlatformInfo.OS.WINDOWS;

import java.io.File;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;

import com.diffplug.common.base.Splitter;

/**
* Utility class to resolve an npm binary to be used by npm-based steps.
* Tries to find an npm executable in the following order:
Expand Down Expand Up @@ -84,9 +83,7 @@ private static Supplier<Optional<File>> pathListFromEnvironment(String environme
return () -> {
String pathList = System.getenv(environmentPathListName);
if (pathList != null) {
return Splitter.on(System.getProperty("path.separator", ":"))
.splitToList(pathList)
.stream()
return Arrays.stream(pathList.split(System.getProperty("path.separator", ":")))
.map(File::new)
.map(dir -> dir.getName().equalsIgnoreCase("node_modules") ? dir.getParentFile() : dir)
.map(dir -> new File(dir, npmExecutableName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.extra.npm;
package com.diffplug.spotless.npm;

import static com.diffplug.spotless.extra.npm.NpmExecutableResolver.tryFind;
import static java.util.Objects.requireNonNull;

import java.io.ByteArrayOutputStream;
Expand All @@ -29,11 +28,7 @@

import javax.annotation.Nullable;

import com.diffplug.common.base.Errors;
import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.JarState;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.*;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down Expand Up @@ -92,7 +87,7 @@ private void runNpmInstall(@Nullable File npm, File npmProjectDir) throws IOExce

private File resolveNpm(@Nullable File npm) {
return Optional.ofNullable(npm)
.orElseGet(() -> tryFind()
.orElseGet(() -> NpmExecutableResolver.tryFind()
.orElseThrow(() -> new IllegalStateException("cannot automatically determine npm executable and none was specifically supplied!")));
}

Expand All @@ -118,7 +113,7 @@ protected static String readFileFromClasspath(Class<?> clazz, String name) {
}
return output.toString(StandardCharsets.UTF_8.name());
} catch (IOException e) {
throw Errors.asRuntime(e);
throw ThrowingEx.asRuntime(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

import java.util.Locale;

import com.diffplug.common.base.StandardSystemProperty;

class PlatformInfo {
private PlatformInfo() {
// no instance
}

static OS normalizedOS() {
final String osNameProperty = StandardSystemProperty.OS_NAME.value();
final String osNameProperty = System.getProperty("os.name");
if (osNameProperty == null) {
throw new RuntimeException("No info about OS available, cannot decide which implementation of j2v8 to use");
}
Expand All @@ -49,7 +47,7 @@ static String normalizedOSName() {
}

static String normalizedArchName() {
final String osArchProperty = StandardSystemProperty.OS_ARCH.value();
final String osArchProperty = System.getProperty("os.arch");
if (osArchProperty == null) {
throw new RuntimeException("No info about ARCH available, cannot decide which implementation of j2v8 to use");
}
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.extra.npm;
package com.diffplug.spotless.npm;

import java.io.File;
import java.io.IOException;
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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -53,7 +53,7 @@ public static class State extends NpmFormatterStepStateBase implements Serializa
super(stepName,
provisioner,
new NpmConfig(
readFileFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/extra/npm/prettier-package.json"),
readFileFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-package.json"),
"prettier"),
buildDir,
npm);
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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

Expand All @@ -26,7 +26,7 @@
import java.util.Map;
import java.util.stream.Collectors;

import com.diffplug.common.base.Errors;
import com.diffplug.spotless.ThrowingEx;

public class SimpleJsonWriter {

Expand Down Expand Up @@ -83,7 +83,7 @@ void toJsonFile(File file) {
try {
Files.write(file.toPath(), toJsonString().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw Errors.asRuntime(e);
throw ThrowingEx.asRuntime(e);
}
}

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.extra.npm;
package com.diffplug.spotless.npm;

import java.util.Arrays;

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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -61,7 +61,7 @@ public State(String stepName, Provisioner provisioner, File buildDir, @Nullable
super(stepName,
provisioner,
new NpmConfig(
readFileFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/extra/npm/tsfmt-package.json"),
readFileFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"),
"typescript-formatter"),
buildDir,
npm);
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.extra.npm;
package com.diffplug.spotless.npm;

class TsFmtResult {

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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

Expand All @@ -22,8 +22,8 @@
import java.io.Serializable;
import java.util.Locale;

import com.diffplug.common.base.Errors;
import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.ThrowingEx;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand All @@ -45,7 +45,7 @@ public TypedTsFmtConfigFile(TsConfigFileType configFileType, File configFile) {
try {
this.configFileSignature = FileSignature.signAsList(configFile);
} catch (IOException e) {
throw Errors.asRuntime(e);
throw ThrowingEx.asRuntime(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.extra.npm;

import static com.diffplug.spotless.extra.npm.NodeJSWrapper.V8_VALUE_CLASS;
package com.diffplug.spotless.npm;

public class V8ArrayWrapper extends ReflectiveObjectWrapper {

Expand All @@ -30,8 +28,8 @@ public V8ArrayWrapper push(Object object) {
ReflectiveObjectWrapper objectWrapper = (ReflectiveObjectWrapper) object;
object = objectWrapper.wrappedObj();
}
if (reflective().clazz(V8_VALUE_CLASS).isAssignableFrom(object.getClass())) {
invoke("push", reflective().typed(V8_VALUE_CLASS, object));
if (reflective().clazz(NodeJSWrapper.V8_VALUE_CLASS).isAssignableFrom(object.getClass())) {
invoke("push", reflective().typed(NodeJSWrapper.V8_VALUE_CLASS, object));
} else {
invoke("push", object);
}
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.extra.npm;
package com.diffplug.spotless.npm;

import java.lang.reflect.Method;

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.extra.npm;
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

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.extra.npm;
package com.diffplug.spotless.npm;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import com.diffplug.spotless.LazyForwardingEquality;
import com.diffplug.spotless.LineEnding;
import com.diffplug.spotless.ThrowingEx;
import com.diffplug.spotless.extra.npm.PrettierFormatterStep;
import com.diffplug.spotless.generic.EndWithNewlineStep;
import com.diffplug.spotless.generic.IndentStep;
import com.diffplug.spotless.generic.LicenseHeaderStep;
import com.diffplug.spotless.generic.ReplaceRegexStep;
import com.diffplug.spotless.generic.ReplaceStep;
import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep;
import com.diffplug.spotless.npm.PrettierFormatterStep;

import groovy.lang.Closure;

Expand Down Expand Up @@ -471,7 +471,7 @@ FormatterStep createStep() {
GradleProvisioner.fromProject(project),
project.getBuildDir(),
npmFileOrNull(),
new com.diffplug.spotless.extra.npm.PrettierConfig(
new com.diffplug.spotless.npm.PrettierConfig(
this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null,
this.prettierConfig));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.gradle.api.Project;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.extra.npm.TsConfigFileType;
import com.diffplug.spotless.extra.npm.TsFmtFormatterStep;
import com.diffplug.spotless.extra.npm.TypedTsFmtConfigFile;
import com.diffplug.spotless.npm.TsConfigFileType;
import com.diffplug.spotless.npm.TsFmtFormatterStep;
import com.diffplug.spotless.npm.TypedTsFmtConfigFile;

public class TypescriptExtension extends FormatExtension {

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.extra.npm;
package com.diffplug.spotless.npm;

import java.io.File;
import java.io.IOException;
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.extra.npm;
package com.diffplug.spotless.npm;

import java.io.File;
import java.util.Arrays;
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.extra.npm;
package com.diffplug.spotless.npm;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
Expand Down
Loading

0 comments on commit 6ee4e77

Please sign in to comment.