Why move task does not move symlinks? - deployment

I have a deployment script where I move a directory to another directory. In this directory I have a symlink relative to a parent folder like this:
abc -> ../dir/file
dir/file is also in the directory which gets deployed.
I move the directory with the following lines of xml:
<move todir="${deploy.dir}">
<fileset dir="${to.deploy}">
<include name="**/*" />
</fileset>
</move>
Everything gets moved but not the symlinks. The stay in the ${deploy.dir}. Why? Maybe Ant does not know how to set the new symlink (the new location)?
How can you fix this? Delete the symlink and use the symlink target to make a new one?

Symbolic links are special files. Ant is not fully capable of handling them. Here is the note.
Ant is not symbolic link aware in moves, deletes and when recursing
down a tree of directories to build up a list of files. Unexpected
things can happen.
You need a custom solution , probably using readlink. Question How do I move a relative symbolic link? and answers points to additional solutions (nothing to do with ant, though)

Related

Nesting files in Nuget package without PowerShell

The title says it all. I have files that I want to nest during the installation of a NuGet package but can't use PowerShell scripts since they won't be run any longer (see here).
Are there any other ways to achieve this goal?
UPDATE: By nested I mean like *.resx and *.Designer.cs or *.xaml and code-behind files *.xaml.cs. I know I can achieve that by adding a <DependentUpon> element in the *.csproj file but I don't know how I can add that element without using PowerShell.
UPDATE2: init.ps1 runs the first time a package is installed in a solution. That won't cut it though. I would need the script to run when the package is installed into a project just like install.ps1 was run up to NuGet3.
UPDATE3: What I want to do is to add 3 files into the Properties folder of the target projects (Resources.resx, Resources.tt and Resources.Designer.cs). They are a replacement for the usual resources implementation. These files are installed by the nuget package when it is added to the project.
This is the part of the *.nuspec file that adds them to the Content folder of the package. As only one of them is actually content (the others being an Embedded Resource and Compile respectively) it would be nice to be able to set their build actions accordingly but one step at a time.
<files>
<file src="Properties\Resources.resx" target="content\Properties\Resources.resx" />
<file src="Properties\Resources.tt.pp" target="content\Properties\Resources.tt.pp" />
<file src="Properties\Resources.Designer.cs" target="content\Properties\Resources.Designer.cs" />
</files>
As these files are added to the projects I want the nesting inside the *.csproj file and not happen via a separate *.props file if that is somehow possible.
Packages can add MSBuild items like this to a project by using a .props file in the package. It would contain the same content that you would put into the .csproj file.
The down side of this is that the content cannot be modified by the user. If you need to modify the user's actual project file and copy content to the project folder you would have to include a .targets file in your package and set BeforeTargets="Build" on your target. This would give you a chance to run before build and make changes as needed.
The build folder works for both packages.config and PackageReference (NETCore SDK) projects. You can find more out about it here: https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package

Include documentation in a JAR file

With Eclipse it is possible to attach a documentation folder to a jar file in order to see the jar classes' documentation while programming. My question is: is it possible to directly include the documentation into the jar file, in order to avoid the programmer to link the two parts every time they need to use the jar file? (and so to let me to distribute just a jar file, rather than a zip file with the jar and its documentation).
EDIT
final result: it is impossible. :(
I didn't get what do you mean with "directly include the documentation", but you can put anything in the jar file. If you use ant (it can be inside Eclipse), just create a target for your distribution build and pass the documentation folder to Jar task.
<jar destfile="${dist}/lib/app.jar">
<fileset dir="${build}/classes"
excludes="**/Test.class"
/>
<fileset dir="${src}/documentation"/>
</jar>

Netbeans, how to build project deploy(war) file into custom folder?

Netbeans project, is it possible to build deploy(.war) file into domain's autodeploy folder automatically, not in dist folder?
So that, it would be VERY useful to deploy project .war file to local glassfish server automatically.
You can automate almost all kinds of things, from compilation files processed by ant stages.
In project.properties file must add a reference for your end folder
war.custom.dir=/path/to/end/folder/
"this is not mandatory but is a correct method"
Then, in your build.xml file should add this chunk of code
<target name="-post-dist">
<echo message="Copy .war file to my custom folder"/>
<copy file="${dist.war}" todir="${war.custom.dir}" />
</target>
And your file .war, will move wherever you want.
Could also be changed your file in the build-impl.xml target "do-ear-dist"
allowing directly effect the compression to your end folder.
Or you could also modify references in your project to work on your end folder, the mechanism is really very simple to customize as you think best.

How to include a resource file in the Jar file generated by Netbeans?

I'm using NB6.7 to auto generate an executable jar file for my project, how and where to tell NB to include a certain resource into the result jar file ? I know if I put the resource in the "lib" directory, NB will put it into "dist/lib/", but what I want is to include the resource within the final executable jar, where in NB do I specify that ?
Frank
There is a way to add arbitrary file/folders to arbitrary location within the jar, without setting up source folders.
NetBeans will, by default, create build.xml at project root.
We can override the -pre-jar target to copy the files and -post-jar target to cleanup.
For example, to copy "res/resource.ext" into "myres/resource.ext" within the jar, add these target to build.xml:
<target name="-pre-jar">
<!-- Single file -->
<copy file="res/resoure.ext" todir="${build.dir}/classes/myres" />
<!-- Folder(s) -->
<copy todir="${build.dir}/classes/myres"><fileset dir="res"/></copy>
</target>
<target name="-post-jar">
<delete dir="${build.dir}/classes/myres/resource.ext" />
<delete dir="${build.dir}/classes/myres"/>
</target>
Since this is Ant, you have great control.
You can rename file, replace file content (e.g. update version or timestamp), convert charset, or run other operations that is not possible with simple inclusion.
I am using NetBeans version 8, but as long as the project is compatible it is likely to work.
Alternatively, use an automated project such as Maven or Gradle, that gives you even more control on the build process, at cost of IDE features such as automatic single file recompile.
I got it : put the resource file in the src dir.
you can do it by...
Go to your project name which is normally on the left hand side of the screen.
Whatever your project name is,
you have to right click on it and then go to the properties of that. [which is normally at the end in menu item]
Then one window will open in that go to the Libraries.
In that you will find
1)ADD PROJECT
2)ADD Libraries
3)ADD JAR FILE
then include the jar / Libraries / folder.
so that will add automatically to your project.
Which will include in lib folder automatically so you don't have to include always.
Hope this help you,

New to Ant - Problem with relative paths

Please help, I'm going slightly mad!!
I'm using Eclipse-generated antfiles to build a project with dependencies, one of which has its own buildfile in a directory which is a sibling to the direct ancestor of the project I'm building. E.g. if my directory is "/base/modules/clinicalcontext", the directory of one of the dependencies is simply "/base/core".
So, the generated build.xml uses ../../core which afaik is correct. But it is not!! From the console it is apparent that Ant goes back three levels and not just two (it gives FileNotFound on "/core/build.xml").
I tried to change the relative path to "../core" and much to my astonishment, this way Ant goes back by one level (it laments "/base/modules/core" being nonexistent). So how in the world I tell Ant t go back by two levels? I'd prefer to avoid using absolute paths, since I might have to move the project to a different machine someday.
Thanks everybody.
All Ant path will be relative to your current working directory.
So, check what directory you are running your script from.
I suggest that you start using ${basedir} to get a path relative to a location of build.xml.
In your case, the relative path should be constructed like this: ${basedir}/../../core, instead of ../../core.
The inconsistencies you encounter illustrate a point why eclipse-generated ant scripts are a good starting point, but never a good project build system.
EDIT. I wonder why eclipse ant generator does not insert ${basedir} in relative paths? Maybe you should report it as a bug.