Wednesday, March 13, 2013
Jenkins CLI commands
Jenkins CLI commands
- build: Builds a job, and optionally waits until its completion.
- cancel-quiet-down: Cancel the effect of the "quiet-down" command.
- clear-queue: Clears the build queue
- connect-node: Reconnect to a node
- copy-job: Copies a job.
- create-job: Creates a new job by reading stdin as a configuration XML file.
- delete-builds: Deletes build record(s).
- delete-job: Deletes a job
- delete-node: Deletes a node
- disable-job: Disables a job
- disconnect-node: Disconnects from a node
- enable-job: Enables a job
- get-job: Dumps the job definition XML to stdout
- groovy: Executes the specified Groovy script.
- groovysh: Runs an interactive groovy shell.
- help: Lists all the available commands.
- install-plugin: Installs a plugin either from a file, an URL, or from update center.
- install-tool: Performs automatic tool installation, and print its location to stdout. Can be only called from
inside a build. - keep-build: Mark the build to keep the build forever.
- list-changes: Dumps the changelog for the specified build(s).
- login: Saves the current credential to allow future commands to run without explicit credential information.
- logout: Deletes the credential stored with the login command.
- mail: Reads stdin and sends that out as an e-mail.
- offline-node: Stop using a node for performing builds temporarily, until the next "online-node" command.
- online-node: Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
- quiet-down: Quiet down Jenkins, in preparation for a restart. Don't start any builds.
- reload-configuration: Discard all the loaded data in memory and reload everything from file system. Useful when
you modified config files directly on disk. - restart: Restart Jenkins
- safe-restart: Safely restart Jenkins
- safe-shutdown: Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down
Jenkins. - set-build-description: Sets the description of a build.
- set-build-display-name: Sets the displayName of a build
- set-build-result: Sets the result of the current build. Works only if invoked from within a build.
- shutdown: Immediately shuts down Jenkins server
- update-job: Updates the job definition XML from stdin. The opposite of the get-job command
- version: Outputs the current version.
- wait-node-offline: Wait for a node to become offline
- wait-node-online: Wait for a node to become online
- who-am-i: Reports your credential and permissions
--
Thank you.
Regards,
Kaleeswaran.S
Monday, March 11, 2013
XMLPropertyListConfiguration / Plist Parser example
XMLPropertyListConfiguration / Plist Parser example
XMLPropertyListConfiguration is having a fantastic API to work with plist files. But there is no much example for this library. After some googling and library analysis, it came to know that it is very very easy to parse the files !. Here is the example.
@Test
public void test() {
try {
String plistFile = "/Users/plistFile/info.plist";
XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
HashMap life = new HashMap();
life.put("Home", "home.png");
life.put("Office", "browse.png");
life.put("School", "mycart.png");
life.put("College", "offers.png");
plist.addProperty("Life", life);
HashMap phones = new HashMap();
phones.put("Nokia", "8000");
phones.put("Samsung", "4000");
List<String> imagesArray = new ArrayList<String>();
imagesArray.add("icon1.png");
imagesArray.add("icon2.png");
imagesArray.add("icon3.png");
phones.put("PhoneIcons", imagesArray);
plist.addProperty("Phones", phones);
List<String> imagesArray1 = new ArrayList<String>();
imagesArray1.add("icon1.png");
imagesArray1.add("icon2.png");
imagesArray1.add("icon3.png");
Map dashBoard = new HashMap();
dashBoard.put("imgArray", imagesArray1);
plist.addProperty("ImageArrayBoard", dashBoard);
plist.addProperty("ImageArray.innnerLevelTag", "IamInnerLevelTag");
plist.save(plistFile);
System.out.println("File saved .... ");
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
}
Thats All, Happy Coding :)
Ref : http://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.html
Wednesday, January 23, 2013
How to print base64 image in jasper report pdf ?
How to print base64 image in jasper report pdf ?
1) import base64 class in jrxml file <import value="org.apache.commons.codec.binary.Base64"/>
2) Create two parameters logo and base64Img in jasper report.
3) logo parameter class as String (java.lang.String) and
4) base64Img parameter class as InputStream (java.io.InputStream) and
5) base64Img parameter Default Value expression should be like "new ByteArrayInputStream(new Base64().decodeBase64($P{logo}.getBytes("UTF-8")))"
Thats all..
Note :
parameter class - specifies the type of that parameter
Default Value expression - just like method. we can write our implementation here.
@Test
public void base64ImageAsStream() {
try {
compileReports();
System.out.println("report ");
String outFileNamePDF = "/Users/user/Tried/POC/imageStreamToPdf/base64ImageStream.pdf";
new File(outFileNamePDF).getParentFile().mkdirs();
String containerJrxmlFile = "/Users/user/Tried/POC/imageStreamToPdf/imageToStreamPdf.jrxml";
Map<String, Object> parameters = new HashMap<String,Object>();
File img = new File("/Users/user/Desktop/wallpaper.jpg");
InputStream fis = new FileInputStream(img);
byte[] imgByte = null;
imgByte = IOUtils.toByteArray(fis);
byte[] encodedImage = Base64.encodeBase64(imgByte);
String encodeImg = new String(encodedImage);
System.out.println("printnng");
parameters.put("logo", encodeImg);
InputStream reportStream = new FileInputStream(containerJrxmlFile);
BufferedInputStream bufferedInputStream = new BufferedInputStream(reportStream);
JasperDesign jasperDesign = JRXmlLoader.load(bufferedInputStream);
// JasperReport jasperReport = (JasperReport) JRLoader.loadObject("/Users/user/Tried/POC/imageStreamToPdf/imageToStreamPdf.jasper");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.exportReport();
System.out.println("pdf report created .... ");
} catch (Exception e) {
e.printStackTrace();
}
}
Enjoy the coding !!!
--
Thank you.
Regards,
Kaleeswaran.S
How to apply dynamic colors to jasper report ?
How to apply dynamic colors to jasper report ?
After some googling, i found the way to apply colors dynamically to jasper report.
My working code is,
We can access all the jasper files styles and everything with the help of JasperDesign class.
Just create some styles like header, body and footer and set colors for those style from java file.
The code "styleList[j].setBackcolor(userBackGRDColor);" - sets the back groud color of a style
@Test
public void dynamicColorPdf() {
try {
System.out.println("pdf report creation started .... ");
String outFileNamePDF = "/Users/user/Tried/POC/imageStreamToPdf/dynamicColorPdf.pdf";
new File(outFileNamePDF).getParentFile().mkdirs();
String containerJrxmlFile = "/Users/user/Tried/POC/imageStreamToPdf/dynamicColorPdf.jrxml";
Map<String, Object> parameters = new HashMap<String,Object>();
InputStream reportStream = new FileInputStream(containerJrxmlFile);
BufferedInputStream bufferedInputStream = new BufferedInputStream(reportStream);
JasperDesign jasperDesign = JRXmlLoader.load(bufferedInputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
// applying styles
java.awt.Color userForeColor = new java.awt.Color(255, 69, 0);
java.awt.Color userBackGRDColor = new java.awt.Color(255, 0, 0);
JRStyle[] styleList = jasperPrint.getStyles();
System.out.println("styleList.length => " + styleList.length);
for (int j = 0; j < styleList.length; j++) {
System.out.println("styleList[j].getName() => " + styleList[j].getName());
if (styleList[j].getName().equals("style1")) {
styleList[j].setBackcolor(userBackGRDColor);
styleList[j].setForecolor(userForeColor);
jasperPrint.addStyle(styleList[j], true);
} else if (styleList[j].getName().equals("style2")) {
styleList[j].setBackcolor(userBackGRDColor);
styleList[j].setForecolor(userForeColor);
jasperPrint.addStyle(styleList[j], true);
}
}
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.exportReport();
System.out.println("pdf report created .... ");
} catch (Exception e) {
e.printStackTrace();
}
}
Happy coding :)
--
Thank you.
Regards,
Kaleeswaran.S
After some googling, i found the way to apply colors dynamically to jasper report.
My working code is,
We can access all the jasper files styles and everything with the help of JasperDesign class.
Just create some styles like header, body and footer and set colors for those style from java file.
The code "styleList[j].setBackcolor(userBackGRDColor);" - sets the back groud color of a style
@Test
public void dynamicColorPdf() {
try {
System.out.println("pdf report creation started .... ");
String outFileNamePDF = "/Users/user/Tried/POC/imageStreamToPdf/dynamicColorPdf.pdf";
new File(outFileNamePDF).getParentFile().mkdirs();
String containerJrxmlFile = "/Users/user/Tried/POC/imageStreamToPdf/dynamicColorPdf.jrxml";
Map<String, Object> parameters = new HashMap<String,Object>();
InputStream reportStream = new FileInputStream(containerJrxmlFile);
BufferedInputStream bufferedInputStream = new BufferedInputStream(reportStream);
JasperDesign jasperDesign = JRXmlLoader.load(bufferedInputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
// applying styles
java.awt.Color userForeColor = new java.awt.Color(255, 69, 0);
java.awt.Color userBackGRDColor = new java.awt.Color(255, 0, 0);
JRStyle[] styleList = jasperPrint.getStyles();
System.out.println("styleList.length => " + styleList.length);
for (int j = 0; j < styleList.length; j++) {
System.out.println("styleList[j].getName() => " + styleList[j].getName());
if (styleList[j].getName().equals("style1")) {
styleList[j].setBackcolor(userBackGRDColor);
styleList[j].setForecolor(userForeColor);
jasperPrint.addStyle(styleList[j], true);
} else if (styleList[j].getName().equals("style2")) {
styleList[j].setBackcolor(userBackGRDColor);
styleList[j].setForecolor(userForeColor);
jasperPrint.addStyle(styleList[j], true);
}
}
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.exportReport();
System.out.println("pdf report created .... ");
} catch (Exception e) {
e.printStackTrace();
}
}
Happy coding :)
--
Thank you.
Regards,
Kaleeswaran.S
How to image stream to jasper report ?
How to image stream to jasper report ?
It is very easy to pass image stream to jasper report pdf.
Steps are,
1) Convert the image to stream and set it in parameter ("logo")
2) In jrxml file , create a parameter with parameter class as "java.io.InputStream"
3) Place a image on the jrxml design, set "Image Expression" to $P{logo} and "Expression class" to java.lang.String
@Test
public void createPdfWithImageAsStream() {
try {
System.out.println("pdf report creation started .... ");
String outFileNamePDF = "/Users/user/Tried/POC/imageStreamToPdf/createPdfWithImageAsStream.pdf";
new File(outFileNamePDF).getParentFile().mkdirs();
String containerJrxmlFile = "/Users/user/Tried/POC/imageStreamToPdf/createPdfWithImageAsStream.jrxml";
// pass logo as stream.
Map<String, Object> parameters = new HashMap<String,Object>();
File img = new File("/Users/user/Desktop/wallpaper.jpg");
InputStream fis = new FileInputStream(img);
System.out.println("printnng");
parameters.put("logo", fis);
InputStream reportStream = new FileInputStream(containerJrxmlFile);
BufferedInputStream bufferedInputStream = new BufferedInputStream(reportStream);
JasperDesign jasperDesign = JRXmlLoader.load(bufferedInputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.exportReport();
System.out.println("pdf report created .... ");
} catch (Exception e) {
e.printStackTrace();
}
}
Happy coding :)
--
Thank you.
Regards,
Kaleeswaran.S
It is very easy to pass image stream to jasper report pdf.
Steps are,
1) Convert the image to stream and set it in parameter ("logo")
2) In jrxml file , create a parameter with parameter class as "java.io.InputStream"
3) Place a image on the jrxml design, set "Image Expression" to $P{logo} and "Expression class" to java.lang.String
@Test
public void createPdfWithImageAsStream() {
try {
System.out.println("pdf report creation started .... ");
String outFileNamePDF = "/Users/user/Tried/POC/imageStreamToPdf/createPdfWithImageAsStream.pdf";
new File(outFileNamePDF).getParentFile().mkdirs();
String containerJrxmlFile = "/Users/user/Tried/POC/imageStreamToPdf/createPdfWithImageAsStream.jrxml";
// pass logo as stream.
Map<String, Object> parameters = new HashMap<String,Object>();
File img = new File("/Users/user/Desktop/wallpaper.jpg");
InputStream fis = new FileInputStream(img);
System.out.println("printnng");
parameters.put("logo", fis);
InputStream reportStream = new FileInputStream(containerJrxmlFile);
BufferedInputStream bufferedInputStream = new BufferedInputStream(reportStream);
JasperDesign jasperDesign = JRXmlLoader.load(bufferedInputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.exportReport();
System.out.println("pdf report created .... ");
} catch (Exception e) {
e.printStackTrace();
}
}
Happy coding :)
--
Thank you.
Regards,
Kaleeswaran.S
Subscribe to:
Posts (Atom)