Skip to content

Commit

Permalink
Windows related tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Oct 1, 2023
1 parent 0b9f29a commit cac57b3
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 44 deletions.
3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core
20 changes: 15 additions & 5 deletions src/main/java/rife/bld/dependencies/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import rife.ioc.HierarchicalProperties;
import rife.tools.StringEncryptor;

import java.io.File;
import java.nio.file.Path;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Pattern;

/**
* Contains the information required to locate a Maven-compatible repository.
Expand Down Expand Up @@ -103,6 +105,12 @@ public Repository(String location) {
this(location, null, null);
}

private final static Pattern WINDOWS_ABSOLUTE_PATH = Pattern.compile("^\\p{L}:\\\\");

private boolean isWindowsLocation() {
return WINDOWS_ABSOLUTE_PATH.matcher(location()).find();
}

/**
* Indicates whether this repository is local.
*
Expand All @@ -111,7 +119,7 @@ public Repository(String location) {
* @since 1.5.10
*/
public boolean isLocal() {
return location().startsWith("/") || location().startsWith("file:");
return location().startsWith("/") || location().startsWith("file:") || isWindowsLocation();
}

/**
Expand Down Expand Up @@ -147,9 +155,10 @@ public String getArtifactLocation(Dependency dependency) {
* @since 1.5.10
*/
public String getArtifactLocation(String groupId, String artifactId) {
var group_path = groupId.replace(".", "/");
var separator = "/";
var result = new StringBuilder();
if (isLocal()) {
separator = File.separator;
if (location().startsWith("file://")) {
result.append(location().substring("file://".length()));
} else {
Expand All @@ -158,10 +167,11 @@ public String getArtifactLocation(String groupId, String artifactId) {
} else {
result.append(location());
}
if (!location().endsWith("/")) {
result.append("/");
if (!location().endsWith(separator)) {
result.append(separator);
}
return result.append(group_path).append("/").append(artifactId).append("/").toString();
var group_path = groupId.replace(".", separator);
return result.append(group_path).append(separator).append(artifactId).append(separator).toString();
}

/**
Expand Down
36 changes: 18 additions & 18 deletions src/test/java/rife/bld/dependencies/TestDependencySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,48 @@ void testAddAll() {

var set_union1 = new DependencySet(set1);
set_union1.addAll(set2);
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
org.eclipse.jetty:jetty-server:11.0.14
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2
org.eclipse.jetty:jetty-http:11.0.14
org.eclipse.jetty:jetty-io:11.0.14
org.eclipse.jetty:jetty-util:11.0.14
org.slf4j:slf4j-simple:2.0.6
org.slf4j:slf4j-api:2.0.6""", StringUtils.join(set_union1, "\n"));
org.slf4j:slf4j-api:2.0.6"""), StringUtils.join(set_union1, System.lineSeparator()));

var set_union2 = new DependencySet(set2);
set_union2.addAll(set1);
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
org.slf4j:slf4j-simple:2.0.6
org.slf4j:slf4j-api:2.0.6
org.eclipse.jetty:jetty-server:11.0.14
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2
org.eclipse.jetty:jetty-http:11.0.14
org.eclipse.jetty:jetty-io:11.0.14
org.eclipse.jetty:jetty-util:11.0.14""", StringUtils.join(set_union2, "\n"));
org.eclipse.jetty:jetty-util:11.0.14"""), StringUtils.join(set_union2, System.lineSeparator()));
}

@Test
void testGenerateDependencyTreeJettySlf4j() {
var dependencies = new DependencySet()
.include(new Dependency("org.eclipse.jetty", "jetty-server", new VersionNumber(11, 0, 14)))
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
├─ org.eclipse.jetty:jetty-server:11.0.14
│ ├─ org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2
│ ├─ org.eclipse.jetty:jetty-http:11.0.14
│ │ └─ org.eclipse.jetty:jetty-util:11.0.14
│ └─ org.eclipse.jetty:jetty-io:11.0.14
└─ org.slf4j:slf4j-simple:2.0.6
└─ org.slf4j:slf4j-api:2.0.6
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
}

@Test
void testGenerateDependencyTreeSpringBoot() {
var dependencies = new DependencySet()
.include(new Dependency("org.springframework.boot", "spring-boot-starter", new VersionNumber(3, 0, 4)));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
└─ org.springframework.boot:spring-boot-starter:3.0.4
├─ org.springframework.boot:spring-boot:3.0.4
│ └─ org.springframework:spring-context:6.0.6
Expand All @@ -117,14 +117,14 @@ void testGenerateDependencyTreeSpringBoot() {
├─ org.springframework:spring-core:6.0.6
│ └─ org.springframework:spring-jcl:6.0.6
└─ org.yaml:snakeyaml:1.33
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
}

@Test
void testGenerateDependencyTreeMaven() {
var dependencies = new DependencySet()
.include(new Dependency("org.apache.maven", "maven-core", new VersionNumber(3, 9, 0)));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
└─ org.apache.maven:maven-core:3.9.0
├─ org.apache.maven:maven-model:3.9.0
├─ org.apache.maven:maven-settings:3.9.0
Expand Down Expand Up @@ -157,14 +157,14 @@ void testGenerateDependencyTreeMaven() {
├─ org.codehaus.plexus:plexus-component-annotations:2.1.0
├─ org.apache.commons:commons-lang3:3.8.1
└─ org.slf4j:slf4j-api:1.7.36
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
}

@Test
void testGenerateDependencyTreePlay() {
var dependencies = new DependencySet()
.include(new Dependency("com.typesafe.play", "play_2.13", new VersionNumber(2, 8, 19)));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
└─ com.typesafe.play:play_2.13:2.8.19
├─ org.scala-lang:scala-library:2.13.10
├─ com.typesafe.play:build-link:2.8.19
Expand Down Expand Up @@ -213,14 +213,14 @@ void testGenerateDependencyTreePlay() {
├─ org.scala-lang.modules:scala-java8-compat_2.13:1.0.2
├─ com.typesafe:ssl-config-core_2.13:0.4.3
└─ org.scala-lang.modules:scala-parser-combinators_2.13:1.1.2
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
}

@Test
void testGenerateDependencyTreeVaadin() {
var dependencies = new DependencySet()
.include(new Dependency("com.vaadin", "vaadin", new VersionNumber(23, 3, 7)));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
└─ com.vaadin:vaadin:23.3.7
├─ com.vaadin:vaadin-core:23.3.7
│ ├─ com.vaadin:flow-server:23.3.4
Expand Down Expand Up @@ -309,7 +309,7 @@ void testGenerateDependencyTreeVaadin() {
│ ├─ net.java.dev.jna:jna:5.11.0
│ └─ net.java.dev.jna:jna-platform:5.11.0
└─ com.auth0:java-jwt:3.19.2
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
}

@Test
Expand All @@ -324,7 +324,7 @@ void testGenerateDependencyTreeVarious() {
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,15)))
.include(new Dependency("org.apache.httpcomponents", "httpcore", new VersionNumber(4,4,16)))
.include(new Dependency("com.google.zxing", "javase", new VersionNumber(3,5,1)));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
├─ com.uwyn.rife2:rife2:1.5.20
├─ com.stripe:stripe-java:20.136.0
├─ org.json:json:20230227
Expand Down Expand Up @@ -352,14 +352,14 @@ void testGenerateDependencyTreeVarious() {
└─ com.google.zxing:javase:3.5.1
├─ com.google.zxing:core:3.5.1
└─ com.beust:jcommander:1.82
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
}

@Test
void testGenerateDependencyTreeCompileRuntime() {
var dependencies = new DependencySet()
.include(new Dependency("net.thauvin.erik", "bitly-shorten", new VersionNumber(0, 9, 4, "SNAPSHOT")));
assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
└─ net.thauvin.erik:bitly-shorten:0.9.4-SNAPSHOT
├─ org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22
│ ├─ org.jetbrains.kotlin:kotlin-stdlib:1.8.22
Expand All @@ -371,6 +371,6 @@ void testGenerateDependencyTreeCompileRuntime() {
│ └─ com.squareup.okio:okio-jvm:3.2.0
├─ com.squareup.okhttp3:logging-interceptor:4.11.0
└─ org.json:json:20230618
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY), compile, runtime));
"""), dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY), compile, runtime));
}
}
11 changes: 6 additions & 5 deletions src/test/java/rife/bld/operations/TestCompileOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject;
import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.util.List;

Expand Down Expand Up @@ -305,11 +306,11 @@ public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagno
var diagnostic4 = operation.diagnostics().get(3);
var diagnostic5 = operation.diagnostics().get(4);

assertEquals("/Source1.java", diagnostic1.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
assertEquals("/Source3.java", diagnostic2.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
assertEquals("/Source3.java", diagnostic3.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
assertEquals("/Source3.java", diagnostic4.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
assertEquals("/Source3.java", diagnostic5.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
assertEquals("Source1.java", diagnostic1.getSource().toUri().getPath().substring(tmp.toURI().getPath().length()));
assertEquals("Source3.java", diagnostic2.getSource().toUri().getPath().substring(tmp.toURI().getPath().length()));
assertEquals("Source3.java", diagnostic3.getSource().toUri().getPath().substring(tmp.toURI().getPath().length()));
assertEquals("Source3.java", diagnostic4.getSource().toUri().getPath().substring(tmp.toURI().getPath().length()));
assertEquals("Source3.java", diagnostic5.getSource().toUri().getPath().substring(tmp.toURI().getPath().length()));

assertFalse(build_main_class1.exists());
assertFalse(build_main_class2.exists());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import rife.bld.WebProject;
import rife.bld.dependencies.*;
import rife.tools.FileUtils;
import rife.tools.StringUtils;

import java.io.File;
import java.nio.file.Files;
Expand Down Expand Up @@ -80,7 +81,7 @@ void testExecution()

var tree = operation.dependencyTree();

assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
compile:
├─ com.uwyn.rife2:rife2:1.5.20
├─ com.stripe:stripe-java:20.136.0
Expand Down Expand Up @@ -120,7 +121,7 @@ void testExecution()
test:
no dependencies
""", tree);
"""), tree);
} finally {
FileUtils.deleteDirectory(tmp);
}
Expand Down Expand Up @@ -152,7 +153,7 @@ void testExecutionProvidedTest()

var tree = operation.dependencyTree();

assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
compile:
no dependencies
Expand Down Expand Up @@ -188,7 +189,7 @@ void testExecutionProvidedTest()
│ └─ org.eclipse.jetty:jetty-security:11.0.15
└─ net.imagej:ij:1.54d
""", tree);
"""), tree);
} finally {
FileUtils.deleteDirectory(tmp);
}
Expand Down Expand Up @@ -229,7 +230,7 @@ void testFromProject()

var tree = operation.dependencyTree();

assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
compile:
├─ com.uwyn.rife2:rife2:1.5.20
├─ com.stripe:stripe-java:20.136.0
Expand Down Expand Up @@ -269,7 +270,7 @@ void testFromProject()
test:
no dependencies
""", tree);
"""), tree);
} finally {
FileUtils.deleteDirectory(tmp);
}
Expand Down Expand Up @@ -305,7 +306,7 @@ void testFromProjectProvidedTest()

var tree = operation.dependencyTree();

assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
compile:
no dependencies
Expand Down Expand Up @@ -341,7 +342,7 @@ void testFromProjectProvidedTest()
│ └─ org.eclipse.jetty:jetty-security:11.0.15
└─ net.imagej:ij:1.54d
""", tree);
"""), tree);
} finally {
FileUtils.deleteDirectory(tmp);
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/rife/bld/operations/TestJUnitOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.junit.jupiter.api.Test;
import rife.tools.FileUtils;
import rife.tools.StringUtils;

import java.io.File;
import java.nio.file.Files;
Expand Down Expand Up @@ -191,7 +192,7 @@ void testFromProject()
return true;
})
.execute();
assertTrue(check_result.toString().contains("""
assertTrue(check_result.toString().contains(StringUtils.convertLineSeparator("""
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
Expand All @@ -204,7 +205,7 @@ void testFromProject()
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
"""));
""")));

} finally {
FileUtils.deleteDirectory(tmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagno

var diagnostic1 = operation.diagnostics().get(0);

assertEquals("/Source1.java", diagnostic1.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
assertEquals("Source1.java", diagnostic1.getSource().toUri().getPath().substring(tmp.toURI().getPath().length()));

assertFalse(build_html1.exists());
assertFalse(build_html2.exists());
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/rife/bld/publish/TestPomBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import rife.bld.dependencies.DependencyScopes;
import rife.bld.dependencies.Scope;
import rife.bld.dependencies.VersionNumber;
import rife.tools.StringUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -108,7 +109,7 @@ void testGenerateInto() throws IOException {

PomBuilder.generateInto(new PublishInfo().name("the thing"), deps, temp);

assertEquals("""
assertEquals(StringUtils.convertLineSeparator("""
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Expand All @@ -126,7 +127,7 @@ void testGenerateInto() throws IOException {
<scope>compile</scope>
</dependency>
</dependencies>
</project>""", String.join(System.lineSeparator(), Files.readAllLines(temp.toPath())));
</project>"""), String.join(System.lineSeparator(), Files.readAllLines(temp.toPath())));
}

@Test
Expand Down

0 comments on commit cac57b3

Please sign in to comment.