sandbox/old-modules/api/test/unit/src/org/netbeans/modules/jackpot30/spi/refactoring/JackpotBasedRefactoringTestBase.java
1.1 --- a/sandbox/old-modules/api/test/unit/src/org/netbeans/modules/jackpot30/spi/refactoring/JackpotBasedRefactoringTestBase.java Mon Dec 19 11:37:36 2016 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,198 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
1.8 - *
1.9 - * The contents of this file are subject to the terms of either the GNU
1.10 - * General Public License Version 2 only ("GPL") or the Common
1.11 - * Development and Distribution License("CDDL") (collectively, the
1.12 - * "License"). You may not use this file except in compliance with the
1.13 - * License. You can obtain a copy of the License at
1.14 - * http://www.netbeans.org/cddl-gplv2.html
1.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.16 - * specific language governing permissions and limitations under the
1.17 - * License. When distributing the software, include this License Header
1.18 - * Notice in each file and include the License file at
1.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
1.20 - * particular file as subject to the "Classpath" exception as provided
1.21 - * by Sun in the GPL Version 2 section of the License file that
1.22 - * accompanied this code. If applicable, add the following below the
1.23 - * License Header, with the fields enclosed by brackets [] replaced by
1.24 - * your own identifying information:
1.25 - * "Portions Copyrighted [year] [name of copyright owner]"
1.26 - *
1.27 - * If you wish your version of this file to be governed by only the CDDL
1.28 - * or only the GPL Version 2, indicate your decision by adding
1.29 - * "[Contributor] elects to include this software in this distribution
1.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.31 - * single choice of license, a recipient has the option to distribute
1.32 - * your version of this file under either the CDDL, the GPL Version 2 or
1.33 - * to extend the choice of license to its licensees as provided above.
1.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
1.35 - * Version 2 license, then the option applies only if the new code is
1.36 - * made subject to such option by the copyright holder.
1.37 - *
1.38 - * Contributor(s):
1.39 - *
1.40 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
1.41 - */
1.42 -
1.43 -package org.netbeans.modules.jackpot30.spi.refactoring;
1.44 -
1.45 -import java.io.IOException;
1.46 -import java.util.Collections;
1.47 -import org.netbeans.api.editor.mimelookup.MimePath;
1.48 -import org.netbeans.api.java.classpath.ClassPath;
1.49 -import org.netbeans.api.java.classpath.GlobalPathRegistry;
1.50 -import org.netbeans.api.java.source.SourceUtils;
1.51 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
1.52 -import org.netbeans.api.java.source.TestUtilities;
1.53 -import org.netbeans.api.project.Project;
1.54 -import org.netbeans.api.project.ProjectManager;
1.55 -import org.netbeans.core.startup.Main;
1.56 -import org.netbeans.junit.NbTestCase;
1.57 -import org.netbeans.modules.java.JavaDataLoader;
1.58 -import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
1.59 -import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
1.60 -import org.netbeans.modules.parsing.impl.indexing.MimeTypes;
1.61 -import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
1.62 -import org.netbeans.modules.parsing.impl.indexing.Util;
1.63 -import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
1.64 -import org.netbeans.spi.java.classpath.ClassPathProvider;
1.65 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
1.66 -import org.netbeans.spi.project.ProjectFactory;
1.67 -import org.netbeans.spi.project.ProjectState;
1.68 -import org.openide.filesystems.FileObject;
1.69 -import org.openide.filesystems.FileUtil;
1.70 -import org.openide.util.Lookup;
1.71 -import org.openide.util.lookup.Lookups;
1.72 -import org.openide.util.lookup.ServiceProvider;
1.73 -
1.74 -/**
1.75 - *
1.76 - * @author lahvac
1.77 - */
1.78 -public class JackpotBasedRefactoringTestBase extends NbTestCase {
1.79 -
1.80 - public JackpotBasedRefactoringTestBase(String name) {
1.81 - super(name);
1.82 - }
1.83 -
1.84 - protected static void writeFilesAndWaitForScan(FileObject sourceRoot, File... files) throws Exception {
1.85 - for (FileObject c : sourceRoot.getChildren()) {
1.86 - c.delete();
1.87 - }
1.88 -
1.89 - for (File f : files) {
1.90 - FileObject fo = FileUtil.createData(sourceRoot, f.filename);
1.91 - TestUtilities.copyStringToFile(fo, f.content);
1.92 - }
1.93 -
1.94 - SourceUtils.waitScanFinished();
1.95 - }
1.96 -
1.97 - protected static void assertContent(FileObject sourceRoot, File... files) throws Exception {
1.98 - for (File f : files) {
1.99 - FileObject fo = sourceRoot.getFileObject(f.filename);
1.100 -
1.101 - assertNotNull(f.filename, fo);
1.102 -
1.103 - assertEquals(f.content.replaceAll("[ \t\n]+", " "), TestUtilities.copyFileToString(FileUtil.toFile(fo)).replaceAll("[ \t\n]+", " "));
1.104 - }
1.105 - }
1.106 -
1.107 - protected static final class File {
1.108 - public final String filename;
1.109 - public final String content;
1.110 -
1.111 - public File(String filename, String content) {
1.112 - this.filename = filename;
1.113 - this.content = content;
1.114 - }
1.115 - }
1.116 -
1.117 - protected FileObject src;
1.118 - protected Project prj;
1.119 -
1.120 - @Override
1.121 - protected void setUp() throws Exception {
1.122 - SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[] {
1.123 - new ClassPathProvider() {
1.124 - public ClassPath findClassPath(FileObject file, String type) {
1.125 - if (src != null && (file == src || FileUtil.isParentOf(src, file))) {
1.126 - if (ClassPath.BOOT.equals(type)) {
1.127 - return ClassPathSupport.createClassPath(System.getProperty("sun.boot.class.path"));
1.128 - }
1.129 - if (ClassPath.COMPILE.equals(type)) {
1.130 - return ClassPathSupport.createClassPath(new FileObject[0]);
1.131 - }
1.132 - if (ClassPath.SOURCE.equals(type)) {
1.133 - return ClassPathSupport.createClassPath(src);
1.134 - }
1.135 - }
1.136 -
1.137 - return null;
1.138 - }
1.139 - },
1.140 - new ProjectFactory() {
1.141 - public boolean isProject(FileObject projectDirectory) {
1.142 - return src == projectDirectory;
1.143 - }
1.144 - public Project loadProject(final FileObject projectDirectory, ProjectState state) throws IOException {
1.145 - if (!isProject(projectDirectory)) return null;
1.146 - return new Project() {
1.147 - public FileObject getProjectDirectory() {
1.148 - return projectDirectory;
1.149 - }
1.150 - public Lookup getLookup() {
1.151 - return Lookup.EMPTY;
1.152 - }
1.153 - };
1.154 - }
1.155 - public void saveProject(Project project) throws IOException, ClassCastException {}
1.156 - },
1.157 - JavaDataLoader.getLoader(JavaDataLoader.class),
1.158 - });
1.159 - Main.initializeURLFactory();
1.160 - org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
1.161 - prepareTest();
1.162 - org.netbeans.api.project.ui.OpenProjects.getDefault().open(new Project[] {prj = ProjectManager.getDefault().findProject(src)}, false);
1.163 - MimeTypes.setAllMimeTypes(Collections.singleton("text/x-java"));
1.164 - GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {ClassPathSupport.createClassPath(src)});
1.165 - RepositoryUpdater.getDefault().start(true);
1.166 - super.setUp();
1.167 - }
1.168 -
1.169 - @Override
1.170 - protected void tearDown() throws Exception {
1.171 - super.tearDown();
1.172 - org.netbeans.api.project.ui.OpenProjects.getDefault().open(new Project[] {prj}, false);
1.173 - prj = null;
1.174 - }
1.175 -
1.176 - private void prepareTest() throws Exception {
1.177 - FileObject workdir = SourceUtilsTestUtil.makeScratchDir(this);
1.178 -
1.179 - src = FileUtil.createFolder(workdir, "src");
1.180 -
1.181 - FileObject cache = FileUtil.createFolder(workdir, "cache");
1.182 -
1.183 - CacheFolder.setCacheFolder(cache);
1.184 - }
1.185 -
1.186 - @ServiceProvider(service=MimeDataProvider.class)
1.187 - public static final class MimeDataProviderImpl implements MimeDataProvider {
1.188 -
1.189 - private static final Lookup L = Lookups.singleton(new JavaCustomIndexer.Factory());
1.190 -
1.191 - public Lookup getLookup(MimePath mimePath) {
1.192 - if ("text/x-java".equals(mimePath.getPath())) {
1.193 - return L;
1.194 - }
1.195 -
1.196 - return null;
1.197 - }
1.198 -
1.199 - }
1.200 -
1.201 -}