+ * For example: + * {@code + *+ */ + + /** + * Switch to enable/disable the Apache Solr 4 web application when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enableSolr", defaultValue = "true") + protected boolean enableSolr; + + /** + * Switch to enable/disable the H2 database when running embedded Tomcat. + * This also brings in the needed H2 database scripts. + */ + @Parameter(property = "maven.alfresco.enableH2", defaultValue = "false") + protected boolean enableH2; + + /** + * Switch to enable/disable the MySQL database when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enableMySQL", defaultValue = "false") + protected boolean enableMySQL; + + /** + * Switch to enable/disable the PostgreSQL database when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enablePostgreSQL", defaultValue = "false") + protected boolean enablePostgreSQL; + + /** + * Switch to enable/disable the Enterprise database (such as Oracle or MS SQL Server) when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enableEnterpriseDb", defaultValue = "false") + protected boolean enableEnterpriseDb; + + /** + * Switch to enable/disable the Platform/Repository (alfresco.war) when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enablePlatform", defaultValue = "true") + protected boolean enablePlatform; + + /** + * Switch to enable/disable the Share (share.war) when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enableShare", defaultValue = "true") + protected boolean enableShare; + + /** + * Enables the use of custom context path for the Share webapp. + * Some solution integrators uses a custom context path for Share in their projects. + * This property enables them to continue to do that in SDK 3 without having to completely override the + * Maven Tomcat plugin configuration, or not use it at all and go back the good old runner project again... + */ + @Parameter(property = "maven.alfresco.shareContextPath", defaultValue = "/share") + protected String shareContextPath; + + /** + * Share Log4j.properties configuration cannot be customized via extension + * put on the classpath, like on the platform side. + * So we need to override the log4j.properties in share/WEB-INF/classes + * to be able to log from custom code. + * This property can be used to turn off this overriding, to produce a WAR with + * the standard Share log4j.properties file. + */ + @Parameter(property = "maven.alfresco.useCustomShareLog4jConfig", defaultValue = "true") + protected boolean useCustomShareLog4jConfig; + + /** + * Switch to enable/disable the Alfresco REST API Explorer (api-explorer.war) when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enableApiExplorer", defaultValue = "false") + protected boolean enableApiExplorer; + + /** + * Switch to enable/disable Alfresco Activiti Workflow Engine (activiti-app.war) when running embedded Tomcat. + * This contains the Alfresco Activiti webapp, including the workflow engine. + * This webapp is also the user interface for people involved in the task and processes + * running in the Activiti engine. + * You also use this webapp to create and manage process definitions, and to display and define analytics + * reports on users' tasks and processes. + */ + @Parameter(property = "maven.alfresco.enableActivitiApp", defaultValue = "false") + protected boolean enableActivitiApp; + + /** + * Switch to enable/disable Alfresco Activiti Admin (activiti-admin.war) when running embedded Tomcat. + * This contains the Alfresco Activiti Administrator webapp. You use this to administer and monitor your + * Alfresco Activiti engines. + * + */ + @Parameter(property = "maven.alfresco.enableActivitiAdmin", defaultValue = "false") + protected boolean enableActivitiAdmin; + + /** + * Switch to enable/disable test properties when running embedded Tomcat. + */ + @Parameter(property = "maven.alfresco.enableTestProperties", defaultValue = "true") + protected boolean enableTestProperties; + + /** + * Control if Tomcat 7 Plugin should be kicked off and start Apache Tomcat + */ + @Parameter(property = "maven.alfresco.startTomcat", defaultValue = "true") + protected boolean startTomcat; + + /** + * Directory containing test files that should be used when running embedded Tomcat + */ + @Parameter(property = "maven.alfresco.testFolder", defaultValue = "src/test/properties/${env}") + protected String testFolder; + + /** + * Test files in testFolder that should be included when running embedded Tomcat + */ + @Parameter(property = "maven.alfresco.testInclude", defaultValue = "**") + protected String testInclude; + + /** + * JARs and AMPs that should be overlayed/applied to the Platform/Repository WAR (i.e. alfresco.war) + */ + @Parameter(property = "maven.alfresco.platform.modules", defaultValue = "") + protected List+ * + * } + *org.alfresco.maven.plugin + *alfresco-maven-plugin + *3.0.0 + *+ * + *community + *true + *true + *true + *false * + *+ * + *+ * + *${alfresco.groupId} + *alfresco-share-services + *${alfresco.share.version} + *amp + *
+ * {@code + *+ * + * @param groupId + * @param artifactId + * @param version + * @param contextPath + * @param contextFile + * @return + */ + private Element createWebAppElement(String groupId, + String artifactId, + String version, + String contextPath, + String contextFile) { + String errorStr = "cannot be null when creating webapp element for Tomcat 7 plugin"; + if (StringUtils.isBlank(groupId)) { + getLog().error("Maven Group Id " + errorStr); + } + if (StringUtils.isBlank(artifactId)) { + getLog().error("Maven Artifact Id " + errorStr); + } + if (StringUtils.isBlank(version)) { + getLog().error("Maven Version number " + errorStr); + } + + Element groupIdEl = element(name("groupId"), groupId); + Element artifactIdEl = element(name("artifactId"), artifactId); + Element versionEl = element(name("version"), version); + Element typeEl = element(name("type"), "war"); + // Make sure webapp is loaded with context and everything, + // if set to 'false' then you will get 404 when trying to access the webapp from browser + Element asWebappEl = element(name("asWebapp"), "true"); + Element contextPathEl = element(name("contextPath"), contextPath); + + Element e; + if (StringUtils.isNotBlank(contextFile)) { + e = element(name("webapp"), + groupIdEl, artifactIdEl, versionEl, typeEl, asWebappEl, contextPathEl, + element(name("contextFile"), contextFile)); + + } else { + e = element(name("webapp"), + groupIdEl, artifactIdEl, versionEl, typeEl, asWebappEl, contextPathEl); + } + + getLog().info(e.toDom().toUnescapedString()); + + return e; + } + + /** + * Returns true if current platform version (i.e. version of alfresco.war) is + * >= 5.1 + * + * @return true if platform version >= 5.1 + */ + private boolean isPlatformVersionGtOrEqTo51() { + if (getPlatformVersionNumber() >= 51) { + return true; + } + + return false; + } + + /** + * Returns true if current platform version (i.e. version of alfresco.war) is + * <= 4.2 + * + * @return true if platform version <= 4.2 + */ + private boolean isPlatformVersionLtOrEqTo42() { + if (getPlatformVersionNumber() <= 42) { + return true; + } + + return false; + } + + /** + * Grabs the first 2 numbers in the version string + * + * @return major and minor version as int, such as 41,50,51 + */ + private int getPlatformVersionNumber() { + return Integer.parseInt(alfrescoPlatformVersion.replaceAll("[^0-9]", "").substring(0, 2)); + } + + /** + * Get the Solr artifactId, it changes when we move to Solr 4 in Alfresco version 5 + * + * @return the Maven artifactId for Solr + */ + private String getSolrArtifactId() { + // artifactId for Solr defaults to version 4 = alfresco-solr4 + + if (isPlatformVersionLtOrEqTo42()) { + // Solr version 1 is used in Alfresco 4.0 -> 4.2, Solr version 4.0 was introduced in Alfresco version 5.0 + alfrescoSolrArtifactId = "alfresco-solr"; + } + + return alfrescoSolrArtifactId; + } + + /** + * Get the Alfresco Platform Webapp artifactId (i.e. for alfresco.war), + * it changes from 'alfresco' to 'alfresco-platform' in 5.1. + * + * @return the Maven artifactId for Alfresco Platform webapp + */ + private String getPlatformWarArtifactId() { + // Default alfrescoPlatformWarArtifactId is 'alfresco-platform' + + if (isPlatformVersionGtOrEqTo51() == false) { + // We are running version 4.2 or 5.0, so use older artifactId + alfrescoPlatformWarArtifactId = "alfresco"; + } else if (alfrescoEdition.equals(ALFRESCO_ENTERPRISE_EDITION)) { + alfrescoPlatformWarArtifactId = "alfresco-enterprise"; + } + + return alfrescoPlatformWarArtifactId; + } + + /** + * Get the Solr webapp element for use by Tomcat, it changes when we move to Solr 4 in Alfresco version 5 + * + * @return tomcat webapp element + */ + private Element getSolrWebappElement() { + Element webappElement = null; + + if (isPlatformVersionLtOrEqTo42()) { + // Solr version 1.0 + webappElement = createWebAppElement("${project.groupId}", getSolrArtifactId(), "${project.version}", + "/solr", "${project.build.testOutputDirectory}/tomcat/context-solr.xml"); + } else { + // Solr version 4.0 + webappElement = createWebAppElement(alfrescoGroupId, getSolrArtifactId(), alfrescoPlatformVersion, + "/solr4", "${project.build.testOutputDirectory}/tomcat/context-solr.xml"); + } + + return webappElement; + } + + /** + * TODO: From 5.1.e and onwards we have the alfresco-repository:h2scripts:jar artifact, so we potentially only need to do this for older than 5.1.e + * + * + * Extract PostgreSQL dialect and ibatis from alfresco-repository, rename to H2Dialect in the test-classes + * + * @return + */ + private void copyH2Dialect() throws MojoExecutionException { + getLog().info("Unpacking DB Dialects and ibatis files from alfresco-repository artifact"); + executeMojo( + plugin( + groupId("org.apache.maven.plugins"), + artifactId("maven-dependency-plugin"), + version(MAVEN_DEPENDENCY_PLUGIN_VERSION) + ), + goal("unpack"), + configuration( + element(name("outputDirectory"), "${project.build.testOutputDirectory}"), + element(name("artifactItems"), + element(name("artifactItem"), + element(name("groupId"), alfrescoGroupId), + element(name("artifactId"), "alfresco-repository"), + element(name("version"), alfrescoPlatformVersion), + element(name("includes"), "alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/dbscripts/upgrade/*/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/ibatis/org.hibernate.dialect.PostgreSQLDialect/*") + ) + ) + ), + execEnv + ); + + // If we're in enterprise we need to make sure we grab everything + if (this.alfrescoEdition.equals(ALFRESCO_ENTERPRISE_EDITION)) { + executeMojo( + plugin( + groupId("org.apache.maven.plugins"), + artifactId("maven-dependency-plugin"), + version(MAVEN_DEPENDENCY_PLUGIN_VERSION) + ), + goal("unpack"), + configuration( + element(name("outputDirectory"), "${project.build.testOutputDirectory}"), + element(name("artifactItems"), + element(name("artifactItem"), + element(name("groupId"), alfrescoGroupId), + element(name("artifactId"), "alfresco-enterprise-repository"), + element(name("version"), alfrescoPlatformVersion), + element(name("includes"), "alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/dbscripts/upgrade/*/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/ibatis/org.hibernate.dialect.PostgreSQLDialect/*") + ) + ) + ), + execEnv + ); + } + + getLog().info("Copying H2 Dialect SQL create files into target/test-classes"); + executeMojo( + plugin( + groupId("org.apache.maven.plugins"), + artifactId("maven-resources-plugin"), + version(MAVEN_RESOURCE_PLUGIN_VERSION) + ), + goal("copy-resources"), + configuration( + element(name("outputDirectory"), "${project.build.testOutputDirectory}"), + element(name("resources"), + element(name("resource"), + element(name("directory"), "${project.build.testOutputDirectory}/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect"), + element(name("includes"), + element(name("include"), "*") + ), + element(name("targetPath"), "alfresco/dbscripts/create/org.hibernate.dialect.H2Dialect") + ), + element(name("resource"), + element(name("directory"), "${project.build.testOutputDirectory}/alfresco/ibatis/org.hibernate.dialect.PostgreSQLDialect"), + element(name("includes"), + element(name("include"), "*") + ), + element(name("targetPath"), "alfresco/ibatis/org.hibernate.dialect.H2Dialect") + ) + ) + ), + execEnv + ); + + } + + + /** + * The directory where the custom war will be assembled + * + * @param baseWarName a war base name, such as 'platform' or 'share' + * @return a directory such as: .../aio/target/platform-war + */ + private String getWarOutputDir(String baseWarName) { + return project.getBuild().getDirectory() + "/" + getWarName(baseWarName); + } + + /** + * Get the war filename based on passed in war type + * + * @param baseWarName a war base name, such as 'platform' or 'share' + * @return + */ + private String getWarName(String baseWarName) { + return baseWarName + "-war"; + } +} diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java index 8147b902..ceb86754 100644 --- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java @@ -1,3 +1,20 @@ +/** + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of the Alfresco SDK. + * + * Licensed 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.alfresco.maven.plugin; import java.io.File; diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/IntegrationTestMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/IntegrationTestMojo.java new file mode 100644 index 00000000..4485c075 --- /dev/null +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/IntegrationTestMojo.java @@ -0,0 +1,274 @@ +/** + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of the Alfresco SDK project. + * + * Licensed 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.alfresco.maven.plugin; + +import org.alfresco.maven.plugin.config.ModuleDependency; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.zeroturnaround.zip.ZipUtil; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.*; + +/** + * Alfresco Plugin mojo that are used when you want to run Integration Tests. + * It will package up all the Integration Test classes and execute contained + * tests with the Maven Failsafe plugin. The test classes will be added + * to the platform war so they can be executed remotely via + * the ${@link org.alfresco.rad.test.AlfrescoTestRunner} + * + * The Alfresco RAD module is also added to the Platform WAR so + * the Alfresco Test runner classes are available. + * + * @author martin.bergljung@alfresco.com + * @since 3.0 + */ +@Mojo(name = "it", + defaultPhase = LifecyclePhase.INTEGRATION_TEST, + aggregator = true, // Only run against the top-level project in a Maven build + requiresDependencyResolution = ResolutionScope.TEST) +public class IntegrationTestMojo extends AbstractRunMojo { + + @Override + public void execute() throws MojoExecutionException { + execEnv = executionEnvironment( + project, + session, + pluginManager + ); + + if (enableSolr) { + unpackSolrConfig(); + fixSolrHomePath(); + replaceSolrConfigProperties(); + installSolr10InLocalRepo(); + } + + if (enableTestProperties && enablePlatform) { + copyAlfrescoGlobalProperties(); + renameAlfrescoGlobalProperties(); + } + + String testJarArtifactId = null; + if (enablePlatform) { + // Add alfresco-rad module to platform WAR + // So we got access to Alfresco Test Runner in the server + platformModules.add( + new ModuleDependency( + "org.alfresco.maven", + "alfresco-rad", + "${alfresco.sdk.version}", + ModuleDependency.TYPE_JAR)); + + // Create a JAR with all tests and add to module dependencies for platform WAR + // So we can run tests on the server + copyTestClassesFromSubModules2Parent(); + testJarArtifactId = packageAndInstallTestsJar(); + platformModules.add( + new ModuleDependency( + project.getGroupId(), + testJarArtifactId, + project.getVersion(), + ModuleDependency.TYPE_JAR)); + // Now build the platform WAR + buildPlatformWar(); + } + + if (enableShare) { + buildShareWar(); + } + + if (enableActivitiApp) { + buildActivitiAppWar(); + } + + if (startTomcat) { + boolean fork = true; + startTomcat(fork); + runIntegrationTests(testJarArtifactId); + stopTomcat(); + } + } + + /** + * In an AIO project copy all integration test (IT) test-classes from sub projects/modules + * to the parent target/test-classes + * + * @throws MojoExecutionException + */ + protected void copyTestClassesFromSubModules2Parent() throws MojoExecutionException { + // Get sub-module names, so we can see where to copy test classes from + List+ * + * } + *${project.groupId} + *share + *${project.version} + *war + *true + */share + *${project.build.directory}/contexts/context-share.xml + *
- * For example: - * {@code - *- */ - - /** - * Switch to enable/disable the Apache Solr 4 web application when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enableSolr", defaultValue = "true") - protected boolean enableSolr; - - /** - * Switch to enable/disable the H2 database when running embedded Tomcat. - * This also brings in the needed H2 database scripts. - */ - @Parameter(property = "maven.alfresco.enableH2", defaultValue = "false") - protected boolean enableH2; - - /** - * Switch to enable/disable the MySQL database when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enableMySQL", defaultValue = "false") - protected boolean enableMySQL; - - /** - * Switch to enable/disable the PostgreSQL database when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enablePostgreSQL", defaultValue = "false") - protected boolean enablePostgreSQL; - - /** - * Switch to enable/disable the Enterprise database (such as Oracle or MS SQL Server) when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enableEnterpriseDb", defaultValue = "false") - protected boolean enableEnterpriseDb; - - /** - * Switch to enable/disable the Platform/Repository (alfresco.war) when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enablePlatform", defaultValue = "true") - protected boolean enablePlatform; - - /** - * Switch to enable/disable the Share (share.war) when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enableShare", defaultValue = "true") - protected boolean enableShare; - - /** - * Enables the use of custom context path for the Share webapp. - * Some solution integrators uses a custom context path for Share in their projects. - * This property enables them to continue to do that in SDK 3 without having to completely override the - * Maven Tomcat plugin configuration, or not use it at all and go back the good old runner project again... - */ - @Parameter(property = "maven.alfresco.shareContextPath", defaultValue = "/share") - protected String shareContextPath; - - /** - * Share Log4j.properties configuration cannot be customized via extension - * put on the classpath, like on the platform side. - * So we need to override the log4j.properties in share/WEB-INF/classes - * to be able to log from custom code. - * This property can be used to turn off this overriding, to produce a WAR with - * the standard Share log4j.properties file. - */ - @Parameter(property = "maven.alfresco.useCustomShareLog4jConfig", defaultValue = "true") - protected boolean useCustomShareLog4jConfig; - - /** - * Switch to enable/disable the Alfresco REST API Explorer (api-explorer.war) when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enableApiExplorer", defaultValue = "false") - protected boolean enableApiExplorer; - - /** - * Switch to enable/disable Alfresco Activiti Workflow Engine (activiti-app.war) when running embedded Tomcat. - * This contains the Alfresco Activiti webapp, including the workflow engine. - * This webapp is also the user interface for people involved in the task and processes - * running in the Activiti engine. - * You also use this webapp to create and manage process definitions, and to display and define analytics - * reports on users' tasks and processes. - */ - @Parameter(property = "maven.alfresco.enableActivitiApp", defaultValue = "false") - protected boolean enableActivitiApp; - - /** - * Switch to enable/disable Alfresco Activiti Admin (activiti-admin.war) when running embedded Tomcat. - * This contains the Alfresco Activiti Administrator webapp. You use this to administer and monitor your - * Alfresco Activiti engines. - * - */ - @Parameter(property = "maven.alfresco.enableActivitiAdmin", defaultValue = "false") - protected boolean enableActivitiAdmin; - - /** - * Switch to enable/disable test properties when running embedded Tomcat. - */ - @Parameter(property = "maven.alfresco.enableTestProperties", defaultValue = "true") - protected boolean enableTestProperties; - - /** - * Control if Tomcat 7 Plugin should be kicked off and start Apache Tomcat - */ - @Parameter(property = "maven.alfresco.startTomcat", defaultValue = "true") - protected boolean startTomcat; - - /** - * Directory containing test files that should be used when running embedded Tomcat - */ - @Parameter(property = "maven.alfresco.testFolder", defaultValue = "src/test/properties/${env}") - protected String testFolder; - - /** - * Test files in testFolder that should be included when running embedded Tomcat - */ - @Parameter(property = "maven.alfresco.testInclude", defaultValue = "**") - protected String testInclude; - - /** - * JARs and AMPs that should be overlayed/applied to the Platform/Repository WAR (i.e. alfresco.war) - */ - @Parameter(property = "maven.alfresco.platform.modules", defaultValue = "") - protected List- * - * } - *org.alfresco.maven.plugin - *alfresco-maven-plugin - *3.0.0 - *- * - *community - *true - *true - *true - *false * - *- * - *- * - *${alfresco.groupId} - *alfresco-share-services - *${alfresco.share.version} - *amp - *
- * {@code - *- * - * @param groupId - * @param artifactId - * @param version - * @param contextPath - * @param contextFile - * @return - */ - private Element createWebAppElement(String groupId, - String artifactId, - String version, - String contextPath, - String contextFile) { - String errorStr = "cannot be null when creating webapp element for Tomcat 7 plugin"; - if (StringUtils.isBlank(groupId)) { - getLog().error("Maven Group Id " + errorStr); - } - if (StringUtils.isBlank(artifactId)) { - getLog().error("Maven Artifact Id " + errorStr); - } - if (StringUtils.isBlank(version)) { - getLog().error("Maven Version number " + errorStr); - } - - Element groupIdEl = element(name("groupId"), groupId); - Element artifactIdEl = element(name("artifactId"), artifactId); - Element versionEl = element(name("version"), version); - Element typeEl = element(name("type"), "war"); - // Make sure webapp is loaded with context and everything, - // if set to 'false' then you will get 404 when trying to access the webapp from browser - Element asWebappEl = element(name("asWebapp"), "true"); - Element contextPathEl = element(name("contextPath"), contextPath); - - Element e; - if (StringUtils.isNotBlank(contextFile)) { - e = element(name("webapp"), - groupIdEl, artifactIdEl, versionEl, typeEl, asWebappEl, contextPathEl, - element(name("contextFile"), contextFile)); - - } else { - e = element(name("webapp"), - groupIdEl, artifactIdEl, versionEl, typeEl, asWebappEl, contextPathEl); - } - - getLog().info(e.toDom().toUnescapedString()); - - return e; - } - - /** - * Returns true if current platform version (i.e. version of alfresco.war) is - * >= 5.1 - * - * @return true if platform version >= 5.1 - */ - private boolean isPlatformVersionGtOrEqTo51() { - if (getPlatformVersionNumber() >= 51) { - return true; - } - - return false; - } - - /** - * Returns true if current platform version (i.e. version of alfresco.war) is - * <= 4.2 - * - * @return true if platform version <= 4.2 - */ - private boolean isPlatformVersionLtOrEqTo42() { - if (getPlatformVersionNumber() <= 42) { - return true; - } - - return false; - } - - /** - * Grabs the first 2 numbers in the version string - * - * @return major and minor version as int, such as 41,50,51 - */ - private int getPlatformVersionNumber() { - return Integer.parseInt(alfrescoPlatformVersion.replaceAll("[^0-9]", "").substring(0, 2)); - } - - /** - * Get the Solr artifactId, it changes when we move to Solr 4 in Alfresco version 5 - * - * @return the Maven artifactId for Solr - */ - private String getSolrArtifactId() { - // artifactId for Solr defaults to version 4 = alfresco-solr4 - - if (isPlatformVersionLtOrEqTo42()) { - // Solr version 1 is used in Alfresco 4.0 -> 4.2, Solr version 4.0 was introduced in Alfresco version 5.0 - alfrescoSolrArtifactId = "alfresco-solr"; - } - - return alfrescoSolrArtifactId; - } - - /** - * Get the Alfresco Platform Webapp artifactId (i.e. for alfresco.war), - * it changes from 'alfresco' to 'alfresco-platform' in 5.1. - * - * @return the Maven artifactId for Alfresco Platform webapp - */ - private String getPlatformWarArtifactId() { - // Default alfrescoPlatformWarArtifactId is 'alfresco-platform' - - if (isPlatformVersionGtOrEqTo51() == false) { - // We are running version 4.2 or 5.0, so use older artifactId - alfrescoPlatformWarArtifactId = "alfresco"; - } else if (alfrescoEdition.equals(ALFRESCO_ENTERPRISE_EDITION)) { - alfrescoPlatformWarArtifactId = "alfresco-enterprise"; - } - - return alfrescoPlatformWarArtifactId; - } - - /** - * Get the Solr webapp element for use by Tomcat, it changes when we move to Solr 4 in Alfresco version 5 - * - * @return tomcat webapp element - */ - private Element getSolrWebappElement() { - Element webappElement = null; - - if (isPlatformVersionLtOrEqTo42()) { - // Solr version 1.0 - webappElement = createWebAppElement("${project.groupId}", getSolrArtifactId(), "${project.version}", - "/solr", "${project.build.testOutputDirectory}/tomcat/context-solr.xml"); - } else { - // Solr version 4.0 - webappElement = createWebAppElement(alfrescoGroupId, getSolrArtifactId(), alfrescoPlatformVersion, - "/solr4", "${project.build.testOutputDirectory}/tomcat/context-solr.xml"); - } - - return webappElement; - } - - /** - * TODO: From 5.1.e and onwards we have the alfresco-repository:h2scripts:jar artifact, so we potentially only need to do this for older than 5.1.e - * - * - * Extract PostgreSQL dialect and ibatis from alfresco-repository, rename to H2Dialect in the test-classes - * - * @return - */ - private void copyH2Dialect() throws MojoExecutionException { - getLog().info("Unpacking DB Dialects and ibatis files from alfresco-repository artifact"); - executeMojo( - plugin( - groupId("org.apache.maven.plugins"), - artifactId("maven-dependency-plugin"), - version(MAVEN_DEPENDENCY_PLUGIN_VERSION) - ), - goal("unpack"), - configuration( - element(name("outputDirectory"), "${project.build.testOutputDirectory}"), - element(name("artifactItems"), - element(name("artifactItem"), - element(name("groupId"), alfrescoGroupId), - element(name("artifactId"), "alfresco-repository"), - element(name("version"), alfrescoPlatformVersion), - element(name("includes"), "alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/dbscripts/upgrade/*/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/ibatis/org.hibernate.dialect.PostgreSQLDialect/*") - ) - ) - ), - execEnv - ); - - // If we're in enterprise we need to make sure we grab everything - if (this.alfrescoEdition.equals(ALFRESCO_ENTERPRISE_EDITION)) { - executeMojo( - plugin( - groupId("org.apache.maven.plugins"), - artifactId("maven-dependency-plugin"), - version(MAVEN_DEPENDENCY_PLUGIN_VERSION) - ), - goal("unpack"), - configuration( - element(name("outputDirectory"), "${project.build.testOutputDirectory}"), - element(name("artifactItems"), - element(name("artifactItem"), - element(name("groupId"), alfrescoGroupId), - element(name("artifactId"), "alfresco-enterprise-repository"), - element(name("version"), alfrescoPlatformVersion), - element(name("includes"), "alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/dbscripts/upgrade/*/org.hibernate.dialect.PostgreSQLDialect/*,alfresco/ibatis/org.hibernate.dialect.PostgreSQLDialect/*") - ) - ) - ), - execEnv - ); - } - - getLog().info("Copying H2 Dialect SQL create files into target/test-classes"); - executeMojo( - plugin( - groupId("org.apache.maven.plugins"), - artifactId("maven-resources-plugin"), - version(MAVEN_RESOURCE_PLUGIN_VERSION) - ), - goal("copy-resources"), - configuration( - element(name("outputDirectory"), "${project.build.testOutputDirectory}"), - element(name("resources"), - element(name("resource"), - element(name("directory"), "${project.build.testOutputDirectory}/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect"), - element(name("includes"), - element(name("include"), "*") - ), - element(name("targetPath"), "alfresco/dbscripts/create/org.hibernate.dialect.H2Dialect") - ), - element(name("resource"), - element(name("directory"), "${project.build.testOutputDirectory}/alfresco/ibatis/org.hibernate.dialect.PostgreSQLDialect"), - element(name("includes"), - element(name("include"), "*") - ), - element(name("targetPath"), "alfresco/ibatis/org.hibernate.dialect.H2Dialect") - ) - ) - ), - execEnv - ); - - } - - - /** - * The directory where the custom war will be assembled - * - * @param baseWarName a war base name, such as 'platform' or 'share' - * @return a directory such as: .../aio/target/platform-war - */ - private String getWarOutputDir(String baseWarName) { - return project.getBuild().getDirectory() + "/" + getWarName(baseWarName); - } - - /** - * Get the war filename based on passed in war type - * - * @param baseWarName a war base name, such as 'platform' or 'share' - * @return - */ - private String getWarName(String baseWarName) { - return baseWarName + "-war"; - } } diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/ValidateMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/ValidateMojo.java index c8aa268a..1943a956 100644 --- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/ValidateMojo.java +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/ValidateMojo.java @@ -1,7 +1,22 @@ +/** + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of the Alfresco SDK. + * + * Licensed 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.alfresco.maven.plugin; -import java.io.File; - import org.alfrescolabs.technical.validation.AlfrescoTechnicalValidation; import org.alfrescolabs.technical.validation.impl.AlfrescoTechnicalValidationImpl; import org.apache.maven.plugin.AbstractMojo; diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java index eec0b9d4..234d57fa 100644 --- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java @@ -1,3 +1,20 @@ +/** + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of the Alfresco SDK. + * + * Licensed 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.alfresco.maven.plugin; import java.text.DateFormat; diff --git a/pom.xml b/pom.xml index 1787d61c..c6e44afa 100644 --- a/pom.xml +++ b/pom.xml @@ -138,7 +138,7 @@- * - * } - *${project.groupId} - *share - *${project.version} - *war - *true - */share - *${project.build.directory}/contexts/context-share.xml - *