001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.maven;
018:
019: import org.apache.maven.artifact.factory.ArtifactFactory;
020: import org.apache.maven.artifact.Artifact;
021: import org.apache.maven.artifact.repository.ArtifactRepository;
022: import org.apache.maven.artifact.resolver.ArtifactResolver;
023: import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
024: import org.apache.maven.artifact.resolver.ArtifactResolutionException;
025: import org.apache.maven.plugin.MojoExecutionException;
026: import org.apache.pluto.util.install.ServerConfig;
027: import org.apache.pluto.util.install.InstallationConfig;
028: import org.apache.pluto.util.install.PortalInstallerFactory;
029: import org.apache.pluto.util.install.PortalInstaller;
030:
031: import java.io.File;
032: import java.util.ArrayList;
033: import java.util.List;
034: import java.util.Iterator;
035: import java.util.Collection;
036: import java.util.Map;
037: import java.util.HashMap;
038:
039: /**
040: * Abstract Mojo for installation tasks.
041: *
042: * @since 07/29/2005
043: */
044: public abstract class AbstractManagementMojo extends AbstractPlutoMojo {
045:
046: /**
047: * @parameter expression="${domain}"
048: */
049: protected String domain = "PlutoDomain";
050:
051: /**
052: * @parameter expression="${server}"
053: */
054: protected String server = "PlutoServer";
055:
056: /**
057: * @parameter expression="${host}"
058: */
059: protected String host = "localhost";
060:
061: /**
062: * @parameter expression="${port}"
063: */
064: protected int port;
065:
066: /**
067: * @component
068: */
069: protected ArtifactFactory artifactFactory;
070:
071: /**
072: * @component
073: */
074: protected ArtifactResolver artifactResolver;
075:
076: /**
077: * @parameter expression="${localRepository}
078: */
079: protected ArtifactRepository artifactRepository;
080:
081: /**
082: * @parameter expression="${project.remoteArtifactRepositories}"
083: */
084: protected List remoteRepositories;
085:
086: /**
087: * @parameter expression="${ctx}" default-value="pluto"
088: *
089: */
090: protected String portalContext;
091:
092: /**
093: * @parameter expression="${pom.currentVersion} default="1.0-SNAPSHOT"
094: */
095: protected String version;
096:
097: /**
098: * at parameter expression="${portletApps}"
099: */
100: protected Map portletApps = new HashMap();
101:
102: protected AbstractManagementMojo() {
103: // Do nothing.
104: }
105:
106: protected List getSharedDependencies()
107: throws ArtifactNotFoundException,
108: ArtifactResolutionException {
109: return getDependencies(InstallationDependency
110: .getSharedDependencies());
111: }
112:
113: protected List getEndorsedDependencies()
114: throws ArtifactNotFoundException,
115: ArtifactResolutionException {
116: return getDependencies(InstallationDependency
117: .getEndorsedDependencies());
118: }
119:
120: private List getDependencies(Collection artifacts)
121: throws ArtifactNotFoundException,
122: ArtifactResolutionException {
123: List list = new ArrayList();
124: Iterator it = artifacts.iterator();
125: while (it.hasNext()) {
126: InstallationDependency dep = (InstallationDependency) it
127: .next();
128: Artifact artifact = artifactFactory
129: .createArtifactWithClassifier(dep.getGroupId(), dep
130: .getArtifactId(), dep.getVersion(), dep
131: .getType(), null);
132:
133: artifactResolver.resolve(artifact, remoteRepositories,
134: artifactRepository);
135: if (artifact.getFile() == null) {
136: getLog().warn(
137: "Unable to find file for artifact: "
138: + artifact.getArtifactId());
139: }
140:
141: list.add(artifact.getFile());
142: }
143: return list;
144: }
145:
146: protected ServerConfig getServerConfig() {
147: ServerConfig config = new ServerConfig();
148: config.setDomain(domain);
149: config.setHost(host);
150: config.setPort(port);
151: config.setServer(server);
152: return config;
153: }
154:
155: protected PortalInstaller getHandler() {
156: return PortalInstallerFactory
157: .getAppServerHandler(installationDirectory);
158: }
159:
160: protected InstallationConfig createInstallationConfig()
161: throws ArtifactNotFoundException,
162: ArtifactResolutionException {
163: InstallationConfig config = new InstallationConfig();
164: config.setInstallationDirectory(installationDirectory);
165: config.setPortalContextPath(portalContext);
166: config.setPortalApplication(getPortalApplication());
167: config.setPortletApplications(getPortletApplications());
168: config.setEndorsedDependencies(getEndorsedDependencies());
169: config.setSharedDependencies(getSharedDependencies());
170: config.setServerConfig(getServerConfig());
171: return config;
172: }
173:
174: private File getPortalApplication()
175: throws ArtifactNotFoundException,
176: ArtifactResolutionException {
177: InstallationDependency dep = InstallationDependency.PORTAL;
178: Artifact artifact = artifactFactory.createBuildArtifact(dep
179: .getGroupId(), dep.getArtifactId(), dep.getVersion(),
180: dep.getType());
181: artifactResolver.resolve(artifact, remoteRepositories,
182: artifactRepository);
183: return artifact.getFile();
184: }
185:
186: private Map getPortletApplications()
187: throws ArtifactNotFoundException,
188: ArtifactResolutionException {
189: Map files = new HashMap();
190: InstallationDependency dep = InstallationDependency.TESTSUITE;
191: Artifact artifact = artifactFactory.createBuildArtifact(dep
192: .getGroupId(), dep.getArtifactId(), dep.getVersion(),
193: dep.getType());
194: artifactResolver.resolve(artifact, remoteRepositories,
195: artifactRepository);
196:
197: files.put("testsuite", artifact.getFile());
198: /*
199: Iterator apps = portletApps.iterator();
200: while(apps.hasNext()) {
201: //files.add(artifactFactory.createBuildArtifact(
202: // InstallMojo.GROUP_ID, apps.next().toString(), version, "war"
203: //).getFile());
204: }
205: */
206: return files;
207: }
208:
209: protected void doValidate() throws Exception {
210: if (installationDirectory == null
211: || !installationDirectory.exists()) {
212: throw new MojoExecutionException(
213: "A valid installation directory must be provided in order to install pluto.");
214:
215: }
216: }
217: }
|