pondělí 12. září 2016

Run Groovy Project Without Compilation Using Gradle

Run Groovy Project Without Compilation Using Gradle

To be honest it is automatically compiled by Gradle. All changes made into "buildSrc/src/main/groovy" are automatically compiled during startup.

Key feature of Gradle is how nicely it manages "buildSrc" directory.

Here is sample project https://bitbucket.org/bugs_/samples/src/default/RunGroovyProjectWithoutCompilationUsingGradle/

sobota 30. července 2016

Update file inside zip inside zip inside zip. Using Gradle, Groovy, Closure

Easy way to modify content of zip file inside scripts. Using Gradle/Groovy

short example:

dependencies {
classpath 'org.zeroturnaround:zt-zip:1.8'
classpath 'org.apache.commons:commons-io:1.3.2'
}
// ----------------------------
import org.apache.commons.io.FileUtils
import org.zeroturnaround.zip.ZipUtil
/**
*
* Extract zipFile into directory in temp, then call closure and give this directory as parameter to closure
* (closure update this directory), then pack this directory back into ZipFile
* Nice method :) */
private void extractZipAndThenPackItBack(File zipFile, Closure closure) {
def extractedDirectory
try {
//Extract
extractedDirectory = getTempDir()
ZipUtil.unpack(zipFile, extractedDirectory);
//Call closure
closure.call(extractedDirectory)
//Pack result back
zipFile.delete()
ZipUtil.pack(extractedDirectory, zipFile);
} finally {
FileUtils.deleteDirectory(extractedDirectory)
}
}
//Sample usage:
extractZipAndThenPackItBack(zipFile) { File directoryWhereZipWasExtracted ->
//update directory where zip was extracted
}

And here is full sample project: https://bitbucket.org/bugs_/samples/src/default/ZipUpdaterGroovyGradleClosure/

čtvrtek 28. července 2016

Count number bytes in UTF-8 for Java String

https://bitbucket.org/bugs_/utils/src/default/CoreUtils/src/main/java/cz/vondr/coreutils/utf/Utf8LengthUtil.java

  • Problem 1: You have Java String variable. And you need get number of bytes in UTF-8
  • Problem 2: You need split String into multiple Strings, in the way that each of them have exact number of bytes. (expect last part of course :) )

Thanks to stackoverflow.com

úterý 15. března 2016

MXBeans ovládání z command line

MX Beany jsem vždy ovládal pomoci JConsole. To ale nejde bez grafického prostředí

Tady je jeden ze způsobů, jak něco spustit z command line
http://wiki.cyclopsgroup.org/jmxterm/download.html

stáhnout jmxterm-1.0-alpha-4-uber.jar

java.exe -jar jmxterm-1.0-alpha-4-uber.jar    (potřebuje to JDK ne jen JRE)

prikaz "jvms"
  (vylistuje jvm procesy)

prikaz "open "
  (se pripoji k procesu)

prikaz "run -d MyApp -b MyApp:name=MyBean nameOfMethod"
  (se spustí danou metodu na dane beane)