How do I get Lazybones to create Multi Modular Java EE 7 Gradle Projects? - gradle

This is my repository in github: https://github.com/joedayz/lazybones-templates/
I used processTemplates according with the documentation
processTemplates 'build.gradle', props
processTemplates 'gradle.properties', props
processTemplates 'src/main/java/*.java', props
processTemplates 'settings.gradle', props
I request the user this information:
props.project_megaproceso = ask("Define value for 'megaproceso' [megaproceso]: ", "megaproceso", "megaproceso")
props.project_macroproceso = ask("Define value for 'macroproceso' [macroproceso]: ", "macroproceso", "macroproceso")
props.project_proceso = ask("Define value for 'proceso' [proceso]: ", "proceso", "proceso")
megaproceso2, macroproceso, proceso are directories or part of file names in my template.
How do I change the names of the unpacked directories and files? The code is in my github.

The post-install scripts for Lazybones currently have full access to both the standard JDK classes and the Apache Commons IO library, specifically to aid with file manipulation.
In this specific case, you can either use File.renameTo() or FileUtils.moveFile/Directory(). For example:
def prevPath = new File(projectDir, "megaproceso2-macroproceso-proceso.ear")
prevPath.renameTo(new File(
projectDir,
"${props.megaproceso}-${props.macroproceso}-${props.processo}.ear"))
The projectDir variable is one of several properties injected into the post-install script. You can find a list of them in the Template Developers Guide.
I think the main advantage of FileUtils.moveFile() is that it works even if you're moving files across devices, but that's not necessary here. Also note that you have to explicitly import the classes from Commons IO if you want to use them.

Related

New Scala.js facade for Three.js -> "Cannot find module "THREE""

As https://github.com/antonkulaga/threejs-facade is heavily outdated I tried an approach like: https://github.com/Katrix-/threejs-facade and would like to create a facade for the new three.js library.
I am by no means a JS expert, nor am I a Scala.js expert, so odds are I am doing something really dumb.
After another question I am using this sbt-scalajs-bundler and sbt-web-scalajs-bundler
My build.sbt looks like this:
lazy val client = (project in file("modules/client"))
.enablePlugins(ScalaJSBundlerPlugin, ScalaJSWeb) // ScalaJSBundlerPlugin automatically enables ScalaJSPlugin
.settings(generalSettings: _*)
.settings(
name := "client"
//, scalaJSModuleKind := ModuleKind.CommonJSModule // ScalaJSBundlerPlugin implicitly sets moduleKind to CommonJSModule enables ScalaJSPlugin
,jsDependencies += ProvidedJS / "three.min.js"
)
lazy val server = (project in file("modules/server"))
.enablePlugins(PlayScala, WebScalaJSBundlerPlugin)
.settings(generalSettings: _*)
.settings(
name := "server"
,scalaJSProjects := Seq(client)
,pipelineStages in Assets := Seq(scalaJSPipeline)
//,pipelineStages := Seq(digest, gzip)
,compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
)
three.min.js is in the resources-folder of my client project.
One part of the Facade is e.g.
#js.native
#JSImport("THREE", "Scene")
class Scene extends Object3D {
and I want to use it like this: val scene = new Scene. On scala.js side this actually compiles just fine, but when I run it I get:
Error: Cannot find module "THREE"
in the browser and I wonder why. It's called like this in three.min.js after all.
Now I tried providing and serving the three.min.js file from the server side as well, because I thought that maybe it was just missing at runtime, but no, that does not seem to be the cause.
So now I wonder what am I doing wrong here?
Just to clarify: Rest of transpiled js works just fine, if I do not export any usage of the Facade!
As explained in this part of Scala.js documentation, #JSImport is interpreted by the compiler as a JavaScript module import.
When you use the CommonJSModule module kind (which is the case when you enable the ScalaJSBundlerPlugin), this import is translated into the following CommonJS import:
var Scene = require("THREE").Scene;
This annotation only tells how your Scala code will be interfaced with the JS world, but it tells nothing about how to resolve the dependency that provides the THREE module.
With scalajs-bundler you can define how to resolve JS dependencies from the NPM registry by adding the following setting to your client project:
npmDependencies += "three" -> "0.84.0"
(And note that you can’t use jsDependencies to resolve these modules with #JSImport)
Also, note that the correct CommonJS import to use three.js is "three" instead of "THREE", so your #JSImport annotation should look like the following:
#JSImport("three", "Scene")
Alternatively, if you don’t want to resolve your dependencies from the NPM registry, you can supply your CommonJS module as a resource file. Just put it under the src/main/resources/Scene.js and refer to it in the #JSImport as follows:
#JSImport("./Scene", "Scene")
You can see a working example here.

assign variables directly to build in jenkins

I am new to Jenkins, i have a wrapper script that runs overnight in Jenkins.
This wrapper script takes input from a .CSV file which contains list of projects. i had to give this way = ./wrapper_script project.csv
This has one problem i.e., it runs all the projects in one single build, but my requirement is i should run one build per project. I have already installed necessary plugins.
How can i give project.csv content as input to the build where i will trigger the wrapper_script.sh directly
Have a look on Job DSL Plugin. You could create a seed-job that reads the CSV file and iterates over the records and creates a job for each record. If you need a more detailed code example, please include sample data from your CSV file.
Ok. Given that the CSV you provided it so simple, you could skip using the CSV library. Your Job DSL seed job would be something like this:
new File('project.csv').splitEachLine(',') { fields ->
job(fields[0]) {
steps {
shell("your build command " + fields[1])
}
}

Can a build template be based on another build template on TeamCity?

I am using TeamCity 9.0.2, and I would like to make a template implement another template, or make a build configuration implement more than one template.
Can this be achieved?
This was not available when you asked the question but since Team City 10 you can now use Kotlin to configure your builds and thus your templates.
From this you can make Templates implement other Templates.
I myself have made Templates inherit from other templates to cut down on reconfiguration time and to not have to repeat myself so many times.
open class TheBaseTemplate(uuidIn: String, extIdIn: String, nameIn: String, additionalSettings: Template.() -> Unit) : Template({
uuid = uuidIn
extId = extIdIn
name = nameIn
/* all the other settings that are the same for the derived templates*/
additionalSettings()
})
object DerivedTemplateA : TheBaseTemplate("myUuidA", "myExtIdA", "myNameA", {
params {
param("set this", "to this")
}
})
object DerivedTemplateB : TheBaseTemplate("myUuidB", "myExtIdB", "myNameB", {
params {
param("set this", "to that")
}
})
object Project : Project({
uuid = "project uuid"
extId = "project extid"
name = "project name"
buildType {
template(DerivedTemplateA)
/* the uuid, extId and name are set here */
}
buildType {
template(DerivedTemplateB)
/* the uuid, extId and name are set here */
}
template(DerivedTemplateA)
template(DerivedTemplateB)
})
The above code might be very hard to understand. It will take some time to familiarise yourself with Kotlin, what it does, and how it interfaces with TeamCity. I should point out that some imports are missing.
Additionally, take the example with a pinch of salt. It is a quick example to demonstrate one way of templates implementing other templates. Do not take this example as the definitive way to do things.
Unfortunately, this is currently not possible but already requested for a long time in TW-12153 (maybe you would like to vote for it).
To share several build steps among several build configurations or build configuration templates, I am using meta runners:
A Meta-Runner allows you to extract build steps, requirements and parameters from a build configuration and create a build runner out of them.
This build runner can then be used as any other build runner in a build step of any other build configuration or template.
Although using meta runners works as a workaround for us, editing meta runners is not as convenient as editing a build configuration template (as it usually requires editing the meta runner definition XML file by hand).
Update 2021
As #zosal points out in his answer TeamCity meanwhile provides another way of sharing common build configuration data or logic by means of the Kotlin DSL. The Kotlin DSL is a very powerful tool but may not always fit in your specific scenario. I would recommend to at least give it a try or watch one of the introductory tutorial videos.

Unitils and DBMaintainer - how to make them work with multiple users/schemas?

I am working on a new Oracle ADF project, that is using Oragle 10g Database, and I am using Unitils and DBMaintainer in our project for:
updating the db structure
unittesting
read in seed data
read in test data
List item
In our project, we have 2 schemas, and 2 db users that have privilegies to connect to these schemas. I have them in a folder structure with incremental names and I am using the #convention for script naming.
001_#schemaA_name.sql
002_#schemaB_name.sql
003_#schemaA_name.sql
This works fine with ant and DBMaintainer update task, and I supply the multiple user names by configuring extra elements for the ant task.
<target name="create" depends="users-drop, users-create" description="This tasks ... ">
<updateDatabase scriptLocations="${dbscript.maintainer.dir}" autoCreateDbMaintainScriptsTable="true">
<database name="${db.user.dans}" driverClassName="${driver}" userName="${db.user.dans}" password="${db.user.dans.pwd}" url="${db.url.full}" schemaNames="${db.user.dans}" />
<database name="idp" driverClassName="${driver}" userName="${db.user.idp}"
password="${db.user.idp.pwd}" url="${db.url.full}" schemaNames="${db.user.idp}" />
</updateDatabase>
</target>
However, I cant figure out, how to make the DBMaintainer update task create the xsd schemas from my db schemas?
So, I decided to use Unitils, since its update creates xsd schemas.
I haven't found any description or documentation for the Unitils ant tasks - can anyone give some hints?
For the time being I have figured out to run Unitils by creating a Junit test, with #Dataset annotation. I can make it work with one schema, and one db user. But I am out of ideas how to make it work with multiple users?
Here is the unitils-local.properties setup I have:
database.url=jdbc\:oracle\:thin\:#localhost\:1521\:vipu
database.schemaNames=a,b
database.userName=a
database.password=a1
Can any of you guys give me a tip, how to make Unitils work with the second user/schema ??
I will be extremely gratefull for your help!
eventually I found a way to inject any unitil.properties of your choice --- by instantiating Unitils yourself!
You need a method that is evoked #BeforeClass, in which you perform something like the following:
#BeforeClass
public void initializeUnitils {
Properties properties;
...
// load properties file/values depending on various conditions
...
Unitils unitils = new Unitils();
unitils.init(properties);
Unitils.setInstance( unitils );
}
I choose the properties file depending on which hibernate configuration is loaded (via #HibernateSessionFactory), but there should be other options as well
I have figure out how to make dbmaintain and unitils work together on multi-database-user support, but the solution is a pure ant hack.
I have set up the configuration for dbmaintain, using multi-database-user support.
I have made a unitils-local.properties file with token keys for replacement.
The init target of my ant script is generating a new unitils-local.properties file, by replacing tokens for username/password/schema with values that are correct for the target envirnonment, and then copies it to the users home directory.
I have sorted the tests into folders, that are prefixed with the schema name
When unitils is invoked, it picks up the unitils-local.properties file just created by the ant script, and does its magic.
Its far from pretty, but it works.
Check out this link: http://www.dbmaintain.org/tutorial.html#From_Java_code
Specifically you may need to do something like:
databases.names=admin,user,read
database.driverClassName=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin://mydb:1521:MYDB
database.admin.username=admin
database.admin.password=adminpwd
database.admin.schemaNames=admin
database.user.userName=user
database.user.password=userpwd
database.user.schemaNames=user
database.read.userName=read
database.read.password=readpwd
database.read.schemaNames=read
Also this link may be helpful: http://www.dbmaintain.org/tutorial.html#Multi-database__user_support
I followed Ryan suggestion. I noticed couple changes when I debugged UnitilsDB.
Following is my running unitils-local.properties:
database.names=db1,db2
database.driverClassName.db1=oracle.jdbc.driver.OracleDriver
database.url.db1=jdbc:oracle:thin:#db1d.company.com:123:db1d
database.userName.db1=user
database.password.db1=password
database.dialect.db1=oracle
database.schemaNames.db1=user_admin
database.driverClassName.db2=oracle.jdbc.driver.OracleDriver
database.url.db2=jdbc:oracle:thin:#db2s.company.com:456:db2s
database.userName.db2=user
database.password.db2=password
database.dialect.db2=oracle
Make sure to use #ConfigurationProperties(prefix = "database.db1") to connecto to particular database in your test case:
#RunWith(UnitilsJUnit4TestClassRunner.class)
#ConfigurationProperties(prefix = "database.db1")
#Transactional
#DataSet
public class MyDAOTest {
..
}

How can I add an MSBuild Import with IVsBuildPropertyStorage?

I'm trying to add an Import task to a .csproj file programmatically, but I don't want to use the Microsoft.Build.BuildEngine objects to do this because VS will then pop up warnings about the project file being modified from outside of Visual Studio.
I've seen a few pages [1] [2] suggesting that the IVsBuildPropertyStorage interface will let me access the MSBuild parts of the .csproj file, but I'm having trouble figuring out how to do this, or if it's even possible really. It looks like I need to specify the name of the property I want to access, but I'm not sure how to figure that out. Calling GetPropertyValue() for an "Import" property doesn't return anything for project files that are already set up how I want my final results to look:
EnvDTE.Project proj = ...;
var sol = Package.GetGlobalService(typeof(VsSolution)) as IVsSolution;
IVsHierarchy hier;
sol.GetProjectOfUniqueName(p.UniqueName, out hier);
var storage = hier as IVsBuildPropertyStorage;
string val;
storage.GetPropertyValue("Import", String.Empty,
(uint)_PersistStorageType.PST_PROJECT_FILE, out val);
// val is null
[1] https://mpfproj.svn.codeplex.com/svn/9.0/Tests/UnitTests/ProjectTest.cs
[2] http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/e1983591-120a-4a2f-a910-e596dd625e68
Thanks. I'd appreciate any suggestions I can get with this.
I asked a similar question see here Programmatically adding and editing the Targets in a Visual Studio Project File What you can do to add an import to the project file programmatically is to use this namespace http://msdn.microsoft.com/en-us/library/microsoft.build.construction.aspx which is from the assembly (in the GAC) Microsoft.Build.dll. You can accomplish this in about 3-4 steps:
the following is pseudo code:
Get the Project File location using the DTE.ActiveSolutionProjects and getting the Properties of each Project. Get the FullPath and the FileName to get the full path of the project file.
Once you have the full path of the project file, call the ProjectRootElement.Open static method:
ProjectRootElement project = ProjectRootElement.Open(projectPath);
Once you have the ProjectRootElement reference, you can call the AddImport method (where name is the Project Identifier Attribute):
project.AddImport(name)
That should do it.
Import element is not a Property element in MSBuild nor and Item one.
I think you can't add an Import using IVsBuildPropertyStorage.

Resources