/* * Geotools2 - OpenSource mapping toolkit http://geotools.org (C) 2003, Geotools * Project Managment Committee (PMC) * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintStream; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; /** * Quick utility that will update you Eclipse .project and .classpath file to * reflect the last build. *
* This utility will process buildReport.txt
to determine the
* build order (and to ensure that you actually try building with maven first).
*
* For each project in buildReport.txt
:
*
src
will be added as a folder compiling to
* target/classes
tests
will be added as a folder compiling to
* target/test_classes
*
* maven build
* gt2eclipse .
*
*
* * If you are running this from eclipse remember to hit refresh afterwords. *
* * @author jgarnett, Refractions Reasearch Inc. * @version CVS Version */ public class GT2Eclipse { static String buildlist; /** * List of tagets based on ext */ public static Set ext(String path) { Set set = new TreeSet(); File ext = new File(path, "ext"); String dir[] = ext.list(); String src; for (int i = 0; i < dir.length; i++) { src = dir[i]; if (src.equals("CVS") || src.equals(".svn")) continue; if (!set.contains(src)) { System.out.println("target " + src + " was not built by maven"); } System.out.println("ext " + src + " not built by maven"); set.add(src); } return set; } /** * List of targets based on plugin */ public static Set plugin(String path) { Set set = new TreeSet(); File plugin = new File(path, "plugin"); String dir[] = plugin.list(); String src; for (int i = 0; i < dir.length; i++) { src = dir[i]; if (src.equals("CVS")||src.equals(".svn")) continue; if (!set.contains(src)) { System.out.println("target " + src + " was not built by maven"); } System.out.println("plugin " + src + " not built by maven"); set.add(src); } return set; } public static void generatebuildlist(String path ) { try { buildlist="buildlist.txt"; BufferedWriter out = new BufferedWriter(new FileWriter(new File(path, buildlist))); out.write("This file is used for building an eclipse .classpath file\n"); FileFilter filter = new FileFilter() { public boolean accept(File pathname) { if (!pathname.isDirectory()) return false; return new File( pathname, "project.xml" ).exists() && new File( pathname, "src" ).exists(); } }; File module = new File(path, "module"); File plugin = new File(path, "plugin"); File ext = new File(path, "ext"); File[] list = module.listFiles( filter ); for (int i = 0; i < list.length; i++) { out.write("gt2:" + list[i].getName() + " \n"); } list = plugin.listFiles( filter ); for (int i = 0; i < list.length; i++) { out.write("gt2:" + list[i].getName() + " \n"); } list = ext.listFiles( filter ); for (int i = 0; i < list.length; i++) { out.write("gt2:" + list[i].getName() + " \n"); } out.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } /** * List of targets build by the lastmaven build
command
* * These targets will be turned into nice little src and tests entries in * your .classpath file. *
*/ public static Set targets(String path) { try { BufferedReader buildReport; if (buildlist == null) { buildReport = new BufferedReader(new FileReader(new File(path, "buildReport.txt"))); } else { buildReport = new BufferedReader(new FileReader(new File(path, buildlist))); } Set set = new TreeSet(); buildReport.readLine(); // skip first line String line; while ((line = buildReport.readLine()) != null) { line = line.substring(line.indexOf(':') + 1); line = line.substring(0, line.indexOf(' ')); // a few corrections if (line.equals("oracle-spatial")) line = "oraclespatial"; if (line.equals("java2drendering")) line = "Java2DRendering"; if (line.equals("wmsserver")) continue; System.out.println("target " + line); set.add(line); } File module = new File(path, "module"); String dir[] = module.list(); String src; for (int i = 0; i < dir.length; i++) { src = dir[i]; if (src.equals("CVS")||src.equals(".svn")) continue; if (!set.contains(src)) { System.out.println("target " + src + " was not built by maven"); continue; } System.out.println("target arc not build by maven"); set.add(src); } // a few corrections // set.add("postgis"); set.add("j2se-demos"); return set; } catch (FileNotFoundException e) { e.printStackTrace(); System.err .println("Please run maven.build from your gt directory." + "This will generate the file buildReports.txt required"); return null; } catch (IOException e) { e.printStackTrace(); System.err .println("Problem understanding the file buildReports.txt"); return null; } } /** * Run through the repository and depending on everything. ** This is *not* very sophisticated, we could run through all the * project.xml files instead. This technique does work it just is not * pretty. *
* * @param path * @param targets * @return */ static public Set dependencies(String path, Set targets) { Set depends = new TreeSet(); // grab everything in the repository File repository = new File(System.getProperty("user.home") + "/.maven/repository"); System.out.println("Repository " + repository + " -- " + repository.exists()); String content[] = repository.list(); if (content != null) { for (int i = 0; i < content.length; i++) { System.out.println("processing " + content[i] + "..."); if ("gt2".equals(content[i])) { System.out.println(" skipping geotools build results"); continue; } File dir = new File(repository, content[i] + "/jars"); String jars[] = dir.list(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.indexOf("-2.0-B") != -1) return false; if (name.endsWith(".md5")) return false; return true; } }); Map map = new HashMap(); for (int j = 0; j < jars.length; j++) { String jar = jars[j]; int split = jar.lastIndexOf('-'); if (split == -1) { System.out.println(" added " + jars[j]); depends.add(content[i] + "/jars/" + jar); continue; } String id = jar.substring(0, split); String version = jar.substring(split + 1, jar.length() - 4); System.out.println("version: " + version + " jar:" + id); if (map.containsKey(id)) { // take the latest version String v = (String) map.get(id); System.out.println("compare " + id + " version " + version + " against " + v + " - " + version.compareToIgnoreCase(v)); if (version.compareToIgnoreCase(v) < 0) { continue; } System.out.println(" update version to " + jars[j]); map.remove(id); } map.put(id, version); } for (Iterator e = map.entrySet().iterator(); e.hasNext();) { Map.Entry entry = (Map.Entry) e.next(); depends.add(content[i] + "/jars/" + entry.getKey() + "-" + entry.getValue() + ".jar"); } } } return depends; } /** grabs first tag on line */ static public String tag(String line) { int start = line.indexOf('>'); int end = line.indexOf('<', start); return line.substring(start + 1, end); } static public List process(String path, String target) { List list = new LinkedList(); try { BufferedReader project = new BufferedReader(new FileReader( new File(path, target))); String line; line = project.readLine(); // first line // skip till dependencies for (; line != null; line = project.readLine()) { line = line.trim(); if (line.equals("