-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Files.copy() such that parent dirs are created
Closes #2761 Also toggled the version back to a bug fix version
- Loading branch information
1 parent
d51fbab
commit 5250a26
Showing
27 changed files
with
262 additions
and
81 deletions.
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
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
...a/org/testng/jarfileutils/JarCreator.java → ...ava/org/testng/testhelper/JarCreator.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
2 changes: 1 addition & 1 deletion
2
...java/testhelper/OutputDirectoryPatch.java → ...stng/testhelper/OutputDirectoryPatch.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
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
69 changes: 69 additions & 0 deletions
69
testng-core/src/test/java/org/testng/testhelper/SourceCode.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,69 @@ | ||
package org.testng.testhelper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import javax.tools.JavaFileObject.Kind; | ||
|
||
public class SourceCode { | ||
|
||
private final String packageName; | ||
private final String name; | ||
private final File directory; | ||
private final boolean skipLoading; | ||
private final File location; | ||
|
||
public SourceCode(String name, String src, File directory, boolean skipLoading) | ||
throws IOException { | ||
this("", name, src, directory, skipLoading); | ||
} | ||
|
||
public SourceCode( | ||
String packageName, String name, String src, File directory, boolean skipLoading) | ||
throws IOException { | ||
this.packageName = packageName; | ||
this.name = name; | ||
this.directory = directory; | ||
this.skipLoading = skipLoading; | ||
String path = name; | ||
boolean includesPackageName = false; | ||
if (packageName != null && !packageName.trim().isEmpty()) { | ||
path = packageName.replaceAll("\\Q.\\E", "/") + "/" + name; | ||
includesPackageName = true; | ||
} | ||
this.location = new File(directory, path + Kind.SOURCE.extension); | ||
if (!includesPackageName && this.location.exists()) { | ||
this.location.delete(); | ||
} | ||
Path parentDir = this.location.getParentFile().toPath(); | ||
if (!Files.exists(parentDir)) { | ||
Files.createDirectories(parentDir); | ||
} | ||
Files.write(location.toPath(), src.getBytes()); | ||
} | ||
|
||
public File getDirectory() { | ||
return directory; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public boolean hasPackageName() { | ||
return packageName != null && !packageName.trim().isEmpty(); | ||
} | ||
|
||
public String getPackageName() { | ||
return packageName; | ||
} | ||
|
||
public boolean isSkipLoading() { | ||
return skipLoading; | ||
} | ||
|
||
public File getLocation() { | ||
return location; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
testng-core/src/test/java/org/testng/testhelper/TestClassGenerator.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,38 @@ | ||
package org.testng.testhelper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public final class TestClassGenerator { | ||
private static final File projectDir = SimpleCompiler.createTempDir(); | ||
|
||
private TestClassGenerator() { | ||
// Utility class. Defeat instantiation. | ||
} | ||
|
||
public static File getProjectDir() { | ||
return projectDir; | ||
} | ||
|
||
public static SourceCode[] generate(String packageName, List<String> classNames) { | ||
return classNames.stream() | ||
.map(className -> generateCode(packageName, className)) | ||
.toArray(SourceCode[]::new); | ||
} | ||
|
||
private static SourceCode generateCode(String packageName, String className) { | ||
String source = "package " + packageName + ";\n\n"; | ||
source += "import org.testng.annotations.Test;\n"; | ||
source += "public class " + className + " {\n"; | ||
source += " @Test\n"; | ||
source += " public void testMethod() {\n"; | ||
source += " }\n"; | ||
source += "}\n"; | ||
try { | ||
return new SourceCode(packageName, className, source, projectDir, false); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
testng-core/src/test/java/org/testng/testhelper/TestNGSimpleClassLoader.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,36 @@ | ||
package org.testng.testhelper; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public final class TestNGSimpleClassLoader extends ClassLoader { | ||
|
||
private final File baseDir; | ||
|
||
public TestNGSimpleClassLoader() { | ||
this(null); | ||
} | ||
|
||
public TestNGSimpleClassLoader(File baseDir) { | ||
this.baseDir = baseDir; | ||
} | ||
|
||
public Class<?> injectByteCode(CompiledCode byteCode) throws ClassNotFoundException { | ||
Class<?> clazz = | ||
defineClass(byteCode.getName(), byteCode.getByteCode(), 0, byteCode.getByteCode().length); | ||
return loadClass(clazz.getName()); | ||
} | ||
|
||
@Override | ||
protected URL findResource(String name) { | ||
if (this.baseDir != null) { | ||
try { | ||
return new File(this.baseDir.getAbsolutePath() + "/" + name).toURI().toURL(); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
return super.findResource(name); | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.