Author: woonsan
Date: Fri Apr 2 10:10:35 2010
New Revision: 930226
URL: http://svn.apache.org/viewvc?rev=930226&view=rev
Log:
JS2-1173: Adding an abstracted file entry collection to support both zip file
and folder.
Added:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/portlet.xml
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/view/
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/view/datetime.jsp
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/view/edit-prefs.vm
(with props)
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/web.xml
(with props)
Modified:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/UnpackResources.java
Added:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java?rev=930226&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
(added)
+++
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
Fri Apr 2 10:10:35 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.maven.utils;
+
+import java.io.File;
+import java.util.zip.ZipEntry;
+
+/**
+ * FileEntry
+ *
+ * @version $Id$
+ */
+public class FileEntry
+{
+ private ZipEntry zipEntry;
+ private File file;
+ private String name;
+
+ public FileEntry(ZipEntry zipEntry)
+ {
+ this.zipEntry = zipEntry;
+ }
+
+ public FileEntry(File file, String name)
+ {
+ this.file = file;
+ this.name = name;
+ }
+
+ public boolean isDirectory()
+ {
+ if (zipEntry != null)
+ {
+ return zipEntry.isDirectory();
+ }
+
+ return file.isDirectory();
+ }
+
+ public String getName()
+ {
+ if (zipEntry != null)
+ {
+ return zipEntry.getName();
+ }
+
+ return name;
+ }
+
+ public long getTime()
+ {
+ if (zipEntry != null)
+ {
+ return zipEntry.getTime();
+ }
+
+ return file.lastModified();
+ }
+
+ public Object getEntryObject()
+ {
+ return (zipEntry != null ? zipEntry : file);
+ }
+}
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntry.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java?rev=930226&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
(added)
+++
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
Fri Apr 2 10:10:35 2010
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.maven.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * FileEntryCollection
+ *
+ * @version $Id$
+ */
+public class FileEntryCollection
+{
+ private ZipFile zipFile;
+ private File folder;
+
+ public FileEntryCollection(ZipFile zipFile)
+ {
+ this.zipFile = zipFile;
+ }
+
+ public FileEntryCollection(File folder)
+ {
+ if (!folder.isDirectory())
+ {
+ throw new IllegalArgumentException("Folder not found: " + folder);
+ }
+
+ this.folder = folder;
+ }
+
+ public String getName()
+ {
+ if (zipFile != null)
+ {
+ return zipFile.getName();
+ }
+
+ return folder.getPath();
+ }
+
+ public Enumeration<? extends FileEntry> entries()
+ {
+ if (zipFile != null)
+ {
+ return new ZipFileEntryEnumeration(zipFile.entries());
+ }
+
+ return new FolderFileEntryEnumeration(folder);
+ }
+
+ public InputStream getInputStream(FileEntry entry) throws IOException
+ {
+ if (zipFile != null)
+ {
+ return zipFile.getInputStream((ZipEntry) entry.getEntryObject());
+ }
+
+ return new FileInputStream((File) entry.getEntryObject());
+ }
+
+ private static class ZipFileEntryEnumeration implements
Enumeration<FileEntry>
+ {
+ private Enumeration<? extends ZipEntry> zipEntries;
+
+ public ZipFileEntryEnumeration(Enumeration<? extends ZipEntry>
zipEntries)
+ {
+ this.zipEntries = zipEntries;
+ }
+
+ public boolean hasMoreElements()
+ {
+ return zipEntries.hasMoreElements();
+ }
+
+ public FileEntry nextElement()
+ {
+ return new FileEntry(zipEntries.nextElement());
+ }
+ }
+
+ private static class FolderFileEntryEnumeration implements
Enumeration<FileEntry>
+ {
+ private File folder;
+ private List<String> entryNames;
+ private Iterator<String> entryNameIterator;
+
+ public FolderFileEntryEnumeration(File folder)
+ {
+ this.folder = folder;
+ entryNames = new LinkedList<String>();
+ fillEntryNames(folder.getPath(), folder, entryNames);
+ entryNameIterator = entryNames.iterator();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return entryNameIterator.hasNext();
+ }
+
+ public FileEntry nextElement()
+ {
+ String entryName = entryNameIterator.next();
+ return new FileEntry(new File(folder, entryName), entryName);
+ }
+
+ private void fillEntryNames(String basePath, File folder, List<String>
entryNames)
+ {
+ File [] children = folder.listFiles();
+
+ if (children != null)
+ {
+ for (File child : children)
+ {
+ String name = child.getPath();
+
+ if (!name.startsWith(basePath))
+ {
+ throw new IllegalStateException("Child file path does
not starts with base path. (" + name + ", " + basePath + ")");
+ }
+
+ name = name.substring(basePath.length());
+
+ if (!"/".equals(File.separator))
+ {
+ name = name.replace(File.separator, "/");
+ }
+
+ if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+
+ entryNames.add(name);
+
+ if (child.isDirectory())
+ {
+ fillEntryNames(basePath, child, entryNames);
+ }
+ }
+ }
+ }
+ }
+}
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/FileEntryCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/UnpackResources.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/UnpackResources.java?rev=930226&r1=930225&r2=930226&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/UnpackResources.java
(original)
+++
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/UnpackResources.java
Fri Apr 2 10:10:35 2010
@@ -21,9 +21,9 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Enumeration;
import java.util.StringTokenizer;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import java.util.zip.ZipFile;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
@@ -390,23 +390,37 @@ public class UnpackResources
{
targetBaseDir.mkdirs();
}
-
- ZipInputStream zis = null;
+
+ FileEntryCollection fileEntryCollection = null;
+ ZipFile zipFile = null;
+
try
{
- zis = new ZipInputStream( new FileInputStream( resourceFile ) );
- ZipEntry ze = null;
- InputStream is = null;
+ if (!resourceFile.isDirectory())
+ {
+ zipFile = new ZipFile( resourceFile );
+ fileEntryCollection = new FileEntryCollection( zipFile );
+ }
+ else
+ {
+ fileEntryCollection = new FileEntryCollection( resourceFile );
+ }
+
+ FileEntry fileEntry = null;
File firstDestFile;
-
- while ( ( ze = zis.getNextEntry() ) != null )
+
+ Enumeration<? extends FileEntry> entries =
fileEntryCollection.entries();
+
+ while ( entries.hasMoreElements() )
{
- if (!ze.isDirectory())
+ fileEntry = entries.nextElement();
+
+ if (!fileEntry.isDirectory())
{
firstDestFile = null;
for ( int i = 0; i < unpackResources.length; i++ )
{
- String destFileName =
unpackResources[i].getDestFileName(ze.getName(), targetDirectory);
+ String destFileName =
unpackResources[i].getDestFileName(fileEntry.getName(), targetDirectory);
if ( destFileName != null )
{
File destFile = new File(destFileName);
@@ -416,15 +430,15 @@ public class UnpackResources
{
throw new
MojoExecutionException("Destination "+destFile.getAbsolutePath()+" already
exists and is not a file");
}
- if ( destFile.lastModified() >= ze.getTime()
|| !unpackResources[i].isOverwrite() )
+ if ( destFile.lastModified() >=
fileEntry.getTime() || !unpackResources[i].isOverwrite() )
{
if (verbose)
{
- log.info(ze.getName()+" skipped:
already exists at "+destFile.getAbsolutePath());
+ log.info(fileEntry.getName()+"
skipped: already exists at "+destFile.getAbsolutePath());
}
else
{
- log.debug(ze.getName()+" skipped:
already exists at "+destFile.getAbsolutePath());
+ log.debug(fileEntry.getName()+"
skipped: already exists at "+destFile.getAbsolutePath());
}
continue;
}
@@ -435,13 +449,14 @@ public class UnpackResources
}
byte[] buffer = new byte[1024];
int length = 0;
+ InputStream is = null;
FileOutputStream fos = null;
try
{
if (firstDestFile == null)
{
firstDestFile = destFile;
- is = zis;
+ is =
fileEntryCollection.getInputStream(fileEntry);
}
else
{
@@ -460,7 +475,7 @@ public class UnpackResources
}
finally
{
- if (is != zis)
+ if (is != null)
{
try
{
@@ -482,14 +497,14 @@ public class UnpackResources
}
}
}
- destFile.setLastModified(ze.getTime());
+ destFile.setLastModified(fileEntry.getTime());
if (verbose)
{
- log.info(ze.getName()+" extracted to
"+destFile.getAbsolutePath());
+ log.info(fileEntry.getName()+" extracted to
"+destFile.getAbsolutePath());
}
else
{
- log.debug(ze.getName()+" extracted to
"+destFile.getAbsolutePath());
+ log.debug(fileEntry.getName()+" extracted to
"+destFile.getAbsolutePath());
}
}
}
@@ -502,11 +517,11 @@ public class UnpackResources
}
finally
{
- if ( zis != null )
+ if ( zipFile != null )
{
try
{
- zis.close();
+ zipFile.close();
}
catch ( IOException e )
{
Added:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java?rev=930226&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
(added)
+++
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
Fri Apr 2 10:10:35 2010
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.maven.utils;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * TestFileEntryCollection
+ *
+ * @version $Id$
+ */
+public class TestFileEntryCollection extends TestCase
+{
+ private static final String TEST_PA_RESOURCE_PATH = "testdata/test-pa";
+
+ private File testPAFolder;
+ private File tempZipFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ URL testPAFolderURL =
getClass().getClassLoader().getResource(TEST_PA_RESOURCE_PATH);
+ assertEquals("The test pa folder url is expected to be a file: url in
this test case",
+ "file", testPAFolderURL.getProtocol());
+ testPAFolder = new File(testPAFolderURL.toURI());
+ assertTrue("Test PA folder not found: " + testPAFolder,
testPAFolder.isDirectory());
+ }
+
+ @Override
+ public void tearDown()
+ {
+ if (tempZipFile != null)
+ {
+ tempZipFile.delete();
+ }
+ }
+
+ public void testFolder() throws Exception
+ {
+ FileEntryCollection fec = new FileEntryCollection(testPAFolder);
+ assertEquals(testPAFolder.getPath(), fec.getName());
+
+ List<FileEntry> entryList = getEntryList(fec);
+
+ String entryName = "WEB-INF";
+ FileEntry entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertTrue(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+
+ entryName = "WEB-INF/web.xml";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+ InputStream is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/portlet.xml";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/jetspeed-portlet.xml";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/view";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertTrue(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+
+ entryName = "WEB-INF/view/datetime.jsp";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/view/edit-prefs.vm";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ assertEquals(new File(testPAFolder, entryName).lastModified(),
entry.getTime());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+ }
+
+ public void testZipFile() throws Exception
+ {
+ tempZipFile = File.createTempFile(getClass().getName(), ".zip");
+
+ OutputStream os = null;
+ BufferedOutputStream bos = null;
+ ZipOutputStream zipOutput = null;
+
+ try
+ {
+ os = new FileOutputStream(tempZipFile);
+ bos = new BufferedOutputStream(os);
+ zipOutput = new ZipOutputStream(bos);
+ addFileEntryToZipOutput(testPAFolder, testPAFolder, zipOutput);
+ }
+ finally
+ {
+ if (zipOutput != null)
+ {
+ try
+ {
+ zipOutput.close();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ if (bos != null)
+ {
+ try
+ {
+ bos.close();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ if (os != null)
+ {
+ try
+ {
+ os.close();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ }
+
+ assertTrue(tempZipFile.length() > 0L);
+
+ ZipFile zipFile = new ZipFile(tempZipFile);
+ FileEntryCollection fec = new FileEntryCollection(zipFile);
+ assertEquals(zipFile.getName(), fec.getName());
+
+ List<FileEntry> entryList = getEntryList(fec);
+
+ String entryName = "WEB-INF/web.xml";
+ FileEntry entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ InputStream is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/portlet.xml";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/jetspeed-portlet.xml";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/view/datetime.jsp";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ entryName = "WEB-INF/view/edit-prefs.vm";
+ entry = findEntry(entryList, entryName);
+ assertNotNull("Entry not found: " + entryName, entry);
+ assertFalse(entry.isDirectory());
+ is = fec.getInputStream(entry);
+ assertNotNull(is);
+ is.close();
+
+ zipFile.close();
+
+ tempZipFile.delete();
+ tempZipFile = null;
+ }
+
+ private void addFileEntryToZipOutput(File baseFolder, File file,
ZipOutputStream zipOutput) throws Exception
+ {
+ if (file.isDirectory())
+ {
+ File [] children = file.listFiles();
+
+ for (File child : children)
+ {
+ addFileEntryToZipOutput(baseFolder, child, zipOutput);
+ }
+ }
+ else
+ {
+ InputStream is = null;
+ BufferedInputStream bis = null;
+
+ try
+ {
+ String entryName =
file.getPath().substring(baseFolder.getPath().length() + 1);
+ if (!File.separator.equals("/"))
+ {
+ entryName = entryName.replace(File.separator, "/");
+ }
+ is = new FileInputStream(file);
+ bis = new BufferedInputStream(is);
+ ZipEntry zipEntry = new ZipEntry(entryName);
+ zipOutput.putNextEntry(zipEntry);
+
+ byte [] buffer = new byte[4096];
+ int readLen = bis.read(buffer, 0, 4096);
+ while (readLen != -1)
+ {
+ zipOutput.write(buffer, 0, readLen);
+ readLen = bis.read(buffer, 0, 4096);
+ }
+
+ zipOutput.closeEntry();
+ }
+ finally
+ {
+ if (bis != null)
+ {
+ try
+ {
+ bis.close();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ private List<FileEntry> getEntryList(final FileEntryCollection fec)
+ {
+ List<FileEntry> list = new LinkedList<FileEntry>();
+
+ Enumeration<? extends FileEntry> entries = fec.entries();
+
+ while (entries.hasMoreElements())
+ {
+ FileEntry entry = entries.nextElement();
+ list.add(entry);
+ }
+
+ return list;
+ }
+
+ private FileEntry findEntry(final List<FileEntry> list, String name)
+ {
+ for (FileEntry entry : list)
+ {
+ if (entry.getName().equals(name))
+ {
+ return entry;
+ }
+ }
+
+ return null;
+ }
+
+
+}
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/java/org/apache/jetspeed/maven/utils/TestFileEntryCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml?rev=930226&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml
(added)
+++
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml
Fri Apr 2 10:10:35 2010
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<portlet-app id="test-pa" version="1.0"
+ xmlns="http://portals.apache.org/jetspeed"
+ xmlns:js="http://portals.apache.org/jetspeed"
+ xmlns:dc="http://www.purl.org/dc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://portals.apache.org/jetspeed
http://portals.apache.org/jetspeed-2/2.1/schemas/jetspeed-portlet.xsd">
+
+ <js:security-constraint-ref>admin</js:security-constraint-ref>
+ <js:metadata name="pa-version">2.1.3</js:metadata>
+
+ <dc:title>Jetspeed-2 Administration Portlets</dc:title>
+ <dc:title xml:lang="en">Jetspeed-2 Administration Portlets</dc:title>
+ <dc:creator>J2 Team</dc:creator>
+
+ <portlet>
+ <portlet-name>LoginPortlet</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <dc:title>Login Portlet</dc:title>
+ <dc:creator>J2 Team</dc:creator>
+ </portlet>
+
+ <portlet>
+ <portlet-name>LoginPortletForXHTMLBasic</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <dc:title>Login XHTML Portlet</dc:title>
+ <dc:creator>J2 Team</dc:creator>
+ <js:metadata name="selector.conditional.role">admin</js:metadata>
+ </portlet>
+
+
+ <portlet>
+ <portlet-name>PortalLoginPortlet</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <dc:title>Portal Login Portlet</dc:title>
+ <dc:creator>J2 Team</dc:creator>
+ <js:metadata name="selector.conditional.role">admin</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>LocaleSelector</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <dc:title>Locale Selector Portlet</dc:title>
+ <dc:creator>J2 Team</dc:creator>
+ </portlet>
+
+ <portlet>
+ <portlet-name>DateTimePortlet</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ </portlet>
+
+ <portlet>
+ <portlet-name>ForgottenPasswordPortlet</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <js:metadata
name="merge.portal.parameters.with.portlet.parameters">true</js:metadata>
+ <js:metadata
name="merge.portal.parameters.before.portlet.parameters">true</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>UserRegistrationPortlet</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <js:metadata
name="merge.portal.parameters.with.portlet.parameters">true</js:metadata>
+ <js:metadata
name="merge.portal.parameters.before.portlet.parameters">true</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>CategoryPortletSelector</portlet-name>
+ <js:security-constraint-ref>AEUV</js:security-constraint-ref>
+ <js:metadata
name="merge.portal.parameters.with.portlet.parameters">true</js:metadata>
+ <js:metadata
name="merge.portal.parameters.before.portlet.parameters">true</js:metadata>
+ <js:metadata name="selector.conditional.role">admin</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>WelcomeToJetspeed</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <js:metadata name="selector.conditional.role">*</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>AboutJetspeed</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <js:metadata name="selector.conditional.role">*</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>JetspeedDeveloper</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ <js:metadata name="selector.conditional.role">*</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>ChangePasswordPortlet</portlet-name>
+ <js:security-constraint-ref>public-view</js:security-constraint-ref>
+ </portlet>
+
+ <portlet>
+ <portlet-name>DevelopersBrowser</portlet-name>
+ <js:security-constraint-ref>devmgr</js:security-constraint-ref>
+ <js:metadata name="selector.conditional.role">*</js:metadata>
+ </portlet>
+
+ <portlet>
+ <portlet-name>DeveloperDetails</portlet-name>
+ <js:security-constraint-ref>devmgr</js:security-constraint-ref>
+ <js:metadata name="selector.conditional.role">*</js:metadata>
+ </portlet>
+
+ <js:services>
+ <js:service name='ApplicationServerManager'/>
+ <js:service name='DeploymentManager'/>
+ <js:service name='EntityAccessor'/>
+ <js:service name='GroupManager'/>
+ <js:service name='PageManager'/>
+ <js:service name='PermissionManager'/>
+ <js:service name='PortletFactory'/>
+ <js:service name='PortalAdministration'/>
+ <js:service name='PortletRegistryComponent'/>
+ <js:service name='PortalStatistics'/>
+ <js:service name="Profiler" />
+ <js:service name='RoleManager'/>
+ <js:service name='SearchComponent'/>
+ <js:service name="SSO" />
+ <js:service name='UserManager'/>
+ <js:service name='DecorationFactory'/>
+ <js:service name='SecurityAccessController'/>
+ <js:service name='PortletTrackingManager'/>
+ <js:service name='PortalConfiguration'/>
+ <js:service name='ImporterManager'/>
+ <js:service name='AuditActivity'/>
+ <js:service name='JetspeedSerializerFactory'/>
+ </js:services>
+
+</portlet-app>
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/test/resources/testdata/test-pa/WEB-INF/jetspeed-portlet.xml
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]