Fix maven build on Windows

This commit is contained in:
Alex Boyko
2016-10-24 12:56:32 -04:00
parent 46e2334b0c
commit ea6079bea2
2 changed files with 156 additions and 150 deletions

View File

@@ -1,75 +1,78 @@
package org.springframework.ide.vscode.commons.maven; package org.springframework.ide.vscode.commons.maven;
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2016 Pivotal, Inc. * Copyright (c) 2016 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Pivotal, Inc. - initial API and implementation * Pivotal, Inc. - initial API and implementation
*******************************************************************************/ *******************************************************************************/
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.junit.Test; import org.junit.Test;
import org.springframework.ide.vscode.commons.util.ExternalCommand; import org.springframework.ide.vscode.commons.util.ExternalCommand;
import org.springframework.ide.vscode.commons.util.ExternalProcess; import org.springframework.ide.vscode.commons.util.ExternalProcess;
/** /**
* Tests for comparing maven calculated dependencies with ours * Tests for comparing maven calculated dependencies with ours
* *
* @author Alex Boyko * @author Alex Boyko
* *
*/ */
public class DependencyTreeTest { public class DependencyTreeTest {
/** /**
* Build test project if it's not built already * Build test project if it's not built already
* @throws Exception * @throws Exception
*/ */
private static void buildProject(Path testProjectPath) throws Exception { private static void buildProject(Path testProjectPath) throws Exception {
if (!Files.exists(testProjectPath.resolve("classpath.txt"))) { if (!Files.exists(testProjectPath.resolve("classpath.txt"))) {
testProjectPath.resolve("mvnw").toFile().setExecutable(true); Path mvnwPath = System.getProperty("os.name").toLowerCase().startsWith("win")
ExternalProcess process = new ExternalProcess(testProjectPath.toFile(), new ExternalCommand("./mvnw", "clean", "package"), true); ? testProjectPath.resolve("mvnw.cmd") : testProjectPath.resolve("mvnw");
if (process.getExitValue() != 0) { mvnwPath.toFile().setExecutable(true);
throw new RuntimeException("Failed to build test project"); 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<Path> 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(); private static Set<Path> readClassPathFile(Path classPathFilePath) throws IOException {
return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet()); InputStream in = Files.newInputStream(classPathFilePath);
} String text = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining());
Path dir = classPathFilePath.getParent();
@Test return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet());
public void mavenTest() throws Exception { }
Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/demo-1").toURI());
buildProject(testProjectPath); @Test
public void mavenTest() throws Exception {
MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve("pom.xml").toFile()); Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/demo-1").toURI());
Set<Path> calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> { buildProject(testProjectPath);
return Paths.get(artifact.getFile().toURI());
}).collect(Collectors.toSet());; MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve("pom.xml").toFile());
Set<Path> calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> {
Set<Path> expectedClasspath = readClassPathFile(testProjectPath.resolve("classpath.txt")); return Paths.get(artifact.getFile().toURI());
assertEquals(expectedClasspath, calculatedClassPath); }).collect(Collectors.toSet());;
}
Set<Path> expectedClasspath = readClassPathFile(testProjectPath.resolve("classpath.txt"));
} assertEquals(expectedClasspath, calculatedClassPath);
}
}

View File

@@ -1,75 +1,78 @@
package org.springframework.ide.vscode.languageserver.testharness; package org.springframework.ide.vscode.languageserver.testharness;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import org.springframework.ide.vscode.commons.java.IClasspath; import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject; import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.java.IType; import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.util.ExternalCommand; import org.springframework.ide.vscode.commons.util.ExternalCommand;
import org.springframework.ide.vscode.commons.util.ExternalProcess; import org.springframework.ide.vscode.commons.util.ExternalProcess;
import org.springframework.ide.vscode.commons.util.HtmlSnippet; import org.springframework.ide.vscode.commons.util.HtmlSnippet;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
/** /**
* Class meant to be used in writing tests that require test projects to be populated * Class meant to be used in writing tests that require test projects to be populated
* from some data on the classpath. * from some data on the classpath.
*/ */
public class TestProjectHarness { public class TestProjectHarness {
private static final class TestProject implements IJavaProject { private static final class TestProject implements IJavaProject {
private Path location; private Path location;
public TestProject(Path location) { public TestProject(Path location) {
this.location = location; this.location = location;
} }
@Override @Override
public HtmlSnippet getJavaDoc() { public HtmlSnippet getJavaDoc() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public String getElementName() { public String getElementName() {
return location.toFile().getName(); return location.toFile().getName();
} }
@Override @Override
public boolean exists() { public boolean exists() {
return true; return true;
} }
@Override @Override
public IClasspath getClasspath() { public IClasspath getClasspath() {
return () -> location; return () -> location;
} }
@Override @Override
public IType findType(String fqName) { public IType findType(String fqName) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }
public Cache<String, IJavaProject> cache = CacheBuilder.newBuilder().build(); public Cache<String, IJavaProject> cache = CacheBuilder.newBuilder().build();
public IJavaProject mavenProject(String name) throws Exception { public IJavaProject mavenProject(String name) throws Exception {
Path testProjectPath = Paths.get(TestProjectHarness.class.getResource("/"+name).toURI()); Path testProjectPath = Paths.get(TestProjectHarness.class.getResource("/" + name).toURI());
assertTrue(Files.exists(testProjectPath)); assertTrue(Files.exists(testProjectPath));
if (!Files.exists(testProjectPath.resolve("classpath.txt"))) { if (!Files.exists(testProjectPath.resolve("classpath.txt"))) {
testProjectPath.resolve("mvnw").toFile().setExecutable(true); Path mvnwPath = System.getProperty("os.name").toLowerCase().startsWith("win")
ExternalProcess process = new ExternalProcess(testProjectPath.toFile(), new ExternalCommand("./mvnw", "clean", "package"), true); ? testProjectPath.resolve("mvnw.cmd") : testProjectPath.resolve("mvnw");
if (process.getExitValue() != 0) { mvnwPath.toFile().setExecutable(true);
throw new RuntimeException("Failed to build test project"); ExternalProcess process = new ExternalProcess(testProjectPath.toFile(),
} new ExternalCommand(mvnwPath.toAbsolutePath().toString(), "clean", "package"), true);
} if (process.getExitValue() != 0) {
return new TestProject(testProjectPath); throw new RuntimeException("Failed to build test project");
} }
}
} return new TestProject(testProjectPath);
}
}