Lines 25-31
Link Here
|
25 |
import java.util.HashMap; |
25 |
import java.util.HashMap; |
26 |
import java.util.Map; |
26 |
import java.util.Map; |
27 |
|
27 |
|
|
|
28 |
import org.apache.juli.logging.Log; |
29 |
import org.apache.juli.logging.LogFactory; |
28 |
import org.apache.tomcat.JarScannerCallback; |
30 |
import org.apache.tomcat.JarScannerCallback; |
|
|
31 |
import org.apache.tomcat.util.res.StringManager; |
29 |
import org.apache.tomcat.util.scan.Jar; |
32 |
import org.apache.tomcat.util.scan.Jar; |
30 |
import org.apache.tomcat.util.scan.JarFactory; |
33 |
import org.apache.tomcat.util.scan.JarFactory; |
31 |
import org.xml.sax.InputSource; |
34 |
import org.xml.sax.InputSource; |
Lines 35-40
Link Here
|
35 |
*/ |
38 |
*/ |
36 |
public class FragmentJarScannerCallback implements JarScannerCallback { |
39 |
public class FragmentJarScannerCallback implements JarScannerCallback { |
37 |
|
40 |
|
|
|
41 |
private static final StringManager sm = |
42 |
StringManager.getManager(Constants.PACKAGE_NAME); |
43 |
|
44 |
private static final Log log = LogFactory.getLog(FragmentJarScannerCallback.class); |
45 |
|
38 |
private static final String FRAGMENT_LOCATION = |
46 |
private static final String FRAGMENT_LOCATION = |
39 |
"META-INF/web-fragment.xml"; |
47 |
"META-INF/web-fragment.xml"; |
40 |
private final WebXmlParser webXmlParser; |
48 |
private final WebXmlParser webXmlParser; |
Lines 42-48
Link Here
|
42 |
private final boolean parseRequired; |
50 |
private final boolean parseRequired; |
43 |
private final Map<String,WebXml> fragments = new HashMap<>(); |
51 |
private final Map<String,WebXml> fragments = new HashMap<>(); |
44 |
private boolean ok = true; |
52 |
private boolean ok = true; |
45 |
|
53 |
private boolean foundJarWithoutFragments = false; |
|
|
54 |
private boolean foundFileWithoutFragments = false; |
55 |
private boolean found = false; |
56 |
|
46 |
public FragmentJarScannerCallback(WebXmlParser webXmlParser, boolean delegate, |
57 |
public FragmentJarScannerCallback(WebXmlParser webXmlParser, boolean delegate, |
47 |
boolean parseRequired) { |
58 |
boolean parseRequired) { |
48 |
this.webXmlParser = webXmlParser; |
59 |
this.webXmlParser = webXmlParser; |
Lines 54-59
Link Here
|
54 |
public void scan(JarURLConnection jarConn, String webappPath, boolean isWebapp) |
65 |
public void scan(JarURLConnection jarConn, String webappPath, boolean isWebapp) |
55 |
throws IOException { |
66 |
throws IOException { |
56 |
|
67 |
|
|
|
68 |
found = false; |
57 |
URL url = jarConn.getURL(); |
69 |
URL url = jarConn.getURL(); |
58 |
URL resourceURL = jarConn.getJarFileURL(); |
70 |
URL resourceURL = jarConn.getJarFileURL(); |
59 |
Jar jar = null; |
71 |
Jar jar = null; |
Lines 77-82
Link Here
|
77 |
// distributable |
89 |
// distributable |
78 |
fragment.setDistributable(true); |
90 |
fragment.setDistributable(true); |
79 |
} else { |
91 |
} else { |
|
|
92 |
found = true; |
80 |
InputSource source = new InputSource( |
93 |
InputSource source = new InputSource( |
81 |
"jar:" + resourceURL.toString() + "!/" + FRAGMENT_LOCATION); |
94 |
"jar:" + resourceURL.toString() + "!/" + FRAGMENT_LOCATION); |
82 |
source.setByteStream(is); |
95 |
source.setByteStream(is); |
Lines 95-100
Link Here
|
95 |
fragment.setJarName(extractJarFileName(url)); |
108 |
fragment.setJarName(extractJarFileName(url)); |
96 |
fragments.put(fragment.getName(), fragment); |
109 |
fragments.put(fragment.getName(), fragment); |
97 |
} |
110 |
} |
|
|
111 |
if(found){ |
112 |
if (log.isDebugEnabled()) { |
113 |
log.debug(sm.getString("fragmentJarScannerCallBack.fragmentInJar", resourceURL.toString())); |
114 |
} |
115 |
}else{ |
116 |
foundJarWithoutFragments = true; |
117 |
if (log.isDebugEnabled()) { |
118 |
log.debug(sm.getString("fragmentJarScannerCallBack.NoFragmentInJar", resourceURL.toString())); |
119 |
} |
120 |
} |
98 |
} |
121 |
} |
99 |
|
122 |
|
100 |
private String extractJarFileName(URL input) { |
123 |
private String extractJarFileName(URL input) { |
Lines 111-116
Link Here
|
111 |
@Override |
134 |
@Override |
112 |
public void scan(File file, String webappPath, boolean isWebapp) throws IOException { |
135 |
public void scan(File file, String webappPath, boolean isWebapp) throws IOException { |
113 |
|
136 |
|
|
|
137 |
found = false; |
114 |
WebXml fragment = new WebXml(); |
138 |
WebXml fragment = new WebXml(); |
115 |
fragment.setWebappJar(isWebapp); |
139 |
fragment.setWebappJar(isWebapp); |
116 |
fragment.setDelegate(delegate); |
140 |
fragment.setDelegate(delegate); |
Lines 118-123
Link Here
|
118 |
File fragmentFile = new File(file, FRAGMENT_LOCATION); |
142 |
File fragmentFile = new File(file, FRAGMENT_LOCATION); |
119 |
try { |
143 |
try { |
120 |
if (fragmentFile.isFile()) { |
144 |
if (fragmentFile.isFile()) { |
|
|
145 |
found = true; |
121 |
try (InputStream stream = new FileInputStream(fragmentFile)) { |
146 |
try (InputStream stream = new FileInputStream(fragmentFile)) { |
122 |
InputSource source = |
147 |
InputSource source = |
123 |
new InputSource(fragmentFile.toURI().toURL().toString()); |
148 |
new InputSource(fragmentFile.toURI().toURL().toString()); |
Lines 139-144
Link Here
|
139 |
fragment.setJarName(file.getName()); |
164 |
fragment.setJarName(file.getName()); |
140 |
fragments.put(fragment.getName(), fragment); |
165 |
fragments.put(fragment.getName(), fragment); |
141 |
} |
166 |
} |
|
|
167 |
if(found){ |
168 |
if (log.isDebugEnabled()) { |
169 |
log.debug(sm.getString("fragmentJarScannerCallBack.fragmentInFile", file.getAbsolutePath())); |
170 |
} |
171 |
}else{ |
172 |
foundFileWithoutFragments = true; |
173 |
if (log.isDebugEnabled()) { |
174 |
log.debug(sm.getString("fragmentJarScannerCallBack.NoFragmentInFile", file.getAbsolutePath())); |
175 |
} |
176 |
} |
142 |
} |
177 |
} |
143 |
|
178 |
|
144 |
|
179 |
|
Lines 156-159
Link Here
|
156 |
public Map<String,WebXml> getFragments() { |
191 |
public Map<String,WebXml> getFragments() { |
157 |
return fragments; |
192 |
return fragments; |
158 |
} |
193 |
} |
|
|
194 |
|
195 |
public boolean scanFoundNoFragments(){ |
196 |
return foundJarWithoutFragments || foundFileWithoutFragments; |
197 |
} |
159 |
} |
198 |
} |