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: ecf057418c761536726f4d3e2edc7b36dc5979ce (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
/*******************************************************************************
 * 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.command;


import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.ws.internal.common.J2EEUtils;
import org.eclipse.jst.ws.internal.common.ResourceUtils;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;

/**
 * 
 * This command copies the server-config.wsdd file to it's proper location in the module.
 * 
 */

public class CopyDeploymentFileCommand extends AbstractDataModelOperation
{
  private String projectName_;
  
  /**
   * Constructor for CopyDeploymentFileCommand.
 * @param String description
 * @param String name
   * 
   */
  public CopyDeploymentFileCommand( String projectName )
  { 
    projectName_   = projectName;
  }

	public IStatus execute( IProgressMonitor monitor, IAdaptable adaptable ) 
	{
    IStatus            status         = Status.OK_STATUS;
    
    try
    {
      IVirtualComponent component      = J2EEUtils.getVirtualComponent( projectName_ );
      IFolder           root           = J2EEUtils.getOutputContainerRoot( component );
      IPath             path           = new Path( "WEB-INF" ).append( "server-config.wsdd" );
      IFile             descriptorFile = root.getFile( path );
      IVirtualFile      newLocation    = component.getRootFolder().getFile( path );
      IPath             targetPath     = newLocation.getWorkspaceRelativePath();
      IFile             targetFile     = (IFile)ResourceUtils.findResource( targetPath );
        
      descriptorFile.refreshLocal( 0, null );
      
      if( targetFile != null && targetFile.exists() )
      {
        // The target file already exists so we will just overwrite its contents.
    	targetFile.setContents( descriptorFile.getContents(), true, false, null );
      }
      else
      {
    	// The target file doesn't exist so we will copy it.
        descriptorFile.copy( targetPath, true, null );
      }
    }
    catch( Throwable exc )
    {
    }
    
    return status;
  }
}

Back to the top