17
17
* limitations under the License.
18
18
*/
19
19
20
- import java .io .File ;
21
- import java .io .IOException ;
22
- import java .io .InputStream ;
23
-
20
+ import org .codehaus .plexus .archiver .resources .PlexusIoVirtualSymlinkResource ;
21
+ import org .codehaus .plexus .archiver .util .ArchiverAttributeUtils ;
24
22
import org .codehaus .plexus .components .io .attributes .PlexusIoResourceAttributeUtils ;
25
23
import org .codehaus .plexus .components .io .attributes .PlexusIoResourceAttributes ;
26
24
import org .codehaus .plexus .components .io .resources .PlexusIoFileResource ;
27
25
import org .codehaus .plexus .components .io .resources .PlexusIoResource ;
28
26
import org .codehaus .plexus .components .io .resources .PlexusIoResourceWithAttributes ;
27
+ import org .codehaus .plexus .components .io .resources .PlexusIoSymlinkResource ;
28
+
29
+ import java .io .File ;
30
+ import java .io .IOException ;
31
+ import java .io .InputStream ;
29
32
30
33
/**
31
34
* @version $Revision: 1502 $ $Date$
@@ -38,6 +41,7 @@ public class ArchiveEntry
38
41
39
42
public static final int DIRECTORY = 2 ;
40
43
44
+ public static final int SYMLINK = 3 ;
41
45
private final PlexusIoResource resource ;
42
46
43
47
private final String name ;
@@ -51,27 +55,27 @@ public class ArchiveEntry
51
55
/**
52
56
* @param name the filename as it will appear in the archive. This is platform-specific
53
57
* normalized with File.separatorChar
54
- * @param original original filename
58
+ * @param resource original filename
55
59
* @param type FILE or DIRECTORY
56
60
* @param mode octal unix style permissions
57
61
*/
58
62
private ArchiveEntry ( String name , PlexusIoResource resource , int type , int mode )
59
63
{
60
64
this .name = name ;
61
65
this .resource = resource ;
62
- this .attributes =
63
- ( resource instanceof PlexusIoResourceWithAttributes ) ? ( (PlexusIoResourceWithAttributes ) resource ).getAttributes ()
64
- : null ;
66
+ this .attributes = ( resource instanceof PlexusIoResourceWithAttributes )
67
+ ? ( (PlexusIoResourceWithAttributes ) resource ).getAttributes () : null ;
65
68
this .type = type ;
66
69
int permissions = mode ;
67
-
70
+
68
71
if ( mode == -1 && this .attributes == null )
69
72
{
70
- permissions = resource .isFile () ? Archiver .DEFAULT_FILE_MODE : Archiver .DEFAULT_DIR_MODE ;
73
+ permissions = resource .isFile () ? Archiver .DEFAULT_FILE_MODE
74
+ : resource .isSymbolicLink () ? Archiver .DEFAULT_SYMLILNK_MODE : Archiver .DEFAULT_DIR_MODE ;
71
75
}
72
-
76
+
73
77
this .mode = permissions == -1 ? permissions : ( permissions & UnixStat .PERM_MASK ) |
74
- ( type == FILE ? UnixStat .FILE_FLAG : UnixStat .DIR_FLAG );
78
+ ( type == FILE ? UnixStat . FILE_FLAG : type == SYMLINK ? UnixStat .LINK_FLAG : UnixStat .DIR_FLAG );
75
79
}
76
80
77
81
/**
@@ -85,8 +89,8 @@ public String getName()
85
89
/**
86
90
* @return The original file that will be stored in the archive.
87
91
* @deprecated As of 1.0-alpha-10, file entries are no longer backed
88
- * by files, but by instances of {@link PlexusIoResource}.
89
- * Consequently, you should use {@link #getInputStream()}-
92
+ * by files, but by instances of {@link PlexusIoResource}.
93
+ * Consequently, you should use {@link #getInputStream()}-
90
94
*/
91
95
public File getFile ()
92
96
{
@@ -107,8 +111,6 @@ public InputStream getInputStream()
107
111
}
108
112
109
113
/**
110
- * TODO: support for SYMLINK?
111
- *
112
114
* @return FILE or DIRECTORY
113
115
*/
114
116
public int getType ()
@@ -131,8 +133,9 @@ public int getMode()
131
133
return attributes .getOctalMode ();
132
134
}
133
135
134
- return ( ( type == FILE ? Archiver .DEFAULT_FILE_MODE : Archiver .DEFAULT_DIR_MODE ) & UnixStat .PERM_MASK )
135
- | ( type == FILE ? UnixStat .FILE_FLAG : UnixStat .DIR_FLAG );
136
+ return ( ( type == FILE ? Archiver .DEFAULT_FILE_MODE
137
+ : type == SYMLINK ? Archiver .DEFAULT_SYMLILNK_MODE : Archiver .DEFAULT_DIR_MODE ) & UnixStat .PERM_MASK ) |
138
+ ( type == FILE ? UnixStat .FILE_FLAG : type == SYMLINK ? UnixStat .LINK_FLAG : UnixStat .DIR_FLAG );
136
139
}
137
140
138
141
public static ArchiveEntry createFileEntry ( String target , PlexusIoResource resource , int permissions )
@@ -142,7 +145,8 @@ public static ArchiveEntry createFileEntry( String target, PlexusIoResource reso
142
145
{
143
146
throw new ArchiverException ( "Not a file: " + resource .getName () );
144
147
}
145
- return new ArchiveEntry ( target , resource , FILE , permissions );
148
+ final int type = resource .isSymbolicLink () ? SYMLINK : FILE ;
149
+ return new ArchiveEntry ( target , resource , type , permissions );
146
150
}
147
151
148
152
public static ArchiveEntry createFileEntry ( String target , File file , int permissions )
@@ -174,7 +178,8 @@ public static ArchiveEntry createDirectoryEntry( String target, PlexusIoResource
174
178
{
175
179
throw new ArchiverException ( "Not a directory: " + resource .getName () );
176
180
}
177
- return new ArchiveEntry ( target , resource , DIRECTORY , permissions );
181
+ final int type = resource .isSymbolicLink () ? SYMLINK : DIRECTORY ;
182
+ return new ArchiveEntry ( target , resource , type , permissions );
178
183
}
179
184
180
185
public static ArchiveEntry createDirectoryEntry ( String target , final File file , int permissions )
@@ -184,18 +189,8 @@ public static ArchiveEntry createDirectoryEntry( String target, final File file,
184
189
{
185
190
throw new ArchiverException ( "Not a directory: " + file );
186
191
}
187
-
188
- PlexusIoResourceAttributes attrs ;
189
- try
190
- {
191
- attrs = PlexusIoResourceAttributeUtils .getFileAttributes ( file );
192
- }
193
- catch ( IOException e )
194
- {
195
- throw new ArchiverException ( "Failed to read filesystem attributes for: " + file , e );
196
- }
197
-
198
- final PlexusIoFileResource res = new PlexusIoFileResource ( file , attrs );
192
+
193
+ final PlexusIoFileResource res = new PlexusIoFileResource ( file , ArchiverAttributeUtils .getFileAttributes (file ));
199
194
return new ArchiveEntry ( target , res , DIRECTORY , permissions );
200
195
}
201
196
@@ -216,6 +211,13 @@ else if ( file.isFile() )
216
211
}
217
212
}
218
213
214
+ public static ArchiveEntry createSymlinkEntry (String symlinkName , int permissions , String symlinkDestination )
215
+ {
216
+ File symlinkFile = new File (symlinkName );
217
+ final ArchiveEntry archiveEntry = new ArchiveEntry (symlinkName , new PlexusIoVirtualSymlinkResource (symlinkFile , symlinkDestination ), SYMLINK , permissions );
218
+ return archiveEntry ;
219
+ }
220
+
219
221
public PlexusIoResourceAttributes getResourceAttributes ()
220
222
{
221
223
return attributes ;
0 commit comments