Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildpatterns/maven/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.classpath
36 changes: 0 additions & 36 deletions buildpatterns/maven/headlessdesigner-maven-plugin/.classpath

This file was deleted.

35 changes: 29 additions & 6 deletions buildpatterns/maven/headlessdesigner-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.ibm.sbt</groupId>
<artifactId>com.ibm.commons</artifactId>
<version>9.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.sbt</groupId>
<artifactId>com.ibm.commons.xml</artifactId>
<version>9.0.0</version>
</dependency>
</dependencies>
<packaging>maven-plugin</packaging>

Expand Down Expand Up @@ -181,6 +191,15 @@
</roles>
</developer>
</developers>

<distributionManagement>
<repository>
<id>artifactory.openntf.org</id>
<name>artifactory.openntf.org</name>
<url>https://artifactory.openntf.org/openntf</url>
</repository>
</distributionManagement>

<profiles>
<profile>
<id>release</id>
Expand Down Expand Up @@ -230,12 +249,16 @@
</plugins>
</build>
</profile>
<profile>
<id>nexus-deploy</id>

<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-staging-openntf</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-staging-openntf</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<description>The headless designer plugins enables you build XPages Application from the On-Disk-Project, invoking the IBM Domino Designer.</description>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,6 +25,15 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.openntf.maven.design.ACL;
import org.openntf.maven.design.ACLEntry;
import org.openntf.maven.util.HDUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.ibm.commons.util.StringUtil;
import com.ibm.commons.util.io.StreamUtil;
import com.ibm.commons.xml.DOMUtil;

@Mojo(name = "ddehd")
@Execute(goal = "ddehd")
Expand Down Expand Up @@ -77,6 +87,12 @@ public class HeadlessDesignerBuilder extends AbstractDesignerPlugin {

@Parameter(defaultValue="${project}", readonly=true, required=true)
private MavenProject project;

/**
* The ACL for the generated database. This overrides any ACL present in the ODP.
*/
@Parameter
private ACL acl;

/**
* Path to File with the build instructions for the headless designer. If
Expand Down Expand Up @@ -115,9 +131,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// Create/overwrite the $TemplateBuild field if needed
if(StringUtils.isNotEmpty(templateBuildName)) {
getLog().debug("Want to build $TemplateBuild for name=" + templateBuildName + ", version=" + templateBuildVersion);
getLog().info("Configuring template build name " + templateBuildName + ", version= " + templateBuildVersion);
configureTemplateBuild(tempOdp);
}
if(acl != null) {
getLog().info("Configuring ACL");
configureAcl(tempOdp);
}

installFeature();
enableFeatures();
Expand Down Expand Up @@ -159,11 +179,17 @@ private void executeDesigner(String fileName) throws MojoExecutionException {
sbDesignerArgs.append("\"");

getLog().debug("Designer call = " + sbDesignerArgs.toString());
ProcessBuilder pb = new ProcessBuilder(m_DesignerExec, "-RPARAMS", "-console", "-vmargs", sbDesignerArgs.toString());
// This uses Runtime instead of ProcessBuilder because the latter doesn't properly launch
// Designer on all systems, and a String instead of an array because Designer is quite
// finicky about that as well
String cmd = m_DesignerExec + " -RPARAMS -console -vmargs " + sbDesignerArgs;

try {
Process process = pb.start();
Process process = Runtime.getRuntime().exec(cmd);
int result = process.waitFor();
if(result != 0) {
throw new MojoExecutionException("Designer task ended with non-zero exit code: " + result);
}
getLog().debug("DDE HeadlessDesigner ended with: " + result);
boolean finished = false;
int nCounter = 0;
Expand All @@ -175,6 +201,8 @@ private void executeDesigner(String fileName) throws MojoExecutionException {
throw new MojoExecutionException("DDE HeadlessDesignerPlugin not finished in 120 sec timeout");

}
} catch (MojoExecutionException ex) {
throw ex;
} catch (Exception ex) {
throw new MojoExecutionException("DDE HeadlessDesignerPlugin reports an error: ", ex);
}
Expand Down Expand Up @@ -224,6 +252,115 @@ private void configureTemplateBuild(File odpPath) throws MojoExecutionException
IOUtils.closeQuietly(templateXmlStream);
}
}

private void configureAcl(File odpPath) throws MojoExecutionException {
File databaseProperties = new File(odpPath, "AppProperties" + File.separator + "database.properties");
if(!databaseProperties.exists()) {
throw new MojoExecutionException("Could not locate database properties file: " + databaseProperties.getAbsolutePath());
}

try {
FileInputStream fis = new FileInputStream(databaseProperties);
String xmlString;
try {
xmlString = StreamUtil.readString(fis);
} finally {
StreamUtil.close(fis);
}
getLog().debug("Read XML of length " + xmlString.length() + " from database.properties file " + databaseProperties.getAbsolutePath());

Document xml = DOMUtil.createDocument(xmlString);
Element aclNode = (Element)DOMUtil.evaluateXPath(xml, "/database/acl").getSingleNode();
if(aclNode == null) {
// Then add a new one under the document element
aclNode = xml.createElement("acl");
xml.getDocumentElement().appendChild(aclNode);
}
// Clear out existing children in favor of our new ACL
DOMUtil.removeChildren(aclNode);

aclNode.setAttribute("adminserver", StringUtil.toString(acl.getAdminServer()));
aclNode.setAttribute("consistentacl", String.valueOf(acl.isConsistentAcl()));
aclNode.setAttribute("maxinternetaccess", StringUtil.toString(acl.getMaxInternetAccess()));
List<String> roles = acl.getRoles();
if(roles != null) {
for(String role : roles) {
String name = HDUtils.getBracketedName(role);
if(StringUtil.isNotEmpty(name)) {
Element roleElement = xml.createElement("role");
roleElement.setTextContent(name);
aclNode.appendChild(roleElement);
}
}
}
List<ACLEntry> entries = acl.getEntries();
if(entries != null) {
for(ACLEntry entry : entries) {
String name = entry.getName();
if(StringUtil.isNotEmpty(name)) {
Element entryElement = xml.createElement("aclentry");
entryElement.setAttribute("name", name);
if("-Default-".equals(name)) {
entryElement.setAttribute("default", "true");
}
if(entry.getType() != null) {
entryElement.setAttribute("type", entry.getType().name());
}
entryElement.setAttribute("level", entry.getLevel().name());
if(!entry.isCreateDocs()) {
entryElement.setAttribute("createdocs", "false");
}
if(entry.isDeleteDocs()) {
entryElement.setAttribute("deletedocs", "true");
}
if(!entry.isCreateLsJavaAgents()) {
entryElement.setAttribute("createlsjavaagents", "false");
}
if(!entry.isCreatePersonalAgents()) {
entryElement.setAttribute("createpersonalagents", "false");
}
if(!entry.isCreatePersonalViews()) {
entryElement.setAttribute("createpersonalviews", "false");
}
if(!entry.isCreateSharedViews()) {
entryElement.setAttribute("createsharedviews", "false");
}
if(!entry.isReadPublicDocs()) {
entryElement.setAttribute("readpublicdocs", "false");
}
if(!entry.isWritePublicDocs()) {
entryElement.setAttribute("writepublicdocs", "false");
}
List<String> entryRoles = entry.getRoles();
if(entryRoles != null) {
for(String role : entryRoles) {
String roleName = HDUtils.getBracketedName(role);
if(StringUtil.isNotEmpty(roleName)) {
Element roleElement = xml.createElement("role");
roleElement.setTextContent(roleName);
entryElement.appendChild(roleElement);
}
}
}

aclNode.appendChild(entryElement);
}
}
}

String resultXml = DOMUtil.getXMLString(xml, false);
getLog().debug("Writing result XML of length " + resultXml.length());
FileOutputStream fos = new FileOutputStream(databaseProperties);
try {
IOUtils.write(resultXml, fos);
} finally {
IOUtils.closeQuietly(fos);
}

} catch(Throwable ex) {
throw new MojoExecutionException("Failed to configure ACL", ex);
}
}

private void installFeature() throws MojoExecutionException {
if (m_Features != null && m_Features.size() > 0) {
Expand All @@ -236,9 +373,8 @@ private void installFeature() throws MojoExecutionException {
StringBuilder sb = new StringBuilder();
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command install -from ");
sb.append(site.getUrl());
sb.append(" -to file:/");
sb.append(m_NotesData);
sb.append("/workspace/applications");
sb.append(" -to ");
sb.append(HDUtils.fileUri(m_NotesData, "workspace", "applications"));
sb.append(" -featureId ");
sb.append(site.getFeatureId());
sb.append(" -version ");
Expand Down Expand Up @@ -277,9 +413,8 @@ private void enableFeatures() throws MojoExecutionException {
pw.println("config,true,true");
for (Feature site : m_Features) {
StringBuilder sb = new StringBuilder();
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command enable -to file:/");
sb.append(m_NotesData);
sb.append("/workspace/applications");
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command enable -to ");
sb.append(HDUtils.fileUri(m_NotesData, "workspace", "applications"));
sb.append(" -featureId ");
sb.append(site.getFeatureId());
sb.append(" -version ");
Expand Down Expand Up @@ -330,9 +465,8 @@ private void disableFeatures() throws MojoExecutionException {
pw.println("config,true,true");
for (Feature site : m_Features) {
StringBuilder sb = new StringBuilder();
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command disable -to file:/");
sb.append(m_NotesData);
sb.append("/workspace/applications");
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command disable -to ");
sb.append(HDUtils.fileUri(m_NotesData, "workspace", "applications"));
sb.append(" -featureId ");
sb.append(site.getFeatureId());
sb.append(" -version ");
Expand Down Expand Up @@ -364,9 +498,8 @@ private void uninstallFeatures() throws MojoExecutionException {
pw.println("config,true,true");
for (Feature site : m_Features) {
StringBuilder sb = new StringBuilder();
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command uninstall -to file:/");
sb.append(m_NotesData);
sb.append("/workspace/applications");
sb.append("com.ibm.designer.domino.tools.userlessbuild.jobs.UpdateManagerJob,-command uninstall -to ");
sb.append(HDUtils.fileUri(m_NotesData, "workspace", "applications"));
sb.append(" -featureId ");
sb.append(site.getFeatureId());
sb.append(" -version ");
Expand Down
Loading