WOBootstrap with Transitive Dependencies

From: Henrique Prange (hprang..mail.com)
Date: Thu Nov 23 2006 - 13:43:37 EST

  • Next message: Henrique Prange: "WOProject Dependencies with Version Range"

    Hi Ulrich,

    I have implemented the generation of POMs with transitive dependencies
    for each JAR of WebObjects. The file with the patch for the entire
    project of maven-wobootstrap-plugin is attached.

    I also made some enhancements in tests. I have just made tests in
    Windows environment. Please, tell me if any problem raise in Mac.

    I apologize for the long time taken to finish this job.

    Cheers,

    Henrique

    -- 
    

    \o/ Henrique Prange, Moleque de Idéias Educaçăo e Tecnologia Ltda | Phone: 55-21-2710-0178 E-mail: hprang..oleque.com.br / \ http://www.moleque.com.br

    Index: .classpath =================================================================== --- .classpath (revision 3666) +++ .classpath (working copy) ..-1,10 +1,10 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src/main/java"/> - <classpathentry kind="src" path="src/test/java"/> - <classpathentry kind="src" path="src/main/resources"/> - <classpathentry kind="src" path="src/test/resources"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> - <classpathentry kind="output" path="bin"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="src" path="src/test/java"/> + <classpathentry excluding="**" kind="src" output="src/main/resources" path="src/main/resources"/> + <classpathentry excluding="**" kind="src" output="src/test/resources" path="src/test/resources"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> Index: pom.xml =================================================================== --- pom.xml (revision 3666) +++ pom.xml (working copy) ..-4,8 +4,8 @@ <artifactId>maven2</artifactId> <groupId>org.objectstyle.woproject.maven2</groupId> <version>2.0-SNAPSHOT</version> - </parent> - + </parent> + <modelVersion>4.0.0</modelVersion> <artifactId>maven-wobootstrap-plugin</artifactId> <packaging>maven-plugin</packaging> ..-10,15 +10,19 @@ <artifactId>maven-wobootstrap-plugin</artifactId> <packaging>maven-plugin</packaging> <name>Maven WOBootstrap Plugin</name> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> + + <build> + <defaultGoal>package</defaultGoal> + </build> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-embedder</artifactId> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-embedder</artifactId> </dependency> <dependency> <groupId>ant</groupId> ..-45,9 +49,11 @@ <artifactId>easymock</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>xmlunit</groupId> + <artifactId>xmlunit</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> </dependencies> - - <build> - <defaultGoal>package</defaultGoal> - </build> </project> \ No newline at end of file Index: src/main/java/org/objectstyle/woproject/maven2/wobootstrap/BootstrapMojo.java =================================================================== --- src/main/java/org/objectstyle/woproject/maven2/wobootstrap/BootstrapMojo.java (revision 3666) +++ src/main/java/org/objectstyle/woproject/maven2/wobootstrap/BootstrapMojo.java (working copy) ..-83,6 +83,7 @@ import org.apache.maven.project.ProjectBuildingException; import org.codehaus.plexus.util.dag.CycleDetectedException; import org.objectstyle.woproject.maven2.wobootstrap.utils.MacOsWebobjectsLocator; +import org.objectstyle.woproject.maven2.wobootstrap.utils.PomGenerator; import org.objectstyle.woproject.maven2.wobootstrap.utils.UnixWebobjectsLocator; import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator; import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsUtils; ..-96,8 +97,8 @@ *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> *..ince 2.0 */ -public class BootstrapMojo extends AbstractMojo -{ +public class BootstrapMojo extends AbstractMojo { + /** * Maven embedder used to call maven plug-ins functions */ ..-143,48 +144,38 @@ /** * Creates a new BootstrapMojo. Verify the OS platform and load the * properties of this plug-ing. - *..hrows MojoExecutionException + * + *..hrows MojoExecutionException + * if any problem occurs during bootstrap execution */ - public BootstrapMojo() throws MojoExecutionException - { + public BootstrapMojo() throws MojoExecutionException { super(); - - if( SystemUtils.IS_OS_MAC_OSX ) - { + if (SystemUtils.IS_OS_MAC_OSX) { locator = new MacOsWebobjectsLocator(); - } - else if( SystemUtils.IS_OS_WINDOWS ) - { + } else if (SystemUtils.IS_OS_WINDOWS) { locator = new WindowsWebobjectsLocator(); - } - else if( SystemUtils.IS_OS_UNIX ) - { + } else if (SystemUtils.IS_OS_UNIX) { locator = new UnixWebobjectsLocator(); + } else { + throw new MojoExecutionException("Unsupported OS platform."); } - else - { - throw new MojoExecutionException( "Unsupported OS platform." ); - } - - InputStream propertiesInputStream = BootstrapMojo.class.getResourceAsStream( "/bootstrap.properties" ); - try - { - pluginProperties.load( propertiesInputStream ); - } - catch( IOException exception ) - { - throw new MojoExecutionException( "Cannot load plug-in properties." ); - } + initialize(); + } - installFileProperties = new Properties(); + /** + * This constructor is only for testing purpose. + * + *..aram locator + * A locator for WebObjects resources + *..hrows MojoExecutionException + * if any problem occurs during bootstrap execution + */ + BootstrapMojo(WebobjectsLocator locator) throws MojoExecutionException { + this.locator = locator; - installFileProperties.setProperty( "groupId", pluginProperties.getProperty( "woproject.convention.group" ) ); - installFileProperties.setProperty( "version", WebobjectsUtils.getWebobjectsVersion( locator ) ); - installFileProperties.setProperty( "packaging", "jar" ); - - installFileProperties.setProperty( "generatePom", "true" ); + initialize(); } /* ..-192,23 +183,19 @@ * *..ee org.apache.maven.plugin.Mojo#execute() */ - public void execute() throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { initializeEmbedder(); - File[] jars = WebobjectsUtils.getWebobjectsJars( locator ); + File[] jars = WebobjectsUtils.getWebobjectsJars(locator); - if( jars == null ) - { - throw new MojoExecutionException( "WebObjects lib folder is missing. Maybe WebObjects isn't installed." ); + if (jars == null) { + throw new MojoExecutionException("WebObjects lib folder is missing. Maybe WebObjects isn't installed."); } - for( int i = 0; i < jars.length; i++ ) - { - Properties properties = fillProperties( jars[i] ); + for (int i = 0; i < jars.length; i++) { + Properties properties = fillProperties(jars[i]); - if( !executeInstallFile( properties ) ) - { - getLog().warn( "Cannot import the following jar: " + jars[i].getName() ); + if (!executeInstallFile(properties)) { + getLog().warn("Cannot import the following jar: " + jars[i].getName()); } } } ..-225,36 +212,26 @@ * <li>artifactId</li> * </ul> * - *..aram properties The defined properties - *..hrows MojoExecutionException If any exception occur during embedder - * execution. + *..aram properties + * The defined properties + *..hrows MojoExecutionException + * If any exception occur during embedder execution. */ - protected boolean executeInstallFile( Properties properties ) throws MojoExecutionException - { - if( properties == null ) - { + protected boolean executeInstallFile(Properties properties) throws MojoExecutionException { + if (properties == null) { return false; } - try - { - embedder.execute( pom, Collections.singletonList( "install:install-file" ), eventMonitor, new ConsoleDownloadMonitor(), properties, targetDirectory ); - } - catch( CycleDetectedException exception ) - { - throw new MojoExecutionException( "Error: cycle detected." ); - } - catch( LifecycleExecutionException exception ) - { - throw new MojoExecutionException( "Error in lifecycle execution." ); - } - catch( BuildFailureException exception ) - { - throw new MojoExecutionException( "Error: build failure." ); - } - catch( DuplicateProjectException exception ) - { - throw new MojoExecutionException( "Error: duplicate project." ); + try { + embedder.execute(pom, Collections.singletonList("install:install-file"), eventMonitor, new ConsoleDownloadMonitor(), properties, targetDirectory); + } catch (CycleDetectedException exception) { + throw new MojoExecutionException("Error: cycle detected."); + } catch (LifecycleExecutionException exception) { + throw new MojoExecutionException("Error in lifecycle execution."); + } catch (BuildFailureException exception) { + throw new MojoExecutionException("Error: build failure."); + } catch (DuplicateProjectException exception) { + throw new MojoExecutionException("Error: duplicate project."); } return true; ..-263,21 +240,34 @@ /** * Fill the contents of a properties based on a JAR file. * - *..aram jar The JAR file + *..aram jar + * The JAR file *..eturn Returns the populated properties or <code>null</code> if cannot * map the JAR file */ - protected Properties fillProperties( File jar ) - { - String artifactId = getArtifactIdForJar( jar ); + protected Properties fillProperties(File jar) { + String artifactId = getArtifactIdForJar(jar); - if( artifactId == null ) - { + if (artifactId == null) { return null; } - installFileProperties.setProperty( "file", jar.getAbsolutePath() ); - installFileProperties.setProperty( "artifactId", artifactId ); + installFileProperties.setProperty("file", jar.getAbsolutePath()); + installFileProperties.setProperty("artifactId", artifactId); + + try { + File tempPom = File.createTempFile("pom-", ".xml"); + + tempPom.deleteOnExit(); + + PomGenerator generator = new PomGenerator(installFileProperties); + + generator.writeModel(tempPom); + + installFileProperties.setProperty("pomFile", tempPom.getAbsolutePath()); + } catch (IOException exception) { + getLog().info("Cannot create a pom file for " + artifactId); + } return installFileProperties; } ..-285,14 +275,13 @@ /** * Resolve the artifactId for a specific JAR file. * - *..aram jar The JAR file + *..aram jar + * The JAR file *..eturn Returns the artifatId or <code>null</code> if cannot find a key * that match the JAR file */ - protected String getArtifactIdForJar( File jar ) - { - if( jar == null ) - { + protected String getArtifactIdForJar(File jar) { + if (jar == null) { return null; } ..-298,13 +287,28 @@ loadNamesMap(); - String jarName = FilenameUtils.getBaseName( jar.getAbsolutePath() ); + String jarName = FilenameUtils.getBaseName(jar.getAbsolutePath()); - return (String) namesMap.get( jarName.toLowerCase() ); + return (String) namesMap.get(jarName.toLowerCase()); } - private void initializeEmbedder() throws MojoExecutionException - { + private void initialize() throws MojoExecutionException { + InputStream propertiesInputStream = BootstrapMojo.class.getResourceAsStream("/bootstrap.properties"); + + try { + pluginProperties.load(propertiesInputStream); + } catch (IOException exception) { + throw new MojoExecutionException("Cannot load plug-in properties."); + } + + installFileProperties = new Properties(); + + installFileProperties.setProperty("groupId", pluginProperties.getProperty("woproject.convention.group")); + installFileProperties.setProperty("version", WebobjectsUtils.getWebobjectsVersion(locator)); + installFileProperties.setProperty("packaging", "jar"); + } + + private void initializeEmbedder() throws MojoExecutionException { embedder = new MavenEmbedder(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ..-309,16 +313,13 @@ ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - embedder.setClassLoader( classLoader ); - embedder.setLogger( new MavenEmbedderConsoleLogger() ); + embedder.setClassLoader(classLoader); + embedder.setLogger(new MavenEmbedderConsoleLogger()); - try - { + try { embedder.start(); - } - catch( MavenEmbedderException exception ) - { - throw new MojoExecutionException( "Cannot start maven embedder." ); + } catch (MavenEmbedderException exception) { + throw new MojoExecutionException("Cannot start maven embedder."); } targetDirectory = SystemUtils.getUserDir(); ..-323,40 +324,34 @@ targetDirectory = SystemUtils.getUserDir(); - File pomFile = new File( targetDirectory, "pom.xml" ); + File pomFile = new File(targetDirectory, "pom.xml"); - try - { - pom = embedder.readProject( pomFile ); - } - catch( ProjectBuildingException exception ) - { - throw new MojoExecutionException( "Cannot read project POM." ); + try { + pom = embedder.readProject(pomFile); + } catch (ProjectBuildingException exception) { + throw new MojoExecutionException("Cannot read project POM."); } - eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) ); + eventMonitor = new DefaultEventMonitor(new PlexusLoggerAdapter(new MavenEmbedderConsoleLogger())); } - - private void loadNamesMap() - { - if( namesMap != null ) - { + + private void loadNamesMap() { + if (namesMap != null) { return; } - String defaultNames = pluginProperties.getProperty( "webobjects.default.names" ); + String defaultNames = pluginProperties.getProperty("webobjects.default.names"); - String originalNames[] = StringUtils.split( defaultNames, "," ); + String originalNames[] = StringUtils.split(defaultNames, ","); - String conventionedNames = pluginProperties.getProperty( "woproject.convention.names" ); + String conventionedNames = pluginProperties.getProperty("woproject.convention.names"); - String artifactIds[] = StringUtils.split( conventionedNames, "," ); + String artifactIds[] = StringUtils.split(conventionedNames, ","); namesMap = new HashMap(); - for( int i = 0; i < originalNames.length; i++ ) - { - namesMap.put( originalNames[i].toLowerCase(), artifactIds[i] ); + for (int i = 0; i < originalNames.length; i++) { + namesMap.put(originalNames[i].toLowerCase(), artifactIds[i]); } } } Index: src/main/java/org/objectstyle/woproject/maven2/wobootstrap/utils/WindowsWebobjectsLocator.java =================================================================== --- src/main/java/org/objectstyle/woproject/maven2/wobootstrap/utils/WindowsWebobjectsLocator.java (revision 3666) +++ src/main/java/org/objectstyle/woproject/maven2/wobootstrap/utils/WindowsWebobjectsLocator.java (working copy) ..-64,19 +64,16 @@ *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> *..ince 2.0 */ -public class WindowsWebobjectsLocator extends AbstractWebobjectsLocator -{ +public class WindowsWebobjectsLocator extends AbstractWebobjectsLocator { /** - * The deafult WebObjects root variable on Windows - *..eprecated New versions of JDK throw Exceptions about getenv not more supported. Please use - * the <code>next.root</code> property instead + * The deafult WebObjects root property on Windows */ - protected static final String DEFAULT_WO_ROOT_VARIABLE = "NEXT_ROOT"; + protected static final String DEFAULT_WO_ROOT_PROPERTY = "next.root"; /** - * The deafult WebObjects root property on Windows + * The deafult WebObjects root variable on Windows */ - protected static final String DEFAULT_WO_ROOT_PROPERTY = "next.root"; + protected static final String DEFAULT_WO_ROOT_VARIABLE = "NEXT_ROOT"; /** * The name of the environment that contains the path for WebObjects folder ..-81,26 +78,23 @@ /** * The name of the environment that contains the path for WebObjects folder */ - protected final String woRootVariable; + protected String woRootVariable; /** * Creates a new <code>WindowsWebobjectsLocator</code> using the default - * WebObjects root variable. + * WebObjects root property. If this property doesn't exists or is equals to + * <code>null</code>, try to find the value using system environment. + * + *..hrows SecurityException + * if a security manager exists and its checkPermission method + * doesn't allow access to the environment variable name */ - public WindowsWebobjectsLocator() - { + public WindowsWebobjectsLocator() { woRootVariable = System.getProperty(DEFAULT_WO_ROOT_PROPERTY); - } - /** - * Creates a new <code>WindowsWebobjectsLocator</code> using the variable - * passed by parameter. - * - *..aram woRootVariable The WebObjects root variable - */ - public WindowsWebobjectsLocator( String woRootVariable ) - { - this.woRootVariable = woRootVariable; + if (woRootVariable == null) { + woRootVariable = System.getenv(DEFAULT_WO_ROOT_VARIABLE); + } } /* ..-106,18 +100,16 @@ /* * (non-Javadoc) * - *..ee org.objectstyle.woproject.maven2.utils.WebobjectsLocator#webobjectsRootDirectory() + *..ee org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator#webobjectsRootDirectory() */ - public File getWebobjectsRootFolder() - { + public File getWebobjectsRootFolder() { String nextRoot = woRootVariable; - if( nextRoot == null ) - { + if (nextRoot == null) { return null; } - return new File( nextRoot ); + return new File(nextRoot); } } Index: src/main/java/org/objectstyle/woproject/maven2/wobootstrap/utils/PomGenerator.java =================================================================== --- src/main/java/org/objectstyle/woproject/maven2/wobootstrap/utils/PomGenerator.java +++ src/main/java/org/objectstyle/woproject/maven2/wobootstrap/utils/PomGenerator.java ..-0,0 +1,153 @@ +/** + * Criado em 22/11/2006 + */ +package org.objectstyle.woproject.maven2.wobootstrap.utils; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.codehaus.plexus.util.IOUtil; + +/** + * This class generates maven project description (POM) for an artifact. The + * generated model includes the transitive dependencies configured into + * bootstrap.properties file. + * + *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> + *..ince 2.0 + */ +public class PomGenerator { + + /** + * Properties that contains the transitive dependencies. + */ + protected static Properties dependencyProperties; + + /** + * The version of the pom model. + */ + private static final String MODEL_VERSION = "4.0.0"; + + /** + * Lazy initialization for <code>dependencieProperties</code>. + */ + private static void loadDependecyProperties() { + + if (dependencyProperties != null) { + return; + } + + dependencyProperties = new Properties(); + + try { + dependencyProperties.load(PomGenerator.class.getResourceAsStream("/bootstrap.properties")); + } catch (IOException exception) { + // TODO: hprange, write an info to log instead + exception.printStackTrace(); + } + } + + /** + * The artifact id. + */ + protected final String artifactId; + + /** + * The group id. + */ + protected final String groupId; + + /** + * The version of the artifact. + */ + protected final String version; + + /** + * Creates a new model generator based on some artifact properties. + * + *..aram properties + * The artifact properties + */ + public PomGenerator(Properties properties) { + + if (properties == null) { + throw new IllegalArgumentException("The properties must not be null"); + } + + groupId = properties.getProperty("groupId"); + artifactId = properties.getProperty("artifactId"); + version = properties.getProperty("version"); + } + + /** + * Generates the model (POM) for the defined artifact including its + * transitive dependencies. + * + *..eturn Returns a <code>Model</code> object + */ + public Model generateModel() { + + Model model = new Model(); + + model.setGroupId(groupId); + model.setArtifactId(artifactId); + model.setVersion(version); + model.setModelVersion(MODEL_VERSION); + + loadDependecyProperties(); + + String dependenciesList = dependencyProperties.getProperty("transitive.dependencies." + model.getArtifactId()); + + if (dependenciesList == null) { + return model; + } + + String[] dependencies = StringUtils.split(dependenciesList, ","); + + for (int i = 0; i < dependencies.length; i++) { + String dependencyArtifactId = dependencies[i]; + + Dependency dependency = new Dependency(); + + dependency.setGroupId(model.getGroupId()); + dependency.setArtifactId(StringUtils.trim(dependencyArtifactId)); + dependency.setVersion(model.getVersion()); + + model.addDependency(dependency); + } + + return model; + } + + /** + * Writes the model (POM) into the specified file. + * + *..aram file + * The file + */ + public void writeModel(File file) { + + if (file == null) { + throw new NullPointerException("Cannot write to a null file."); + } + + FileWriter writer = null; + + try { + writer = new FileWriter(file); + + new MavenXpp3Writer().write(writer, generateModel()); + } catch (IOException exception) { + // TODO: hprange, write an info to log instead + exception.printStackTrace(); + } finally { + IOUtil.close(writer); + } + } +} Index: src/main/resources/bootstrap.properties =================================================================== --- src/main/resources/bootstrap.properties (revision 3666) +++ src/main/resources/bootstrap.properties (working copy) ..-58,3 +58,13 @@ java-wo-jsp-servlet,\ java-wo-smil,\ java-xml + +#Transitive dependencies for WebObjects jars +transitive.dependencies.java-dtw = java-webobjects, java-foundation, java-eo-control, java-eo-access, java-eo-project, java-dtw-generation +transitive.dependencies.java-dtw-generation = java-foundation, java-webobjects, java-eo-control +transitive.dependencies.java-wo-extensions = java-webobjects, java-foundation +transitive.dependencies.java-webobjects = java-foundation, java-xml, java-eo-control +transitive.dependencies.java-eo-access = java-foundation, java-eo-control +transitive.dependencies.java-eo-control = java-foundation +transitive.dependencies.java-eo-project = java-foundation, java-eo-access, java-webobjects +transitive.dependencies.java-jdbc-adaptor = java-foundation, java-eo-access, java-eo-control Index: src/test/java/org/objectstyle/woproject/maven2/utils/TestWebObjectsUtils.java =================================================================== --- src/test/java/org/objectstyle/woproject/maven2/utils/TestWebObjectsUtils.java (revision 3671) +++ src/test/java/org/objectstyle/woproject/maven2/utils/TestWebObjectsUtils.java (working copy) ..-1,148 +0,0 @@ -/* ==================================================================== - * - * The ObjectStyle Group Software License, Version 1.0 - * - * Copyright (c) 2006 The ObjectStyle Group, - * and individual authors of the software. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the - * ObjectStyle Group (http://objectstyle.org/)." - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * - * 4. The names "ObjectStyle Group" and "Cayenne" - * must not be used to endorse or promote products derived - * from this software without prior written permission. For written - * permission, please contact andru..bjectstyle.org. - * - * 5. Products derived from this software may not be called "ObjectStyle" - * nor may "ObjectStyle" appear in their names without prior written - * permission of the ObjectStyle Group. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the ObjectStyle Group. For more - * information on the ObjectStyle Group, please see - * <http://objectstyle.org/>. - * - */ -package org.objectstyle.woproject.maven2.utils; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.commons.io.FileUtils; -import org.easymock.EasyMock; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsUtils; - -/** - *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> - */ -public class TestWebObjectsUtils extends TestCase -{ - protected WebobjectsLocator mockLocator; - - /* - * (non-Javadoc) - * - *..ee junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - - mockLocator = (WebobjectsLocator) EasyMock.createMock( WebobjectsLocator.class ); - } - - public void testCheckWebObjectsVersion() throws Exception - { - File versionFile = FileUtils.toFile( getClass().getResource( "/version.plist" ) ); - - EasyMock.expect( mockLocator.getWebobjectsVersionFile() ).andReturn( versionFile ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertEquals( "5.2.4", WebobjectsUtils.getWebobjectsVersion( mockLocator ) ); - } - - public void testFileCannotBeFound() throws Exception - { - File versionFile = new File( FileUtils.toFile( getClass().getResource( "/" ) ), "inexistent.txt" ); - - EasyMock.expect( mockLocator.getWebobjectsVersionFile() ).andReturn( versionFile ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertNull( WebobjectsUtils.getWebobjectsVersion( mockLocator ) ); - } - - public void testNullVersionFile() throws Exception - { - EasyMock.expect( mockLocator.getWebobjectsVersionFile() ).andReturn( null ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertNull( WebobjectsUtils.getWebobjectsVersion( mockLocator ) ); - } - - public void testNullWebObjectsLocator() throws Exception - { - assertNull( WebobjectsUtils.getWebobjectsVersion( null ) ); - } - - public void testObtainWebObjectsLibs() throws Exception - { - File jarsFolder = FileUtils.toFile( getClass().getResource( "/mock-jar1.jar" ) ).getParentFile(); - - EasyMock.expect( mockLocator.getWebobjectsLibFolder() ).andReturn( jarsFolder ); - - EasyMock.replay( new Object[] { mockLocator } ); - - File[] foundLibs = WebobjectsUtils.getWebobjectsJars( mockLocator ); - - assertEquals( 2, foundLibs.length ); - } - - public void testWebObjectsJarsWithNullLocator() throws Exception - { - assertNull( WebobjectsUtils.getWebobjectsJars( null ) ); - } - - public void testWebObjectsJarsWithNullLibFolder() throws Exception - { - EasyMock.expect( mockLocator.getWebobjectsLibFolder() ).andReturn( null ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertNull( WebobjectsUtils.getWebobjectsJars( mockLocator ) ); - } -} Index: src/test/java/org/objectstyle/woproject/maven2/utils/TestWebobjectsLocator.java =================================================================== --- src/test/java/org/objectstyle/woproject/maven2/utils/TestWebobjectsLocator.java (revision 3666) +++ src/test/java/org/objectstyle/woproject/maven2/utils/TestWebobjectsLocator.java (working copy) ..-1,130 +0,0 @@ -/* ==================================================================== - * - * The ObjectStyle Group Software License, Version 1.0 - * - * Copyright (c) 2006 The ObjectStyle Group, - * and individual authors of the software. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the - * ObjectStyle Group (http://objectstyle.org/)." - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * - * 4. The names "ObjectStyle Group" and "Cayenne" - * must not be used to endorse or promote products derived - * from this software without prior written permission. For written - * permission, please contact andru..bjectstyle.org. - * - * 5. Products derived from this software may not be called "ObjectStyle" - * nor may "ObjectStyle" appear in their names without prior written - * permission of the ObjectStyle Group. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the ObjectStyle Group. For more - * information on the ObjectStyle Group, please see - * <http://objectstyle.org/>. - * - */ -package org.objectstyle.woproject.maven2.utils; - -import junit.framework.TestCase; - -import org.apache.commons.lang.SystemUtils; -import org.objectstyle.woproject.maven2.wobootstrap.utils.MacOsWebobjectsLocator; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WindowsWebobjectsLocator; - -/** - *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> - */ -public class TestWebobjectsLocator extends TestCase -{ - protected WebobjectsLocator locator; - - /* - * (non-Javadoc) - * - *..ee junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - - if( SystemUtils.IS_OS_WINDOWS ) - { - locator = new WindowsWebobjectsLocator(); - } - - if( SystemUtils.IS_OS_MAC_OSX ) - { - locator = new MacOsWebobjectsLocator(); - } - } - - /** - * I know it's not good, but if you don't have WebObjects installed, forget. - * This test will fail. - * - *..hrows Exception - */ - public void testCheckWebObjectsVersionFile() throws Exception - { - assertNotNull( locator.getWebobjectsVersionFile() ); - } - - public void testFindWebObjectsRootFolder() throws Exception - { - assertNotNull( locator.getWebobjectsRootFolder() ); - } - - /** - * I know it's not good, but if you don't have WebObjects installed, forget. - * This test will fail. - * - *..hrows Exception - */ - public void testWebObjectsLibsFolder() throws Exception - { - assertNotNull( locator.getWebobjectsLibFolder() ); - } - - public void testWebObjectsRootFolderCannotBeFoundOnWindows() throws Exception - { - if( SystemUtils.IS_OS_WINDOWS ) - { - locator = new WindowsWebobjectsLocator( "an_inexistent_evnvar_for_test" ); - - assertNull( locator.getWebobjectsRootFolder() ); - assertNull( locator.getWebobjectsLibFolder() ); - assertNull( locator.getWebobjectsVersionFile() ); - } - } -} Index: src/test/java/org/objectstyle/woproject/maven2/wobootstrap/TestBootstrapMojo.java =================================================================== --- src/test/java/org/objectstyle/woproject/maven2/wobootstrap/TestBootstrapMojo.java (revision 3666) +++ src/test/java/org/objectstyle/woproject/maven2/wobootstrap/TestBootstrapMojo.java (working copy) ..-53,137 +53,130 @@ * <http://objectstyle.org/>. * */ -package org.objectstyle.woproject.maven2.wobootstrap; - -import java.io.File; -import java.util.Properties; - -import junit.framework.TestCase; - -import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.easymock.EasyMock; +package org.objectstyle.woproject.maven2.wobootstrap; + +import java.io.File; +import java.util.Properties; + +import junit.framework.TestCase; + +import org.apache.commons.io.FileUtils; +import org.apache.maven.plugin.MojoExecutionException; +import org.easymock.EasyMock; import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator; - -/** - * Criado em 30/09/2006 - */ - -/** - *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> - */ -public class TestBootstrapMojo extends TestCase -{ - protected String input[]; - - protected BootstrapMojo mojo; - - protected String output[]; - - /* - * (non-Javadoc) - * - *..ee junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - - input = new String[] { "c:/JavaDirectToWeb.jar", "c:/JavaFoundation.jar", "c:/javaeoutil.jar", "c:/JavaXML.jar" }; - - output = new String[] { "java-dtw", "java-foundation", "java-eo-util", "java-xml" }; - - mojo = new BootstrapMojo(); - } - - public void testArtifatIdConvention() throws Exception - { - for( int i = 0; i < input.length; i++ ) - { - File jar = new File( input[i] ); - - assertEquals( output[i], mojo.getArtifactIdForJar( jar ) ); - } - } - - public void testCaseInsensitiveNameMapping() throws Exception - { - for( int i = 0; i < input.length; i++ ) - { - input[i] = input[i].toLowerCase(); - } - - for( int i = 0; i < input.length; i++ ) - { - File jar = new File( input[i] ); - - assertEquals( output[i], mojo.getArtifactIdForJar( jar ) ); - } - } - - public void testExecuteEmbedderWithNullProperties() throws Exception - { - assertFalse( mojo.executeInstallFile( null ) ); - } - - public void testFillValidProperties() throws Exception - { - File resourcesPath = FileUtils.toFile( getClass().getResource( "/" ) ); - - String filePath = "JavaWOExtensions.jar"; - - File mockJar = new File( resourcesPath, filePath ); - - Properties properties = mojo.fillProperties( mockJar ); - - assertEquals( "webobjects.apple", properties.getProperty( "groupId" ) ); - assertNotNull( properties.getProperty( "version" ) ); - assertEquals( "jar", properties.getProperty( "packaging" ) ); - assertEquals( mockJar.getAbsolutePath(), properties.getProperty( "file" ) ); - assertEquals( "java-wo-extensions", properties.getProperty( "artifactId" ) ); - } - - public void testNoJarMapping() throws Exception - { - String filePath = "c:\\JavaWOExtensionsXXX.jar"; - - File invalidJar = new File( filePath ); - - Properties properties = mojo.fillProperties( invalidJar ); - - assertNull( properties ); - } - - public void testNullJarFile() throws Exception - { - assertNull( mojo.getArtifactIdForJar( null ) ); - assertNull( mojo.fillProperties( null ) ); - } - - public void testWebObjectsNotInstalled() throws Exception - { - //TODO: fix me - //problem with sure fire and classpath (maven stuff used for tests is 2.0.0 maven embedder requires 2.0.4) - if(5 == 5) { - return; - } - WebobjectsLocator mockLocator = (WebobjectsLocator) EasyMock.createMock( WebobjectsLocator.class ); - - EasyMock.expect( mockLocator.getWebobjectsLibFolder() ).andReturn( null ); - - mojo.locator = mockLocator; - - EasyMock.replay( new Object[] { mockLocator } ); - - try - { - mojo.execute(); - - fail( "WebOjects not installed, must throws an exception." ); - } - catch( MojoExecutionException exception ) - { - assertEquals( "WebObjects lib folder is missing. Maybe WebObjects isn't installed.", exception.getMessage() ); - } - } -} + +/** + * Criado em 30/09/2006 + */ + +/** + *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> + */ +public class TestBootstrapMojo extends TestCase { + protected String input[]; + + protected BootstrapMojo mojo; + + protected String output[]; + + public void notTestWebObjectsNotInstalled() throws Exception { + // TODO: fix me + // problem with sure fire and classpath (maven stuff used for tests is + // 2.0.0 maven embedder requires 2.0.4) + + WebobjectsLocator mockLocator = (WebobjectsLocator) EasyMock.createMock(WebobjectsLocator.class); + + EasyMock.expect(mockLocator.getWebobjectsLibFolder()).andReturn(null); + + mojo.locator = mockLocator; + + EasyMock.replay(new Object[] { mockLocator }); + + try { + mojo.execute(); + + fail("WebOjects not installed, must throws an exception."); + } catch (MojoExecutionException exception) { + assertEquals("WebObjects lib folder is missing. Maybe WebObjects isn't installed.", exception.getMessage()); + } + } + + /* + * (non-Javadoc) + * + *..ee junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + input = new String[] { "c:/JavaDirectToWeb.jar", "c:/JavaFoundation.jar", "c:/javaeoutil.jar", "c:/JavaXML.jar" }; + + output = new String[] { "java-dtw", "java-foundation", "java-eo-util", "java-xml" }; + + File versionFile = FileUtils.toFile(getClass().getResource("/version.plist")); + + WebobjectsLocator mockLocator = (WebobjectsLocator) EasyMock.createMock(WebobjectsLocator.class); + + EasyMock.expect(mockLocator.getWebobjectsVersionFile()).andReturn(versionFile); + + EasyMock.replay(new Object[] { mockLocator }); + + mojo = new BootstrapMojo(mockLocator); + } + + public void testArtifatIdConvention() throws Exception { + for (int i = 0; i < input.length; i++) { + File jar = new File(input[i]); + + assertEquals(output[i], mojo.getArtifactIdForJar(jar)); + } + } + + public void testCaseInsensitiveNameMapping() throws Exception { + for (int i = 0; i < input.length; i++) { + input[i] = input[i].toLowerCase(); + } + + for (int i = 0; i < input.length; i++) { + File jar = new File(input[i]); + + assertEquals(output[i], mojo.getArtifactIdForJar(jar)); + } + } + + public void testExecuteEmbedderWithNullProperties() throws Exception { + assertFalse(mojo.executeInstallFile(null)); + } + + public void testFillValidProperties() throws Exception { + File resourcesPath = FileUtils.toFile(getClass().getResource("/")); + + String filePath = "JavaWOExtensions.jar"; + + File mockJar = new File(resourcesPath, filePath); + + Properties properties = mojo.fillProperties(mockJar); + + assertEquals("webobjects.apple", properties.getProperty("groupId")); + assertNotNull(properties.getProperty("version")); + assertEquals("jar", properties.getProperty("packaging")); + assertEquals(mockJar.getAbsolutePath(), properties.getProperty("file")); + assertEquals("java-wo-extensions", properties.getProperty("artifactId")); + assertNotNull(properties.getProperty("pomFile")); + } + + public void testNoJarMapping() throws Exception { + String filePath = "c:\\JavaWOExtensionsXXX.jar"; + + File invalidJar = new File(filePath); + + Properties properties = mojo.fillProperties(invalidJar); + + assertNull(properties); + } + + public void testNullJarFile() throws Exception { + assertNull(mojo.getArtifactIdForJar(null)); + assertNull(mojo.fillProperties(null)); + } +} Index: src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestWebObjectsUtils.java =================================================================== --- src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestWebObjectsUtils.java (revision 3671) +++ src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestWebObjectsUtils.java (working copy) ..-52,97 +52,86 @@ * information on the ObjectStyle Group, please see * <http://objectstyle.org/>. * - */ -package org.objectstyle.woproject.maven2.utils; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.commons.io.FileUtils; -import org.easymock.EasyMock; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsUtils; - -/** - *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> - */ -public class TestWebObjectsUtils extends TestCase -{ - protected WebobjectsLocator mockLocator; - - /* - * (non-Javadoc) - * - *..ee junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - - mockLocator = (WebobjectsLocator) EasyMock.createMock( WebobjectsLocator.class ); - } - - public void testCheckWebObjectsVersion() throws Exception - { - File versionFile = FileUtils.toFile( getClass().getResource( "/version.plist" ) ); - - EasyMock.expect( mockLocator.getWebobjectsVersionFile() ).andReturn( versionFile ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertEquals( "5.2.4", WebobjectsUtils.getWebobjectsVersion( mockLocator ) ); - } - - public void testFileCannotBeFound() throws Exception - { - File versionFile = new File( FileUtils.toFile( getClass().getResource( "/" ) ), "inexistent.txt" ); - - EasyMock.expect( mockLocator.getWebobjectsVersionFile() ).andReturn( versionFile ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertNull( WebobjectsUtils.getWebobjectsVersion( mockLocator ) ); - } - - public void testNullVersionFile() throws Exception - { - EasyMock.expect( mockLocator.getWebobjectsVersionFile() ).andReturn( null ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertNull( WebobjectsUtils.getWebobjectsVersion( mockLocator ) ); - } - - public void testNullWebObjectsLocator() throws Exception - { - assertNull( WebobjectsUtils.getWebobjectsVersion( null ) ); - } - - public void testObtainWebObjectsLibs() throws Exception - { - File jarsFolder = FileUtils.toFile( getClass().getResource( "/mock-jar1.jar" ) ).getParentFile(); - - EasyMock.expect( mockLocator.getWebobjectsLibFolder() ).andReturn( jarsFolder ); - - EasyMock.replay( new Object[] { mockLocator } ); - - File[] foundLibs = WebobjectsUtils.getWebobjectsJars( mockLocator ); - - assertEquals( 2, foundLibs.length ); - } - - public void testWebObjectsJarsWithNullLocator() throws Exception - { - assertNull( WebobjectsUtils.getWebobjectsJars( null ) ); - } - - public void testWebObjectsJarsWithNullLibFolder() throws Exception - { - EasyMock.expect( mockLocator.getWebobjectsLibFolder() ).andReturn( null ); - - EasyMock.replay( new Object[] { mockLocator } ); - - assertNull( WebobjectsUtils.getWebobjectsJars( mockLocator ) ); - } -} + */ +package org.objectstyle.woproject.maven2.wobootstrap.utils; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.commons.io.FileUtils; +import org.easymock.EasyMock; + +/** + *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> + */ +public class TestWebObjectsUtils extends TestCase { + protected WebobjectsLocator mockLocator; + + /* + * (non-Javadoc) + * + *..ee junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + mockLocator = (WebobjectsLocator) EasyMock.createMock(WebobjectsLocator.class); + } + + public void testCheckWebObjectsVersion() throws Exception { + File versionFile = FileUtils.toFile(getClass().getResource("/version.plist")); + + EasyMock.expect(mockLocator.getWebobjectsVersionFile()).andReturn(versionFile); + + EasyMock.replay(new Object[] { mockLocator }); + + assertEquals("5.2.4", WebobjectsUtils.getWebobjectsVersion(mockLocator)); + } + + public void testFileCannotBeFound() throws Exception { + File versionFile = new File(FileUtils.toFile(getClass().getResource("/")), "inexistent.txt"); + + EasyMock.expect(mockLocator.getWebobjectsVersionFile()).andReturn(versionFile); + + EasyMock.replay(new Object[] { mockLocator }); + + assertNull(WebobjectsUtils.getWebobjectsVersion(mockLocator)); + } + + public void testNullVersionFile() throws Exception { + EasyMock.expect(mockLocator.getWebobjectsVersionFile()).andReturn(null); + + EasyMock.replay(new Object[] { mockLocator }); + + assertNull(WebobjectsUtils.getWebobjectsVersion(mockLocator)); + } + + public void testNullWebObjectsLocator() throws Exception { + assertNull(WebobjectsUtils.getWebobjectsVersion(null)); + } + + public void testObtainWebObjectsLibs() throws Exception { + File jarsFolder = FileUtils.toFile(getClass().getResource("/mock-jar1.jar")).getParentFile(); + + EasyMock.expect(mockLocator.getWebobjectsLibFolder()).andReturn(jarsFolder); + + EasyMock.replay(new Object[] { mockLocator }); + + File[] foundLibs = WebobjectsUtils.getWebobjectsJars(mockLocator); + + assertEquals(2, foundLibs.length); + } + + public void testWebObjectsJarsWithNullLibFolder() throws Exception { + EasyMock.expect(mockLocator.getWebobjectsLibFolder()).andReturn(null); + + EasyMock.replay(new Object[] { mockLocator }); + + assertNull(WebobjectsUtils.getWebobjectsJars(mockLocator)); + } + + public void testWebObjectsJarsWithNullLocator() throws Exception { + assertNull(WebobjectsUtils.getWebobjectsJars(null)); + } +} Index: src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestWebobjectsLocator.java =================================================================== --- src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestWebobjectsLocator.java (revision 3666) +++ src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestWebobjectsLocator.java (working copy) ..-52,79 +52,69 @@ * information on the ObjectStyle Group, please see * <http://objectstyle.org/>. * - */ -package org.objectstyle.woproject.maven2.utils; - -import junit.framework.TestCase; - -import org.apache.commons.lang.SystemUtils; -import org.objectstyle.woproject.maven2.wobootstrap.utils.MacOsWebobjectsLocator; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WebobjectsLocator; -import org.objectstyle.woproject.maven2.wobootstrap.utils.WindowsWebobjectsLocator; - -/** - *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> - */ -public class TestWebobjectsLocator extends TestCase -{ - protected WebobjectsLocator locator; - - /* - * (non-Javadoc) - * - *..ee junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - - if( SystemUtils.IS_OS_WINDOWS ) - { - locator = new WindowsWebobjectsLocator(); - } - - if( SystemUtils.IS_OS_MAC_OSX ) - { - locator = new MacOsWebobjectsLocator(); - } - } - - /** - * I know it's not good, but if you don't have WebObjects installed, forget. - * This test will fail. - * - *..hrows Exception - */ - public void testCheckWebObjectsVersionFile() throws Exception - { - assertNotNull( locator.getWebobjectsVersionFile() ); - } - - public void testFindWebObjectsRootFolder() throws Exception - { - assertNotNull( locator.getWebobjectsRootFolder() ); - } - - /** - * I know it's not good, but if you don't have WebObjects installed, forget. - * This test will fail. - * - *..hrows Exception - */ - public void testWebObjectsLibsFolder() throws Exception - { - assertNotNull( locator.getWebobjectsLibFolder() ); - } - - public void testWebObjectsRootFolderCannotBeFoundOnWindows() throws Exception - { - if( SystemUtils.IS_OS_WINDOWS ) - { - locator = new WindowsWebobjectsLocator( "an_inexistent_evnvar_for_test" ); - - assertNull( locator.getWebobjectsRootFolder() ); - assertNull( locator.getWebobjectsLibFolder() ); - assertNull( locator.getWebobjectsVersionFile() ); - } - } -} + */ +package org.objectstyle.woproject.maven2.wobootstrap.utils; + +import junit.framework.TestCase; + +import org.apache.commons.lang.SystemUtils; + +/** + *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> + */ +public class TestWebobjectsLocator extends TestCase { + protected WebobjectsLocator locator; + + /* + * (non-Javadoc) + * + *..ee junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + if (SystemUtils.IS_OS_WINDOWS) { + locator = new WindowsWebobjectsLocator(); + } + + if (SystemUtils.IS_OS_MAC_OSX) { + locator = new MacOsWebobjectsLocator(); + } + } + + /** + * I know it's not good, but if you don't have WebObjects installed, forget. + * This test will fail. + * + *..hrows Exception + */ + public void testCheckWebObjectsVersionFile() throws Exception { + assertNotNull(locator.getWebobjectsVersionFile()); + } + + public void testFindWebObjectsRootFolder() throws Exception { + assertNotNull(locator.getWebobjectsRootFolder()); + } + + /** + * I know it's not good, but if you don't have WebObjects installed, forget. + * This test will fail. + * + *..hrows Exception + */ + public void testWebObjectsLibsFolder() throws Exception { + assertNotNull(locator.getWebobjectsLibFolder()); + } + + public void testWoRootFolderNullOnWindows() throws Exception { + if (!SystemUtils.IS_OS_WINDOWS) { + return; + } + + ((WindowsWebobjectsLocator) locator).woRootVariable = null; + + assertNull(locator.getWebobjectsLibFolder()); + assertNull(locator.getWebobjectsRootFolder()); + assertNull(locator.getWebobjectsVersionFile()); + } +} Index: src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestPomGenerator.java =================================================================== --- src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestPomGenerator.java +++ src/test/java/org/objectstyle/woproject/maven2/wobootstrap/utils/TestPomGenerator.java ..-0,0 +1,104 @@ +/** + * Criado em 22/11/2006 + */ +package org.objectstyle.woproject.maven2.wobootstrap.utils; + +import java.io.File; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.io.FileUtils; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.custommonkey.xmlunit.XMLTestCase; + +/** + *..uthor <a href="mailto:hprange@moleque.com.br">Henrique Prange</a> + */ +public class TestPomGenerator extends XMLTestCase { + protected PomGenerator generator; + + protected static final String ARTIFACT_ID = "java-eo-access"; + + protected static final String GROUP_ID = "webobjects.apple"; + + protected static final String VERSION = "5.3"; + + /* + * (non-Javadoc) + * + *..ee junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + Properties properties = new Properties(); + + properties.setProperty("artifactId", ARTIFACT_ID); + properties.setProperty("groupId", GROUP_ID); + properties.setProperty("version", VERSION); + + generator = new PomGenerator(properties); + } + + public void testModelGeneration() throws Exception { + Model model = generator.generateModel(); + + assertEquals(ARTIFACT_ID, model.getArtifactId()); + assertEquals(GROUP_ID, model.getGroupId()); + assertEquals(VERSION, model.getVersion()); + assertEquals("4.0.0", model.getModelVersion()); + } + + public void testModelWithDependencies() throws Exception { + Model model = generator.generateModel(); + + List dependencies = model.getDependencies(); + + assertEquals(2, dependencies.size()); + + String[] expectedDependencies = { "java-foundation", "java-eo-control" }; + + for (int i = 0; i < expectedDependencies.length; i++) { + Dependency dependency = (Dependency) dependencies.get(i); + + assertEquals(GROUP_ID, dependency.getGroupId()); + assertEquals(expectedDependencies[i], dependency.getArtifactId()); + assertEquals(VERSION, dependency.getVersion()); + } + } + + public void testNullProperties() throws Exception { + + try { + generator = new PomGenerator(null); + + fail("Must throw an IllegalArgumentException"); + } catch (IllegalArgumentException exception) { + assertEquals("The properties must not be null", exception.getMessage()); + } + } + + public void testWriteToFile() throws Exception { + + File expectedFile = FileUtils.toFile(getClass().getResource("/example.pom")); + + File createdFile = File.createTempFile("pom-", "xml"); + + createdFile.deleteOnExit(); + + generator.writeModel(createdFile); + + assertXMLEqual(FileUtils.readFileToString(expectedFile, null), FileUtils.readFileToString(createdFile, null)); + } + + public void testWriteToNullFile() throws Exception { + try { + generator.writeModel(null); + + fail("Writing to a null file. Must throw an exception."); + } catch (NullPointerException exception) { + assertEquals("Cannot write to a null file.", exception.getMessage()); + } + } +} Index: src/test/resources/example.pom =================================================================== --- src/test/resources/example.pom +++ src/test/resources/example.pom ..-0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?><project> + <modelVersion>4.0.0</modelVersion> + <groupId>webobjects.apple</groupId> + <artifactId>java-eo-access</artifactId> + <version>5.3</version> + <dependencies> + <dependency> + <groupId>webobjects.apple</groupId> + <artifactId>java-foundation</artifactId> + <version>5.3</version> + </dependency> + <dependency> + <groupId>webobjects.apple</groupId> + <artifactId>java-eo-control</artifactId> + <version>5.3</version> + </dependency> + </dependencies> +</project> \ No newline at end of file



    This archive was generated by hypermail 2.0.0 : Thu Nov 23 2006 - 13:44:04 EST