RSS
 

Archive for November, 2009

IvyDE

30 Nov

What is IvyDE?

According to the website:

IvyDE lets you manage your dependencies declared in an ivy.xml in your Java Eclipse projects. IvyDE will contribute to the classpath of your Java project, with the classpath container. It also bring an editor of ivy.xml files, with completion.

Installation

  • The IvyDE update site for eclipse: http://www.apache.org/dist/ant/ivyde/updatesite
  • Integrate with eclipse’s ant: add $ECLIPSE_HOME/plugins/org.apache.ivy_2.X.X.XXXXXXXXX.jar in to “Global Entries” below

 
 

Apache Ivy

27 Nov

Install Ivy

wget http://apache.ntu.edu.tw/ant/ivy/2.1.0/apache-ivy-2.1.0-bin.tar.gz
tar zxvf apache-ivy-2.1.0-bin.tar.gz
cd apache-ivy-2.1.0
sudo cp ivy-2.1.0.jar /usr/share/ant/lib
cd src/example/hello-ivy
ant -verbose

Example ivy.xml

<ivy version="2.0">
 <info organisation="mistasy" module="IvyDemo" />
 <dependencies>
  <dependency org="org.slf4j" name="slf4j-api" rev="1.5.8" />
  <dependency org="ch.qos.logback" name="logback-core" rev="0.9.17" />
  <dependency org="ch.qos.logback" name="logback-classic" rev="0.9.17" />
 </dependencies>
</ivy-module>

Ivy mapping to Maven

  • groudId=>org
  • artifactId=>name
  • version=>rev
<dependency>
 <groupId>ch.qos.logback</groupId>
 <artifactId>logback-classic</artifactId>
 <version>0.9.17</version>
</dependency>

Ivy with eclipse

see: IvyDE

Using sun’s java.net maven repository

see: this article

Introduction

Terminology

  • organisation – like “org.apache“, “ibm“, etc.
  • module – chain of revisions each has a descriptor(ivy.xml) and one or more artifacts.
  • artifact – like “ant-1.7.0-bin.zip“, “apache-ant-1.7.0-src.tar.gz“, etc.
  • type(of an artifact) – like “jar“, “bin“, “source“, etc.
  • extension – like “.jar“, etc.
  • revision – revision of module(not source).
  • status(of a revision) – like “integration“, “milestone” and “release“.
  • configuration(of a module) – distinct dependency-sets.

Patterns

It includes: [organisation] , [module] , [branch] , [revision] , [artifact] , [type] , [ext](extension), [conf](configuration) , [originalname].

About pattern of retrieve task

Here is a very clear explanation:

Ivy files do not define any such concept as “filename”.

Instead, they define artifacts. Artifacts have the following attributes:

  • Module organisation
  • Module name
  • Module revision
  • Artifact name
  • Artifact type
  • Artifact extension

The only thing guaranteed to be unique for an artifact is the combination of all of the above attributes (and that guarantee only applies within a single repository).

 
 

天機不可洩漏 – java read password

25 Nov

under java 1.5

click here

java 1.6

package idv.mistasy.test;

import java.io.Console;
import java.util.Scanner;

public class ConsoleTest {
	public static void main(String[] args) {
		Console console;
		char[] passwd;
		if (System.console() != null) {
			console = System.console();
			if (console.readPassword() != null) {
				passwd = console.readPassword();
				System.out.println(passwd);
			}
		} else {
			System.out.println("This console sucks");
		}
	}
}
 
 

Jline

25 Nov

Website: http://jline.sourceforge.net/downloads.html

Sourceforge: http://sourceforge.net/projects/jline/

Note: please download jline-0.9.4!

package idv.mistasy.example;

import jline.ConsoleReader;
import jline.Terminal;
import jline.UnixTerminal;

public class JlineDemo {
	public static String readPassword(String prompt) {
		try {
			Terminal t = Terminal.getTerminal();
			if (t instanceof jline.UnixTerminal) {
				UnixTerminal ut = (UnixTerminal) t;
				ConsoleReader reader = new ConsoleReader();
//				ConsoleReaderInputStream cris =
//					new ConsoleReaderInputStream(reader);

				Character mask = new Character((char) 0);
//				reader.setEchoCharacter(new Character('0'));
				String line = null;
				do {
					line = reader.readLine(prompt, mask);
					if (line != null) {
//						reader.setEchoCharacter(null);
						reader.flushConsole();
						ut.restoreTerminal();
						return line;
					}
				} while (line != null && line.length() > 0);
			}
		} catch (Exception e) {
		}
		return null;
	}
}