Archive { public static Collection<URL> getConfigurationURL(List<String> appDeployDirectories, Set<Archive> appDeployArchives, String configuration) throws IOException { if (configuration == null || configuration.isEmpty()) throw new IllegalArgumentException("The path to the configuration cannot be empty"); if (appDeployDirectories == null || appDeployDirectories.isEmpty() || appDeployArchives == null || appDeployArchives.isEmpty()) return Collections.emptyList(); Collection<URL> result = new LinkedHashSet<URL>(); for (String directory : appDeployDirectories) { File dir = new File(directory); if (!dir.exists()) { LOG.debug("The directory {} doesn't exist", directory); continue; } result.addAll(getConfigurationURL(dir, appDeployArchives, configuration, true)); } return result; } Archive(String type, boolean useDirWoExt, boolean allowsDir, Set<Archive> subArchives); String getType(); boolean isUseDirWoExt(); boolean isAllowsDir(); Set<Archive> getSubArchives(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static Collection<URL> getConfigurationURL(List<String> appDeployDirectories,
      Set<Archive> appDeployArchives, String configuration); static URL createArchiveURL(String url); static boolean isArchiveURL(String url); static final String PROTOCOL; static final Archive WAR; static final Archive EAR; }
@Test public void testGetConfigurationURL() throws Exception { try { Archive.getConfigurationURL(null, null, null); fail("An IllegalArgumentException was expected"); } catch (IllegalArgumentException e) { } String configuration = "foo/config.xml"; URL urlArchives = getClass().getResource("."); String path = new File(urlArchives.toURI()).getAbsolutePath(); Archive zip = new Archive("zip", true, true, Collections.singleton(new Archive("zip", true, true, null))); assertTrue(Archive.getConfigurationURL(null, null, configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(null, Collections.<Archive> emptySet(), configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(null, Collections.singleton(zip), configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(Collections.<String> emptyList(), null, configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(Collections.<String> emptyList(), Collections.<Archive> emptySet(), configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(Collections.<String> emptyList(), Collections.singleton(zip), configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(null, null, configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(null, Collections.<Archive> emptySet(), configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(Collections.singletonList(path), null, configuration).isEmpty()); assertTrue(Archive.getConfigurationURL(Collections.singletonList(path), Collections.<Archive> emptySet(), configuration).isEmpty()); Collection<URL> result = Archive.getConfigurationURL(Collections.singletonList(path), Collections.singleton(zip), configuration); String[] aResult1 = {"ar-with-dir-and-ar-with-config-dir.zip!/ar-without-dir.zip!/foo/config.xml", "ar-with-dir-and-ar-with-config-dir.zip!/dir-with-ext.zip/foo/config.xml", "ar-with-dir-and-ar-with-config-file.zip!/foo/config.xml", "ar-with-dir-and-ar.zip!/ar-without-dir.zip!/foo/config.xml", "ar-with-dir-and-ar.zip!/dir-with-ext.zip/foo/config.xml", "ar-without-dir.zip!/foo/config.xml", "dir-with-dir-and-ar-with-config-dir.zip/ar-without-dir.zip!/foo/config.xml", "dir-with-dir-and-ar-with-config-dir.zip/dir-with-ext.zip/foo/config.xml", "dir-with-dir-and-ar-with-config-file.zip/foo/config.xml", "dir-with-dir-and-ar.zip/ar-without-dir.zip!/foo/config.xml", "dir-with-dir-and-ar.zip/dir-with-ext.zip/foo/config.xml", "dir-with-ext.zip/foo/config.xml", "dir-without-ext/foo/config.xml", "dir-without-ext-with-ar/foo/config.xml"}; assertEquals(aResult1.length, result.size()); Iterator<URL> it = result.iterator(); for (int i = 0; it.hasNext(); i++) { String p = it.next().toString(); assertTrue(p + " doesn't end with " + aResult1[i], p.endsWith(aResult1[i])); } zip = new Archive("zip", false, true, Collections.singleton(new Archive("zip", false, true, null))); result = Archive.getConfigurationURL(Collections.singletonList(path), Collections.singleton(zip), configuration); String[] aResult2 = {"ar-with-dir-and-ar-with-config-dir.zip!/ar-without-dir.zip!/foo/config.xml", "ar-with-dir-and-ar-with-config-dir.zip!/dir-with-ext.zip/foo/config.xml", "ar-with-dir-and-ar-with-config-file.zip!/foo/config.xml", "ar-with-dir-and-ar.zip!/ar-without-dir.zip!/foo/config.xml", "ar-with-dir-and-ar.zip!/dir-with-ext.zip/foo/config.xml", "ar-without-dir.zip!/foo/config.xml", "dir-with-dir-and-ar-with-config-dir.zip/ar-without-dir.zip!/foo/config.xml", "dir-with-dir-and-ar-with-config-dir.zip/dir-with-ext.zip/foo/config.xml", "dir-with-dir-and-ar-with-config-file.zip/foo/config.xml", "dir-with-dir-and-ar.zip/ar-without-dir.zip!/foo/config.xml", "dir-with-dir-and-ar.zip/dir-with-ext.zip/foo/config.xml", "dir-with-ext.zip/foo/config.xml", "dir-without-ext-with-ar.zip!/foo/config.xml"}; assertEquals(aResult2.length, result.size()); it = result.iterator(); for (int i = 0; it.hasNext(); i++) { String p = it.next().toString(); assertTrue(p + " doesn't end with " + aResult2[i], p.endsWith(aResult2[i])); } zip = new Archive("zip", false, false, Collections.singleton(new Archive("zip", false, false, null))); result = Archive.getConfigurationURL(Collections.singletonList(path), Collections.singleton(zip), configuration); String[] aResult3 = {"ar-with-dir-and-ar-with-config-dir.zip!/ar-without-dir.zip!/foo/config.xml", "ar-with-dir-and-ar-with-config-file.zip!/foo/config.xml", "ar-with-dir-and-ar.zip!/ar-without-dir.zip!/foo/config.xml", "ar-without-dir.zip!/foo/config.xml", "dir-without-ext-with-ar.zip!/foo/config.xml"}; assertEquals(aResult3.length, result.size()); it = result.iterator(); for (int i = 0; it.hasNext(); i++) { String p = it.next().toString(); assertTrue(p + " doesn't end with " + aResult3[i], p.endsWith(aResult3[i])); } zip = new Archive("zip", false, false, null); result = Archive.getConfigurationURL(Collections.singletonList(path), Collections.singleton(zip), configuration); String[] aResult4 = {"ar-with-dir-and-ar-with-config-file.zip!/foo/config.xml", "ar-without-dir.zip!/foo/config.xml", "dir-without-ext-with-ar.zip!/foo/config.xml"}; assertEquals(aResult4.length, result.size()); it = result.iterator(); for (int i = 0; it.hasNext(); i++) { String p = it.next().toString(); assertTrue(p + " doesn't end with " + aResult4[i], p.endsWith(aResult4[i])); } zip = new Archive("zip", true, false, Collections.singleton(new Archive("zip", true, false, null))); result = Archive.getConfigurationURL(Collections.singletonList(path), Collections.singleton(zip), configuration); String[] aResult5 = {"ar-with-dir-and-ar-with-config-dir.zip!/ar-without-dir.zip!/foo/config.xml", "ar-with-dir-and-ar-with-config-file.zip!/foo/config.xml", "ar-with-dir-and-ar.zip!/ar-without-dir.zip!/foo/config.xml", "ar-without-dir.zip!/foo/config.xml", "dir-without-ext/foo/config.xml", "dir-without-ext-with-ar/foo/config.xml"}; assertEquals(aResult5.length, result.size()); it = result.iterator(); for (int i = 0; it.hasNext(); i++) { String p = it.next().toString(); assertTrue(p + " doesn't end with " + aResult5[i], p.endsWith(aResult5[i])); } zip = new Archive("zip", true, false, null); result = Archive.getConfigurationURL(Collections.singletonList(path), Collections.singleton(zip), configuration); String[] aResult6 = {"ar-with-dir-and-ar-with-config-file.zip!/foo/config.xml", "ar-without-dir.zip!/foo/config.xml", "dir-without-ext/foo/config.xml", "dir-without-ext-with-ar/foo/config.xml"}; assertEquals(aResult6.length, result.size()); it = result.iterator(); for (int i = 0; it.hasNext(); i++) { String p = it.next().toString(); assertTrue(p + " doesn't end with " + aResult6[i], p.endsWith(aResult6[i])); } }