maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r354417 - in /maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src: main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ main/java/org/apache/maven/scm/provider/clearcase/command/update/ main/java/org/apache/m...
Date Tue, 06 Dec 2005 12:49:24 GMT
Author: evenisse
Date: Tue Dec  6 04:48:57 2005
New Revision: 354417

URL: http://svn.apache.org/viewcvs?rev=354417&view=rev
Log:
PR: SCM-100
Submitted by: Wim Deblauwe

Implements the checkout and update commands for ClearCase. Note that currently checkout from
a label is not supported (as done by the maven-release-plugin), but the checkout should work
in combination with Continuum.

Added:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt
  (with props)
Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommand.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutConsumer.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepository.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkin/ClearCaseCheckInCommandTest.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommandTest.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommand.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommand.java?rev=354417&r1=354416&r2=354417&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommand.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommand.java
Tue Dec  6 04:48:57 2005
@@ -18,19 +18,27 @@
 
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.providers.clearcase.settings.io.xpp3.ClearcaseXpp3Reader;
+import org.apache.maven.scm.providers.clearcase.settings.Settings;
 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 import org.apache.maven.scm.provider.ScmProviderRepository;
 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
+import org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.FileReader;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 /**
- * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
- * @version $Id$
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
  */
 public class ClearCaseCheckOutCommand
     extends AbstractCheckOutCommand
@@ -44,7 +52,11 @@
                                                         String tag )
         throws ScmException
     {
-        Commandline cl = createCommandLine( fileSet.getBasedir(), tag );
+        ClearCaseScmProviderRepository repo = (ClearCaseScmProviderRepository) repository;
+        File workingDirectory = fileSet.getBasedir();
+        getLogger().info( "basedir: " + workingDirectory );
+        getLogger().info( "tag: " + tag );
+        //Commandline cl = createCommandLine( fileSet.getBasedir(), tag );
 
         ClearCaseCheckOutConsumer consumer = new ClearCaseCheckOutConsumer( getLogger() );
 
@@ -52,14 +64,53 @@
 
         int exitCode;
 
+        Commandline cl;
         try
         {
-            exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
+            // Since clearcase only wants to checkout to a non-existent directory, first
delete the working dir if it already exists
+            FileUtils.deleteDirectory( workingDirectory );
+            // First create the view
+            String viewName = getUniqueViewName( repo, workingDirectory.getAbsolutePath()
);
+            cl = createCreateViewCommandLine( workingDirectory, viewName );
+            getLogger().info( "create view: " + cl.toString() );
+            exitCode = CommandLineUtils.executeCommandLine( cl, new CommandLineUtils.StringStreamConsumer(),
stderr );
+
+            if ( exitCode == 0 )
+            {
+                File configSpecLocation;
+
+                if ( tag == null )
+                {
+                    configSpecLocation = repo.getConfigSpec();
+                }
+                else
+                {
+                    // TODO We are building on a label
+                    throw new UnsupportedOperationException( "Building on a label not supported
yet" );
+//                    configSpecLocation = new File( "configspec.txt" );
+//                    FileWriter writer = new FileWriter( configSpecLocation );
+//                    writer.append( "ELEMENT * " + tag );
+//                    // If we did not tag the directories leading to the root directory
+//                    // of this module, then we need the following line also (otherwise,
we will
+//                    // not be able to access our module in the given view
+//                    writer.append( "element * /main/LATEST" );
+//                    writer.close();
+                }
+                cl = createUpdateConfigSpecCommandLine( workingDirectory, configSpecLocation,
+                                                        viewName );
+
+                getLogger().info( "update config spec: " + cl.toString() );
+                exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
+            }
         }
         catch ( CommandLineException ex )
         {
             throw new ScmException( "Error while executing clearcase command.", ex );
         }
+        catch ( IOException ex )
+        {
+            throw new ScmException( "Error while deleting working directory.", ex );
+        }
 
         if ( exitCode != 0 )
         {
@@ -73,7 +124,48 @@
     //
     // ----------------------------------------------------------------------
 
-    public static Commandline createCommandLine( File workingDirectory, String branch )
+    private static Commandline createDeleteViewCommandLine( ClearCaseScmProviderRepository
repository, File workingDirectory )
+    {
+        Commandline command = new Commandline();
+
+        command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+
+        command.setExecutable( "cleartool" );
+
+        command.createArgument().setValue( "rmview" );
+        command.createArgument().setValue( "-force" );
+        command.createArgument().setValue( "-tag" );
+        command.createArgument().setValue( getUniqueViewName( repository, workingDirectory.getAbsolutePath()
) );
+
+        return command;
+    }
+
+    protected static Commandline createCreateViewCommandLine( File workingDirectory, String
viewName )
+        throws IOException
+    {
+        Commandline command = new Commandline();
+
+        // We have to execute from 1 level up from the working dir, since we had to delete
the working dir
+        command.setWorkingDirectory( new File( workingDirectory, ".." ).getAbsolutePath()
);
+
+        command.setExecutable( "cleartool" );
+
+        command.createArgument().setValue( "mkview" );
+        command.createArgument().setValue( "-snapshot" );
+        command.createArgument().setValue( "-tag" );
+        command.createArgument().setValue( viewName );
+
+        command.createArgument().setValue( "-vws" );
+        command.createArgument().setValue( getViewStore() + viewName + ".vws" );
+
+        command.createArgument().setValue( workingDirectory.getCanonicalPath() );
+
+
+        return command;
+    }
+
+    protected static Commandline createUpdateConfigSpecCommandLine( File workingDirectory,
File configSpecLocation,
+                                                                    String viewName )
     {
         Commandline command = new Commandline();
 
@@ -81,15 +173,75 @@
 
         command.setExecutable( "cleartool" );
 
-        command.createArgument().setValue( "co" );
+        command.createArgument().setValue( "setcs" );
+        command.createArgument().setValue( "-tag" );
+        command.createArgument().setValue( viewName );
+        command.createArgument().setValue( configSpecLocation.getAbsolutePath() );
+
+        return command;
 
-        if ( branch != null )
+    }
+
+    private static String getUniqueViewName( ClearCaseScmProviderRepository repository, String
absolutePath )
+    {
+        String uniqueId;
+        int lastIndexBack = absolutePath.lastIndexOf( '\\' );
+        int lastIndexForward = absolutePath.lastIndexOf( '/' );
+        if( lastIndexBack != -1 )
         {
-            command.createArgument().setValue( "-branch" );
+            uniqueId = absolutePath.substring( lastIndexBack + 1 );
+        }
+        else
+        {
+            uniqueId = absolutePath.substring( lastIndexForward + 1 );
+        }
+        return repository.getViewName(uniqueId);
+    }
 
-            command.createArgument().setValue( branch );
+    protected static String getViewStore()
+    {
+        String result = null;
+
+        File scmUserDir = new File( System.getProperty( "user.dir" ), ".scm" );
+        File settingsFile = new File( scmUserDir, "clearcase-settings.xml" );
+        if( settingsFile.exists() )
+        {
+            try
+            {
+                ClearcaseXpp3Reader reader = new ClearcaseXpp3Reader();
+                Settings settings = reader.read( new FileReader( settingsFile ) );
+                result = settings.getViewstore();
+            }
+            catch ( IOException e )
+            {
+                result = null;
+            }
+            catch ( XmlPullParserException e )
+            {
+                result = null;
+            }
         }
 
-        return command;
+        if( result == null )
+        {
+            result = "\\\\" + getHostName() + "\\viewstore\\";
+        }
+        return result;
+    }
+
+    private static String getHostName()
+    {
+        String hostname;
+        try
+        {
+            hostname = InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            // Should never happen
+            throw new RuntimeException( e );
+        }
+        return hostname;
     }
+
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutConsumer.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutConsumer.java?rev=354417&r1=354416&r2=354417&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutConsumer.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutConsumer.java
Tue Dec  6 04:48:57 2005
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileStatus;
 import org.apache.maven.scm.log.ScmLogger;
 import org.codehaus.plexus.util.cli.StreamConsumer;
 
@@ -23,8 +25,7 @@
 import java.util.List;
 
 /**
- * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
- * @version $Id$
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
  */
 public class ClearCaseCheckOutConsumer
     implements StreamConsumer
@@ -48,6 +49,7 @@
 
     public void consumeLine( String line )
     {
+        checkedOutFiles.add( new ScmFile( line, ScmFileStatus.CHECKED_OUT ) );
     }
 
     // ----------------------------------------------------------------------

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java?rev=354417&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java
Tue Dec  6 04:48:57 2005
@@ -0,0 +1,92 @@
+package org.apache.maven.scm.provider.clearcase.command.update;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * 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
+ *
+ *      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.
+ */
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.changelog.ChangeLogCommand;
+import org.apache.maven.scm.command.update.AbstractUpdateCommand;
+import org.apache.maven.scm.command.update.UpdateScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
+import org.apache.maven.scm.provider.clearcase.command.changelog.ClearCaseChangeLogCommand;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
+ */
+public class ClearCaseUpdateCommand
+        extends AbstractUpdateCommand
+        implements ClearCaseCommand
+{
+    protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet
fileSet, String tag )
+        throws ScmException
+    {
+        getLogger().info( "executing update command..." );
+        Commandline cl = createCommandLine( fileSet );
+
+        ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( getLogger() );
+
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+
+        int exitCode;
+
+        try
+        {
+            exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
+        }
+        catch (CommandLineException ex)
+        {
+            throw new ScmException( "Error while executing clearcase command.", ex );
+        }
+
+        if (exitCode != 0)
+        {
+            return new UpdateScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(),
false );
+        }
+
+        return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() );
+    }
+
+    protected ChangeLogCommand getChangeLogCommand()
+    {
+        return new ClearCaseChangeLogCommand();
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public static Commandline createCommandLine( ScmFileSet scmFileSet )
+    {
+        Commandline command = new Commandline();
+
+        File workingDirectory = scmFileSet.getBasedir();
+
+        command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+
+        command.setExecutable( "cleartool" );
+
+        command.createArgument().setValue( "update" );
+
+        return command;
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java?rev=354417&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java
Tue Dec  6 04:48:57 2005
@@ -0,0 +1,69 @@
+package org.apache.maven.scm.provider.clearcase.command.update;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * 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
+ *
+ *      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.
+ */
+
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileStatus;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
+ */
+public class ClearCaseUpdateConsumer
+        implements StreamConsumer
+{
+    private ScmLogger logger;
+
+    private List updatedFiles = new ArrayList();
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public ClearCaseUpdateConsumer( ScmLogger logger )
+    {
+        this.logger = logger;
+    }
+
+    // ----------------------------------------------------------------------
+    // Stream Consumer Implementation
+    // ----------------------------------------------------------------------
+
+    public void consumeLine( String line )
+    {
+        logger.debug( line );
+        if( line.indexOf( "Loading" ) > -1 )
+        {
+            int beginIndex = line.indexOf( '"' );
+            String fileName = line.substring( beginIndex + 1, line.indexOf( '"', beginIndex
+ 1 ) );
+            updatedFiles.add( new ScmFile( fileName, ScmFileStatus.UPDATED ) );
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public List getUpdatedFiles()
+    {
+        return updatedFiles;
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepository.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepository.java?rev=354417&r1=354416&r2=354417&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepository.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/main/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepository.java
Tue Dec  6 04:48:57 2005
@@ -17,6 +17,15 @@
  */
 
 import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.StringTokenizer;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -25,12 +34,128 @@
 public class ClearCaseScmProviderRepository
     extends ScmProviderRepository
 {
-    public ClearCaseScmProviderRepository()
+    private boolean viewNameGivenByUser = false;
+    private String viewName;
+    private File configSpec;
+
+    /**
+     *
+     * @param url format is [view_name]:[url_to_configspec] or [view_name]|[url_to_configspec]
+     */
+    public ClearCaseScmProviderRepository( String url )
+        throws ScmRepositoryException
+    {
+        try
+        {
+            parseUrl( url );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage()
+ ")" );
+        }
+        catch ( URISyntaxException e )
+        {
+            throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage()
+ ")" );
+        }
+        catch ( UnknownHostException e )
+        {
+            throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage()
+ ")" );
+        }
+    }
+
+    private void parseUrl( String url )
+        throws MalformedURLException, URISyntaxException, UnknownHostException
+    {
+        if( url.indexOf( '|' ) != -1 )
+        {
+            StringTokenizer tokenizer = new StringTokenizer( url, "|" );
+            fillInProperties( tokenizer );
+        }
+        else
+        {
+            StringTokenizer tokenizer = new StringTokenizer( url, ":" );
+            fillInProperties( tokenizer );
+        }
+    }
+
+    private void fillInProperties( StringTokenizer tokenizer )
+        throws UnknownHostException, URISyntaxException, MalformedURLException
+    {
+        if( tokenizer.countTokens() == 1 )
+        {
+           //No view name was given
+            viewName = getDefaultViewName();
+            String spec = tokenizer.nextToken();
+            System.out.println( "spec = " + spec );
+            configSpec = createConfigSpecFile( spec );
+        }
+        else
+        {
+            viewName = tokenizer.nextToken();
+            viewNameGivenByUser = true;
+            System.out.println( "viewName = " + viewName );
+            String pathname = tokenizer.nextToken();
+            System.out.println( "pathname = " + pathname );
+            configSpec = createConfigSpecFile( pathname );
+        }
+    }
+
+    private File createConfigSpecFile( String spec )
+        throws URISyntaxException, MalformedURLException
     {
+        File result;
+        if( spec.indexOf( ':' ) == -1 )
+        {
+            result = new File( spec );
+        }
+        else
+        {
+            result = new File( new URL( spec ).toURI() );
+        }
+        return result;
+    }
+
+    /**
+     * Default: ${hostname}-{user.name}-maven
+     * @return
+     */
+    private String getDefaultViewName()
+        throws UnknownHostException
+    {
+        String username = System.getProperty( "user.name", "nouser" );
+        String hostname = getHostName();
+        return username + "-" + hostname + "-maven";
+    }
+
+    private String getHostName()
+        throws UnknownHostException
+    {
+        return InetAddress.getLocalHost().getHostName();
+    }
+
+    /**
+     * Returns the name of the view. If it is defined in the scm url, then it is returned
as defined there.
+     * If it is the default name, then the uniqueId is added
+     * @param uniqueId
+     * @return the name of the view
+     */
+    public String getViewName( String uniqueId )
+    {
+        String result;
+        if( viewNameGivenByUser )
+        {
+            result = viewName;
+        }
+        else
+        {
+            result = viewName + "-" + uniqueId;
+        }
+
+        return result;
     }
 
-    public String getModule()
+    public File getConfigSpec()
     {
-        return null;
+        return configSpec;
     }
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkin/ClearCaseCheckInCommandTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkin/ClearCaseCheckInCommandTest.java?rev=354417&r1=354416&r2=354417&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkin/ClearCaseCheckInCommandTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkin/ClearCaseCheckInCommandTest.java
Tue Dec  6 04:48:57 2005
@@ -18,6 +18,7 @@
 
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.ScmException;
 import org.codehaus.plexus.util.cli.Commandline;
 
 import java.io.File;
@@ -28,6 +29,7 @@
 public class ClearCaseCheckInCommandTest extends ScmTestCase
 {
     public void testCommand()
+        throws ScmException
     {
         File file = new File( "test.java" );
         ScmFileSet scmFileSet = new ScmFileSet( getWorkingDirectory(), file );

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommandTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommandTest.java?rev=354417&r1=354416&r2=354417&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommandTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/checkout/ClearCaseCheckOutCommandTest.java
Tue Dec  6 04:48:57 2005
@@ -19,45 +19,26 @@
 import org.apache.maven.scm.ScmTestCase;
 import org.codehaus.plexus.util.cli.Commandline;
 
+import java.io.IOException;
 import java.io.File;
 
 /**
- * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
- * @version $Id$
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
  */
 public class ClearCaseCheckOutCommandTest
     extends ScmTestCase
 {
-    public void testGetCommandLine()
-        throws Exception
+    public void testCreateViewCommandLine()
+        throws IOException
     {
-        String branch = null;
-
-        testCommandLine( branch,
-                         "cleartool co" );
+        Commandline commandLine = ClearCaseCheckOutCommand.createCreateViewCommandLine( getWorkingDirectory(),
"testView" );
+        assertEquals( "cleartool mkview -snapshot -tag testView -vws " + ClearCaseCheckOutCommand.getViewStore()
+ "testView.vws " + getWorkingDirectory(), commandLine.toString() );
     }
 
-    public void testGetCommandLineWithBranch()
-        throws Exception
+    public void testUpdateConfigSpec()
     {
-        String branch = "myBranch";
-
-        testCommandLine( branch,
-                         "cleartool co -branch myBranch" );
-    }
-
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    private void testCommandLine( String branch, String commandLine )
-        throws Exception
-    {
-        File workingDirectory = getTestFile( "target/clearcase-checkout-command-test" );
-
-        Commandline cl = ClearCaseCheckOutCommand.createCommandLine( workingDirectory, branch
);
-
-        assertEquals( commandLine, cl.toString() );
+        File configSpecLocation = new File( "\\\\myserver\\configspecs\\testconfigspec.txt"
);
+        Commandline commandLine = ClearCaseCheckOutCommand.createUpdateConfigSpecCommandLine(
getWorkingDirectory(), configSpecLocation, "testView" );
+        assertEquals( "cleartool setcs -tag testView " + configSpecLocation, commandLine.toString()
);
     }
 }

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java?rev=354417&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java
Tue Dec  6 04:48:57 2005
@@ -0,0 +1,34 @@
+package org.apache.maven.scm.provider.clearcase.command.update;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * 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
+ *
+ *      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.
+ */
+
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmTestCase;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
+ */
+public class ClearCaseUpdateCommandTest extends ScmTestCase
+{
+    public void testCommand()
+    {
+        ScmFileSet scmFileSet = new ScmFileSet( getWorkingDirectory() );
+        Commandline commandLine = ClearCaseUpdateCommand.createCommandLine( scmFileSet );
+        assertEquals( "cleartool update", commandLine.toString() );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java?rev=354417&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java
Tue Dec  6 04:48:57 2005
@@ -0,0 +1,60 @@
+package org.apache.maven.scm.provider.clearcase.command.update;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * 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
+ *
+ *      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.
+ */
+
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.log.DefaultLog;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
+ */
+public class ClearCaseUpdateConsumerTest extends ScmTestCase
+{
+    public void testConsumer() throws IOException
+    {
+        InputStream inputStream = getResourceAsStream( "/clearcase/update/update.txt" );
+
+        BufferedReader in = new BufferedReader( new InputStreamReader( inputStream ) );
+
+        String s = in.readLine();
+
+        ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( new DefaultLog()
);
+
+        while (s != null)
+        {
+            consumer.consumeLine( s );
+
+            s = in.readLine();
+        }
+
+        Collection entries = consumer.getUpdatedFiles();
+
+        assertEquals( "Wrong number of entries returned", 1, entries.size() );
+
+        ScmFile scmFile = (ScmFile)entries.iterator().next();
+        assertEquals( "my_vob\\modules\\utils\\utils-logging-jar\\testfile.txt", scmFile.getPath()
);
+        assertEquals( ScmFileStatus.UPDATED, scmFile.getStatus() );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/command/update/ClearCaseUpdateConsumerTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java?rev=354417&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java
Tue Dec  6 04:48:57 2005
@@ -0,0 +1,66 @@
+package org.apache.maven.scm.provider.clearcase.repository;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * 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
+ *
+ *      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.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+
+import java.io.IOException;
+import java.io.File;
+
+/**
+ * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
+ */
+public class ClearCaseScmProviderRepositoryTest extends TestCase
+{
+    public ClearCaseScmProviderRepositoryTest()
+    {
+    }
+
+    public void testParsingUrlWithPipe()
+        throws ScmRepositoryException, IOException
+    {
+        String viewName = "my_module_view";
+        String configSpecPath = "//myserver/ClearCase/ConfigSpecs/mymodule.txt";
+        String url = viewName + "|" + configSpecPath;
+        ClearCaseScmProviderRepository repository = new ClearCaseScmProviderRepository( url
);
+        assertEquals( new File( configSpecPath ).getPath(), repository.getConfigSpec().getPath()
);
+        assertEquals( viewName, repository.getViewName( "bla" ) );
+    }
+
+    public void testParsingUrlWithColon()
+        throws ScmRepositoryException
+    {
+        String viewName = "my_module_view";
+        String configSpecPath = "//myserver/ClearCase/ConfigSpecs/mymodule.txt";
+        String url = viewName + ":" + configSpecPath;
+        ClearCaseScmProviderRepository repository = new ClearCaseScmProviderRepository( url
);
+        assertEquals( new File( configSpecPath ).getPath(), repository.getConfigSpec().getPath()
);
+        assertEquals( viewName, repository.getViewName( "bla" ) );
+    }
+
+    public void testParsingUrlWithoutViewName()
+        throws ScmRepositoryException
+    {
+        String configSpecPath = "//myserver/ClearCase/ConfigSpecs/mymodule.txt";
+        String url = configSpecPath;
+        ClearCaseScmProviderRepository repository = new ClearCaseScmProviderRepository( url
);
+        assertEquals( new File( configSpecPath ).getPath(), repository.getConfigSpec().getPath()
);
+        assertNotNull( repository.getViewName( "15" ) );
+        assertTrue( repository.getViewName( "15" ).indexOf( "15" ) != -1 );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/java/org/apache/maven/scm/provider/clearcase/repository/ClearCaseScmProviderRepositoryTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt?rev=354417&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt
Tue Dec  6 04:48:57 2005
@@ -0,0 +1,51 @@
+Processing dir "my_vob\modules\utils".
+Making dir "my_vob\modules\utils\utils-logging-jar".
+Processing dir "my_vob\modules\utils\utils-logging-jar".
+.
+Processing dir "my_vob\modules\utils\utils-logging-jar\src".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\main".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\main\com".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp\mis".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp\mis\utils".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp\mis\utils\logging".
+...
+End dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp\mis\utils\logging".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp\mis\utils".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp\mis".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\main\com\mycomp".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\main\com".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\main".
+.
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\test".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\test\com".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp\mis".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp\mis\utils".
+Processing dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp\mis\utils\logging".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp\mis\utils\logging".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp\mis\utils".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp\mis".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\test\com\mycomp".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\test\com".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src\test".
+.
+End dir "my_vob\modules\utils\utils-logging-jar\src".
+.
+Loading "my_vob\modules\utils\utils-logging-jar\testfile.txt" (50 bytes).
+End dir "my_vob\modules\utils\utils-logging-jar".
+End dir "my_vob\modules\utils".
+.
+Done loading "\my_vob\modules\utils" (21 objects, copied 0 KB).
+Log has been written to "C:\Program Files\Apache Software Foundation\continuum-1.0.1\apps\continuum\working-directory\32\update.01-dec-05.16.11.18.updt".

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-clearcase/src/test/resources/clearcase/update/update.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message