myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r1345321 - in /myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin: pom.xml src/main/java/org/apache/myfaces/tobago/maven/plugin/UnPackThemeMojo.java
Date Fri, 01 Jun 2012 19:45:37 GMT
Author: bommel
Date: Fri Jun  1 19:45:36 2012
New Revision: 1345321

URL: http://svn.apache.org/viewvc?rev=1345321&view=rev
Log:
(TOBAGO-945)
Add the version of Tobago to the resources URL to avoid caching when updating Tobago

Modified:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/pom.xml
    myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/src/main/java/org/apache/myfaces/tobago/maven/plugin/UnPackThemeMojo.java

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/pom.xml?rev=1345321&r1=1345320&r2=1345321&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/pom.xml (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/pom.xml Fri Jun 
1 19:45:36 2012
@@ -38,27 +38,27 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
+      <version>2.2.1</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-project</artifactId>
-      <version>2.0</version>
+      <version>2.2.1</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-archiver</artifactId>
-      <version>2.0</version>
+      <version>2.4.1</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.0.5</version>
+      <version>2.0.5</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
-      <version>2.0</version>
+      <version>2.2.1</version>
     </dependency>
   </dependencies>
   <build>
@@ -84,6 +84,14 @@
     <pluginManagement>
       <plugins>
         <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.3.2</version>
+          <configuration>
+            <source>1.5</source>
+            <target>1.5</target>
+          </configuration>
+        </plugin>
+        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-plugin-plugin</artifactId>
           <version>2.4.1</version>

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/src/main/java/org/apache/myfaces/tobago/maven/plugin/UnPackThemeMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/src/main/java/org/apache/myfaces/tobago/maven/plugin/UnPackThemeMojo.java?rev=1345321&r1=1345320&r2=1345321&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/src/main/java/org/apache/myfaces/tobago/maven/plugin/UnPackThemeMojo.java
(original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/tobago-theme-plugin/src/main/java/org/apache/myfaces/tobago/maven/plugin/UnPackThemeMojo.java
Fri Jun  1 19:45:36 2012
@@ -23,15 +23,24 @@ import org.codehaus.plexus.archiver.Arch
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipEntry;
+import org.codehaus.plexus.archiver.zip.ZipFile;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.FileInputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Locale;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipEntry;
+import java.util.Properties;
 
 /**
  *
@@ -65,19 +74,35 @@ public class UnPackThemeMojo extends Abs
    */
   private File webappDirectory;
 
+  /**
+   * Don't use the versioned information of the themes..
+   *
+   * @parameter
+   */
+  private boolean ignoreVersioned;
+
 
-  private boolean findThemeDescriptor(File jarFile) throws MojoExecutionException {
-    ZipInputStream zip = null;
+  private String getThemeDescriptor(File jarFile) throws MojoExecutionException {
+    ZipFile zip = null;
     try {
-      zip = new ZipInputStream(new FileInputStream(jarFile));
-      while (zip.available() > 0) {
-        ZipEntry nextEntry = zip.getNextEntry();
+      zip = new ZipFile(jarFile);
+      Enumeration files = zip.getEntries();
+      while (files.hasMoreElements()) {
+        ZipEntry nextEntry = (ZipEntry) files.nextElement();
         if (nextEntry == null || nextEntry.isDirectory()) {
           continue;
         }
         String name = nextEntry.getName();
-        if (name.equals("META-INF/tobago-theme.xml")|| name.equals("META-INF/tobago-config.xml"))
{
-          return true;
+        if (name.equals("META-INF/tobago-theme.xml") || name.equals("META-INF/tobago-config.xml"))
{
+          XmlStreamReader xsr = null;
+          try {
+            StringWriter stringWriter = new StringWriter();
+            xsr = ReaderFactory.newXmlReader(zip.getInputStream(nextEntry));
+            IOUtil.copy(xsr, stringWriter);
+            return stringWriter.toString();
+          } finally {
+            IOUtil.close(xsr);
+          }
         }
       }
     } catch (IOException e) {
@@ -91,8 +116,7 @@ public class UnPackThemeMojo extends Abs
         }
       }
     }
-
-    return false;
+    return null;
   }
 
   public void execute() throws MojoExecutionException {
@@ -104,37 +128,79 @@ public class UnPackThemeMojo extends Abs
       while (artifacts.hasNext()) {
 
         String artifact = (String) artifacts.next();
-        getLog().debug("Testing jar "+ artifact);
+        if (getLog().isDebugEnabled()) {
+          getLog().debug("Testing jar "+ artifact);
+        }
 
         File file = new File(artifact);
-        if (file.isFile() && artifact.endsWith(".jar") && findThemeDescriptor(file))
{
-          String name = file.getName();
-          File tempLocation = new File(workDirectory, name.substring(0, name.length() - 4));
-          boolean process = false;
-          if (!tempLocation.exists()) {
-            tempLocation.mkdirs();
-            process = true;
-          } else if (file.lastModified() > tempLocation.lastModified()) {
-            process = true;
-          }
-          if (process) {
-            getLog().debug("Expanding theme "+ name);
-            try {
-              unpack(file, tempLocation);
-              String[] fileNames = getThemeFiles(tempLocation);
-              for (int i = 0, fileNamesLength = fileNames.length; i < fileNamesLength;
i++) {
-                String fileName = fileNames[i];
-
-                File fromFile = new File(tempLocation, fileName);
-                File toFile = new File(webappDirectory, fileName);
+        if (file.isFile() && artifact.endsWith(".jar")) {
+          String descriptor = getThemeDescriptor(file);
+          if (descriptor != null) {
+
+            String name = file.getName();
+            File tempLocation = new File(workDirectory, name.substring(0, name.length() -
4));
+            boolean process = false;
+            if (!tempLocation.exists()) {
+              tempLocation.mkdirs();
+              process = true;
+            } else if (file.lastModified() > tempLocation.lastModified()) {
+              process = true;
+            }
+            if (process) {
+              try {
+                unpack(file, tempLocation);
+                String version = null;
+                String resourcePath = null;
                 try {
-                  FileUtils.copyFile(fromFile, toFile);
+                  Xpp3Dom xpp3Dom = Xpp3DomBuilder.build(new StringReader(descriptor));
+                  Xpp3Dom themeDefinitions = xpp3Dom.getChild("theme-definitions");
+                  if (themeDefinitions != null && !ignoreVersioned) {
+                    for (Xpp3Dom themeDefinition : themeDefinitions.getChildren()) {
+                      Xpp3Dom versionedDom = themeDefinition.getChild("versioned");
+                      if (versionedDom != null) {
+                        boolean versioned = Boolean.parseBoolean(versionedDom.getValue());
+                        if (versioned) {
+                          Xpp3Dom resourcePathDom = themeDefinition.getChild("resource-path");
+                          resourcePath = resourcePathDom.getValue();
+                          Properties properties = new Properties();
+                          String metaInf = tempLocation + "/META-INF/MANIFEST.MF";
+                          properties.load(new StringReader(FileUtils.fileRead(metaInf)));
+                          version = properties.getProperty("Implementation-Version");
+                        }
+                      }
+                    }
+                  }
                 } catch (IOException e) {
-                  throw new MojoExecutionException("Error copy file: " + fromFile + "to:
" + toFile, e);
+                  getLog().error(e);
+                } catch (XmlPullParserException e) {
+                  getLog().error(e);
+                }
+                if (getLog().isDebugEnabled()) {
+                  getLog().debug("Expanding theme: "+ name);
+                  getLog().debug("Version: " + version);
+                  getLog().debug("ResourcePath: " + resourcePath);
                 }
+                String[] fileNames = getThemeFiles(tempLocation);
+                for (int i = 0, fileNamesLength = fileNames.length; i < fileNamesLength;
i++) {
+                  String fileName = fileNames[i];
+                  File fromFile = new File(tempLocation, fileName);
+                  String toFileName = fileName;
+                  if (resourcePath != null && toFileName.startsWith(resourcePath))
{
+                    toFileName = resourcePath + "/" + version + "/" +toFileName.substring(resourcePath.length()+1);
+                  }
+                  if (getLog().isDebugEnabled()) {
+                    getLog().debug("Copy file " + fromFile + " to: " + toFileName);
+                  }
+                  File toFile = new File(webappDirectory, toFileName);
+                  try {
+                    FileUtils.copyFile(fromFile, toFile);
+                  } catch (IOException e) {
+                    throw new MojoExecutionException("Error copy file: " + fromFile + " to:
" + toFile, e);
+                  }
+                }
+              } catch (NoSuchArchiverException e) {
+                getLog().info("Skip unpacking dependency file with unknown extension: " +
file.getPath());
               }
-            } catch (NoSuchArchiverException e) {
-              getLog().info("Skip unpacking dependency file with unknown extension: " + file.getPath());
             }
           }
         }
@@ -152,8 +218,6 @@ public class UnPackThemeMojo extends Abs
       unArchiver.setSourceFile(file);
       unArchiver.setDestDirectory(location);
       unArchiver.extract();
-    } catch (IOException e) {
-      throw new MojoExecutionException("Error unpacking file: " + file + "to: " + location,
e);
     } catch (ArchiverException e) {
       throw new MojoExecutionException("Error unpacking file: " + file + "to: " + location,
e);
     }



Mime
View raw message