View Javadoc

1   package org.apache.maven.plugin.assembly.archive.phase;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.model.Model;
23  import org.apache.maven.plugin.assembly.DefaultAssemblyContext;
24  import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
25  import org.apache.maven.plugin.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask;
26  import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
27  import org.apache.maven.plugin.assembly.model.Assembly;
28  import org.apache.maven.plugin.assembly.model.FileSet;
29  import org.apache.maven.plugin.assembly.testutils.MockManager;
30  import org.apache.maven.plugin.assembly.testutils.TestFileManager;
31  import org.apache.maven.project.MavenProject;
32  import org.codehaus.plexus.logging.Logger;
33  import org.easymock.MockControl;
34  
35  import java.io.File;
36  import java.io.IOException;
37  
38  import junit.framework.TestCase;
39  
40  public class FileSetAssemblyPhaseTest
41      extends TestCase
42  {
43  
44      private final MockManager mockManager = new MockManager();
45  
46      private final TestFileManager fileManager = new TestFileManager( "file-set-assembly.test.", "" );
47  
48      @Override
49      public void tearDown()
50          throws IOException
51      {
52          fileManager.cleanUp();
53      }
54  
55      public void testShouldNotFailWhenNoFileSetsSpecified()
56          throws ArchiveCreationException, AssemblyFormattingException
57      {
58          final Assembly assembly = new Assembly();
59  
60          assembly.setId( "test" );
61  
62          final MockAndControlForLogger macLogger = new MockAndControlForLogger();
63          final MockAndControlForAddFileSetsTask macTask =
64              new MockAndControlForAddFileSetsTask( mockManager, fileManager );
65  
66          mockManager.replayAll();
67  
68          createPhase( macLogger ).execute( assembly, macTask.archiver, macTask.configSource,
69                                            new DefaultAssemblyContext() );
70  
71          mockManager.verifyAll();
72      }
73  
74      public void testShouldAddOneFileSet()
75          throws ArchiveCreationException, AssemblyFormattingException
76      {
77          final Assembly assembly = new Assembly();
78  
79          assembly.setId( "test" );
80          assembly.setIncludeBaseDirectory( false );
81  
82          final FileSet fs = new FileSet();
83          fs.setOutputDirectory( "/out" );
84          fs.setDirectory( "/input" );
85          fs.setFileMode( "777" );
86          fs.setDirectoryMode( "777" );
87  
88          assembly.addFileSet( fs );
89  
90          final MockAndControlForLogger macLogger = new MockAndControlForLogger();
91          final MockAndControlForAddFileSetsTask macTask =
92              new MockAndControlForAddFileSetsTask( mockManager, fileManager );
93  
94          macTask.expectGetArchiveBaseDirectory();
95  
96          final File basedir = fileManager.createTempDir();
97  
98          final MavenProject project = new MavenProject( new Model() );
99  
100         macLogger.expectDebug( true, true );
101 
102         final int dirMode = Integer.parseInt( "777", 8 );
103         final int fileMode = Integer.parseInt( "777", 8 );
104 
105         final int[] modes = { -1, -1, dirMode, fileMode };
106 
107         macTask.expectAdditionOfSingleFileSet( project, basedir, "final-name", false, modes, 1, true );
108 
109         mockManager.replayAll();
110 
111         createPhase( macLogger ).execute( assembly, macTask.archiver, macTask.configSource,
112                                           new DefaultAssemblyContext() );
113 
114         mockManager.verifyAll();
115     }
116 
117     private FileSetAssemblyPhase createPhase( final MockAndControlForLogger macLogger )
118     {
119         final FileSetAssemblyPhase phase = new FileSetAssemblyPhase();
120 
121         phase.enableLogging( macLogger.logger );
122 
123         return phase;
124     }
125 
126     private final class MockAndControlForLogger
127     {
128         Logger logger;
129 
130         MockControl control;
131 
132         MockAndControlForLogger()
133         {
134             control = MockControl.createControl( Logger.class );
135             mockManager.add( control );
136 
137             logger = (Logger) control.getMock();
138         }
139 
140         public void expectDebug( final boolean debugCheck, final boolean debugEnabled )
141         {
142             if ( debugCheck )
143             {
144                 logger.isDebugEnabled();
145                 control.setReturnValue( debugEnabled, MockControl.ONE_OR_MORE );
146             }
147 
148             logger.debug( null );
149             control.setMatcher( MockControl.ALWAYS_MATCHER );
150             control.setVoidCallable( MockControl.ONE_OR_MORE );
151         }
152     }
153 
154 }