1 package org.codehaus.plexus.archiver.manager;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Locale;
24
25
26
27 import org.codehaus.plexus.PlexusConstants;
28 import org.codehaus.plexus.PlexusContainer;
29 import org.codehaus.plexus.archiver.ArchiveContentLister;
30 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
31
32 import org.codehaus.plexus.context.Context;
33 import org.codehaus.plexus.context.ContextException;
34 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
35 import org.codehaus.plexus.util.FileUtils;
36 import org.codehaus.plexus.util.StringUtils;
37
38
39
40
41
42
43 public class DefaultArchiveContentListerManager
44 implements ArchiveContentListerManager, Contextualizable
45 {
46 private PlexusContainer container;
47
48
49
50
51
52 public void contextualize( Context context )
53 throws ContextException
54 {
55 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
56 }
57
58 public ArchiveContentLister getArchiveContentLister( String archiveContentListerName )
59 throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException
60 {
61 try
62 {
63 return (ArchiveContentLister) container.lookup( ArchiveContentLister.ROLE, archiveContentListerName );
64 }
65 catch ( ComponentLookupException e )
66 {
67 throw new org.codehaus.plexus.archiver.manager.NoSuchArchiverException( archiveContentListerName );
68 }
69 }
70
71 public ArchiveContentLister getArchiveContentLister( File file )
72 throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException
73 {
74 return getArchiveContentLister( getFileExtention( file ) );
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 private static String getFileExtention ( File file )
120 {
121 String path = file.getAbsolutePath();
122
123 String archiveExt = FileUtils.getExtension( path ).toLowerCase( Locale.ENGLISH );
124
125 if ( "gz".equals( archiveExt ) || "bz2".equals( archiveExt ) )
126 {
127 String [] tokens = StringUtils.split( path, "." );
128
129 if ( tokens.length > 2 && "tar".equals( tokens[tokens.length - 2].toLowerCase( Locale.ENGLISH ) ) )
130 {
131 archiveExt = "tar." + archiveExt;
132 }
133 }
134 return archiveExt;
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 }