提交 c0aae0f7 编写于 作者: A Alexander Fedorov

#10 added org.jkiss.dbeaver.runtime.ide.core with tests

Former-commit-id: da115bfe
上级 08f71f81
......@@ -41,6 +41,7 @@
<!-- DBeaver -->
<plugin id="org.jkiss.dbeaver.model" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.runtime.ide.core" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.core" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ui" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.erd" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.runtime.ide.core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Vendor: %Bundle-Vendor
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.jkiss.dbeaver.runtime.ide.core
Bundle-Version: 4.2.2
Bundle-Release-Date: 20171002
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
org.eclipse.core.resources;visibility:=reexport
Export-Package: org.jkiss.dbeaver.runtime.ide.core
#Properties file for org.jkiss.dbeaver.runtime.ide.core
Bundle-Vendor = JKISS
Bundle-Name = DBeaver Runtime IDE Core
\ No newline at end of file
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.,\
OSGI-INF/
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>dbeaver</artifactId>
<version>1.0.0</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.runtime.ide.core</artifactId>
<version>4.2.2</version>
<packaging>eclipse-plugin</packaging>
</project>
package org.jkiss.dbeaver.runtime.ide.core;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class IdeCore {
public static final String BUNDLE_SYMBOLIC_NAME = "org.jkiss.dbeaver.runtime.ide.core"; //$NON-NLS-1$
public static IStatus createError(String message) {
return new Status(IStatus.ERROR, BUNDLE_SYMBOLIC_NAME, message);
}
public static IStatus createError(String message, Throwable t) {
return new Status(IStatus.ERROR, BUNDLE_SYMBOLIC_NAME, message, t);
}
}
package org.jkiss.dbeaver.runtime.ide.core;
import java.net.URI;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jkiss.dbeaver.runtime.internal.ide.core.CreateLinkedFileRunnable;
import org.jkiss.dbeaver.runtime.internal.ide.core.CreateLinkedFolderRunnable;
public class WorkspaceResources {
public static IStatus linkFile(IFile file, URI location, IProgressMonitor monitor) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
workspace.run(new CreateLinkedFileRunnable(file, location), monitor);
} catch (CoreException e) {
return e.getStatus();
} catch (Throwable e) {
String message = CreateLinkedFileRunnable.composeErrorMessage(file, location);
return IdeCore.createError(message, e);
}
return Status.OK_STATUS;
}
public static IStatus linkFolder(IFolder folder, URI location, IProgressMonitor monitor) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
workspace.run(new CreateLinkedFolderRunnable(folder, location), monitor);
} catch (CoreException e) {
return e.getStatus();
} catch (Throwable e) {
String message = CreateLinkedFolderRunnable.composeErrorMessage(folder, location);
return IdeCore.createError(message, e);
}
return Status.OK_STATUS;
}
}
package org.jkiss.dbeaver.runtime.internal.ide.core;
import java.net.URI;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.runtime.ide.core.IdeCore;
public class CreateLinkedFileRunnable implements ICoreRunnable {
private final IFile file;
private final URI location;
private final int flags;
public CreateLinkedFileRunnable(IFile file, URI location)
{
this.file = file;
this.location = location;
this.flags = IResource.NONE;
}
@Override
public void run(IProgressMonitor monitor) throws CoreException
{
if (file == null || location == null) {
String message = composeErrorMessage(file, location);
IStatus error = IdeCore.createError(message);
throw new CoreException(error);
}
file.createLink(location, flags, monitor);
}
public static String composeErrorMessage(IFile file, URI location)
{
String message = NLS.bind(IdeCoreMessages.CreateLinkedFileRunnable_e_unable_to_link, file, location);
return message;
}
}
package org.jkiss.dbeaver.runtime.internal.ide.core;
import java.net.URI;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.runtime.ide.core.IdeCore;
public class CreateLinkedFolderRunnable implements ICoreRunnable {
private final IFolder folder;
private final URI location;
private final int flags;
public CreateLinkedFolderRunnable(IFolder folder, URI location)
{
this.folder = folder;
this.location = location;
this.flags = IResource.NONE;
}
@Override
public void run(IProgressMonitor monitor) throws CoreException
{
if (folder == null || location == null) {
String message = composeErrorMessage(folder, location);
IStatus error = IdeCore.createError(message);
throw new CoreException(error);
}
folder.createLink(location, flags, monitor);
}
public static String composeErrorMessage(IFolder folder, URI location)
{
String message = NLS.bind(IdeCoreMessages.CreateLinkedFolderRunnable_e_unable_to_link, folder, location);
return message;
}
}
package org.jkiss.dbeaver.runtime.internal.ide.core;
import org.eclipse.osgi.util.NLS;
public class IdeCoreMessages extends NLS {
private static final String BUNDLE_NAME = "org.jkiss.dbeaver.runtime.internal.ide.core.ide_core_messages"; //$NON-NLS-1$
public static String CreateLinkedFileRunnable_e_unable_to_link;
public static String CreateLinkedFolderRunnable_e_unable_to_link;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, IdeCoreMessages.class);
}
private IdeCoreMessages()
{
}
}
CreateLinkedFileRunnable_e_unable_to_link=Unable to link file {0} with location {1}
CreateLinkedFolderRunnable_e_unable_to_link=Unable to link folder {0} with location {1}
......@@ -23,6 +23,7 @@
<module>modules/org.jkiss.utils</module>
<module>modules/org.jkiss.wmi</module>
<module>plugins/org.jkiss.dbeaver.runtime.ide.core</module>
<module>plugins/org.jkiss.dbeaver.core</module>
<module>plugins/org.jkiss.dbeaver.ui</module>
<module>plugins/org.jkiss.dbeaver.core.application</module>
......@@ -70,6 +71,8 @@
<module>product/updateSite</module>
<module>product/standalone</module>
<module>tests/org.jkiss.dbeaver.runtime.ide.core.tests</module>
</modules>
<repositories>
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.runtime.ide.core.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.jkiss.dbeaver.runtime.ide.core.tests
Bundle-Version: 4.2.2
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.junit,
org.jkiss.dbeaver.runtime.ide.core
#Properties file for org.jkiss.dbeaver.runtime.ide.core.tests
Bundle-Vendor = JKISS
Bundle-Name = DBeaver Runtime IDE Core Tests
\ No newline at end of file
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.,\
OSGI-INF/
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>dbeaver</artifactId>
<version>1.0.0</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.runtime.ide.core.tests</artifactId>
<version>4.2.2</version>
<packaging>eclipse-test-plugin</packaging>
</project>
package org.jkiss.dbeaver.runtime.ide.core;
import java.io.ByteArrayInputStream;
import java.net.URI;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@SuppressWarnings("nls")
public class WorkspaceResourcesTest {
private static IProject project;
private static IFolder folder;
private static IFile file;
private static URI folderLocation;
private static URI fileLocation;
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@Before
public void setUp() throws Exception
{
Assert.assertTrue(Platform.isRunning());
project = ResourcesPlugin.getWorkspace().getRoot().getProject("some_project");
try {
project.create(null);
project.open(null);
folder = project.getFolder("some_folder");
folder.create(true, true, null);
file = folder.getFile("some_file");
file.create(new ByteArrayInputStream("some_content".getBytes()), IResource.NONE, null);
} catch (CoreException e) {
System.out.println(e);
}
folderLocation = tempFolder.newFolder().toURI();
fileLocation = tempFolder.newFile().toURI();
}
@After
public void tearDown() throws Exception
{
if (project.exists()) {
project.delete(true, true, null);
}
}
@Test
public void testLinkFileNegative()
{
Assert.assertFalse(WorkspaceResources.linkFile(null, fileLocation, null).isOK());
Assert.assertFalse(WorkspaceResources.linkFile(file, null, null).isOK());
Assert.assertFalse(WorkspaceResources.linkFile(file, fileLocation, null).isOK());
}
@Test
public void testLinkFilePositive()
{
IFile another = folder.getFile("another");
IStatus linkFile = WorkspaceResources.linkFile(another, fileLocation, null);
Assert.assertTrue(linkFile.isOK());
Assert.assertTrue(another.isLinked());
URI locationURI = another.getLocationURI();
Assert.assertTrue(fileLocation.equals(locationURI));
}
@Test
public void testLinkFolderNegative()
{
Assert.assertFalse(WorkspaceResources.linkFolder(null, folderLocation, null).isOK());
Assert.assertFalse(WorkspaceResources.linkFolder(folder, null, null).isOK());
Assert.assertFalse(WorkspaceResources.linkFolder(folder, folderLocation, null).isOK());
}
@Test
public void testLinkFolderPositive()
{
IFolder another = folder.getFolder("another");
IStatus linkFolder = WorkspaceResources.linkFolder(another, folderLocation, null);
Assert.assertTrue(linkFolder.isOK());
Assert.assertTrue(another.isLinked());
URI locationURI = another.getLocationURI();
Assert.assertTrue(folderLocation.equals(locationURI));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册