Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1501 - in development/main/transit: handler/src/main/net/dpml/transit/artifact installer/src/main/net/dpml/transit/installer

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1501 - in development/main/transit: handler/src/main/net/dpml/transit/artifact installer/src/main/net/dpml/transit/installer
  • Date: Sun, 16 Jan 2005 19:12:54 +0100

Author: niclas
Date: Sun Jan 16 19:12:53 2005
New Revision: 1501

Removed:

development/main/transit/installer/src/main/net/dpml/transit/installer/InstallException.java

development/main/transit/installer/src/main/net/dpml/transit/installer/Unzip.java
Modified:

development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java

development/main/transit/installer/src/main/net/dpml/transit/installer/ConsoleInstaller.java

development/main/transit/installer/src/main/net/dpml/transit/installer/Main.java

development/main/transit/installer/src/main/net/dpml/transit/installer/ProgressIndicator.java

development/main/transit/installer/src/main/net/dpml/transit/installer/SwingInstaller.java

development/main/transit/installer/src/main/net/dpml/transit/installer/Worker.java
Log:
Fixed up the installer to pass the checkstyle stuff.

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
Sun Jan 16 19:12:53 2005
@@ -91,7 +91,9 @@
private HashSet m_knownGroups;

/**
- * locks TODO: what are the key/values
+ * locks.
+ * The key is the Artifact one wants to lock against, and the value is an
+ * anonymously lock object.
*/
private HashMap m_locks;

@@ -230,10 +232,13 @@
{
connection = (URLConnection) m_connections.get( artifact );
// TODO: Investigate if the cache is used properly.
+ // Niclas: I suspect that the value is dropped from the
+ // WeakHashMap more or less immediately, and that we
+ // must start using the SoftReferences instead.
if( connection == null )
{
// Not in cache. Why not? ---> Garbage Collection has
occurred.
- String message = this + " - Info: Connection no longer
in cache. Reconnecting." ;
+ String message = this + " - Info: Connection no longer
in cache. Reconnecting.";
Transit.getInstance().getLogWriter().println( message );
URL remote = createRemoteUrl( artifact );
connection = remote.openConnection();

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
Sun Jan 16 19:12:53 2005
@@ -1,17 +1,17 @@
-/*
+/*
* Copyright 2004 Niclas Hedhman, DPML
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -41,7 +41,7 @@
* The singleton delegating authenticator instance.
*/
private static DelegatingAuthenticator m_INSTANCE;
-
+
//
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------
@@ -67,7 +67,7 @@
return m_INSTANCE;
}
}
-
+
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -75,7 +75,7 @@
/**
* Creation of a new delegating authenticator.
*/
- DelegatingAuthenticator()
+ DelegatingAuthenticator()
{
m_authenticators = new HashMap();
}
@@ -97,7 +97,7 @@
m_authenticators.put( id, authenticator );
}
}
-
+
/**
* Remove an authenticator from the set of authenticators managed by the
* singleton delegating authenticator.
@@ -118,7 +118,7 @@
}
}
}
-
+
/**
* Returns the password authenticator.
* @return the password authenticator
@@ -147,7 +147,7 @@
}
return auth.resolvePasswordAuthentication( this );
}
- }
+ }
catch( UnknownHostException e )
{
return null;

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
Sun Jan 16 19:12:53 2005
@@ -155,9 +155,9 @@
monitor.failedDownload( artifact );
}

- String error =
- "Unresolvable artifact: ["
- + artifact
+ String error =
+ "Unresolvable artifact: ["
+ + artifact
+ "].";
throw new ArtifactNotFoundException( error, artifact );
}
@@ -197,7 +197,6 @@
*/
private ResourceHost findAnyPresence( Artifact artifact, File dest )
{
- // TODO: Change this method to check all resource hosts in parallel.
Iterator list = m_resourceHosts.values().iterator();
while ( list.hasNext() )
{
@@ -234,7 +233,7 @@
{
host.download( artifact, destination );
return true;
- }
+ }
catch( IOException e )
{
if( monitor != null )

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java
Sun Jan 16 19:12:53 2005
@@ -18,11 +18,13 @@
package net.dpml.transit.artifact;

import java.io.IOException;
+import java.io.PrintWriter;

import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

+import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;

/**
@@ -62,12 +64,12 @@
try
{
m_context = SecuredTransitContext.create();
- }
+ }
catch( TransitException e )
{
e.printStackTrace();
throw e;
- }
+ }
catch( RuntimeException e )
{
e.printStackTrace();
@@ -120,7 +122,7 @@
String internal = getInternalPath( u ); //SJM
if( null != internal )
{
- buf.append( internal );
+ buf.append( internal );
}

String version = u.getUserInfo();
@@ -192,7 +194,7 @@
{
try
{
- // TODO: Improve the parsing algorithm and have some more checks.
+ // Niclas: Improve the parsing algorithm and have some more
checks.
String protocol = dest.getProtocol();

String specPath = spec.substring( start, limit );
@@ -248,10 +250,24 @@

setURL( dest, protocol, host, port, authority, user, path,
query, ref );

- }
+ }
catch( Throwable e )
{
- e.printStackTrace(); // TODO: fix me
+ try
+ {
+ PrintWriter log = Transit.getInstance().getLogWriter();
+ String message = "Unable to parse the URL: "
+ + dest + ", " + spec + ", " + start + ", " + limit;
+ log.println( message );
+ log.println(
"---------------------------------------------------" );
+ e.printStackTrace( log );
+ }
+ catch( TransitException f )
+ {
+ // Panic!!!! Should not happen.
+ f.printStackTrace();
+ e.printStackTrace();
+ }
}
}
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
Sun Jan 16 19:12:53 2005
@@ -99,15 +99,15 @@
//
------------------------------------------------------------------------

/**
- * Create a set of resource hosts relative to the information optained at
the
- * authorative anchor. The implementation will attempt to locate a
hosts.xml
+ * Create a set of resource hosts relative to the information optained at
the
+ * authorative anchor. The implementation will attempt to locate a
hosts.xml
* at the authorative location and if available will resolve host
defintions
* and return. Otherwise the behaviour is dependent on the type of
authority - if
- * the authority url protocol is "file:" then property based host
descripts will
+ * the authority url protocol is "file:" then property based host
descripts will
* be read from the [authorative]/hosts direrectory. All files in the
directory
* will be considered. If the a property based host file does not contain
the property
- * declaration "dpml.transit.resourcehost.base" the file not be
processed. If the
- * authorative url is not the "file:" protocol then the implementation
will attempt
+ * declaration "dpml.transit.resourcehost.base" the file not be
processed. If the
+ * authorative url is not the "file:" protocol then the implementation
will attempt
* to locate a resource named "index.lst" containing a set of host
descriptor filenames
* to evaluation.
*
@@ -119,7 +119,7 @@
throws IOException, TransitException
{
ArrayList result = new ArrayList();
-
+
URL hosts = new URL( m_authorative, "hosts.xml" );
InputStream input = null;
try
@@ -147,9 +147,9 @@
File base = new File( authorative );
if( !base.exists() )
{
- final String error =
- "Authority base directory ["
- + base
+ final String error =
+ "Authority base directory ["
+ + base
+ "] does not exist.";
throw new FileNotFoundException( error );
}
@@ -166,7 +166,7 @@
return hostArray;
}

- /**
+ /**
* Creates the ResourceHosts defined in the properties for the
ResourceHost.
*
* <pre>
@@ -197,13 +197,13 @@
{
result.add( host );
}
- }
+ }
catch( MalformedURLException e )
{
- final String error =
+ final String error =
"Unable to construct a URL from " + m_authorative + " and
" + files[i];
throw new TransitException( error );
- }
+ }
catch( IOException e )
{
throw new TransitException( "Unable to read : " +
m_authorative + ", " + files[i], e );
@@ -297,12 +297,12 @@
}
catch( MalformedURLException mue )
{
- final String error =
- "The file ["
- + file
- + "] ("
- + file.exists()
- + ") raised a malformed url exception with the message '"
+ final String error =
+ "The file ["
+ + file
+ + "] ("
+ + file.exists()
+ + ") raised a malformed url exception with the message '"
+ mue.getMessage()
+ "'.";
throw new TransitException( error );
@@ -334,7 +334,7 @@
base = base + "/";
}
baseUrl = new URL( base );
- }
+ }
catch( MalformedURLException e )
{
throw new TransitException( base + ", found in " + hostDef + "
is not a valid URL.", e );
@@ -343,7 +343,7 @@
if( base.startsWith( "file:" ) )
{
base = base.substring( FILE_PROTOCOL_LENGTH );
-
+
File f = new File( base );
if( !f.isAbsolute() )
{
@@ -352,16 +352,16 @@
base = f.toURL().toExternalForm();
}

- String classname =
- Util.getProperty(
- props, "dpml.transit.resourcehost.class",
+ String classname =
+ Util.getProperty(
+ props, "dpml.transit.resourcehost.class",
"net.dpml.transit.artifact.ClassicResourceHost" );

String known = Util.getProperty( props,
"dpml.transit.resourcehost.knowngroups", null ).trim();

URL groupFile = getRelativeURL( hostDef, known );

- String priorityText =
+ String priorityText =
Util.getProperty( props, "dpml.transit.resourcehost.priority",
DEFAULT_PRIORITY_STRING );
if( "".equals( priorityText ) )
{
@@ -372,13 +372,13 @@
String password = Util.getProperty( props,
"dpml.transit.resourcehost.password", "" );
String prompt = Util.getProperty( props,
"dpml.transit.resourcehost.prompt", "" );
String scheme = Util.getProperty( props,
"dpml.transit.resourcehost.scheme", "" );
- boolean enabled =
- Util.getProperty(
+ boolean enabled =
+ Util.getProperty(
props, "dpml.transit.resourcehost.enabled", TRUE_VALUE
).equalsIgnoreCase( TRUE_VALUE );
- boolean trusted =
- Util.getProperty(
+ boolean trusted =
+ Util.getProperty(
props, "dpml.transit.resourcehost.trusted", "false"
).equalsIgnoreCase( TRUE_VALUE );
- String policyType =
+ String policyType =
Util.getProperty( props, "dpml.transit.resourcehost.policy",
"fast" );
if( "".equals( policyType ) )
{
@@ -389,14 +389,14 @@

try
{
- return createResourceHost(
- classname, baseUrl, groupFile, priority, policy, enabled,
trusted,
+ return createResourceHost(
+ classname, baseUrl, groupFile, priority, policy, enabled,
trusted,
username, password, scheme, prompt );
}
catch( Throwable e )
{
- final String error =
- "Could not construct a resource hosts from the host
descriptor: "
+ final String error =
+ "Could not construct a resource hosts from the host
descriptor: "
+ hostDef;
throw new TransitException( error, e );
}
@@ -417,18 +417,18 @@
}
catch( MalformedURLException mue )
{
- final String error =
- "An error occured while attempting to construct a new url
using the path ["
- + path
- + "] and base url ["
- + anchor
+ final String error =
+ "An error occured while attempting to construct a new url
using the path ["
+ + path
+ + "] and base url ["
+ + anchor
+ "].";
throw new TransitException( error, mue );
}
}

/**
- * Return the class relative a supplied filename using this class as the
+ * Return the class relative a supplied filename using this class as the
* reference classloader.
* @param classname the classname of the class to load
* @return the class
@@ -443,7 +443,7 @@
* Return a set of known groups froma host.
* @param href the host against which the request is to be made
* @return the set of known group names
- * @exception TransitException if an error occurs while attempting to
read the
+ * @exception TransitException if an error occurs while attempting to
read the
* remote address
*/
private String[] getKnownGroups( URL href ) throws TransitException
@@ -453,11 +453,11 @@
try
{
return Util.readListFile( href );
- }
+ }
catch( Exception e )
{
- final String error =
- "Unable to extract the groups from "
+ final String error =
+ "Unable to extract the groups from "
+ href;
throw new TransitException( error, e );
}
@@ -485,8 +485,8 @@
* @exception TransitException if a construction error occurs
* @exception IOException if an IO related error occurs
*/
- ResourceHost createResourceHost(
- String classname, URL base, URL index, int priority, Policy policy,
+ ResourceHost createResourceHost(
+ String classname, URL base, URL index, int priority, Policy policy,
boolean enabled, boolean trusted, String username, String password,
String scheme, String prompt )
throws TransitException, IOException
@@ -531,59 +531,59 @@
}
else
{
- final String error =
- "Class "
- + classname
- + " does not implement "
+ final String error =
+ "Class "
+ + classname
+ + " does not implement "
+ ResourceHost.class.getName() + ".";
throw new TransitException( error );
}
- }
+ }
catch( ClassNotFoundException e )
{
- final String error =
- "The resource host factory classname ["
- + classname
+ final String error =
+ "The resource host factory classname ["
+ + classname
+ "] is unknown.";
throw new TransitException( error );
}
catch( NoSuchMethodException e )
{
- final String error =
- "The resource host factory class ["
- + classname
+ final String error =
+ "The resource host factory class ["
+ + classname
+ "] does not declare the required constructor.";
throw new TransitException( error );
}
catch( IllegalAccessException e )
{
- final String error =
- "The resource host factory class ["
- + classname
+ final String error =
+ "The resource host factory class ["
+ + classname
+ "] is not accessible.";
throw new TransitException( error );
}
catch( IllegalArgumentException e )
{
- final String error =
- "The resource host factory class ["
- + classname
+ final String error =
+ "The resource host factory class ["
+ + classname
+ "] could not be established due to an internal error.";
throw new TransitException( error, e );
}
catch( InstantiationException e )
{
- final String error =
- "The resource host factory class ["
- + classname
+ final String error =
+ "The resource host factory class ["
+ + classname
+ "] could not be instantiated.";
throw new TransitException( error, e );
}
catch( InvocationTargetException e )
{
- final String error =
- "The resource host factory class ["
- + classname
+ final String error =
+ "The resource host factory class ["
+ + classname
+ "] raised an unexpected error during instantiation.";
throw new TransitException( error, e.getTargetException() );
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java
Sun Jan 16 19:12:53 2005
@@ -1,18 +1,18 @@
-/*
+/*
* Copyright 2004-2005 Stephen McConnell, DPML
* Copyright 2004 Niclas Hedhman, DPML
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -25,8 +25,6 @@
/**
* Default authenticator that provides support for username password
* based authentication in conjunction with the repository proxy settings.
- * TODO: setup implementation of password authentication relative to
- * supplied hosts.
*
* @version $Id: DefaultAuthenticator.java 30977 2004-07-30 08:57:54Z niclas
$
*/
@@ -52,7 +50,7 @@
* @param password the password
* @exception NullPointerException if either the username or password
argument is null
*/
- public TransitAuthenticatorImpl( String username, String password )
+ public TransitAuthenticatorImpl( String username, String password )
throws NullPointerException
{
if( username == null )

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
Sun Jan 16 19:12:53 2005
@@ -1,18 +1,18 @@
-/*
+/*
* Copyright 2004 Stephen McConnell
* Copyright 2004 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -34,9 +34,9 @@
import org.w3c.dom.Element;

/**
- * Utility class supporting the translation of an XML based hosts file to a
+ * Utility class supporting the translation of an XML based hosts file to a
* set of ResourceHost descriptors.
- *
+ *
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
*/
@@ -47,11 +47,11 @@
//
------------------------------------------------------------------------

/**
- * The factory used to create resource hosts based on the data collected
+ * The factory used to create resource hosts based on the data collected
* from xml based specifications.
*/
private final ResourceHostFactory m_resourceHostFactory;
-
+
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -74,10 +74,10 @@
* @param result a list containing the acculated host definitions
* @param input the input stream of an XML document
* @exception IOException if an IO related error occurs
- * @exception TransitException if an error occurs in constructing the
+ * @exception TransitException if an error occurs in constructing the
* host defintions
*/
- void buildResourceHosts( List result, InputStream input )
+ void buildResourceHosts( List result, InputStream input )
throws IOException, TransitException
{
try
@@ -93,7 +93,7 @@
}
catch( Exception e )
{
- final String error =
+ final String error =
"Unabled to construct host defintions from source.";
throw new TransitException( error, e );
}
@@ -104,10 +104,10 @@
* @param element the XML host element
* @return the resource host
* @exception IOException if an IO related error occurs
- * @exception TransitException if an error occurs in constructing the
+ * @exception TransitException if an error occurs in constructing the
* host defintions
*/
- private ResourceHost buildResourceHost( Element element )
+ private ResourceHost buildResourceHost( Element element )
throws IOException, TransitException
{
String classname = getClassname( element );
@@ -121,9 +121,9 @@
String password = getPassword( element );
String scheme = getScheme( element );
String prompt = getPrompt( element );
-
- return m_resourceHostFactory.createResourceHost(
- classname, base, index, priority, policy, enabled, trusted,
+
+ return m_resourceHostFactory.createResourceHost(
+ classname, base, index, priority, policy, enabled, trusted,
username, password, scheme, prompt );
}

@@ -133,7 +133,7 @@
* @return the resource host base url
* @exception IOException if an IO related error occurs
*/
- private URL getBaseURL( Element root )
+ private URL getBaseURL( Element root )
throws IOException
{
String base = ElementHelper.getAttribute( root, "href", null );
@@ -163,12 +163,12 @@
* Resolve a base url to a local file repository using a supplied path.
If the path
* resolves to an absolute filename a local repository will be created at
that location
* otherwise a repository will be created relative to ${dpml.home}.
- *
+ *
* @param path the repository path
* @return the repository url
* @exception IOException if an IO related error occurs
*/
- private URL resolveLocalRepositoryURL( String path )
+ private URL resolveLocalRepositoryURL( String path )
throws IOException
{
File base = new File( path );
@@ -192,7 +192,7 @@
* @return the index url (possibly null)
* @exception IOException if an IO related error occurs
*/
- private URL getKnownGroupsURL( Element root )
+ private URL getKnownGroupsURL( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "index" );
@@ -218,9 +218,9 @@
* @return the host classname
* @exception IOException if an IO related error occurs
*/
- private String getClassname( Element root )
+ private String getClassname( Element root )
throws IOException
- {
+ {
String defaultClass =
"net.dpml.transit.artifact.ClassicResourceHost";
Element element = ElementHelper.getChild( root, "class" );
if( null == element )
@@ -233,20 +233,22 @@
{
classname = ElementHelper.getValue( element );
if( classname == null )
+ {
classname = defaultClass;
+ }
}
return classname;
}


/**
- * Get the host priority from the supplied host element using the value
of
+ * Get the host priority from the supplied host element using the value of
* the child element named 'priority'.
* @param root the XML host element
* @return the priority
* @exception IOException if an IO related error occurs
*/
- private int getPriority( Element root )
+ private int getPriority( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "priority" );
@@ -269,7 +271,7 @@
* @return the enabled status
* @exception IOException if an IO related error occurs
*/
- private boolean getEnabled( Element root )
+ private boolean getEnabled( Element root )
throws IOException
{
String enabled = ElementHelper.getAttribute( root, "enabled", "true"
);
@@ -277,13 +279,13 @@
}

/**
- * Get the host trusted status from the supplied host element using the
+ * Get the host trusted status from the supplied host element using the
* value of a child element named 'trusted'.
* @param root the XML host element
* @return the trusted status
* @exception IOException if an IO related error occurs
*/
- private boolean getTrusted( Element root )
+ private boolean getTrusted( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "trusted" );
@@ -296,13 +298,13 @@
}

/**
- * Get the host timestamp policy from the supplied host element using the
+ * Get the host timestamp policy from the supplied host element using the
* value of a child element named 'policy'.
* @param root the XML host element
* @return the timestamp policy
* @exception IOException if an IO related error occurs
*/
- private Policy getPolicy( Element root )
+ private Policy getPolicy( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "policy" );
@@ -314,13 +316,13 @@
}

/**
- * Get the username from the supplied host element's credentials element
using the
+ * Get the username from the supplied host element's credentials element
using the
* value of a child element named 'username'.
* @param root the XML host element
* @return the username
* @exception IOException if an IO related error occurs
*/
- private String getUsername( Element root )
+ private String getUsername( Element root )
throws IOException
{
Element credentials = ElementHelper.getChild( root, "credentials" );
@@ -341,13 +343,13 @@
}

/**
- * Get the password from the supplied host element's credentials element
using the
+ * Get the password from the supplied host element's credentials element
using the
* value of a child element named 'password'.
* @param root the XML host element
* @return the password
* @exception IOException if an IO related error occurs
*/
- private String getPassword( Element root )
+ private String getPassword( Element root )
throws IOException
{
Element credentials = ElementHelper.getChild( root, "credentials" );
@@ -366,15 +368,15 @@
return ElementHelper.getValue( element );
}
}
-
+
/**
- * Get the scheme from the supplied host element using the
+ * Get the scheme from the supplied host element using the
* value of a child element named 'scheme'.
* @param root the XML host element
* @return the scheme
* @exception IOException if an IO related error occurs
*/
- private String getScheme( Element root )
+ private String getScheme( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "scheme" );
@@ -389,13 +391,13 @@
}

/**
- * Get the prompt/realm from the supplied host element using the
+ * Get the prompt/realm from the supplied host element using the
* value of a child element named 'prompt'.
* @param root the XML host element
* @return the prompt/realm
* @exception IOException if an IO related error occurs
*/
- private String getPrompt( Element root )
+ private String getPrompt( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "prompt" );

Modified:
development/main/transit/installer/src/main/net/dpml/transit/installer/ConsoleInstaller.java
==============================================================================
---
development/main/transit/installer/src/main/net/dpml/transit/installer/ConsoleInstaller.java
(original)
+++
development/main/transit/installer/src/main/net/dpml/transit/installer/ConsoleInstaller.java
Sun Jan 16 19:12:53 2005
@@ -1,33 +1,44 @@
-/*
+/*
* Copyright 2004-2005 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dpml.transit.installer;

-import java.io.File;
-
-public class ConsoleInstaller
+/** The installer for console output.
+ */
+public final class ConsoleInstaller
{
- private static final int BUFFER_SIZE = 10000;
-
- public ConsoleInstaller()
+ /** The minimum change to trigger a new output. */
+ private static final int STEP = 2;
+
+ /** The full scale (i.e. 100%) */
+ private static final int FULL_SCALE = 100;
+
+ /** The package protected constructor.
+ */
+ ConsoleInstaller()
{
}
-
+
+ /** Start working.
+ * This method is the entry point for starting the installation. It will
+ * create a Worker and pass a console oriented ProgressIndicator to it.
+ * @throws Exception if something goes terribly wrong.
+ */
public void start()
throws Exception
{
@@ -35,46 +46,64 @@
Worker w = Main.createWorker( indicator );
w.start();
}
-
- public class ConsoleProgress
+
+ /** The ProgressIndicator implementation which outputs to the standard
output.
+ */
+ class ConsoleProgress
implements ProgressIndicator
{
- int m_OldPercent;
-
+ /** Cached value of previous progress percentage, to know whether it
is
+ * time to update the output.
+ */
+ private int m_oldPercent;
+
+ /** The Worker reports back some type of message.
+ * @param message the message to be shown to the user.
+ */
public void message( String message )
{
System.out.println( message );
}
-
- public void error( String message )
- throws InstallException
- {
- System.out.println( message );
- throw new InstallException( message );
- }
-
+
+ /** The Worker is indicating that a progressive value indicator is
+ * starting.
+ */
public void start()
{
System.out.print( "[
] 0%" );
- m_OldPercent = 0;
- }
-
+ m_oldPercent = 0;
+ }
+
+ /** The Worker is updating the progressive value indicator.
+ * @param percentage the completion percentage of the operation.
+ */
public void progress( int percentage )
{
- if( percentage - m_OldPercent < 2 )
+ if( percentage - m_oldPercent < STEP )
+ {
return;
- m_OldPercent = percentage;
- if( percentage > 100 )
+ }
+ m_oldPercent = percentage;
+ if( percentage > FULL_SCALE )
+ {
return;
- int size = percentage / 2;
+ }
+ int size = percentage / STEP;
System.out.print( "\r[" );
- for( int i = 0 ; i < size ; i++ )
+ for( int i = 0; i < size; i++ )
+ {
System.out.print( "*" );
- for( int i = 0 ; i < 50-size ; i++ )
+ }
+ for( int i = 0; i < ( FULL_SCALE / STEP ) - size; i++ )
+ {
System.out.print( " " );
+ }
System.out.print( "] " + percentage + "%" );
}
-
+
+ /** The Worker is indicating that a progressive value indicator is
+ * finished.
+ */
public void finished()
{
System.out.print(
"\r[**************************************************] 100%" );
@@ -82,4 +111,4 @@
}
}
}
-
+

Modified:
development/main/transit/installer/src/main/net/dpml/transit/installer/Main.java
==============================================================================
---
development/main/transit/installer/src/main/net/dpml/transit/installer/Main.java
(original)
+++
development/main/transit/installer/src/main/net/dpml/transit/installer/Main.java
Sun Jan 16 19:12:53 2005
@@ -1,17 +1,17 @@
-/*
+/*
* Copyright 2004-2005 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -20,40 +20,57 @@

import java.io.File;

-public class Main
+/** The entry class for commandline operation of the installers.
+ */
+public final class Main
{
- static public void main( String[] args )
+ /** No public access to this class. */
+ private Main()
+ {
+ }
+
+ /** The JVM entry method for the installer application.
+ * @param arguments The arguments that was passed on the commandline to
this
+ * application.
+ * @throws Exception for any exception that occurs in the underlying
+ * implementation.
+ */
+ public static void main( String[] arguments )
throws Exception
{
- if( args.length == 0 )
+ if( arguments.length == 0 )
{
ConsoleInstaller installer = new ConsoleInstaller();
installer.start();
return;
}
- if( args[0].equals( "-console" ) )
+ if( arguments[0].equals( "-console" ) )
{
ConsoleInstaller installer = new ConsoleInstaller();
installer.start();
return;
}
-
- if( args[0].equals( "-gui" ) )
+
+ if( arguments[0].equals( "-gui" ) )
{
SwingInstaller installer = new SwingInstaller();
installer.start();
return;
}
}
-
+
+ /** Creates the same worker for each of the installers.
+ * @param indicator The indicator to pass to the Worker to be created.
+ * @return A worker instance for the installation process.
+ */
static Worker createWorker( ProgressIndicator indicator )
{
File userHome = new File( System.getProperty( "user.home" ) );
File dpmlHome = new File( userHome, ".dpml" );
File antLibDir = new File( userHome, ".ant/lib" );
File cwDir = new File( System.getProperty( "user.dir" ) );
-
+
Worker w = new Worker( indicator, dpmlHome, antLibDir, cwDir );
return w;
}
-}
+}

Modified:
development/main/transit/installer/src/main/net/dpml/transit/installer/ProgressIndicator.java
==============================================================================
---
development/main/transit/installer/src/main/net/dpml/transit/installer/ProgressIndicator.java
(original)
+++
development/main/transit/installer/src/main/net/dpml/transit/installer/ProgressIndicator.java
Sun Jan 16 19:12:53 2005
@@ -1,33 +1,45 @@
-/*
+/*
* Copyright 2004-2005 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dpml.transit.installer;

+/** Interface for callback from the Worker to the Installer.
+ */
public interface ProgressIndicator
{
+ /** The Worker reports back some type of message.
+ * @param message the message to be shown to the user.
+ */
void message( String message );
-
- void error( String errormessage ) throws Exception;
-
+
+ /** The Worker is indicating that a progressive value indicator is
+ * starting.
+ */
void start();
-
+
+ /** The Worker is updating the progressive value indicator.
+ * @param percentage the completion percentage of the operation.
+ */
void progress( int percentage );
-
+
+ /** The Worker is indicating that a progressive value indicator is
+ * finished.
+ */
void finished();
}
-
+

Modified:
development/main/transit/installer/src/main/net/dpml/transit/installer/SwingInstaller.java
==============================================================================
---
development/main/transit/installer/src/main/net/dpml/transit/installer/SwingInstaller.java
(original)
+++
development/main/transit/installer/src/main/net/dpml/transit/installer/SwingInstaller.java
Sun Jan 16 19:12:53 2005
@@ -1,17 +1,17 @@
-/*
+/*
* Copyright 2004-2005 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -24,8 +24,6 @@
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;
@@ -34,23 +32,79 @@
import javax.swing.JProgressBar;
import javax.swing.JTextArea;

-public class SwingInstaller
+/** This is the installer that provides the Swing output ProgressIndicator.
+ * The Swing ProgressIndicator implementation is an inner class of this
+ * class, and the SwingInstaller class establishes the output windows.
+ */
+public final class SwingInstaller
implements ActionListener
{
- private JFrame m_ProgressWindow;
- private JProgressBar m_ProgressBar;
- private JTextArea m_TextArea;
- private JButton m_FinishButton;
-
- public SwingInstaller()
+ /** The minimum size of panel. */
+ private static final int PANEL_MIN_SIZE = 10;
+
+ /** The minimum size of the springs. */
+ private static final int SPRING_MIN_SIZE = 0;
+
+ /** The preferred size of the springs. */
+ private static final int SPRING_PREF_SIZE = 10;
+
+ /** The maximum size of the springs. */
+ private static final int SPRING_MAX_SIZE = 100;
+
+ /** The minimum size of the width of the value controls. */
+ private static final int VALUE_MIN_WIDTH = 50;
+
+ /** The preferred size of the width of the value controls. */
+ private static final int VALUE_PREF_WIDTH = 300;
+
+ /** The maximum size of the width of the value controls. */
+ private static final int VALUE_MAX_WIDTH = 1200;
+
+ /** Satisfy Checkstyle for now. */
+ private static final int TEN = 10;
+ /** Satisfy Checkstyle for now. */
+ private static final int TWENTY = 20;
+ /** Satisfy Checkstyle for now. */
+ private static final int TWENTY_FIVE = 25;
+ /** Satisfy Checkstyle for now. */
+ private static final int THIRTY = 30;
+ /** Satisfy Checkstyle for now. */
+ private static final int FORTY = 40;
+ /** Satisfy Checkstyle for now. */
+ private static final int FIFTY = 50;
+ /** Satisfy Checkstyle for now. */
+ private static final int HUNDRED = 100;
+ /** Satisfy Checkstyle for now. */
+ private static final int THREE_HUNDRED = 300;
+ /** Satisfy Checkstyle for now. */
+ private static final int THOUSAND = 1000;
+
+
+ /** The main frame for the GUI application. */
+ private JFrame m_progressWindow;
+
+ /** The progress bar to show something is happening. */
+ private JProgressBar m_progressBar;
+
+ /** Text area to output message into. */
+ private JTextArea m_textArea;
+
+ /** The button to finish off the installation and exit. */
+ private JButton m_finishButton;
+
+ /** The package protected constructor for the installer.
+ * The constructor creates all the controls and other GUI elements
+ * for the application.
+ */
+ SwingInstaller()
{
- m_ProgressWindow = new JFrame();
- Container pane = m_ProgressWindow.getContentPane();
+ m_progressWindow = new JFrame();
+ Container pane = m_progressWindow.getContentPane();
final BoxLayout layout = new BoxLayout( pane, BoxLayout.X_AXIS );
pane.setLayout( layout );
-
+
JPanel leadColumn = new JPanel();
- leadColumn.setMinimumSize( new Dimension( 10, 10 ) );
+ leadColumn.setMinimumSize( new Dimension( PANEL_MIN_SIZE,
PANEL_MIN_SIZE ) );
pane.add( leadColumn );

JPanel column = new JPanel();
@@ -59,62 +113,78 @@
pane.add( column );

JPanel trailColumn = new JPanel();
- trailColumn.setMinimumSize( new Dimension( 10, 10 ) );
+ trailColumn.setMinimumSize( new Dimension( PANEL_MIN_SIZE,
PANEL_MIN_SIZE ) );
pane.add( trailColumn );
-
+
JPanel leadRow = new JPanel();
- leadRow.setMinimumSize( new Dimension( 10, 10 ) );
+ leadRow.setMinimumSize( new Dimension( PANEL_MIN_SIZE,
PANEL_MIN_SIZE ) );
column.add( leadRow );
-
+
final JLabel label = new JLabel( "Installing Magic - The new age of
build systems." );
column.add( label );
-
- m_ProgressWindow.setTitle( "Transit Installer" );
+
+ m_progressWindow.setTitle( "Transit Installer" );
final JPanel spring1 = new JPanel();
- setSizes( spring1, 0, 10, 100 );
+ setSizes( spring1, SPRING_MIN_SIZE, SPRING_PREF_SIZE,
SPRING_MAX_SIZE );
column.add( spring1 );

- m_ProgressBar = createProgressBar();
- column.add( m_ProgressBar );
+ m_progressBar = createProgressBar();
+ column.add( m_progressBar );
final JPanel spring2 = new JPanel();
- setSizes( spring2, 0, 10, 100 );
+ setSizes( spring2, SPRING_MIN_SIZE, SPRING_PREF_SIZE,
SPRING_MAX_SIZE );
column.add( spring2 );
-
+
final JPanel spring3 = new JPanel();
- setSizes( spring3, 0, 10, 100 );
+ setSizes( spring3, SPRING_MIN_SIZE, SPRING_PREF_SIZE,
SPRING_MAX_SIZE );
column.add( spring3 );

- m_TextArea = createTextArea();
- column.add( m_TextArea );
+ m_textArea = createTextArea();
+ column.add( m_textArea );
final JPanel spring4 = new JPanel();
- setSizes( spring4, 0, 10, 100 );
+ setSizes( spring4, SPRING_MIN_SIZE, SPRING_PREF_SIZE,
SPRING_MAX_SIZE );
column.add( spring4 );
-
- m_FinishButton = createFinishButton();
- column.add( m_FinishButton );
-
+
+ m_finishButton = createFinishButton();
+ column.add( m_finishButton );
+
final JPanel spring5 = new JPanel();
- setSizes( spring5, 0, 10, 100 );
+ setSizes( spring5, SPRING_MIN_SIZE, SPRING_PREF_SIZE,
SPRING_MAX_SIZE );
column.add( spring5 );
-
- m_ProgressWindow.pack();
- m_ProgressWindow.setVisible( true );
+
+ m_progressWindow.pack();
+ m_progressWindow.setVisible( true );
}
-
+
+ /** The ActionListener method.
+ * Used to receive action events.
+ * @param event The action event.
+ */
public void actionPerformed( ActionEvent event )
{
System.out.println( event.toString() );
}
-
+
+ /** Start the installation.
+ * This method creates the Worker and ask the worker to get going,
+ * providing it with the ProgressIndicator to report back to.
+ * @throws Exception if something goes terribly wrong.
+ */
public void start()
throws Exception
{
ProgressIndicator indicator = new SwingProgress();
Worker w = Main.createWorker( indicator );
w.start();
- m_FinishButton.setEnabled( true );
+ m_finishButton.setEnabled( true );
}

+ /** Sets the sizes of a JPanel.
+ * This method should only be used for square panels.
+ * @param panel the JPanel to be sized.
+ * @param min the minimum size for both the height and width.
+ * @param pref the preferred size for both the height and width.
+ * @param max the maximum size for both the height and width.
+ */
private void setSizes( JPanel panel, int min, int pref, int max )
{
Dimension minDim = new Dimension( min, min );
@@ -125,26 +195,32 @@
panel.setMaximumSize( maxDim );
}

+ /** Creates the ProgressBar.
+ * @return a suitable JProgressBar to be used as a progressive value
indicator.
+ */
private JProgressBar createProgressBar()
{
- final Dimension minDim = new Dimension( 50, 10 );
- final Dimension prefDim = new Dimension( 300, 25 );
- final Dimension maxDim = new Dimension( 1200, 50 );
+ final Dimension minDim = new Dimension( VALUE_MIN_WIDTH, TEN );
+ final Dimension prefDim = new Dimension( VALUE_PREF_WIDTH,
TWENTY_FIVE );
+ final Dimension maxDim = new Dimension( VALUE_PREF_WIDTH, FIFTY );
JProgressBar bar = new JProgressBar();
bar.setStringPainted( true );
bar.setMinimumSize( minDim );
bar.setPreferredSize( prefDim );
bar.setMaximumSize( maxDim );
bar.setMinimum( 0 );
- bar.setMaximum( 100 );
+ bar.setMaximum( HUNDRED );
return bar;
}
-
+
+ /** Creates the TextArea.
+ * @return the Text Area to be used for reporting messages from the
worker.
+ */
private JTextArea createTextArea()
{
- final Dimension minDim = new Dimension( 50, 50 );
- final Dimension prefDim = new Dimension( 300, 300 );
- final Dimension maxDim = new Dimension( 1200, 1000 );
+ final Dimension minDim = new Dimension( VALUE_MIN_WIDTH, FIFTY );
+ final Dimension prefDim = new Dimension( VALUE_PREF_WIDTH,
THREE_HUNDRED );
+ final Dimension maxDim = new Dimension( VALUE_PREF_WIDTH, THOUSAND );
JTextArea area = new JTextArea();
area.setMinimumSize( minDim );
area.setPreferredSize( prefDim );
@@ -152,49 +228,60 @@
return area;
}

+ /** Creates the Finish button.
+ * @return a Button with the text "Finish" on it.
+ */
private JButton createFinishButton()
{
- final Dimension minDim = new Dimension( 20, 20 );
- final Dimension prefDim = new Dimension( 50, 30 );
- final Dimension maxDim = new Dimension( 100, 40 );
+ final Dimension minDim = new Dimension( TWENTY, TWENTY );
+ final Dimension prefDim = new Dimension( FIFTY, THIRTY );
+ final Dimension maxDim = new Dimension( HUNDRED, FORTY );
JButton button = new JButton( "Finish" );
button.setMinimumSize( minDim );
button.setPreferredSize( prefDim );
button.setMaximumSize( maxDim );
button.setEnabled( false );
- button.addActionListener( this );
+ button.addActionListener( this );
return button;
}
-
- public class SwingProgress
+
+ /** The ProgressIndicator implementation for the SwingInstaller.
+ */
+ class SwingProgress
implements ProgressIndicator
{
+ /** The Worker reports back some type of message.
+ * @param message the message to be shown to the user.
+ */
public void message( String message )
{
- m_TextArea.append( message );
- m_TextArea.append( "\n" );
+ m_textArea.append( message );
+ m_textArea.append( "\n" );
}
-
- public void error( String message )
- {
- m_TextArea.append( "Error: " + message );
- m_TextArea.append( "\n" );
- }
-
+
+ /** The Worker is indicating that a progressive value indicator is
+ * starting.
+ */
public void start()
{
}
-
+
+ /** The Worker is updating the progressive value indicator.
+ * @param percentage the completion percentage of the operation.
+ */
public void progress( int percentage )
{
- m_ProgressBar.setValue( percentage );
- m_ProgressBar.setString( percentage + "%" );
+ m_progressBar.setValue( percentage );
+ m_progressBar.setString( percentage + "%" );
}
-
+
+ /** The Worker is indicating that a progressive value indicator is
+ * finished.
+ */
public void finished()
{
}
}
}
-
-
+
+

Modified:
development/main/transit/installer/src/main/net/dpml/transit/installer/Worker.java
==============================================================================
---
development/main/transit/installer/src/main/net/dpml/transit/installer/Worker.java
(original)
+++
development/main/transit/installer/src/main/net/dpml/transit/installer/Worker.java
Sun Jan 16 19:12:53 2005
@@ -1,17 +1,17 @@
-/*
+/*
* Copyright 2004-2005 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -21,90 +21,131 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

-import java.net.URL;
-import java.net.URLConnection;
-
import java.util.Enumeration;

import java.util.jar.JarFile;
import java.util.jar.JarEntry;

-public class Worker
+/** The worker class for the Installer.
+ * All the activity within the installer, that is not visually oriented is
+ * controlled by this class.
+ */
+public final class Worker
{
+ /** Copy buffer size. */
private static final int BUFFER_SIZE = 10000;
-
- private File m_DpmlHome;
- private File m_AntLibDir;
- private File m_DevDir;
-
- private ProgressIndicator m_Progress;
- private int m_ProgressSize;
-
- public Worker( ProgressIndicator indicator,
- File dpmlHome, File antLib, File devDir )
- {
- m_DpmlHome = dpmlHome;
- m_AntLibDir = antLib;
- m_Progress = indicator;
- m_DevDir = devDir;
+
+ /** Multiplier to bring a ratio to a percentage. */
+ private static final int PERCENT_MULTIPLIER = 100;
+
+ /** Location of the DPML */
+ private File m_dpmlHome;
+
+ /** Location of the Ant Library directory. */
+ private File m_antLibDir;
+
+ /** Location of the current working directory.
+ * Not used at the moment.
+ */
+ private File m_devDir;
+
+ /** The ProgressIndicator to be used. */
+ private ProgressIndicator m_progress;
+
+ /** The final size of the progress to be visualized. */
+ private int m_progressSize;
+
+ /** Package protected constructor.
+ * @param indicator the ProgressIndicator to send messages and progress
+ * reporting to.
+ * @param dpmlHome the home directory of DPML, typically $HOME/.dpml
+ * @param antLib the directory of the Ant library, typically
$HOME/ant/lib
+ * @param devDir development directory, not currently used and should be
+ * passed the current directory.
+ */
+ Worker( ProgressIndicator indicator, File dpmlHome, File antLib, File
devDir )
+ {
+ m_dpmlHome = dpmlHome;
+ m_antLibDir = antLib;
+ m_progress = indicator;
+ m_devDir = devDir;
}
-
+
+ /** Start working.
+ * @throws Exception if something goes terribly wrong.
+ */
public void start()
throws Exception
{
- m_Progress.message( "Creating DPML Home." );
- if( ! m_DpmlHome.exists() )
- m_DpmlHome.mkdirs();
- m_Progress.message( "Creating Ant plugin library." );
- if( ! m_AntLibDir.exists() )
- m_AntLibDir.mkdirs();
+ m_progress.message( "Creating DPML Home." );
+
+ if( !m_dpmlHome.exists() )
+ {
+ m_dpmlHome.mkdirs();
+ }
+
+ m_progress.message( "Creating Ant plugin library." );
+
+ if( !m_antLibDir.exists() )
+ {
+ m_antLibDir.mkdirs();
+ }
+
InputStream dpml = getClass().getClassLoader().getResourceAsStream(
"dpml.jar" );
if( dpml == null )
{
System.err.println( "The install bundle is corrupt. Please
download it from http://www.dpml.net again." );
- System.exit(1);
+ System.exit( 1 );
}
- File tmp = File.createTempFile( "install", ".tmp", m_DpmlHome );
+ File tmp = File.createTempFile( "install", ".tmp", m_dpmlHome );
tmp.deleteOnExit();
FileOutputStream fos = new FileOutputStream( tmp );
copy( dpml, fos, false );
- unjar( tmp, m_DpmlHome );
+ unjar( tmp, m_dpmlHome );
tmp.delete();
-
+
InputStream antLib =
getClass().getClassLoader().getResourceAsStream( "antlib.jar" );
if( antLib == null )
{
System.err.println( "The install bundle is corrupt. Please
download it from http://www.dpml.net again." );
- System.exit(2);
+ System.exit( 2 );
}
- tmp = File.createTempFile( "install", ".tmp", m_AntLibDir );
+ tmp = File.createTempFile( "install", ".tmp", m_antLibDir );
tmp.deleteOnExit();
fos = new FileOutputStream( tmp );
copy( antLib, fos, false );
- unjar( tmp, m_AntLibDir );
+ unjar( tmp, m_antLibDir );
tmp.delete();
-
+
createPath();
-
+
InputStream readme =
getClass().getClassLoader().getResourceAsStream( "README.txt" );
if( readme != null )
+ {
copy( readme, System.out, false );
+ }
}
-
+
+ /** Unjar a jarFile to a particular directory.
+ *
+ * @param jarFile the JAR to be unjarred.
+ * @param toDir the directory that will receive the content of the Jar
file.
+ * @throws IOException if either the file can't be read or the result
can't be
+ * written.
+ */
private void unjar( File jarFile, File toDir )
throws IOException
{
- m_Progress.message( "Unjaring " + jarFile );
- m_Progress.start();
+ m_progress.message( "Unjaring " + jarFile );
+ m_progress.start();
JarFile jar = new JarFile( jarFile );
Enumeration entries = jar.entries();
- for( int counter=0; entries.hasMoreElements() ; counter++ )
+ for( int counter=0; entries.hasMoreElements(); counter++ )
{
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
@@ -118,15 +159,24 @@
{
InputStream in = jar.getInputStream( entry );
FileOutputStream out = new FileOutputStream( dest );
- m_ProgressSize = (int) entry.getSize();
+ m_progressSize = (int) entry.getSize();
copy( in, out, true );
in.close();
out.close();
}
}
- m_Progress.finished();
+ m_progress.finished();
}
-
+
+ /** Copy from one stream to another, and optionally report it to the
+ * ProgressIndicator.
+ * @param from the source input stream.
+ * @param to the destination output stream.
+ * @param report true if the copy should be reported to the
ProgressIndicator,
+ * false otherwise.
+ * @throws IOException if either the file can't be read or the result
can't be
+ * written.
+ */
private void copy( InputStream from, OutputStream to, boolean report )
throws IOException
{
@@ -139,80 +189,90 @@
byte[] data = new byte[ BUFFER_SIZE ];
bytesRead = in.read( data, 0, BUFFER_SIZE );
counter = counter + bytesRead;
- if( m_ProgressSize > 0 && report )
+ if( m_progressSize > 0 && report )
{
- m_Progress.progress( ( counter * 100 ) / m_ProgressSize );
+ m_progress.progress( ( counter * PERCENT_MULTIPLIER ) /
m_progressSize );
}
if( bytesRead != -1 )
+ {
out.write( data, 0, bytesRead );
+ }
} while( bytesRead != -1 );
out.flush();
}

+ /** Create the PATH for various operating systems.
+ */
private void createPath()
{
String os = System.getProperty( "os.name" ).toLowerCase();
if( os.indexOf( "win" ) >= 0 )
+ {
createPathInWindows();
+ }
createPathInNix();
}
-
+
+ /** Create the PATH for Unix/Linux.
+ */
private void createPathInNix()
{
-
+
}
-
+
+ /** Create the PATH for Windows.
+ */
private void createPathInWindows()
{
}
-
+
/* Not used. Future?
private void copy( File file, File toDir )
throws IOException
{
- m_Progress.message( "Copying " + file + " to " + file );
- m_Progress.start();
+ m_progress.message( "Copying " + file + " to " + file );
+ m_progress.start();
toDir.mkdirs();
String name = file.getName();
File destFile = new File( toDir, name );
-
+
FileInputStream in = new FileInputStream( file );
FileOutputStream out = new FileOutputStream( destFile );
-
- m_ProgressSize = file.length();
+
+ m_progressSize = file.length();
copy( in, out );
-
+
in.close();
out.close();
- m_Progress.finished();
+ m_progress.finished();
}
-*/
+*/
/* Future use
private File download( String url )
throws IOException
- {
+ {
URL download = new URL( url );
- m_Progress.message( "Connecting to " + download.getHost() );
+ m_progress.message( "Connecting to " + download.getHost() );

URLConnection conn = download.openConnection();
conn.connect();
- m_ProgressSize = conn.getContentLength();
-
- m_Progress.message( "Downloading " + url );
- m_Progress.start();
+ m_progressSize = conn.getContentLength();
+
+ m_progress.message( "Downloading " + url );
+ m_progress.start();
InputStream in = conn.getInputStream();
-
+
File tmp = File.createTempFile( "magic", null );
tmp.deleteOnExit();
-
+
FileOutputStream out = new FileOutputStream( tmp );
-
+
copy( in, out );
in.close();
out.close();
- m_Progress.finished();
- return tmp;
+ m_progress.finished();
+ return tmp;
}
*/
-
+
}



  • svn commit: r1501 - in development/main/transit: handler/src/main/net/dpml/transit/artifact installer/src/main/net/dpml/transit/installer, niclas, 01/16/2005

Archive powered by MHonArc 2.6.24.

Top of Page