This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 206623
Collapse All | Expand All

(-)a/refactoring.api/apichanges.xml (+15 lines)
Lines 49-54 Link Here
49
    <apidef name="refactoring">Refactoring API</apidef>
49
    <apidef name="refactoring">Refactoring API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="CopyRefactoring">
53
        <api name="refactoring"/>
54
        <summary>Added CopyRefactoring to support Copy of multiple files.</summary>
55
        <version major="1" minor="21"/>
56
        <date day="21" month="12" year="2011"/>
57
        <author login="ralphbenjamin"/>
58
        <compatibility addition="yes"/>
59
        <description>
60
            <p>
61
                Added support to copy multiple files at once.
62
            </p>    
63
        </description>
64
        <class package="org.netbeans.modules.refactoring.api" name="CopyRefactoring"/>
65
        <issue number="206623"/>
66
    </change>
52
    <change id="Scope">
67
    <change id="Scope">
53
        <api name="refactoring"/>
68
        <api name="refactoring"/>
54
        <summary>Scope added to allow to specify a limited scope for WhereUsedQuery</summary>
69
        <summary>Scope added to allow to specify a limited scope for WhereUsedQuery</summary>
(-)a/refactoring.api/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.modules.refactoring.api
2
OpenIDE-Module: org.netbeans.modules.refactoring.api
3
OpenIDE-Module-Layer: org/netbeans/modules/refactoring/api/resources/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/refactoring/api/resources/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/refactoring/api/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/refactoring/api/resources/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.20
5
OpenIDE-Module-Specification-Version: 1.21
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
7
7
(-)a/refactoring.api/nbproject/project.xml (+5 lines)
Lines 200-205 Link Here
200
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
200
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
201
                        <compile-dependency/>
201
                        <compile-dependency/>
202
                    </test-dependency>
202
                    </test-dependency>
203
                    <test-dependency>
204
                        <code-name-base>org.openide.util.lookup</code-name-base>
205
                        <compile-dependency/>
206
                        <test/>
207
                    </test-dependency>
203
                </test-type>
208
                </test-type>
204
            </test-dependencies>
209
            </test-dependencies>
205
            <public-packages>
210
            <public-packages>
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/CopyRefactoring.java (+109 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.refactoring.api;
46
47
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.NonNull;
49
import org.openide.util.Lookup;
50
import org.openide.util.Parameters;
51
52
/**
53
 * This class is just holder for parameters of Copy Refactoring.
54
 * Refactoring itself is implemented in plugins.
55
 * 
56
 * @see org.netbeans.modules.refactoring.spi.RefactoringPlugin
57
 * @see org.netbeans.modules.refactoring.spi.RefactoringPluginFactory
58
 * @see AbstractRefactoring
59
 * @see RefactoringSession
60
 * @author Ralph Ruijs
61
 * @since 1.21
62
 */
63
public final class CopyRefactoring extends AbstractRefactoring {
64
65
    private Lookup target;
66
67
    /**
68
     * Creates a new instance of CopyRefactoring.
69
     * Copy Refactoring implementations currently understand the following types:
70
     * <table border="1">
71
     *   <tr><th>Module</th><th>Types the Module Understands</th><th>Implementation</th></tr>
72
     *   <tr><td>Refactoring API (Default impl.)</td><td>{@link org.openide.filesystems.FileObject}(s)</td><td>Does file copy</td></tr>
73
     *   <tr><td>Java Refactoring</td><td><ul>
74
     *                                    <li>{@link org.openide.filesystems.FileObject}(s) with content type text/x-java (class copy)
75
     *                                    </ul>
76
     *                              <td>Updates name, package declaration and import statements</td></tr>
77
     * </table>
78
     * @param objectsToCopy Object to be copied stored into Lookup
79
     */
80
    public CopyRefactoring (@NonNull Lookup objectsToCopy) {
81
        super(objectsToCopy);
82
    }
83
84
    /**
85
     * Target for copying.
86
     * Copy Refactoring implementations currently understand the following types:
87
     * <table border="1">
88
     *   <tr><th>Module</th><th>Types the Module Understands</th><th>Implementation</th></tr>
89
     *   <tr><td>Refactoring API (Default impl.)</td><td>{@link java.net.URL}</td>
90
     *        <td>Creates directory corresponding to specified URL (if it does not exist) and copies all FileObjects into this folder.</td></tr>
91
     *   <tr><td>Java Refactoring</td><td>{@link java.net.URL}</td><td>Updates name, package declaration and import statements</td></tr>
92
     * </table>
93
     * @param target
94
     */
95
    public void setTarget(@NonNull Lookup target) {
96
        Parameters.notNull("target", target); // NOI18N
97
        this.target = target;
98
    }
99
100
    /**
101
     * Target for moving
102
     * @see #setTarget
103
     * @return target
104
     */
105
    @CheckForNull
106
    public Lookup getTarget() {
107
        return this.target;
108
    }
109
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/plugins/CopyFile.java (+133 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.refactoring.plugins;
43
44
import java.io.IOException;
45
import java.net.URL;
46
import java.util.Arrays;
47
import org.netbeans.modules.refactoring.api.Context;
48
import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation;
49
import org.openide.ErrorManager;
50
import org.openide.filesystems.FileObject;
51
import org.openide.loaders.DataFolder;
52
import org.openide.loaders.DataObject;
53
import org.openide.text.PositionBounds;
54
import org.openide.util.Lookup;
55
import org.openide.util.NbBundle;
56
57
/**
58
 *
59
 * @author Ralph Ruijs
60
 */
61
public class CopyFile extends SimpleRefactoringElementImplementation {
62
63
    private FileObject fo;
64
    private DataObject newOne;
65
    private final URL target;
66
    private final String newName;
67
    private final Context context;
68
69
    public CopyFile(FileObject fo, URL target, String newName, Context context) {
70
        this.fo = fo;
71
        this.target = target;
72
        this.newName = newName;
73
        this.context = context;
74
    }
75
76
    @Override
77
    public String getText() {
78
        return NbBundle.getMessage(CopyFile.class, "TXT_CopyFile", fo.getNameExt());
79
    }
80
81
    @Override
82
    public String getDisplayText() {
83
        return getText();
84
    }
85
86
    @Override
87
    public void performChange() {
88
        try {
89
            FileObject targetFo = FileHandlingFactory.getOrCreateFolder(target);
90
            FileObject Fo = fo;
91
            DataObject dob = DataObject.find(Fo);
92
            newOne = dob.copy(DataFolder.findFolder(targetFo));
93
            newOne.rename(newName == null ? fo.getName() : newName);
94
            FileObject[] newFiles = context.lookup(FileObject[].class);
95
            if (newFiles == null) {
96
                newFiles = new FileObject[]{newOne.getPrimaryFile()};
97
            } else {
98
                newFiles = Arrays.copyOf(newFiles, newFiles.length + 1);
99
                newFiles[newFiles.length - 1] = newOne.getPrimaryFile();
100
            }
101
            context.add(newFiles);
102
            context.add(newOne.getPrimaryFile());
103
        } catch (IOException ex) {
104
            throw new IllegalStateException(ex);
105
        }
106
    }
107
108
    @Override
109
    public void undoChange() {
110
        try {
111
            if (newOne != null) {
112
                newOne.delete();
113
            }
114
        } catch (IOException ex) {
115
            ErrorManager.getDefault().notify(ex);
116
        }
117
    }
118
119
    @Override
120
    public Lookup getLookup() {
121
        return Lookup.EMPTY;
122
    }
123
124
    @Override
125
    public FileObject getParentFile() {
126
        return fo;
127
    }
128
129
    @Override
130
    public PositionBounds getPosition() {
131
        return null;
132
    }
133
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/plugins/FileHandlingFactory.java (-7 / +3 lines)
Lines 49-59 Link Here
49
import java.net.URL;
49
import java.net.URL;
50
import java.util.Collection;
50
import java.util.Collection;
51
import org.netbeans.api.fileinfo.NonRecursiveFolder;
51
import org.netbeans.api.fileinfo.NonRecursiveFolder;
52
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
52
import org.netbeans.modules.refactoring.api.*;
53
import org.netbeans.modules.refactoring.api.MoveRefactoring;
54
import org.netbeans.modules.refactoring.api.RenameRefactoring;
55
import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;
56
import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;
57
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
53
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
58
import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
54
import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
59
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
Lines 94-102 Link Here
94
                    return new FileDeletePlugin((SafeDeleteRefactoring) refactoring);
90
                    return new FileDeletePlugin((SafeDeleteRefactoring) refactoring);
95
                }
91
                }
96
            }
92
            }
97
        } else if (refactoring instanceof SingleCopyRefactoring) {
93
        } else if (refactoring instanceof SingleCopyRefactoring || refactoring instanceof CopyRefactoring) {
98
            if (!o.isEmpty()) {
94
            if (!o.isEmpty()) {
99
                return new FileCopyPlugin((SingleCopyRefactoring) refactoring);
95
                return new FilesCopyPlugin(refactoring);
100
            }
96
            }
101
        }
97
        }
102
        return null;
98
        return null;
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/plugins/FileCopyPlugin.java (-75 / +23 lines)
Lines 43-73 Link Here
43
 */
43
 */
44
package org.netbeans.modules.refactoring.plugins;
44
package org.netbeans.modules.refactoring.plugins;
45
45
46
import java.io.IOException;
47
import java.net.URL;
46
import java.net.URL;
47
import java.util.Collection;
48
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
49
import org.netbeans.modules.refactoring.api.CopyRefactoring;
50
import org.netbeans.modules.refactoring.api.Problem;
48
import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;
51
import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;
49
import org.netbeans.modules.refactoring.api.Problem;
50
import org.netbeans.modules.refactoring.api.RefactoringSession;
51
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
52
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
52
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
53
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
53
import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation;
54
import org.openide.ErrorManager;
55
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
56
import org.openide.loaders.DataFolder;
57
import org.openide.loaders.DataObject;
58
import org.openide.text.PositionBounds;
59
import org.openide.util.Lookup;
60
import org.openide.util.NbBundle;
61
55
62
/**
56
/**
63
 *
57
 *
64
 * @author  Jan Becicka
58
 * @author Ralph Ruijs
65
 */
59
 */
66
public class FileCopyPlugin implements RefactoringPlugin {
60
public class FilesCopyPlugin implements RefactoringPlugin {
67
    private SingleCopyRefactoring refactoring;
61
    private AbstractRefactoring refactoring;
68
    
62
    
69
    /** Creates a new instance of WhereUsedQuery */
63
    /** Creates a new instance of WhereUsedQuery */
70
    public FileCopyPlugin(SingleCopyRefactoring refactoring) {
64
    public FilesCopyPlugin(AbstractRefactoring refactoring) {
71
        this.refactoring = refactoring;
65
        this.refactoring = refactoring;
72
    }
66
    }
73
    
67
    
Lines 78-84 Link Here
78
    
72
    
79
    @Override
73
    @Override
80
    public Problem prepare(RefactoringElementsBag elements) {
74
    public Problem prepare(RefactoringElementsBag elements) {
81
        elements.add(refactoring, new CopyFile(refactoring.getRefactoringSource().lookup(FileObject.class), elements.getSession()));
75
        URL target = null;
76
        String newName = null;
77
        if(refactoring instanceof SingleCopyRefactoring) {
78
            SingleCopyRefactoring scr = (SingleCopyRefactoring) refactoring;
79
            target = scr.getTarget().lookup(URL.class);
80
            newName = scr.getNewName();
81
        } else if(refactoring instanceof CopyRefactoring) {
82
            CopyRefactoring scr = (CopyRefactoring) refactoring;
83
            target = scr.getTarget().lookup(URL.class);
84
        }
85
        
86
        Collection<? extends FileObject> fileObjects = refactoring.getRefactoringSource().lookupAll(FileObject.class);
87
        for (FileObject fileObject : fileObjects) {
88
            elements.add(refactoring, new CopyFile(fileObject, target, newName, refactoring.getContext()));
89
        }
82
        return null;
90
        return null;
83
    }
91
    }
84
    
92
    
Lines 95-158 Link Here
95
    @Override
103
    @Override
96
    public void cancelRequest() {
104
    public void cancelRequest() {
97
    }
105
    }
98
    
99
    private class CopyFile extends SimpleRefactoringElementImplementation {
100
        
101
        private FileObject fo;
102
        private RefactoringSession session;
103
        private DataObject newOne;
104
        public CopyFile(FileObject fo, RefactoringSession session) {
105
            this.fo = fo;
106
            this.session = session;
107
        }
108
        @Override
109
        public String getText() {            
110
            return NbBundle.getMessage(FileCopyPlugin.class, "TXT_CopyFile", fo.getNameExt());
111
        }
112
        
113
        @Override
114
        public String getDisplayText() {
115
            return getText();
116
        }
117
        
118
        @Override
119
        public void performChange() {
120
            try {
121
                FileObject fo = FileHandlingFactory.getOrCreateFolder(refactoring.getTarget().lookup(URL.class));
122
                FileObject source = refactoring.getRefactoringSource().lookup(FileObject.class);
123
                DataObject dob = DataObject.find(source);
124
                newOne = dob.copy(DataFolder.findFolder(fo));
125
                newOne.rename(refactoring.getNewName());
126
                refactoring.getContext().add(newOne.getPrimaryFile());
127
            } catch (IOException ex) {
128
                throw new IllegalStateException(ex);
129
            }
130
        }
131
        
132
        @Override
133
        public void undoChange() {
134
            try {
135
                if (newOne != null) {
136
                    newOne.delete();
137
                }
138
            } catch (IOException ex) {
139
                ErrorManager.getDefault().notify(ex);
140
            }
141
        }
142
        
143
        @Override
144
        public Lookup getLookup() {
145
            return Lookup.EMPTY;
146
        }
147
        
148
        @Override
149
        public FileObject getParentFile() {
150
            return fo;
151
        }
152
        
153
        @Override
154
        public PositionBounds getPosition() {
155
            return null;
156
        }
157
    }
158
}
106
}
(-)a/refactoring.api/test/unit/src/org/netbeans/modules/refactoring/plugins/FilesCopyPluginTest.java (+154 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.refactoring.plugins;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.io.OutputStream;
47
import org.junit.*;
48
import org.netbeans.junit.NbTestCase;
49
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
50
import org.netbeans.modules.refactoring.api.CopyRefactoring;
51
import org.netbeans.modules.refactoring.api.RefactoringSession;
52
import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;
53
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
54
import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.util.lookup.Lookups;
58
import org.openide.util.test.MockLookup;
59
60
/**
61
 *
62
 * @author Ralph Ruijs
63
 */
64
public class FilesCopyPluginTest extends NbTestCase {
65
    
66
    private FileObject f;
67
    private FileObject f1;
68
69
    public FilesCopyPluginTest(String name) {
70
        super(name);
71
    }
72
73
    @BeforeClass
74
    public static void setUpClass() throws Exception {
75
        MockLookup.setInstances(new RefactoringPluginFactory() {
76
77
            @Override
78
            public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {
79
                return new FilesCopyPlugin(refactoring);
80
            }
81
        });
82
    }
83
84
    @AfterClass
85
    public static void tearDownClass() throws Exception {
86
    }
87
    
88
    @Before
89
    public void setUp() throws IOException {
90
        clearWorkDir();
91
        f = FileUtil.createData(FileUtil.toFileObject(getWorkDir()), "test");
92
        OutputStream outputStream = f.getOutputStream();
93
        outputStream.write("test".getBytes());
94
        outputStream.close();
95
        f1 = FileUtil.createData(FileUtil.toFileObject(getWorkDir()), "test1");
96
        outputStream = f1.getOutputStream();
97
        outputStream.write("test1".getBytes());
98
        outputStream.close();
99
    }
100
    
101
    @After
102
    public void tearDown() {
103
    }
104
105
    /**
106
     * Test of preCheck method, of class FilesCopyPlugin.
107
     */
108
    @Test
109
    public void testChecks() {
110
        FilesCopyPlugin copyPlugin = new FilesCopyPlugin(null);
111
        assertEquals(null, copyPlugin.preCheck());
112
        assertEquals(null, copyPlugin.fastCheckParameters());
113
        assertEquals(null, copyPlugin.checkParameters());
114
    }
115
116
    /**
117
     * Test of prepare method, of class FilesCopyPlugin.
118
     */
119
    @Test
120
    public void testPrepare() throws Exception {
121
        RefactoringSession session = RefactoringSession.create("junit");
122
        CopyRefactoring copyRefactoring = new CopyRefactoring(Lookups.fixed(f));
123
        File target = new File(getWorkDirPath() + File.separatorChar + "junit" + File.separatorChar);
124
        copyRefactoring.setTarget(Lookups.fixed(target.toURI().toURL()));
125
        copyRefactoring.prepare(session);
126
        session.doRefactoring(true);
127
        FileObject newOne = copyRefactoring.getContext().lookup(FileObject.class);
128
        assertEquals(newOne.asText(), f.asText());
129
        
130
        session = RefactoringSession.create("junit1");
131
        target = new File(getWorkDirPath() + File.separatorChar + "junit1" + File.separatorChar);
132
        copyRefactoring = new CopyRefactoring(Lookups.fixed(f, f1));
133
        copyRefactoring.setTarget(Lookups.fixed(target.toURI().toURL()));
134
        copyRefactoring.prepare(session);
135
        session.doRefactoring(true);
136
        FileObject[] newOnes = copyRefactoring.getContext().lookup(FileObject[].class);
137
        assertEquals(newOnes[0].asText(), f.asText());
138
        assertEquals(newOnes[0].getName(), f.getName());
139
        assertEquals(newOnes[1].asText(), f1.asText());
140
        assertEquals(newOnes[1].getName(), f1.getName());
141
        
142
        session = RefactoringSession.create("junit2");
143
        SingleCopyRefactoring singleCopyRefactoring = new SingleCopyRefactoring(Lookups.fixed(f));
144
        target = new File(getWorkDirPath() + File.separatorChar + "junit" + File.separatorChar);
145
        singleCopyRefactoring.setTarget(Lookups.fixed(target.toURI().toURL()));
146
        String newName = "HelloWorld";
147
        singleCopyRefactoring.setNewName(newName);
148
        singleCopyRefactoring.prepare(session);
149
        session.doRefactoring(true);
150
        FileObject newOneRenamed = singleCopyRefactoring.getContext().lookup(FileObject.class);
151
        assertEquals(newOneRenamed.asText(), f.asText());
152
        assertEquals(newOneRenamed.getName(), newName);
153
    }
154
}

Return to bug 206623