1 19 20 21 package org.netbeans.modules.j2ee.deployment.devmodules.api; 22 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import javax.enterprise.deploy.shared.ModuleType ; 28 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 29 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 30 import org.netbeans.modules.j2ee.deployment.plugins.api.AntDeploymentProvider; 31 import org.openide.filesystems.FileLock; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 35 42 public final class AntDeploymentHelper { 43 44 79 public static void writeDeploymentScript(File file, Object moduleType, String serverInstanceID) 80 throws IOException { 81 AntDeploymentProvider provider = null; 82 if (serverInstanceID != null) { 83 ServerInstance si = ServerRegistry.getInstance().getServerInstance(serverInstanceID); 84 if (si != null) { 85 provider = si.getAntDeploymentProvider(); 86 } 87 } 88 file.createNewFile(); 89 FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); 90 FileLock lock = fo.lock(); 91 try { 92 OutputStream os = fo.getOutputStream(lock); 93 try { 94 if (provider == null) { 95 InputStream is = ServerInstance.class.getResourceAsStream("resources/default-ant-deploy.xml"); try { 97 FileUtil.copy(is, os); 98 } finally { 99 is.close(); 100 } 101 } else { 102 provider.writeDeploymentScript(os, moduleType); 103 } 104 } finally { 105 os.close(); 106 } 107 } finally { 108 lock.releaseLock(); 109 } 110 } 111 112 123 public static File getDeploymentPropertiesFile(String serverInstanceID) { 124 if (serverInstanceID == null) { 125 throw new NullPointerException ("The serverInstanceID must not be null"); } 127 ServerInstance si = ServerRegistry.getInstance().getServerInstance(serverInstanceID); 128 if (si == null) { 129 return null; 130 } 131 AntDeploymentProvider sup = si.getAntDeploymentProvider(); 132 return sup == null ? null : sup.getDeploymentPropertiesFile(); 133 } 134 } 135 | Popular Tags |