From ea6079bea28fb0c8bd99f0a657cc034b2ab90c0f Mon Sep 17 00:00:00 2001 From: Alex Boyko Date: Mon, 24 Oct 2016 12:56:32 -0400 Subject: [PATCH] Fix maven build on Windows --- .../commons/maven/DependencyTreeTest.java | 153 +++++++++--------- .../testharness/TestProjectHarness.java | 153 +++++++++--------- 2 files changed, 156 insertions(+), 150 deletions(-) diff --git a/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java b/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java index 6c6fc2bbb..304c6b609 100644 --- a/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java +++ b/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java @@ -1,75 +1,78 @@ -package org.springframework.ide.vscode.commons.maven; - -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -import static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.maven.project.MavenProject; -import org.junit.Test; -import org.springframework.ide.vscode.commons.util.ExternalCommand; -import org.springframework.ide.vscode.commons.util.ExternalProcess; - -/** - * Tests for comparing maven calculated dependencies with ours - * - * @author Alex Boyko - * - */ -public class DependencyTreeTest { - - /** - * Build test project if it's not built already - * @throws Exception - */ - private static void buildProject(Path testProjectPath) throws Exception { - if (!Files.exists(testProjectPath.resolve("classpath.txt"))) { - testProjectPath.resolve("mvnw").toFile().setExecutable(true); - ExternalProcess process = new ExternalProcess(testProjectPath.toFile(), new ExternalCommand("./mvnw", "clean", "package"), true); - if (process.getExitValue() != 0) { - throw new RuntimeException("Failed to build test project"); - } - } - } - - private static Set readClassPathFile(Path classPathFilePath) throws IOException { - InputStream in = Files.newInputStream(classPathFilePath); - String text = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining()); - Path dir = classPathFilePath.getParent(); - return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet()); - } - - @Test - public void mavenTest() throws Exception { - Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/demo-1").toURI()); - buildProject(testProjectPath); - - MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve("pom.xml").toFile()); - Set calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> { - return Paths.get(artifact.getFile().toURI()); - }).collect(Collectors.toSet());; - - Set expectedClasspath = readClassPathFile(testProjectPath.resolve("classpath.txt")); - assertEquals(expectedClasspath, calculatedClassPath); - } - -} +package org.springframework.ide.vscode.commons.maven; + +/******************************************************************************* + * Copyright (c) 2016 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.maven.project.MavenProject; +import org.junit.Test; +import org.springframework.ide.vscode.commons.util.ExternalCommand; +import org.springframework.ide.vscode.commons.util.ExternalProcess; + +/** + * Tests for comparing maven calculated dependencies with ours + * + * @author Alex Boyko + * + */ +public class DependencyTreeTest { + + /** + * Build test project if it's not built already + * @throws Exception + */ + private static void buildProject(Path testProjectPath) throws Exception { + if (!Files.exists(testProjectPath.resolve("classpath.txt"))) { + Path mvnwPath = System.getProperty("os.name").toLowerCase().startsWith("win") + ? testProjectPath.resolve("mvnw.cmd") : testProjectPath.resolve("mvnw"); + mvnwPath.toFile().setExecutable(true); + ExternalProcess process = new ExternalProcess(testProjectPath.toFile(), + new ExternalCommand(mvnwPath.toAbsolutePath().toString(), "clean", "package"), true); + if (process.getExitValue() != 0) { + throw new RuntimeException("Failed to build test project"); + } + } + } + + private static Set readClassPathFile(Path classPathFilePath) throws IOException { + InputStream in = Files.newInputStream(classPathFilePath); + String text = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining()); + Path dir = classPathFilePath.getParent(); + return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet()); + } + + @Test + public void mavenTest() throws Exception { + Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/demo-1").toURI()); + buildProject(testProjectPath); + + MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve("pom.xml").toFile()); + Set calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> { + return Paths.get(artifact.getFile().toURI()); + }).collect(Collectors.toSet());; + + Set expectedClasspath = readClassPathFile(testProjectPath.resolve("classpath.txt")); + assertEquals(expectedClasspath, calculatedClassPath); + } + +} diff --git a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestProjectHarness.java b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestProjectHarness.java index 3f3535231..f21c658ad 100644 --- a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestProjectHarness.java +++ b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestProjectHarness.java @@ -1,75 +1,78 @@ -package org.springframework.ide.vscode.languageserver.testharness; - -import static org.junit.Assert.assertTrue; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.springframework.ide.vscode.commons.java.IClasspath; -import org.springframework.ide.vscode.commons.java.IJavaProject; -import org.springframework.ide.vscode.commons.java.IType; -import org.springframework.ide.vscode.commons.util.ExternalCommand; -import org.springframework.ide.vscode.commons.util.ExternalProcess; -import org.springframework.ide.vscode.commons.util.HtmlSnippet; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; - -/** - * Class meant to be used in writing tests that require test projects to be populated - * from some data on the classpath. - */ -public class TestProjectHarness { - - private static final class TestProject implements IJavaProject { - private Path location; - - public TestProject(Path location) { - this.location = location; - } - - @Override - public HtmlSnippet getJavaDoc() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getElementName() { - return location.toFile().getName(); - } - - @Override - public boolean exists() { - return true; - } - - @Override - public IClasspath getClasspath() { - return () -> location; - } - - @Override - public IType findType(String fqName) { - // TODO Auto-generated method stub - return null; - } - } - - public Cache cache = CacheBuilder.newBuilder().build(); - - public IJavaProject mavenProject(String name) throws Exception { - Path testProjectPath = Paths.get(TestProjectHarness.class.getResource("/"+name).toURI()); - assertTrue(Files.exists(testProjectPath)); - if (!Files.exists(testProjectPath.resolve("classpath.txt"))) { - testProjectPath.resolve("mvnw").toFile().setExecutable(true); - ExternalProcess process = new ExternalProcess(testProjectPath.toFile(), new ExternalCommand("./mvnw", "clean", "package"), true); - if (process.getExitValue() != 0) { - throw new RuntimeException("Failed to build test project"); - } - } - return new TestProject(testProjectPath); - } - -} +package org.springframework.ide.vscode.languageserver.testharness; + +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.springframework.ide.vscode.commons.java.IClasspath; +import org.springframework.ide.vscode.commons.java.IJavaProject; +import org.springframework.ide.vscode.commons.java.IType; +import org.springframework.ide.vscode.commons.util.ExternalCommand; +import org.springframework.ide.vscode.commons.util.ExternalProcess; +import org.springframework.ide.vscode.commons.util.HtmlSnippet; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + +/** + * Class meant to be used in writing tests that require test projects to be populated + * from some data on the classpath. + */ +public class TestProjectHarness { + + private static final class TestProject implements IJavaProject { + private Path location; + + public TestProject(Path location) { + this.location = location; + } + + @Override + public HtmlSnippet getJavaDoc() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getElementName() { + return location.toFile().getName(); + } + + @Override + public boolean exists() { + return true; + } + + @Override + public IClasspath getClasspath() { + return () -> location; + } + + @Override + public IType findType(String fqName) { + // TODO Auto-generated method stub + return null; + } + } + + public Cache cache = CacheBuilder.newBuilder().build(); + + public IJavaProject mavenProject(String name) throws Exception { + Path testProjectPath = Paths.get(TestProjectHarness.class.getResource("/" + name).toURI()); + assertTrue(Files.exists(testProjectPath)); + if (!Files.exists(testProjectPath.resolve("classpath.txt"))) { + Path mvnwPath = System.getProperty("os.name").toLowerCase().startsWith("win") + ? testProjectPath.resolve("mvnw.cmd") : testProjectPath.resolve("mvnw"); + mvnwPath.toFile().setExecutable(true); + ExternalProcess process = new ExternalProcess(testProjectPath.toFile(), + new ExternalCommand(mvnwPath.toAbsolutePath().toString(), "clean", "package"), true); + if (process.getExitValue() != 0) { + throw new RuntimeException("Failed to build test project"); + } + } + return new TestProject(testProjectPath); + } + +}