svn commit: rev 46198 - avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic
[email protected] 16 Sep 2004 19:29:43 -0000
| Newsgroups | gmane.comp.jakarta.avalon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: niclas
Date: Thu Sep 16 12:29:42 2004
New Revision: 46198
Modified:
avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/ConsoleInstaller.java
avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/SwingInstaller.java
avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/Worker.java
Log:
Cleaning up the code.
Modified: avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/ConsoleInstaller.java
==============================================================================
--- avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/ConsoleInstaller.java (original)
+++ avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/ConsoleInstaller.java Thu Sep 16 12:29:42 2004
@@ -33,10 +33,11 @@
File userHome = new File( System.getProperty( "user.home" ) );
File magicHome = new File( userHome, ".magic" );
File antLibDir = new File( userHome, ".ant/lib" );
+ File cwDir = new File( System.getProperty( "user.dir" ) );
ProgressIndicator indicator = new ConsoleProgress();
- Worker w = new Worker( magicHome, antLibDir );
- w.start( indicator );
+ Worker w = new Worker( indicator, magicHome, antLibDir, cwDir );
+ w.start();
}
public class ConsoleProgress
Modified: avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/SwingInstaller.java
==============================================================================
--- avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/SwingInstaller.java (original)
+++ avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/SwingInstaller.java Thu Sep 16 12:29:42 2004
@@ -20,9 +20,13 @@
import java.awt.Container;
import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
import java.io.File;
import javax.swing.BoxLayout;
+import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@@ -30,11 +34,13 @@
import javax.swing.JTextArea;
public class SwingInstaller
+ implements ActionListener
{
private JFrame m_ProgressWindow;
private JProgressBar m_ProgressBar;
private JTextArea m_TextArea;
-
+ private JButton m_FinishButton;
+
public SwingInstaller()
{
m_ProgressWindow = new JFrame();
@@ -83,20 +89,34 @@
setSizes( spring4, 0, 10, 100 );
column.add( spring4 );
+ m_FinishButton = createFinishButton();
+ column.add( m_FinishButton );
+
+ final JPanel spring5 = new JPanel();
+ setSizes( spring5, 0, 10, 100 );
+ column.add( spring5 );
+
m_ProgressWindow.pack();
m_ProgressWindow.setVisible( true );
}
+ public void actionPerformed( ActionEvent event )
+ {
+ System.out.println( event.toString() );
+ }
+
public void start()
throws Exception
{
File userHome = new File( System.getProperty( "user.home" ) );
File magicHome = new File( userHome, ".magic" );
File antLibDir = new File( userHome, ".ant/lib" );
+ File cwDir = new File( System.getProperty( "user.dir" ) );
ProgressIndicator indicator = new SwingProgress();
- Worker w = new Worker( magicHome, antLibDir );
- w.start( indicator );
+ Worker w = new Worker( indicator, magicHome, antLibDir, cwDir );
+ w.start();
+ m_FinishButton.setEnabled( true );
}
private void setSizes( JPanel panel, int min, int pref, int max )
@@ -135,7 +155,21 @@
area.setMaximumSize( maxDim );
return area;
}
-
+
+ private JButton createFinishButton()
+ {
+ final Dimension minDim = new Dimension( 20, 20 );
+ final Dimension prefDim = new Dimension( 50, 30 );
+ final Dimension maxDim = new Dimension( 100, 40 );
+ JButton button = new JButton( "Finish" );
+ button.setMinimumSize( minDim );
+ button.setPreferredSize( prefDim );
+ button.setMaximumSize( maxDim );
+ button.setEnabled( false );
+ button.addActionListener( this );
+ return button;
+ }
+
public class SwingProgress
implements ProgressIndicator
{
Modified: avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/Worker.java
==============================================================================
--- avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/Worker.java (original)
+++ avalon/trunk/tools/magic-installer/src/main/org/apache/metro/installer/magic/Worker.java Thu Sep 16 12:29:42 2004
@@ -40,14 +40,21 @@
private File m_MagicHome;
private File m_AntLibDir;
+ private File m_DevDir;
- public Worker( File magicHome, File antLib )
+ private ProgressIndicator m_Progress;
+ private long m_ProgressSize;
+
+ public Worker( ProgressIndicator indicator,
+ File magicHome, File antLib, File devDir )
{
m_MagicHome = magicHome;
m_AntLibDir = antLib;
+ m_Progress = indicator;
+ m_DevDir = devDir;
}
- public void start( ProgressIndicator indicator )
+ public void start()
throws Exception
{
/* Not sure what to do with these yet.
@@ -56,52 +63,70 @@
*/
String url = "http://www.dpml.net/avalon/tools/bars/avalon-tools-magic.bar";
- File barFile = download( url, indicator );
- unjar( barFile, m_MagicHome, indicator );
+ File barFile = download( url );
+ unjar( barFile, m_MagicHome );
File toolsJar = new File( m_MagicHome, "jars/avalon-tools-magic.jar" );
+ copy( toolsJar, m_AntLibDir );
+
+ File globalBuild = new File( m_MagicHome, "templates/global/build.xml" );
+
+ // Below is for testing purposes. The following 2 lines should be removed
+ // as soon as Magic contains the global/build.xml file.
+ if( ! globalBuild.isFile() )
+ globalBuild = new File( m_MagicHome, "templates/standard.xml" );
+
+ copy( globalBuild, m_DevDir );
+
+ m_Progress.message( "Cleaning up." );
- copy( toolsJar, m_AntLibDir, indicator );
- indicator.message( "Cleaning up." );
File jarsDir = toolsJar.getParentFile();
- toolsJar.delete();
- jarsDir.delete();
+ deleteDir( jarsDir );
+ File barsDir = new File( m_MagicHome, "bars/" );
+ deleteDir( barsDir );
}
- private void unjar( File barFile, File toDir, ProgressIndicator indicator )
+ private void unjar( File barFile, File toDir )
throws IOException
{
- indicator.message( "Unzipping " + barFile );
- indicator.start();
+ m_Progress.message( "Unzipping " + barFile );
+ m_Progress.start();
JarFile jar = new JarFile( barFile );
Enumeration entries = jar.entries();
while( entries.hasMoreElements() )
{
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
- InputStream in = jar.getInputStream( entry );
- File file = new File( toDir, name );
- FileOutputStream out = new FileOutputStream( file );
- long size = entry.getSize();
- copy( in, out, indicator, size );
- in.close();
- out.close();
+ File dest = new File( toDir, name );
+ if( entry.isDirectory() )
+ {
+ dest.mkdirs();
+ }
+ else
+ {
+ InputStream in = jar.getInputStream( entry );
+ FileOutputStream out = new FileOutputStream( dest );
+ m_ProgressSize = entry.getSize();
+ copy( in, out );
+ in.close();
+ out.close();
+ }
}
- indicator.finished();
+ m_Progress.finished();
}
- private File download( String url, ProgressIndicator indicator )
+ private File download( String url )
throws IOException
{
URL download = new URL( url );
- indicator.message( "Connecting to " + download.getHost() );
+ m_Progress.message( "Connecting to " + download.getHost() );
URLConnection conn = download.openConnection();
conn.connect();
- int size = conn.getContentLength();
+ m_ProgressSize = conn.getContentLength();
- indicator.message( "Downloading " + url );
- indicator.start();
+ m_Progress.message( "Downloading " + url );
+ m_Progress.start();
InputStream in = conn.getInputStream();
File tmp = File.createTempFile( "magic", null );
@@ -109,16 +134,15 @@
FileOutputStream out = new FileOutputStream( tmp );
- copy( in, out, indicator, size );
+ copy( in, out );
in.close();
out.close();
- indicator.finished();
+ m_Progress.finished();
return tmp;
}
- private void copy( InputStream from, OutputStream to,
- ProgressIndicator indicator, long size )
+ private void copy( InputStream from, OutputStream to )
throws IOException
{
BufferedOutputStream out = new BufferedOutputStream( to );
@@ -130,19 +154,19 @@
byte[] data = new byte[ BUFFER_SIZE ];
bytesRead = in.read( data, 0, BUFFER_SIZE );
counter = counter + bytesRead;
- if( size != 0 )
- indicator.progress( (int) ( ( counter * 100 ) / size ) );
+ if( m_ProgressSize != 0 )
+ m_Progress.progress( (int) ( ( counter * 100 ) / m_ProgressSize ) );
if( bytesRead != -1 )
out.write( data, 0, bytesRead );
} while( bytesRead != -1 );
out.flush();
}
- private void copy( File file, File toDir, ProgressIndicator indicator )
+ private void copy( File file, File toDir )
throws IOException
{
- indicator.message( "Copying " + file + " to " + file );
- indicator.start();
+ m_Progress.message( "Copying " + file + " to " + file );
+ m_Progress.start();
toDir.mkdirs();
String name = file.getName();
File destFile = new File( toDir, name );
@@ -150,11 +174,19 @@
FileInputStream in = new FileInputStream( file );
FileOutputStream out = new FileOutputStream( destFile );
- long size = file.length();
- copy( in, out, indicator, size );
+ m_ProgressSize = file.length();
+ copy( in, out );
in.close();
out.close();
- indicator.finished();
+ m_Progress.finished();
+ }
+
+ private void deleteDir( File dir )
+ {
+ File[] files = dir.listFiles();
+ for( int i=0 ; i < files.length ; i++ )
+ files[i].delete();
+ dir.delete();
}
}