Skip to content

Commit

Permalink
Fix #652 - Nested target feature needs to support windows path in
Browse files Browse the repository at this point in the history
project_loc expansion

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Feb 15, 2022
1 parent c543cdf commit 89ef155
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -32,7 +36,6 @@
import org.eclipse.equinox.p2.metadata.VersionedId;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.tycho.core.resolver.shared.IncludeSourceMode;
import org.eclipse.tycho.core.shared.BuildFailureException;
import org.eclipse.tycho.core.shared.MockMavenContext;
import org.eclipse.tycho.core.shared.TargetEnvironment;
import org.eclipse.tycho.p2.impl.test.ResourceUtil;
Expand Down Expand Up @@ -95,6 +98,18 @@ static List<TargetEnvironment> defaultEnvironments() {
return Collections.singletonList(new TargetEnvironment(null, null, null));
}

@Test
public void testURI() throws URISyntaxException, MalformedURLException {
String uri = TargetDefinitionResolver
.convertRawToUri("file:C:\\ws\\target-testcase\\tycho\\target.references\\target.refs/base.target");
//check that it has the missing / infront of the protocol
assertTrue(uri + " does not start with file:/", uri.startsWith("file:/"));
//check that this could be parsed as an URI afterwards
URI parsed = new URI(uri);
parsed.toURL();

}

@Test
public void testResolveNoLocations() throws Exception {
TargetDefinition definition = definitionWith();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ TargetDefinitionContent resolveContentWithExceptions(TargetDefinition definition
String resolvePath = resolvePath(referenceLocation.getUri(), definition);
URI resolvedUri;
try {
resolvedUri = new URI(resolvePath);
resolvedUri = new URI(convertRawToUri(resolvePath));
} catch (URISyntaxException e) {
throw new ResolverException("Invalid URI " + resolvePath + ": " + e.getMessage(), e);
}
Expand Down Expand Up @@ -274,6 +274,17 @@ public IArtifactRepository getArtifactRepository() {
};
}

static String convertRawToUri(String resolvePath) {
//We need to convert windows path separators here...
resolvePath = resolvePath.replace('\\', '/');
String lc = resolvePath.toLowerCase();
if (lc.startsWith("file:") && !lc.startsWith("file:/")) {
//according to rfc a file URI must always start with a slash
resolvePath = resolvePath.replaceFirst("(?i)^file:", "file:/");
}
return resolvePath;
}

protected String resolvePath(String path, TargetDefinition definition) {
path = resolvePattern(path, SYSTEM_PROPERTY_PATTERN,
key -> mavenContext.getSessionProperties().getProperty(key, ""));
Expand Down

0 comments on commit 89ef155

Please sign in to comment.