View | Details | Raw Unified | Return to bug 52952
Collapse All | Expand All

(-)java/org/apache/catalina/core/StandardServer.java (-22 / +14 lines)
Lines 470-476 Link Here
470
                        // This should never happen but bug 56684 suggests that
470
                        // This should never happen but bug 56684 suggests that
471
                        // it does.
471
                        // it does.
472
                        log.warn(sm.getString("standardServer.accept.timeout",
472
                        log.warn(sm.getString("standardServer.accept.timeout",
473
                                Long.valueOf(System.currentTimeMillis() - acceptStartTime)), ste);
473
                                System.currentTimeMillis() - acceptStartTime), ste);
474
                        continue;
474
                        continue;
475
                    } catch (AccessControlException ace) {
475
                    } catch (AccessControlException ace) {
476
                        log.warn("StandardServer.accept security exception: "
476
                        log.warn("StandardServer.accept security exception: "
Lines 498-504 Link Here
498
                            ch = stream.read();
498
                            ch = stream.read();
499
                        } catch (IOException e) {
499
                        } catch (IOException e) {
500
                            log.warn("StandardServer.await: read: ", e);
500
                            log.warn("StandardServer.await: read: ", e);
501
                            ch = -1;
502
                        }
501
                        }
503
                        if (ch < 32)  // Control character or EOF terminates loop
502
                        if (ch < 32)  // Control character or EOF terminates loop
504
                            break;
503
                            break;
Lines 555-563 Link Here
555
            return (null);
554
            return (null);
556
        }
555
        }
557
        synchronized (servicesLock) {
556
        synchronized (servicesLock) {
558
            for (int i = 0; i < services.length; i++) {
557
            for (Service service : services) {
559
                if (name.equals(services[i].getName())) {
558
                if (name.equals(service.getName())) {
560
                    return (services[i]);
559
                    return (service);
561
                }
560
                }
562
            }
561
            }
563
        }
562
        }
Lines 687-698 Link Here
687
     */
686
     */
688
    @Override
687
    @Override
689
    public String toString() {
688
    public String toString() {
690
689
        return  "StandardServer[" + getPort() + "]";
691
        StringBuilder sb = new StringBuilder("StandardServer[");
692
        sb.append(getPort());
693
        sb.append("]");
694
        return (sb.toString());
695
696
    }
690
    }
697
691
698
692
Lines 787-794 Link Here
787
781
788
        // Start our defined Services
782
        // Start our defined Services
789
        synchronized (servicesLock) {
783
        synchronized (servicesLock) {
790
            for (int i = 0; i < services.length; i++) {
784
            for (Service service : services) {
791
                services[i].start();
785
                service.start();
792
            }
786
            }
793
        }
787
        }
794
    }
788
    }
Lines 808-815 Link Here
808
        fireLifecycleEvent(CONFIGURE_STOP_EVENT, null);
802
        fireLifecycleEvent(CONFIGURE_STOP_EVENT, null);
809
803
810
        // Stop our defined Services
804
        // Stop our defined Services
811
        for (int i = 0; i < services.length; i++) {
805
        for (Service service : services) {
812
            services[i].stop();
806
            service.stop();
813
        }
807
        }
814
808
815
        globalNamingResources.stop();
809
        globalNamingResources.stop();
Lines 857-866 Link Here
857
                                        f.getName().endsWith(".jar")) {
851
                                        f.getName().endsWith(".jar")) {
858
                                    ExtensionValidator.addSystemResource(f);
852
                                    ExtensionValidator.addSystemResource(f);
859
                                }
853
                                }
860
                            } catch (URISyntaxException e) {
854
                            } catch (URISyntaxException | IOException e) {
861
                                // Ignore
855
                                // Ignore
862
                            } catch (IOException e) {
863
                                // Ignore
864
                            }
856
                            }
865
                        }
857
                        }
866
                    }
858
                    }
Lines 869-876 Link Here
869
            }
861
            }
870
        }
862
        }
871
        // Initialize our defined Services
863
        // Initialize our defined Services
872
        for (int i = 0; i < services.length; i++) {
864
        for (Service service : services) {
873
            services[i].init();
865
            service.init();
874
        }
866
        }
875
    }
867
    }
876
868
Lines 877-884 Link Here
877
    @Override
869
    @Override
878
    protected void destroyInternal() throws LifecycleException {
870
    protected void destroyInternal() throws LifecycleException {
879
        // Destroy our defined Services
871
        // Destroy our defined Services
880
        for (int i = 0; i < services.length; i++) {
872
        for (Service service : services) {
881
            services[i].destroy();
873
            service.destroy();
882
        }
874
        }
883
875
884
        globalNamingResources.destroy();
876
        globalNamingResources.destroy();
(-)java/org/apache/catalina/util/Extension.java (-11 / +31 lines)
Lines 19-24 Link Here
19
package org.apache.catalina.util;
19
package org.apache.catalina.util;
20
20
21
21
22
import java.util.Objects;
22
import java.util.StringTokenizer;
23
import java.util.StringTokenizer;
23
24
24
25
Lines 44-50 Link Here
44
 */
45
 */
45
public final class Extension {
46
public final class Extension {
46
47
47
48
    // ------------------------------------------------------------- Properties
48
    // ------------------------------------------------------------- Properties
49
49
50
50
Lines 51-57 Link Here
51
    /**
51
    /**
52
     * The name of the optional package being made available, or required.
52
     * The name of the optional package being made available, or required.
53
     */
53
     */
54
    private String extensionName = null;
54
    private String extensionName;
55
55
56
56
57
    public String getExtensionName() {
57
    public String getExtensionName() {
Lines 66-72 Link Here
66
     * The URL from which the most recent version of this optional package
66
     * The URL from which the most recent version of this optional package
67
     * can be obtained if it is not already installed.
67
     * can be obtained if it is not already installed.
68
     */
68
     */
69
    private String implementationURL = null;
69
    private String implementationURL;
70
70
71
    public String getImplementationURL() {
71
    public String getImplementationURL() {
72
        return (this.implementationURL);
72
        return (this.implementationURL);
Lines 81-87 Link Here
81
     * The name of the company or organization that produced this
81
     * The name of the company or organization that produced this
82
     * implementation of this optional package.
82
     * implementation of this optional package.
83
     */
83
     */
84
    private String implementationVendor = null;
84
    private String implementationVendor;
85
85
86
    public String getImplementationVendor() {
86
    public String getImplementationVendor() {
87
        return (this.implementationVendor);
87
        return (this.implementationVendor);
Lines 96-102 Link Here
96
     * The unique identifier of the company that produced the optional
96
     * The unique identifier of the company that produced the optional
97
     * package contained in this JAR file.
97
     * package contained in this JAR file.
98
     */
98
     */
99
    private String implementationVendorId = null;
99
    private String implementationVendorId;
100
100
101
    public String getImplementationVendorId() {
101
    public String getImplementationVendorId() {
102
        return (this.implementationVendorId);
102
        return (this.implementationVendorId);
Lines 111-117 Link Here
111
     * The version number (dotted decimal notation) for this implementation
111
     * The version number (dotted decimal notation) for this implementation
112
     * of the optional package.
112
     * of the optional package.
113
     */
113
     */
114
    private String implementationVersion = null;
114
    private String implementationVersion;
115
115
116
    public String getImplementationVersion() {
116
    public String getImplementationVersion() {
117
        return (this.implementationVersion);
117
        return (this.implementationVersion);
Lines 126-132 Link Here
126
     * The name of the company or organization that originated the
126
     * The name of the company or organization that originated the
127
     * specification to which this optional package conforms.
127
     * specification to which this optional package conforms.
128
     */
128
     */
129
    private String specificationVendor = null;
129
    private String specificationVendor;
130
130
131
    public String getSpecificationVendor() {
131
    public String getSpecificationVendor() {
132
        return (this.specificationVendor);
132
        return (this.specificationVendor);
Lines 141-147 Link Here
141
     * The version number (dotted decimal notation) of the specification
141
     * The version number (dotted decimal notation) of the specification
142
     * to which this optional package conforms.
142
     * to which this optional package conforms.
143
     */
143
     */
144
    private String specificationVersion = null;
144
    private String specificationVersion;
145
145
146
    public String getSpecificationVersion() {
146
    public String getSpecificationVersion() {
147
        return (this.specificationVersion);
147
        return (this.specificationVersion);
Lines 153-162 Link Here
153
153
154
154
155
    /**
155
    /**
156
     * mark this extension as fulfilled
156
     * fulfilled is true if all the required extension dependencies have been
157
     * fulfilled is true if all the required extension dependencies have been
157
     * satisfied
158
     * satisfied
158
     */
159
     */
159
    private boolean fulfilled = false;
160
    private boolean fulfilled;
160
161
161
    public void setFulfilled(boolean fulfilled) {
162
    public void setFulfilled(boolean fulfilled) {
162
        this.fulfilled = fulfilled;
163
        this.fulfilled = fulfilled;
Lines 248-254 Link Here
248
249
249
    }
250
    }
250
251
252
    @Override
253
    public boolean equals(Object o) {
254
        if (this == o) return true;
255
        if (!(o instanceof Extension)) return false;
256
        Extension extension = (Extension) o;
257
        return Objects.equals(extensionName, extension.extensionName) &&
258
                Objects.equals(implementationURL, extension.implementationURL) &&
259
                Objects.equals(implementationVendor, extension.implementationVendor) &&
260
                Objects.equals(implementationVendorId, extension.implementationVendorId) &&
261
                Objects.equals(implementationVersion, extension.implementationVersion) &&
262
                Objects.equals(specificationVendor, extension.specificationVendor) &&
263
                Objects.equals(specificationVersion, extension.specificationVersion);
264
    }
251
265
266
    @Override
267
    public int hashCode() {
268
        return Objects.hash(extensionName, implementationURL, implementationVendor, implementationVendorId,
269
                implementationVersion, specificationVendor, specificationVersion);
270
    }
271
252
    // -------------------------------------------------------- Private Methods
272
    // -------------------------------------------------------- Private Methods
253
273
254
274
Lines 272-279 Link Here
272
292
273
        StringTokenizer fTok = new StringTokenizer(first, ".", true);
293
        StringTokenizer fTok = new StringTokenizer(first, ".", true);
274
        StringTokenizer sTok = new StringTokenizer(second, ".", true);
294
        StringTokenizer sTok = new StringTokenizer(second, ".", true);
275
        int fVersion = 0;
295
        int fVersion;
276
        int sVersion = 0;
296
        int sVersion;
277
        while (fTok.hasMoreTokens() || sTok.hasMoreTokens()) {
297
        while (fTok.hasMoreTokens() || sTok.hasMoreTokens()) {
278
            if (fTok.hasMoreTokens())
298
            if (fTok.hasMoreTokens())
279
                fVersion = Integer.parseInt(fTok.nextToken());
299
                fVersion = Integer.parseInt(fTok.nextToken());
(-)java/org/apache/catalina/util/ExtensionValidator.java (-56 / +46 lines)
Lines 20-28 Link Here
20
import java.io.FileInputStream;
20
import java.io.FileInputStream;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.InputStream;
22
import java.io.InputStream;
23
import java.util.ArrayList;
23
import java.util.HashSet;
24
import java.util.Iterator;
24
import java.util.List;
25
import java.util.Locale;
25
import java.util.Locale;
26
import java.util.Set;
26
import java.util.StringTokenizer;
27
import java.util.StringTokenizer;
27
import java.util.jar.JarInputStream;
28
import java.util.jar.JarInputStream;
28
import java.util.jar.Manifest;
29
import java.util.jar.Manifest;
Lines 56-67 Link Here
56
    private static final StringManager sm =
57
    private static final StringManager sm =
57
            StringManager.getManager("org.apache.catalina.util");
58
            StringManager.getManager("org.apache.catalina.util");
58
59
59
    private static volatile ArrayList<Extension> containerAvailableExtensions =
60
    private static final String MANIFEST_PATH = "/META-INF/MANIFEST.MF";
60
            null;
61
    private static final ArrayList<ManifestResource> containerManifestResources =
62
            new ArrayList<>();
63
61
62
    private static volatile Set<Extension> containerAvailableExtensions;
63
    private static final Set<ManifestResource> containerManifestResources =
64
            new HashSet<>();
64
65
66
65
    // ----------------------------------------------------- Static Initializer
67
    // ----------------------------------------------------- Static Initializer
66
68
67
69
Lines 129-144 Link Here
129
                    throws IOException {
131
                    throws IOException {
130
132
131
        String appName = context.getName();
133
        String appName = context.getName();
132
        ArrayList<ManifestResource> appManifestResources = new ArrayList<>();
134
        Set<ManifestResource> appManifestResources = new HashSet<>();
133
135
134
        // Web application manifest
136
        // Web application manifest
135
        WebResource resource = resources.getResource("/META-INF/MANIFEST.MF");
137
        WebResource resource = resources.getResource(MANIFEST_PATH);
136
        if (resource.isFile()) {
138
        if (resource.isFile()) {
137
            try (InputStream inputStream = resource.getInputStream()) {
139
            try (InputStream inputStream = resource.getInputStream()) {
138
                Manifest manifest = new Manifest(inputStream);
140
                Manifest manifest = new Manifest(inputStream);
139
                ManifestResource mre = new ManifestResource
141
                ManifestResource mre = new ManifestResource
140
                    (sm.getString("extensionValidator.web-application-manifest"),
142
                    (sm.getString("extensionValidator.web-application-manifest"),
141
                    manifest, ManifestResource.WAR);
143
                    manifest, ManifestResource.ResourceType.WAR);
142
                appManifestResources.add(mre);
144
                appManifestResources.add(mre);
143
            }
145
            }
144
        }
146
        }
Lines 145-160 Link Here
145
147
146
        // Web application library manifests
148
        // Web application library manifests
147
        WebResource[] manifestResources =
149
        WebResource[] manifestResources =
148
                resources.getClassLoaderResources("/META-INF/MANIFEST.MF");
150
                resources.getClassLoaderResources(MANIFEST_PATH);
149
        for (WebResource manifestResource : manifestResources) {
151
        for (WebResource manifestResource : manifestResources) {
150
            if (manifestResource.isFile()) {
152
            if (manifestResource.isFile()) {
151
                // Primarily used for error reporting
153
                // Primarily used for error reporting
152
                String jarName = manifestResource.getURL().toExternalForm();
154
                String jarName = manifestResource.getURL().toExternalForm();
153
                Manifest jmanifest = null;
154
                try (InputStream is = manifestResource.getInputStream()) {
155
                try (InputStream is = manifestResource.getInputStream()) {
155
                    jmanifest = new Manifest(is);
156
                    Manifest jmanifest = new Manifest(is);
156
                    ManifestResource mre = new ManifestResource(jarName,
157
                    ManifestResource mre = new ManifestResource(jarName,
157
                            jmanifest, ManifestResource.APPLICATION);
158
                            jmanifest, ManifestResource.ResourceType.APPLICATION);
158
                    appManifestResources.add(mre);
159
                    appManifestResources.add(mre);
159
                }
160
                }
160
            }
161
            }
Lines 176-182 Link Here
176
            Manifest manifest = getManifest(is);
177
            Manifest manifest = getManifest(is);
177
            if (manifest != null) {
178
            if (manifest != null) {
178
                ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest,
179
                ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest,
179
                        ManifestResource.SYSTEM);
180
                        ManifestResource.ResourceType.SYSTEM);
180
                containerManifestResources.add(mre);
181
                containerManifestResources.add(mre);
181
            }
182
            }
182
        }
183
        }
Lines 187-193 Link Here
187
188
188
189
189
    /**
190
    /**
190
     * Validates a <code>ArrayList</code> of <code>ManifestResource</code>
191
     * Validates a <code>Set</code> of <code>ManifestResource</code>
191
     * objects. This method requires an application name (which is the
192
     * objects. This method requires an application name (which is the
192
     * context root of the application at runtime).
193
     * context root of the application at runtime).
193
     *
194
     *
Lines 206-220 Link Here
206
     * @return true if manifest resource file requirements are met
207
     * @return true if manifest resource file requirements are met
207
     */
208
     */
208
    private static boolean validateManifestResources(String appName,
209
    private static boolean validateManifestResources(String appName,
209
            ArrayList<ManifestResource> resources) {
210
            Set<ManifestResource> resources) {
210
        boolean passes = true;
211
        boolean passes = true;
211
        int failureCount = 0;
212
        int failureCount = 0;
212
        ArrayList<Extension> availableExtensions = null;
213
        Set<Extension> availableExtensions = null;
213
214
214
        Iterator<ManifestResource> it = resources.iterator();
215
        for (ManifestResource mre : resources) {
215
        while (it.hasNext()) {
216
            List<Extension> requiredList = mre.getRequiredExtensions();
216
            ManifestResource mre = it.next();
217
            ArrayList<Extension> requiredList = mre.getRequiredExtensions();
218
            if (requiredList == null) {
217
            if (requiredList == null) {
219
                continue;
218
                continue;
220
            }
219
            }
Lines 228-246 Link Here
228
            // yet
227
            // yet
229
            if (containerAvailableExtensions == null) {
228
            if (containerAvailableExtensions == null) {
230
                containerAvailableExtensions
229
                containerAvailableExtensions
231
                    = buildAvailableExtensionsList(containerManifestResources);
230
                        = buildAvailableExtensionsList(containerManifestResources);
232
            }
231
            }
233
232
234
            // iterate through the list of required extensions
233
            // iterate through the list of required extensions
235
            Iterator<Extension> rit = requiredList.iterator();
234
            for (Extension requiredExt : requiredList) {
236
            while (rit.hasNext()) {
237
                boolean found = false;
235
                boolean found = false;
238
                Extension requiredExt = rit.next();
236
239
                // check the application itself for the extension
237
                // check the application itself for the extension
240
                if (availableExtensions != null) {
238
                if (availableExtensions != null) {
241
                    Iterator<Extension> ait = availableExtensions.iterator();
239
                    for (Extension targetExt : availableExtensions) {
242
                    while (ait.hasNext()) {
243
                        Extension targetExt = ait.next();
244
                        if (targetExt.isCompatibleWith(requiredExt)) {
240
                        if (targetExt.isCompatibleWith(requiredExt)) {
245
                            requiredExt.setFulfilled(true);
241
                            requiredExt.setFulfilled(true);
246
                            found = true;
242
                            found = true;
Lines 248-259 Link Here
248
                        }
244
                        }
249
                    }
245
                    }
250
                }
246
                }
247
251
                // check the container level list for the extension
248
                // check the container level list for the extension
252
                if (!found && containerAvailableExtensions != null) {
249
                if (!found && containerAvailableExtensions != null) {
253
                    Iterator<Extension> cit =
250
                    for (Extension targetExt : containerAvailableExtensions) {
254
                        containerAvailableExtensions.iterator();
255
                    while (cit.hasNext()) {
256
                        Extension targetExt = cit.next();
257
                        if (targetExt.isCompatibleWith(requiredExt)) {
251
                        if (targetExt.isCompatibleWith(requiredExt)) {
258
                            requiredExt.setFulfilled(true);
252
                            requiredExt.setFulfilled(true);
259
                            found = true;
253
                            found = true;
Lines 261-272 Link Here
261
                        }
255
                        }
262
                    }
256
                    }
263
                }
257
                }
258
264
                if (!found) {
259
                if (!found) {
265
                    // Failure
260
                    // Failure
266
                    log.info(sm.getString(
261
                    log.info(sm.getString(
267
                        "extensionValidator.extension-not-found-error",
262
                            "extensionValidator.extension-not-found-error",
268
                        appName, mre.getResourceName(),
263
                            appName, mre.getResourceName(),
269
                        requiredExt.getExtensionName()));
264
                            requiredExt.getExtensionName()));
270
                    passes = false;
265
                    passes = false;
271
                    failureCount++;
266
                    failureCount++;
272
                }
267
                }
Lines 299-323 Link Here
299
    *
294
    *
300
    * @return HashMap Map of available extensions
295
    * @return HashMap Map of available extensions
301
    */
296
    */
302
    private static ArrayList<Extension> buildAvailableExtensionsList(
297
    private static Set<Extension> buildAvailableExtensionsList(
303
            ArrayList<ManifestResource> resources) {
298
            Set<ManifestResource> resources) {
304
299
305
        ArrayList<Extension> availableList = null;
300
        Set<Extension> availableList = null;
306
301
307
        Iterator<ManifestResource> it = resources.iterator();
302
        for (ManifestResource mre : resources) {
308
        while (it.hasNext()) {
303
            List<Extension> list = mre.getAvailableExtensions();
309
            ManifestResource mre = it.next();
310
            ArrayList<Extension> list = mre.getAvailableExtensions();
311
            if (list != null) {
304
            if (list != null) {
312
                Iterator<Extension> values = list.iterator();
305
                for (Extension ext : list) {
313
                while (values.hasNext()) {
314
                    Extension ext = values.next();
315
                    if (availableList == null) {
306
                    if (availableList == null) {
316
                        availableList = new ArrayList<>();
307
                        availableList = new HashSet<>();
317
                        availableList.add(ext);
318
                    } else {
319
                        availableList.add(ext);
320
                    }
308
                    }
309
                    availableList.add(ext);
321
                }
310
                }
322
            }
311
            }
323
        }
312
        }
Lines 332-338 Link Here
332
     * @return The WAR's or JAR's manifest
321
     * @return The WAR's or JAR's manifest
333
     */
322
     */
334
    private static Manifest getManifest(InputStream inStream) throws IOException {
323
    private static Manifest getManifest(InputStream inStream) throws IOException {
335
        Manifest manifest = null;
324
        Manifest manifest;
336
        try (JarInputStream jin = new JarInputStream(inStream)) {
325
        try (JarInputStream jin = new JarInputStream(inStream)) {
337
            manifest = jin.getManifest();
326
            manifest = jin.getManifest();
338
        }
327
        }
Lines 359-373 Link Here
359
                if (files == null) {
348
                if (files == null) {
360
                    continue;
349
                    continue;
361
                }
350
                }
362
                for (int i = 0; i < files.length; i++) {
351
363
                    if (files[i].getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") &&
352
                for (File file : files) {
364
                            files[i].isFile()) {
353
                    if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") &&
354
                            file.isFile()) {
365
                        try {
355
                        try {
366
                            addSystemResource(files[i]);
356
                            addSystemResource(file);
367
                        } catch (IOException e) {
357
                        } catch (IOException e) {
368
                            log.error
358
                            log.error
369
                                (sm.getString
359
                                    (sm.getString
370
                                 ("extensionValidator.failload", files[i]), e);
360
                                            ("extensionValidator.failload", file), e);
371
                        }
361
                        }
372
                    }
362
                    }
373
                }
363
                }
(-)java/org/apache/catalina/util/ManifestResource.java (-39 / +49 lines)
Lines 16-23 Link Here
16
 */
16
 */
17
package org.apache.catalina.util;
17
package org.apache.catalina.util;
18
18
19
import java.util.ArrayList;
19
import java.nio.file.Path;
20
import java.util.Iterator;
20
import java.nio.file.Paths;
21
import java.util.*;
21
import java.util.jar.Attributes;
22
import java.util.jar.Attributes;
22
import java.util.jar.Manifest;
23
import java.util.jar.Manifest;
23
24
Lines 32-50 Link Here
32
33
33
    // ------------------------------------------------------------- Properties
34
    // ------------------------------------------------------------- Properties
34
35
35
    // These are the resource types for determining effect error messages
36
    // This enum is the resource types for determining effect error messages
36
    public static final int SYSTEM = 1;
37
    public enum ResourceType {
37
    public static final int WAR = 2;
38
        SYSTEM,
38
    public static final int APPLICATION = 3;
39
        WAR,
40
        APPLICATION
41
    }
39
42
40
    private ArrayList<Extension> availableExtensions = null;
43
    private List<Extension> availableExtensions;
41
    private ArrayList<Extension> requiredExtensions = null;
44
    private List<Extension> requiredExtensions;
42
45
43
    private final String resourceName;
46
    private final String resourceName;
44
    private final int resourceType;
47
    private final ResourceType resourceType;
45
48
46
    public ManifestResource(String resourceName, Manifest manifest,
49
    public ManifestResource(String resourceName, Manifest manifest,
47
                            int resourceType) {
50
                            ResourceType resourceType) {
48
        this.resourceName = resourceName;
51
        this.resourceName = resourceName;
49
        this.resourceType = resourceType;
52
        this.resourceType = resourceType;
50
        processManifest(manifest);
53
        processManifest(manifest);
Lines 62-80 Link Here
62
    /**
65
    /**
63
     * Gets the list of available extensions
66
     * Gets the list of available extensions
64
     *
67
     *
65
     * @return List of available extensions
68
     * @return Unmodifiable list of available extensions
66
     */
69
     */
67
    public ArrayList<Extension> getAvailableExtensions() {
70
    public List<Extension> getAvailableExtensions() {
68
        return availableExtensions;
71
        return Collections.unmodifiableList(availableExtensions);
69
    }
72
    }
70
73
71
    /**
74
    /**
72
     * Gets the list of required extensions
75
     * Gets the list of required extensions
73
     *
76
     *
74
     * @return List of required extensions
77
     * @return Unmodifiable list of required extensions
75
     */
78
     */
76
    public ArrayList<Extension> getRequiredExtensions() {
79
    public List<Extension> getRequiredExtensions() {
77
        return requiredExtensions;
80
        return Collections.unmodifiableList(requiredExtensions);
78
    }
81
    }
79
82
80
    // --------------------------------------------------------- Public Methods
83
    // --------------------------------------------------------- Public Methods
Lines 107-117 Link Here
107
        if (requiredExtensions == null) {
110
        if (requiredExtensions == null) {
108
            return true;
111
            return true;
109
        }
112
        }
110
        Iterator<Extension> it = requiredExtensions.iterator();
113
        for(Extension ext : requiredExtensions){
111
        while (it.hasNext()) {
112
            Extension ext = it.next();
113
            if (!ext.isFulfilled()) return false;
114
            if (!ext.isFulfilled()) return false;
114
        }
115
        }
116
115
        return true;
117
        return true;
116
    }
118
    }
117
119
Lines 118-141 Link Here
118
    @Override
120
    @Override
119
    public String toString() {
121
    public String toString() {
120
122
121
        StringBuilder sb = new StringBuilder("ManifestResource[");
123
        return "ManifestResource[" + resourceName +
122
        sb.append(resourceName);
124
                ", isFulfilled=" +
125
                isFulfilled() +
126
                ", requiredExtensionCount =" +
127
                getRequiredExtensionCount() +
128
                ", availableExtensionCount=" +
129
                getAvailableExtensionCount() +
130
                ", resourceType=" +
131
                resourceType +
132
                "]";
133
    }
123
134
124
        sb.append(", isFulfilled=");
135
    @Override
125
        sb.append(isFulfilled() +"");
136
    public boolean equals(Object o) {
126
        sb.append(", requiredExtensionCount =");
137
        if (this == o) return true;
127
        sb.append(getRequiredExtensionCount());
138
        if (!(o instanceof ManifestResource)) return false;
128
        sb.append(", availableExtensionCount=");
139
        ManifestResource that = (ManifestResource) o;
129
        sb.append(getAvailableExtensionCount());
140
        return Objects.equals(availableExtensions, that.availableExtensions) &&
130
        switch (resourceType) {
141
                Objects.equals(requiredExtensions, that.requiredExtensions) &&
131
            case SYSTEM : sb.append(", resourceType=SYSTEM"); break;
142
                Objects.equals(resourceName, that.resourceName) &&
132
            case WAR : sb.append(", resourceType=WAR"); break;
143
                resourceType == that.resourceType;
133
            case APPLICATION : sb.append(", resourceType=APPLICATION"); break;
134
        }
135
        sb.append("]");
136
        return (sb.toString());
137
    }
144
    }
138
145
146
    @Override
147
    public int hashCode() {
148
        return Objects.hash(availableExtensions, requiredExtensions, resourceName, resourceType);
149
    }
139
150
140
    // -------------------------------------------------------- Private Methods
151
    // -------------------------------------------------------- Private Methods
141
152
Lines 154-160 Link Here
154
     * @return List of required extensions, or null if the application
165
     * @return List of required extensions, or null if the application
155
     * does not require any extensions
166
     * does not require any extensions
156
     */
167
     */
157
    private ArrayList<Extension> getRequiredExtensions(Manifest manifest) {
168
    private List<Extension> getRequiredExtensions(Manifest manifest) {
158
169
159
        Attributes attributes = manifest.getMainAttributes();
170
        Attributes attributes = manifest.getMainAttributes();
160
        String names = attributes.getValue("Extension-List");
171
        String names = attributes.getValue("Extension-List");
Lines 161-167 Link Here
161
        if (names == null)
172
        if (names == null)
162
            return null;
173
            return null;
163
174
164
        ArrayList<Extension> extensionList = new ArrayList<>();
175
        List<Extension> extensionList = new ArrayList<>();
165
        names += " ";
176
        names += " ";
166
177
167
        while (true) {
178
        while (true) {
Lines 201-207 Link Here
201
     * @return List of available extensions, or null if the web application
212
     * @return List of available extensions, or null if the web application
202
     * does not bundle any extensions
213
     * does not bundle any extensions
203
     */
214
     */
204
    private ArrayList<Extension> getAvailableExtensions(Manifest manifest) {
215
    private List<Extension> getAvailableExtensions(Manifest manifest) {
205
216
206
        Attributes attributes = manifest.getMainAttributes();
217
        Attributes attributes = manifest.getMainAttributes();
207
        String name = attributes.getValue("Extension-Name");
218
        String name = attributes.getValue("Extension-Name");
Lines 208-214 Link Here
208
        if (name == null)
219
        if (name == null)
209
            return null;
220
            return null;
210
221
211
        ArrayList<Extension> extensionList = new ArrayList<>();
222
        List<Extension> extensionList = new ArrayList<>();
212
223
213
        Extension extension = new Extension();
224
        Extension extension = new Extension();
214
        extension.setExtensionName(name);
225
        extension.setExtensionName(name);
Lines 227-231 Link Here
227
238
228
        return extensionList;
239
        return extensionList;
229
    }
240
    }
230
231
}
241
}

Return to bug 52952