1 19 20 package org.netbeans.modules.j2ee.archive.project; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.netbeans.api.project.Project; 25 import org.netbeans.api.project.ProjectManager; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 27 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 28 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 29 import org.netbeans.spi.project.support.ant.AntProjectHelper; 30 import org.netbeans.spi.project.support.ant.EditableProperties; 31 import org.openide.ErrorManager; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.Mutex; 34 import org.openide.util.MutexException; 35 import org.w3c.dom.Element ; 36 37 public class ArchiveProjectProperties { 38 39 private Project project; 40 private AntProjectHelper helper; 41 private EditableProperties projectProps, privateProps; 42 43 final public static String J2EE_SERVER_INSTANCE = "j2ee.server.instance"; 45 final public static String J2EE_SERVER_TYPE = "j2ee.server.type"; 47 final public static String SOURCE_ARCHIVE = "source.archive"; 49 final public static String DIST_DIR = "dist.dir"; 51 final public static String WAR_NAME = "war.name"; 54 final public static String PROXY_PROJECT_DIR = "proxy.project.dir"; 56 final public static String TMP_PROJ_DIR_VALUE = "tmpproj"; 58 final public static String DIST_DIR_VALUE = "dist"; 60 final public static String DIST_ARCHIVE ="dist.archive"; 62 final public static String CONTENT_DIR = "content.dir"; 64 final public static String CONF_DIR = "conf.dir"; 66 public static final String SETUP_DIR_VALUE = "setup"; 68 public static final String ARCHIVE_TYPE = "javaee.archive.type"; 70 public static final String PROJECT_TYPE_VALUE_UNKNOWN = "unknown"; 72 public static final String PROJECT_TYPE_VALUE_WAR = "war"; 74 public static final String PROJECT_TYPE_VALUE_EAR = "ear"; 76 public static final String PROJECT_TYPE_VALUE_CAR = "car"; 78 public static final String PROJECT_TYPE_VALUE_RAR = "rar"; 80 public static final String PROJECT_TYPE_VALUE_JAR = "jar"; 82 public static final String WAR_ARCHIVES = "javaee.archive.war.archives"; 83 public static final String JAR_ARCHIVES = "javaee.archive.jar.archives"; 84 public static final String RAR_ARCHIVES = "javaee.archive.rar.archives"; 85 86 public static final String DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; public static final String ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; public static final String CAR_ARCHIVES = "javaee.archive.car.archives"; 89 90 public ArchiveProjectProperties(Project project, AntProjectHelper helper 91 ) { 92 this.project = project; 93 this.helper = helper; 94 95 privateProps = helper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 96 projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 97 98 } 101 102 public void save() { 103 try { 104 ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 105 public Object run() throws IOException { 106 try { 108 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps); 112 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps); 113 Element data = helper.getPrimaryConfigurationData(true); 114 helper.putPrimaryConfigurationData(data, true); 115 ProjectManager.getDefault().saveProject(project); 116 } catch (IOException e) { 117 ErrorManager.getDefault().notify(e); 118 } 119 return null; 120 } 121 }); 122 } catch (MutexException e) { 123 ErrorManager.getDefault().notify(e.getException()); 124 } 125 } 126 127 public Object get(String propertyName) { 128 Object retVal; 131 if (J2EE_SERVER_INSTANCE.equals(propertyName)) 132 retVal = privateProps.getProperty(J2EE_SERVER_INSTANCE); 133 else 134 retVal = projectProps.getProperty(propertyName); 135 return retVal; 136 } 137 138 public void put( String propertyName, String value ) { 139 if (J2EE_SERVER_INSTANCE.equals(propertyName)) { 141 projectProps.put(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID((String ) value)); 142 privateProps.put(J2EE_SERVER_INSTANCE,value); 144 145 } else { 146 projectProps.put(propertyName, value); 147 } 148 } 149 150 public static void setServerInstance(final Project project, final AntProjectHelper helper, final String serverInstanceID) { 151 ProjectManager.mutex().writeAccess(new Runnable () { 152 public void run() { 153 try { 154 EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 155 EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 156 setNewServerInstanceValue(serverInstanceID, projectProps, privateProps); 157 File projectFolder = FileUtil.toFile(project.getProjectDirectory()); 159 try { 160 AntDeploymentHelper.writeDeploymentScript(new File (projectFolder, ANT_DEPLOY_BUILD_SCRIPT), 161 mapType(projectProps.getProperty(ARCHIVE_TYPE)), serverInstanceID); } catch (IOException ioe) { 163 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 164 } 165 File antDeployPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID); 166 if (antDeployPropsFile == null) { 167 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 168 } else { 169 privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, antDeployPropsFile.getAbsolutePath()); 170 } 171 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps); 172 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps); 173 ProjectManager.getDefault().saveProject(project); 174 } catch (IOException e) { 175 ErrorManager.getDefault().notify(e); 176 } 177 } 178 }); 179 } 180 181 private static void setNewServerInstanceValue(String newServInstID, EditableProperties projectProps, EditableProperties privateProps) { 182 projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(newServInstID)); 184 185 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 187 } 188 public static Object mapType(String string) { 189 Object retVal = J2eeModule.EJB; 190 if (string.equals(ArchiveProjectProperties.PROJECT_TYPE_VALUE_CAR)) { 191 retVal = J2eeModule.CLIENT; 192 } 193 if (string.equals(ArchiveProjectProperties.PROJECT_TYPE_VALUE_WAR)) { 194 retVal = J2eeModule.WAR; 195 } 196 if (string.equals(ArchiveProjectProperties.PROJECT_TYPE_VALUE_JAR)) { 197 retVal = J2eeModule.EJB; 198 } 199 if (string.equals(ArchiveProjectProperties.PROJECT_TYPE_VALUE_EAR)) { 200 retVal = J2eeModule.EAR; 201 } 202 if (string.equals(ArchiveProjectProperties.PROJECT_TYPE_VALUE_RAR)) { 203 retVal = J2eeModule.CONN; 204 } 205 return retVal; 206 } 207 208 } 209 | Popular Tags |