Make port configurable and dynamic

This commit is contained in:
Ole Hejlskov
2017-03-09 16:44:22 +01:00
parent aede276f9b
commit 85c7e11bb6
3 changed files with 215 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<alfresco-config>
<config evaluator="string-compare" condition="WebFramework">
<web-framework>
<autowire>
<!-- Changing this to 'development' currently breaks the Admin Console.
Instead we make a POST to clear Share dependency caches, see 'clear-caches-refresh-ws' profile. -->
<mode>production</mode> <!-- not really need in the long run, used for YUI - deprecate -->
</autowire>
<!--
We don't need to do this when we have the new refresh mojos in the Alfresco plug-in.
If resource caching has been disabled then all the dependency caches will be cleared
before processing the Aikau jsonModel request...
(i.e. this.dojoDependencyHandler.clearCaches() )
For more information see the Aikau source code: https://github.com/Alfresco/Aikau
-->
<disable-resource-caching>false</disable-resource-caching>
</web-framework>
</config>
<!-- Global config section -->
<config replace="true">
<flags>
<!--
Developer debugging setting to turn on DEBUG mode for client scripts in the browser
-->
<client-debug>true</client-debug>
<!--
LOGGING can always be toggled at runtime when in DEBUG mode (Ctrl, Ctrl, Shift, Shift).
This flag automatically activates logging on page load.
-->
<client-debug-autologging>false</client-debug-autologging>
</flags>
</config>
<!--
Disable CSRF completely for now
It seems Share has issues on 4.2.x with the embedded tomcat and CSRFPolicy
-->
<config evaluator="string-compare" condition="CSRFPolicy" replace="true">
<filter/>
</config>
<!--
Change so it is picked up from property where the Alfresco Repo Webapp is running
(e.g. http://localhost:8080/alfresco)
-->
<config evaluator="string-compare" condition="Remote">
<remote>
<endpoint>
<id>alfresco-noauth</id>
<name>Alfresco - unauthenticated access</name>
<description>Access to Alfresco Repository WebScripts that do not require authentication</description>
<connector-id>alfresco</connector-id>
<endpoint-url>${alfresco.repo.url}/s</endpoint-url>
<identity>none</identity>
</endpoint>
<endpoint>
<id>alfresco</id>
<name>Alfresco - user access</name>
<description>Access to Alfresco Repository WebScripts that require user authentication</description>
<connector-id>alfresco</connector-id>
<endpoint-url>${alfresco.repo.url}/s</endpoint-url>
<identity>user</identity>
</endpoint>
<endpoint>
<id>alfresco-feed</id>
<name>Alfresco Feed</name>
<description>Alfresco Feed - supports basic HTTP authentication via the EndPointProxyServlet</description>
<connector-id>http</connector-id>
<endpoint-url>${alfresco.repo.url}/s</endpoint-url>
<basic-auth>true</basic-auth>
<identity>user</identity>
</endpoint>
<endpoint>
<id>activiti-admin</id>
<name>Activiti Admin UI - user access</name>
<description>Access to Activiti Admin UI, that requires user authentication</description>
<connector-id>activiti-admin-connector</connector-id>
<endpoint-url>${alfresco.repo.url}/activiti-admin</endpoint-url>
<identity>user</identity>
</endpoint>
<endpoint>
<id>alfresco-api</id>
<parent-id>alfresco</parent-id>
<name>Alfresco Public API - user access</name>
<description>Access to Alfresco Repository Public API that require user authentication.
This makes use of the authentication that is provided by parent 'alfresco' endpoint.</description>
<connector-id>alfresco</connector-id>
<endpoint-url>${alfresco.repo.url}/alfresco/api</endpoint-url>
<identity>user</identity>
</endpoint>
</remote>
</config>
</alfresco-config>

View File

@@ -263,6 +263,19 @@ public abstract class AbstractRunMojo extends AbstractMojo {
@Parameter(property = "maven.alfresco.tomcat.custom.webapps", defaultValue = "") @Parameter(property = "maven.alfresco.tomcat.custom.webapps", defaultValue = "")
protected List<TomcatWebapp> tomcatCustomWebapps; protected List<TomcatWebapp> tomcatCustomWebapps;
/**
* Port to run Tomcat on
*/
@Parameter(property = "maven.alfresco.tomcat.port", defaultValue = "8080")
protected String tomcatPort;
/**
* Legacy to be compatible with maven.tomcat.port
*/
@Parameter(property = "maven.tomcat.port", defaultValue = "8080")
protected String mavenTomcatPort;
/** /**
* Maven GAV properties for standard Alfresco web applications. * Maven GAV properties for standard Alfresco web applications.
*/ */
@@ -326,6 +339,20 @@ public abstract class AbstractRunMojo extends AbstractMojo {
*/ */
protected ExecutionEnvironment execEnv; protected ExecutionEnvironment execEnv;
/**
* Get the Tomcat port. By default the port is changed by using the maven.alfresco.tomcat.port property
* but for legacy and external configuration purposes maven.tomcat.port will override if defined
*/
protected String getPort() {
String port = tomcatPort;
if (mavenTomcatPort.toString() != tomcatPort.toString()) {
port = mavenTomcatPort;
getLog().info( "Tomcat Port overridden by property maven.tomcat.port");
}
return port;
}
/** /**
* Download and unpack the Solr 4 configuration as we don't have it in the project. * Download and unpack the Solr 4 configuration as we don't have it in the project.
* It will reside under /alf_data_dev/solr * It will reside under /alf_data_dev/solr
@@ -411,7 +438,12 @@ public abstract class AbstractRunMojo extends AbstractMojo {
element(name("replacement"), element(name("replacement"),
element(name("token"), "@@ALFRESCO_SOLR4_DATA_DIR@@"), element(name("token"), "@@ALFRESCO_SOLR4_DATA_DIR@@"),
element(name("value"), "${solrDataDir}/index") element(name("value"), "${solrDataDir}/index")
),
element(name("replacement"),
element(name("token"), "alfresco.port=8080"),
element(name("value"), "alfresco.port=" + getPort())
) )
) )
), ),
execEnv execEnv
@@ -523,6 +555,36 @@ public abstract class AbstractRunMojo extends AbstractMojo {
), ),
execEnv execEnv
); );
executeMojo(
plugin(
groupId("com.google.code.maven-replacer-plugin"),
artifactId("replacer"),
version(MAVEN_REPLACER_PLUGIN_VERSION)
),
goal("replace"),
configuration(
element(name("regex"), "false"),
element(name("includes"),
element(name("include"), "${project.build.testOutputDirectory}/*.properties")
),
element(name("replacements"),
element(name("replacement"),
element(name("token"), "alfresco.port=8080"),
element(name("value"), "alfresco.port=" + getPort())
),
element(name("replacement"),
element(name("token"), "share.port=8080"),
element(name("value"), "share.port=" + getPort())
),
element(name("replacement"),
element(name("token"), "solr.port=8080"),
element(name("value"), "solr.port=" + getPort())
)
)
),
execEnv
);
} }
/** /**
@@ -647,6 +709,46 @@ public abstract class AbstractRunMojo extends AbstractMojo {
); );
} }
/**
* Copy Share Config Custom in order to have global overrides for development and dynamic port
*
* @throws MojoExecutionException
*/
protected void copyShareConfigCustom() throws MojoExecutionException {
final String warOutputDir = getWarOutputDir(SHARE_WAR_PREFIX_NAME);
final String distDir = warOutputDir + "/WEB-INF/classes/alfresco/web-extension/";
String repoUrl = project.getProperties().getProperty("alfresco.repo.url");
if (repoUrl == null) {
project.getProperties().setProperty("alfresco.repo.url", "http://localhost:" + getPort() + "/alfresco");
}
getLog().info("Copying Share config custom to: " + distDir);
executeMojo(
plugin(
groupId("org.apache.maven.plugins"),
artifactId("maven-resources-plugin"),
version(MAVEN_RESOURCE_PLUGIN_VERSION)
),
goal("copy-resources"),
configuration(
element(name("outputDirectory"), distDir),
element(name("resources"),
element(name("resource"),
element(name("directory"), "src/test/resources/share"),
element(name("includes"),
element(name("include"), "*.xml")
),
element(name("filtering"), "true")
)
)
),
execEnv
);
}
/** /**
* Copy a custom Share Log4J config into the share-war/WEB-INF/classes dir. * Copy a custom Share Log4J config into the share-war/WEB-INF/classes dir.
* There is no custom classpath resolve mechanism for Share log4j, * There is no custom classpath resolve mechanism for Share log4j,
@@ -718,6 +820,7 @@ public abstract class AbstractRunMojo extends AbstractMojo {
alfrescoGroupId, alfrescoShareWarArtifactId, alfrescoShareVersion); alfrescoGroupId, alfrescoShareWarArtifactId, alfrescoShareVersion);
copyShareLog4jConfig(); copyShareLog4jConfig();
copyShareConfigCustom();
String shareWarArtifactId = packageAndInstallCustomWar(SHARE_WAR_PREFIX_NAME); String shareWarArtifactId = packageAndInstallCustomWar(SHARE_WAR_PREFIX_NAME);
@@ -1070,6 +1173,11 @@ public abstract class AbstractRunMojo extends AbstractMojo {
configuration( configuration(
element(name("fork"), fork ? "true" : "false"), element(name("fork"), fork ? "true" : "false"),
/*
* Port
*/
element(name( "port" ), getPort()),
/* /*
* SDK Projects doesn't have packaging set to 'war', they are JARs or POMs, * SDK Projects doesn't have packaging set to 'war', they are JARs or POMs,
* this setting ignores that fact. * this setting ignores that fact.

View File

@@ -81,6 +81,8 @@ public class IntegrationTestMojo extends AbstractRunMojo {
// execEnv.getMavenSession().getGoals().add("alfresco:it"); // execEnv.getMavenSession().getGoals().add("alfresco:it");
getLog().info("Checking if Tomcat is already running on port " + "");
if (enableSolr) { if (enableSolr) {
unpackSolrConfig(); unpackSolrConfig();
fixSolrHomePath(); fixSolrHomePath();