Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 2fe3eaaf0f2d7d2ca0e08c12dd746758bef0cbee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*******************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.ws.internal.axis.creation.ui.task;


import java.io.File;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jst.ws.internal.axis.consumption.core.common.JavaWSDLParameter;
import org.eclipse.jst.ws.internal.axis.consumption.ui.util.FileUtil;
import org.eclipse.jst.ws.internal.common.J2EEUtils;
import org.eclipse.jst.ws.internal.common.ResourceUtils;
import org.eclipse.jst.ws.internal.common.ServerUtils;
import org.eclipse.wst.command.internal.provisional.env.core.SimpleCommand;
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment;
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils;
import org.eclipse.wst.command.internal.provisional.env.core.common.SimpleStatus;
import org.eclipse.wst.command.internal.provisional.env.core.common.Status;

public class MoveDeploymentFilesTask extends SimpleCommand {

	private final String LABEL = "TASK_LABEL_MOVE_DEPLOYMENT_FILES";
	private final String DESCRIPTION = "TASK_DESC_MOVE_DEPLOYMENT_FILES";
	private final String WEB_INF = "WEB-INF";	//$NON-NLS-1$
	private final String META_INF = "META-INF";	//$NON-NLS-1$

	private MessageUtils msgUtils_;
	private MessageUtils coreMsgUtils_;
	private IProject serverProject;
	private String   moduleName_;
	
    private JavaWSDLParameter javaWSDLParam_;
	
	public MoveDeploymentFilesTask( String moduleName )
    {
      String pluginId = "org.eclipse.jst.ws.axis.creation.ui";
      msgUtils_ = new MessageUtils(pluginId + ".plugin", this);
      coreMsgUtils_ = new MessageUtils( "org.eclipse.jst.ws.axis.consumption.core.consumption", this );
      setDescription(msgUtils_.getMessage(DESCRIPTION));
      setName(msgUtils_.getMessage(LABEL));
	  
	  moduleName_ = moduleName;
    }

  /**
	* Execute DefaultsForJavaToWSDLTask
	*/
	public Status execute(Environment env) {
		Status status = new SimpleStatus("");
		if (javaWSDLParam_ == null) {
		  status = new SimpleStatus("",coreMsgUtils_.getMessage("MSG_ERROR_JAVA_WSDL_PARAM_NOT_SET"), Status.ERROR);
		  env.getStatusHandler().reportError(status);
		  return status;
		}

		IProject project = serverProject;
		//String projectURL = ResourceUtils.getEncodedWebProjectURL(project);
		String projectURL = ServerUtils.getEncodedWebComponentURL(project, moduleName_);
		
		if (projectURL == null) {
		    status = new SimpleStatus("",msgUtils_.getMessage("MSG_ERROR_PROJECT_URL",new String[] { project.toString()}), Status.ERROR);
		    env.getStatusHandler().reportError(status);
		    return status;		  
		} else {
			javaWSDLParam_.setProjectURL(projectURL);
		}

		try {
//			if (!project.hasNature(IWebNatureConstants.J2EE_NATURE_ID))
//				return status;
//		} catch (Exception ex) {
//		  status = new SimpleStatus("",msgUtils_.getMessage("MSG_ERROR_INTERAL"), Status.ERROR, ex);
//		  env.getStatusHandler().reportError(status);
//		  return status;		  
//		}
		String[] deployFiles = javaWSDLParam_.getDeploymentFiles();
		String javaOutput = javaWSDLParam_.getJavaOutput();

		if (deployFiles == null || javaOutput == null) {
			return status;
		}


		IPath webinfPath = J2EEUtils.getWebInfPath(project, moduleName_ );

			for (int i = 0; i < deployFiles.length; i++) {
        File f = new File(deployFiles[i]);
        String resourceToMove = f.getName();
				String targetFileName = ResourceUtils.getWorkspaceRoot().getFile(webinfPath.addTrailingSeparator().append(resourceToMove)).getLocation().toString();
				FileUtil.createTargetFile(deployFiles[i], targetFileName, true);
				File deploymentFile = new File(deployFiles[i]);
				deploymentFile.delete();
				deployFiles[i] = targetFileName;
			}

		} catch (Exception e) {
		  status = new SimpleStatus("",msgUtils_.getMessage("MSG_ERROR_MOVE_RESOURCE",new String[] { e.getLocalizedMessage()}), Status.ERROR, e);
		  env.getStatusHandler().reportError(status);
		  return status;		  
		}
		
		return status;
	}

	public JavaWSDLParameter getJavaWSDLParam()
	{
		return javaWSDLParam_;
	}
	
	public void setJavaWSDLParam(JavaWSDLParameter javaWSDLParam)
	{
		javaWSDLParam_ = javaWSDLParam;
	}
	
	public void setServerProject(IProject serverProject)
	{
	  this.serverProject = serverProject;
	}
}

Back to the top