001: /**
002: * EasyBeans
003: * Copyright (C) 2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ClientFile.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.ant.archive.file;
025:
026: import java.io.File;
027:
028: import org.apache.tools.ant.BuildException;
029: import org.apache.tools.ant.Project;
030: import org.apache.tools.ant.taskdefs.Jar;
031: import org.apache.tools.ant.taskdefs.Manifest;
032: import org.apache.tools.ant.taskdefs.ManifestException;
033: import org.apache.tools.ant.taskdefs.Manifest.Attribute;
034: import org.apache.tools.ant.types.FileSet;
035: import org.apache.tools.ant.types.ZipFileSet;
036: import org.ow2.easybeans.ant.archive.api.IClient;
037: import org.ow2.easybeans.ant.archive.info.ArchiveInfo;
038: import org.ow2.easybeans.ant.archive.info.ClientInfo;
039:
040: /**
041: * Creates a Client file.
042: * @author Florent Benoit
043: */
044: public class ClientFile extends Jar implements IClient {
045:
046: /**
047: * Path to the Standard deployment descriptor.
048: */
049: private static final String DEPLOYMENT_DESCRIPTOR = "META-INF/application-client.xml";
050:
051: /**
052: * Reference to the client archive info object.
053: */
054: private ClientInfo clientInfo = null;
055:
056: /**
057: * Reference to the archive info object.
058: */
059: private ArchiveInfo archiveInfo = null;
060:
061: /**
062: * Creates an archive for the given project.
063: * @param p the given project
064: */
065: public ClientFile(final Project p) {
066: super ();
067: setProject(p);
068: }
069:
070: /**
071: * Sets the information about an archive.
072: * @param archiveInfo the object that holds data information.
073: */
074: public void setArchiveInfo(final ArchiveInfo archiveInfo) {
075: this .archiveInfo = archiveInfo;
076: }
077:
078: /**
079: * Sets the information about a Client archive.
080: * @param clientInfo the object that holds data information.
081: */
082: public void setClientInfo(final ClientInfo clientInfo) {
083: setArchiveInfo(clientInfo);
084: this .clientInfo = clientInfo;
085: }
086:
087: /**
088: * Execute the task.
089: */
090: @Override
091: public void execute() {
092:
093: // Deployment descriptor
094: if (archiveInfo.getDd() != null) {
095: setDD(archiveInfo.getDd());
096: }
097:
098: // Main class attribute ?
099: String mainClass = clientInfo.getMainClass();
100: if (mainClass != null) {
101: Manifest mf = new Manifest();
102: Attribute attribute = new Attribute();
103: attribute.setName("Main-Class");
104: attribute.setValue(mainClass);
105:
106: // Add attribute
107: try {
108: mf.addConfiguredAttribute(attribute);
109: } catch (ManifestException e) {
110: throw new BuildException(
111: "Cannot add the Main-Class attribute in the manifest",
112: e);
113: }
114:
115: // Add Manifest
116: try {
117: addConfiguredManifest(mf);
118: } catch (ManifestException e) {
119: throw new BuildException("Cannot add the manifest", e);
120: }
121: }
122:
123: // dest file
124: setDestFile(archiveInfo.getDest());
125:
126: // fileset
127: for (FileSet fileSet : archiveInfo.getFileSetList()) {
128: addFileset(fileSet);
129: }
130:
131: super .execute();
132: }
133:
134: /**
135: * Add the given DD file into the archive.
136: * @param dd the path to the DDesc file.
137: */
138: public void setDD(final File dd) {
139: ZipFileSet zipFileSet = new ZipFileSet();
140: zipFileSet.setFile(dd);
141: zipFileSet.setFullpath(DEPLOYMENT_DESCRIPTOR);
142: addFileset(zipFileSet);
143: }
144:
145: }
|