Index: tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/pom.xml
===================================================================
--- tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/pom.xml	(revision 0)
+++ tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/pom.xml	(revision 38314)
@@ -0,0 +1,124 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<artifactId>org.gvsig.andamiupdater</artifactId>
+	<packaging>jar</packaging>
+	<name>org.gvsig.andamiupdater</name>
+	<version>1.0.0-SNAPSHOT</version>
+    <parent>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.maven.base.pom</artifactId>
+        <version>1.0.8-SNAPSHOT</version>
+    </parent>
+    <scm>
+        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/applications/_fwAndami-updater</connection>
+        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/applications/_fwAndami-updater</developerConnection>
+        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/branches/v2_0_0_prep/applications/_fwAndami-updater</url>
+    </scm>
+	<properties>
+        <andami.lib.dir>${gvsig.install.dir}/lib</andami.lib.dir>
+        <!--
+            Default gvSIG installation folder relative to the current workspace
+        -->
+        <gvsig.install.dir>${basedir}/../build/product</gvsig.install.dir>
+    </properties>
+	<dependencies>
+		<dependency>
+	    	<groupId>org.gvsig</groupId>
+    		<artifactId>org.gvsig.andami</artifactId>
+		    <version>2.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+			<groupId>org.apache.ant</groupId>
+			<artifactId>ant</artifactId>
+            <scope>compile</scope>
+		</dependency>
+        <dependency>
+            <groupId>com.sardak</groupId>
+            <artifactId>antform</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>ant-contrib</groupId>
+            <artifactId>ant-contrib</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+	</dependencies>
+	<build>
+        <plugins>
+           <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addClasspath>true</addClasspath>
+                            <mainClass>org.gvsig.andamiupdater.Updater</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+    	<profile>
+            <id>install-extension</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+                <property>
+                    <name>install-extension</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins
+						</groupId>
+                        <artifactId>maven-dependency-plugin
+						</artifactId>
+                        <executions>
+                            <execution>
+                                <id>copy-own-dependencies-for-andamiupdater
+								</id>
+                                <phase>install</phase>
+                                <goals>
+                                    <goal>copy-dependencies</goal>
+                                </goals>
+                                <configuration>
+                                    <outputDirectory>${andami.lib.dir}</outputDirectory>
+                                    <overWriteReleases>true</overWriteReleases>
+                                    <overWriteSnapshots>true</overWriteSnapshots>
+                                    <overWriteIfNewer>true</overWriteIfNewer>
+                                    <includeScope>runtime</includeScope>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>copy-andamiupdater</id>
+                                <phase>install</phase>
+                                <goals>
+                                    <goal>copy</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>org.gvsig</groupId>
+                                            <artifactId>org.gvsig.andamiupdater</artifactId>
+                                            <version>1.0.0-SNAPSHOT</version>
+                                            <type>jar</type>
+                                            <overWrite>true</overWrite>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${andami.lib.dir}</outputDirectory>
+                                    <overWriteReleases>true</overWriteReleases>
+                                    <overWriteSnapshots>false</overWriteSnapshots>
+                                    <overWriteIfNewer>true</overWriteIfNewer>
+                                    <excludeTransitive>false</excludeTransitive>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+     </profiles>
+</project>

Property changes on: tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/pom.xml
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/src/main/java/org/gvsig/andamiupdater/Updater.java
===================================================================
--- tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/src/main/java/org/gvsig/andamiupdater/Updater.java	(revision 0)
+++ tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/src/main/java/org/gvsig/andamiupdater/Updater.java	(revision 38314)
@@ -0,0 +1,270 @@
+/* gvSIG. Geographic Information System of the Valencian Government
+ *
+ * Copyright (C) 2007-2008 Infrastructures and Transports Department
+ * of the Valencian Government (CIT)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ */
+package org.gvsig.andamiupdater;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+
+import com.sardak.antform.AntForm;
+import com.sardak.antform.AntMenu;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+
+/**
+ * @author gvSIG Team
+ * @version $Id$
+ * 
+ */
+public class Updater {
+
+    private String[] args;
+
+    /**
+     * @param args
+     */
+    public Updater(String[] args) {
+        this.args = args;
+    }
+
+    /**
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+        Updater updater = new Updater(args);
+        updater.copyFiles();
+        updater.executeScripts();
+        updater.removeAll();
+        updater.launchApp(args);
+    }
+
+    private File getApplicationDirectory() {
+        String appDir = new File("").getAbsolutePath();
+        return new File(appDir);
+    }
+
+    private File getPluginsDirectory() {
+        return new File(getApplicationDirectory(), this.args[1]);
+    }
+
+    /**
+     * @param args
+     * @throws Exception
+     */
+    @SuppressWarnings("unchecked")
+    private void launchApp(String[] args) throws Exception {
+
+        try {
+
+            Class launcher_class = Class.forName("com.iver.andami.Launcher");
+
+            Object launcher = launcher_class.newInstance();
+            Method main =
+                launcher_class
+                    .getMethod("main", new Class[] { String[].class });
+
+            main.invoke(launcher, new Object[] { args });
+
+        } catch (ClassNotFoundException e) {
+
+            Class launcher_class = Class.forName("org.gvsig.andami.Launcher");
+            Object launcher = launcher_class.newInstance();
+            Method main =
+                launcher_class
+                    .getMethod("main", new Class[] { String[].class });
+
+            main.invoke(launcher, new Object[] { args });
+        }
+    }
+
+    /**
+     * 
+     */
+    private void removeAll() {
+        File updateDirectory =
+            new File(getApplicationDirectory().toString() + File.separator
+                + "update");
+        if (updateDirectory.exists()) {
+            deleteDir(updateDirectory);
+        }
+
+    }
+
+    private boolean deleteDir(File dir) {
+        if (dir.isDirectory()) {
+            String[] children = dir.list();
+            for (int i = 0; i < children.length; i++) {
+                boolean success = deleteDir(new File(dir, children[i]));
+                if (!success) {
+                    return false;
+                }
+            }
+        }
+
+        // The directory is now empty so delete it
+        return dir.delete();
+    }
+
+    /**
+     * Reads every line of appDirectory/update/scripts.lst and executes the ant
+     * file that this line points to
+     */
+    private void executeScripts() {
+
+        String antFilesScriptPath =
+            getApplicationDirectory() + File.separator + "update"
+                + File.separator + "scripts.lst";
+        File antFilesScript = new File(antFilesScriptPath);
+
+        if (antFilesScript.exists()) {
+            try {
+
+                FileInputStream fstream = new FileInputStream(antFilesScript);
+
+                // Get the object of DataInputStream
+                DataInputStream in = new DataInputStream(fstream);
+                BufferedReader br =
+                    new BufferedReader(new InputStreamReader(in));
+                String strLine;
+
+                // Read File Line By Line
+                while ((strLine = br.readLine()) != null) {
+                    // Print the content on the console
+                    File antFile = new File(strLine);
+                    executeAntFile(antFile);
+                }
+
+                // Close the input stream
+                in.close();
+
+            } catch (Exception e) {// Catch exception if any
+                System.err.println("Error: " + e.getMessage());
+            }
+
+        }
+
+    }
+
+    /**
+     * Copies all files and folders from gvSIG/update to gvSIG/extensions
+     * 
+     * @throws IOException
+     * 
+     */
+    private void copyFiles() throws IOException {
+        File updateFolder =
+            new File(getApplicationDirectory().toString() + File.separator
+                + "update");
+        File filesFolder =
+            new File(updateFolder.toString() + File.separator + "files");
+        File pluginsDirectory = getPluginsDirectory();
+
+        if (updateFolder.exists()) {
+            String[] childrenDirs = filesFolder.list();
+
+            if (childrenDirs != null) {
+                for (int i = 0; i < childrenDirs.length; i++) {
+                    File sourceLocation =
+                        new File(filesFolder, childrenDirs[i]);
+                    File targetLocation =
+                        new File(pluginsDirectory, childrenDirs[i]);
+                    // lo copio todo
+                    copyFilesAndFolders(sourceLocation, targetLocation);
+                }
+            }
+        }
+    }
+
+    private boolean copyFilesAndFolders(File sourceLocation, File targetLocation)
+        throws IOException {
+
+        if (sourceLocation.isDirectory()) {
+            if (!targetLocation.exists()) {
+                targetLocation.mkdir();
+            }
+
+            String[] children = sourceLocation.list();
+            if (children != null) {
+                for (int i = 0; i < children.length; i++) {
+                    copyFilesAndFolders(new File(sourceLocation, children[i]),
+                        new File(targetLocation, children[i]));
+                }
+            }
+        } else {
+            InputStream in = new FileInputStream(sourceLocation);
+            OutputStream out = new FileOutputStream(targetLocation);
+
+            // Copy the bits from instream to outstream
+            byte[] buf = new byte[1024];
+            int len;
+            while ((len = in.read(buf)) > 0) {
+                out.write(buf, 0, len);
+            }
+            in.close();
+            out.close();
+        }
+
+        return true;
+    }
+
+    // PRIVATE VOID EXECUTEANTFILE(FILE FILE) {
+    // PROJECT P = NEW PROJECT();
+    // P.SETUSERPROPERTY("ANT.FILE", FILE.GETABSOLUTEPATH());
+    // P.SETPROPERTY("GVSIG_DIR", GETAPPLICATIONDIRECTORY().GETABSOLUTEPATH());
+    // P
+    // .SETPROPERTY("EXTENSIONS_DIR", GETPLUGINSDIRECTORY()
+    // .GETABSOLUTEPATH());
+    // P.INIT();
+    // PROJECTHELPER HELPER = PROJECTHELPER.GETPROJECTHELPER();
+    // P.ADDREFERENCE("ANT.PROJECTHELPER", HELPER);
+    // HELPER.PARSE(P, FILE);
+    // P.EXECUTETARGET(P.GETDEFAULTTARGET());
+    // }
+
+    private void executeAntFile(File file) {
+        Project p = new Project();
+        p.setUserProperty("ant.file", file.getAbsolutePath());
+        p.setUserProperty("gvsig_dir", getApplicationDirectory()
+            .getAbsolutePath());
+        p.setUserProperty("extensions_dir", getPluginsDirectory()
+            .getAbsolutePath());
+        p.init();
+        p.setBaseDir(file.getParentFile());
+        p.addTaskDefinition("antform", AntForm.class);
+        p.addTaskDefinition("antmenu", AntMenu.class);
+        p.init();
+        ProjectHelper helper = ProjectHelper.getProjectHelper();
+        p.addReference("ant.projectHelper", helper);
+        helper.parse(p, file);
+        p.executeTarget(p.getDefaultTarget());
+    }
+
+}

Property changes on: tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater/src/main/java/org/gvsig/andamiupdater/Updater.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain


Property changes on: tags/v2_0_0_Build_2047/applications/_fwAndami-updater/_fwAndami-updater
___________________________________________________________________
Added: svn:ignore
   + .settings
target
.classpath
.project


