Gradle: Generate folder structure dynamically during build - spring-boot

I have a gradle project where I want to convert WSDLs to Java classes using a gradle task. Requirement is to dynamically generate the individual java classes in separate sub-directories under a package/folder based on the number of WSDLs present. Currently my java classes are being generated under a single package/folder.
For example, if I have 2 WSDLs in my source folder then the gradle task should generate 2 java classes in separate sub-directories under the package/folder.
Please help me with a script code for the directories creation based on above scenario.

Related

Assembling a jar using Maven containing only files in a specified folder

I have the following Maven project structure.
project
-- src
-- main
-- java
-- models
-- resources
I want to create and deploy a jar project-models.jar containing everything inside the folder models and nothing else. Since I'm not very familiar with Maven, I'd really appreciate if you could provide me some example.
models belongs to resources (They should neither be compiled nor tested, should they?)
See How to create an additional attached jar artifact from the project:
Specify a list of fileset patterns to be included or excluded by adding <includes>/<include> or <excludes>/<exclude> and add a classifier in your pom.xml.
Note: the jar-plugin must be defined in a new execution, otherwise it will replace the default use of the jar-plugin instead of adding a second artifact. The classifier is also required to create more than one artifact.

Directory Structure for Cucumber + Maven + POM project under SRC & TEST folder

I am looking for effective project Structure to manage it with POM, Cucumber(Feature and Step definition Files) under Maven's Src & test folders.
What should be correct way to manage? Where to use Maven's src and test folder.
Please Share. Thanks in Advance.
Project Structure for a Maven project with Cucumber + POM
base package contains Page object initialization class where it can be extended to all the page classes
browser package contains the browser factory class which contains the methods to invoke Chrome, Firefox, IE etc.,
custom Exception package used to throw the custom messages
features package contains the feature files
pages package contains the page objects classes like login, home page with the relevant web elements and methods
resources package contains the driver information, test data information, xml configuration, property file etc.,
runner package contains the runner classes which is created in manual. Otherwise we can refer the same package for dynamic runner class creation in maven parallel plugin dependency.
steps package contains the step definition for each specific pages.
utils package contains the utility classes like common utility, selenium utility, excel utility etc.,
Under target
cucumber - parallel contains the parallel execution report
cucumber-reports contains the normal execution report
generated-test-sources contains the dynamic runner class files which is created during the run time for parallel execution.
feature files are not java code and should be in src\test\resources folder

Maven Test Automation Project

I have a maven test automation project developed using selenium and testng. This is what I am doing with my framework:
1.I have main class in src/main/java and within the main class I trigger methods to dynamically create and run the testng xml.
2.The tests to be run are determined from the XMLFlag.xls sheet and test data for the tests is set in TestNG.xlsx sheet in src/main/resources.
3.I have successfully created a jar of my entire package.
Since I have put my Test Data sheets(TestNG.xlsx and XMLFlag.xls)under src/main/resources, these Test data sheets get packaged within the jar.
But ideally, I would like to run my test scripts for different sets of test data and see if the scripts are successful.
for example: I would like to run my scripts with ,say, username:abcd and password:1234 for the first time and then run the same set of scripts with username:efgh and password:9876.
But with my Test data sheets packaged within the jar I will not be able to achieve the above scenario since I cannot edit the test data sheets.
So let me say to overcome the above problem:
1.I put my Test data sheets in src/test/resources and not src/main/resources and then create a jar.
But when I do this and try to run the jar,
I get an error message:
.\src\test\resources\XMLFlag.xls (The system cannot find the path specified)
This, I believe, is because the Test data sheets get placed in test-classes folder under target folder and not within the jar.
To put it in simple words:
i. I want the test data sheets to be outside my jar, so that it can be edited and test scripts can be run based on the users requirement.
ii.If the test data sheets are outside my jar and everything else within my framework is dependent on test data information(ie.test scripts, testng.xml) and is packaged within the jar, my jar would not run.
Is there a way to avoid this error and accomplish what I want to do?
Or should I restructure my entire framework??
Kindly help me out.
How about passing the Test Data sheets as program arguments when you're executing your jar?
That is,
java -jar c:/path/to/your/jar c:/path/to/your/testng.xlsx c:/path/to/your/xmlflag.xlsx
and then just in your main method, read the file names and their content such as
File testNgXlsxFile = new File(args[0]);
and pass the information from the files to your framework.
Is that possible?

ActiveJDBC Instrumentation: Unable to instrument the model classes which are in Jar

I am using activejdbc 1.4.9. I created one jar (using maven) which has two ActiveJDBC Model Classes. I added the jar to the application. Application has three more model classes. When I compile and try to run the application (gradle based), activejdbc is instrumenting only 3 classes which are in application but not instrumenting the classes which are in jar. When I try to write the data into the two models which are in jar, It is throwing exception as
org.javalite.activejdbc.DBException: Failed to retrieve metadata from DB. Are you sure table exists in DB ?
Now I have certain doubts. Please help me to resolve and understand few things.
How instrumentation happens ?
When we create a jar, will it include instrumented classes ?
Why it is throwing this error ?
It is throwing this error in case classes have not been instrumented. This means that before placing your model classes into a jar file, you need to instrument them. Does not matter which build method you use though. This http://javalite.io/instrumentation explains what is instrumentation and how to do it. Instrumentation does not create jars, it merely adds some byte code into your classes. In all scenarios you need:
Write code :)
Compile
Instrument
after this, you can do any of the following:
run app using class files in the file system
package class files into jar file and use that on your classpath
package jar file into a larger app (WAR, EAR, RAR, etc.) and deploy your app
making sense?

Can I use the gradle connector to get arbitrary configuration information from a build.gradle file?

I'm using the Gradle connector with a Gradle project that is downloaded from a service. I want to do some Gradle operations on that project but need some information from the project.
The downloaded project's build.gradle has some properties that I would like to extract :
group = "value0"
archivesBaseName = "value1"
version = "value2"
If I use
ProjectConnection.getModel(GradleProject.class)
I can get some values from the model but not those ones that I want (perhaps I am using it wrong?). Is there a way to extract those specific values out of the project (perhaps a different model)? I can also just do some text parsing on the build file, but I'd like that to be my last option.
The Gradle tooling API only exposes a subset of the build script information, using its own models. As far as I can tell, the properties that you are interested in are not exposed by default. However, you can expose your own custom model. For an example, see samples/toolingApi/customModel in the full Gradle distribution.

Resources