Today, my colleague asked me where to obtain the default resource file of the Liferay framework when building Theme in Maven. I compared the process of using Ant to compile and deploy Theme and using Maven to compile and deploy Theme, and found that: when copying the default resource file of the framework, it is actually a completely different policy!
Ant replication Liferay default resource file policy:
As we all know, when using Ant to compile Theme, our programmers need to add some resource files different from the Liferay framework under the _ diffs directory, the resource files of the Liferay framework will be copied to your new theme project from the $ LIFERAY_HOME \ tomcat-7.0.23 \ webapps \ ROOT \ html \ themes directory.
- <copy todir="docroot" overwrite="true">
- <fileset
- dir="${app.server.portal.dir}/html/themes/_styled"
- />
- </copy>
By default, Maven replicates Liferay resource files:
Maven does not copy resource files from ROOT/html/themes. Instead, it willCalled portal-web-6.1.0.war. This warPackage on your machine ~ /. M2/repository points to the local repository: for example, my repository is C: \ Documents ents and Settings \ charles. wang \. m2 \ repository \ com \ liferay \ portal-web \ 6.1.0Directory.
All of this happens.Liferay-maven-pluginLifecycleTheme-mergeWhen we slow down 10 thousand times, we can see the details clearly (The essence of Taiji).
Theme-merge stageLet's use the resource file + system resource file merge developed by ourselves to artifact:
First, it defines the related environment Configuration:
- [DEBUG] -----------------------------------------------------------------------
- [DEBUG] Goal: com.liferay.maven.plugins:liferay-maven-plugin:6.1.0:theme-merge (default)
- [DEBUG] Style: Regular
- [DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
- <configuration>
- <liferayVersion>6.1.0</liferayVersion>
- <localArtifactRepository>${localRepository}</localArtifactRepository>
- <parentTheme default-value="_styled">_styled</parentTheme>
- <remoteArtifactRepositories>${project.remoteArtifactRepositories}</remoteArtifactRepositories>
- <themeType default-value="vm">vm</themeType>
- <webappDir>${project.build.directory}/${project.build.finalName}</webappDir>
- <workDir>${project.build.directory}/liferay-theme/work</workDir>
- </configuration>
Final executionTheme-mergeCorresponding class, located inLiferay-maven-plugin-6.1.0.jarOfThemeMergeMojoClass, all the parameters used in the class are written in the configuration file and passed in:
These parameters are related to the machine on which you run the Maven command, because you have set~ /. M2/repositoryLocal repository, and you have setPom. xmlFor more information about these parameters on my machine, see the 02-16 lines:
- [DEBUG] logging ing mojo 'com. liferay. maven. plugins: liferay-maven-plugin: 6.1.0: theme-merge' with basic aggregator -->
- [DEBUG] (f) liferayVersion = 6.1.0
- [DEBUG] (f) localArtifactRepository = id: local
- Url: file: // C:/Documents % 20and % 20 Settings/charles. wang/. m2/repository/
- Layout: none
-
- [DEBUG] (f) parentTheme = _ styled
- [DEBUG] (f) remoteArtifactRepositories = [id: central
- Url: http://repo1.maven.org/maven2
- Layout: default
- Snapshots: [enabled => false, update => daily]
- Releases: [enabled => true, update => daily]
- ]
- [DEBUG] (f) themeType = vm
- [DEBUG] (f) webappDir = D: \ WalmartProject \ maven-build-theme \ target \ maven-build-theme-0.0.1-SNAPSHOT
- [DEBUG] (f) workDir = D: \ WalmartProject \ maven-build-theme \ target \ liferay-theme \ work
- [DEBUG] -- end configuration-
- [DEBUG] Expanding: C: \ Documents and Settings \ charles. wang \. m2 \ repository \ com \ liferay \ portal-web \ 6.1.0 \ portal-web-6.1.0.war into D: \ WalmartProject \ maven-build-theme \ target \ liferay-theme \ work is where to obtain the resource file log)
Then the second line shows howPortal-web-6.1.0.warCopy the related static Resources in the package to your custom theme application. This log is executed by the following code snippet. It first defines that you want to obtain the static Resources in the war package.(Include)And exclusion(Exclude)Resources:
- protected void doExecute() throws Exception {
- if (!this.workDir.exists()) {
- this.workDir.mkdirs();
- }
-
- String parentThemeGroupId = "com.liferay.portal";
- String parentThemeArtifactId = "portal-web";
- String parentThemeVersion = this.liferayVersion;
-
- String[] excludes = { "html/themes/classic/_diffs/**", "html/themes/control_panel/_diffs/**" };
-
- String[] includes = { "html/themes/_unstyled/**", "html/themes/_styled/**", "html/themes/classic/**", "html/themes/control_panel/**" };
Then createArtifactObject pointing~ /. M2/repositoryWarehousePortal-web-6.1.0.warPackage:
- Artifact artifact = this.artifactFactory.createArtifact(parentThemeGroupId, parentThemeArtifactId, parentThemeVersion, "", "war");
Unbind the war package and extract resources from it according to the defined pair des and excludes:
- this.artifactResolver.resolve(artifact, this.remoteArtifactRepositories, this.localArtifactRepository);
-
- UnArchiver unArchiver = this.archiverManager.getUnArchiver(artifact.getFile());
-
- unArchiver.setDestDirectory(this.workDir);
- unArchiver.setSourceFile(artifact.getFile());
-
- IncludeExcludeFileSelector includeExcludeFileSelector = new IncludeExcludeFileSelector();
-
- includeExcludeFileSelector.setExcludes(excludes);
- includeExcludeFileSelector.setIncludes(includes);
-
- unArchiver.setFileSelectors(new FileSelector[] { includeExcludeFileSelector });
-
- unArchiver.extract();
Finally, let's make some copies. The extracted resource files are copied to our custom theme application:
- FileUtils.copyDirectory(new File(this.workDir, "html/themes/_unstyled"), this.webappDir);
- FileUtils.copyDirectory(new File(this.workDir, "html/themes/_styled"), this.webappDir);
- FileUtils.copyDirectory(new File(this.workDir, "html/themes/" + this.parentTheme), this.webappDir);
- FileUtils.copyDirectory(this.workDir, this.webappDir);
Therefore, we can see both the resource file defined by ourselves and the resource file containing theme in the custom theme.