-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1265 from SweeXordious/Fixes_path_containing_spaces
Fixes folder path containing space
- Loading branch information
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
codegen/src/test/java/org/web3j/codegen/unit/gen/CompilerClassLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2020 Web3 Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.web3j.codegen.unit.gen; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Objects; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import org.web3j.codegen.unit.gen.java.Setup; | ||
|
||
public class CompilerClassLoaderTest { | ||
|
||
String javaSourcePath = "org/com/test/contract/"; | ||
String greeterSourceName = "Greeter"; | ||
URL javaSourcesUrl = Objects.requireNonNull(Setup.class.getClassLoader().getResource("java")); | ||
@TempDir static File temp; | ||
|
||
@Test | ||
public void compileClassTest() throws ClassNotFoundException { | ||
CompilerClassLoader compilerClassLoader = new CompilerClassLoader(temp, javaSourcesUrl); | ||
Assertions.assertNotEquals( | ||
null, | ||
compilerClassLoader.loadClass( | ||
(javaSourcePath + greeterSourceName).replace(File.separator, "."))); | ||
} | ||
|
||
@Test | ||
public void compileClassWithPathContainingSpacesTest() | ||
throws ClassNotFoundException, IOException { | ||
File tempWithSpaces = new File(temp, "With Spaces"); | ||
File greeterSource = | ||
new File( | ||
Paths.get( | ||
javaSourcesUrl.getPath(), | ||
javaSourcePath, | ||
greeterSourceName + ".java") | ||
.toString()); | ||
Assertions.assertTrue(greeterSource.exists()); | ||
|
||
String javaPathWithSpaces = tempWithSpaces.toString() + File.separator + "java"; | ||
File sourcePathWithSpaces = new File(javaPathWithSpaces + File.separator + javaSourcePath); | ||
Assertions.assertTrue(sourcePathWithSpaces.mkdirs()); | ||
|
||
Files.copy( | ||
greeterSource.toPath(), | ||
Paths.get( | ||
sourcePathWithSpaces.toPath() | ||
+ File.separator | ||
+ greeterSourceName | ||
+ ".java")); | ||
File greeterSourceWithSpaces = new File(sourcePathWithSpaces, greeterSourceName + ".java"); | ||
Assertions.assertTrue(greeterSourceWithSpaces.exists()); | ||
|
||
CompilerClassLoader compilerClassLoader = | ||
new CompilerClassLoader( | ||
tempWithSpaces, new File(javaPathWithSpaces).toURI().toURL()); | ||
Assertions.assertNotEquals( | ||
null, | ||
compilerClassLoader.loadClass( | ||
(javaSourcePath + greeterSourceName).replace(File.separator, "."))); | ||
} | ||
} |