Source libs for requirred tools added

git-svn-id: https://svn.libreccm.org/ccm/trunk@102 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2009-03-15 15:52:37 +00:00
parent 23644633b6
commit b7f6c31891
6 changed files with 741 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<project basedir="." name="Makefile-Gateway" default="build">
<property name="libdir" value="../lib"/>
<property name="instdir" value="/usr/share/ccm-devel/classes"/>
<target name="build">
<mkdir dir="build"/>
<javac srcdir="."
destdir="build">
<classpath>
<fileset dir="${libdir}">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="deploy" depends="build">
<copy todir="${instdir}">
<fileset dir="build">
<include name="**"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="build"/>
</target>
</project>

View File

@ -0,0 +1,201 @@
/*
* Copyright (C) 2001 ArsDigita Corporation. All Rights Reserved.
*
* The contents of this file are subject to the ArsDigita Public
* License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of
* the License at http://www.arsdigita.com/ADPL.txt
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*/
package com.redhat.ccm.config;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.oro.text.perl.Perl5Util;
import org.apache.oro.text.regex.MatchResult;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Matcher;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.PatternMatcherInput;
import org.apache.oro.text.regex.Substitution;
import org.apache.oro.text.regex.Util;
import org.apache.oro.text.regex.MalformedPatternException;
public class ConfigHelper {
public static void loadVariables(BufferedReader in,
Map vars)
throws IOException {
Perl5Util perl5 = new Perl5Util();
String line;
int number = 0;
while ((line = in.readLine()) != null) {
number++;
if (perl5.match("/^\\s*$/", line) ||
perl5.match("/^\\s*#/", line)) {
continue;
} else if (perl5.match("/\\s*((?:\\w|-)+)\\s*=\\s*(.*?)\\s*$/", line)) {
MatchResult result = perl5.getMatch();
String key = result.group(1);
String value = result.group(2);
vars.put(key, value);
} else {
throw new RuntimeException("syntax error in config file at " +
"line " + line);
}
}
}
public static String extractVariables(BufferedReader in,
Map vars)
throws IOException {
String firstLine = "";
Perl5Util perl5 = new Perl5Util();
String line;
int number = 0;
while ((line = in.readLine()) != null) {
if (perl5.match("/^\\s*\\/\\/\\s*::((?:\\w|-)+)::\\s*->\\s*(.*?)\\s*$/",
line)) {
MatchResult result = perl5.getMatch();
String key = result.group(1);
String value = result.group(2);
if (!vars.containsKey(key)) {
vars.put(key, value);
}
} else if (perl5.match("/^\\s*\\/\\/\\s*(.*?)\\s*$/",
line) && number == 0) {
MatchResult result = perl5.getMatch();
firstLine = result.group(1);
}
number++;
}
return (firstLine);
}
public static String interpolate(String text,
Map vars) {
HashSubstitution subst = new HashSubstitution(vars);
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
StringBuffer result = new StringBuffer();
PatternMatcherInput input = new PatternMatcherInput(text);
try {
Util.substitute(result,
matcher,
compiler.compile("(::(?:\\w|-)+::)"),
subst,
input,
Util.SUBSTITUTE_ALL);
} catch (MalformedPatternException e) {
e.printStackTrace();
throw new RuntimeException("cannot perform substitution: " +
e.getMessage());
}
return result.toString();
}
public static void loadVariablesFromString(String in, Map vars) {
Perl5Util perl5 = new Perl5Util();
ArrayList arraylist = new ArrayList();
if (in != null) {
perl5.split(arraylist, "/,/", in);
Iterator iter = arraylist.iterator();
while (iter.hasNext()) {
String key = (String)iter.next();
if (!iter.hasNext()) {
throw new RuntimeException("mismatched number of " +
"elements in: " + in);
}
String value = (String)iter.next();
vars.put(key, value);
}
}
}
public static void interpolateVars(Map vars1, Map vars2) {
Iterator keys = vars1.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
vars1.put(key, interpolate((String)vars1.get(key), vars2));
}
}
public static void interpolateVars(Map[] vars1, Map[] vars2) {
Map combined = new TreeMap();
for (int i = 0; i < vars2.length; i++) {
combined.putAll(vars2[i]);
}
for (int i = 0; i < vars1.length; i++) {
Iterator keys = vars1[i].keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
vars1[i].put(key, interpolate((String)vars1[i].get(key), combined));
}
}
}
private static class HashSubstitution implements Substitution {
private Map m_hash;
public HashSubstitution(Map hash) {
m_hash = hash;
}
public void appendSubstitution(StringBuffer appendBuffer,
MatchResult match,
int substitutionCount,
PatternMatcherInput originalInput,
PatternMatcher matcher,
Pattern pattern) {
String placeholder = match.toString();
String key = placeholder.substring(2, placeholder.length()-2);
Object value = (m_hash.containsKey(key) ?
m_hash.get(key) :
placeholder);
String val;
try {
PlaceholderValueGenerator gen = (PlaceholderValueGenerator)value;
val = gen.generate();
} catch (ClassCastException ex) {
val = (String)value;
}
appendBuffer.append(val);
}
}
public interface PlaceholderValueGenerator {
public String generate();
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2001 ArsDigita Corporation. All Rights Reserved.
*
* The contents of this file are subject to the ArsDigita Public
* License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of
* the License at http://www.arsdigita.com/ADPL.txt
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*/
package com.redhat.ccm.config;
import java.util.TreeMap;
import java.util.Iterator;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class IntegrateConfig {
public static void main(String args[]) {
try {
BufferedReader conf = new BufferedReader(new FileReader(args[0]));
TreeMap vars = new TreeMap();
ConfigHelper.loadVariables(conf, vars);
conf.close();
for (int i = 2 ; i < args.length ; i++) {
BufferedReader in = new BufferedReader(new FileReader(args[i]));
ConfigHelper.extractVariables(in, vars);
in.close();
}
BufferedWriter out = new BufferedWriter(new FileWriter(args[1]));
printVariables(out, vars);
out.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
public static void printVariables(BufferedWriter out,
TreeMap vars)
throws IOException {
Iterator keys = vars.keySet().iterator();
while (keys.hasNext()) {
String key = (String)keys.next();
String value = (String)vars.get(key);
String line = key + " = " + value;
out.write(line, 0, line.length());
out.newLine();
}
}
}

View File

@ -0,0 +1,102 @@
/*
* Copyright (C) 2001 ArsDigita Corporation. All Rights Reserved.
*
* The contents of this file are subject to the ArsDigita Public
* License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of
* the License at http://www.arsdigita.com/ADPL.txt
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*/
package com.redhat.ccm.config;
import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeMap;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class MakeConfig {
public static void main(String args[]) {
try {
TreeMap vars[] = new TreeMap[args.length];
String labels[] = new String[args.length];
for (int i = 1 ; i < args.length ; i++) {
BufferedReader in = new BufferedReader(new FileReader(args[i]));
TreeMap theseVars = new TreeMap();
labels[i - 1] = ConfigHelper.extractVariables(in, theseVars);
vars[i - 1] = theseVars;
in.close();
}
String projectVars = System.getProperty("projectVars");
TreeMap theseVars = new TreeMap();
ConfigHelper.loadVariablesFromString(projectVars,theseVars);
labels[args.length - 1] = "System Properties";
vars[args.length - 1] = theseVars;
ConfigHelper.interpolateVars(vars, vars);
BufferedWriter out = new BufferedWriter(new FileWriter(args[0]));
printVariables(out, vars, labels);
out.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
public static void printVariables(BufferedWriter out,
TreeMap[] vars,
String[] labels)
throws IOException {
HashSet allvars = new HashSet();
String text = "";
for (int i = vars.length - 1; i >= 0; i--) {
StringBuffer sb = new StringBuffer();
if (labels[i] != null && vars[i].size() > 0) {
sb.append("# " + labels[i] + System.getProperty("line.separator"));
}
Iterator keys = vars[i].keySet().iterator();
while (keys.hasNext()) {
String key = (String)keys.next();
if (! allvars.contains(key)) {
allvars.add(key);
String value = (String)vars[i].get(key);
String line = key + " = " + value;
sb.append(line + System.getProperty("line.separator"));
}
}
if (vars[i].size() > 0) {
sb.append(System.getProperty("line.separator"));
}
text = sb + text;
}
out.write(text, 0, text.length());
}
}

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) 2001 ArsDigita Corporation. All Rights Reserved.
*
* The contents of this file are subject to the ArsDigita Public
* License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of
* the License at http://www.arsdigita.com/ADPL.txt
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*/
package com.redhat.ccm.config;
import java.util.TreeMap;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class MakeInit {
public static void main(String args[]) {
try {
BufferedReader conf = new BufferedReader(new FileReader(args[0]));
TreeMap vars = new TreeMap();
ConfigHelper.loadVariables(conf, vars);
conf.close();
BufferedWriter out1 = new BufferedWriter(new FileWriter(args[1]));
BufferedWriter out2 = new BufferedWriter(new FileWriter(args[2]));
for (int i = 3 ; i < args.length ; i++) {
BufferedReader in = new BufferedReader(new FileReader(args[i]));
interpolate(in, out1, out2, vars);
in.close();
}
out1.close();
out2.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
public static void interpolate(BufferedReader in,
BufferedWriter out1,
BufferedWriter out2,
TreeMap vars)
throws IOException {
String line;
while ((line = in.readLine()) != null) {
String result = line.startsWith("//") ?
line :
ConfigHelper.interpolate(line, vars);
out1.write(result, 0, result.length());
out1.newLine();
out2.write(line, 0, line.length());
out2.newLine();
}
}
}

View File

@ -0,0 +1,255 @@
package com.redhat.ccm.tools.ant.taskdefs;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.FileScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.ExecuteJava;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.ant.util.IdentityMapper;
import org.apache.tools.ant.util.SourceFileScanner;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
/**
* JDO enhancement task.
*
* @author Dennis Gregorovic <a href="mailto:dgregor@redhat.com">dgregor@redhat.com</a>
*/
public class JDOEnhance extends MatchingTask {
private CommandlineJava m_cmdline = new CommandlineJava();
private File m_destination = null;
private File[] m_enhanceList = new File[0];
private Mapper m_mapperElement = null;
private Path m_source = null;
//private Path m_classes = null;
private Path m_jdo = null;
private Vector m_classes = new Vector();
private final static String DEFAULT_CLASSNAME = "com.sun.jdori.enhancer.Main";
public JDOEnhance() {
m_cmdline.setClassname(DEFAULT_CLASSNAME);
}
public File getDestination() {
return m_destination;
}
public Path getSource() {
return m_source;
}
public void setClasspath(Path s) {
createClasspath().append(s);
}
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}
public Path createClasspath() {
return m_cmdline.createClasspath(project).createPath();
}
/**
* The name of the class that does the enhancement
*/
public void setClassname(String classname) {
m_cmdline.setClassname(classname);
}
/**
* The directory that the enhanced class files will be written to.
*/
public void setDestination(File destination) {
m_destination = destination;
}
/**
* The source path for jdo and class files
*/
public void setSource(Path source) {
//m_source = source;
}
public Path createSrcpath() {
if (m_source == null) {
m_source = new Path(project);
}
return m_source.createPath();
}
public void addDirset(DirSet set) {
m_classes.addElement(set);
}
//public Path createClasses() {
// if (m_classes == null) {
// m_classes = new Path(project);
// }
// return m_classes.createPath();
//}
public Path createJdo() {
if (m_jdo == null) {
m_jdo = new Path(project);
}
return m_jdo.createPath();
}
/**
* Defines the mapper to map source to destination files.
*/
public Mapper createMapper() throws BuildException {
if (m_mapperElement != null) {
throw new BuildException("Cannot define more than one mapper",
location);
}
m_mapperElement = new Mapper(project);
return m_mapperElement;
}
public void execute() throws BuildException {
log("running jdoenhance target", Project.MSG_VERBOSE);
// compare source files with target directory to figure out which files
// need to be enhanced
for (int i = 0; i < m_classes.size(); i++) {
DirSet dirset = (DirSet) m_classes.elementAt(i);
File fromDir = dirset.getDir(project);
DirectoryScanner ds = dirset.getDirectoryScanner(project);
String[] srcDirs = ds.getIncludedDirectories();
log(fromDir.toString(), Project.MSG_VERBOSE);
for (int j = 0; j < srcDirs.length; j++) {
log(srcDirs[j].toString(), Project.MSG_VERBOSE);
}
log(m_destination.toString(), Project.MSG_VERBOSE);
scanDir(fromDir, m_destination, srcDirs);
}
if (m_enhanceList.length > 0) {
log("Enhancing " + m_enhanceList.length +
" class file"
+ (m_enhanceList.length == 1 ? "" : "s"));
Path newPath = new Path(project);
newPath.addExisting(m_source);
m_cmdline.createArgument().setValue("-s");
m_cmdline.createArgument().setValue(newPath.toString());
m_cmdline.createArgument().setValue("-d");
m_cmdline.createArgument().setValue(getDestination().getAbsolutePath());
for (int i = 0; i < m_enhanceList.length; i++) {
String arg = m_enhanceList[i].getAbsolutePath();
m_cmdline.createArgument().setValue(arg);
}
String[] jdo_list = m_jdo.list();
String[] includes = { "**/*.jdo" };
for (int i = 0; i < jdo_list.length; i++) {
File jdoDir = project.resolveFile(jdo_list[i]);
DirectoryScanner ds = getDirectoryScanner(jdoDir);
ds.setIncludes(includes);
ds.scan();
String[] jdo_files = ds.getIncludedFiles();
for (int j = 0; j < jdo_files.length; j++) {
File arg = new File(ds.getBasedir(), jdo_files[j]);
m_cmdline.createArgument().setValue(arg.getAbsolutePath());
}
}
log(m_cmdline.describeCommand(), Project.MSG_VERBOSE);
run(m_cmdline.getCommandline());
}
}
/**
* Scans the directory looking for class files to be enhanced.
*/
protected void scanDir(File srcDir, File destDir, String[] dirs) {
log(srcDir.toString(), Project.MSG_VERBOSE);
log(destDir.toString(), Project.MSG_VERBOSE);
FileNameMapper mapper = null;
if (m_mapperElement != null) {
mapper = m_mapperElement.getImplementation();
} else {
mapper = new IdentityMapper();
}
FilenameFilter classFileFilter = new FilenameFilter() {
public boolean accept( File dir, String name ) {
if ( name.endsWith(".class") &&
name.indexOf("$") == -1 ) {
return true;
}
return false;
}
};
SourceFileScanner sfs = new SourceFileScanner(this);
for (int i = 0; i < dirs.length; i++) {
File dir = new File(srcDir, dirs[i]);
log(dir.toString(), Project.MSG_VERBOSE);
String[] files = dir.list(classFileFilter);
for (int j = 0; j < files.length; j++) {
files[j] = (new File(dirs[i], files[j])).toString();
}
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, mapper);
if (newFiles.length > 0) {
File[] newEnhanceList = new File[m_enhanceList.length + newFiles.length];
System.arraycopy(m_enhanceList, 0,
newEnhanceList, 0,
m_enhanceList.length);
System.arraycopy(newFiles, 0,
newEnhanceList, m_enhanceList.length,
newFiles.length);
m_enhanceList = newEnhanceList;
}
}
}
private void run(CommandlineJava command) throws BuildException {
Path newPath = new Path(project);
newPath.addExisting(command.getClasspath());
ExecuteJava exe = new ExecuteJava();
exe.setJavaCommand(command.getJavaCommand());
exe.setClasspath(newPath);
exe.setSystemProperties(command.getSystemProperties());
exe.execute(project);
}
/**
* Executes the given classname with the given arguments in a separate VM.
*/
private int run(String[] command) throws BuildException {
Execute exe = null;
exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
Project.MSG_WARN));
exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(command);
try {
int rc = exe.execute();
if (exe.killedProcess()) {
log("Timeout: killed the sub-process", Project.MSG_WARN);
}
return rc;
} catch (IOException e) {
throw new BuildException(e, location);
}
}
}