Compiling SASS using jRuby - css

I'm using jruby to compile scss files to css using ant build script.
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="compileSCSS" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<path id="JRuby">
<fileset file="libs/jruby-complete-1.7.18.jar"/> <!-- Location of JRuby jar file -->
</path>
<target name="compileSCSS">
<echo message="Compiling scss files..." />
<property name="filesIn" value="style.scss" />
<property name="fileOutDir" value="output/" />
<property name="root" value="." />
<script language="ruby" classpathref="JRuby">
<![CDATA[
require './libs/sass/lib/sass'
require './libs/sass/lib/sass/exec'
files = Dir.glob($project.getProperty('filesIn'))
files.each do |file|
opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
opts.parse
end
]]>
</script>
<echo message="Done compiling SCSS source files." />
</target>
</project>
This is my build script. I'm using jruby 1.7.8 and SASS source code from github (version 3.4.9).
Its throwing exception :
javax.script.ScriptException: org.jruby.embed.EvalFailedException:
(NameError) uninitialized constant Sass::Exec::Sass
Please help. What could be the Issue?

Related

How to loop macrodef in Ant script?

Currently, I am writing an Ant Script that removes the signatures of signed Jar files.
Removing the signature for a single jar file was successful using the script below.
<project name="unsign">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="ant-lib/ant-contrib-0.6.jar" />
<property name="jarPath" location="C:\Users\Administrator\Desktop\tempDir" />
<property name="resultPath" location="C:\Users\Administrator\Desktop\tempDir-result" />
<target name="unsignJar">
<unsignjar jarFile="${jarPath}/com.google.guava_15.0.0.v201403281430.jar" />
</target>
<macrodef name="unsignjar" description="Unsign a jar file">
<attribute name="jarfile" description="Jar file to unsign " />
<sequential>
<copy toFile="#{jarFile}_MANIFEST.tmp">
<resources>
<zipentry zipfile="#{jarFile}" name="META-INF/MANIFEST.MF" />
</resources>
</copy>
<replaceregexp file="#{jarFile}_MANIFEST.tmp" match="\nName:(.+?)\nSH" replace="SH" flags="gis" byline="false" />
<replaceregexp file="#{jarFile}_MANIFEST.tmp" match="SHA(.*)" replace="" flags="gis" byline="false" />
<jar jarfile="#{jarFile}.tmp" manifest="#{jarFile}_MANIFEST.tmp">
<zipfileset src="#{jarFile}">
<include name="**" />
<exclude name="META-INF/*.SF" />
<exclude name="META-INF/*.DSA" />
<exclude name="META-INF/*.RSA" />
</zipfileset>
</jar>
<!-- Removing the temporary manifest -->
<delete file="#{jarFile}_MANIFEST.tmp" />
<!-- Swapping the original Jar file with the temporary one -->
<move file="#{jarFile}.tmp" tofile="#{jarFile}" overwrite="true" />
</sequential>
</macrodef>
</project>

Exclude target framework from NuGet package

How can i exclude specific target framework from nuspec (NuGet package) generation?
This is my csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
dotnet pack command generates NuGet package that contains all target frameworks not only netstandard2.0 and net5.0
Generated nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ExampleLibrary</id>
<version>1.0.0</version>
<authors>ExampleLibrary</authors>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework="net5.0-windows7.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows7.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);_ExcludeTargetFramework;_ExcludeTargetFrameworkDependency</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="_ExcludeTargetFramework" AfterTargets="_GetTargetFrameworksOutput" BeforeTargets="_WalkEachTargetPerFramework">
<ItemGroup>
<_TargetFrameworks Remove="net5.0-windows7.0" />
</ItemGroup>
</Target>
<Target Name="_ExcludeTargetFrameworkDependency" AfterTargets="_WalkEachTargetPerFramework" BeforeTargets="GenerateNuspec">
<ItemGroup>
<_FrameworksWithSuppressedDependencies Include="net5.0-windows7.0" />
</ItemGroup>
</Target>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ExampleLibrary</id>
<version>1.0.0</version>
<authors>ExampleLibrary</authors>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>
Remove all the dependencies (including TargetFramework)
In case you want to remove all dependencies (ie all target frameworks), the above solution won't work. Build will fail with the following error:
error MSB4044: The "ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework".
Easy way
In case you just want to remove all dependencies, you can use the SuppressDependenciesWhenPacking property.
<PropertyGroup>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>
Full control of Nuspec
Otherwise, if you want to have a full control on the content of Nuspec after a first pass of generation, you can use a variation of this:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<UsingTask
TaskName="RemoveDependencies"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Nuspec ParameterType="System.String" Required="true"/>
</ParameterGroup>
<Task>
<Reference Include="System.Xml"/>
<Reference Include="System.Xml.Linq"/>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Xml.Linq"/>
<Code Type="Fragment" Language="cs">
<!-- Modify XML of the NuSpec -->
<![CDATA[
XElement doc = XElement.Load(Nuspec);
var dependenciesElement = doc.Descendants(XName.Get("dependencies", "http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd")).FirstOrDefault();
if (dependenciesElement != null)
{
dependenciesElement.Remove();
}
using (var textWriter = File.CreateText(Nuspec))
{
doc.Save(textWriter);
}]]>
</Code>
</Task>
</UsingTask>
<!-- From https://stackoverflow.com/questions/53762903/how-to-inject-a-custom-dependency-in-an-msbuild-nuget-pack-generated-nuspec -->
<!-- Disable nupkg generation before running pack -->
<Target Name="__DisablePacking" BeforeTargets="GenerateNuspec" Condition="$(NuspecFile) == '' And $(IsPackable) != 'false'">
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
</Target>
<!-- Remove .Net Standard 2.0 dependency as it's a native package -->
<!-- Modify the generated nuspec file and rerun the pack target -->
<Target Name="__ExcludeTargetFrameworkDependency" AfterTargets="Pack" Condition="$(NuspecFile) == '' And $(IsPackable) != 'false'">
<!-- Get the nuspec file name -->
<PropertyGroup>
<_NugetPackOutputAsProperty>#(NuGetPackOutput)</_NugetPackOutputAsProperty>
</PropertyGroup>
<ItemGroup>
<_NugetPackOutputAsItem Remove="#(_NugetPackOutputAsItem)"/>
<_NugetPackOutputAsItem Include="$(_NugetPackOutputAsProperty.Split(';'))" />
</ItemGroup>
<PropertyGroup>
<__NuspecFileName>%(_NugetPackOutputAsItem.Identity)</__NuspecFileName>
</PropertyGroup>
<Message Importance="High" Text="Remove Dependencies from $(__NuspecFileName)" />
<RemoveDependencies Nuspec="$(__NuspecFileName)" />
<!-- Invoke the Pack target again with packing enabled -->
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
<MsBuild
Projects="$(MSBuildProjectFullPath)"
Targets="Pack"
Properties="NuspecFile=$(__NuspecFileName);NoPackageAnalysis=true">
</MsBuild>
</Target>
</Project>
Notes:
GenerateNuspec target is doing both generation and packing. To disable packing after nuspec generation, we can use the ContinuePackingAfterGeneratingNuspec property.
Pack target is invoked twice (once by the user) and the second time with the system after first pack.
__ExcludeTargetFrameworkDependency rely on the Nuspec File value to be empty to execute on the first pack and to not execute on the second run. It obviously won't work if a Nuspec file is provided for the first run (with NuspecFile property).
Note the usage of And $(IsPackable) != 'false' to avoid invoking the target on test projects.
All NuGet targets like GenerateNuspec are located in C:\Program Files\dotnet\sdk\6.0.308\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets
All NuGet tasks for .NET 6, like PackTask, are located in C:\Program Files\dotnet\sdk\6.0.308\Sdks\NuGet.Build.Tasks.Pack\Desktop\NuGet.Build.Tasks.Pack.dll

Error when creating JavaFX jar file from codes written in Groovy

I tried to create a standalone jar file from source codes written in Groovy, using the following build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build" default="build" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property name="groovy" value="C:/groovy-2.4.5"/>
<property name="source" value="source"/>
<property name="binary" value="binary"/>
<property name="distribution" value="distribution"/>
<property name="data" value="data"/>
<property name="name" value="application"/>
<property name="class" value="ziphil.main.Launcher"/>
<path id="groovy.classpath">
<fileset dir="${groovy}/embeddable/"/>
</path>
<path id="compile.class.path">
<fileset dir="${groovy}/lib/"/>
</path>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.classpath"/>
<target name="clean">
<mkdir dir="${binary}"/>
<mkdir dir="${distribution}"/>
<delete>
<fileset dir="${binary}" includes="**/*"/>
<fileset dir="${distribution}" includes="**/*"/>
</delete>
</target>
<target name="compile" depends="clean">
<groovyc srcdir="${source}" destdir="${binary}" classpathref="compile.class.path" encoding="UTF-8"/>
<copy todir="${binary}/${data}">
<fileset dir="${source}/${data}"/>
</copy>
</target>
<target name="build" depends="compile">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${java}/lib/ant-javafx.jar"/>
<fx:application id="id" name="${name}" mainClass="${class}"/>
<fx:resources id="appRes">
<fx:fileset dir="${distribution}" includes="${name}.jar"/>
</fx:resources>
<fx:jar destfile="${distribution}/${name}.jar">
<fx:application refid="id"/>
<fx:resources refid="appRes"/>
<fileset dir="${binary}"/>
</fx:jar>
</target>
<target name="run" depends="build">
<java jar="${distribution}/${name}.jar" fork="true"/>
</target>
</project>
But I had an error saying that the main class was not found when trying to run the created jar file (in run target of the XML above). What should I do to resolve this error?
You may have to add to the runtime classpath all the jars that your application depends on. I guess that you need at least to include compile.class.path to your runtime classpath :
<target name="run" depends="build">
<java jar="${distribution}/${name}.jar" fork="true" classpathref="compile.class.path"/>
</target>

Css is not working after deployment of a JavaFX app in Eclipse

If I deploy a JavaFX app from Eclipse then it won't load the CSS file for some reason, though the app works as expected inside Eclipse.
Main class:
public class Main extends Application {
Stage primaryStage;
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
showMain();
}
public void showMain(){
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("Mainwindow.fxml"));
AnchorPane ap = loader.load();
ap.getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
Scene scene = new Scene(ap);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
The css is:
#CHARSET "UTF-8";
.button{
-fx-background-color: blue;
}
The fxml:
<AnchorPane prefHeight="381.0" prefWidth="446.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<Button layoutX="14.0" layoutY="14.0" mnemonicParsing="false" text="Button" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="14.0" />
</children>
</AnchorPane>
In the build.xml I just set the obligatory things. I don't convert the css into bss. I sign it and that's all.
The build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="JavaFXTester6_Web" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
<target name="setup-staging-area">
<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />
<mkdir dir="externalLibs" />
<mkdir dir="project" />
<copy todir="project">
<fileset dir="/home/zooey/LinuxEclipse/linuxWorkspace/JavaFXTester6_Web">
<include name="src/**" />
</fileset>
</copy>
<mkdir dir="projectRefs" />
</target>
<target name='do-compile'>
<delete dir="build" />
<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />
<!-- Copy project-libs references -->
<copy todir="build/libs">
<fileset dir="externalLibs">
</fileset>
</copy>
<!-- Copy project references -->
<!-- Copy project sources itself -->
<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*"/>
</fileset>
</copy>
<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="UTF-8">
<classpath>
<fileset dir="build/libs">
<include name="*"/>
</fileset>
</classpath>
</javac>
<!-- Copy over none Java-Files -->
<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
<delete file="dist"/>
<delete file="deploy" />
<mkdir dir="dist" />
<mkdir dir="dist/libs" />
<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="JavaFXTester6_Web.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
</fx:resources>
<fx:application id="fxApplication"
name="Test"
mainClass="application.Main"
/>
<mkdir dir="build/classes/META-INF" />
<fx:jar destfile="dist/JavaFXTester6_Web.jar">
<fx:application refid="fxApplication"/>
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes"/>
<manifest>
<attribute name="Implementation-Vendor" value="ZA"/>
<attribute name="Implementation-Title" value="Test"/>
<attribute name="Implementation-Version" value="1.0"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<fx:signjar //intentionally removed >
<fileset dir='dist'>
<include name='**/*.jar' />
</fileset>
</fx:signjar>
<mkdir dir="deploy" />
<!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
<fx:deploy
embedJNLP="false"
extension="false"
width="400" height="400"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="JavaFXTester6_Web"
placeholderref="webtest"
placeholderid="webtest"
updatemode="background" >
<fx:info title="JavaFXTester6_Web" vendor="ZA"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
<fx:permissions elevated="true"/>
</fx:deploy>
</target>
The file system I get after running the build.xml:
The same in my file browser:
I couldn't fin any solutions, everybody mentions the conversion from css to bss, but I tried both (so with Main.class.getResource(style.bss)... too) and no solution. I have unfortunately no more ideas. Can you help? Thank you!
The problem is because of the #CHARSET "UTF-8"; in your css file.
JavaFX cannot parse it and will throw a parse exception.
Remove the CHARSET declaration from the css and try again.
I have the same problem. It all works fine in Eclipse but when I compile and run the jar, the CSS is ignored. Extracting the complied jar shows the CSS file and images in the same folder as the Java class files.
FXML
<stylesheets>
<URL value="#Style.css" />
</stylesheets>
CSS
-fx-background-image: url("background.jpg");
Okay, I figured it out. The CSS file and the image file need to be in the root directory of the jar. In Eclipse the CSS file and image files are in the package with the Java files, but when you compile they need to go in the src folder outside of the package.
You do not need the line;
Java
ap.getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
The FXML file should tell the program where to find the CSS file, and the CSS file tells the program where to find images.

loading jars during splash screen

I have a main application which is referencing to 4-5 external jar files. So while compiling the project netbeans ide(javafx application) takes long time. Therefore I want to design a splash screen and which will be displayed till all jars gets loaded.
My JNLP file is
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="Black.jnlp">
<information>
<title>Black</title>
<vendor>RATTAN</vendor>
<description>Sample JavaFX 2.0 application.</description>
<offline-allowed/>
</information>
<resources>
<jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
</resources>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="Black.jar" size="3393158" download="eager" />
<jar href="lib/commons-io-1.3.2.jar" size="95655" download="eager" />
<jar href="lib/commons-lang-2.0.jar" size="179420" download="eager" />
<jar href="lib/newlink.jar" size="6160" download="eager" />
<jar href="lib/scribe-1.3.0.jar" size="74543" download="eager" />
</resources>
<security>
<all-permissions/>
</security>
<applet-desc width="800" height="600" main-class="com.javafx.main.NoJavaFXFallback" name="Black" >
<param name="requiredFXVersion" value="2.2+"/>
</applet-desc>
<jfx:javafx-desc width="800" height="600" main-class="test.Test" name="Black" />
<update check="always"/>
</jnlp>
Use preloaders module from JavaFx
here is complete tutorial:
http://docs.oracle.com/javafx/2/deployment/preloaders.htm
Good luck,'.

Resources