New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Files.copy() such that parent dirs are created #2764
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not the latest version or the next one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last released version was
7.6.0
. Am guessing that this qualifies to be a bugfix release. Hence the version as7.6.1
7.7.0
- Will be the version for the next release (I have already moved the milestones etc., Dont want to go through that ritual once again)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we release 7.6.x during this year and maybe once per year lift the major version to allow smaller releases from time to time.